From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) (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 723ED2F49F6 for ; Sun, 2 Aug 2026 17:41:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785692474; cv=none; b=RvA+fxiq1sb0TAlr9+h+sA6yMysnnpZTQ41V3wklmTkKuXJ0/R/vxF/w7M/UFAcQ8qdEqQyTjtcJuxI2x+9ND8KSxUYMiKDavcfmp3da0RDcNPf6RdZNr6gFkUYyn/f8MKGrGlGA1sMLW4EgqUuNwSx8I1kCGOUtGccyrq1/EsU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785692474; c=relaxed/simple; bh=3OhirNyMf54WSFzJShiX8eOgeTq9nhO3PqfEs+vn6oc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mOe2z6RAYOFJsC9qwF1u+YDmMpEvvn3tpqf2p5B9nsCJa66NA22D12zo9uszU0nAoameIo0a6W8iWAYv4qFz8cAzlWg0diZQCgdXdf2qqFjte3EmFIhxVaYzh7AgB8fEajS7n5gJbUIpJQkmFAIhqCXrQPrT2M7666/84PnJFsw= 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=pnZ7r8CF; arc=none smtp.client-ip=209.85.221.43 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="pnZ7r8CF" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-472326ca506so1829183f8f.2 for ; Sun, 02 Aug 2026 10:41:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785692470; x=1786297270; 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:content-type; bh=GNTSo9k4OEOZmjLMcV0fOaIKqB7Gshw/tjsufsKjn48=; b=pnZ7r8CFboyz89WgadLbiTpcm3KnnLVTpCr8o3Df4k0yQAnCmDSosOvrLpEbew8KU/ WGnit8zQVYderFNYYCjvkU5/uAFqpceRrXg1hCOtULgGRO5rdaXCymmY+UfW1K2vbYRN KUM0aQ82+gzmqOJidwyU2s4eErxxH5yUdz90IawXBPCmQhbP+gbQi4I/IfhE+scDAXhy +3WqXT77oJJeRwbl4PNyOt0dqpUTZ3y2c3KVPhbSnv3Zswzl5UdmGeDx5FNVJI8UKdse DrOpthJPJNv57KVcm9kkXjgq58oRGFGNblVoNw8ct90TOdrl2kMnmYO79E6HGi6HFzGk Edfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785692470; x=1786297270; 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:content-type; bh=GNTSo9k4OEOZmjLMcV0fOaIKqB7Gshw/tjsufsKjn48=; b=TTe1zU+gNzWnqnygDfWfCkHvaCIMKJjmkcL5rGckHbWFYco/HmRTpddfuXL8T8xGr6 AQWN0j1JMM1RA/2cp3NI5NpSQBoynDMbXAWwL/X8sQnskO3jhiWfCcNWDVAqKeaVKQr2 NX4d+t1z6XQ7dvgrH4lO37J8Ym8Y1q+WwJF5nGImUYhdNaSwscSWZpLNk0B8GCHOrs2L iEcY/ahna4wJ9DqDrNuU89cirLshWitH1q6jK0nICa2AVY4NGvCVGs6msfD806jsxD18 79/X95StDtP+TuodKrumhsJdijsAEQsvViMazPhRWADyajaVtsgIDoahXuOVTFdtEdH0 K5hQ== X-Forwarded-Encrypted: i=1; AHgh+RqIfS+kXwmqOa33QsHuqVBrWmpHaH4flL5S9ss7BAwYcLZvib4qw9YRMgbDSy3Y4/KaLD1YV9JLEK+RWoY=@vger.kernel.org X-Gm-Message-State: AOJu0YxTozKAaerFPCTg7aWl7wzWdOWHr5EfyypFCFCiQWcWDY41MSXO zyVauYiB1nmI4IErC3Tj3T58nYLEzcW+6Z0i7WTme3OJcoFr476FqYnJ X-Gm-Gg: AR+sD13d3DstW+5ye/rpO9xdYPCD9/le4KS7ogfsZUhIJxGOhC7rr/PfhYXLAIcNFPj hmVlM9a4XvFyCrRjLjmjVCZw2cj1GoDHlZHN5hLJlro0Zyy3Ss73dL81mEWwmG2RSfvOCkmSSyZ Jfw2zBUnoQ1fiGtVrBYRQOhEEWCueRi8NnRLhkVDTCppsnZUcEYsPB6akjgadCatB/Pu+ftBue/ I7c1oF8elBzsXHOzsU7iFPWlz5/hdIHitGrQWf0vk9xO5QwTOrWXDSexdP1+03EqR1iRzHzZm8t Uub9auqOlz+UDNTOwpiGA6aSvLuelovPw/WqwnGRLd9lW69tsz0s6868onTwCzorg8XfferjVaO Z/WDHA0sQmUjNjW9Ic2bD7NAbmTQc7y30Ew0Y5/I/5+iDUGHJi5ooym5f7Ufv5QFVlmCTguZPPW A/NghUMjj19Gnt9K35tLNehP6ODgis75c9pR+OmrQdSTpZ44XHSxJTDw+Zz6DR8D+olMs9VqlX0 6Y4DYCuazjiup+n8TUsLEiNwC/GD7ySaiO9IuIQFQ0SkGb8pLd1Pd42wMmXtbryYmE= X-Received: by 2002:a5d:64e1:0:b0:47f:8488:50f0 with SMTP id ffacd0b85a97d-47fd72ba756mr17412763f8f.4.1785692469675; Sun, 02 Aug 2026 10:41:09 -0700 (PDT) Received: from a9d4faf53c34.fritz.box (dynamic-002-214-008-136.2.214.pool.telefonica.de. [2.214.8.136]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47fd458ab61sm25607861f8f.25.2026.08.02.10.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 10:41:09 -0700 (PDT) From: Abhin Parekadan Jose To: mst@redhat.com, jasowangio@gmail.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, Abhin Parekadan Jose Subject: [PATCH 1/2] virtio_pci_modern_dev: warn once on invalid status Date: Sun, 2 Aug 2026 17:40:58 +0000 Message-ID: <20260802174059.4082-2-abhinjoses@gmail.com> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20260802174059.4082-1-abhinjoses@gmail.com> References: <20260802174059.4082-1-abhinjoses@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 vp_modern_get_status() returns the raw device_status byte as read from the common configuration structure (struct virtio_pci_common_cfg, mapped via the VIRTIO_PCI_CAP_COMMON_CFG capability). That byte should only ever contain some combination of the status bits defined by the virtio spec (bits 0-3, 6-7); bits 4 and 5 are reserved and a spec-compliant device must never set them. A value with any other bit set means either the device is violating the spec, or the read never reached real device state at all -- e.g. because a write of 0x0000 to the PCI_COMMAND register (config space offset 4) clears the Memory Space Enable bit, causing the device to stop responding to memory-mapped register accesses -- effectively simulating an unresponsive/removed device without a real hot-unplug. In that case the MMIO read returns the bus's synthesized all-ones response instead of real device state. Add VIRTIO_STATUS_ERROR() to the uapi header to recognize such values, and warn once from vp_modern_get_status() when it sees one, so the bogus status is visible at its source rather than only showing up as confusing behavior in callers. Signed-off-by: Abhin Parekadan Jose --- drivers/virtio/virtio_pci_modern_dev.c | 8 +++++++- include/uapi/linux/virtio_config.h | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_pci_modern_dev.c b/drivers/virtio/virtio_pci_modern_dev.c index 413a8c353463..60dd8acf1c28 100644 --- a/drivers/virtio/virtio_pci_modern_dev.c +++ b/drivers/virtio/virtio_pci_modern_dev.c @@ -480,8 +480,14 @@ EXPORT_SYMBOL_GPL(vp_modern_generation); u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev) { struct virtio_pci_common_cfg __iomem *cfg = mdev->common; + u8 status = vp_ioread8(&cfg->device_status); - return vp_ioread8(&cfg->device_status); + if (VIRTIO_STATUS_ERROR(status)) { + WARN_ONCE(1, "virtio: device returned error status: %#x\n", + status); + } + + return status; } EXPORT_SYMBOL_GPL(vp_modern_get_status); diff --git a/include/uapi/linux/virtio_config.h b/include/uapi/linux/virtio_config.h index 2445f365bce7..6f458914c0ba 100644 --- a/include/uapi/linux/virtio_config.h +++ b/include/uapi/linux/virtio_config.h @@ -45,6 +45,22 @@ /* We've given up on this device. */ #define VIRTIO_CONFIG_S_FAILED 0x80 +/* + * Check if a status value indicates an error + * All device_status bits currently defined by the virtio spec (bits + * 0,1,2,3,6,7). Bits 4 and 5 (0x10, 0x20) are reserved/undefined -- a + * real device must never set them. A status byte with any bit outside + * this mask set cannot be a legitimate value: either the device is + * violating the spec, or the read never actually reached it (e.g. + * PCI_COMMAND memory decode is disabled and this is a synthesized + * all-ones bus response instead of real device state). + */ +#define VIRTIO_STATUS_ERROR(val) \ + (((u8)(val)) & \ + ~(VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER | \ + VIRTIO_CONFIG_S_DRIVER_OK | VIRTIO_CONFIG_S_FEATURES_OK | \ + VIRTIO_CONFIG_S_NEEDS_RESET | VIRTIO_CONFIG_S_FAILED)) + /* * Virtio feature bits VIRTIO_TRANSPORT_F_START through * VIRTIO_TRANSPORT_F_END are reserved for the transport -- 2.51.1