From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 5492CA0350; Fri, 26 Jun 2020 12:38:40 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 98AD71BEAE; Fri, 26 Jun 2020 12:38:39 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 8DCA81BEA9 for ; Fri, 26 Jun 2020 12:38:38 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593167918; 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:autocrypt:autocrypt; bh=O1SWA9tB/yH+uQ22tmA0fTXCNxbomkKwDGXo0Qz+4nY=; b=eUXZFRr6BXdZi+0i41OQrmXRwqFFu+tYWlPxUYJp0G3osytWsMc0rwM3kzNxYhuJX6Gezm 77Un7E0hPoCjm8CZIfojHqaIEi78LxGetT221KdB2ov4verewGcNOC2+5bsUj85h+/Rmss U46CvP0quZk8L7s0IurCkBsmPr1+bIM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-28-HguVzG7ONlOcL6hL2h_l7g-1; Fri, 26 Jun 2020 06:38:36 -0400 X-MC-Unique: HguVzG7ONlOcL6hL2h_l7g-1 Received: by mail-wm1-f69.google.com with SMTP id g124so10287293wmg.6 for ; Fri, 26 Jun 2020 03:38:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:autocrypt:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=O1SWA9tB/yH+uQ22tmA0fTXCNxbomkKwDGXo0Qz+4nY=; b=ehb7ivzfVlKwtDIn0BcQr1sNv94Ua6AgRCaK3MpOTZPZfKo5NNPJa3nmOqDpW4cwfw UT+O+3D/xUuat0YV1VU9AELKkybV0VWbdjEWLuCjhIV0tAltyG0zrQVDJBAsdqTp6mte 85HjjdHkd4GfPsPMzyA73COBrDxVpo4QCWxfgiIT+uWM5M0NkW6zwjj8AL5fWxFffE04 a8BgXJxm3j51cFVPlaM9ov/iWqy4rVF42nak1dtS9XSVUpBmsHr7BMtFVkCM/4jyQlBg TqsIL6+kOktDVM9beSe0w1YqbORBELTKCtUBQhVs51eVh7onI/aoa2H1a4Tpe4OIzKyB Wl4A== X-Gm-Message-State: AOAM533ZAbs8OOip6za/k+Wwiki0MX/FY/g3ECy72BxJglDrtpXUAXzd pfxWi4faxd/OU0LoGcrFSMmnaHrl2D7ItRXzUpqH9bwxVMBeL0LfsPw87ZYwmkk3GwyfnF8jBNr P4wQ= X-Received: by 2002:adf:e50a:: with SMTP id j10mr3209510wrm.71.1593167914215; Fri, 26 Jun 2020 03:38:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEQ/hNTn8xMu9BL3fwTSwiLq4+iEmAKflyThEEwNJ8JfiHYQmB47x6z1jmXr0MTbLQ3qUw8g== X-Received: by 2002:adf:e50a:: with SMTP id j10mr3209476wrm.71.1593167913788; Fri, 26 Jun 2020 03:38:33 -0700 (PDT) Received: from amorenoz.users.ipa.redhat.com ([92.176.159.3]) by smtp.gmail.com with ESMTPSA id a81sm17035842wmf.30.2020.06.26.03.38.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 26 Jun 2020 03:38:32 -0700 (PDT) To: Maxime Coquelin , matan@mellanox.com, xiao.w.wang@intel.com, zhihong.wang@intel.com, chenbo.xia@intel.com, david.marchand@redhat.com, viacheslavo@mellanox.com, hemant.agrawal@nxp.com, sachin.saxena@nxp.com, grive@u256.net, dev@dpdk.org References: <20200624122701.1369327-1-maxime.coquelin@redhat.com> <20200624122701.1369327-7-maxime.coquelin@redhat.com> From: Adrian Moreno Autocrypt: addr=amorenoz@redhat.com; prefer-encrypt=mutual; keydata= mQENBF1syNUBCADQ9dk3fDMxOZ/+OQpmbanpodYxEv8IRtDz8PXw8YX7UyGfozOpLjQ8Fftj ZxuubYNbt2QVbSgviFilFdNWu2eTnN/JaGtfhmTOLPVoakkPHZF8lbgImMoch7L0fH8wN2IM KPxQyPNlX+K9FD5brHsV1lfe1TwAxmhcvLW8yNrVq+9eDIDykxc7tH4exIqXgZroahGxMHKy c8Ti2kJka/t6pDfRaY0J+6J7I1nrn6GXXSMNA45EH8+0N/QlcXhP3rfftnoPeVmpjswzvJqY FNjf/Q5VPLx7RX0Qx+y8mMB2JcChV5Bl7D7x5EUbItj6+Sy7QfOgCtPegk9HSrBCNYaLABEB AAG0I0FkcmlhbiBNb3Jlbm8gPGFtb3Jlbm96QHJlZGhhdC5jb20+iQFUBBMBCAA+FiEEogUD gihhmbOPHy26d5C5fbYeFsUFAl1syNUCGwMFCQHhM4AFCwkIBwIGFQoJCAsCBBYCAwECHgEC F4AACgkQd5C5fbYeFsX7qwgArGHSkX+ILNcujkVzjTG4OtkpJMPFlkn/1PxSEKD0jLuzx14B COzpg/Mqj3Re/QBuOas+ci9bsUA0/2nORtmmEBvzDOJpR5FH1jaGCx8USlY4WM6QqEDNZgTw hsy9KhjFzFjMk+oo3HyItXA+Uq9yrRBTjNBGTXxezMRcMuUZ4MIAfY0IRBglL2BufiuL43jD BvTENNFLoQ/wFV7qkFWSkv+8IjTsxr7M6XUo1QLd29Hn0dvwssN579HL1+BP46i2REpzeBEG L75iVChi+YnIQQNMJ9NYarVabZx4Y1Gn8+7B/1SNArDV+IDgnYgt7E58otoV2Ap310dmtuvE VbxGpbkBDQRdbMjVAQgAqyp9oA7WDu7/Y9T4Ommt69iZx8os7shUIfdgPEy5xrcPn6qGwN1/ HQ4j8nWfBG9uuX1X0RXUZIUEtYTxtED4yaCQMTqDUf9cBAwAA2mYxBfoiNYx8YqxM+sT0/J4 2qmDd+y+20UR4yzHE8AmIbspTzDFIJDAi+jKSR8F355z0sfW7CIMDC4ZWrPsskjEy1YN/U10 r6tRRH1kNyrCSbTG0d9MtcQO58h7DLXuzUhErB+BtG52A04t5cweIJTJC+koV5XPeilzlHnm RFoj0ncruGa9Odns21BNt3cy9wLfK+aUnWuAB1uc6bJGQPiAwjkilz7g7MBRUuIQ2Zt7HGLc SwARAQABiQE8BBgBCAAmFiEEogUDgihhmbOPHy26d5C5fbYeFsUFAl1syNUCGwwFCQHhM4AA CgkQd5C5fbYeFsUlSwf8CH+u/IXaE7WeWxwFkMaORfW8cM4q0xrL3M6yRGuQNW+kMjnrvK9U J9G+L1/5uTRbDQ/4LdoKqize8LjehA+iF6ba4t9Npikh8fLKWgaJfQ/hPhH4C3O5gWPOLTW6 ylGxiuER4CdFwQIoAMMslhFA7G+teeOKBq36E+1+zrybI6Xy1UBSlpDK9j4CtTnMQejjuSQb Qhle+l8VroaUHq869wjAhRHHhqmtJKggI+OvzgQpDIwfHIDypb1BuKydi2W6cVYEALUYyCLS dTBDhzj8zR5tPCsga8J7+TclQzkWOiI2C6ZtiWrMsL/Uym3uXk5nsoc7lSj7yLd/MrBRhYfP JQ== Message-ID: Date: Fri, 26 Jun 2020 12:38:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20200624122701.1369327-7-maxime.coquelin@redhat.com> Content-Language: en-US Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=amorenoz@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH v2 06/14] vhost: replace vDPA device ID in Vhost 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 6/24/20 2:26 PM, Maxime Coquelin wrote: > This removes the notion of device ID in Vhost library > as a preliminary step to get rid of the vDPA device ID. > > Signed-off-by: Maxime Coquelin > --- > drivers/vdpa/ifc/ifcvf_vdpa.c | 12 ++++---- > drivers/vdpa/mlx5/mlx5_vdpa.c | 18 ++++------- > examples/vdpa/main.c | 9 +++++- > lib/librte_vhost/rte_vhost.h | 20 ++++++------ > lib/librte_vhost/rte_vhost_version.map | 4 +-- > lib/librte_vhost/socket.c | 42 ++++++++++---------------- > lib/librte_vhost/vhost.c | 19 +++++------- > lib/librte_vhost/vhost.h | 8 ++--- > lib/librte_vhost/vhost_user.c | 28 +++++------------ > 9 files changed, 66 insertions(+), 94 deletions(-) > > diff --git a/drivers/vdpa/ifc/ifcvf_vdpa.c b/drivers/vdpa/ifc/ifcvf_vdpa.c > index 0418f9a07f..4163047744 100644 > --- a/drivers/vdpa/ifc/ifcvf_vdpa.c > +++ b/drivers/vdpa/ifc/ifcvf_vdpa.c > @@ -881,7 +881,7 @@ ifcvf_dev_config(int vid) > struct internal_list *list; > struct ifcvf_internal *internal; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > @@ -907,7 +907,7 @@ ifcvf_dev_close(int vid) > struct internal_list *list; > struct ifcvf_internal *internal; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > @@ -947,7 +947,7 @@ ifcvf_set_features(int vid) > struct ifcvf_internal *internal; > uint64_t log_base = 0, log_size = 0; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > @@ -978,7 +978,7 @@ ifcvf_get_vfio_group_fd(int vid) > struct rte_vdpa_device *vdev; > struct internal_list *list; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > @@ -994,7 +994,7 @@ ifcvf_get_vfio_device_fd(int vid) > struct rte_vdpa_device *vdev; > struct internal_list *list; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > @@ -1013,7 +1013,7 @@ ifcvf_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > struct vfio_region_info reg = { .argsz = sizeof(reg) }; > int ret; > > - vdev = rte_vdpa_get_device(rte_vhost_get_vdpa_device_id(vid)); > + vdev = rte_vhost_get_vdpa_device(vid); > list = find_internal_resource_by_vdev(vdev); > if (list == NULL) { > DRV_LOG(ERR, "Invalid vDPA device: %p", vdev); > diff --git a/drivers/vdpa/mlx5/mlx5_vdpa.c b/drivers/vdpa/mlx5/mlx5_vdpa.c > index 9ea032d57b..47db5fd6f4 100644 > --- a/drivers/vdpa/mlx5/mlx5_vdpa.c > +++ b/drivers/vdpa/mlx5/mlx5_vdpa.c > @@ -129,8 +129,7 @@ mlx5_vdpa_get_protocol_features(struct rte_vdpa_device *vdev, > static int > mlx5_vdpa_set_vring_state(int vid, int vring, int state) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > @@ -171,8 +170,7 @@ mlx5_vdpa_direct_db_prepare(struct mlx5_vdpa_priv *priv) > static int > mlx5_vdpa_features_set(int vid) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > uint64_t log_base, log_size; > @@ -292,8 +290,7 @@ mlx5_vdpa_mtu_set(struct mlx5_vdpa_priv *priv) > static int > mlx5_vdpa_dev_close(int vid) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > int ret = 0; > @@ -322,8 +319,7 @@ mlx5_vdpa_dev_close(int vid) > static int > mlx5_vdpa_dev_config(int vid) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > @@ -354,8 +350,7 @@ mlx5_vdpa_dev_config(int vid) > static int > mlx5_vdpa_get_device_fd(int vid) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > @@ -369,8 +364,7 @@ mlx5_vdpa_get_device_fd(int vid) > static int > mlx5_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size) > { > - struct rte_vdpa_device *vdev = rte_vdpa_get_device( > - rte_vhost_get_vdpa_device_id(vid)); > + struct rte_vdpa_device *vdev = rte_vhost_get_vdpa_device(vid); > struct mlx5_vdpa_priv *priv = > mlx5_vdpa_find_priv_resource_by_vdev(vdev); > > diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c > index bdb00603cc..6a719e32d8 100644 > --- a/examples/vdpa/main.c > +++ b/examples/vdpa/main.c > @@ -149,6 +149,7 @@ start_vdpa(struct vdpa_port *vport) > { > int ret; > char *socket_path = vport->ifname; > + struct rte_vdpa_device *vdev; > int did = vport->did; > > if (client_mode) > @@ -173,7 +174,13 @@ start_vdpa(struct vdpa_port *vport) > "register driver ops failed: %s\n", > socket_path); > > - ret = rte_vhost_driver_attach_vdpa_device(socket_path, did); > + vdev = rte_vdpa_get_device(did); > + if (!vdev) > + rte_exit(EXIT_FAILURE, > + "vDPA device retrieval failed: %p\n", > + vdev); > + > + ret = rte_vhost_driver_attach_vdpa_device(socket_path, vdev); > if (ret != 0) > rte_exit(EXIT_FAILURE, > "attach vdpa device failed: %s\n", > diff --git a/lib/librte_vhost/rte_vhost.h b/lib/librte_vhost/rte_vhost.h > index d43669f2c2..2fbc364643 100644 > --- a/lib/librte_vhost/rte_vhost.h > +++ b/lib/librte_vhost/rte_vhost.h > @@ -90,6 +90,7 @@ extern "C" { > #define VHOST_USER_F_PROTOCOL_FEATURES 30 > #endif > > +struct rte_vdpa_device; > > /** > * Information relating to memory regions including offsets to > @@ -402,14 +403,15 @@ int rte_vhost_driver_unregister(const char *path); > * > * @param path > * The vhost-user socket file path > - * @param did > - * Device id > + * @param dev > + * vDPA device pointer > * @return > * 0 on success, -1 on failure > */ > __rte_experimental > int > -rte_vhost_driver_attach_vdpa_device(const char *path, int did); > +rte_vhost_driver_attach_vdpa_device(const char *path, > + struct rte_vdpa_device *dev); > > /** > * Unset the vdpa device id > @@ -429,11 +431,11 @@ rte_vhost_driver_detach_vdpa_device(const char *path); > * @param path > * The vhost-user socket file path > * @return > - * Device id, -1 on failure > + * vDPA device pointer, NULL on failure > */ > __rte_experimental > -int > -rte_vhost_driver_get_vdpa_device_id(const char *path); > +struct rte_vdpa_device * > +rte_vhost_driver_get_vdpa_device(const char *path); > > /** > * Set the feature bits the vhost-user driver supports. > @@ -977,11 +979,11 @@ rte_vhost_extern_callback_register(int vid, > * @param vid > * vhost device id > * @return > - * device id > + * vDPA device pointer on success, NULL on failure > */ > __rte_experimental > -int > -rte_vhost_get_vdpa_device_id(int vid); > +struct rte_vdpa_device * > +rte_vhost_get_vdpa_device(int vid); > > /** > * Notify the guest that should get virtio configuration space from backend. > diff --git a/lib/librte_vhost/rte_vhost_version.map b/lib/librte_vhost/rte_vhost_version.map > index 9325ee4227..60d67445d7 100644 > --- a/lib/librte_vhost/rte_vhost_version.map > +++ b/lib/librte_vhost/rte_vhost_version.map > @@ -43,8 +43,8 @@ EXPERIMENTAL { > rte_vdpa_reset_stats; > rte_vhost_driver_attach_vdpa_device; > rte_vhost_driver_detach_vdpa_device; > - rte_vhost_driver_get_vdpa_device_id; > - rte_vhost_get_vdpa_device_id; > + rte_vhost_driver_get_vdpa_device; > + rte_vhost_get_vdpa_device; > rte_vhost_driver_get_protocol_features; > rte_vhost_driver_get_queue_num; > rte_vhost_get_log_base; > diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c > index da575b608c..49267cebf9 100644 > --- a/lib/librte_vhost/socket.c > +++ b/lib/librte_vhost/socket.c > @@ -55,12 +55,7 @@ struct vhost_user_socket { > > uint64_t protocol_features; > > - /* > - * Device id to identify a specific backend device. > - * It's set to -1 for the default software implementation. > - * If valid, one socket can have 1 connection only. > - */ > - int vdpa_dev_id; > + struct rte_vdpa_device *vdpa_dev; > > struct vhost_device_ops const *notify_ops; > }; > @@ -230,7 +225,7 @@ vhost_user_add_connection(int fd, struct vhost_user_socket *vsocket) > > vhost_set_builtin_virtio_net(vid, vsocket->use_builtin_virtio_net); > > - vhost_attach_vdpa_device(vid, vsocket->vdpa_dev_id); > + vhost_attach_vdpa_device(vid, vsocket->vdpa_dev); > > if (vsocket->dequeue_zero_copy) > vhost_enable_dequeue_zero_copy(vid); > @@ -578,17 +573,18 @@ find_vhost_user_socket(const char *path) > } > > int > -rte_vhost_driver_attach_vdpa_device(const char *path, int did) > +rte_vhost_driver_attach_vdpa_device(const char *path, > + struct rte_vdpa_device *dev) > { > struct vhost_user_socket *vsocket; > > - if (rte_vdpa_get_device(did) == NULL || path == NULL) > + if (dev == NULL || path == NULL) > return -1; > > pthread_mutex_lock(&vhost_user.mutex); > vsocket = find_vhost_user_socket(path); > if (vsocket) > - vsocket->vdpa_dev_id = did; > + vsocket->vdpa_dev = dev; > pthread_mutex_unlock(&vhost_user.mutex); > > return vsocket ? 0 : -1; > @@ -602,25 +598,25 @@ rte_vhost_driver_detach_vdpa_device(const char *path) > pthread_mutex_lock(&vhost_user.mutex); > vsocket = find_vhost_user_socket(path); > if (vsocket) > - vsocket->vdpa_dev_id = -1; > + vsocket->vdpa_dev = NULL; > pthread_mutex_unlock(&vhost_user.mutex); > > return vsocket ? 0 : -1; > } > > -int > -rte_vhost_driver_get_vdpa_device_id(const char *path) > +struct rte_vdpa_device * > +rte_vhost_driver_get_vdpa_device(const char *path) > { > struct vhost_user_socket *vsocket; > - int did = -1; > + struct rte_vdpa_device *dev = NULL; > > pthread_mutex_lock(&vhost_user.mutex); > vsocket = find_vhost_user_socket(path); > if (vsocket) > - did = vsocket->vdpa_dev_id; > + dev = vsocket->vdpa_dev; > pthread_mutex_unlock(&vhost_user.mutex); > > - return did; > + return dev; > } > > int > @@ -693,7 +689,6 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) > struct vhost_user_socket *vsocket; > uint64_t vdpa_features; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > int ret = 0; > > pthread_mutex_lock(&vhost_user.mutex); > @@ -705,8 +700,7 @@ rte_vhost_driver_get_features(const char *path, uint64_t *features) > goto unlock_exit; > } > > - did = vsocket->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = vsocket->vdpa_dev; > if (!vdpa_dev || !vdpa_dev->ops->get_features) { > *features = vsocket->features; > goto unlock_exit; > @@ -748,7 +742,6 @@ rte_vhost_driver_get_protocol_features(const char *path, > struct vhost_user_socket *vsocket; > uint64_t vdpa_protocol_features; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > int ret = 0; > > pthread_mutex_lock(&vhost_user.mutex); > @@ -760,8 +753,7 @@ rte_vhost_driver_get_protocol_features(const char *path, > goto unlock_exit; > } > > - did = vsocket->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = vsocket->vdpa_dev; > if (!vdpa_dev || !vdpa_dev->ops->get_protocol_features) { > *protocol_features = vsocket->protocol_features; > goto unlock_exit; > @@ -790,7 +782,6 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) > struct vhost_user_socket *vsocket; > uint32_t vdpa_queue_num; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > int ret = 0; > > pthread_mutex_lock(&vhost_user.mutex); > @@ -802,8 +793,7 @@ rte_vhost_driver_get_queue_num(const char *path, uint32_t *queue_num) > goto unlock_exit; > } > > - did = vsocket->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = vsocket->vdpa_dev; > if (!vdpa_dev || !vdpa_dev->ops->get_queue_num) { > *queue_num = VHOST_MAX_QUEUE_PAIRS; > goto unlock_exit; > @@ -878,7 +868,7 @@ rte_vhost_driver_register(const char *path, uint64_t flags) > "error: failed to init connection mutex\n"); > goto out_free; > } > - vsocket->vdpa_dev_id = -1; > + vsocket->vdpa_dev = NULL; > vsocket->dequeue_zero_copy = flags & RTE_VHOST_USER_DEQUEUE_ZERO_COPY; > vsocket->extbuf = flags & RTE_VHOST_USER_EXTBUF_SUPPORT; > vsocket->linearbuf = flags & RTE_VHOST_USER_LINEARBUF_SUPPORT; > diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c > index 0266318440..0d822d6a3f 100644 > --- a/lib/librte_vhost/vhost.c > +++ b/lib/librte_vhost/vhost.c > @@ -633,7 +633,6 @@ vhost_new_device(void) > dev->vid = i; > dev->flags = VIRTIO_DEV_BUILTIN_VIRTIO_NET; > dev->slave_req_fd = -1; > - dev->vdpa_dev_id = -1; > dev->postcopy_ufd = -1; > rte_spinlock_init(&dev->slave_req_lock); > > @@ -644,11 +643,9 @@ void > vhost_destroy_device_notify(struct virtio_net *dev) > { > struct rte_vdpa_device *vdpa_dev; > - int did; > > if (dev->flags & VIRTIO_DEV_RUNNING) { > - did = dev->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = dev->vdpa_dev; > if (vdpa_dev && vdpa_dev->ops->dev_close) > vdpa_dev->ops->dev_close(dev->vid); > dev->flags &= ~VIRTIO_DEV_RUNNING; > @@ -677,17 +674,14 @@ vhost_destroy_device(int vid) > } > > void > -vhost_attach_vdpa_device(int vid, int did) > +vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *vdpa_dev) > { > struct virtio_net *dev = get_device(vid); > > if (dev == NULL) > return; > > - if (rte_vdpa_get_device(did) == NULL) > - return; > - > - dev->vdpa_dev_id = did; > + dev->vdpa_dev = vdpa_dev; > } > > void > @@ -1402,14 +1396,15 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid) > return ret; > } > > -int rte_vhost_get_vdpa_device_id(int vid) > +struct rte_vdpa_device * > +rte_vhost_get_vdpa_device(int vid) > { > struct virtio_net *dev = get_device(vid); > > if (dev == NULL) > - return -1; > + return NULL; > > - return dev->vdpa_dev_id; > + return dev->vdpa_dev; > } > > int rte_vhost_get_log_base(int vid, uint64_t *log_base, > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h > index df98d15de6..819857a65a 100644 > --- a/lib/librte_vhost/vhost.h > +++ b/lib/librte_vhost/vhost.h > @@ -377,11 +377,7 @@ struct virtio_net { > int postcopy_ufd; > int postcopy_listening; > > - /* > - * Device id to identify a specific backend device. > - * It's set to -1 for the default software implementation. > - */ > - int vdpa_dev_id; > + struct rte_vdpa_device *vdpa_dev; > > /* context data for the external message handlers */ > void *extern_data; > @@ -639,7 +635,7 @@ void free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq); > > int alloc_vring_queue(struct virtio_net *dev, uint32_t vring_idx); > > -void vhost_attach_vdpa_device(int vid, int did); > +void vhost_attach_vdpa_device(int vid, struct rte_vdpa_device *dev); > > void vhost_set_ifname(int, const char *if_name, unsigned int if_len); > void vhost_enable_dequeue_zero_copy(int vid); > diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c > index ea9cd107b9..3405cd8c0b 100644 > --- a/lib/librte_vhost/vhost_user.c > +++ b/lib/librte_vhost/vhost_user.c > @@ -315,7 +315,6 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, > uint64_t features = msg->payload.u64; > uint64_t vhost_features = 0; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > > if (validate_msg_fds(msg, 0) != 0) > return RTE_VHOST_MSG_RESULT_ERR; > @@ -384,8 +383,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, > } > } > > - did = dev->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = dev->vdpa_dev; > if (vdpa_dev && vdpa_dev->ops->set_features) > vdpa_dev->ops->set_features(dev->vid); > > @@ -1971,7 +1969,6 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, > int enable = (int)msg->payload.state.num; > int index = (int)msg->payload.state.index; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > > if (validate_msg_fds(msg, 0) != 0) > return RTE_VHOST_MSG_RESULT_ERR; > @@ -1980,8 +1977,7 @@ vhost_user_set_vring_enable(struct virtio_net **pdev, > "set queue enable: %d to qp idx: %d\n", > enable, index); > > - did = dev->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = dev->vdpa_dev; > if (vdpa_dev && vdpa_dev->ops->set_vring_state) > vdpa_dev->ops->set_vring_state(dev->vid, index, enable); > > @@ -2147,7 +2143,6 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, > struct virtio_net *dev = *pdev; > uint8_t *mac = (uint8_t *)&msg->payload.u64; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > > if (validate_msg_fds(msg, 0) != 0) > return RTE_VHOST_MSG_RESULT_ERR; > @@ -2165,8 +2160,7 @@ vhost_user_send_rarp(struct virtio_net **pdev, struct VhostUserMsg *msg, > * copied before the flag is set. > */ > __atomic_store_n(&dev->broadcast_rarp, 1, __ATOMIC_RELEASE); > - did = dev->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = dev->vdpa_dev; > if (vdpa_dev && vdpa_dev->ops->migration_done) > vdpa_dev->ops->migration_done(dev->vid); > > @@ -2613,7 +2607,6 @@ vhost_user_msg_handler(int vid, int fd) > struct virtio_net *dev; > struct VhostUserMsg msg; > struct rte_vdpa_device *vdpa_dev; > - int did = -1; > int ret; > int unlock_required = 0; > bool handled; > @@ -2805,8 +2798,7 @@ vhost_user_msg_handler(int vid, int fd) > } > } > > - did = dev->vdpa_dev_id; > - vdpa_dev = rte_vdpa_get_device(did); > + vdpa_dev = dev->vdpa_dev; > if (vdpa_dev && virtio_is_ready(dev) && > !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) && > msg.request.master == VHOST_USER_SET_VRING_CALL) { > @@ -2955,7 +2947,7 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) > { > struct virtio_net *dev; > struct rte_vdpa_device *vdpa_dev; > - int vfio_device_fd, did, ret = 0; > + int vfio_device_fd, ret = 0; > uint64_t offset, size; > unsigned int i; > > @@ -2963,9 +2955,9 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) > if (!dev) > return -ENODEV; > > - did = dev->vdpa_dev_id; > - if (did < 0) > - return -EINVAL; > + vdpa_dev = dev->vdpa_dev; > + if (vdpa_dev == NULL) > + return -ENODEV; > > if (!(dev->features & (1ULL << VIRTIO_F_VERSION_1)) || > !(dev->features & (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) || > @@ -2977,10 +2969,6 @@ int rte_vhost_host_notifier_ctrl(int vid, bool enable) > (1ULL << VHOST_USER_PROTOCOL_F_HOST_NOTIFIER))) > return -ENOTSUP; > > - vdpa_dev = rte_vdpa_get_device(did); > - if (!vdpa_dev) > - return -ENODEV; > - > RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_vfio_device_fd, -ENOTSUP); > RTE_FUNC_PTR_OR_ERR_RET(vdpa_dev->ops->get_notify_area, -ENOTSUP); > > Acked-by: Adrián Moreno -- Adrián Moreno