mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>, Peter Anvin <hpa@zytor.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andy Lutomirski <luto@kernel.org>, Borislav Petkov <bp@alien8.de>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: [patch 19/41] x86/fpu: Use bitfield accessors for desc_struct
Date: Fri, 25 Aug 2017 12:31:22 +0200	[thread overview]
Message-ID: <20170825104414.474032436@linutronix.de> (raw)
In-Reply-To: <20170825103103.287814238@linutronix.de>

[-- Attachment #1: x86-fpu--Use-bitfield-accessors-for-desc_struct.patch --]
[-- Type: text/plain, Size: 5043 bytes --]

desc_struct is a union of u32 fields and bitfields. The access to the u32
fields is done with magic macros.

Convert it to use the bitfields and replace the macro magic with parseable
inline functions.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/math-emu/fpu_entry.c   |   11 ++++-----
 arch/x86/math-emu/fpu_system.h  |   48 ++++++++++++++++++++++++++++++----------
 arch/x86/math-emu/get_address.c |   17 +++++++-------
 3 files changed, 51 insertions(+), 25 deletions(-)

Index: b/arch/x86/math-emu/fpu_entry.c
===================================================================
--- a/arch/x86/math-emu/fpu_entry.c
+++ b/arch/x86/math-emu/fpu_entry.c
@@ -147,7 +147,7 @@ void math_emulate(struct math_emu_info *
 		}
 
 		code_descriptor = FPU_get_ldt_descriptor(FPU_CS);
-		if (SEG_D_SIZE(code_descriptor)) {
+		if (code_descriptor.d) {
 			/* The above test may be wrong, the book is not clear */
 			/* Segmented 32 bit protected mode */
 			addr_modes.default_mode = SEG32;
@@ -155,11 +155,10 @@ void math_emulate(struct math_emu_info *
 			/* 16 bit protected mode */
 			addr_modes.default_mode = PM16;
 		}
-		FPU_EIP += code_base = SEG_BASE_ADDR(code_descriptor);
-		code_limit = code_base
-		    + (SEG_LIMIT(code_descriptor) +
-		       1) * SEG_GRANULARITY(code_descriptor)
-		    - 1;
+		FPU_EIP += code_base = seg_get_base(&code_descriptor);
+		code_limit = seg_get_limit(&code_descriptor) + 1;
+		code_limit *= seg_get_granularity(&code_descriptor);
+		code_limit += code_base - 1;
 		if (code_limit < code_base)
 			code_limit = 0xffffffff;
 	}
Index: b/arch/x86/math-emu/fpu_system.h
===================================================================
--- a/arch/x86/math-emu/fpu_system.h
+++ b/arch/x86/math-emu/fpu_system.h
@@ -34,17 +34,43 @@ static inline struct desc_struct FPU_get
 	return ret;
 }
 
-#define SEG_D_SIZE(x)		((x).b & (3 << 21))
-#define SEG_G_BIT(x)		((x).b & (1 << 23))
-#define SEG_GRANULARITY(x)	(((x).b & (1 << 23)) ? 4096 : 1)
-#define SEG_286_MODE(x)		((x).b & ( 0xff000000 | 0xf0000 | (1 << 23)))
-#define SEG_BASE_ADDR(s)	(((s).b & 0xff000000) \
-				 | (((s).b & 0xff) << 16) | ((s).a >> 16))
-#define SEG_LIMIT(s)		(((s).b & 0xff0000) | ((s).a & 0xffff))
-#define SEG_EXECUTE_ONLY(s)	(((s).b & ((1 << 11) | (1 << 9))) == (1 << 11))
-#define SEG_WRITE_PERM(s)	(((s).b & ((1 << 11) | (1 << 9))) == (1 << 9))
-#define SEG_EXPAND_DOWN(s)	(((s).b & ((1 << 11) | (1 << 10))) \
-				 == (1 << 10))
+#define SEG_TYPE_WRITABLE	(1U << 1)
+#define SEG_TYPE_EXPANDS_DOWN	(1U << 2)
+#define SEG_TYPE_EXECUTE	(1U << 3)
+#define SEG_TYPE_EXPAND_MASK	(SEG_TYPE_EXPANDS_DOWN | SEG_TYPE_EXECUTE)
+#define SEG_TYPE_EXECUTE_MASK	(SEG_TYPE_WRITABLE | SEG_TYPE_EXECUTE)
+
+static inline unsigned long seg_get_base(struct desc_struct *d)
+{
+	unsigned long base = (unsigned long)d->base2 << 24;
+
+	return base | ((unsigned long)d->base1 << 16) | d->base0;
+}
+
+static inline unsigned long seg_get_limit(struct desc_struct *d)
+{
+	return ((unsigned long)d->limit << 16) | d->limit0;
+}
+
+static inline unsigned long seg_get_granularity(struct desc_struct *d)
+{
+	return d->g ? 4096 : 1;
+}
+
+static inline bool seg_expands_down(struct desc_struct *d)
+{
+	return (d->type & SEG_TYPE_EXPAND_MASK) == SEG_TYPE_EXPANDS_DOWN;
+}
+
+static inline bool seg_execute_only(struct desc_struct *d)
+{
+	return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_EXECUTE;
+}
+
+static inline bool seg_writable(struct desc_struct *d)
+{
+	return (d->type & SEG_TYPE_EXECUTE_MASK) == SEG_TYPE_WRITABLE;
+}
 
 #define I387			(&current->thread.fpu.state)
 #define FPU_info		(I387->soft.info)
Index: b/arch/x86/math-emu/get_address.c
===================================================================
--- a/arch/x86/math-emu/get_address.c
+++ b/arch/x86/math-emu/get_address.c
@@ -159,17 +159,18 @@ static long pm_address(u_char FPU_modrm,
 	}
 
 	descriptor = FPU_get_ldt_descriptor(addr->selector);
-	base_address = SEG_BASE_ADDR(descriptor);
+	base_address = seg_get_base(&descriptor);
 	address = base_address + offset;
-	limit = base_address
-	    + (SEG_LIMIT(descriptor) + 1) * SEG_GRANULARITY(descriptor) - 1;
+	limit = seg_get_limit(&descriptor) + 1;
+	limit *= seg_get_granularity(&descriptor);
+	limit += base_address - 1;
 	if (limit < base_address)
 		limit = 0xffffffff;
 
-	if (SEG_EXPAND_DOWN(descriptor)) {
-		if (SEG_G_BIT(descriptor))
+	if (seg_expands_down(&descriptor)) {
+		if (descriptor.g) {
 			seg_top = 0xffffffff;
-		else {
+		} else {
 			seg_top = base_address + (1 << 20);
 			if (seg_top < base_address)
 				seg_top = 0xffffffff;
@@ -182,8 +183,8 @@ static long pm_address(u_char FPU_modrm,
 		    (address > limit) || (address < base_address) ? 0 :
 		    ((limit - address) >= 254 ? 255 : limit - address + 1);
 	}
-	if (SEG_EXECUTE_ONLY(descriptor) ||
-	    (!SEG_WRITE_PERM(descriptor) && (FPU_modrm & FPU_WRITE_BIT))) {
+	if (seg_execute_only(&descriptor) ||
+	    (!seg_writable(&descriptor) && (FPU_modrm & FPU_WRITE_BIT))) {
 		access_limit = 0;
 	}
 	return address;

  parent reply	other threads:[~2017-08-25 10:54 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-25 10:31 [patch 00/41] x86: Cleanup IDT code Thomas Gleixner
2017-08-25 10:31 ` [patch 01/41] x86/irq: Remove vector_used_by_percpu_irq() Thomas Gleixner
2017-08-25 10:31 ` [patch 02/41] x86/irq: Unexport used_vectors Thomas Gleixner
2017-08-25 10:31 ` [patch 03/41] x86/irq: Move ifdeffery to header file Thomas Gleixner
2017-08-25 12:45   ` Thomas Gleixner
2017-08-25 10:31 ` [patch 04/41] x86/boot: Move EISA setup to a proper place Thomas Gleixner
2017-08-25 11:59   ` Thomas Gleixner
2017-08-25 10:31 ` [patch 05/41] x86/tracing: Introduce a static key for exception tracing Thomas Gleixner
2017-08-25 15:24   ` Steven Rostedt
2017-08-25 10:31 ` [patch 06/41] x86/traps: Simplify pagefault tracing logic Thomas Gleixner
2017-08-25 14:59   ` Andy Lutomirski
2017-08-25 15:10   ` Steven Rostedt
2017-08-25 15:11     ` Thomas Gleixner
2017-08-25 10:31 ` [patch 07/41] x86/apic: Remove the duplicated tracing version of local_timer_interrupt Thomas Gleixner
2017-08-25 15:29   ` Steven Rostedt
2017-08-25 10:31 ` [patch 08/41] x86/apic: Use this_cpu_ptr in local_timer_interrupt Thomas Gleixner
2017-08-25 10:31 ` [patch 09/41] x86/irq: Get rid of duplicated trace_x86_platform_ipi() code Thomas Gleixner
2017-08-25 15:41   ` Steven Rostedt
2017-08-25 10:31 ` [patch 10/41] x86/apic: Remove the duplicated tracing versions of interrupts Thomas Gleixner
2017-08-25 15:49   ` Steven Rostedt
2017-08-28  7:50     ` Peter Zijlstra
2017-08-25 10:31 ` [patch 11/41] x86/irqwork: Get rid of duplicated tracing interrupt code Thomas Gleixner
2017-08-25 15:55   ` Steven Rostedt
2017-08-25 10:31 ` [patch 12/41] x86/mce: Remove " Thomas Gleixner
2017-08-25 16:09   ` Steven Rostedt
2017-08-25 16:13     ` Thomas Gleixner
2017-08-25 10:31 ` [patch 13/41] x86/smp: Remove pointless duplicated " Thomas Gleixner
2017-08-25 18:24   ` Steven Rostedt
2017-08-25 10:31 ` [patch 14/41] x86/smp: Use static key for reschedule interrupt tracing Thomas Gleixner
2017-08-25 19:40   ` Steven Rostedt
2017-08-25 20:07     ` Thomas Gleixner
2017-08-25 21:10       ` Steven Rostedt
2017-08-25 10:31 ` [patch 15/41] x86/idt: Remove tracing idt completely Thomas Gleixner
2017-08-25 21:18   ` Steven Rostedt
2017-08-25 21:22     ` Thomas Gleixner
2017-08-25 21:29       ` Thomas Gleixner
2017-08-25 10:31 ` [patch 16/41] x86/tracing: Disentangle pagefault and resched IPI tracing key Thomas Gleixner
2017-08-25 10:31 ` [patch 17/41] x86/idt: Unify gate_struct handling for 32/64bit Thomas Gleixner
2017-08-25 10:31 ` [patch 18/41] x86/percpu: Use static initializer for GDT entry Thomas Gleixner
2017-08-25 10:31 ` Thomas Gleixner [this message]
2017-08-25 10:31 ` [patch 20/41] x86: Replace access to desc_struct:a/b fields Thomas Gleixner
2017-08-25 11:14   ` Juergen Gross
2017-08-25 13:56   ` Boris Ostrovsky
2017-08-25 14:02     ` Thomas Gleixner
2017-08-25 14:16       ` Steven Rostedt
2017-08-25 10:31 ` [patch 21/41] x86/gdt: Use bitfields for initialization Thomas Gleixner
2017-08-25 10:31 ` [patch 22/41] x86/ldttss: Cleanup 32bit descriptors Thomas Gleixner
2017-08-25 10:31 ` [patch 23/41] x86/idt: Create file for IDT related code Thomas Gleixner
2017-08-25 10:31 ` [patch 24/41] x86/idt: Move 32bit idt_descr to C code Thomas Gleixner
2017-08-25 10:31 ` [patch 25/41] x86/idt: Remove unused set_trap_gate() Thomas Gleixner
2017-08-25 10:31 ` [patch 26/41] x86/idt: Consolidate IDT invalidation Thomas Gleixner
2017-08-25 10:31 ` [patch 27/41] x86/idt: Move early IDT handler setup to IDT code Thomas Gleixner
2017-08-25 10:31 ` [patch 28/41] x86/idt: Move early IDT setup out of 32bit asm Thomas Gleixner
2017-08-25 10:31 ` [patch 29/41] x86/idt: Prepare for table based init Thomas Gleixner
2017-08-25 10:31 ` [patch 30/41] x86/idt: Switch early trap init to IDT tables Thomas Gleixner
2017-08-25 14:57   ` Andy Lutomirski
2017-08-25 10:31 ` [patch 31/41] x86/idt: Move debug stack init to table based Thomas Gleixner
2017-08-25 10:31 ` [patch 32/41] x86/idt: Move ist stack based traps to table init Thomas Gleixner
2017-08-25 10:31 ` [patch 33/41] x86/idt: Move regular trap init to tables Thomas Gleixner
2017-08-25 10:31 ` [patch 34/41] x86/idt: Move APIC gate initialization " Thomas Gleixner
2017-08-25 10:31 ` [patch 35/41] x86/idt: Move interrupt gate initialization to IDT code Thomas Gleixner
2017-08-25 10:31 ` [patch 36/41] x86/idt: Remove unused functions/inlines Thomas Gleixner
2017-08-25 10:31 ` [patch 37/41] x86/irq: Get rid of the first_system_vector bogisity Thomas Gleixner
2017-08-25 10:31 ` [patch 38/41] x86/idt: Deinline setup functions Thomas Gleixner
2017-08-25 10:31 ` [patch 39/41] x86/idt: Simplify alloc_intr_gate Thomas Gleixner
2017-08-25 11:16   ` Juergen Gross
2017-08-25 10:31 ` [patch 40/41] x86/idt: Hide set_intr_gate() Thomas Gleixner
2017-08-25 10:56   ` Paolo Bonzini
2017-08-25 10:31 ` [patch 41/41] x86/irq: Remove duplicated used_vectors definition Thomas Gleixner

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=20170825104414.474032436@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.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

Powered by JetHome