All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Roger Pau Monné" <roger.pau@citrix.com>,
	Xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH 7/8] x86/public: Split the struct cpu_user_regs type
Date: Fri, 21 Mar 2025 15:11:02 +0000	[thread overview]
Message-ID: <eaaf2aef-129a-45ce-b5e7-ae884c2385f3@citrix.com> (raw)
In-Reply-To: <8edba542-9844-409e-bbf0-5ff1c9287a10@suse.com>

On 17/03/2025 12:15 pm, Jan Beulich wrote:
> On 11.03.2025 22:10, Andrew Cooper wrote:
>> In order to support FRED, we're going to have to remove the {ds..gs} fields
>> from struct cpu_user_regs, meaning that it is going to have to become a
>> different type to the structure embedded in vcpu_guest_context_u.
>>
>> struct cpu_user_regs is a name used in common Xen code (i.e. needs to stay
>> using this name), so renaming the public struct to be guest_user_regs in Xen's
>> view only.
>>
>> Introduce a brand hew cpu-user-regs.h, currently containing a duplicate
>> structure.  This removes the need for current.h to include public/xen.h, and
>> highlights a case where the emulator was picking up cpu_user_regs
>> transitively.
>>
>> No functional change.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Thanks.

>> cpu_user_regs_t and the guest handle don't seem to be used anywhere.  I'm
>> tempted to exclude them from Xen builds.
> I concur. We can always re-expose them should they be needed somewhere.

It's actually a little ugly to do.

#ifdef __XEN__
#undef cpu_user_regs
#else
typedef struct cpu_user_regs cpu_user_regs_t;
DEFINE_XEN_GUEST_HANDLE(cpu_user_regs_t);
#endif

and I don't particularly like it, given the complexity of #ifdef-ary
around it.  Thoughts?

>
>> --- /dev/null
>> +++ b/xen/arch/x86/include/asm/cpu-user-regs.h
>> @@ -0,0 +1,69 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +#ifndef X86_CPU_USER_REGS_H
>> +#define X86_CPU_USER_REGS_H
>> +
>> +#define DECL_REG_LOHI(which) union { \
>> +    uint64_t r ## which ## x; \
>> +    uint32_t e ## which ## x; \
>> +    uint16_t which ## x; \
>> +    struct { \
>> +        uint8_t which ## l; \
>> +        uint8_t which ## h; \
>> +    }; \
>> +}
>> +#define DECL_REG_LO8(name) union { \
>> +    uint64_t r ## name; \
>> +    uint32_t e ## name; \
>> +    uint16_t name; \
>> +    uint8_t name ## l; \
>> +}
>> +#define DECL_REG_LO16(name) union { \
>> +    uint64_t r ## name; \
>> +    uint32_t e ## name; \
>> +    uint16_t name; \
>> +}
>> +#define DECL_REG_HI(num) union { \
>> +    uint64_t r ## num; \
>> +    uint32_t r ## num ## d; \
>> +    uint16_t r ## num ## w; \
>> +    uint8_t r ## num ## b; \
>> +}
> Can we try to avoid repeating these here? The #undef-s in the public header are
> to keep external consumers' namespaces reasonably tidy. In Xen, since we don't
> otherwise use identifiers of these names, can't we simply #ifdef-out those
> #undef-s, and then not re-introduce the same (less the two underscores) here?
> Granted we then need to include the public header here, but I think that's a
> fair price to pay to avoid the redundancy.

Breaking the connection between asm/current.h and public/xen.h is very
important IMO.  Right now, the public interface/types/defines are in
every TU, and they absolutely shouldn't be.

Sadly, the compiler isn't happy when including public/xen.h after
asm/current.h, hence the dropping of the underscores.

I did have half a mind to expand them fully.  I find them unintuitive,
but I also didn't think I'd successfully argue that change in.

I'm not terribly fussed how we do this, but I really do want to reduce
the header tangle.

>
>> +struct cpu_user_regs
>> +{
>> +    DECL_REG_HI(15);
>> +    DECL_REG_HI(14);
>> +    DECL_REG_HI(13);
>> +    DECL_REG_HI(12);
>> +    DECL_REG_LO8(bp);
>> +    DECL_REG_LOHI(b);
>> +    DECL_REG_HI(11);
>> +    DECL_REG_HI(10);
>> +    DECL_REG_HI(9);
>> +    DECL_REG_HI(8);
>> +    DECL_REG_LOHI(a);
>> +    DECL_REG_LOHI(c);
>> +    DECL_REG_LOHI(d);
>> +    DECL_REG_LO8(si);
>> +    DECL_REG_LO8(di);
>> +    uint32_t error_code;
>> +    uint32_t entry_vector;
>> +    DECL_REG_LO16(ip);
>> +    uint16_t cs, _pad0[1];
>> +    uint8_t  saved_upcall_mask;
>> +    uint8_t  _pad1[3];
>> +    DECL_REG_LO16(flags); /* rflags.IF == !saved_upcall_mask */
>> +    DECL_REG_LO8(sp);
>> +    uint16_t ss, _pad2[3];
>> +    uint16_t es, _pad3[3];
>> +    uint16_t ds, _pad4[3];
>> +    uint16_t fs, _pad5[3];
>> +    uint16_t gs, _pad6[3];
> I had to peek ahead at the last patch to figure why you introduce these 4 fields
> (plus their padding) here, just to remove them again. Personally I think it would
> be neater if both were folded; nevertheless I'd like to leave this entirely to
> you.

While both patches are reasonably small, I think it's important for
bisection to keep them separate.  They're both complex in separate ways.

~Andrew


  reply	other threads:[~2025-03-21 15:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-11 21:10 [PATCH 0/8] x86: Drop the vm86 segments selectors from struct cpu_user_regs Andrew Cooper
2025-03-11 21:10 ` [PATCH 1/8] x86/regs: Fold x86_64/regs.h into it's single includer Andrew Cooper
2025-03-17 10:49   ` Jan Beulich
2025-03-11 21:10 ` [PATCH 2/8] x86/traps: Rework register state printing to use a struct Andrew Cooper
2025-03-17 10:54   ` Jan Beulich
2025-03-11 21:10 ` [PATCH 3/8] x86/traps: Avoid OoB accesses to print the data selectors Andrew Cooper
2025-03-17 11:00   ` Jan Beulich
2025-03-17 11:04     ` Andrew Cooper
2025-03-11 21:10 ` [PATCH 4/8] Revert "x86/traps: 'Fix' safety of read_registers() in #DF path" Andrew Cooper
2025-03-17 11:03   ` Jan Beulich
2025-03-11 21:10 ` [PATCH 5/8] x86/domctl: Stop using XLAT_cpu_user_regs() Andrew Cooper
2025-03-17 11:38   ` Jan Beulich
2025-03-21 16:01     ` Andrew Cooper
2025-03-24 10:01       ` Jan Beulich
2025-03-17 11:42   ` Jan Beulich
2025-03-21 17:13     ` Andrew Cooper
2025-03-24  9:53       ` Jan Beulich
2025-03-11 21:10 ` [PATCH 6/8] x86/pv: Store the data segment selectors outside of cpu_user_regs Andrew Cooper
2025-03-17 11:58   ` Jan Beulich
2025-03-17 12:00     ` Andrew Cooper
2025-03-11 21:10 ` [PATCH 7/8] x86/public: Split the struct cpu_user_regs type Andrew Cooper
2025-03-17 12:15   ` Jan Beulich
2025-03-21 15:11     ` Andrew Cooper [this message]
2025-03-24  9:47       ` Jan Beulich
2025-07-25 17:34         ` Roger Pau Monné
2025-03-11 21:10 ` [PATCH 8/8] x86: Drop the vm86 segments selectors from struct cpu_user_regs Andrew Cooper
2025-03-17 12:16   ` 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=eaaf2aef-129a-45ce-b5e7-ae884c2385f3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.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.