From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.154 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796331341; b=ct8+MXcmDsyrCHeHaSGChdYPcCu10XD+o880A5qm9kw+i6V5vZw3nQRoBVvEvxJedZ2M Bu6GC8qub7aCJHcaCQ9LSoMATiYvqS217jm9y5kviJtANZ4ekAv57zsIVTm1sYGMGQFge wNLWjjN73h+Z7AmWUFwrju1f2qBROgUT9hKR5sYyIS1hf7hoF1wDe/DQK42hw90o4NHeC plXJlpxIyYeBH21Bw8cP5QLwB2uKIQmEzDzrZVJXHvU1etJ5DesffEU7vMgpc7V3PT7k4 qIxu9IXXahI9GrW1Qs53JRs5rkN3oq3TIi9GCcbcBBJhA2SWX+Arbaj6r22UuEvqRAA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331341; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: X-Mailer:MIME-Version:Content-Type:Content-Transfer-Encoding; bh=mHlZgxoEGR6MBQheWL105RrqiscNwdwFsvysjXaVL5g=; b=bcIQ/n/7M+5ZqMF2RcL/AGE7LxuerDMpEJAGSHq1Sz/g0iDUYHx9yhUtDTbxnh6AUYfL GsznoidCUkSHeZd9GPNhMbgkwFLAlMy0uC/UvIkyo7zkMtZwXAVcVpM99GdF8d9/JhUUS nMFd9hjAF3K8Tw4JfY7DTiLwlaYOONB9ns52PWMparUkm6s+jZ9+pVX2WPQkDP79uDWhg zNcMOXz8Zi+/MMvN5MU42V4SpPWDB6BGlXo3N/mCjbGibZ7ZV0MSjPomRg2+rrqWfwBx4 wfkzl7dbz9sBxCfFg8yZefpeB1ugDS3ICpOqie16BSxnb/6xNhiW8UwdxNMSWqyzlKg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=shazbot.org; spf=pass smtp.mailfrom=shazbot.org; dkim=pass header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=V7tOPRTE; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=zQuVPHLO; arc=none smtp.remote-ip=202.12.124.154 Received: from fhigh-b3-smtp.messagingengine.com (fhigh-b3-smtp.messagingengine.com [202.12.124.154]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F3449606A684 for ; Thu, 3 Dec 2026 20:55:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F3449606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=shazbot.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=shazbot.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=shazbot.org header.i=@shazbot.org header.a=rsa-sha256 header.s=fm3 header.b=V7tOPRTE; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=zQuVPHLO Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 534B57A0141 for ; Thu, 3 Dec 2026 15:55:39 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 03 Dec 2026 15:55:39 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=shazbot.org; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1796331338; x=1796417738; bh=mHlZgxoEGR6MBQheWL105RrqiscNwdwFsvysjXaVL5g=; b= V7tOPRTEnHTODaYxvj+ALdJ/zCVzOQOgXRRRvtx1TewU3D5g9BKL5bSyzqQG6ibH jkHl6qMYX17sv0O72w2yKbtYV2bGMtq9wko8xc3nAVthV9Et5sCf1n5C+JC1MnS5 PsHVEBtor6N/gRGfamB/JNlgHyuEaehA1PEekKZfQgadazi12dMEgRx6kWjRTBl9 bHTz9AztcJFT7C04lQnECIk1oC1o90TzQQB4b83lNrP58/KvBiA438KGP1K+PDk4 kaIP6r8Pba1XZs4PTAIHBHSRg9QYOUb827Z5KDUfWuf0Lat3DsXuPIGNVL+BqMJL dRkX7EogEpzdmo99K0XUrQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1796331338; x= 1796417738; bh=mHlZgxoEGR6MBQheWL105RrqiscNwdwFsvysjXaVL5g=; b=z QuVPHLOvoPz+PiXC92M4v5SKbWE93cqpHR09MpB068uwPV9wuQAOG29sW4b8Qv9+ oWkNV7DqoNrUQivlUoK3avT06yTbLbh3zJImgizSjQXjqr9f62V1U+5vZwtLzec+ 4tm9bnkYsRuiYav5btbf0ZwxW31CjWazDJ0eQOBXWOhBzzXF0R/8e1Z51yKo4b0O gIugyL/6USN36HVTg+5ToPcm1ehKJS/srgz91gtMbmJEvQs7vXMvEZhAeXBiJudZ le4tV2utu4BWkZBzPrI9yQ+3zZBYTflRqXr18nRuQQBUITsq5AfLA9qaXJeUWVyo 4tfxPn/YCdymHJ+ntpa0w== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=shazbot.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796331338; d=shazbot.org; mf=PGFsZXhAc2hhemJvdC5vcmc+; rt=PGt2bUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:Ar+ckIY8Sg9pGXG+NJmICMF+ys3lk++RrqT+EMa6h/zr5tW sbLgYfIWxUKuHKbE+aRWcou6UZBZv+JR9loX5jZL8kkS2d/D2Aewsj0zDvMgQKGr NGkNv5qVNUkoycNKWztWV1xZL8/NKrJP99eobVRB+STmpwwC6Q0UyPsLx5viNryz GQp0gbXyyDHjSRG4mOdjzAPZLJV4Oo4cpw1nG722ixP08fHqysH8JwuYgMldwwy4 nTbMkkw8ukjKwXdlIRCQUUObakhjYDey/imAKfLOz0Em3Bwf8W2WELa6mq+SqL6e j3dNU36de71mwhcgfzc5txS8gk4o25NsPi83OcA==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=12; hn=cc,content-transfer-encoding,content-type,date,feedback-id, from,in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:hOK6PCERhakFLiZ6O11eofqEugAZZZWQbkkfAsyQDwU=:bO17/eIvb6OGtiPAtQfPXHozBwZVKZN4ynjdKA8jyCE=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE1YGIKon4u96g0tFg+qEvELSvnw5bkeCo5iKZ9/tqiyf5m2bsFMzA11nICIIRW0u nvtdXFSB3jSXCsW3Oxn+rZgGZ/W29W6ziLlLpetJSI3fYSVvVtv+KiVQNan79y6U28b696 Qdqi+5z7R3v9MED/RiMDO3kq2+ttY1poKh22OQ6IHmh9nDThEYJXffaIPsFrCyT6pWA1rV emDF3IGD4Oc2zeB3Jddoj2Y5h8y6vl01k2jny42vgq7TmZEqq687WhiAbNZPQgBzJ1mSWy pDiZKZSXc9GX2Kp5UFx5fz0mozw0wm/TIgRY9k5dffOdVSZi8/eDxgyXaoDCcXqSGP2ZcJ e35MQzCO5lCFalJFRJL5/zISfKAXqfaayOeZIZ5Oq0TesfnMFUDhwitCAkTPrV88/x/N8u 20UYHb72RkNuDRSjWIUiYKNvQiBljpYRiUJ9fxfuND2uV1PaRWoVhKAMY+Jl1RiXDRHVbY BDXrZIy+i2f6jJHy2cBfXHJIf1Dk7MNNba3+zIsk7ctqf32axEUSl8FcCyF5n/esOkyc0O zjKMplnwcYzH0LlhKfdOlq0nOWSuJ83HwBRXPDa7X9IQFXx9Fiu0xefu9Pt2ouzdB3ec1+ yXI3/95QYu6JnJTCzcfz2Ks/exBOchaUkL0DwJV0avFuCp7oyLIox3wo4eqw X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 15:55:37 -0500 (EST) Date: Thu, 3 Dec 2026 13:55:36 -0700 From: Alex Williamson To: Cc: , , , , , alex@shazbot.org Subject: Re: [PATCH 2/2] vfio/pci: Make the CXL DVSEC read-only Message-ID: <20261203135536.7bd80320@shazbot.org> In-Reply-To: <20261202091105.1674275-3-mhonap@nvidia.com> References: <20261202091105.1674275-1-mhonap@nvidia.com> <20261202091105.1674275-3-mhonap@nvidia.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 2 Dec 2026 14:41:05 +0530 wrote: > From: Manish Honap > > Since commit 6467d0740a2b ("vfio/pci: Add DVSEC PCI Extended Config > Capability to user visible list."), vfio-pci passes user writes to > every DVSEC through to the device. Before that commit DVSECs were > hidden. > > For a function that is CXL.cache and CXL.mem capable, the user can then: > - clear Cache_Enable or Mem_Enable in DVSEC Control, > - set Initiate CXL Reset or Initiate Cache Writeback and Invalidation > in DVSEC Control2, which the host does not see or handle, > - write the DVSEC Range registers, > - set Config Lock, after which the host cannot change the locked > registers. > > This change keeps the CXL Device DVSEC visible and makes it read-only: > reads return the device values and writes are dropped. The capability is > matched by its start, so a CXL DVSEC that directly follows another DVSEC > relies on the earlier patch to correctly calculate start of abutting > capabilities. "earlier patch" is only relevant to the series on the mailing list, not to the commit once merged. > Fixes: 6467d0740a2b ("vfio/pci: Add DVSEC PCI Extended Config Capability to user visible list.") > Signed-off-by: Manish Honap > --- > drivers/vfio/pci/vfio_pci_config.c | 23 +++++++++++++++++++++++ > include/linux/vfio_pci_core.h | 1 + > 2 files changed, 24 insertions(+) > > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c > index dd0b899fbdfd..2bc0c7cbc4b7 100644 > --- a/drivers/vfio/pci/vfio_pci_config.c > +++ b/drivers/vfio/pci/vfio_pci_config.c > @@ -1746,6 +1746,23 @@ static int vfio_ecap_init(struct vfio_pci_core_device *vdev) > return 0; > } > > +static u16 vfio_pci_cxl_dvsec(struct pci_dev *pdev) > +{ > + u16 dvsec, cap; > + > + dvsec = pci_find_dvsec_capability(pdev, PCI_VENDOR_ID_CXL, > + PCI_DVSEC_CXL_DEVICE); > + if (!dvsec || > + pci_read_config_word(pdev, dvsec + PCI_DVSEC_CXL_CAP, &cap)) > + return 0; > + > + if (!(cap & PCI_DVSEC_CXL_CACHE_CAPABLE) || > + !(cap & PCI_DVSEC_CXL_MEM_CAPABLE)) > + return 0; Have we actually checked whether type 1 or 3 expose unsafe accesses through the CXL DVSEC or are we only focused on type 2? > + > + return dvsec; > +} > + > /* > * Nag about hardware bugs, hopefully to have vendors fix them, but at least > * to collect a list of dependencies for the VF INTx pin quirk below. > @@ -1863,6 +1880,8 @@ int vfio_config_init(struct vfio_pci_core_device *vdev) > if (ret) > goto out; > > + vdev->cxl_dvsec = vfio_pci_cxl_dvsec(vdev->pdev); > + This belongs in vfio_ecap_init(), probably after we've checked for collision in the pci_config_map: if (ecap == PCI_EXT_CAP_ID_DVSEC) { u16 cxl_dvsec = vfio_pci_probe_cxl_dvsec(pdev, epos); if (cxl_dvsec) { if (vdev->cxl_dvsec) pci_warn(pdev, "Device contains multiple CXL DVSEC capabilities\n"); vdev->cxl_dvsec = cxl_dvsec; } } The suggested probe would unfortunately duplicate the read and check of the DVSEC headers, but this seems like the logical place to test and add since we've already got a DVSEC in hand. > return 0; > > out: > @@ -1953,6 +1972,10 @@ ssize_t vfio_pci_config_rw_single(struct vfio_pci_core_device *vdev, > perm = &ecap_perms[cap_id]; > > cap_start = vfio_find_cap_start(vdev, *ppos); > + > + if (cap_id == PCI_EXT_CAP_ID_DVSEC && > + cap_start == vdev->cxl_dvsec) > + perm = &direct_ro_perms; This is basically just open coding in the rw dispatch handler what should be done in a perm writefn. Define a writefn for this: static int vfio_dvsec_config_write(struct vfio_pci_core_device *vdev, int pos, int count, struct perm_bits *perm, int offset, __le32 val) { if (pos - offset == vdev->cxl_dvsec) return count; return vfio_raw_config_write(vdev, pos, count, perm, offset, val); } Set the PCI_EXT_CAP_ID_DVSEC writefn to this new function. > } else { > WARN_ON(cap_id > PCI_CAP_ID_MAX); > > diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h > index 2f3fa2787737..dc25f737fe93 100644 > --- a/include/linux/vfio_pci_core.h > +++ b/include/linux/vfio_pci_core.h > @@ -109,6 +109,7 @@ struct vfio_pci_core_device { > u8 *pci_config_map; > u8 *vconfig; > struct perm_bits *msi_perm; > + u16 cxl_dvsec; > spinlock_t irqlock; > struct mutex igate; > struct xarray ctx; This adds a hole in the structure. There's an existing gap after ioeventfds_nr. Thanks, Alex