From patchwork Thu May 9 11:45:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wafer X-Patchwork-Id: 13659671 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 408E4C10F1A for ; Thu, 9 May 2024 11:48:07 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s52F0-0006tv-An; Thu, 09 May 2024 07:47: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 1s52Et-0006gq-NW for qemu-devel@nongnu.org; Thu, 09 May 2024 07:47:07 -0400 Received: from mail-psaapc01on2070e.outbound.protection.outlook.com ([2a01:111:f400:feae::70e] 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 1s52El-00007e-JI for qemu-devel@nongnu.org; Thu, 09 May 2024 07:47:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VV7GSk+Cdffec0tj/B5TsZZ3yXWkRp+T86FL8vWZn+IoISDnfjOqwgAfk/qjG02GAl9oH1xEbWrDjAIh41iU4KmZHRaIrP+V0iLc9t6itOMTpexRASoEGjnSC3/9mUm2DByyObBznT96d7z8TPwKPZ6i1O77X3beKCJEoBmvxJXYRdY6ujaOsioqkoeODHRUgY2aaANAl00fUDqqv6IGT7gQL3j5JCm706dDqBsOVWdb6KxuEaoiK3vQCedC7bmAxlBvlYMO16cgFxd6QBA0aBagCaCb/PH41CQSBD1QYGzMTinUJ1vLp1QOo947lrIZPZdPfJXIOGlXZyXvs7mayw== 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=X2xE4pfdPjPOAxTkSHWMYb7NOTXwUEBRAu7ZG5NBDnk=; b=Vd2Hv4nUWghVzxbZuTgNf84CZ6fm6iGDQQ4zq/F6ZeKJF6/FsyiXP4BInRZI3kKdk0ZaBEUbZ4pH3t7mo8N+VaVjw/g5ZvSfESuBWKkh/Y3JntFsEBVF8vrbYTbuEAOpWMpgMlJc13wcB5cgwPkx2r1L0k1XXfogHq4vEu+rjZs+tskNTqZ7qe8ve7I04t34zKZ69TJBlz9xcyKBJHSndGfRrw9mA6BcDu6C9tF0k3u7qVsLlPuIRFesKlvjhPT7fiZQw345cFvBuGg57ZdpUFVKguxxv90QZ5b3WpmKan8qZT01xzBnGJWW29UN/3FFI0UxLfn/WvkEG+wbEGqMqQ== 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=X2xE4pfdPjPOAxTkSHWMYb7NOTXwUEBRAu7ZG5NBDnk=; b=FrU1irh/7Lq9CRTkb1h/nUizTTmDfizWJDoV9qQW7kkhLirQMsqxBS6v627yvZ+RuaB4CS7nJW+fAM3Im/sMeNEOO2Ml58OmorPKWjf2WT1ELUS4toWGIGGZFe8I2Ez8DhR4FUKXA6avKObem1h1rqxIjo8fMnOlCNWIYa3bQyZbGKwWVvYYtuzfeS0aggpW6sEeMIlk8M8EBr6Fm/54OCibq+8i3CVSv0LRGnh1D/6UuAc9RvDLcjvFSGOr+V2luou7cOJx1P/uFzggDrTahK+wyS8w6oRGWwzZJEz9O6B+u3PQdwengSq17t6rXypHiHWAAiIAA5Ek2y0joAYkSA== 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 JH0PR06MB6511.apcprd06.prod.outlook.com (2603:1096:990:34::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.47; Thu, 9 May 2024 11:46:52 +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.046; Thu, 9 May 2024 11:46:52 +0000 From: Wafer To: mst@redhat.com Cc: eperezma@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org, angus.chen@jaguarmicro.com, Wafer Subject: [PATCH v2] hw/virtio: Fix obtain the buffer id from the last descriptor Date: Thu, 9 May 2024 19:45:52 +0800 Message-Id: <20240509114552.11525-2-wafer@jaguarmicro.com> X-Mailer: git-send-email 2.27.0 X-ClientProxiedBy: SI2PR01CA0026.apcprd01.prod.exchangelabs.com (2603:1096:4:192::16) To PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4713:EE_|JH0PR06MB6511:EE_ X-MS-Office365-Filtering-Correlation-Id: 72240c3f-eaf1-4b02-f5e4-08dc701db7f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230031|1800799015|52116005|376005|366007|38350700005; X-Microsoft-Antispam-Message-Info: =?utf-8?q?aJJvQHyKRUIj1kYbGkoZaIkavfuadba?= =?utf-8?q?NFDd3UKCbdsi+ZN5OgOxbC4AUkqBAnwDjv+GSccU0acD9tiI9+7C+0CYRnXDpabh9?= =?utf-8?q?60qxBUqIkgNUUDNWOFo5NbEoTwuNPq+PNzCqSAH8xe98USDBTVg5euVoSTfkfIEhe?= =?utf-8?q?PiR5Q7PdsEF2mentrSHQf6gEHiYvNE9A/nl4NUndtkLoHFS/e3KJh5iowhF/AdizH?= =?utf-8?q?gVSCaVfOM2+5yYu5fe4B3i589WWCpT8EJ66xluLVAIxxBqII3ZOlYc6mNlQ+vNAAW?= =?utf-8?q?ArQPhDAq4kOWukds6Z4jvq42IcIFXkj8taVBBhPETHjtVtKFqsUR151LQmZFI73nN?= =?utf-8?q?v5jR9Ym1MF/JtbNrPl9sKvp1VNFOphMP/ijoIW344cwpHldVxM8eFIVVUOYY2gfKA?= =?utf-8?q?NL7F9ONU/DIzXC5fUrLqG7r2zFfDn/D6VPen1edOKGk1DzOQIfve0lIqZ66ElNfb7?= =?utf-8?q?MD6J1na+yGpH58r48AfPWWPVu9MtrbA02FrYamWSoTvOAIPlI4NmSe0w9YnFtHkGi?= =?utf-8?q?XGxUfOnqzueDumq7vURfYbfnFWYv7VeeIIBGFARshRVTskSzajeuPxKI6r4mHRgIR?= =?utf-8?q?yKjxGmbIKjNGvnWZ60pR/kvklDfHfFKt6sRCtl9HHmjUVqQbc1dGhH15h8mjnkedH?= =?utf-8?q?KXkTwhhrOXKB/MHzuOsOMJj0Q/GXM0KP9fxxkd4XVAxqVWKIgdXVE+k4yAXYjUjXf?= =?utf-8?q?7Ucak/vQ6J2nsf800VHCGDfywrrKW1Ne4Eos9xNd/6PH/o2YibzfpqiisZVRWeQoV?= =?utf-8?q?HVnkpJdBZq4Mt5mtDHXD9bXpmtvA5tKp9x7k/Yw3cvQVHGhoQqvBsf2XL08begA2e?= =?utf-8?q?Ukv0dE040wrCyrgPLV7SqCofJgEbQ+GYdHPNoVW5w/aREpCbIHnjvBcOrAKDJXupL?= =?utf-8?q?FZscbGhhwvO3Vt3H1FbLnb0Jzdz9UENELjskz/wJiEuDcLW2heiNGuFZRc1G4Omlk?= =?utf-8?q?LLfkhN8jVdK9wZR2emKYUdtC5ekJO60QDxkbXDnsU5qjz+kaGzO3RnxMu+Ekqeqih?= =?utf-8?q?IZbiGKs9rwdaiNH9FK6XvtoTMe540dq7va2TRXfkW9xtx66dG6zqms98OHrr24nrF?= =?utf-8?q?OSreiWGOU5ShscMpz9DF4yHAuAiuv/QSSnFap+/T4AiKDbjCE5QeRSBQNhZTeoppK?= =?utf-8?q?F7dSDKKLorbjXGvDGZ1e7dY/S+UxRffiz/lSIR+w+Cag6v9SfrYvwK6RpiTJEVdCF?= =?utf-8?q?bw3t/pswiONvaDge2Lc3cZriQY3X/laOgy2Q=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)(1800799015)(52116005)(376005)(366007)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?URwgKfguV5t+Nl09Uc0qMvCRq8UG?= =?utf-8?q?nahBV7JTp3jQcHfL0lEyY6XO614t5VLwelekjhDVOIIsQVKoau2tUd2NwbFqxaV0z?= =?utf-8?q?gFoRJwWkXKdaJosnmMgjrTvcmHRAwdhbH21iePSRSR2+Cs7j3pCuFdGGn7pFIOAXC?= =?utf-8?q?k+HF5k8jr5iq6N98Ne4xFDZ++vE+53rUJVpKpdB7+5W1iKBcKGBc3sDfvSEQYjl6W?= =?utf-8?q?otCIDtWkyhGJj//Pg437Zxa9aIFL++3Xl7VsoiocMqQlR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ANppB1U9y5RWquDdDQ+Hxr2z?= =?utf-8?q?g6xUd30vIIRXU4vSVbH8g1KZJgOEpeZIdawQi2sEMNp82SArb6aXCMywH4fILAvrN?= =?utf-8?q?SosIpUqbvxMcbNKbdrONlb/jh8rYIVdU5X2moXdHRvAINjFSgaQdoQvNufLEQUdwW?= =?utf-8?q?zLAN/t+KUMuZc87qiJlr6gQq7UQcecj+NoJCgR4k9tqZBmba3T3sf5rE5zMGiHVR7?= =?utf-8?q?A5eFvKC/cjPIfD4iYgl6LR+kAiyhCiwHxGlysX0on+hPDQSUa4qT43CyasBGysWoc?= =?utf-8?q?nni/+1wo3WCNAsbGKWpriwgqgD7cjMyg0PlhViwXGChDUlr1WSv531JLKgZKehN/9?= =?utf-8?q?/d37K8dyZDyy/J4w37xzQ2cD7lGL4p/e0lRV2yh25CEojRtTUSZGGtimJnvz6bDys?= =?utf-8?q?fzKFv/9tlvZl?= X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72240c3f-eaf1-4b02-f5e4-08dc701db7f6 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4713.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 May 2024 11:46:52.4253 (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: 5RsJDrc8Rl+BThw+9SMsPn/+7qRpwrQj0ny9UkQy+j0pfDv2CYGk714PV+FRfqY3YsPeOSbQW+R7Dzkn5h7kFw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB6511 Received-SPF: pass client-ip=2a01:111:f400:feae::70e; envelope-from=wafer@jaguarmicro.com; helo=APC01-PSA-obe.outbound.protection.outlook.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, SPF_PASS=-0.001, T_SPF_HELO_TEMPERROR=0.01 autolearn=ham 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 --- 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++) {