From nobody Tue Sep 29 02:33:42 2026 Received: from pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com [52.26.1.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 961BB370D5C for ; Thu, 13 Aug 2026 08:38:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.26.1.71 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786610333; cv=none; b=Um4fuZn1rgxEePRgInt0uujFl8Cu9A5m/fOmzIE8qeR6o8XhOAN7VO1G1x8zIgjcnClBxqXKX8u3MhTKSmxMWlXSiyI/SJQRqKLQASd36o3McaT+IvIoxmGp9bPBc5s7O5wxD9M97dTvJnBALqEmc0G5EwP6RYtgnmIICJDvAok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786610333; c=relaxed/simple; bh=+Qhd6dnoLVR3wLQ+4H2tfRt6mmL6d9gmzKv9n/TIFbo=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PaCNxAlbGS8AkxS6sjTZpiURjEWbhucJyDlbZ7cfLEAw1R0SvydKuMRQzT6wJhkl+h5f5N2L97njuf/1FPwnJwtR0gti8ESPxtvos1Jh8uhCpl/4jGbeaqwobRBBNAot//pA7OgqQebDMNAveXNW8qpgklommzD96xMr7Pw9Z7g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.co.uk; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (2048-bit key) header.d=amazon.co.uk header.i=@amazon.co.uk header.b=JwckBrLM; arc=none smtp.client-ip=52.26.1.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.co.uk header.i=@amazon.co.uk header.b="JwckBrLM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.co.uk; i=@amazon.co.uk; q=dns/txt; s=amazoncorp2; t=1786610332; x=1818146332; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OiMxWWgeTujqbgE7ezz77HF/8P0Px6KsHd2qPlZ08SI=; b=JwckBrLMfoEJxeGe5BuHDFho0mkk7B72wtLOKLL79QzvSdvE9vTmo/dA RJjREZ72UCSUBeiykgk6A4DZP9dDk6eVfZ0G9zqzC5oYXBM/PdjSAIePK g+vGoMFuDOJzrkr19lC5ApcZBftAZLbKqLRAMOdRjwG4H1OmqRHg893W3 U8Jqxdz8k74Ks4TYZweJ+QglYRvSaaouNbP4kI8V3GXlXDNbw+8UG5A68 /a4vNTci/tPAdAwAdMQbb6tC+KUS2QGeY04TqzX5Lp2wQnoUvp0Y5q0uN tHHTFl5RkmjNmPAYJYAUiE+XSTnMGAm6EN9ATexLx5sCV6inDpd4KXTzP A==; X-CSE-ConnectionGUID: p9wS+nuyS4yD2RD1gud+gg== X-CSE-MsgGUID: Ee7kMtNdSsmHGZgacS8EkA== X-IronPort-AV: E=Sophos;i="6.25,221,1779148800"; d="scan'208";a="25890684" Received: from ip-10-5-12-219.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.12.219]) by internal-pdx-out-006.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Aug 2026 08:38:49 +0000 Received: from EX19MTAUWA002.ant.amazon.com [205.251.233.178:18252] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.22.18:2525] with esmtp (Farcaster) id 7425172b-4a03-49e6-944c-4efca9aa54c9; Thu, 13 Aug 2026 08:38:49 +0000 (UTC) X-Farcaster-Flow-ID: 7425172b-4a03-49e6-944c-4efca9aa54c9 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWA002.ant.amazon.com (10.250.64.202) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.45; Thu, 13 Aug 2026 08:38:48 +0000 Received: from dev-dsk-jaspwise-1b-5558f826.eu-west-1.amazon.com (10.13.227.24) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.45; Thu, 13 Aug 2026 08:38:47 +0000 From: Jasper Wise To: , , CC: , , Subject: [PATCH] misc: nsm: mark device ready before registering the hwrng and misc device Date: Thu, 13 Aug 2026 08:37:52 +0000 Message-ID: <20260813083752.581981-1-jaspwise@amazon.co.uk> X-Mailer: git-send-email 2.50.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: EX19D038UWB003.ant.amazon.com (10.13.139.157) To EX19D001UWA001.ant.amazon.com (10.13.138.214) Content-Type: text/plain; charset="utf-8" nsm_device_probe() registers an hwrng provider and /dev/nsm. hwrng_register() can make this the current RNG, and the hwrng fill kthread finds it through the RCU-protected get_current_rng() rather than under the rng_mutex that hwrng_register() holds, so it can be in nsm_rng_read() offering buffers and kicking the queue before probe has returned. The driver never calls virtio_device_ready(), so DRIVER_OK is set on its behalf by virtio_dev_probe(), only once probe has returned. The virtio spec is explicit about that ordering in 3.1 Device Initialization: | The driver MUST NOT send any buffer available notifications to the | device before setting DRIVER_OK. A device that waits for DRIVER_OK before servicing the queue therefore leaves that read unanswered. Set DRIVER_OK once the virtqueue exists and before either interface is registered, so that the queue is usable by the time anything that can reach it is published; commit f5866db64f34 ("virtio_console: enable VQs early") and commit 1d774589f924 ("i2c: virtio: mark device ready before registering the adapter") do the same for the same reason. The err_hwrng and err_misc paths then unwind a device that is live, so reset it before deleting the virtqueue - the core only adds VIRTIO_CONFIG_S_FAILED to the status when probe fails, it does not reset. Fixes: b9873755a6c8 ("misc: Add Nitro Secure Module driver") Signed-off-by: Jasper Wise --- drivers/misc/nsm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/misc/nsm.c b/drivers/misc/nsm.c index 3960506eb7ab..088f93a8de5f 100644 --- a/drivers/misc/nsm.c +++ b/drivers/misc/nsm.c @@ -440,6 +440,8 @@ static int nsm_device_probe(struct virtio_device *vdev) =20 mutex_init(&nsm->lock); =20 + virtio_device_ready(vdev); + /* Register as hwrng provider */ nsm->hwrng =3D (struct hwrng) { .read =3D nsm_rng_read, @@ -472,6 +474,7 @@ static int nsm_device_probe(struct virtio_device *vdev) err_misc: hwrng_unregister(&nsm->hwrng); err_hwrng: + virtio_reset_device(vdev); vdev->config->del_vqs(vdev); err_init_vq: return rc; base-commit: f5098b6bae761e346ebcd9da7f95622c04733cff --=20 2.50.1