From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.167.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796311536; b=m7TXfQuGDSxTw8Pm+qeDg6hqV9OSeBJjTGAnbIS1n/+SVIYWh5lPQxknQYfv0WdN3pjG ilbFBxQzvAHh1QO54FS2FOCzJO6ptOiMtzhcfT8rbBy6PIO5cm2+RydkQ7weB4c+c3fvk Jx10SVFgVIwt7RXMdNuTujuP7M/rgTciQ01T3DeeMyjHpdYFPxz7XNSioylWZCF3kzjB2 Holx5qYznX3vqss6ouD5p8JoLm3zmgkllRyLbnqKPuy26UzAQAxUqMTyPpziw1wcdr+eR 10m+widuvwhF8DQZ0Qu1zdXZSW0IYklyVY0tK3tM1fZj0bw5+l9+WzTm2bChp8Y29nw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796311536; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=UCO2w/e+kW4HLJgh4BbvU633QYW1AM3qtIQwUcWzs2c=; b=H18kN6310By6npRkHHeFN/HagEi5s2RIiUogF9sghV03FAvdYxnpeehvXnOacUbyuXnF AIRhfVwq+Zg52b/yBAVbhIVX9HEGC14T0+QIOqhkGrUOJodGubliiRCC6bcXu+rshOSPu uD0ktVUwdw6lAYjuyGomVSD7xtCL3JtTfLhqY+nB909KFB7WnBfh7XoqiOKN+VaBHZttH 1ntEx9Bbq6TG8/yTvhep7qpKRQH501gqHT+KYzxsfrcwJ9iT3D6PE0pSlKx3dAxEw3CLa HV4COi3pcgeYeNCMdqqzAMUqJM2A6yec0WsI3JRNcuoFgVnFR0G1RjZluvWV8noBMMA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=O8pkxuaf; arc=none smtp.remote-ip=209.85.167.171 Received: from mail-oi1-f171.google.com (mail-oi1-f171.google.com [209.85.167.171]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0151606A322 for ; Thu, 3 Dec 2026 15:25:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F0151606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=O8pkxuaf Received: by mail-oi1-f171.google.com with SMTP id 5614622812f47-57e47de950fso5439927b6e.0 for ; Thu, 03 Dec 2026 07:25:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796311534; x=1796916334; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=UCO2w/e+kW4HLJgh4BbvU633QYW1AM3qtIQwUcWzs2c=; b=O8pkxuafQ6p1WzuJnW0wNKByDSHrH2rmbFbTFIOrHAhagGRytLsOSGEhR0W5aO/dP+ ObgfwYL9OmzYgXBDkO7Z5h6ksZot7y28A8UPywhco+Vf8hvK7bMeNrkvZytfm4CVNVWb l4buKpKpHC47tS5taN39Fq+w6cw/abSWNqZhFseIWtCB/MH3v4lQUgEaKkbUzGWuoZw/ cMunbRePYLLMJAz0pr+UD7uOGhP3e5/Evq7TQehOXIOJBQaQRxAjojdXj3c1OV1s+p6Q 7yD+aVvh1/4i5esayuUKI2Lna1duLLmGIYdOJYqnDbGXQH8ywk285CqxCNhZpB6A7xld dPfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796311534; x=1796916334; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UCO2w/e+kW4HLJgh4BbvU633QYW1AM3qtIQwUcWzs2c=; b=Vw5GHJ6jprlhMen+b+aHtZNY6ZxPyxgtm+IgFvRfkmKJCn6Pa+EXAhbe5HfJjp+NEt RQ/1QCOxUTDLdMhm/gRAAyWyyUCYsWIy/7JQcT4lpSUIAmaP5t/ABG0e/p01P6A4la97 JxodgB2fyxLwE4EITEfp7cTbJg0lM5cPCQXeE0IHWRijU2sC0coP79MoKcFQMYbO43FH iL5+SPn/gYPeon+hZ4Au5PP93wIEX6vsbsn7L/WF69YUXHjoACrFcg1oBrWZQUnjs9Ht UGjRh2LmxNc7+1quiB1XGtdCWjWFVudLV6PCgNF5dSLhufxPAH3CB1xzVzfOFbhGu4gK V/sw== X-Forwarded-Encrypted: i=1; AL+hErHsVQYQxgmZT65TW+Tl1Qx+ZO90T9Pv9o9wooC/fd/nfMbgSc2dLSY2wmWheUY5W4hx1dj2EINTsoutX4c=@vger.kernel.org X-Gm-Message-State: APuU4Z8D2HTlkJ/M6uVY8x/Vo6xFLTtC/MRej35g8sicsd1qBfZXeBTy DTWQWjBVp+pt7WsWocRRqlISqkmg3t+4WkDObSRbYC6DGjw+Ib+/rEPk X-Gm-Gg: AZFdTZerHI+v0lTh0ascw91RHy1HW/o58MnizRLoVbJlx1jNgKTvexXkPZLmY5sfUL0 4BEvYEgMdxeqvN0zjcrTabXpCiDAecNkTHbPXAgbL07SB4t8t/YgPtA4NSHZebWtz4oZFOciGAm jLJPWexs2zd6H0Mdp54Or3XlRCUH/FN1ZD9J6tyRoqNklMKq2m73BJdWJsntTUbB52y7zT/qAUi 3VAuKOUtQQozUcMsoH44sGj7JjAMRPOuAbHc/xws9WJnzlAQfR6CeqFpP5QcDJgvbzh2mj5fn7m 9p7/K+plLmM9NXE62QLF9cVVoXDa1PmsIB+FrYdQM0nJluFPPpQF5D1ZIAb8O07r4u83aoCP30g E93Ee4uQs0aIFGa91zcoM70uFNfd4uI4hnUUMK1wHjlEr4cE3bzT1a7iuR2bXKipP+SIjcHjP2y HeHmNZVOutZZUZ0hoMO9UIyvMuKkttYmaoy6xKc6KKLh75u1qfyfbAnBoa7M+/BOE/hKL8msecR gpYLJQsI0jmmiacIiLj557Q6qc3C1SMRmA5IoyXgcxk0pVqIkD2K7D3L/1FHMJO/gt1zj7oClZb oHsFjzayDkUk00zR9joynIMiGTs87Ys0megkO92sldU84Mv8xWFAT26thfU2cVqIQmjF9NcC9y9 YRA4dEWTUUuhKX2wrtdtUlT8UIcVzC+BbZHV4SkEsPT8qnru0xXXi+xbJ3NfFT4B/XEc= X-Received: by 2002:a05:6808:1307:b0:573:b907:d555 with SMTP id 5614622812f47-57a07715062mr50440285b6e.9.1796311533833; Thu, 03 Dec 2026 07:25:33 -0800 (PST) Received: from tempest-testimage-cc-centos9-stream-server-1191361818 (chi-dyn-129-114-108-164.tacc.chameleoncloud.org. [129.114.108.164]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-4bc5f7ae7dcsm36989287fac.8.2026.12.03.07.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 07:25:33 -0800 (PST) From: Yuho Choi To: "Michael S. Tsirkin" , Jason Wang Cc: =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Xuan Zhuo , virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Yuho Choi Subject: [PATCH v3] vdpa/vp_vdpa: Wait for device reset to complete Date: Thu, 3 Dec 2026 15:24:50 +0000 Message-ID: <20261203152530.1953781-2-oss.patchbox@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit vp_vdpa_reset() writes 0 to device_status and returns at once, but the virtio spec requires the driver to wait until device_status reads back 0. With a device that takes time to reset, the vDPA bus driver can set the device up again before the reset is done, and the late reset then wipes that setup; the device may also still use the old rings. Wait for the read-back, as vp_reset() does. Fixes: 64b9f64f80a6 ("vdpa: introduce virtio pci driver") Signed-off-by: Yuho Choi --- I used an LLM to write and run the test below. v3: - Tested in QEMU/KVM, including a QEMU that completes the reset 1 to 100 ms late, which shows the bug (see below). - Shorter changelog that describes what the test shows. No code change. v2: https://lore.kernel.org/r/20261116030152.1704527-2-oss.patchbox@gmail.com v1: https://lore.kernel.org/r/20260926211507.1330179-1-oss.patchbox@gmail.com Tested on d06ce6f1eb5e with KASAN guests in QEMU/KVM (q35, intel-iommu) and a modern-only virtio-net-pci device bound to vp_vdpa, using it through virtio_vdpa (vdpa dev add, traffic, vdpa dev del) and through vhost_vdpa (VHOST_VDPA_SET_STATUS 0, then read the status back): 1. Stock QEMU 6.2 completes a reset at once, so device_status reads 0 at the first poll. Both kernels pass 20 cycles of each. 2. A QEMU v11.2.0-rc1 with a test-only change completes the reset 1, 2, 5, 10, 20 or 100 ms after the write of 0, as a slower device might. Without this patch every boot failed, 3 of 3 at each delay: the late reset wipes the setup that follows it. Depending on the delay, the virtio_net probe fails with -95, no packets are received, vdpa dev del never returns, or vhost_vdpa reads the old status right after SET_STATUS 0 or fails its next setup with -EINVAL. At 100 ms: WARNING: drivers/pci/msi/msi.c:816 at __pci_enable_msix_range+0xb3d/0xdc0 WARNING: drivers/vdpa/virtio_pci/vp_vdpa.c:224 at vp_vdpa_set_status+0x412/0x630 WARNING: drivers/virtio/virtio.c:380 at virtio_dev_remove+0x182/0x1e0 With this patch: 10 of 10 cycles of each at every delay, no warnings, 3 of 3 boots each. Like vp_reset(), the loop has no bound, so a surprise-removed device that reads back all ones keeps it spinning (pointed out on v1). I kept it the same as vp_reset(). drivers/vdpa/virtio_pci/vp_vdpa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c b/drivers/vdpa/virtio_pci/vp_vdpa.c index 646efd9384fb..eba82ff253ea 100644 --- a/drivers/vdpa/virtio_pci/vp_vdpa.c +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c @@ -8,6 +8,7 @@ * Based on virtio_pci_modern.c. */ +#include #include #include #include @@ -236,6 +237,9 @@ static int vp_vdpa_reset(struct vdpa_device *vdpa) u8 s = vp_vdpa_get_status(vdpa); vp_modern_set_status(mdev, 0); + /* Wait for the reset to complete */ + while (vp_modern_get_status(mdev)) + fsleep(1000); if (s & VIRTIO_CONFIG_S_DRIVER_OK) vp_vdpa_free_irq(vp_vdpa); base-commit: d06ce6f1eb5eeffd4ebcfde345dc34a98131d106 -- 2.56.1