From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 977B7A0C4D; Thu, 17 Jun 2021 15:00:09 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1A3FC4067A; Thu, 17 Jun 2021 15:00:09 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mails.dpdk.org (Postfix) with ESMTP id 1471E40150 for ; Thu, 17 Jun 2021 15:00:06 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623934806; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ece+PTj4BeTISPzbKPIaGvgl8IPck6zMb0hafbWx7sQ=; b=UoHBihdrk5obzfgH2mLKAlcGlkaPBXDv+qmmxPk0r43WK4nLrKQeFAAPbs5npT8EdElMxe ZsEc+9QptLr4tBhYqFBeIELMoXI94UapEx2G+xlWy3SxPqJ4QM1fe5VXtsTBtUQLGLn8rQ egIHIGD/sRZUPKWX7ZuYXPXsnE43VKc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-559-vrudcPAAMCi-_7jsy2Zn8Q-1; Thu, 17 Jun 2021 09:00:04 -0400 X-MC-Unique: vrudcPAAMCi-_7jsy2Zn8Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EEF2C801106; Thu, 17 Jun 2021 13:00:03 +0000 (UTC) Received: from [10.36.110.45] (unknown [10.36.110.45]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CAB8C5B4A0; Thu, 17 Jun 2021 12:59:59 +0000 (UTC) To: "Xia, Chenbo" , "dev@dpdk.org" , "amorenoz@redhat.com" , "david.marchand@redhat.com" References: <20210608141405.52917-1-maxime.coquelin@redhat.com> <20210608141405.52917-3-maxime.coquelin@redhat.com> From: Maxime Coquelin Message-ID: <25d9c681-1677-75b1-d0d2-c9718837533f@redhat.com> Date: Thu, 17 Jun 2021 14:59:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=maxime.coquelin@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH 2/3] net/virtio: add device config support to vDPA X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 6/16/21 2:26 PM, Xia, Chenbo wrote: > Hi Maxime, > >> -----Original Message----- >> From: Maxime Coquelin >> Sent: Tuesday, June 8, 2021 10:14 PM >> To: dev@dpdk.org; Xia, Chenbo ; amorenoz@redhat.com; >> david.marchand@redhat.com >> Cc: Maxime Coquelin >> Subject: [PATCH 2/3] net/virtio: add device config support to vDPA >> >> This patch introduces two virtio-user callbacks to get >> and set device's config, and implements it for vDPA >> backends. >> >> Signed-off-by: Maxime Coquelin >> --- >> drivers/net/virtio/virtio_user/vhost.h | 3 + >> drivers/net/virtio/virtio_user/vhost_vdpa.c | 69 +++++++++++++++++++++ >> 2 files changed, 72 insertions(+) >> >> diff --git a/drivers/net/virtio/virtio_user/vhost.h >> b/drivers/net/virtio/virtio_user/vhost.h >> index c49e88036d..dfbf6be033 100644 >> --- a/drivers/net/virtio/virtio_user/vhost.h >> +++ b/drivers/net/virtio/virtio_user/vhost.h >> @@ -79,6 +79,9 @@ struct virtio_user_backend_ops { >> int (*set_vring_addr)(struct virtio_user_dev *dev, struct >> vhost_vring_addr *addr); >> int (*get_status)(struct virtio_user_dev *dev, uint8_t *status); >> int (*set_status)(struct virtio_user_dev *dev, uint8_t status); >> + int (*get_config)(struct virtio_user_dev *dev, uint8_t *data, uint32_t >> off, uint32_t len); >> + int (*set_config)(struct virtio_user_dev *dev, const uint8_t *data, >> uint32_t off, >> + uint32_t len); >> int (*enable_qp)(struct virtio_user_dev *dev, uint16_t pair_idx, int >> enable); >> int (*dma_map)(struct virtio_user_dev *dev, void *addr, uint64_t iova, >> size_t len); >> int (*dma_unmap)(struct virtio_user_dev *dev, void *addr, uint64_t iova, >> size_t len); >> diff --git a/drivers/net/virtio/virtio_user/vhost_vdpa.c >> b/drivers/net/virtio/virtio_user/vhost_vdpa.c >> index e2d6d3504d..59bc712d48 100644 >> --- a/drivers/net/virtio/virtio_user/vhost_vdpa.c >> +++ b/drivers/net/virtio/virtio_user/vhost_vdpa.c >> @@ -41,6 +41,8 @@ struct vhost_vdpa_data { >> #define VHOST_VDPA_GET_DEVICE_ID _IOR(VHOST_VIRTIO, 0x70, __u32) >> #define VHOST_VDPA_GET_STATUS _IOR(VHOST_VIRTIO, 0x71, __u8) >> #define VHOST_VDPA_SET_STATUS _IOW(VHOST_VIRTIO, 0x72, __u8) >> +#define VHOST_VDPA_GET_CONFIG _IOR(VHOST_VIRTIO, 0x73, struct >> vhost_vdpa_config) >> +#define VHOST_VDPA_SET_CONFIG _IOW(VHOST_VIRTIO, 0x74, struct >> vhost_vdpa_config) >> #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, struct >> vhost_vring_state) >> #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64) >> #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64) >> @@ -65,6 +67,12 @@ struct vhost_iotlb_msg { >> >> #define VHOST_IOTLB_MSG_V2 0x2 >> >> +struct vhost_vdpa_config { >> + uint32_t off; >> + uint32_t len; >> + uint8_t buf[0]; >> +}; >> + >> struct vhost_msg { >> uint32_t type; >> uint32_t reserved; >> @@ -440,6 +448,65 @@ vhost_vdpa_set_status(struct virtio_user_dev *dev, >> uint8_t status) >> return vhost_vdpa_ioctl(data->vhostfd, VHOST_VDPA_SET_STATUS, &status); >> } >> >> +static int >> +vhost_vdpa_get_config(struct virtio_user_dev *dev, uint8_t *data, uint32_t >> off, uint32_t len) >> +{ >> + struct vhost_vdpa_data *vdpa_data = dev->backend_data; >> + struct vhost_vdpa_config *config; >> + int ret = 0; >> + >> + config = malloc(sizeof(*config) + len); >> + if (!config) { >> + PMD_DRV_LOG(ERR, "Failed to allocate vDPA config data\n"); > > No need to add '\n'. And same for below three 'PMD_DRV_LOG' Yes, it is unecessary. >> + return -1; >> + } >> + >> + config->off = off; >> + config->len = len; >> + >> + ret = vhost_vdpa_ioctl(vdpa_data->vhostfd, VHOST_VDPA_GET_CONFIG, >> config); >> + if (ret) { >> + PMD_DRV_LOG(ERR, "Failed to get vDPA config (offset %x, len %x)\n", > > Better add '0x' here as it will be friendly to user 😊 Indeed, fixing it in v2. >> off, len); >> + ret = -1; >> + goto out; >> + } >> + >> + memcpy(data, config->buf, len); >> +out: >> + free(config); >> + >> + return ret; >> +} >> + >> +static int >> +vhost_vdpa_set_config(struct virtio_user_dev *dev, const uint8_t *data, >> uint32_t off, uint32_t len) >> +{ >> + struct vhost_vdpa_data *vdpa_data = dev->backend_data; >> + struct vhost_vdpa_config *config; >> + int ret = 0; >> + >> + config = malloc(sizeof(*config) + len); >> + if (!config) { >> + PMD_DRV_LOG(ERR, "Failed to allocate vDPA config data\n"); >> + return -1; >> + } >> + >> + config->off = off; >> + config->len = len; >> + >> + memcpy(config->buf, data, len); >> + >> + ret = vhost_vdpa_ioctl(vdpa_data->vhostfd, VHOST_VDPA_SET_CONFIG, >> config); >> + if (ret) { >> + PMD_DRV_LOG(ERR, "Failed to set vDPA config (offset %x, len %x)\n", >> off, len); > > Ditto Fixed in v2. Thanks, Maxime > Thanks, > Chenbo > >> + ret = -1; >> + } >> + >> + free(config); >> + >> + return ret; >> +} >> + >> /** >> * Set up environment to talk with a vhost vdpa backend. >> * >> @@ -559,6 +626,8 @@ struct virtio_user_backend_ops virtio_ops_vdpa = { >> .set_vring_addr = vhost_vdpa_set_vring_addr, >> .get_status = vhost_vdpa_get_status, >> .set_status = vhost_vdpa_set_status, >> + .get_config = vhost_vdpa_get_config, >> + .set_config = vhost_vdpa_set_config, >> .enable_qp = vhost_vdpa_enable_queue_pair, >> .dma_map = vhost_vdpa_dma_map_batch, >> .dma_unmap = vhost_vdpa_dma_unmap_batch, >> -- >> 2.31.1 >