From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 453B93D9DA2 for ; Wed, 22 Apr 2026 13:11:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776863467; cv=none; b=Yw6EJB7Fap1bapxrW4t5dA+mT7ulfirwfAFR53rs0KJwlNMWzxDfK+mF4Ow83FiXdl/LEiUTWwCayZS4/xAYK2f/+GBNfzp7NATlwI/QaSF5bvZdpB4D5WqmLg89ogeesYJpi5rFbzjBSNl+YJ/nUa66c9Uip73RM5BFCVN+B74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776863467; c=relaxed/simple; bh=6dX0PzOsvQzuVsAQ1OLovx2RSIPr5HJX+ZoCwBnrXJ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=oxXiMM5GIbsc53fhqqX7Kyq7EY5K7TG0KPtxzVeVaqFTVlkENVwn+6n4orQ32NQj6CklAo6mOktHEjt2Qo2atZ8C4e1WkYYQsChf8ftMwAb9TsIxEo3dO/Vi3o/gE1RfEvDfscYuzjeQiuc9Qp4kNvGPabF9ccxSE/LwBuT73+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ILhH4y8J; arc=none smtp.client-ip=209.85.214.173 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.b="ILhH4y8J" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-2ad9a9be502so33660385ad.0 for ; Wed, 22 Apr 2026 06:11:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776863464; x=1777468264; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=opyqOEmxu5ONdPehlI5jbPlGmvm0e7vGWmLDp5P5SYs=; b=ILhH4y8JmSxUqmvqfERpAQzrjndZ1uUh62PJDsfTZVWZ/o8PtIPjWRVmJ2TA6vehJK eqtmEdmECjxJPRp3jVMAaYiWT/WKTQoKSOZ5Iqg0dbAC8Kf0N6yR15SQe+zh27FMDEAY Lo59Zc7yEarI5US9XA7tczgSKzAj2MhvVYzEYAb8BPDmi9auVCu7vNk605YieKgtFs4e jbMsyM9xfV+eFQKE8gPt2tDEMaTuiTR0ncyDHj28F7OVJlxeN3imxSqIQySLbJtgQr6k u8fvYmJVBisNL4XtmqbF1ggB5ECTRgTaqWRanlM1UlZwhBNLd+s2ptktya8oSt3PWSS9 cQMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776863464; x=1777468264; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=opyqOEmxu5ONdPehlI5jbPlGmvm0e7vGWmLDp5P5SYs=; b=LVBFAjwcp//E7XgboEN076GtYXhrRUSCr7ymytt0X/s1BM1BhMc6JOZ2dKdbUtQOL+ xhvfT3uU1a1e4hLA4eQOIQhWAWR7WuL0uP7g6xgs5v4BFAmrHh4o9segIJDgHKzytcw1 XkBLPeWEe/Fb2n/bQYIMe4FgaLmRPINmYgOVmU6MxzSExDy/RIiam0gC1WOS22LHr2nL oABcTHBTwbiOqJSJWyfH3wEosbqieBtSZ1LserTjEh1WE86iisCUIJLtq0QKvMHFGWn3 tw+IJkbK+nFrKuw5DxEnQ5KyqzfH+7qoSYSf+92ThwSksO+jYtJMmbjkJ3vZJIa0HOoc 9obw== X-Forwarded-Encrypted: i=1; AFNElJ8gqipc1XNTgKbq3UiBHL0gpf4njtQ0zY10jn3XZe0PWOvqWY3FUNP1v8ZP0EPZTESWMuqf+ugue6nxBOU=@vger.kernel.org X-Gm-Message-State: AOJu0Ywp0YWjLTavJVuaoUuESiTWU1f+4qgn4QIhm46SJFHv07bS6wcO DhmiPiVZu4gK2aiTkvYbJdq+ugDGpAcU6SuvtASKO83HuxsehAMb/q3JO2Pjvh3w X-Gm-Gg: AeBDievi1WG+m3vA6etgUK8EYw0uQxjqblhFMKbxRhfN7HsuwEuf/U7g1CAMgAYKfDy HzHyqWwNMB/n2wPQyZj3gKc7fEH+ymwx1dZ1QrTgc5U5QGl8t20pCDeSRVpNae1QoCecPVldUZB lyUpwxke+ytVcmajQR4H8RyCh/Ou1sGbHPO0+tM3/WMk8vBcM0Z1i0SwACdkxAuFRvytx77xNno 5AI5IvyPq3Fm5qmfkHVQz7zaOvUXptrVAbPmOwTk1vuhU30HDmfYDlmAvTuzaqEC+0QmCVS5oaI P8w9O16a4Wy/x6CfonwHinchD35iXzHTzLNblwsL3dwWzSX/qo7WkmJLVbZItHDcfdwW4Rhhrr5 vrPsNcIPnOxvCdH7XsklvzjfF8dlfqBtdIgVW+nMNWY+lBZaGls7a4JdewKdVLpNkN2eMf1qu+N jhIbAKVqRfFcrmMS61l5I2S26qouv12YFYb49WoBRqQhgMeZ4pTjwFXhrlVI1EfjnaaNDs2usAv X1IBBWa1pMplSfHLkJIC32AcRBvK0706tKXsa7Nmfmt1acj X-Received: by 2002:a17:903:11d0:b0:2b2:ec00:7966 with SMTP id d9443c01a7336-2b5f9f1ab06mr250725425ad.21.1776863462787; Wed, 22 Apr 2026 06:11:02 -0700 (PDT) Received: from baver-zenith.localdomain ([124.49.88.131]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b606ce9891sm127892235ad.83.2026.04.22.06.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2026 06:11:02 -0700 (PDT) From: Sungho Bae To: mst@redhat.com, jasowang@redhat.com Cc: xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Sungho Bae Subject: [RFC PATCH v3 2/4] virtio_ring: export virtqueue_reinit_vring() for noirq restore Date: Wed, 22 Apr 2026 22:10:12 +0900 Message-Id: <20260422131014.956-3-baver.bae@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260422131014.956-1-baver.bae@gmail.com> References: <20260422131014.956-1-baver.bae@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Sungho Bae After a device reset in noirq context the existing vrings must be re-initialized without any memory allocation, because GFP_KERNEL is not available. The internal helpers virtqueue_reset_split() and virtqueue_reset_packed() already reset vring indices and descriptor state in place. Add a thin exported wrapper, virtqueue_reinit_vring(), that dispatches to the appropriate helper based on the ring layout. This will be used by a subsequent patch that adds noirq system-sleep PM callbacks for virtio-mmio. Signed-off-by: Sungho Bae --- drivers/virtio/virtio_ring.c | 30 ++++++++++++++++++++++++++++++ include/linux/virtio_ring.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fbca7ce1c6bf..528157b1211d 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -3936,5 +3936,35 @@ void virtqueue_map_sync_single_range_for_device(const struct virtqueue *_vq, } EXPORT_SYMBOL_GPL(virtqueue_map_sync_single_range_for_device); +/** + * virtqueue_reinit_vring - reinitialize vring state without reallocation + * @_vq: the virtqueue + * + * Reset the avail/used indices and descriptor state of an existing + * virtqueue so it can be reused after a device reset. No memory is + * allocated or freed, making this safe for use in noirq context. + * + * The caller must ensure that all in-flight buffers have been completed + * or detached before invoking this function. Calling it with outstanding + * descriptors will corrupt the free-list state because num_free is + * unconditionally restored to the ring's maximum capacity while the + * desc_extra next-chain and free_head reflect only the partial free list + * that existed at reset time. + */ +void virtqueue_reinit_vring(struct virtqueue *_vq) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + unsigned int num = virtqueue_is_packed(vq) ? + vq->packed.vring.num : vq->split.vring.num; + + WARN_ON(vq->vq.num_free != num); + + if (virtqueue_is_packed(vq)) + virtqueue_reset_packed(vq); + else + virtqueue_reset_split(vq); +} +EXPORT_SYMBOL_GPL(virtqueue_reinit_vring); + MODULE_DESCRIPTION("Virtio ring implementation"); MODULE_LICENSE("GPL"); diff --git a/include/linux/virtio_ring.h b/include/linux/virtio_ring.h index c97a12c1cda3..26c7c9d0a151 100644 --- a/include/linux/virtio_ring.h +++ b/include/linux/virtio_ring.h @@ -118,6 +118,9 @@ void vring_del_virtqueue(struct virtqueue *vq); /* Filter out transport-specific feature bits. */ void vring_transport_features(struct virtio_device *vdev); +/* Reinitialize a virtqueue without reallocation (safe in noirq context) */ +void virtqueue_reinit_vring(struct virtqueue *_vq); + irqreturn_t vring_interrupt(int irq, void *_vq); u32 vring_notification_data(struct virtqueue *_vq); -- 2.43.0