From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Stewart Hildebrand <stewart.hildebrand@amd.com>
Cc: xen-devel@lists.xenproject.org
Subject: Re: [PATCH v4 4/4] vpci: allow 32-bit BAR writes with memory decoding enabled
Date: Fri, 24 Apr 2026 10:50:54 +0200 [thread overview]
Message-ID: <aesu7sCLTaodcyWL@macbook.local> (raw)
In-Reply-To: <20260406191203.97662-5-stewart.hildebrand@amd.com>
On Mon, Apr 06, 2026 at 03:11:58PM -0400, Stewart Hildebrand wrote:
> Currently, Xen vPCI refuses BAR writes if the BAR is mapped in p2m. If
> firmware initializes a 32-bit BAR to a bad address, Linux may try to
> write a new address to the 32-bit BAR without disabling memory decoding.
> Since Xen refuses such writes, the BAR (and thus PCI device) will be
> non-functional.
>
> Allow the hardware domain to issue 32-bit BAR writes with memory
> decoding enabled. This increases the compatibility of PVH dom0 with more
> hardware.
>
> Note that Linux aims at disabling memory decoding before writing 64-bit
> BARs. Continue to refuse 64-bit BAR writes in Xen while those BARs are
> mapped for now to avoid mapping half-updated BARs in p2m.
While Linux does the disabling for 64bit BARs, I wonder if at some we
will need to handle 64bit BAR writes anyway for other OSes, specially
with domU support.
> Resolves: https://gitlab.com/xen-project/xen/-/issues/197
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
> ---
> v3->v4:
> * rebase on dynamically allocated map queue
>
> v2->v3:
> * minor tweaks for fixed number of map/unmap slots
>
> v1->v2:
> * rework on top of queued BAR map/unmap operation machinery
>
> RFC->v1:
> * keep memory decoding enabled in hardware
> * allow write while memory decoding is enabled for 32-bit BARs only
> * rework BAR mapping machinery to support unmap-then-map operation
> ---
> xen/drivers/vpci/header.c | 32 +++++++++++++++++++++++---------
> 1 file changed, 23 insertions(+), 9 deletions(-)
>
> diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
> index 20fe380552f4..dc4f585b4e40 100644
> --- a/xen/drivers/vpci/header.c
> +++ b/xen/drivers/vpci/header.c
> @@ -670,6 +670,7 @@ static void cf_check bar_write(
> {
> struct vpci_bar *bar = data;
> bool hi = false;
> + uint16_t cmd = 0;
>
> ASSERT(is_hardware_domain(pdev->domain));
>
> @@ -683,19 +684,29 @@ static void cf_check bar_write(
> val &= PCI_BASE_ADDRESS_MEM_MASK;
>
> /*
> - * Xen only cares whether the BAR is mapped into the p2m, so allow BAR
> - * writes as long as the BAR is not mapped into the p2m.
> + * Allow 64-bit BAR writes only when the BAR is not mapped in p2m. Always
> + * allow 32-bit BAR writes.
> */
> if ( bar->enabled )
> {
> - /* If the value written is the current one avoid printing a warning. */
> - if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) )
> - gprintk(XENLOG_WARNING,
> - "%pp: ignored BAR %zu write while mapped\n",
> - &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> - return;
> - }
> + if ( bar->type == VPCI_BAR_MEM32 )
> + {
> + if ( val == bar->addr )
> + return;
>
> + cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
> + modify_bars(pdev, cmd, false, false);
> + }
> + else
> + {
> + /* If the value written is the same avoid printing a warning. */
> + if ( val != (uint32_t)(bar->addr >> (hi ? 32 : 0)) )
> + gprintk(XENLOG_WARNING,
> + "%pp: ignored BAR %zu write while mapped\n",
> + &pdev->sbdf, bar - pdev->vpci->header.bars + hi);
> + return;
> + }
> + }
>
> /*
> * Update the cached address, so that when memory decoding is enabled
> @@ -715,6 +726,9 @@ static void cf_check bar_write(
> }
>
> pci_conf_write32(pdev->sbdf, reg, val);
I don't think it matters a lot, but here we are changing the position
of the BAR in the host memory map while the mappings are still active.
> +
> + if ( bar->enabled )
> + modify_bars(pdev, cmd, false, true);
> }
>
> static void cf_check guest_mem_bar_write(const struct pci_dev *pdev,
As it's in context here - we possibly want to do something similar
with guest writes now that we can?
While we might not have a user-case for domUs ATM, I think it's vest
if we also fix that use case at the same time that dom0 is fixed
(unless there's something that prevents it).
Thanks, Roger.
next prev parent reply other threads:[~2026-04-24 8:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-06 19:11 [PATCH v4 0/4] vpci: allow 32-bit BAR writes with memory decoding enabled Stewart Hildebrand
2026-04-06 19:11 ` [PATCH v4 1/4] vpci: Use pervcpu ranges for BAR mapping Stewart Hildebrand
2026-04-16 14:26 ` Jan Beulich
2026-04-16 15:29 ` Jan Beulich
2026-04-24 7:49 ` Roger Pau Monné
2026-04-06 19:11 ` [PATCH v4 2/4] vpci: allow queueing of mapping operations Stewart Hildebrand
2026-04-09 15:17 ` Mykyta Poturai
2026-04-16 14:59 ` Jan Beulich
2026-04-06 19:11 ` [PATCH v4 3/4] vpci: allow BAR map/unmap without affecting memory decoding bit Stewart Hildebrand
2026-04-24 8:38 ` Roger Pau Monné
2026-04-06 19:11 ` [PATCH v4 4/4] vpci: allow 32-bit BAR writes with memory decoding enabled Stewart Hildebrand
2026-04-21 13:34 ` Jan Beulich
2026-04-24 8:50 ` Roger Pau Monné [this message]
2026-05-04 5:52 ` Jan Beulich
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=aesu7sCLTaodcyWL@macbook.local \
--to=roger.pau@citrix.com \
--cc=stewart.hildebrand@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.