public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Vegard Nossum <vegard.nossum@oracle.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org, Brian Gerst <brgerst@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Linus Torvalds <torvalds@linuxfoundation.org>
Subject: Re: [PATCH 1/5] x86: provide new infrastructure for GDT descriptors
Date: Wed, 20 Dec 2023 10:51:11 +0100	[thread overview]
Message-ID: <ZYK5D/KfzpEjQr+8@gmail.com> (raw)
In-Reply-To: <20231219151200.2878271-2-vegard.nossum@oracle.com>


* Vegard Nossum <vegard.nossum@oracle.com> wrote:

> @@ -27,14 +77,14 @@ struct desc_struct {
>  		.base0		= (u16) (base),			\
>  		.base1		= ((base) >> 16) & 0xFF,	\
>  		.base2		= ((base) >> 24) & 0xFF,	\
> -		.type		= (flags & 0x0f),		\
> -		.s		= (flags >> 4) & 0x01,		\
> -		.dpl		= (flags >> 5) & 0x03,		\
> -		.p		= (flags >> 7) & 0x01,		\
> -		.avl		= (flags >> 12) & 0x01,		\
> -		.l		= (flags >> 13) & 0x01,		\
> -		.d		= (flags >> 14) & 0x01,		\
> -		.g		= (flags >> 15) & 0x01,		\
> +		.type		= ((flags) & 0x0f),		\
> +		.s		= ((flags) >> 4) & 0x01,	\
> +		.dpl		= ((flags) >> 5) & 0x03,	\
> +		.p		= ((flags) >> 7) & 0x01,	\
> +		.avl		= ((flags) >> 12) & 0x01,	\
> +		.l		= ((flags) >> 13) & 0x01,	\
> +		.d		= ((flags) >> 14) & 0x01,	\
> +		.g		= ((flags) >> 15) & 0x01,	\

Yeah, so how about writing it like this:

 #define GDT_ENTRY_INIT(flags, base, limit)			\
	{							\
		.limit0		= ((limit) >>  0) & 0xFFFF,	\
		.limit1		= ((limit) >> 16) & 0x000F,	\
		.base0		= ((base)  >>  0) & 0xFFFF,	\
		.base1		= ((base)  >> 16) & 0x00FF,	\
		.base2		= ((base)  >> 24) & 0x00FF,	\
		.type		= ((flags) >>  0) & 0x000F,	\
		.s		= ((flags) >>  4) & 0x0001,	\
		.dpl		= ((flags) >>  5) & 0x0003,	\
		.p		= ((flags) >>  7) & 0x0001,	\
		.avl		= ((flags) >> 12) & 0x0001,	\
		.l		= ((flags) >> 13) & 0x0001,	\
		.d		= ((flags) >> 14) & 0x0001,	\
		.g		= ((flags) >> 15) & 0x0001,	\
	}

This encodes it all in a very simple format, without C syntactic
variations: bit position and mask.

Thanks,

	Ingo

  reply	other threads:[~2023-12-20  9:51 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19 15:11 [PATCH 0/5] replace magic numbers in GDT descriptors Vegard Nossum
2023-12-19 15:11 ` [PATCH 1/5] x86: provide new infrastructure for " Vegard Nossum
2023-12-20  9:51   ` Ingo Molnar [this message]
2023-12-20 10:04   ` [tip: x86/asm] x86/asm: Provide " tip-bot2 for Vegard Nossum
2023-12-19 15:11 ` [PATCH 2/5] x86: replace magic numbers in GDT descriptors, part 1 Vegard Nossum
2023-12-20 10:04   ` [tip: x86/asm] x86/asm: Replace magic numbers in GDT descriptors, preparations tip-bot2 for Vegard Nossum
2023-12-19 15:11 ` [PATCH 3/5] x86: replace magic numbers in GDT descriptors, part 2 Vegard Nossum
2023-12-20 10:04   ` [tip: x86/asm] x86/asm: Replace magic numbers in GDT descriptors, script-generated change tip-bot2 for Vegard Nossum
2023-12-19 15:11 ` [PATCH 4/5] x86: always set A (accessed) flag in GDT descriptors Vegard Nossum
2023-12-20 10:04   ` [tip: x86/asm] x86/asm: Always " tip-bot2 for Vegard Nossum
2023-12-19 15:12 ` [PATCH 5/5] x86: add DB flag to 32-bit percpu GDT entry Vegard Nossum
2023-12-20 10:03   ` [tip: x86/asm] x86/asm: Add " tip-bot2 for Vegard Nossum
2023-12-19 17:33 ` [PATCH 0/5] replace magic numbers in GDT descriptors Linus Torvalds
2023-12-20  9:59   ` Ingo Molnar

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=ZYK5D/KfzpEjQr+8@gmail.com \
    --to=mingo@kernel.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linuxfoundation.org \
    --cc=vegard.nossum@oracle.com \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox