From: Shuai Xue <xueshuai@linux.alibaba.com>
To: mhonap@nvidia.com, alex@shazbot.org, jgg@ziepe.ca,
ankita@nvidia.com, jic23@kernel.org, dave.jiang@intel.com,
alejandro.lucero-palau@amd.com, smadhavan@nvidia.com,
corbet@lwn.net, skhan@linuxfoundation.org, dave@stgolabs.net,
alison.schofield@intel.com, vishal.l.verma@intel.com,
iweiny@kernel.org, ming.li@zohomail.com, yishaih@nvidia.com,
skolothumtho@nvidia.com, kevin.tian@intel.com,
bhelgaas@google.com, dmatlack@google.com, kees@kernel.org,
gustavoars@kernel.org
Cc: cjia@nvidia.com, kjaju@nvidia.com, vsethi@nvidia.com,
zhiw@nvidia.com, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-cxl@vger.kernel.org, linux-pci@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v4 17/27] vfio/cxl: Virtualize the CXL DVSEC
Date: Thu, 3 Sep 2026 20:27:46 +0800 [thread overview]
Message-ID: <3dc96249-5103-4b00-8981-5d309ad9e941@linux.alibaba.com> (raw)
In-Reply-To: <20260813093631.2288172-18-mhonap@nvidia.com>
On 8/13/26 5:36 PM, mhonap@nvidia.com wrote:
> From: Manish Honap <mhonap@nvidia.com>
>
> Serve reads of the CXL DVSEC body from the per-open shadow and keep guest
> writes in the shadow rather than letting them reach the hardware, so a
> guest cannot reprogram the device through the DVSEC. Accesses outside the
> CXL DVSEC return -ENODEV and take the default DVSEC handling, so a device
> that also exposes a vendor DVSEC is unaffected.
>
> Route each shadow write through the CXL r4.0 field class rather than
> storing it verbatim: Control stays programmable, Status is
> write-1-to-clear, and Capability, Lock and the Range registers keep their
> firmware snapshot. The guest can no longer set Config Lock or scribble the
> capability and range fields.
>
> Signed-off-by: Manish Honap <mhonap@nvidia.com>
> ---
> drivers/vfio/pci/cxl/vfio_cxl_core.c | 88 ++++++++++++++++++++++++++++
> drivers/vfio/pci/vfio_pci_config.c | 36 +++++++++++-
> include/linux/vfio_pci_core.h | 5 ++
> include/uapi/linux/pci_regs.h | 1 +
> 4 files changed, 129 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/vfio/pci/cxl/vfio_cxl_core.c b/drivers/vfio/pci/cxl/vfio_cxl_core.c
> index 2e516a0929c6..9fed909cb9d3 100644
> --- a/drivers/vfio/pci/cxl/vfio_cxl_core.c
> +++ b/drivers/vfio/pci/cxl/vfio_cxl_core.c
> @@ -148,11 +148,99 @@ static void vfio_cxl_close_device(struct vfio_pci_core_device *vdev)
> cxl->dvsec_shadow = NULL;
> }
>
> +/* Read a 16-bit DVSEC field from the shadow; @off is DVSEC-relative. */
> +static u16 vfio_cxl_dvsec16(struct vfio_cxl_state *cxl, u32 off)
> +{
> + u32 dw = cxl->dvsec_shadow[off / sizeof(u32)];
> +
> + return (dw >> (8 * (off % sizeof(u32)))) & 0xffff;
> +}
> +
> +/*
> + * Apply the CXL r4.0 8.1.3 write class for the 16-bit DVSEC register at @off.
> + * Control is programmable, Status is write-1-to-clear, and Capability, Lock and
> + * the Range registers stay fixed at their firmware snapshot.
> + */
> +static u16 vfio_cxl_dvsec_field(u32 off, u16 old, u16 wval, u16 wmask)
> +{
> + switch (off) {
> + case PCI_DVSEC_CXL_CTRL:
> + /*
> + * CXL.mem stays enabled for as long as the guest owns the device.
> + * The HDM decoder maps the guest window to device memory, so a
> + * store to it while CXL.mem is disabled completes on the device as
> + * an error that the host fabric reports as an SError, which is
> + * fatal. The spec does not pin down accesses to a decoder whose
> + * CXL.mem is off and many hosts SError, so ignore a guest request
> + * to clear the enable and keep the bit set.
> + */
> + return ((old & ~wmask) | (wval & wmask)) | PCI_DVSEC_CXL_MEM_ENABLE;
> + case PCI_DVSEC_CXL_CTRL2:
> + return (old & ~wmask) | (wval & wmask);
Control2 is routed through the r4.0 write class as plain RW,
but both INITIATE bits are self-clearing doorbells per spec: the guest
sets the bit, the device performs the operation and clears it, and
completion is observed in STATUS2 (Cache_Invalid for the WBI). With the
plain-RW class the shadow latches the bit at 1 forever, and because
reads are served from the open-time snapshot, Cache_Invalid
(CXL_DVSEC_STATUS2_CACHE_INVALID) never changes either.
Both polling paths are dead ends.
The interesting part is that the series already models this correctly
for the sibling command bit -- the vfio_cxl_reset() epilogue does:
/*
* The guest-facing DVSEC bookkeeping only applies while the device
* is open. Initiate_CXL_Reset self-clears in hardware; mirror that
* and stamp the outcome onto a fresh hardware STATUS2 read for the
* polling guest.
*/
INIT_CXL_RST is self-cleared in the shadow and the outcome is
stamped into STATUS2 for the polling guest. Initiate_Cache_WBI just
never gets the same treatment.
The polling contract is one this series itself implements on the host
side: cxl_reset_wait_cache_wbi() sets WBI, then polls STATUS2
Cache_Invalid with a 100ms budget. A guest kernel running the same
sequence would set WBI, poll the frozen snapshot, and time out before
ever reaching INIT_CXL_RST, so whether a guest-initiated CXL reset
succeeds depends on the open-time STATUS2 value rather than on device
state. The stuck command bit is also directly visible to any guest
reading CTRL2 back.
Would the minimal fix be to mirror the epilogue's INIT_CXL_RST handling
for WBI: self-clear the bit on the 0->1 write and set Cache_Invalid in
the shadow (the host already runs the real WBI at VM power on/off via
cxl_reset_dvsec_sequence(), and the existing W1C class on STATUS2 lets
the guest clear Cache_Invalid before the next round)? Or is forwarding
the WBI to hardware and keeping Cache_Invalid live the intended
long-term model?
Thanks.
Shuai
next prev parent reply other threads:[~2026-09-03 12:27 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-13 9:36 [PATCH v4 00/27] vfio/pci: Add CXL Type-2 device passthrough support mhonap
2026-08-13 9:36 ` [PATCH v4 01/27] cxl: Fix resource.c include path and export cxl_restore_hdm_after_pci_reset mhonap
2026-08-21 22:52 ` Jonathan Cameron
2026-08-22 1:22 ` Manish Honap
2026-09-03 10:07 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 02/27] cxl/regs: Skip sub-block region request for BAR-owning drivers mhonap
2026-08-25 21:26 ` Alex Williamson
2026-09-03 10:07 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 03/27] cxl: Move component register defines to uapi/cxl/cxl_regs.h mhonap
2026-08-28 15:27 ` Dave Jiang
2026-09-03 10:08 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 04/27] cxl: Establish media readiness in cxl_mem_probe() mhonap
2026-08-25 22:18 ` Alex Williamson
2026-08-28 15:59 ` Dave Jiang
2026-09-03 10:08 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 05/27] cxl: Add a function-scoped reset entry for vfio-pci mhonap
2026-08-25 23:11 ` Alex Williamson
2026-09-03 10:09 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 06/27] vfio/pci: Add CXL ops registration interface mhonap
2026-08-26 21:11 ` Alex Williamson
2026-09-03 10:10 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 07/27] vfio/pci: Detect CXL devices and load vfio-cxl on demand mhonap
2026-08-26 22:17 ` Alex Williamson
2026-09-03 10:10 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 08/27] vfio/cxl: Add the vfio-cxl module skeleton mhonap
2026-08-26 22:50 ` Alex Williamson
2026-09-03 10:11 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 09/27] vfio/cxl: Create the CXL memory device at bind mhonap
2026-08-27 20:43 ` Alex Williamson
2026-09-03 10:11 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 10/27] vfio/cxl: Reject unsupported decoder topologies " mhonap
2026-08-27 20:58 ` Alex Williamson
2026-09-03 10:12 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 11/27] vfio/cxl: Own the whole component register BAR mhonap
2026-08-27 21:13 ` Alex Williamson
2026-09-03 10:12 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 12/27] vfio/pci: Let a provider exclude a BAR sub-range from mmap mhonap
2026-08-27 22:37 ` Alex Williamson
2026-09-03 10:12 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 13/27] vfio/pci: Refuse read/write to an excluded BAR sub-range mhonap
2026-08-13 9:36 ` [PATCH v4 14/27] vfio: Add CXL region type for the HDM region mhonap
2026-08-27 22:43 ` Alex Williamson
2026-09-03 10:13 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 15/27] vfio/pci: Call CXL open and close hooks around device use mhonap
2026-08-27 23:03 ` Alex Williamson
2026-09-03 10:13 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 16/27] vfio/cxl: Shadow the CXL DVSEC body at open mhonap
2026-08-28 15:09 ` Alex Williamson
2026-09-03 10:14 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 17/27] vfio/cxl: Virtualize the CXL DVSEC mhonap
2026-08-28 16:39 ` Alex Williamson
2026-09-03 10:14 ` Manish Honap
2026-09-03 12:27 ` Shuai Xue [this message]
2026-09-03 14:47 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 18/27] vfio/cxl: Expose the HDM memory and trap the decoder registers mhonap
2026-08-28 20:53 ` Alex Williamson
2026-09-03 10:14 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 19/27] vfio/cxl: Keep the HDM decoder block off the direct BAR mapping mhonap
2026-08-13 9:36 ` [PATCH v4 20/27] vfio/cxl: Emulate the HDM decoder commit handshake mhonap
2026-08-13 9:36 ` [PATCH v4 21/27] vfio/cxl: Describe the CXL device and decoder geometry to userspace mhonap
2026-08-13 9:36 ` [PATCH v4 22/27] vfio/cxl: Revoke the HDM mapping on reset and power transitions mhonap
2026-08-28 21:54 ` Alex Williamson
2026-09-03 10:15 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 23/27] vfio/cxl: Refresh the decoder snapshot after a device reset mhonap
2026-08-28 22:33 ` Alex Williamson
2026-09-03 10:15 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 24/27] vfio/cxl: Service a guest-triggered CXL reset mhonap
2026-08-28 23:09 ` Alex Williamson
2026-09-03 10:15 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 25/27] vfio/pci: Provide an opt-out for the CXL Type-2 extensions mhonap
2026-08-28 22:56 ` Alex Williamson
2026-09-03 10:16 ` Manish Honap
2026-08-13 9:36 ` [PATCH v4 26/27] Documentation: vfio-pci: Document CXL Type-2 device passthrough mhonap
2026-08-13 9:36 ` [PATCH v4 27/27] selftests/vfio: Add CXL Type-2 passthrough corner-case tests mhonap
2026-08-26 7:28 ` Shuai Xue
2026-08-26 16:17 ` Manish Honap
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3dc96249-5103-4b00-8981-5d309ad9e941@linux.alibaba.com \
--to=xueshuai@linux.alibaba.com \
--cc=alejandro.lucero-palau@amd.com \
--cc=alex@shazbot.org \
--cc=alison.schofield@intel.com \
--cc=ankita@nvidia.com \
--cc=bhelgaas@google.com \
--cc=cjia@nvidia.com \
--cc=corbet@lwn.net \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=dmatlack@google.com \
--cc=gustavoars@kernel.org \
--cc=iweiny@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jic23@kernel.org \
--cc=kees@kernel.org \
--cc=kevin.tian@intel.com \
--cc=kjaju@nvidia.com \
--cc=kvm@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mhonap@nvidia.com \
--cc=ming.li@zohomail.com \
--cc=skhan@linuxfoundation.org \
--cc=skolothumtho@nvidia.com \
--cc=smadhavan@nvidia.com \
--cc=vishal.l.verma@intel.com \
--cc=vsethi@nvidia.com \
--cc=yishaih@nvidia.com \
--cc=zhiw@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.