From: "Roger Pau Monné" <roger@xenproject.org>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
Teddy Astie <teddy.astie@vates.tech>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v2 1/2] x86/pci: prevent cross-device accesses in pci_mmcfg_{read,write}()
Date: Wed, 12 Aug 2026 10:06:23 +0200 [thread overview]
Message-ID: <anwpfyZ4PIbd5m4S@macbook.local> (raw)
In-Reply-To: <a711a0d1-dbf0-44fb-a419-38abc62480ad@suse.com>
On Wed, Aug 12, 2026 at 08:28:50AM +0200, Jan Beulich wrote:
> On 07.08.2026 10:01, Roger Pau Monné wrote:
> > On Fri, Aug 07, 2026 at 08:22:44AM +0200, Jan Beulich wrote:
> >> On 06.08.2026 17:26, Roger Pau Monne wrote:
> >>> Introduce a specific check that prevents an accesses from spilling across
> >>> two devices.
> >>>
> >>> Signed-off-by: Roger Pau Monné <roger@xenproject.org>
> >>
> >> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> >> albeit with a remark:
> >>
> >>> --- a/xen/arch/x86/x86_64/mmconfig_64.c
> >>> +++ b/xen/arch/x86/x86_64/mmconfig_64.c
> >>> @@ -61,7 +61,8 @@ int pci_mmcfg_read(unsigned int seg, unsigned int bus,
> >>> char __iomem *addr;
> >>>
> >>> /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
> >>> - if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) {
> >>> + if (unlikely((bus > 255) || (devfn > 255) ||
> >>> + (reg + len > PCI_CFG_SPACE_EXP_SIZE))) {
> >>> err: *value = -1;
> >>> return -EINVAL;
> >>> }
> >>> @@ -91,7 +92,8 @@ int pci_mmcfg_write(unsigned int seg, unsigned int bus,
> >>> char __iomem *addr;
> >>>
> >>> /* Why do we have this when nobody checks it. How about a BUG()!? -AK */
> >>> - if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
> >>> + if (unlikely((bus > 255) || (devfn > 255) ||
> >>> + (reg + len > PCI_CFG_SPACE_EXP_SIZE)))
> >>> return -EINVAL;
> >>>
> >>> addr = pci_dev_base(seg, bus, devfn);
> >>
> >> In both cases the unlikely() uses won't have the intended effect, from all I
> >> know. They would help as used here only if the compiler managed to fold all
> >> three parts of the ||-expression into a single conditional branch, which I
> >> don't think it would end up doing.
> >
> > I don't mind dropping the unlikely() while changing the line. I tend
> > to leave those alone if present, even when I'm not sure they are
> > actually helpful.
>
> I think unlikely() is actually reasonable to have here, yet it would need to
> be four of them, not just one. Unless reachable from a DomU-accessible path,
> converting to BUG_ON() (or ASSERT_UNREACHABLE()) instead would also be an
> option.
Hm, let's do that in a separate patch, I don't want to merge it with
the work here.
> > The comment ahead of the check is also not very
> > useful IMO, but I've decided to leave it alone.
>
> Indeed, that's an odd thing to survive over 20 years (I think).
I can also take care of the comment there.
Thanks, Roger.
next prev parent reply other threads:[~2026-08-12 8:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-06 15:26 [PATCH v2 0/2] vpci: allow unaligned accesses by the hardware domain Roger Pau Monne
2026-08-06 15:26 ` [PATCH v2 1/2] x86/pci: prevent cross-device accesses in pci_mmcfg_{read,write}() Roger Pau Monne
2026-08-07 6:22 ` Jan Beulich
2026-08-07 8:01 ` Roger Pau Monné
2026-08-12 6:28 ` Jan Beulich
2026-08-12 8:06 ` Roger Pau Monné [this message]
2026-08-10 15:40 ` Stewart Hildebrand
2026-08-06 15:26 ` [PATCH v2 2/2] xen/vpci: allow unaligned accesses by the hardware domain Roger Pau Monne
2026-08-07 6:39 ` Jan Beulich
2026-08-10 15:41 ` Stewart Hildebrand
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=anwpfyZ4PIbd5m4S@macbook.local \
--to=roger@xenproject.org \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=teddy.astie@vates.tech \
--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.