From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jiqian Chen <Jiqian.Chen@amd.com>
Cc: xen-devel@lists.xenproject.org, Huang Rui <ray.huang@amd.com>
Subject: Re: [PATCH v4 02/10] vpci/header: Emulate legacy capability list for dom0
Date: Thu, 15 May 2025 18:29:58 +0200 [thread overview]
Message-ID: <aCYWhmUBa_AyYh6N@macbook.lan> (raw)
In-Reply-To: <20250509090542.2199676-3-Jiqian.Chen@amd.com>
On Fri, May 09, 2025 at 05:05:34PM +0800, Jiqian Chen wrote:
> Current logic of emulating legacy capability list is only for domU.
> So, expand it to emulate for dom0 too. Then it will be easy to hide
> a capability whose initialization fails in a function.
>
> And restrict adding PCI_STATUS register only for domU since dom0
> has no limitation to access that register.
>
> Signed-off-by: Jiqian Chen <Jiqian.Chen@amd.com>
> ---
> cc: "Roger Pau Monné" <roger.pau@citrix.com>
> ---
> v3->v4 changes:
> * Also pass supported_caps to pci_find_next_cap_ttl() for dom0 since the n is zero when dom0,
> and add a comment to explain it.
> * Restrict adding PCI_STATUS register only for domU since dom0 has no limitation to access that register.
> * For dom0 register handler, set vpci_hw_write8 to it instead of NULL.
>
> v2->v3 changes:
> * Not to add handler of PCI_CAP_LIST_ID when domain is dom0.
>
> v1->v2 changes:
> new patch.
>
> Best regards,
> Jiqian Chen.
> ---
> xen/drivers/vpci/header.c | 53 ++++++++++++++++++++++++---------------
> xen/drivers/vpci/vpci.c | 6 +++++
> xen/include/xen/vpci.h | 2 ++
> 3 files changed, 41 insertions(+), 20 deletions(-)
>
> diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
> index 3e9b44454b43..a06c518c506c 100644
> --- a/xen/drivers/vpci/header.c
> +++ b/xen/drivers/vpci/header.c
> @@ -749,9 +749,9 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
> {
> int rc;
> bool mask_cap_list = false;
> + bool is_hwdom = is_hardware_domain(pdev->domain);
>
> - if ( !is_hardware_domain(pdev->domain) &&
> - pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST )
> + if ( pci_conf_read16(pdev->sbdf, PCI_STATUS) & PCI_STATUS_CAP_LIST )
> {
> /* Only expose capabilities to the guest that vPCI can handle. */
> unsigned int next, ttl = 48;
> @@ -759,12 +759,18 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
> PCI_CAP_ID_MSI,
> PCI_CAP_ID_MSIX,
> };
> + /*
> + * For dom0, we should expose all capabilities instead of a fixed
> + * capabilities array, so setting n to 0 here is to get the next
> + * capability position directly in pci_find_next_cap_ttl.
> + */
> + const unsigned int n = is_hwdom ? 0 : ARRAY_SIZE(supported_caps);
>
> next = pci_find_next_cap_ttl(pdev->sbdf, PCI_CAPABILITY_LIST,
> - supported_caps,
> - ARRAY_SIZE(supported_caps), &ttl);
> + supported_caps, n, &ttl);
>
> - rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
> + rc = vpci_add_register(pdev->vpci, vpci_read_val,
> + is_hwdom ? vpci_hw_write8 : NULL,
> PCI_CAPABILITY_LIST, 1,
> (void *)(uintptr_t)next);
> if ( rc )
> @@ -772,7 +778,7 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
>
> next &= ~3;
>
> - if ( !next )
> + if ( !next && !is_hwdom )
> /*
> * If we don't have any supported capabilities to expose to the
> * guest, mask the PCI_STATUS_CAP_LIST bit in the status
> @@ -786,15 +792,18 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
>
> next = pci_find_next_cap_ttl(pdev->sbdf,
> pos + PCI_CAP_LIST_NEXT,
> - supported_caps,
> - ARRAY_SIZE(supported_caps), &ttl);
> + supported_caps, n, &ttl);
>
> - rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
> - pos + PCI_CAP_LIST_ID, 1, NULL);
> - if ( rc )
> - return rc;
> + if ( !is_hwdom )
> + {
> + rc = vpci_add_register(pdev->vpci, vpci_hw_read8, NULL,
> + pos + PCI_CAP_LIST_ID, 1, NULL);
> + if ( rc )
> + return rc;
> + }
>
> - rc = vpci_add_register(pdev->vpci, vpci_read_val, NULL,
> + rc = vpci_add_register(pdev->vpci, vpci_read_val,
> + is_hwdom ? vpci_hw_write8 : NULL,
> pos + PCI_CAP_LIST_NEXT, 1,
> (void *)(uintptr_t)next);
> if ( rc )
> @@ -805,13 +814,17 @@ static int vpci_init_capability_list(struct pci_dev *pdev)
> }
>
> /* Utilize rsvdp_mask to hide PCI_STATUS_CAP_LIST from the guest. */
> - return vpci_add_register_mask(pdev->vpci, vpci_hw_read16, vpci_hw_write16,
> - PCI_STATUS, 2, NULL,
> - PCI_STATUS_RO_MASK &
> - ~(mask_cap_list ? PCI_STATUS_CAP_LIST : 0),
> - PCI_STATUS_RW1C_MASK,
> - mask_cap_list ? PCI_STATUS_CAP_LIST : 0,
> - PCI_STATUS_RSVDZ_MASK);
> + return is_hwdom ? 0 : vpci_add_register_mask(pdev->vpci, vpci_hw_read16,
> + vpci_hw_write16, PCI_STATUS,
> + 2, NULL,
> + PCI_STATUS_RO_MASK &
> + ~(mask_cap_list ?
> + PCI_STATUS_CAP_LIST :
> + 0),
> + PCI_STATUS_RW1C_MASK,
> + mask_cap_list ?
> + PCI_STATUS_CAP_LIST : 0,
> + PCI_STATUS_RSVDZ_MASK);
Wow, that's a bit too much indentation for my taste. Do you think you
could do:
/* Return early for the hw domain, no masking of PCI_STATUS. */
if ( is_hwdom )
return 0;
...
So that you don't have to touch the current return chunk?
Thanks, Roger.
next prev parent reply other threads:[~2025-05-15 16:30 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-09 9:05 [PATCH v4 00/10] Support hiding capability when its initialization fails Jiqian Chen
2025-05-09 9:05 ` [PATCH v4 01/10] vpci/header: Move emulating cap list logic into new function Jiqian Chen
2025-05-09 9:05 ` [PATCH v4 02/10] vpci/header: Emulate legacy capability list for dom0 Jiqian Chen
2025-05-15 16:29 ` Roger Pau Monné [this message]
2025-05-16 2:33 ` Chen, Jiqian
2025-05-09 9:05 ` [PATCH v4 03/10] vpci/header: Emulate extended " Jiqian Chen
2025-05-18 14:20 ` Jan Beulich
2025-05-19 6:43 ` Chen, Jiqian
2025-05-19 6:56 ` Jan Beulich
2025-05-19 7:13 ` Chen, Jiqian
2025-05-19 13:10 ` Jan Beulich
2025-05-19 13:21 ` Roger Pau Monné
2025-05-21 6:08 ` Chen, Jiqian
2025-05-21 6:25 ` Jan Beulich
2025-05-21 6:44 ` Chen, Jiqian
2025-05-09 9:05 ` [PATCH v4 04/10] vpci: Refactor REGISTER_VPCI_INIT Jiqian Chen
2025-05-18 14:34 ` Jan Beulich
2025-05-19 6:56 ` Chen, Jiqian
2025-05-19 13:07 ` Jan Beulich
2025-05-09 9:05 ` [PATCH v4 05/10] vpci: Hide legacy capability when it fails to initialize Jiqian Chen
2025-05-18 14:44 ` Jan Beulich
2025-05-19 7:35 ` Chen, Jiqian
2025-05-19 10:04 ` Roger Pau Monné
2025-05-09 9:05 ` [PATCH v4 06/10] vpci: Hide extended " Jiqian Chen
2025-05-18 14:47 ` Jan Beulich
2025-05-19 7:41 ` Chen, Jiqian
2025-05-19 13:12 ` Jan Beulich
2025-05-09 9:05 ` [PATCH v4 07/10] vpci: Refactor vpci_remove_register to remove matched registers Jiqian Chen
2025-05-19 6:30 ` Jan Beulich
2025-05-19 7:44 ` Chen, Jiqian
2025-05-19 10:24 ` Roger Pau Monné
2025-05-09 9:05 ` [PATCH v4 08/10] vpci/rebar: Remove registers when init_rebar() fails Jiqian Chen
2025-05-19 6:54 ` Jan Beulich
2025-05-19 7:49 ` Chen, Jiqian
2025-05-09 9:05 ` [PATCH v4 09/10] vpci/msi: Free MSI resources when init_msi() fails Jiqian Chen
2025-05-20 6:40 ` Jan Beulich
2025-05-20 9:09 ` Roger Pau Monné
2025-05-20 9:14 ` Jan Beulich
2025-05-20 9:43 ` Roger Pau Monné
2025-05-21 7:00 ` Chen, Jiqian
2025-05-21 11:23 ` Roger Pau Monné
2025-05-22 2:21 ` Chen, Jiqian
2025-05-22 7:12 ` Roger Pau Monné
2025-05-22 7:27 ` Chen, Jiqian
2025-05-09 9:05 ` [PATCH v4 10/10] vpci/msix: Add function to clean MSIX resources Jiqian Chen
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=aCYWhmUBa_AyYh6N@macbook.lan \
--to=roger.pau@citrix.com \
--cc=Jiqian.Chen@amd.com \
--cc=ray.huang@amd.com \
--cc=xen-devel@lists.xenproject.org \
/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.