From patchwork Thu Apr 4 16:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wafer X-Patchwork-Id: 13618081 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 8335FCD1292 for ; Thu, 4 Apr 2024 17:03:57 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rsQUG-0004KF-8V; Thu, 04 Apr 2024 13:02:52 -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 1rsQUC-0004JY-Su for qemu-devel@nongnu.org; Thu, 04 Apr 2024 13:02:49 -0400 Received: from mail-tyzapc01on2117.outbound.protection.outlook.com ([40.107.117.117] helo=APC01-TYZ-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 1rsQU6-0000eN-8U for qemu-devel@nongnu.org; Thu, 04 Apr 2024 13:02:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNKoniCAVus1jTG/qsw1fAGQfv3BX0VvntJc65IgFi1y4Nm7lGeMbY4KxH/Gwe/+yfDqeaWBLjry2UfQWzjtr3c48FWgsokFkaTqcC9CNz5rbBf0MQdBEZAiDARsjJq1Sq/EBcky1GzeePT3rShHP9ZuZuuairx9T6iXrG0hQye2XYxM0enROSYVqoUVNaujhe5wHzvG+nLyf2MIqC09sf+EMziCr6G036TjYFszpaSV6lh21dRZCu+FIkcZCjJj32v0ITxARry/s+eJ8Xczo6kKpVj/fbD1Ea6NEUT0xdEjHEt4ug1knozhIhW7/0Wkg94SlfdUTo+l4NmGPGjRuQ== 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=YwDzHiCDBH2brPtN142TsURvVfW3NodchY7UKIQDcD0=; b=fxQck9xCNJ7xnbn/wCkLc9sxjOI9rMEbgM+B6dY2XMucBxtFm8Wn9gsYJ57XaRkDGc0BF0aj3Qe81jlcAjWKO3YOIMOhP//r9bNL+ss1qOGVY/Xm51h+r5+DcM349EydC9w4dY89kDRolPGvDYLrD0m1oVW1FIow1cniUMoiZLbofdA6v3vRoQVB9bTBiCgjcSylU/kDLZb4clbViqm3zE4UnUP2T5NAzLpsm8hsBtaS5+xgTQZvp2Xi6AP2HE7++UGVxzEfQLPFcL24+MQBjuQEgR6s1sHaqEyNb5dHHPqsMxIyH0fnz8FeGHrYZ0L7N1P1ziGgj4eVtxdbU1v9oQ== 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=YwDzHiCDBH2brPtN142TsURvVfW3NodchY7UKIQDcD0=; b=clWh3XsFXN2nt1KzvZkVZxiOGAmbr79cTy6cB99kf2zJa7ZnvSwS7K9R215jzhmS6STZpgP6FOOK7/SQhY+fXGX4uHkvbHlj5Sm5HJ5WygzDNGOGVugUSoEbCUdNwtpTrYagq0mzrmWbo5YMGJJvYjEHnhmLm9Vf/wlKGpx7iCNYN6FqNmBo3a7kwSK31pC+3AWNQcQsQo1FD5IzsxtQKIiiitBV3vuD0tytdks7YeYFPX9Ov5ch59I6sogUhonQLiUG9CftyRgGkCfLytwNKNgDe4qyIUXPw/6I+KiDOECdfeNpbw85XnBst9MOkC4CSKj79gZRynGATszlCP+oCg== Received: from PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) by TYZPR06MB6325.apcprd06.prod.outlook.com (2603:1096:400:419::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Thu, 4 Apr 2024 16:57:31 +0000 Received: from PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::807:eccb:cfd5:e6b5]) by PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::807:eccb:cfd5:e6b5%3]) with mapi id 15.20.7409.042; Thu, 4 Apr 2024 16:57:30 +0000 From: Wafer To: mst@redhat.com, jasowang@redhat.com Cc: qemu-devel@nongnu.org, angus.chen@jaguarmicro.com, Wafer Subject: [PATCH v2] hw/virtio: Fix packed virtqueue flush used_idx Date: Fri, 5 Apr 2024 00:57:06 +0800 Message-Id: <20240404165706.23338-2-wafer@jaguarmicro.com> X-Mailer: git-send-email 2.27.0 X-ClientProxiedBy: SI2PR02CA0025.apcprd02.prod.outlook.com (2603:1096:4:195::21) To PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4713:EE_|TYZPR06MB6325:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NMyfZUqvqz+hCkz0f6Fd9HRz9XFnNN34OKOZ9rEIerDenOeAjp6F0YILVdUwAGqV5SIrpg8pP8wpfVujkKMKbTig5U+MSKOwcvsFyRyKFJw0uXiBQgXJoWODpF+u9EJZxJ3IHM0Hyk4bkYcdGIxOyQZXT6y6MmrrHpycAFd6sb46U2kQu19QQxp/xV0x2vr1IH4LSDDa1jdLI4QCpSQEAlA2JA823huEY3syfiqd8WCWwvOcGZDUYuTVwCEY1ECn3zEQwF15zvWI2O13DTgy0xlvH+cZsktxaEPuy2orq8lUqY4NAGc1fNaE02aDqsaa1CAXVGSh74oKH5MZo9NhyLnuh3Y6Wsk+ZfSluMor4Fgz/36mjPIcoupFKFX9TfBVtzV/3ck8CEdFyLSt7RmgIuPgMQWeACLCShygxrIJGiCwyY2POik9M7Fkd3BO3nvLSXgXkIFigCsQ6/A023Edj3LRKa9g3Uf6kVKYFY50YWrLoyttS05nAdiHgnd1PdAR5rnaFtzM++X6DzSfb7sACxgUySSZaXNMBG+gVf2RnRkneu3rTJ2quAC9GPt+El3+2FL//m+c1F88w8rIOAr6ZZm1AY90jzdL/IVUHjT0twNI9qfeA5GmyFXx6NIjCXXKqhC26fVeJnquD2AOnEYQJNa+GizkvbJ9rMCuoOXff3cFI/nvW2Vk+dRImXy6H2HeRenT7308w6I69fKh7SLgSmYvG8dsgzlJYSV63nraSf4= 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)(366007)(376005)(38350700005); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uCEpaxEDKTz0739v/mciqejdS42OAp/Z0jmEqmVRmDA3kRcZsfYlkqBq2or3UuIuP2Ahum1vc/UikVFZMek1GAw2IJGqorIo3/yqckcXfPeOcBZMhfa6Sj0rDH41qnBRAsf2TFdq2QF8ynvPqxfxv+FkDAC37jcptE5qr96I3iEmhgwY1aPKczmXORVS1uD3oTklioa3IbJG9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z8G+7tQQXzVeKPw2lEO3PgLwxea3542nGgV5HY6l1hUPG+GWuQjZFluB24BXZEoycsbWCf+uRBg0D6spLrD00VB6xMUF84VwnXxTNYF/aRrir+JrDAYMK6u0HQ07H4N0F3hdQl6KgxKCsCljpcMvci5zKaQ74NiRdspE4qXKVnXFMPaFbLuTNoTqEq+AFw72ly088FaP3Z9g2a5PTW0iD4IlxGpx3FO3X4w2ceAN5+FPMm+Uk/yo72uaxC4rffOtHPqjtykUkn/mKqO+doMHl+J7Bacy4Cd5SDLp1PkqoztK0w1YO3Lt+VLTgULcdl/1l6mvHggvdX5229A1J7DwsgV/CMC2nA== X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: a6db98aa-b195-49da-e894-08dc54c850e3 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4713.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Apr 2024 16:57:30.8717 (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: cdowz/GDuag9dd9FswODtH5iwj72gaTihDWlQ86pUvH2aDfL2iV12DTRINQO/7s/UlJglmZcMjHMvSTTJ87eMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR06MB6325 Received-SPF: pass client-ip=40.107.117.117; envelope-from=wafer@jaguarmicro.com; helo=APC01-TYZ-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, RCVD_IN_MSPIKE_H2=-0.001, 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 If a virtio-net device has the VIRTIO_NET_F_MRG_RXBUF feature but not the VIRTIO_RING_F_INDIRECT_DESC feature, 'VirtIONetQueue->rx_vq' will use the merge feature to store data in multiple 'elems'. The 'num_buffers' in the virtio header indicates how many elements are merged. If the value of 'num_buffers' is greater than 1, all the merged elements will be filled into the descriptor ring. The 'idx' of the elements should be the value of 'vq->used_idx' plus 'ndescs'. Signed-off-by: Wafer Acked-by: Eugenio PĂ©rez --- Changes in v2: - Clarify more in commit message; --- hw/virtio/virtio.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index fb6b4ccd83..cab5832cac 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -957,12 +957,20 @@ static void virtqueue_packed_flush(VirtQueue *vq, unsigned int count) return; } + /* + * For indirect element's 'ndescs' is 1. + * For all other elemment's 'ndescs' is the + * number of descriptors chained by NEXT (as set in virtqueue_packed_pop). + * So When the 'elem' be filled into the descriptor ring, + * The 'idx' of this 'elem' shall be + * the value of 'vq->used_idx' plus the 'ndescs'. + */ + ndescs += vq->used_elems[0].ndescs; for (i = 1; i < count; i++) { - virtqueue_packed_fill_desc(vq, &vq->used_elems[i], i, false); + virtqueue_packed_fill_desc(vq, &vq->used_elems[i], ndescs, false); ndescs += vq->used_elems[i].ndescs; } virtqueue_packed_fill_desc(vq, &vq->used_elems[0], 0, true); - ndescs += vq->used_elems[0].ndescs; vq->inuse -= ndescs; vq->used_idx += ndescs;