From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id 0312F27D for ; Mon, 25 Feb 2019 08:49:06 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 408EC4E938; Mon, 25 Feb 2019 07:49:06 +0000 (UTC) Received: from [10.72.12.94] (ovpn-12-94.pek2.redhat.com [10.72.12.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1508E5C21E; Mon, 25 Feb 2019 07:48:59 +0000 (UTC) To: Changpeng Liu , dev@dpdk.org Cc: dariusz.stojaczyk@intel.com, maxime.coquelin@redhat.com, tiwei.bie@intel.com, zhihong.wang@intel.com References: <1551081095-14286-1-git-send-email-changpeng.liu@intel.com> From: Jason Wang Message-ID: <1a43221c-2bc7-efce-0e18-c425bfe1d201@redhat.com> Date: Mon, 25 Feb 2019 15:48:58 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1551081095-14286-1-git-send-email-changpeng.liu@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 25 Feb 2019 07:49:06 +0000 (UTC) Subject: Re: [dpdk-dev] [PATCH] vhost: add virtio configuration space access socket messages X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Feb 2019 07:49:07 -0000 On 2019/2/25 下午3:51, Changpeng Liu wrote: > This patch adds new vhost user messages GET_CONFIG and SET_CONFIG > used to get/set virtio device's PCI configuration space. I think it's better to describe the reason for doing this. I believe vhost is transport independent. Thanks > > Signed-off-by: Changpeng Liu > --- > lib/librte_vhost/rte_vhost.h | 8 ++++++++ > lib/librte_vhost/vhost_user.c | 44 +++++++++++++++++++++++++++++++++++++++++++ > lib/librte_vhost/vhost_user.h | 16 ++++++++++++++++ > 3 files changed, 68 insertions(+) > > diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h > index 2753670..ab710ce 100644 > --- a/lib/librte_vhost/rte_vhost.h > +++ b/lib/librte_vhost/rte_vhost.h > @@ -63,6 +63,10 @@ > #define VHOST_USER_PROTOCOL_F_PAGEFAULT 8 > #endif > > +#ifndef VHOST_USER_PROTOCOL_F_CONFIG > +#define VHOST_USER_PROTOCOL_F_CONFIG 9 > +#endif > + > #ifndef VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD > #define VHOST_USER_PROTOCOL_F_SLAVE_SEND_FD 10 > #endif > @@ -173,6 +177,10 @@ struct vhost_device_ops { > > int (*vring_state_changed)(int vid, uint16_t queue_id, int enable); /**< triggered when a vring is enabled or disabled */ > > + int (*get_config)(int vid, uint8_t *config, uint32_t config_len); > + int (*set_config)(int vid, uint8_t *config, uint32_t offset, > + uint32_t len, uint32_t flags); > + > /** > * Features could be changed after the feature negotiation. > * For example, VHOST_F_LOG_ALL will be set/cleared at the > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index b086ad9..8e42734 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -73,6 +73,8 @@ > [VHOST_USER_NET_SET_MTU] = "VHOST_USER_NET_SET_MTU", > [VHOST_USER_SET_SLAVE_REQ_FD] = "VHOST_USER_SET_SLAVE_REQ_FD", > [VHOST_USER_IOTLB_MSG] = "VHOST_USER_IOTLB_MSG", > + [VHOST_USER_GET_CONFIG] = "VHOST_USER_GET_CONFIG", > + [VHOST_USER_SET_CONFIG] = "VHOST_USER_SET_CONFIG", > [VHOST_USER_CRYPTO_CREATE_SESS] = "VHOST_USER_CRYPTO_CREATE_SESS", > [VHOST_USER_CRYPTO_CLOSE_SESS] = "VHOST_USER_CRYPTO_CLOSE_SESS", > [VHOST_USER_POSTCOPY_ADVISE] = "VHOST_USER_POSTCOPY_ADVISE", > @@ -359,6 +361,46 @@ > return RTE_VHOST_MSG_RESULT_OK; > } > > +static int > +vhost_user_get_config(struct virtio_net **pdev, struct VhostUserMsg *msg, > + int main_fd __rte_unused) > +{ > + struct virtio_net *dev = *pdev; > + > + if (!dev->notify_ops->get_config) { > + msg->size = sizeof(uint64_t); > + return RTE_VHOST_MSG_RESULT_REPLY; > + } > + > + if (dev->notify_ops->get_config(dev->vid, > + msg->payload.config.region, > + msg->payload.config.size) != 0) { > + msg->size = sizeof(uint64_t); > + } > + > + return RTE_VHOST_MSG_RESULT_REPLY; > +} > + > +static int > +vhost_user_set_config(struct virtio_net **pdev, struct VhostUserMsg *msg, > + int main_fd __rte_unused) > +{ > + struct virtio_net *dev = *pdev; > + > + if (!dev->notify_ops->set_config) > + return RTE_VHOST_MSG_RESULT_ERR; > + > + if (dev->notify_ops->set_config(dev->vid, > + msg->payload.config.region, > + msg->payload.config.offset, > + msg->payload.config.size, > + msg->payload.config.flags) != 0) { > + return RTE_VHOST_MSG_RESULT_ERR; > + } > + > + return RTE_VHOST_MSG_RESULT_OK; > +} > + > /* > * Reallocate virtio_dev and vhost_virtqueue data structure to make them on the > * same numa node as the memory of vring descriptor. > @@ -1725,6 +1767,8 @@ typedef int (*vhost_message_handler_t)(struct virtio_net **pdev, > [VHOST_USER_NET_SET_MTU] = vhost_user_net_set_mtu, > [VHOST_USER_SET_SLAVE_REQ_FD] = vhost_user_set_req_fd, > [VHOST_USER_IOTLB_MSG] = vhost_user_iotlb_msg, > + [VHOST_USER_GET_CONFIG] = vhost_user_get_config, > + [VHOST_USER_SET_CONFIG] = vhost_user_set_config, > [VHOST_USER_POSTCOPY_ADVISE] = vhost_user_set_postcopy_advise, > [VHOST_USER_POSTCOPY_LISTEN] = vhost_user_set_postcopy_listen, > [VHOST_USER_POSTCOPY_END] = vhost_user_postcopy_end, > diff --git a/lib/librte_vhost/vhost_user.h b/lib/librte_vhost/vhost_user.h > index 2a650fe..057cdec 100644 > --- a/lib/librte_vhost/vhost_user.h > +++ b/lib/librte_vhost/vhost_user.h > @@ -12,6 +12,11 @@ > > /* refer to hw/virtio/vhost-user.c */ > > +/* > + * Maximum size of virtio device config space > + */ > +#define VHOST_USER_MAX_CONFIG_SIZE 256 > + > #define VHOST_MEMORY_MAX_NREGIONS 8 > > #define VHOST_USER_PROTOCOL_FEATURES ((1ULL << VHOST_USER_PROTOCOL_F_MQ) | \ > @@ -49,6 +54,8 @@ > VHOST_USER_NET_SET_MTU = 20, > VHOST_USER_SET_SLAVE_REQ_FD = 21, > VHOST_USER_IOTLB_MSG = 22, > + VHOST_USER_GET_CONFIG = 24, > + VHOST_USER_SET_CONFIG = 25, > VHOST_USER_CRYPTO_CREATE_SESS = 26, > VHOST_USER_CRYPTO_CLOSE_SESS = 27, > VHOST_USER_POSTCOPY_ADVISE = 28, > @@ -60,6 +67,7 @@ > typedef enum VhostUserSlaveRequest { > VHOST_USER_SLAVE_NONE = 0, > VHOST_USER_SLAVE_IOTLB_MSG = 1, > + VHOST_USER_SLAVE_CONFIG_CHANGE_MSG = 2, > VHOST_USER_SLAVE_VRING_HOST_NOTIFIER_MSG = 3, > VHOST_USER_SLAVE_MAX > } VhostUserSlaveRequest; > @@ -112,6 +120,13 @@ > uint64_t offset; > } VhostUserVringArea; > > +typedef struct VhostUserConfig { > + uint32_t offset; > + uint32_t size; > + uint32_t flags; > + uint8_t region[VHOST_USER_MAX_CONFIG_SIZE]; > +} VhostUserConfig; > + > typedef struct VhostUserMsg { > union { > uint32_t master; /* a VhostUserRequest value */ > @@ -131,6 +146,7 @@ > struct vhost_vring_addr addr; > VhostUserMemory memory; > VhostUserLog log; > + VhostUserConfig config; > struct vhost_iotlb_msg iotlb; > VhostUserCryptoSessionParam crypto_session; > VhostUserVringArea area;