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 C6AB442A9D; Tue, 9 May 2023 07:29:23 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9B480410FA; Tue, 9 May 2023 07:29:23 +0200 (CEST) Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by mails.dpdk.org (Postfix) with ESMTP id 3E925410D7 for ; Tue, 9 May 2023 07:29:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683610161; x=1715146161; h=from:to:subject:date:message-id:references:in-reply-to: content-transfer-encoding:mime-version; bh=1HUOlAOGBra8VUQ0GgoTNjAoZYZWV/smJe85ji/AU4g=; b=nCks60lBnKjEpnEJUHg4B9JrVXFZIIrMPB4bqLFV+/0NOpk6BuITYIYP Lpypd+ykoatcDIFw64k82f4O+UK3t85FGV65Gs87Q4m+tWMlblJ2BiGcQ HQ0j53rYor89rQ8TrU0oaRlehopyI6LZKoLWT7t3W+0Jq13X+0NrrCRFH aVB5LNz4MRtnkr67ZC/WU+XFFCYwrQE4Ekx2vxpGtq7OOhLB6h/HhvpAz A+u4+XR+E1WK6ocAiGKZGKYfWuofmW8QnGX9dpQbZxdJLlIFcKYIpjpdQ Yn4/W2iY7iSlw5pEl8A626x1QQ79p74TPXJBCzWjaFuAsG1BSu9fClg2L A==; X-IronPort-AV: E=McAfee;i="6600,9927,10704"; a="329434327" X-IronPort-AV: E=Sophos;i="5.99,261,1677571200"; d="scan'208";a="329434327" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 May 2023 22:29:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10704"; a="729337225" X-IronPort-AV: E=Sophos;i="5.99,261,1677571200"; d="scan'208";a="729337225" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga008.jf.intel.com with ESMTP; 08 May 2023 22:29:19 -0700 Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 8 May 2023 22:29:19 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Mon, 8 May 2023 22:29:19 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23 via Frontend Transport; Mon, 8 May 2023 22:29:19 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.168) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.23; Mon, 8 May 2023 22:29:18 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lN8vmO1tFxZ/dZ3HqnTqBLFabQcvTLG/gHHbMw7nrGTkJnZKN+fHizrCpFJrxvsaozrs9SzEnOQEDMie9LI5NZAXWwIkdxh5PHWYXw+yCAnhSPVG9JWxfYisBnlxrtPyoJpxYeAXIjR5IjgzwrPRRCyo+tBmwr7yYzgROAgrcDr6GjT8afxwTLsv/p/1q5fZf8gTT3tlEAwNIGnjh8+SebZ8bnaw4UuLNGllUP/XTBPUDazn7eLYzKhf2kyBB7dExdGWt6qtfABPYDBoeLt9MIkvPZvuYBHqDSuyNdbF4fAZDg2PsqMmNs91fjvPafWRKVurRHmmg34f4gKokNUhKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=gqzjo3psX1B+YCnckCrMaDXzGO8/akwKUaSeCmvjJek=; b=glw8pt9pSFMXPOZndAjifWL1o4+AdgsTKYfzZAgg80da3pGLjgfh3kHVbl/cDEoza3b3jDljrsCQxXamh8wvSm2Koj3wtEXLgVZPsHPgPZOLkQFyPXTrQKYp9z7M3Qvfgk19JG2gifix6i0a3zn50VBUnuzSaqI59TT5Gd4vgU8Q+4Q85Y7a36yvLL0bErMQH46a9cMlh0cmLtiKJp8lpKM81/JkbtnfGegDNLshReWoAozYb6xIn3bQeAmmHMyxp6s12u0Clg5+VCI90MPBk5w+38lr4fxVYvutHDBJVIPhYbivvsz602pgf4bvhLHdoBckibi8zzCmia7Gccas/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from SN6PR11MB3504.namprd11.prod.outlook.com (2603:10b6:805:d0::17) by SJ2PR11MB8566.namprd11.prod.outlook.com (2603:10b6:a03:56e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.32; Tue, 9 May 2023 05:29:11 +0000 Received: from SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::5797:849:7a10:560d]) by SN6PR11MB3504.namprd11.prod.outlook.com ([fe80::5797:849:7a10:560d%6]) with mapi id 15.20.6363.032; Tue, 9 May 2023 05:29:10 +0000 From: "Xia, Chenbo" To: Maxime Coquelin , "dev@dpdk.org" , "david.marchand@redhat.com" , "mkp@redhat.com" , "fbl@redhat.com" , "jasowang@redhat.com" , "Liang, Cunming" , "Xie, Yongji" , "echaudro@redhat.com" , "eperezma@redhat.com" , "amorenoz@redhat.com" Subject: RE: [RFC 17/27] vhost: add control virtqueue support Thread-Topic: [RFC 17/27] vhost: add control virtqueue support Thread-Index: AQHZY+ehVg3YFkYNoEObvx8GO+Nr9q9LN26Q Date: Tue, 9 May 2023 05:29:10 +0000 Message-ID: References: <20230331154259.1447831-1-maxime.coquelin@redhat.com> <20230331154259.1447831-18-maxime.coquelin@redhat.com> In-Reply-To: <20230331154259.1447831-18-maxime.coquelin@redhat.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SN6PR11MB3504:EE_|SJ2PR11MB8566:EE_ x-ms-office365-filtering-correlation-id: 902d4e4a-451d-41fa-249e-08db504e5164 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: OESQOnXvRSr4rMk122jp399xFkBd6T82qDZdUTPErKAZ+L6iHAy5zNybxEilHmxopdzQvdK9yUa1I2AsyJ6eCcs9zQtQ5Jip4PyC0yyj5VEy1FmjM4KLGvjCIwcZh00MqSOjJReNZqvp6slf509qys/6S6jtqah9VLOxeDdu101eEbTyZsZ00CARWOfmLs4qG/Dfqx/yK/BvEkrlHI4QfdX27BaiPGArR7sX21Nu2ZX2IH7JUYzLK7xjSN8kaCGrO6wK5qKFya2d7cXqDnIWNz4Wn3TXEKGbmEG3rZY4TSBxxopHiDfPHkKbszGoyHIaNYPqdPjTMuDkicxjTmxheC4EJ0QvgGS54VakV0ThEd//FmHPWSH+bJYbzquLjjW/p/czzLDrnY8NHB2MshBIXRQcHtCbzroWOYed3OzYpYVfgl4TRknDkp9fO3vLUOpbAGHZAlFSoS7BBdL+IiXZCz12Xt8wZmG1lquIc/xYPBxthhbgF75hqIqbvrIUvnXUaScNgEaBkkt0lSaWpmNLM07QoAfho7ubaY0npsw/XDdngvdsVQGAvdJCjhAn79vwkic84R2cLWZ63rxzertyMZw3BcRN6Uc+Ef7jUU1rtpfGPceN88sqjGGrM3vx4zbk0F99f4Hec7Z78Z9id44iFQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB3504.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(396003)(136003)(376002)(366004)(39860400002)(346002)(451199021)(66556008)(66446008)(64756008)(316002)(478600001)(76116006)(7696005)(66946007)(110136005)(86362001)(66476007)(33656002)(83380400001)(26005)(53546011)(6506007)(9686003)(52536014)(2906002)(71200400001)(5660300002)(41300700001)(7416002)(8936002)(8676002)(921005)(55016003)(82960400001)(38100700002)(122000001)(186003)(38070700005); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?qK0vu3nCW4ufX5gwvJMGtZLp6ABLYKNDrptUxH1KaxcsFrb70tFRXDNSKinG?= =?us-ascii?Q?P9m61tZxpUfK3D/pfCjQ4wpYidDLYnQSX/m2c5C+jq7kzj0/AssfGHPUHMlH?= =?us-ascii?Q?Hijl7IlUh1VWPuUHFnSBKuYeUJTYqKiokh9Pvznnd5R5QQTVe9ZV1yEzt+a2?= =?us-ascii?Q?Lj1IP9bdx31H1re4vlyBvK9mQxqL9ePUb/uRzaLTQIEnVuh6tRSR6u7KigRl?= =?us-ascii?Q?opaQhY9+Aah9V6+4NIAUDaYpIHWpugGxAh2RqpnTSv58DpootaWZF9BlgiJD?= =?us-ascii?Q?pH94o4JMbhRlDHYHsuTPnKIY0OLCyfMj/sK/chHzIRIyY9oMSz1RHzle6uzR?= =?us-ascii?Q?2aGHIssB/C+qUFndx2lD6DTslWdhVUs+mGlPyTDUheMCQ5RSu+LoKIdBf3De?= =?us-ascii?Q?dYu969a+NK3jRs5Bam2L0vE3Waq5jRyUwoZ8aGutzpIFSPhyR++g/rL+TWP2?= =?us-ascii?Q?9jGaO0G3LdORJHWPRIGiNbi3w8iv5VAfdRYIQYmnmVQGkS6pI9KCPAzBiNdL?= =?us-ascii?Q?gNnHrtHwEZXYbOTMBUSo8fscbtk26UfKCUgrV3XwHJOkwXdTDN30xuS0DHGi?= =?us-ascii?Q?q58awO0J/ilVahVyU4HpZT7790KgV/twkkBCq9MG4CoDoApIBKS5S2VJbhFS?= =?us-ascii?Q?qlwCACmEYiInfG9tbRXcbNcelCT9FPdJTy5pg7dKLb0FX3ypoddgCYkHCbE3?= =?us-ascii?Q?VIsIFzZ4lJOiu+gEpfiK4DM0lw1kzYV7DCm1y+Phrz5Z/MKiaaDMf7BmdrsF?= =?us-ascii?Q?zuIV1tr/OSQbuqELEUjS+/DHrIgSfB1lbH1Yop1/GQAe1j6fGeMEmOZPKW9r?= =?us-ascii?Q?FGrGxuW7qyVMe4OqNlkc/r5QEM1T51fP0mZVXZw/C1EV4EH0uD7SyExmcQ7W?= =?us-ascii?Q?nFK2haeKOfbbrhu2KrK0O30D4wgTQwSYf3C8HfLNZMduP24G6OsYZ0VlWMbx?= =?us-ascii?Q?/jCbt7G8JaomGtGUpbS9lXB1zuWZMxyAOodjvijsQU8aZg2bOh4l+Z2n+IET?= =?us-ascii?Q?ZR87/x5pmpEPwK7hhSCNBx/CrwjjJUvUseWgsyvJA52AMsVUTuP55Z1BBRLb?= =?us-ascii?Q?eetnjYuyuJ0BY+EoRA2rRJhmAoVDw+qIm/YXFq2XPknTveFgydaYDuVgZd3R?= =?us-ascii?Q?jnMCjHhHavyH/80hE7489khBTnWYFwdkOJUBPX6iJSq4l3JMq+VnuuvJfIvf?= =?us-ascii?Q?6Qe4TH8YNjms8DWleBtkxIj5YyyD3MdZbMjV5s9DKes5BOmcFubGpTqZffsL?= =?us-ascii?Q?WY4oeH8sNGECTi+GYDVA+5hKZW1FAjHt87LzB33jrRVOFezPg7eeiwBc0x71?= =?us-ascii?Q?6VLA5JIDbHxlj7UQkKSDUjNLcll6RojT8oOmRqZd15YXVujeTrK6/Np9OBse?= =?us-ascii?Q?JNkEhuGtUuyG0uQkV/yQBu6HS9diJDPFckBFGf5zlaccBJX+GQbnu4bgcF4q?= =?us-ascii?Q?KcRdtHDYxLSuSCpPhvj5UP5DzUJylRy/C5aFr5iMD2S1cM5zKLy3NXTvtvQn?= =?us-ascii?Q?39+ziQzIBIy3eRhrHV/2npnrW9Ld8P+A/OaZthr19ZY0Jb6mWNitN7kWYkKg?= =?us-ascii?Q?qxWjhmyVxpiIvVm3N8x83DWd/a3wISrHgQ/7+5oc?= Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB3504.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 902d4e4a-451d-41fa-249e-08db504e5164 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 May 2023 05:29:10.6095 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: j7YgRFcrNPFknJEM4v7tFeSQEZQSh4aTpHlf2uMqyMB44spp9JeGnt80y7VdYXjoaMzNA7g92Tku1RB37XwxcA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ2PR11MB8566 X-OriginatorOrg: intel.com 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 Hi Maxime, > -----Original Message----- > From: Maxime Coquelin > Sent: Friday, March 31, 2023 11:43 PM > To: dev@dpdk.org; david.marchand@redhat.com; Xia, Chenbo > ; mkp@redhat.com; fbl@redhat.com; > jasowang@redhat.com; Liang, Cunming ; Xie, Yongj= i > ; echaudro@redhat.com; eperezma@redhat.com; > amorenoz@redhat.com > Cc: Maxime Coquelin > Subject: [RFC 17/27] vhost: add control virtqueue support >=20 > In order to support multi-queue with VDUSE, having > control queue support in required. in -> is >=20 > This patch adds control queue implementation, it will be > used later when adding VDUSE support. Only split ring > layout is supported for now, packed ring support will be > added later. >=20 > Signed-off-by: Maxime Coquelin > --- > lib/vhost/meson.build | 1 + > lib/vhost/vhost.h | 2 + > lib/vhost/virtio_net_ctrl.c | 282 ++++++++++++++++++++++++++++++++++++ > lib/vhost/virtio_net_ctrl.h | 10 ++ > 4 files changed, 295 insertions(+) > create mode 100644 lib/vhost/virtio_net_ctrl.c > create mode 100644 lib/vhost/virtio_net_ctrl.h >=20 > diff --git a/lib/vhost/meson.build b/lib/vhost/meson.build > index 197a51d936..cdcd403df3 100644 > --- a/lib/vhost/meson.build > +++ b/lib/vhost/meson.build > @@ -28,6 +28,7 @@ sources =3D files( > 'vhost_crypto.c', > 'vhost_user.c', > 'virtio_net.c', > + 'virtio_net_ctrl.c', > ) > headers =3D files( > 'rte_vdpa.h', > diff --git a/lib/vhost/vhost.h b/lib/vhost/vhost.h > index 8f0875b4e2..76663aed24 100644 > --- a/lib/vhost/vhost.h > +++ b/lib/vhost/vhost.h > @@ -525,6 +525,8 @@ struct virtio_net { > int postcopy_ufd; > int postcopy_listening; >=20 > + struct vhost_virtqueue *cvq; > + > struct rte_vdpa_device *vdpa_dev; >=20 > /* context data for the external message handlers */ > diff --git a/lib/vhost/virtio_net_ctrl.c b/lib/vhost/virtio_net_ctrl.c > new file mode 100644 > index 0000000000..16ea63b42f > --- /dev/null > +++ b/lib/vhost/virtio_net_ctrl.c > @@ -0,0 +1,282 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (c) 2023 Red Hat, Inc. > + */ > + > +#undef RTE_ANNOTATE_LOCKS > + > +#include > +#include > +#include > + > +#include "vhost.h" > +#include "virtio_net_ctrl.h" > + > +struct virtio_net_ctrl { > + uint8_t class; > + uint8_t command; > + uint8_t command_data[]; > +}; > + > +struct virtio_net_ctrl_elem { > + struct virtio_net_ctrl *ctrl_req; > + uint16_t head_idx; > + uint16_t n_descs; > + uint8_t *desc_ack; > +}; > + > +static int > +virtio_net_ctrl_pop(struct virtio_net *dev, struct virtio_net_ctrl_elem > *ctrl_elem) > +{ > + struct vhost_virtqueue *cvq =3D dev->cvq; > + uint16_t avail_idx, desc_idx, n_descs =3D 0; > + uint64_t desc_len, desc_addr, desc_iova, data_len =3D 0; > + uint8_t *ctrl_req; > + struct vring_desc *descs; > + > + avail_idx =3D __atomic_load_n(&cvq->avail->idx, __ATOMIC_ACQUIRE); > + if (avail_idx =3D=3D cvq->last_avail_idx) { > + VHOST_LOG_CONFIG(dev->ifname, DEBUG, "Control queue empty\n"); > + return 0; > + } > + > + desc_idx =3D cvq->avail->ring[cvq->last_avail_idx]; > + if (desc_idx >=3D cvq->size) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Out of range desc index, > dropping\n"); > + goto err; > + } > + > + ctrl_elem->head_idx =3D desc_idx; > + > + if (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) { > + desc_len =3D cvq->desc[desc_idx].len; > + desc_iova =3D cvq->desc[desc_idx].addr; > + > + descs =3D (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, > cvq, > + desc_iova, &desc_len, VHOST_ACCESS_RO); > + if (!descs || desc_len !=3D cvq->desc[desc_idx].len) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to map ctrl > indirect descs\n"); > + goto err; > + } > + > + desc_idx =3D 0; > + } else { > + descs =3D cvq->desc; > + } > + > + while (1) { > + desc_len =3D descs[desc_idx].len; > + desc_iova =3D descs[desc_idx].addr; > + > + n_descs++; > + > + if (descs[desc_idx].flags & VRING_DESC_F_WRITE) { > + if (ctrl_elem->desc_ack) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, > + "Unexpected ctrl chain layout\n"); > + goto err; > + } > + > + if (desc_len !=3D sizeof(uint8_t)) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, > + "Invalid ack size for ctrl req, > dropping\n"); > + goto err; > + } > + > + ctrl_elem->desc_ack =3D (uint8_t > *)(uintptr_t)vhost_iova_to_vva(dev, cvq, > + desc_iova, &desc_len, VHOST_ACCESS_WO); > + if (!ctrl_elem->desc_ack || desc_len !=3D sizeof(uint8_t)) > { > + VHOST_LOG_CONFIG(dev->ifname, ERR, > + "Failed to map ctrl ack descriptor\n"); > + goto err; > + } > + } else { > + if (ctrl_elem->desc_ack) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, > + "Unexpected ctrl chain layout\n"); > + goto err; > + } > + > + data_len +=3D desc_len; > + } > + > + if (!(descs[desc_idx].flags & VRING_DESC_F_NEXT)) > + break; > + > + desc_idx =3D descs[desc_idx].next; > + } > + > + desc_idx =3D ctrl_elem->head_idx; > + > + if (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) > + ctrl_elem->n_descs =3D 1; > + else > + ctrl_elem->n_descs =3D n_descs; > + > + if (!ctrl_elem->desc_ack) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Missing ctrl ack > descriptor\n"); > + goto err; > + } > + > + if (data_len < sizeof(ctrl_elem->ctrl_req->class) + > sizeof(ctrl_elem->ctrl_req->command)) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Invalid control header > size\n"); > + goto err; > + } > + > + ctrl_elem->ctrl_req =3D malloc(data_len); > + if (!ctrl_elem->ctrl_req) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to alloc ctrl > request\n"); > + goto err; > + } > + > + ctrl_req =3D (uint8_t *)ctrl_elem->ctrl_req; > + > + if (cvq->desc[desc_idx].flags & VRING_DESC_F_INDIRECT) { > + desc_len =3D cvq->desc[desc_idx].len; > + desc_iova =3D cvq->desc[desc_idx].addr; > + > + descs =3D (struct vring_desc *)(uintptr_t)vhost_iova_to_vva(dev, > cvq, > + desc_iova, &desc_len, VHOST_ACCESS_RO); > + if (!descs || desc_len !=3D cvq->desc[desc_idx].len) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to map ctrl > indirect descs\n"); > + goto err; goto free_err? Thanks, Chenbo=20 > + } > + > + desc_idx =3D 0; > + } else { > + descs =3D cvq->desc; > + } > + > + while (!(descs[desc_idx].flags & VRING_DESC_F_WRITE)) { > + desc_len =3D descs[desc_idx].len; > + desc_iova =3D descs[desc_idx].addr; > + > + desc_addr =3D vhost_iova_to_vva(dev, cvq, desc_iova, &desc_len, > VHOST_ACCESS_RO); > + if (!desc_addr || desc_len < descs[desc_idx].len) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Failed to map ctrl > descriptor\n"); > + goto free_err; > + } > + > + memcpy(ctrl_req, (void *)(uintptr_t)desc_addr, desc_len); > + ctrl_req +=3D desc_len; > + > + if (!(descs[desc_idx].flags & VRING_DESC_F_NEXT)) > + break; > + > + desc_idx =3D descs[desc_idx].next; > + } > + > + cvq->last_avail_idx++; > + if (cvq->last_avail_idx >=3D cvq->size) > + cvq->last_avail_idx -=3D cvq->size; > + > + if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) > + vhost_avail_event(cvq) =3D cvq->last_avail_idx; > + > + return 1; > + > +free_err: > + free(ctrl_elem->ctrl_req); > +err: > + cvq->last_avail_idx++; > + if (cvq->last_avail_idx >=3D cvq->size) > + cvq->last_avail_idx -=3D cvq->size; > + > + if (dev->features & (1ULL << VIRTIO_RING_F_EVENT_IDX)) > + vhost_avail_event(cvq) =3D cvq->last_avail_idx; > + > + return -1; > +} > + > +static uint8_t > +virtio_net_ctrl_handle_req(struct virtio_net *dev, struct virtio_net_ctr= l > *ctrl_req) > +{ > + uint8_t ret =3D VIRTIO_NET_ERR; > + > + if (ctrl_req->class =3D=3D VIRTIO_NET_CTRL_MQ && > + ctrl_req->command =3D=3D VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET) { > + uint16_t queue_pairs; > + uint32_t i; > + > + queue_pairs =3D *(uint16_t *)(uintptr_t)ctrl_req->command_data; > + VHOST_LOG_CONFIG(dev->ifname, INFO, "Ctrl req: MQ %u queue > pairs\n", queue_pairs); > + ret =3D VIRTIO_NET_OK; > + > + for (i =3D 0; i < dev->nr_vring; i++) { > + struct vhost_virtqueue *vq =3D dev->virtqueue[i]; > + bool enable; > + > + if (vq =3D=3D dev->cvq) > + continue; > + > + if (i < queue_pairs * 2) > + enable =3D true; > + else > + enable =3D false; > + > + vq->enabled =3D enable; > + if (dev->notify_ops->vring_state_changed) > + dev->notify_ops->vring_state_changed(dev->vid, i, > enable); > + } > + } > + > + return ret; > +} > + > +static int > +virtio_net_ctrl_push(struct virtio_net *dev, struct virtio_net_ctrl_elem > *ctrl_elem) > +{ > + struct vhost_virtqueue *cvq =3D dev->cvq; > + struct vring_used_elem *used_elem; > + > + used_elem =3D &cvq->used->ring[cvq->last_used_idx]; > + used_elem->id =3D ctrl_elem->head_idx; > + used_elem->len =3D ctrl_elem->n_descs; > + > + cvq->last_used_idx++; > + if (cvq->last_used_idx >=3D cvq->size) > + cvq->last_used_idx -=3D cvq->size; > + > + __atomic_store_n(&cvq->used->idx, cvq->last_used_idx, > __ATOMIC_RELEASE); > + > + free(ctrl_elem->ctrl_req); > + > + return 0; > +} > + > +int > +virtio_net_ctrl_handle(struct virtio_net *dev) > +{ > + int ret =3D 0; > + > + if (dev->features & (1ULL << VIRTIO_F_RING_PACKED)) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "Packed ring not supported > yet\n"); > + return -1; > + } > + > + if (!dev->cvq) { > + VHOST_LOG_CONFIG(dev->ifname, ERR, "missing control queue\n"); > + return -1; > + } > + > + rte_spinlock_lock(&dev->cvq->access_lock); > + > + while (1) { > + struct virtio_net_ctrl_elem ctrl_elem; > + > + memset(&ctrl_elem, 0, sizeof(struct virtio_net_ctrl_elem)); > + > + ret =3D virtio_net_ctrl_pop(dev, &ctrl_elem); > + if (ret <=3D 0) > + break; > + > + *ctrl_elem.desc_ack =3D virtio_net_ctrl_handle_req(dev, > ctrl_elem.ctrl_req); > + > + ret =3D virtio_net_ctrl_push(dev, &ctrl_elem); > + if (ret < 0) > + break; > + } > + > + rte_spinlock_unlock(&dev->cvq->access_lock); > + > + return ret; > +} > diff --git a/lib/vhost/virtio_net_ctrl.h b/lib/vhost/virtio_net_ctrl.h > new file mode 100644 > index 0000000000..9a90f4b9da > --- /dev/null > +++ b/lib/vhost/virtio_net_ctrl.h > @@ -0,0 +1,10 @@ > +/* SPDX-License-Identifier: BSD-3-Clause > + * Copyright (c) 2023 Red Hat, Inc. > + */ > + > +#ifndef _VIRTIO_NET_CTRL_H > +#define _VIRTIO_NET_CTRL_H > + > +int virtio_net_ctrl_handle(struct virtio_net *dev); > + > +#endif > -- > 2.39.2