From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH v3 2/4] x86/hvm: fix handling of accesses to partial r/o MMIO pages
Date: Wed, 23 Apr 2025 10:52:18 +0200 [thread overview]
Message-ID: <aAiqQnRXrXQAX1Vl@macbook.lan> (raw)
In-Reply-To: <b63ff1ca-2752-44fe-8a32-0a721eec1abb@suse.com>
On Wed, Apr 23, 2025 at 10:32:33AM +0200, Jan Beulich wrote:
> On 23.04.2025 10:21, Roger Pau Monné wrote:
> > On Tue, Apr 22, 2025 at 08:46:13AM +0200, Jan Beulich wrote:
> >> On 17.04.2025 18:23, Roger Pau Monné wrote:
> >>> On Thu, Apr 17, 2025 at 05:38:54PM +0200, Jan Beulich wrote:
> >>>> On 17.04.2025 17:25, Roger Pau Monne wrote:
> >>>>> --- /dev/null
> >>>>> +++ b/xen/arch/x86/hvm/mmio.c
> >>>>> @@ -0,0 +1,125 @@
> >>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
> >>>>> +/*
> >>>>> + * MMIO related routines.
> >>>>> + *
> >>>>> + * Copyright (c) 2025 Cloud Software Group
> >>>>> + */
> >>>>> +
> >>>>> +#include <xen/io.h>
> >>>>> +#include <xen/mm.h>
> >>>>> +
> >>>>> +#include <asm/p2m.h>
> >>>>> +
> >>>>> +static int cf_check subpage_mmio_accept(struct vcpu *v, unsigned long addr)
> >>>>> +{
> >>>>> + p2m_type_t t;
> >>>>> + mfn_t mfn = get_gfn_query_unlocked(v->domain, PFN_DOWN(addr), &t);
> >>>>> +
> >>>>> + return !mfn_eq(mfn, INVALID_MFN) && t == p2m_mmio_direct &&
> >>>>> + subpage_mmio_find_page(mfn);
> >>>>> +}
> >>>>> +
> >>>>> +/*
> >>>>> + * The guest has read access to those regions, and consequently read accesses
> >>>>> + * shouldn't fault. However read-modify-write operations may take this path,
> >>>>> + * so handling of reads is necessary.
> >>>>> + */
> >>>>> +static int cf_check subpage_mmio_read(
> >>>>> + struct vcpu *v, unsigned long addr, unsigned int len, unsigned long *data)
> >>>>> +{
> >>>>> + struct domain *d = v->domain;
> >>>>> + unsigned long gfn = PFN_DOWN(addr);
> >>>>> + p2m_type_t t;
> >>>>> + mfn_t mfn;
> >>>>> + struct subpage_ro_range *entry;
> >>>>> + volatile void __iomem *mem;
> >>>>> +
> >>>>> + *data = ~0UL;
> >>>>> +
> >>>>> + if ( !IS_ALIGNED(len | addr, len) )
> >>>>
> >>>> What's the point of doing the | ? len can't be misaligned with itself?
> >>>
> >>> Hm, it's the same form that's used in mmio_ro_emulated_write(), I
> >>> assumed it was to catch illegal access lengths, like 3.
> >>
> >> Oh, I see. But that's not using IS_ALIGNED(), and imo validly so, despite the
> >> apparent open-coding. IS_ALIGNED() requires the 2nd argument to be a power of
> >> two. The combined check there is folding the power-of-2 one with the is-
> >> aligned one.
> >
> > Do you think it's worth keeping those checks then?
>
> Yes, I think we should be as strict as possible in what we (try to) emulate.
>
> > I could do:
> >
> > if ( len & (len - 1) || len > 8 || !IS_ALIGNED(addr, len) )
> >
> > As a possibly more complete and easier to parse check?
>
> If you dislike the form mmio_ro_emulated_write() uses, sure. However, you
> will want to check len to be non-zero, while I'm unsure you need to check
> len > 8 - mmio_ro_emulated_write() doesn't have such. Albeit - perhaps
> wrongly so; we'd end at the ASSERT_UNREACHABLE() in
> subpage_mmio_write_emulate() if a wider store was used. I guess I ought to
> make a patch there, and you want to keep the "len > 8".
OK, let me send v4 with those adjustments then.
Thanks, Roger.
next prev parent reply other threads:[~2025-04-23 8:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-17 15:25 [PATCH v3 0/4] xen/x86: fix implementation of subpage r/o MMIO Roger Pau Monne
2025-04-17 15:25 ` [PATCH v3 1/4] xen/io: provide helpers for multi size MMIO accesses Roger Pau Monne
2025-04-17 15:32 ` Jan Beulich
2025-04-17 15:25 ` [PATCH v3 2/4] x86/hvm: fix handling of accesses to partial r/o MMIO pages Roger Pau Monne
2025-04-17 15:38 ` Jan Beulich
2025-04-17 16:23 ` Roger Pau Monné
2025-04-22 6:46 ` Jan Beulich
2025-04-23 8:21 ` Roger Pau Monné
2025-04-23 8:32 ` Jan Beulich
2025-04-23 8:52 ` Roger Pau Monné [this message]
2025-04-17 15:25 ` [PATCH v3 3/4] x86/hvm: only register the r/o subpage ops when needed Roger Pau Monne
2025-04-17 15:25 ` [PATCH v3 4/4] x86/mm: move mmio_ro_emulated_write() to PV only file Roger Pau Monne
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=aAiqQnRXrXQAX1Vl@macbook.lan \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.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.