From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 26E343EBF0C for ; Wed, 15 Apr 2026 17:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776274845; cv=none; b=aAhSX2VKAH4rOEI/YcM5wDT2vNvu319z4+2y+l5fGLlu1/LywzKb3VWGYtKa5j1Jpsji8XY6oARIO4UXRHQ62N8MjwWTc4B3/CXzi5alvKOdGQHNNRwfWcCGp1lKGe0bG/jj5aHPCIOf0vnsBi3fKRX4QEJkXlm3Ks7IzhcHNCM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776274845; c=relaxed/simple; bh=/wzY0uR7XsAJFVFm2VHFAgX1e1WWVRZFNs7XSXLzWTE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CObyNutqEHGm18tU7rPRIVwT0Kt4Xoy9sMITdb8P9JWUILqiRVonk3O4JiyMhbWHrUv5E1bhS+Ak7lY+RX/QYl3qPEuAYJzy4qzciUc0QudfaoxQ+bYKCEP9AiMu8AyN9sCuQXW8ZtLQgFjLBqJw9xgV7lh9VZvPdwwBQYdYOFI= 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=PuSc8wXR; arc=none smtp.client-ip=209.85.216.54 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="PuSc8wXR" Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-35691a231a7so4534604a91.3 for ; Wed, 15 Apr 2026 10:40:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776274843; x=1776879643; 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=s02OsJTTkDH9VQI7tIvBGr+0nakaQaimTmuWsyQJa9E=; b=PuSc8wXRvVPfmY1jKjOFVuziOeFA/iK/Ynrunf2dws2CemBpH6p91VsdcTdq0jTnjO ENsGoIIkMJsL0XM53SiESU5bxyb+kjoF+Hxj/jAPAUxYhiVWn37TnifyTJdb1PrVIisJ bIuQW7H5K/iiR7addd5NbYwT83e5PHXKjp7U0oWuaeiij3qmHKDwChK3EW80vA24GauX BhP6NiszgrvXbNHnZ4OCrcDzhGyfSefP8G1C5ZTSTmNhG5G0ewlOsWHzR7aro2jeVC01 8LizG8ijqtUq7ZUAFCbdBNKCtA28ZKNZ1f8GcHQuXGJRsS/NOnD2ghs102anFrWmGsVf mQFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776274843; x=1776879643; 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=s02OsJTTkDH9VQI7tIvBGr+0nakaQaimTmuWsyQJa9E=; b=MSArID38cWO41PW7gqLLqbc+gHZNSUafwR7gtj9Lk3Aa/wz7JuRz9EWsDCS8lQVTob BtjCm2Sf7n7qVguXI/Nv3VBFgIwBTAW4ESo6jDmARxd+Tr5sFvZyFMErnYuGt0HQ2dZ2 fdAw1YjeLQFpkui4m8dYsR8GZw7WO1yrG9gzFJROEB+dG2fESbsrFHQAfBtYv6KSK7X+ VOObnK5OqHLSlQ34YCYJPngsyFL4Se0BLuMmhipJA3D4o2b+3nHFCs1awvWQxfROkPW1 G0REIlL9yaA1XgQQBHAhRWFoSIOFW19svizLuzBXDF5s4F0xzYgosbhFkvg2Gj0+T3vr W1Sw== X-Forwarded-Encrypted: i=1; AFNElJ+lZ89tWoVOkT6aca1sEcnppomuVzyGVJT0gBx44x2V+aU6wVHPc4pB5EyqeU9iNfUDiRmUFGUeun2K9aE=@vger.kernel.org X-Gm-Message-State: AOJu0YzfwyPCLy6j5lKEknTdnfUsYGESM58jSXxt2RgGOqni6GYtB1du Nyyra/gwmVBw9V6j/snFmJpJj2/rC1zpz6KO+7Wj/k9VW7yRw3rUoGkoeW0I6UrY X-Gm-Gg: AeBDievt47i9iukHByjICRC142pKaBGghWke/1gXPIipOP9xJXNrU0qSxcj80KhbC+z ki/ageVOYfdAjWLOCftH1a3c+khGKk88HyE4lAyA4STHz0mGftatpu9NY3UgeXYEbTTYvRbtTa7 WQ9UFC4n01CKzpUkb4WXYwjSphvRvPFDz2DeLYsPgD3j0hUOG4Jdt7rfd68+fdkxzTy2yJrLrBK UqJVfXJWJ1nPI2Riky+xO1nDrwFj0nw3DPl8hFqbMLqw62xuSUZlmseiqvCGohE7jgoVyNkTHDH ac8qzjUUZw76EabP8x/W4Robzsfib6Zu0Ag7yZVMBDIJcn36W/heb3wligiHrCBbZ5Al8yQThFa UdUhpXftQIaehAok0pTv0HNrS2Be38++tqnz4UPFbo3HrTZe0t8Csc+DWX7mIMGSZDPRzXhA+I9 oX4vxtVMp75qWbcDexqHZA1dtVTZ9bMBwdSoR9LFAHCDbW2h+xqcR6KAxYWotA3NaOoMLhu2sUs rk66j4VVxB66aJSYCHZY4+OzytSTf4/jUHRyw== X-Received: by 2002:a17:90b:4d0e:b0:35c:b02:b5c1 with SMTP id 98e67ed59e1d1-35e4254fa24mr22085159a91.2.1776274843412; Wed, 15 Apr 2026 10:40:43 -0700 (PDT) Received: from baver-zenith.localdomain ([124.49.88.131]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35fd1fe9b50sm2891026a91.3.2026.04.15.10.40.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Apr 2026 10:40:43 -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 v1 2/4] virtio_ring: export virtqueue_reinit_vring() for noirq restore Date: Thu, 16 Apr 2026 02:38:31 +0900 Message-Id: <20260415173833.6319-3-baver.bae@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260415173833.6319-1-baver.bae@gmail.com> References: <20260415173833.6319-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 | 19 +++++++++++++++++++ include/linux/virtio_ring.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index fbca7ce1c6bf..a57c625b5936 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -3936,5 +3936,24 @@ 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. + */ +void virtqueue_reinit_vring(struct virtqueue *_vq) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + + 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.34.1