From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A781D314B95 for ; Sun, 2 Aug 2026 18:10:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785694235; cv=none; b=M6TXlHyjdnMjhgtGHPjtzwO50iPt9heV0LaZfc+8yn4uXe25RG8jaWJrGeH6z/cpce/BlCXr5rx0WwRglMiTVxm0wPuX20CPcMZQ7zod4tqLFlIqvlNqG3rij8PC1K6p7vvMDcMaUW789iGbazT0B2wV8v8PdinKbWZCoPWNABU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785694235; c=relaxed/simple; bh=LIkuI23ru68AL7kN+JvGgQXMhZWmeZ2+PfGGzYwQ8gU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ElF0TRjZMXY4wt+KUJJkOCJlaIIU6x+wNejWKsyLWmWhm1hgysFQ8GSKl1XGL/Q4p56KhBd5b48+fSTSWSj7T8CVSklz4DblVboclSfwtA9TfdyxGgQgrsNh1Or2f3AzbIqwNDm1Fp3DsuCtBZiOP2n1RdolYmUIMkXEr7ok3JI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=irufLt26; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=AO89jQhL; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="irufLt26"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="AO89jQhL" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785694232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SqFBg6nB/z21F6d3F0FRo0Q9T52fV8s+MEGcMWr8o18=; b=irufLt26vxSfEs+cFJpHxrlUeIXuxk/ui4iokLLk2ia80nKAYPKeBF4Lcs/dDTd7ZpS2Qu 8sl4QBG32Duq9+o6YrqIbWfIzJOC2nhrcwoi5nN9oqeZM2rYp7Yaj8QbE8Hg5A4jJUFA8Z 38Jeqq0/jT14jWj0zgt/1W1qDwHF90s= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-570-SKD8ZuNgO7u-_vF_J1T8zw-1; Sun, 02 Aug 2026 14:10:29 -0400 X-MC-Unique: SKD8ZuNgO7u-_vF_J1T8zw-1 X-Mimecast-MFC-AGG-ID: SKD8ZuNgO7u-_vF_J1T8zw_1785694228 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4954a93c565so6527455e9.2 for ; Sun, 02 Aug 2026 11:10:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785694228; x=1786299028; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=SqFBg6nB/z21F6d3F0FRo0Q9T52fV8s+MEGcMWr8o18=; b=AO89jQhLkBL7MuBjt1CoZA6F91NHQiCGN6ZjspYlNf4pgsMNPDBBZjhHDqNSy653nz ieMHHF+5/TGfV1or2FuqRDPFCIdB7yaMmrpd5shVsd+sWsqGU1EklnW5crgh+7If9ncx gbrKQhF7V0Ipmb9BaGY13Q3YEMlsn+8jm5Pz4kqXtW7uIA8beiYlEHtsnxKYXSdW2nU2 WmhSb3W3Kxf+/BOL1COtycq2vL08HzZT0RKQ0idkFFPW8K606YRB0ppU4+ROTIV5QfVo MVTQjjPHOxjuMKp5siv6KnHkrzFQ1tQ5juYGmDQvBzXO0C1NBqMQ+vDJNoNSKnM1vbQu te3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785694228; x=1786299028; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=SqFBg6nB/z21F6d3F0FRo0Q9T52fV8s+MEGcMWr8o18=; b=radwUy3kf0efruqhI8sEmwj01Vuj0iZTRTvC3DJ1ugLsop8bF9IErq53KnkJhEOEQj eUawiLPZ9d7Sfftx5BBZaL1711IbPHCu0ORBrKctNrlnuoR6ZVsF2QR5PD5b/so5PUUn KhY7b8WMcMSWXnfZGiHnMcOUON2E/qzVBIWQGboiD5elcJUHphzCaRNYEG+reygbyP35 O/7PcUI8dipfV8+bIk6MtnVsycoxU9mDXM8squOzmj5FF0/AltjSYllwVkm6tQsXUrR7 KGF3wianbxt/QJ9X7vahnsVXxCr86TqRE55qO96wb4sJ6URPqxgAPN2KOdmAjXx9wl1X YhFA== X-Forwarded-Encrypted: i=1; AHgh+RprliWiCQ9gGK+xwg0D2pS8SVFbUlow6+e8S1EtsY3sICWObQBmYSIW5kmamQCtXn+WC1dTN/K3rVFrtdU=@vger.kernel.org X-Gm-Message-State: AOJu0YzOsrvbp/RNHc2DzwF1WODko/B1N3pXmgVg/MMLaqoBBOqBeOgT 90bGJhAedoyXZADk6ub0ER/FjKgd1z3DUtb6bSsPqKMYk51vqgHXweYeKJE0ibVXRzXV4UDXlXc 6PmlbbPKaONPF4mYQRfhtWgi3LunLcy3Xp9cj/i5g01tObTZR/GGQ+9viO8stQwdd0ZHtwcUNSA == X-Gm-Gg: AR+sD13kXGvuWdijr6Vc2+6ANmcbgikzXDK9ZYjxVuxI2OMe7Gnc9gvXb8GcqlotyU5 kGyE1aMpylqU9tlFC1ulUmr0V1q5eKcuJOL7JO87UAYUdZ1ogwad2cK+xzSdDmjRoS+PjTGTtJn axuB8lSL+YF2bnosUUOhVUnrs+M2bQg6HeYBWOcWzXGNi4AcZb96A9lYTAnxsdXzcu/Kc/VFxjZ tUdVRvurFyVfOouhjItQJJgzCbkXUpcq2CGC17mcLyOFPJ+YzlrTkeb1Gy7BNA9sny7Cji1YYy9 89OPd4EboJeQZEWoOOVuGcmkUPk/QzBcm/UBWTd1RbsaNkgtA67NXp1+60toG8Go1E4W4r8ryto U0JAw5ea3buvRgdgG3KfITQ== X-Received: by 2002:a05:600c:a47:b0:498:1371:6612 with SMTP id 5b1f17b1804b1-49813716987mr68492845e9.6.1785694228030; Sun, 02 Aug 2026 11:10:28 -0700 (PDT) X-Received: by 2002:a05:600c:a47:b0:498:1371:6612 with SMTP id 5b1f17b1804b1-49813716987mr68492315e9.6.1785694227525; Sun, 02 Aug 2026 11:10:27 -0700 (PDT) Received: from redhat.com (IGLD-80-230-28-14.inter.net.il. [80.230.28.14]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-498081a1910sm71056355e9.4.2026.08.02.11.10.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Aug 2026 11:10:26 -0700 (PDT) Date: Sun, 2 Aug 2026 14:10:23 -0400 From: "Michael S. Tsirkin" To: Abhin Parekadan Jose Cc: jasowangio@gmail.com, xuanzhuo@linux.alibaba.com, eperezma@redhat.com, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] virtio_pci_modern_dev: warn once on invalid status Message-ID: <20260802140707-mutt-send-email-mst@kernel.org> References: <20260802174059.4082-1-abhinjoses@gmail.com> <20260802174059.4082-2-abhinjoses@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260802174059.4082-2-abhinjoses@gmail.com> On Sun, Aug 02, 2026 at 05:40:58PM +0000, Abhin Parekadan Jose wrote: > 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. Future versions of the spec are likely to use these bits, I prefer to make the drivers future proof. In fact, things like kexec mean that we don't know what drove the device earlier, so we do not know that the previous driver did not write 0xFF there. > 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)) > + Not clear what this does in UAPI, even if useful. > /* > * Virtio feature bits VIRTIO_TRANSPORT_F_START through > * VIRTIO_TRANSPORT_F_END are reserved for the transport > -- > 2.51.1