From patchwork Fri May 10 07:27:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wafer X-Patchwork-Id: 13660979 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B550CC25B4F for ; Fri, 10 May 2024 07:34:58 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s5Kli-0008V0-GF; Fri, 10 May 2024 03:34:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s5Kle-0008Us-Fh for qemu-devel@nongnu.org; Fri, 10 May 2024 03:34:10 -0400 Received: from mail-psaapc01on2132.outbound.protection.outlook.com ([40.107.255.132] helo=APC01-PSA-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s5Klb-0007j4-Lq for qemu-devel@nongnu.org; Fri, 10 May 2024 03:34:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FEbOMV2+Gm4XPydQy5L7MVbglPQKest3/KLG8b2CcABXZWdqQXuTJUqjcOFQTABN1+oEft5HjGBUwEdiAnxRbj9S9YqYMzycPF7JHzm0TloK3sEYsdUtag0Y5Oa7rj92mxJE6DcEbipGoSk3zUXSu1G4M7a4GYYFcJl0EUKxKnhJ1RBXXL/U+IxB1xrKlhEiH42qxF36jo72PFEL3Fa2POH9BNmSpWaSQzX83gJqqxph5fTviphuEizQF5+XwJ2m7Foq5X7d84b008bP71ipr3pybltrwIPbayV2F2yupa2GXoE7LfeSSeRpivlrrFjwFVz3X83VPQfzn6Usp/dYCw== 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=o4SyXo5LCdaGG7sh5s3v/VTZLyCIQcxRld+eOfuga2M=; b=bk/VOmcZEicZR+CugRpdJNUmOxN+7FqJdcpxPiNmSGbBPu9oCp/gLQh+jVITsWNT4bWZtm2N0EBq/4S6/yhInDDunkEmXUHgDmh8hBh2uLEGcVbS/5PMPN4PxEp7F9b9VWlGBjc0TTKSj66QK150UF53N+csRJDGmcXBM9AHX7XHyiZ6ac/sY1KLAmVRFDNjtz0XuuJDo7zFFd3pCTHNlRCv3pNHlsQRXhgTvFSnN8qktvibL8/mYP2yfCfby+AoDuk/aurIdLnS+jNHKaNrdk6mvqa/x5zzz8ZoDljGE0CAM74K5L2B6/JWJDwAwkIhW6SVAInIbJMyyoi+1mHfkw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=jaguarmicro.com; dmarc=pass action=none header.from=jaguarmicro.com; dkim=pass header.d=jaguarmicro.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jaguarmicro.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=o4SyXo5LCdaGG7sh5s3v/VTZLyCIQcxRld+eOfuga2M=; b=M7xWpXgDa4HCJIaATRrOfz0qWyyHSzItbHIYI6LeVwYnCwufQZcWwt7SVwYsvbg6Wxqhvs4awLtsjLCFcX/ids2SdqElJ3HW8unl7afYHoIZmsURKDo138n4lj70iBcuUobh6ojwCFehWhIX5ZMW8JOJ5l5CSiCUofj7Apsbb/evnchUPcmnbJM+UBQhnwcIzBr1ibFHRe0OoJMAxppZlOIoKDOBYUQnpcEJeXyVHbWAXIxBB+2yP9Dcdbh8XR1tV5NJjBx/PsHu/4KL/KavFXyHBzSpB++jXWPCY2DhNQkbtTKlH3HF0a0MYGplpjYS8N2BqykUCsGtszwh9/OD/g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=jaguarmicro.com; Received: from PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) by KL1PR06MB5969.apcprd06.prod.outlook.com (2603:1096:820:ca::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.45; Fri, 10 May 2024 07:28:58 +0000 Received: from PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::b6f8:321a:6742:9bde]) by PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::b6f8:321a:6742:9bde%6]) with mapi id 15.20.7544.048; Fri, 10 May 2024 07:28:56 +0000 From: Wafer To: eperezma@redhat.com, mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, angus.chen@jaguarmicro.com, Wafer Subject: [PATCH v3] hw/virtio: Fix obtain the buffer id from the last descriptor Date: Fri, 10 May 2024 15:27:53 +0800 Message-Id: <20240510072753.26158-2-wafer@jaguarmicro.com> X-Mailer: git-send-email 2.27.0 X-ClientProxiedBy: SI1PR02CA0009.apcprd02.prod.outlook.com (2603:1096:4:1f7::10) To PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4713:EE_|KL1PR06MB5969:EE_ X-MS-Office365-Filtering-Correlation-Id: 1661f4f7-6055-4bdb-d499-08dc70c2da0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|366007|52116005|1800799015|376005|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?OxIEHGactmBSnOSXXhQkPwJBs/mWPg9?= =?utf-8?q?c9Yz2pufY+d4Ry946dDqJdLZZJSzmvccGEFTpoBdr+GNg+cVbJYgkUYT+2eU+JpWs?= =?utf-8?q?5b7nQAF3ySuNSGejHHylH8kbSG2wGuUtXkhli5VvO/wefGeruajsecxRMyvjiUfyt?= =?utf-8?q?dF9sAMGcGrcY6S+GhfbKvGLrtCotJ0KjCdx+7foROrPG9tPdoDkSVLU90PhD93WI4?= =?utf-8?q?AoqD+Q7xyT6412dPn/XLLQJaAx0MUcAtoNnpKMR9uZiHZUhhTfOq5b7XilZ24viXI?= =?utf-8?q?rUF7KxLgiCrtCpUrWh0fOScykoOMgCgfs0HhEul7cs8aSlg3ASTJ8OuK48uFSSV0K?= =?utf-8?q?ZhiB7KvFMmE2J03JG5PBLLWx3G6CrHcpbkT0vFagPv+aAsUYFKqV2oh4TQ50aulB9?= =?utf-8?q?hNphYWs7QtmN8MPpgSSrcMlOG/yrGKsRIs/VmnLQfBT/uU5NdP20bzLEvbQ1zpr1W?= =?utf-8?q?6v0Moo+NF9fqm7/JremsNsQ7jIIytV70mXvzQRUTvQEwa0c/7drCJ1ijJtSgOtjYY?= =?utf-8?q?szg9a/SCTSUIIpUhRvvkm/OJPkRITb234In0Ti2UuGA8HWAlBItB9731USIl6u1wL?= =?utf-8?q?e6B5I5wJk414IFAwPffonuZchF6N7vUPG73t7tuvvJiu2tUaFTbJX0qDtFJLCGUd8?= =?utf-8?q?o6WTCD6etDuhvPhY7oYBKjPEDzzaln/ynkGEE5W2wUC8QpihKmXo0DGvjoXhRJPFj?= =?utf-8?q?BuHW29jOqOyJG/z1uciLZxOxXodTy73Lko/QvKR+/65EF2mZ6MbjQbuegYC99+r+B?= =?utf-8?q?7S/jUwjpUJGmQxPASCJxf0XKEXvpeQDq2fn8DNEkPvI3gTOFQS4G63tLk4KT8MaCn?= =?utf-8?q?evggLBadLdmD1EXEqu7iFEJhmeV6KPvGo4oG+b/t24JTAbry+A4j1nxXgJwWZ9bSE?= =?utf-8?q?mxsRm0hIj2ep0Zu4SUiWmiClWkARO9q2W5tJBiaqK7ydzM/ZO7MdBhKzzfNLmVM8u?= =?utf-8?q?AC21EO7eKM3bi9kXsSWGL2OaLW+3DPrt5koSeJTTwPuxT5fmelflrYPGAmOm7OX4Q?= =?utf-8?q?2uti1moGNdKG+tmgg+iv66SrlaWwkI62zEyVT8pJ6+XF3drr7SCcCQGShNpiHg7wQ?= =?utf-8?q?MgZCjVtx8Qf7ajCTdph+8LPXk6twsa1s6pvwAhqJo9Y97CHFrl5nvkhZ5169nnTJS?= =?utf-8?q?yjAET5fWKLtRmWwa77OPtlNHmnWI86fnChZwAiGCmoX25h9OVESu3SrLKq3uVXJe+?= =?utf-8?q?YwHZaW0xQwtzN63+RI5ISZbrz5v79DguEyFw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:PUZPR06MB4713.apcprd06.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(366007)(52116005)(1800799015)(376005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?01zjeAf66D8FZBhiyXLxFpuy/+sr?= =?utf-8?q?n+j+kXg+qsc5gufX3vK3nobs25feU5ZPq3eD45g55Yb6Mcy7N6nDFtv+FdVzlBPgH?= =?utf-8?q?gojM9lbTGz+R+HSJmEamuXXqGYs2GvHcsAcYI4l7Xo4DtvLDO56TlolyR3wWTfg6F?= =?utf-8?q?beZXCubX7iG57jwb0xAdUhzYd00rRxtm1sGz5KmRwZ/efJga9u/phq651zZ3JXGuk?= =?utf-8?q?7JJWl21CXyv3P/RvWz93xY9pPZVfavW3Ur8ZztkEqPezNzFUmZXTmhY6XFkTcHhPY?= =?utf-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8?q?dDFYyR/eiqWYrgJTqNGUnAY3n1BGJpMhHfk2GyKluCa+V5DbYoxMdJj0uSbQWh4YZ?= =?utf-8?q?YnLreLsRwQN/rzyHdLTD63j8uVyS5ALlVzYeHOvrRGSKXcwJKqzvHMe/17m4m77UT?= =?utf-8?q?U2r0qHPWSnZie26xro4riRsafqBDUxjxWnuafKkfAmc7r74fe10P/NkJizkPx+LFZ?= =?utf-8?q?h7blyAEPJkfoOVANtMCUModnNZbmv2GnbsQS0Mj13rQxuR3NaJq4J1qvpCaLPoT/h?= =?utf-8?q?uttaA2bZlC4RnXOgXLEbunbn3xCcbWJ198frkUyxCAO2Z6A4n192dHgkwIHEzE2ZU?= =?utf-8?q?nhngvoZyaOPgQeWWvDLOXSEfqLssHdXXOf66W0zvUkQs2PeCL8bo8uhxi2POCf5j0?= =?utf-8?q?fz1DrE0pRPM2?= X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1661f4f7-6055-4bdb-d499-08dc70c2da0e X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4713.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 May 2024 07:28:56.6490 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 1e45a5c2-d3e1-46b3-a0e6-c5ebf6d8ba7b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7Yf3hTW957Vu5icS2CMX6/oBuke3Al+7fJOx9U0PgI5sFLFHoR7HZiNyljbUEO/vXB6doK6uba0k3VYtoxLiDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: KL1PR06MB5969 Received-SPF: pass client-ip=40.107.255.132; envelope-from=wafer@jaguarmicro.com; helo=APC01-PSA-obe.outbound.protection.outlook.com X-Spam_score_int: -7 X-Spam_score: -0.8 X-Spam_bar: / X-Spam_report: (-0.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_BL_SPAMCOP_NET=1.347, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org The virtio-1.3 specification writes: 2.8.6 Next Flag: Descriptor Chaining Buffer ID is included in the last descriptor in the list. If the feature (_F_INDIRECT_DESC) has been negotiated, install only one descriptor in the virtqueue. Therefor the buffer id should be obtained from the first descriptor. In descriptor chaining scenarios, the buffer id should be obtained from the last descriptor. Fixes: 86044b24e8 ("virtio: basic packed virtqueue support") Signed-off-by: Wafer Reviewed-by: Jason Wang Reviewed-by: Eugenio PĂ©rez Acked-by: Jason Wang --- Changes in v3: - Add Acked-by Jason Wang Changes in v2: - Use Jason suggestion: Move the code out of the loop. --- hw/virtio/virtio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 871674f9be..e9e8447878 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1744,6 +1744,11 @@ static void *virtqueue_packed_pop(VirtQueue *vq, size_t sz) &indirect_desc_cache); } while (rc == VIRTQUEUE_READ_DESC_MORE); + if (desc_cache != &indirect_desc_cache) { + /* Buffer ID is included in the last descriptor in the list. */ + id = desc.id; + } + /* Now copy what we have collected and mapped */ elem = virtqueue_alloc_element(sz, out_num, in_num); for (i = 0; i < out_num; i++) {