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=1796331335; b=Kem7Eji0Jf/lVj7tD3yGOt2mezxqHt1nEu3rPnvpmGUUNtYQymoV/5CMEAEBJOV+whZp NhOw5QIcURtrcJOb+JbvIs+XeQqex+K0jaIl7VQqM4xW1RnoqxtE+Iotg8sMLISpdk0/O TmRmY2PejJfe/RzyIYPNDJbxJi6gZSssQjd18/P7DWCdCwamOI5NsC1/2UBfy7oHwx44Z MN4qK60O5Z2tOxm1Uya7sC0trQKBGVhleCqQj2C75+QSWrBuUN2QqlrHsVXTFUfQm88/h zSTaqKqbYHYUUog8r/Rfvdv0mwwP4+vLlIna9Q8KMwRh9qflBg+XzqVW9Min1pwZfWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796331335; 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=XZtTlfw0rALJofiiUPh4A+ZLzY0STGCtZAE5oCo7kdc=; b=Khmj3Ls/Guo/55RJAvPYwmIP91IG1kgIDZCGVpSxgtyc++kdNA3ayvC3Ggfb8uICf4+k moZ0eaKZX2lKwCxvx4Wf5LneAZRcDmyCZuJ8/ZiT513rbmTu1NFmBjXZYIIkXME/eLuTk icB2wvFI28Wknn4/EcBNNI/uzDXvTMXQvn0RahuD2NSiUiOA7alNzYgatHc69TPlXeGmd h8ZiydCDkEFinJqJTx7C9gUXBrwgXOl3EFhLhswTqObtx0gwkZ9zyOSgmR8tQOftOBUdb tLiTlquHe2ajaJDoTjMIuo5yv8YJePPdgxg99frUTYHXOlPew4Snv5fDtyt4A6XwxXA== 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=RjYiSuyM; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ItPRGJ0I; 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) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFF4E606A681 for ; Thu, 3 Dec 2026 20:55:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EFF4E606A681 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=RjYiSuyM; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ItPRGJ0I Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 22CE87A0149 for ; Thu, 3 Dec 2026 15:55:33 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Thu, 03 Dec 2026 15:55:33 -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=1796331332; x=1796417732; bh=XZtTlfw0rALJofiiUPh4A+ZLzY0STGCtZAE5oCo7kdc=; b= RjYiSuyM7WqfcneRXgvWnqyEgMoNz1zi477Cgdacc+8eyC7ehOvVUENOQAjIfsiq MMYD2FDv2sU7Fy3flqcDUaadaptenxTEsSJJEiPb9csdenPS1b7ttmcmUCFqrwLT 6g5QYlmJXg40UVqmgdov5Oas2F94n0u7WK2zoKqDx0Y5X4JrluSh8wMjdJ8AIkUr iUqBITdEddkSk5NJoLqbBfx+v9MKjdEtn4SLZPf+IQ5nbkjYItU6v2PvKi9JHRo9 oBamLQ23AeOjeBtfhquBjgXRylP9oS2VujFyHS4eSNVYXUHjWX2tCZWC5SJEeLU/ dV6nErdhfR7c8Qs++gnOaA== 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=1796331332; x= 1796417732; bh=XZtTlfw0rALJofiiUPh4A+ZLzY0STGCtZAE5oCo7kdc=; b=I tPRGJ0I+hhZ2WiuqhK6u7oUKWekBdamQ1FNPcelp3z15uIB9aoF+DgnTb+jp/HkH P+xNLCaVxI9ckgfjIvvW7R8AKpDgVmRa0GlouIzTPRva5aHIDfs+GNEDt1TrBbVJ Twtdal/7ZZUJFRrIeJHD/+OySwWgk2ZMc9g8F2Ve4J/jeWXjnV8hXf8FiGPnMnq4 5sBZQcw7e+G8e7DZtvjIf2rvrazJsqTKiLPxZ/OJwTyDFB+1gRoT3Y6L+BgU2yjA xcNu8epEY0nxaKGl2D0BK6C0ta931JeLxbfBeUQmU0T91KIpyw25onm1f43tWPZZ tT7jUARjTAbGhvr0cBlNA== 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=1796331332; d=shazbot.org; mf=PGFsZXhAc2hhemJvdC5vcmc+; rt=PGxpbnV4LWN4bEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:FRUylZYCM3o/9BDD3LwJAq6lwbstCd4AkAaBbOIsBuUPQ3O 3lUkr/ZXs+cRSwiByMt3CVnND1XAad3K7Qgz5hrzxlecmm5q8Ba1l2Gkd2nJdSVG 2mtVix3RQPVUe+w4o0gWNXWzuHI1ZHH2dyZsOY6TMn+es02sCnCXZ5Mf2brUzFXk yyGplqL54kh2doSPIhgdCy7XnB5yZZai6GMQ5gqXagzSwmMMkLIrmTtApXHMX5T+ 0dLqgUUjmUGI+5qtpRzEldbKD3ujdVWxHMaaXdNrHzwueUiuti/hq46Hedl9yGfk 9upeJg7drAfsZD8j29A38NEXoY1s2GlN4Q+tCuw==; 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:QglkG2M004vlCgWks8qFlgl8y2t/ELqCwg+/9OPvTxU=:0k1MLkfIgEOHmCiXhiUl6bp8qVk3dE7nt52PM0FjepY=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTF/CsyjeaDabj6XXlTRfqMvZeHAJB1LjZI6Tq2/z/0c+t7p945IB8XFAbLhLWa3GI 2veYifFIoAwK0566voAGTXXPbZAaPqBfGygppjumxGDDSv/KY9tMC0J7VFg+y+UrA09FGo FVso++GXmoAswexL2UU5u07n30eanUKFBHOUjtCzl4BtqybPhIGqFVyYMgBDgl3TPKekXE EuZghyp5lVcmHkSNf0UOs0I8gDHEJTyO/KUSBUFLRGkHVZyzwcLmtMvtktYH3Fb8fKXetP PosCKleljG4PnGD0n3zgu+mhoBan4hfvgwR6s6g9pAZ8pGAXQmelri8z4QCyQTJU0IXwXZ +jkxFdV5zO5FxI1BSB2H6qe+ZLGK62xQ0+TWU9ZYtFo3XtEsd8huL0bzHOEGSrdUo07c1s LJXt2QCwa8+fWDNck1PJqAZ8vzL/HzoXvFNt8Iza8mlxnZGYJYpiWijX3HOBP8o2/Owe6d IFRApJ+DZJVlnjihcWCvoww+pmquTJMrjMNNFSlgE4O71ylW2cMOFnEciS4ftLfbkn9eNA UjcEw9daBy6Rtro3t2PT/bt/vOcjVvwNWirllhc2ZYj41s/SXu3JK7glKKXZR9COwMAYJS QId+rEWFU7djAV3fb3SdW64OUSkjB64jOPLMCyGrKsvX3ddVFAMSHrz4nOuQ X-ME-Proxy: Feedback-ID: i03f14258:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 3 Dec 2026 15:55:31 -0500 (EST) Date: Thu, 3 Dec 2026 13:55:29 -0700 From: Alex Williamson To: Cc: , , , , , alex@shazbot.org Subject: Re: [PATCH 1/2] vfio/pci: Find the start of an abutting extended capability Message-ID: <20261203135529.2f28ff30@shazbot.org> In-Reply-To: <20261202091105.1674275-2-mhonap@nvidia.com> References: <20261202091105.1674275-1-mhonap@nvidia.com> <20261202091105.1674275-2-mhonap@nvidia.com> X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-pc-linux-gnu) X-Mailing-List: linux-cxl@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:04 +0530 wrote: > From: Manish Honap > > vfio_find_cap_start() walks through pci_config_map while the bytes hold > same capability ID. When two DVSEC's are back-to-back, we cannot > correctly tell what is the start of second capability. Due to this > the offset into the second capability resolves to the start of first > capability. Yes, but what issue results from that? AIUI, it breaks virtualization of the next cap offset, so we don't provide the capability chain we intended to. Config space outside a capability has direct access, and so does the DVSEC capability, so the bug is that we've jumped from the virtualized to the physical capability chain. > For above case, walk the extended vconfig capability chain for > determining the correct start of the abutting capabilities. > > Standard capabilities keep the walk back through the map. Why, it has the same problem and we're even ignoring the comment that raises this exact question. Standard config space has fewer options where a capability can have multiple instances, but the vendor specific capability is at least one that could generate the same issue. Needs a Fixes: tag, probably pointing back to the original XXX comment below 89e1f7d4c66d. > Signed-off-by: Manish Honap > --- > drivers/vfio/pci/vfio_pci_config.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/drivers/vfio/pci/vfio_pci_config.c b/drivers/vfio/pci/vfio_pci_config.c > index 9914f3ac69ae..dd0b899fbdfd 100644 > --- a/drivers/vfio/pci/vfio_pci_config.c > +++ b/drivers/vfio/pci/vfio_pci_config.c > @@ -1129,6 +1129,23 @@ int __init vfio_pci_init_perm_bits(void) > return ret; > } > > +static int vfio_find_ecap_start(struct vfio_pci_core_device *vdev, int pos) > +{ > + struct pci_dev *pdev = vdev->pdev; > + int loops = (pdev->cfg_size - PCI_CFG_SPACE_SIZE) / PCI_CAP_SIZEOF; > + int epos = PCI_CFG_SPACE_SIZE, start = PCI_CFG_SPACE_SIZE; > + > + while (loops-- && epos >= PCI_CFG_SPACE_SIZE) { > + u32 header = le32_to_cpu(*(__le32 *)&vdev->vconfig[epos]); > + > + if (epos <= pos && epos > start) > + start = epos; > + epos = PCI_EXT_CAP_NEXT(header); > + } > + > + return start; > +} > + > static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos) > { > u8 cap; > @@ -1139,6 +1156,10 @@ static int vfio_find_cap_start(struct vfio_pci_core_device *vdev, int pos) > if (cap == PCI_CAP_ID_BASIC) > return 0; > > + /* Abutting DVSECs share one map ID */ Any abutting capability shares the same ID in the map. Don't focus on only the capability you're tripping on. > + if (pos >= PCI_CFG_SPACE_SIZE) > + return vfio_find_ecap_start(vdev, pos); > + > /* XXX Can we have to abutting capabilities of the same type? */ > while (pos - 1 >= base && vdev->pci_config_map[pos - 1] == cap) > pos--; Address this with a standard capability version of the same. The loop can then go away. It might also be worth adding a WARN_ON_ONCE(cap >= PCI_CAP_ID_INVALID_VIRT) prior to either since those dummy IDs live outside capability chains. Thanks, Alex