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 34DBEA053A; Mon, 27 Jul 2020 15:14:07 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BB40C2C6E; Mon, 27 Jul 2020 15:14:05 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 193512B86 for ; Mon, 27 Jul 2020 15:14:03 +0200 (CEST) IronPort-SDR: GdUeAeWTRU2fN6wcAL3S60eLduJqGDhl9EuO1HWNkJOTyvynRk+W2qxPEH0BgqecgL1cLuSyoc uRa9Q7YaWOYg== X-IronPort-AV: E=McAfee;i="6000,8403,9694"; a="235871544" X-IronPort-AV: E=Sophos;i="5.75,402,1589266800"; d="scan'208";a="235871544" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jul 2020 06:14:03 -0700 IronPort-SDR: cSRdmX4p81IT2NLILaH2nq7XMAf1lsN2DTnj5YarVC4YcVQXcehMzfEBsxiieOpMFfrKEo2Osh NRksNJINSQiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,402,1589266800"; d="scan'208";a="393980778" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga001.fm.intel.com with ESMTP; 27 Jul 2020 06:14:03 -0700 Received: from fmsmsx153.amr.corp.intel.com (10.18.125.6) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 06:14:02 -0700 Received: from FMSEDG001.ED.cps.intel.com (10.1.192.133) by FMSMSX153.amr.corp.intel.com (10.18.125.6) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 06:14:02 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.109) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 27 Jul 2020 06:14:02 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZB+q6futwS3c36b3RJpXYqHDbvXFtWjkN1YW284Xa/lhQkQQ/gcBdcI3wiT/B28KAZcgQ5qPF9gM2sDu2vvGTlxJ/yGttsntIm8rxJC566YwJExH2K6MdkJ0R8+BUkY+MPs+75f/c9E7b0IuKYsY8G+eZVnBNRCmOk3q5dhOHtZUOrGvPzo9iG0zNCbxeCJ01KhZGKZGcF5L/lWdV2IuCKvyT52AspjJsByFkYDCGSLbB8s0kH1MR8LS/90Uov+KoZjC2Jh6jyhOQOCgAglOno3YK35HA3pSJX7DZbfUUnTasd27rb6phZXlxnCmC2GKgGq/xVjofKm+dy43HPirHA== 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-SenderADCheck; bh=znVI2Eze/QMJOnL0aGvxT2V3GuOMUgqfKXtL4eDb1D4=; b=E1acXMLJhvmp/jWf7huzY3CaA4adsPRy5M82zf/X69af/csMmodlLzNYo61Boz6d4WELm+PhTnMxl/ZRwFfzbNAlqZV5Z0ygqGTDm7zWbkWQa9wBqwxpu07gVVjVi9cvPTeLdrSlDWIFy6yUW1A+zpoHcuSA0tbVKOSCh+wSA2f6Kf/OkHJ50jz2brGSLf04/MkJ4yn5yqT386NwbluqHieJamLoVdqM44ZlkpBVAxZdzCDcjFDPO0F+uAvAywj0fYC3DIXlNeJocI7QP8l0BU1rXYFs22iZLW55GGFZpN7JC3+0Ya6kkFrbfYzlYaVyDcQygO11ytkzbZ3nzcJU5A== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=znVI2Eze/QMJOnL0aGvxT2V3GuOMUgqfKXtL4eDb1D4=; b=XE1I8fEUrB2kt5rns1QA2z6UXWtWYZ5oea3ieRP5cXXwWl3enhTioXAuw9W9zs/E1A2RPZi1DncELa/svIIMCqIqwN2BQsUXEBnDqUpVhj59uW3/KvDFIHNn2F32wKXbsJeHZLJmkd52bP23n8Hx7VvjR3/MND6o9IXiIa1H/QI= Received: from MN2PR11MB4063.namprd11.prod.outlook.com (2603:10b6:208:13f::22) by MN2PR11MB4143.namprd11.prod.outlook.com (2603:10b6:208:137::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.24; Mon, 27 Jul 2020 13:14:00 +0000 Received: from MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::b898:36f5:61cb:42ca]) by MN2PR11MB4063.namprd11.prod.outlook.com ([fe80::b898:36f5:61cb:42ca%7]) with mapi id 15.20.3216.033; Mon, 27 Jul 2020 13:14:00 +0000 From: "Xia, Chenbo" To: "Fu, Patrick" , "dev@dpdk.org" , "maxime.coquelin@redhat.com" Thread-Topic: [PATCH v3] vhost: fix async copy fail on multi-page buffers Thread-Index: AQHWY+A8JIiRNBuFW0u4jWlevREMBakbZq3Q Date: Mon, 27 Jul 2020 13:14:00 +0000 Message-ID: References: <20200720025242.3066787-1-patrick.fu@intel.com> <20200727063307.3703071-1-patrick.fu@intel.com> In-Reply-To: <20200727063307.3703071-1-patrick.fu@intel.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.2.0.6 authentication-results: intel.com; dkim=none (message not signed) header.d=none;intel.com; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.193] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8c9d700e-4523-4bb3-7544-08d8322eed64 x-ms-traffictypediagnostic: MN2PR11MB4143: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:983; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: woyTTs4vJHNwehKZFiq+23tWT7b+769aneD7ONeHOeHZXT3JzO/DCGGx8RvOVTMFvSXYFEmCvM8EZMZ/SEch6Th4z+0va1nIwuesQtATrqDYBRLcw8rylpe2v/GFW8zbuegchch8V77KiR8nd8WnXJFA7IWk1atEgqhZ7snkVXTcZcpxPq1zbHSPTimuPUnFSS9z92RJlarynZLjdeyCz3VOje4FcVrOFm4p8f4DuBNHSFFwE8VBYmNfR1rMNO/IR60WlmkgOr/imlAk+Bsj/UzphYLxGrF69SFHDl0tHjltzS2uhxmhHEzuEax9EOfraEWe8rrVZH5lBq5DJvxG7Q== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:MN2PR11MB4063.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(136003)(376002)(396003)(366004)(346002)(39860400002)(53546011)(6506007)(83380400001)(66476007)(86362001)(55016002)(8936002)(71200400001)(7696005)(66446008)(8676002)(33656002)(66556008)(64756008)(186003)(9686003)(5660300002)(478600001)(26005)(52536014)(76116006)(66946007)(110136005)(2906002)(316002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata: ImOqHqP17/WCBZFYw8Wcpf5amp6489cHWFb0lm+v4qXVQxuyH2dhSYkjhTqQZWFluZI9P1UiPVCsq8AjXqrO8DNglbtbr7XTUV8SOxCzuCoghqqMHWVL+zUcumyq9QYwUUBLU1M8SBgqop86sT7X4NAT6GsccOfm1LTzPBl4fei2P0aaRSVgIbE13qXB9ObhUJ8fou6VAoD0qgdww3AymQ1y5qp0A4S8C/A9+AKUwrk+eZJ20GpIdVRJo+F6eW6yEJe4AOfE+Rfq2IOiD/Bb5Gj4zGtElThucK7GqblA8H7boZ+IKess/iEW6Twid0lTx+TKa2u7XpAGAYvNgE7pgYbYNXnVNctdESoqPnnec8WuE1pnhVBA7fM3xylS2H+Apt5QoePuLlVTCav6QWIXMuiAdRWfnly/JNIjW/G0u0zEIdOy1EqZC6PEIzv9JFesl3q+sR8wDPdCA5SKueWpgMJGxqwqbO43ZmHAimfr63HJDVjSHfXxLALJ1bY19Yv2 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: MN2PR11MB4063.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c9d700e-4523-4bb3-7544-08d8322eed64 X-MS-Exchange-CrossTenant-originalarrivaltime: 27 Jul 2020 13:14:00.3044 (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: VBC31bwy2BkwvJMTqBGXkpLdVesMvVLUMIabcYuo9zeTMWoB8bE4SWlnTop4uZ1CT9GZRIh+plRpb6fytd6UOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR11MB4143 X-OriginatorOrg: intel.com Subject: Re: [dpdk-dev] [PATCH v3] vhost: fix async copy fail on multi-page buffers 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" Hi Patrick, > -----Original Message----- > From: Fu, Patrick > Sent: Monday, July 27, 2020 2:33 PM > To: dev@dpdk.org; maxime.coquelin@redhat.com; Xia, Chenbo > > Cc: Fu, Patrick > Subject: [PATCH v3] vhost: fix async copy fail on multi-page buffers >=20 > From: Patrick Fu >=20 > Async copy fails when single ring buffer vector is splited on multiple ph= ysical > pages. This happens because current hpa address translation function does= n't > handle multi-page buffers. A new gpa to hpa address conversion function, = which > returns the hpa on the first hitting host pages, is implemented in this p= atch. > Async data path recursively calls this new function to construct a multi-= segments > async copy descriptor for ring buffers crossing physical page boundaries. >=20 > Fixes: cd6760da1076 ("vhost: introduce async enqueue for split ring") >=20 > Signed-off-by: Patrick Fu > --- > v2: > - change commit message and title > - v1 patch used CPU to copy multi-page buffers; v2 patch split the copy = into > multiple async copy segments whenever possible >=20 > v3: > - added fixline >=20 > lib/librte_vhost/vhost.h | 50 +++++++++++++++++++++++++++++++++++ > lib/librte_vhost/virtio_net.c | 40 +++++++++++++++++----------- > 2 files changed, 75 insertions(+), 15 deletions(-) >=20 > diff --git a/lib/librte_vhost/vhost.h b/lib/librte_vhost/vhost.h index > 0f7212f88..05c202a57 100644 > --- a/lib/librte_vhost/vhost.h > +++ b/lib/librte_vhost/vhost.h > @@ -616,6 +616,56 @@ gpa_to_hpa(struct virtio_net *dev, uint64_t gpa, > uint64_t size) > return 0; > } >=20 > +static __rte_always_inline rte_iova_t > +gpa_to_first_hpa(struct virtio_net *dev, uint64_t gpa, > + uint64_t gpa_size, uint64_t *hpa_size) { > + uint32_t i; > + struct guest_page *page; > + struct guest_page key; > + > + *hpa_size =3D gpa_size; > + if (dev->nr_guest_pages >=3D VHOST_BINARY_SEARCH_THRESH) { > + key.guest_phys_addr =3D gpa & ~(dev->guest_pages[0].size - 1); > + page =3D bsearch(&key, dev->guest_pages, dev->nr_guest_pages, > + sizeof(struct guest_page), guest_page_addrcmp); > + if (page) { > + if (gpa + gpa_size <=3D > + page->guest_phys_addr + page->size) { > + return gpa - page->guest_phys_addr + > + page->host_phys_addr; > + } else if (gpa < page->guest_phys_addr + > + page->size) { > + *hpa_size =3D page->guest_phys_addr + > + page->size - gpa; > + return gpa - page->guest_phys_addr + > + page->host_phys_addr; > + } > + } > + } else { > + for (i =3D 0; i < dev->nr_guest_pages; i++) { > + page =3D &dev->guest_pages[i]; > + > + if (gpa >=3D page->guest_phys_addr) { > + if (gpa + gpa_size < Should the '<' be '<=3D' here? > + page->guest_phys_addr + page->size) { > + return gpa - page->guest_phys_addr + > + page->host_phys_addr; > + } else if (gpa < page->guest_phys_addr + > + page->size) { > + *hpa_size =3D page->guest_phys_addr + > + page->size - gpa; > + return gpa - page->guest_phys_addr + > + page->host_phys_addr; > + } > + } > + } > + } > + > + *hpa_size =3D 0; > + return 0; > +} > + > static __rte_always_inline uint64_t > hva_to_gpa(struct virtio_net *dev, uint64_t vva, uint64_t len) { diff -= -git > a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c index > 95a0bc19f..124a33a10 100644 > --- a/lib/librte_vhost/virtio_net.c > +++ b/lib/librte_vhost/virtio_net.c > @@ -980,6 +980,7 @@ async_mbuf_to_desc(struct virtio_net *dev, struct > vhost_virtqueue *vq, > struct batch_copy_elem *batch_copy =3D vq->batch_copy_elems; > struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr =3D NULL; > int error =3D 0; > + uint64_t mapped_len; >=20 > uint32_t tlen =3D 0; > int tvec_idx =3D 0; > @@ -1072,24 +1073,31 @@ async_mbuf_to_desc(struct virtio_net *dev, struct > vhost_virtqueue *vq, >=20 > cpy_len =3D RTE_MIN(buf_avail, mbuf_avail); >=20 > - if (unlikely(cpy_len >=3D cpy_threshold)) { > - hpa =3D (void *)(uintptr_t)gpa_to_hpa(dev, > - buf_iova + buf_offset, cpy_len); > + while (unlikely(cpy_len && cpy_len >=3D cpy_threshold)) { > + hpa =3D (void *)(uintptr_t)gpa_to_first_hpa(dev, > + buf_iova + buf_offset, > + cpy_len, &mapped_len); >=20 > - if (unlikely(!hpa)) { > - error =3D -1; > - goto out; > - } > + if (unlikely(!hpa || mapped_len < cpy_threshold)) > + break; >=20 > async_fill_vec(src_iovec + tvec_idx, > (void *)(uintptr_t)rte_pktmbuf_iova_offset(m, > - mbuf_offset), cpy_len); > + mbuf_offset), (size_t)mapped_len); >=20 > - async_fill_vec(dst_iovec + tvec_idx, hpa, cpy_len); > + async_fill_vec(dst_iovec + tvec_idx, > + hpa, (size_t)mapped_len); >=20 > - tlen +=3D cpy_len; > + tlen +=3D (uint32_t)mapped_len; > + cpy_len -=3D (uint32_t)mapped_len; > + mbuf_avail -=3D (uint32_t)mapped_len; > + mbuf_offset +=3D (uint32_t)mapped_len; > + buf_avail -=3D (uint32_t)mapped_len; > + buf_offset +=3D (uint32_t)mapped_len; Will it be ok we just transform the uint64_t to uint32_t here? What if mapped_len > MAX uint32_t ? Thanks! Chenbo > tvec_idx++; > - } else { > + } > + > + if (likely(cpy_len)) { > if (unlikely(vq->batch_copy_nb_elems >=3D vq->size)) { > rte_memcpy( > (void *)((uintptr_t)(buf_addr + buf_offset)), > @@ -1112,10 +1120,12 @@ async_mbuf_to_desc(struct virtio_net *dev, struct > vhost_virtqueue *vq, > } > } >=20 > - mbuf_avail -=3D cpy_len; > - mbuf_offset +=3D cpy_len; > - buf_avail -=3D cpy_len; > - buf_offset +=3D cpy_len; > + if (cpy_len) { > + mbuf_avail -=3D cpy_len; > + mbuf_offset +=3D cpy_len; > + buf_avail -=3D cpy_len; > + buf_offset +=3D cpy_len; > + } > } >=20 > out: > -- > 2.18.4