From nobody Sun Oct 5 18:41:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1687282181; cv=none; d=zohomail.com; s=zohoarc; b=dVMYfcXJXHo8W0lyEC72/2DU2ILaQy5ARjqARlm9rt88VOvw6lq+/Zt50le2mgPEUVD9XjmeYcGqjCifz5AbJJoT0El/wXUNRF0FkPsYh9dsAKWLJFh7Ohn9lMCJyjyxU9uRObi8S4/Alov4ayM29R8WAbT0Qo4NkZbBvEUb6s0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687282181; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=OHujXKoC6+pvKbdfEDtYmXpzoxjEyy+YGxjQhJLOU0Y=; b=WWuI5qZhonzhwyoch5v0MRRWG+4i+wyIhh27hA3J3k/UPV4Lh7cV4lvbepqM6IaVnqr8W5Wcms/q5dh9TcMiA4sAMX66iPfV6DQpzKJsXMi9zpQ6gqpIWPqChugTgGq+lDFQQsPS0NNa3BSCxzCflolVC+REI/HbQonwtRz/0dY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1687282181917538.6399438642702; Tue, 20 Jun 2023 10:29:41 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.552103.862013 (Exim 4.92) (envelope-from ) id 1qBfAT-0002Gu-6p; Tue, 20 Jun 2023 17:29:25 +0000 Received: by outflank-mailman (output) from mailman id 552103.862013; Tue, 20 Jun 2023 17:29:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qBfAT-0002Fu-1N; Tue, 20 Jun 2023 17:29:25 +0000 Received: by outflank-mailman (input) for mailman id 552103; Tue, 20 Jun 2023 17:29:24 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qBf7k-0004q1-9f for xen-devel@lists.xenproject.org; Tue, 20 Jun 2023 17:26:36 +0000 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [2607:f8b0:4864:20::a36]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9a4881d5-0f8f-11ee-8611-37d641c3527e; Tue, 20 Jun 2023 19:26:34 +0200 (CEST) Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4715758343aso1420761e0c.1 for ; Tue, 20 Jun 2023 10:26:34 -0700 (PDT) Received: from joel-Precision-7920-Tower.. ([24.53.71.1]) by smtp.gmail.com with ESMTPSA id e65-20020a0dc244000000b0056cffe97a11sm604604ywd.13.2023.06.20.10.26.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 10:26:32 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9a4881d5-0f8f-11ee-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687281993; x=1689873993; 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; bh=OHujXKoC6+pvKbdfEDtYmXpzoxjEyy+YGxjQhJLOU0Y=; b=GM+CG3fWRPKOG4chiQRmboIRPep8REP/M8D+0GeYUmtTHRWf/d2klrmsavq5Cp+SFY mXAFc+c517Cql+9sL95wm3ozozHbV5djHykxm4q5KD0NDvXGtC1ci5gDMQklVHI43Hgx t+oy7zCw3J2vA2BJ3qzL6GWWzcGm2cLxOLwt/v1wZy1LBC7ya0d8jYzgjvAluAc/XA02 apVxuVVCddQCVq++rywBUAd7/un/VWrrvZUlvF7NqPObTXgXUSwO+3yOHWRyjSzYNT7Q 7TdzzijFwWvqNgZMM2RnbbVcIe3wCN87Fx5KMzW6GW2mXeAIuTNl0fB/g5pBSAYVpVj1 /TBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687281993; x=1689873993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OHujXKoC6+pvKbdfEDtYmXpzoxjEyy+YGxjQhJLOU0Y=; b=QcStLAMYwZnx7kmRBXauEH2NtL2pSbqN86nZTCM3OdH/UIpxPZEe2MikbvxGGWOEfo SUHByn6FzEea+jRZ4tlug6+cDW5h5MCnXoL7Sz2zTxB3pDHxhRbXdtWVeGmR84TKwS2M ycFK8SU0pQBHbWGDJo6smXZ4kgrpXCFaP8pvO87W1YQqivMD1QkFMYmzABsJMzcoZq5c wPN/1X5Y6WCOlxdE0dngAOixUxEDtBbaehrxfwYxlUvqhL9/9W7XOtu6eoLxSDQaLz5W 7CardVHvWz9CdWYl9d2J8/1EQRwu3s6GwcvgQ01PMTTMYqhsOMgCeRX+p/KtHbtelILb bzMQ== X-Gm-Message-State: AC+VfDyRfPvbvhleWetcjyqsCQk8jn5zFlnsGMs4KbjgiecUxTZ8Xyqh l//aE0A1k6Lb4D7zGygNxdE= X-Google-Smtp-Source: ACHHUZ5QiJc1oXfSp4p9cZik4NYdz6sPHMrvS71pbTKO/RMTg1uRBBt5TM62D7CH5DnCPiKqY10dDg== X-Received: by 2002:a1f:5c93:0:b0:464:7682:3506 with SMTP id q141-20020a1f5c93000000b0046476823506mr4435739vkb.12.1687281993305; Tue, 20 Jun 2023 10:26:33 -0700 (PDT) From: Joel Upham To: qemu-devel@nongnu.org Cc: Joel Upham , Stefano Stabellini , Anthony Perard , Paul Durrant , xen-devel@lists.xenproject.org (open list:X86 Xen CPUs) Subject: [PATCH v1 19/23] xen/pt: Fake capability id Date: Tue, 20 Jun 2023 13:24:53 -0400 Message-Id: <65b91216c1337b560548f39978d41c988b498517.1687278381.git.jupham125@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1687282182352100001 Content-Type: text/plain; charset="utf-8" Some PCIe capabilities needed to be faked for the xen implementation to wor= k. This is the situation when we were asked to hide (aka "hardwire to 0") some PCIe ext capability, but it was located at offset 0x100 in PCIe config space. In this case we can't simply exclude it from the linked list of capabilities (as it is the first entry in the list), so we must fake its Capability ID in PCIe Extended Capability header, leaving the Next Ptr field intact while returning zeroes on attempts to read capability body (writes are ignored). Signed-off-by: Alexey Gerasimenko Signed-off-by: Joel Upham --- hw/xen/xen_pt_config_init.c | 72 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index 4e14adf2b2..41b43b9445 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -16,6 +16,7 @@ #include "qapi/error.h" #include "qemu/timer.h" #include "xen_pt.h" +#include "xen-host-pci-device.h" #include "hw/xen/xen-legacy-backend.h" =20 #define XEN_PT_MERGE_VALUE(value, data, val_mask) \ @@ -31,6 +32,10 @@ static int xen_pt_ext_cap_ptr_reg_init(XenPCIPassthrough= State *s, XenPTRegInfo *reg, uint32_t real_offset, uint32_t *data); +static int xen_pt_ext_cap_capid_reg_init(XenPCIPassthroughState *s, + XenPTRegInfo *reg, + uint32_t real_offset, + uint32_t *data); =20 /* helper */ =20 @@ -995,6 +1000,17 @@ static XenPTRegInfo xen_pt_emu_reg_pcie[] =3D { .u.b.read =3D xen_pt_byte_reg_read, .u.b.write =3D xen_pt_byte_reg_write, }, + /* PCI Express Capabilities Register */ + { + .offset =3D PCI_EXP_FLAGS, + .size =3D 2, + .init_val =3D 0x0000, + .ro_mask =3D 0xFFFF, + .emu_mask =3D 0xFFFF, + .init =3D xen_pt_pcie_capabilities_reg_init, + .u.w.read =3D xen_pt_word_reg_read, + .u.w.write =3D xen_pt_word_reg_write, + }, /* Device Capabilities reg */ { .offset =3D PCI_EXP_DEVCAP, @@ -1633,6 +1649,54 @@ static XenPTRegInfo xen_pt_emu_reg_igd_opregion[] = =3D { }, }; =20 +/**************************** + * Emulated registers for + * PCIe Extended Capabilities + */ + +static uint16_t fake_cap_id =3D XEN_PCIE_FAKE_CAP_ID_BASE; + +/* PCIe Extended Capability ID reg */ +static int xen_pt_ext_cap_capid_reg_init(XenPCIPassthroughState *s, + XenPTRegInfo *reg, + uint32_t real_offset, + uint32_t *data) +{ + uint16_t reg_field; + int rc; + XenPTRegGroup *reg_grp_entry =3D NULL; + + /* use real device register's value as initial value */ + rc =3D xen_host_pci_get_word(&s->real_device, real_offset, ®_field); + if (rc) { + return rc; + } + + reg_grp_entry =3D xen_pt_find_reg_grp(s, real_offset); + + if (reg_grp_entry) { + if (reg_grp_entry->reg_grp->grp_type =3D=3D XEN_PT_GRP_TYPE_HARDWI= RED && + reg_grp_entry->base_offset =3D=3D PCI_CONFIG_SPACE_SIZE) { + /* + * This is the situation when we were asked to hide (aka + * "hardwire to 0") some PCIe ext capability, but it was locat= ed + * at offset 0x100 in PCIe config space. In this case we can't + * simply exclude it from the linked list of capabilities + * (as it is the first entry in the list), so we must fake its + * Capability ID in PCIe Extended Capability header, leaving + * the Next Ptr field intact while returning zeroes on attempts + * to read capability body (writes are ignored). + */ + reg_field =3D fake_cap_id; + /* increment the value in order to have unique Capability IDs = */ + fake_cap_id++; + } + } + + *data =3D reg_field; + return 0; +} + /* Vendor-specific Ext Capability Structure reg static information table */ static XenPTRegInfo xen_pt_ext_cap_emu_reg_vendor[] =3D { { @@ -2938,7 +3002,13 @@ void xen_pt_config_init(XenPCIPassthroughState *s, E= rror **errp) } } =20 - if (xen_pt_emu_reg_grps[i].grp_type =3D=3D XEN_PT_GRP_TYPE_EMU) { + if (xen_pt_emu_reg_grps[i].grp_type =3D=3D XEN_PT_GRP_TYPE_EMU || + /* + * We need to always emulate the PCIe Extended Capability + * header for a hidden capability which starts at offset 0x100 + */ + (xen_pt_emu_reg_grps[i].grp_type =3D=3D XEN_PT_GRP_TYPE_HARDWI= RED && + reg_grp_offset =3D=3D 0x100)) { if (xen_pt_emu_reg_grps[i].emu_regs) { int j =3D 0; XenPTRegInfo *regs =3D xen_pt_emu_reg_grps[i].emu_regs; --=20 2.34.1