From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) (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 B15D8363C46 for ; Fri, 17 Apr 2026 13:35:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776432945; cv=none; b=SG++wdYadHCkD4boKyVmlTZPAcS9cnOLoNRC23Lk9urENB+BGfJorSzVAEp8/6/kYhgeHyj6fcr8i8SBKiMld/6Lte8iLFiJCZuCB3HMVkFXgl/Bq5rdpwnGbJa+hX+t1JQsLzqODM8osDGj2wRt642nkDCLSdd0jhX3NCTF7Xg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776432945; c=relaxed/simple; bh=eTMe5owLpd6fJTbocIxLhNrLvVXdrBoqyF5Kn1ZFt6Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HX28ZtG89PcTFrNplUmcdT8Vw+NHJZkhTdgTi7Zk5nWj1E2kpKo5RU1Mq2lPLAeElsvfoG53DoUmwWrwfsD83gNeA7hFDIdJWShtSUt9Z9i0wwmqc4/It6GXc2DiHVq1P2ojWRXbzGpRhvIB7djMTA7iLoDnyQkUD1cF+gNmysU= 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=bapG++Bh; arc=none smtp.client-ip=209.85.215.179 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="bapG++Bh" Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-c795a88e8acso235220a12.3 for ; Fri, 17 Apr 2026 06:35:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776432944; x=1777037744; 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=/5XV/aTMjGl4rij/mQzWRn5Aq74xFtFSJgvscfZnyWI=; b=bapG++Bh7sQarPAJ7m71bCs+oy9vLJ3IDYfBN0U3/DQ6C/or7IQqaePBMP6MIyD5pu 9Un1EchOAY17YbJcU6zqRXaRCIOEc+mhMLmYQNWCsFstzVhgbBKgazRSG163zM5lIr4Q 583XXXMntpiAipkERgABzxP4MeECICsmVEqBFKVpv3/qY1Bp0DHSj2xDO1EDFrlSjoFp E6UiIdDa8IUdih33clnw4Bc4DJ0ITS6kfF0/r+VD4d9qwS9/97iJzVWZoXLZoJfErT8S fnM6J9X4gqpMxRKzGFLkVs53dcUgJ8fBr0UlnOenyzIkt2n42QLTqP/z+JC7yJuWnrEh wHkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776432944; x=1777037744; 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=/5XV/aTMjGl4rij/mQzWRn5Aq74xFtFSJgvscfZnyWI=; b=ZRa/gIMm7SLgD8iw89nzWpr6GB1W0EpuYmvGgLavZSLxXrsjJdOKzOMTung42D+2OA Do9oGW9itomxcUvV5I2EEtsnqCf4vMvLikkXScgLeZYUVOQer/mjwi8VTb9LkhAhfFLL y3YjduWYaDs6z50tNjWBK3b+eiNYQAxuxfcpifjLhG2pCj98TgaO7PIfIADbjOysFDxO afjDEwWyWwQr9iIQA7aXtIi4XnYPrC+hfaCCbGXd4k4IAhFmsGSps8mtq5NxJzgUx+3j RfSxlYd3w42GuXgNY23w9fT3Ki3u5D+s4JMlq6Xkww1RUxa7WAo9ITACHa+vierQiOVY u5YA== X-Forwarded-Encrypted: i=1; AFNElJ+pVbW983uxeLmrS3L0up+yxcJ7t9CrPROSU9fV7Mtq27JsIdtXKnGQ4pbFp/CqneOdT1y8OWA7HOcleKs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw44/0cnb9FLQT5voHpwnhWupcgoBsFnxyViW3ztnLtCRoFVcNp fit6pLbxx6jnkov5EvIK+KUmBVpxmAJIGNRvLY0HwAQPTvuJsxARWLuY X-Gm-Gg: AeBDietkpRIE8d0LBAO5CsH1XdNqyeFITLhotYgSYP/k4vdV/MKp06dV7Sp+g5vps7J 7j8XYEZL+7OmTLz5Q9ijgK9GG4u3wpxSfu6LDOrEU/6U9HVv6Df8Dwg8AO/vNTXWeUvvXIHTk/8 +JV3e40ksnReJo/kvtChtN86hsL+zvh3dCk8iHStWnREgt0EAPGfO38RQIfdvyFivkHLBvhQKh+ 61ahKs8FIzCN4zBZkcH4hdrwt6pxpd40g4k8Uh6fiZJY8NY59W+2pzXjPtTSyZLWKeqWSTUNs/A a+7mRQrhtafO4/SHFYLqirLf5KpRlxNND5B++gZRd3m6db5/PVgXcnACszxqvQ/TkhWL5+muHXy D+27Ouq2DPh3H7SQYTsgx/hn6pJBSr3cFxnPHlDv60FqnNS/S+WYYZkldwtnVo+a63Lnm0bysSi kFwVc8K3O5H3LjZzIYkHzqflt4x0zAQfux1lBNoozQJh8TrhQZzK2FJWNpvoZg77j7zIokfXakZ mIjOlkd6OfFfQjsPsTPiHjNYARs5CsAt8E/yQ== X-Received: by 2002:a05:6a20:a109:b0:398:9403:49f4 with SMTP id adf61e73a8af0-3a08d89fa27mr3174513637.30.1776432943930; Fri, 17 Apr 2026 06:35:43 -0700 (PDT) Received: from baver-zenith.localdomain ([124.49.88.131]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c7976fa3604sm1421272a12.14.2026.04.17.06.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Apr 2026 06:35: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 v2 2/4] virtio_ring: export virtqueue_reinit_vring() for noirq restore Date: Fri, 17 Apr 2026 22:34:28 +0900 Message-Id: <20260417133430.507-3-baver.bae@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260417133430.507-1-baver.bae@gmail.com> References: <20260417133430.507-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.43.0