From nobody Sat Nov 23 15:13:40 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=jaguarmicro.com); dmarc=pass(p=quarantine dis=none) header.from=jaguarmicro.com ARC-Seal: i=2; a=rsa-sha256; t=1732241221; cv=pass; d=zohomail.com; s=zohoarc; b=VZOuYIKOY6qsNYgX3RtH5LWNYFLZKLZmak2wSv3KKV4Q6kTJ8BAf8GQzVPP40Lz7qu7lZImjiT6G0NuBGWOB03NM3cmveFXG93OsYgetONmAO6pWPO2Ug5M1XYpFoyul9g9y6SAfjCEywTuEDMG8xI+Sz7uY3tUaO4rBXyW/Ih0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732241221; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=mDRNaBhsdGNP7c+rFnvXi7rATKTb1Z6ndlel8sb1NIE=; b=FOb8g8B2/Lszk/ggfu1zjNKSFMpAK2HqSsPwo1HU0XWRefjceNOaURsAnJbFobuU69ajlfde1OpHEGS79IvXP2pXNM0Lsn8Tt2DLhCwJxAGJkClQtfPbcdy6MUst65Wdw/fP1dAtukoqhQfE1zyLUU0S1F3zT5tQzZVb2N3XYTM= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=jaguarmicro.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1732241221341918.2211646256153; Thu, 21 Nov 2024 18:07:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tEJ4H-00019D-FP; Thu, 21 Nov 2024 21:06:45 -0500 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 1tEJ4D-00018v-2j for qemu-devel@nongnu.org; Thu, 21 Nov 2024 21:06:42 -0500 Received: from mail-psaapc01on2105.outbound.protection.outlook.com ([40.107.255.105] 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 1tEJ48-0005qb-PJ for qemu-devel@nongnu.org; Thu, 21 Nov 2024 21:06:39 -0500 Received: from PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) by SEZPR06MB5198.apcprd06.prod.outlook.com (2603:1096:101:72::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8182.16; Fri, 22 Nov 2024 02:01:14 +0000 Received: from PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::b6f8:321a:6742:9bde]) by PUZPR06MB4713.apcprd06.prod.outlook.com ([fe80::b6f8:321a:6742:9bde%5]) with mapi id 15.20.8182.016; Fri, 22 Nov 2024 02:01:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=N8x+JqtR2/neakaq6RxQPBbD/Q/cD2Yx8bEi2rAbxz4cA3ZMuiioReca+i54/9p+374oGgnJeaOBfopIzFPa6TzWxfQdNE/nqESsKvADErf7gYPPuMAbtgCabLvUIsGl5RphyZX0Rh10fTHElxlBmJ4GhpwYsK4yP0GhTx7jYTZFVhp6coa9utujuxuMUjclQe/zYjjnjCyIpLJkaoNNaPmB+EJNnNW+1BEGfFt5QdHDL8Hahj1DLRhWBKd3MzdERQsdRErQCqj1neSfLMnfqMsIzDXlAfgvVPwXm0Z+BsRiYTWBR++9XXvK1cCfxk8u55iBs+MDjqMZLImTWN7pbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=mDRNaBhsdGNP7c+rFnvXi7rATKTb1Z6ndlel8sb1NIE=; b=H/UP0/NR1KDygi4LAn1pyBGZfnhY1SO/4kD07jcUf8tzAodIUpTpBILH3FNYQ1gXjC59siV4+Co6aYaawIYQwvMOlGDhu3OLc0tp8Ph3cI+Jwuwye0r/39FufFuagWK28j4377aLneVk/cEGyTTgytsjm7LZ5H7dEOzo2hgi2HKWLo0oH1sVhiXMJNqclBdJCXn9WdHTpPxsQCj2uSeOnOHO/trsE9ZPMIXlVETUYwINAvEDPEiVA3zeb3/WTyhGwuzoAot8p8IyJCITtKUhokImUY7d55SITN+EabRDq25mZ4jgcyP5UyRrAMR+3IiaJuzmdAvTU9hr0/t+pP8kXQ== 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=mDRNaBhsdGNP7c+rFnvXi7rATKTb1Z6ndlel8sb1NIE=; b=AThLQV1q7GHQ3T+Jv+BfZKXKYRay9+yNdpLzBTAB+3/lC8mjo12JdAER9FMKmogdKTHLzmjMASJ8qQUmxPhG5sox25iXxNAZwQPNVxGNepDPjyVFqTSa15dSck2Qi9Uw4kgmDQnomn3/ppgcKSihVj+E4j6ivjZpoZVEI8H869PJBBKry3OWg4xv44m2eMa6ZMOVIk2+FBaSif8AOgzr3hbFghlHl6TYhEsPRoAqYk9QEWOqovKBpUIikwGEIMCmALMlWOn0/AAGJIMB8tcbzVStgIs8PRg5ZfQTBgDP7vkzFw/btgYkwkznHhbMVqrNmZrzFlAtSU//9rttiT1pfw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=jaguarmicro.com; From: Wafer To: mst@redhat.com, jasowang@redhat.com, groug@kaod.org Cc: eperezma@redhat.com, qemu-devel@nongnu.org, angus.chen@jaguarmicro.com, Wafer Xie Subject: [PATCH] hw/virtio: Fix getting the correct ring number on loading Date: Fri, 22 Nov 2024 10:00:02 +0800 Message-Id: <20241122020002.564-1-Wafer@jaguarmicro.com> X-Mailer: git-send-email 2.33.1.windows.1 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SG2PR02CA0119.apcprd02.prod.outlook.com (2603:1096:4:92::35) To PUZPR06MB4713.apcprd06.prod.outlook.com (2603:1096:301:b4::10) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PUZPR06MB4713:EE_|SEZPR06MB5198:EE_ X-MS-Office365-Filtering-Correlation-Id: 77a6851c-6063-4ed5-a1eb-08dd0a998ae6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?QnpSoV5Hk4jdIYLGPvpCVWKjSQMuAYD5Lqzm9VpCBmuomUoJowlAJBLvKLnE?= =?us-ascii?Q?LIFtD9coN81SEp8v7+zMnHk3NyGT3We6Mq0gD0rEIt7JXF4q8+A0QTz70M0h?= =?us-ascii?Q?SOCFqzZWnDgBdLhTW9DFdESlkQJ4jAX3XL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N2L8QjmkZDP59f41MTbu2xEfwI2VHryZ6jFMfZVUnT0mWKLJRVx?= =?us-ascii?Q?diFB1AFFu9SnDS0QMSFpxE1Ir2kZd5oa6QDTYsghJjFN1DVX3SVd9gIW8aCR?= =?us-ascii?Q?o6Sa9RYTky8aEsiG7NdoAJJaj936O2EqiwtP+tHSTTtL05hZZDMNQlYhEnVh?= =?us-ascii?Q?VnqBREgkdvAPw8Bf2hkkGXzWgIuec9v6D43x7xW4iH3nh6X2tdEhXoc1KEus?= =?us-ascii?Q?QWoVHzsrQPZSdwL1YMi74u2VrlNbSyFSffEWQI0RK/BRHsyQYxT9k0k2E31D?= =?us-ascii?Q?x1u0UE86ieBAnYKvxPul/wBk5vGgLkWLceXSjm1qNZE8nPR6sBAFwqlsPN9M?= =?us-ascii?Q?L/Zeh0s=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:(13230040)(366016)(1800799024)(376014)(52116014)(38350700014); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?v0j23SBSS83uaHTNDdR5LfL6N8nelhMWDLtSpYasNaYjUwdtnIXO+9W5hnTQ?= =?us-ascii?Q?7ZPqkl8W5u7XEaTCUmBifvFat/3FpCo/Ua+UyCpV11CFv6EgM6fZ6cevl6+a?= =?us-ascii?Q?i21MP0Nj1zHRb7+Z43fK31mXZf9a+1NNyf6OKewRSLJxdBAj3skF/NBM+uYk?= =?us-ascii?Q?SoiVzUwhaTtmYlgJoY5TXTegUXp/27GrU6tRwDsrEbwrT9YSv45UK0trOnfb?= =?us-ascii?Q?Nu7RmQ62v+9btwQ/+8lfWxbUQwueyICEJA6teCoC/ni3kk6KXnnTEmrX3hHA?= =?us-ascii?Q?Ebatw3XeQUdUVwl35GjcYO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?Q?HAs2fOtcAKRYMViSkK/L1+1eqng8/ZP4eMXAW61Us+CVrxak6hjxZ2GlGi9A?= =?us-ascii?Q?VpOEMgkgpku/FSLfNAL6GAsQOyFyUYBH78Hb8oCMxPk5LIrw/O7PbC/DirL4?= =?us-ascii?Q?MH852EzBQl0749XrnfakK4QRnzEHURTfoRqKiH3+wN5OGbNyV/qJVXDnA/Am?= =?us-ascii?Q?AV/a7eV6MPirJC+5+j5fjmBsesbE7Z/JdPKCqvLeqzHcPzt8n3XB0vEtuFIT?= =?us-ascii?Q?8GjfypBpG97jbqp4cqXuWmrRJSfRjEu2z1B8FaQx3huwiPluGop+8ziGXoSj?= =?us-ascii?Q?rR9D1hu/a09Jzi2oHWO+CrooZmjsrapYVZzL5H4Mk5MD1Jyl1QqlYL5G51JV?= =?us-ascii?Q?k80agiR+XmAHvhjt7386d4LcKtACjkoMYcmAwr5Z?= X-OriginatorOrg: jaguarmicro.com X-MS-Exchange-CrossTenant-Network-Message-Id: 77a6851c-6063-4ed5-a1eb-08dd0a998ae6 X-MS-Exchange-CrossTenant-AuthSource: PUZPR06MB4713.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2024 02:01:13.5158 (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: leiU9cP1qPblOF3fFymxXLwwvE3OPYTgmbWCdvZCnmDDhKzRc9MsJBODE6SFuqGEDBLn713r2+E0AcSyo1vtgg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SEZPR06MB5198 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.255.105; 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, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @jaguarmicro.com) X-ZM-MESSAGEID: 1732241224614116600 Content-Type: text/plain; charset="utf-8" From: Wafer Xie The virtio-1.2 specification writes: 2.7.6 The Virtqueue Available Ring: "idx field indicates where the driver would put the next descriptor entry in the ring (modulo the queue size). This starts at 0, and increases" The idx will increase from 0 to 0xFFFF and repeat, So idx may be less than last_avail_idx. Fixes: 616a6552 (virtio: add endian-ambivalent support to VirtIODevice) Signed-off-by: Wafer Xie --- hw/virtio/virtio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index a26f18908e..ae7d407113 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3362,7 +3362,13 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int ver= sion_id) continue; } =20 - nheads =3D vring_avail_idx(&vdev->vq[i]) - vdev->vq[i].last_av= ail_idx; + if (vring_avail_idx(&vdev->vq[i]) >=3D vdev->vq[i].last_avail_= idx) { + nheads =3D vring_avail_idx(&vdev->vq[i]) - + vdev->vq[i].last_avail_idx; + } else { + nheads =3D UINT16_MAX - vdev->vq[i].last_avail_idx + + vring_avail_idx(&vdev->vq[i]) + 1; + } /* Check it isn't doing strange things with descriptor numbers= . */ if (nheads > vdev->vq[i].vring.num) { virtio_error(vdev, "VQ %d size 0x%x Guest index 0x%x " --=20 2.31.1