From: "Roger Pau Monné" <roger.pau@citrix.com>
To: dmkhn@proton.me
Cc: xen-devel@lists.xenproject.org, andrew.cooper3@citrix.com,
anthony.perard@vates.tech, jbeulich@suse.com, julien@xen.org,
michal.orzel@amd.com, sstabellini@kernel.org, dmukhin@ford.com
Subject: Re: [PATCH v2 2/2] xen/domain: rewrite emulation_flags_ok()
Date: Wed, 21 May 2025 17:07:12 +0200 [thread overview]
Message-ID: <aC3sIHgUpCFxW35K@macbook.local> (raw)
In-Reply-To: <20250516022855.1146121-3-dmukhin@ford.com>
On Fri, May 16, 2025 at 02:29:16AM +0000, dmkhn@proton.me wrote:
> From: Denis Mukhin <dmukhin@ford.com>
>
> Rewrite emulation_flags_ok() to simplify future modifications.
>
> Also, introduce X86_EMU_{BASELINE,OPTIONAL} helper macros.
>
> No functional change intended.
>
> Signed-off-by: Denis Mukhin <dmukhin@ford.com>
> ---
> Changes since v1:
> - kept use of non-public X86_EMU_XXX flags
> - corrected some comments and macro definitions
> ---
> xen/arch/x86/domain.c | 29 +++++++++++------------------
> xen/arch/x86/include/asm/domain.h | 6 ++++++
> 2 files changed, 17 insertions(+), 18 deletions(-)
>
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index f197dad4c0..c64c2c6fef 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -750,25 +750,18 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
> BUILD_BUG_ON(X86_EMU_ALL != XEN_X86_EMU_ALL);
> #endif
>
> - if ( is_hvm_domain(d) )
> - {
> - if ( is_hardware_domain(d) &&
> - emflags != (X86_EMU_VPCI | X86_EMU_LAPIC | X86_EMU_IOAPIC) )
> - return false;
> - if ( !is_hardware_domain(d) &&
> - /* HVM PIRQ feature is user-selectable. */
> - (emflags & ~X86_EMU_USE_PIRQ) !=
> - (X86_EMU_ALL & ~(X86_EMU_VPCI | X86_EMU_USE_PIRQ)) &&
> - emflags != X86_EMU_LAPIC )
> - return false;
> - }
> - else if ( emflags != 0 && emflags != X86_EMU_PIT )
> - {
> - /* PV or classic PVH. */
> - return false;
> - }
> + /* PV */
> + if ( !is_hvm_domain(d) )
> + return emflags == 0 || emflags == X86_EMU_PIT;
>
> - return true;
> + /* HVM */
> + if ( is_hardware_domain(d) )
> + return emflags == (X86_EMU_LAPIC |
> + X86_EMU_IOAPIC |
> + X86_EMU_VPCI);
> +
> + return (emflags & ~X86_EMU_OPTIONAL) == X86_EMU_BASELINE ||
> + emflags == X86_EMU_LAPIC;
> }
>
> void __init arch_init_idle_domain(struct domain *d)
> diff --git a/xen/arch/x86/include/asm/domain.h b/xen/arch/x86/include/asm/domain.h
> index 8c0dea12a5..3a9a9fd80d 100644
> --- a/xen/arch/x86/include/asm/domain.h
> +++ b/xen/arch/x86/include/asm/domain.h
> @@ -494,6 +494,12 @@ struct arch_domain
> X86_EMU_PIT | X86_EMU_USE_PIRQ | \
> X86_EMU_VPCI)
>
> +/* User-selectable features. */
> +#define X86_EMU_OPTIONAL (X86_EMU_USE_PIRQ)
> +
> +#define X86_EMU_BASELINE (X86_EMU_ALL & ~(X86_EMU_VPCI | \
> +
> X86_EMU_OPTIONAL))
If you go this route I think you need to name those
X86_EMU_HVM_{BASELINE,OPTIONAL}, because they are really meaningful
only for HVM domains.
Regarding vPCI and HVM: we might want to enable it in the future for
domUs, but the fact is that right now it will collide badly with
ioreqs. So for the time being on x86 it would be best if vPCI is
limited to PVH hardware domain exclusively, otherwise the hypervisor
internals might malfunction. We shouldn't really allow dom0 to create
this kind of malformed domain as much as possible.
static const struct {
bool pv, hwdom;
uint32_t base, optional;
} allowed_conf[] = {
/* PV */
{ true, false, 0, X86_EMU_PIT },
/* PVH hardware domain */
{ false, true, X86_EMU_LAPIC | X86_EMU_IOAPIC | X86_EMU_VPCI, 0 },
/* PVH domU */
{ false, false, X86_EMU_LAPIC, 0 },
/* HVM */
{ false, false, X86_EMU_ALL & ~(X86_EMU_VPCI | X86_EMU_USE_PIRQ),
X86_EMU_VPCI | X86_EMU_USE_PIRQ },
};
unsigned int i;
for ( i = 0; i < ARRAY_SIZE(allowed_conf); i++ )
{
if ( is_pv_domain(d) == allowed_conf[i].pv &&
/*
* A hardware domain can also use !hwdom entries, but not the
* other way around
*/
(is_hardware_domain(d) || !allowed_conf[i].hwdom) &&
(emflags & ~allowed_conf[i].optional) == allowed_conf[i].base )
return true;
}
printk(XENLOG_INFO "%pd: invalid emulation flags: %#x\n", d, emflags);
return false;
I think the above (not even build tested) is slightly clearer, and
allows for easier expansion going forward?
Regards, Roger.
next prev parent reply other threads:[~2025-05-21 15:07 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 2:29 [PATCH v2 0/2] xen/domain: updates to hardware emulation flags dmkhn
2025-05-16 2:29 ` [PATCH v2 1/2] xen/domain: introduce non-x86 " dmkhn
2025-05-20 15:21 ` Jan Beulich
2025-05-20 21:39 ` dmkhn
2025-05-21 6:01 ` Jan Beulich
2025-05-21 14:05 ` Roger Pau Monné
2025-05-28 21:17 ` dmkhn
2025-05-16 2:29 ` [PATCH v2 2/2] xen/domain: rewrite emulation_flags_ok() dmkhn
2025-05-20 15:24 ` Jan Beulich
2025-05-20 22:38 ` dmkhn
2025-05-20 23:00 ` Stefano Stabellini
2025-05-21 6:51 ` Jan Beulich
2025-05-21 6:04 ` Jan Beulich
2025-05-21 15:07 ` Roger Pau Monné [this message]
2025-05-22 0:26 ` dmkhn
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=aC3sIHgUpCFxW35K@macbook.local \
--to=roger.pau@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=dmkhn@proton.me \
--cc=dmukhin@ford.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=sstabellini@kernel.org \
--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.