* [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL
@ 2019-08-28 19:38 Rasmus Villemoes
2019-08-28 19:38 ` [PATCH 2/2] x86: mmu.h: move mm_context_t::ia32_compat member a bit down Rasmus Villemoes
2019-10-07 8:56 ` [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
0 siblings, 2 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2019-08-28 19:38 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86
Cc: Rasmus Villemoes, linux-kernel
The placement of the lock member in mm_context_t suggests that it is
used to protect the vdso* members, but AFAICT, it is only ever used
under #ifdef CONFIG_MODIFY_LDT_SYSCALL. So guarding the member by the
same config option is a cheap way to reduce sizeof(mm_struct) by 32
bytes (only for !CONFIG_MODIFY_LDT_SYSCALL kernels, of course).
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
arch/x86/include/asm/mmu.h | 11 ++++++++---
arch/x86/include/asm/mmu_context.h | 3 +--
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
index e78c7db87801..b1bb47a3577b 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -30,14 +30,13 @@ typedef struct {
#ifdef CONFIG_MODIFY_LDT_SYSCALL
struct rw_semaphore ldt_usr_sem;
struct ldt_struct *ldt;
+ struct mutex lock;
#endif
-
#ifdef CONFIG_X86_64
/* True if mm supports a task running in 32 bit compatibility mode. */
unsigned short ia32_compat;
#endif
- struct mutex lock;
void __user *vdso; /* vdso base address */
const struct vdso_image *vdso_image; /* vdso image in use */
@@ -56,10 +55,16 @@ typedef struct {
#endif
} mm_context_t;
+#ifdef CONFIG_MODIFY_LDT_SYSCALL
+#define INIT_MM_CONTEXT_LOCK(mm) .lock = __MUTEX_INITIALIZER(mm.context.lock),
+#else
+#define INIT_MM_CONTEXT_LOCK(mm)
+#endif
+
#define INIT_MM_CONTEXT(mm) \
.context = { \
.ctx_id = 1, \
- .lock = __MUTEX_INITIALIZER(mm.context.lock), \
+ INIT_MM_CONTEXT_LOCK(mm) \
}
void leave_mm(int cpu);
diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
index 9024236693d2..ac8e3ef8a774 100644
--- a/arch/x86/include/asm/mmu_context.h
+++ b/arch/x86/include/asm/mmu_context.h
@@ -82,6 +82,7 @@ static inline void init_new_context_ldt(struct mm_struct *mm)
{
mm->context.ldt = NULL;
init_rwsem(&mm->context.ldt_usr_sem);
+ mutex_init(&mm->context.lock);
}
int ldt_dup_context(struct mm_struct *oldmm, struct mm_struct *mm);
void destroy_context_ldt(struct mm_struct *mm);
@@ -186,8 +187,6 @@ void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk);
static inline int init_new_context(struct task_struct *tsk,
struct mm_struct *mm)
{
- mutex_init(&mm->context.lock);
-
mm->context.ctx_id = atomic64_inc_return(&last_mm_ctx_id);
atomic64_set(&mm->context.tlb_gen, 0);
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] x86: mmu.h: move mm_context_t::ia32_compat member a bit down
2019-08-28 19:38 [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
@ 2019-08-28 19:38 ` Rasmus Villemoes
2019-10-07 8:56 ` [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2019-08-28 19:38 UTC (permalink / raw)
To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H. Peter Anvin, x86
Cc: Rasmus Villemoes, linux-kernel
For CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=n, there's both a
6-byte hole after ia32_compat as well as a 4-byte hole after
perf_rdpmc_allowed. So rearranging things a bit we cut 8 bytes of
sizeof(struct mm_struct).
For a CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS=y kernel, this patch
just moves the 6-byte hole to another place in mm_context_t.
Putting the ia32_compat member after the pkey members is deliberate to
keep the latter two (when present) in the same 4-byte unit.
Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
---
arch/x86/include/asm/mmu.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
index b1bb47a3577b..ba3d22fcd507 100644
--- a/arch/x86/include/asm/mmu.h
+++ b/arch/x86/include/asm/mmu.h
@@ -32,10 +32,6 @@ typedef struct {
struct ldt_struct *ldt;
struct mutex lock;
#endif
-#ifdef CONFIG_X86_64
- /* True if mm supports a task running in 32 bit compatibility mode. */
- unsigned short ia32_compat;
-#endif
void __user *vdso; /* vdso base address */
const struct vdso_image *vdso_image; /* vdso image in use */
@@ -49,6 +45,10 @@ typedef struct {
u16 pkey_allocation_map;
s16 execute_only_pkey;
#endif
+#ifdef CONFIG_X86_64
+ /* True if mm supports a task running in 32 bit compatibility mode. */
+ unsigned short ia32_compat;
+#endif
#ifdef CONFIG_X86_INTEL_MPX
/* address of the bounds directory */
void __user *bd_addr;
--
2.20.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL
2019-08-28 19:38 [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
2019-08-28 19:38 ` [PATCH 2/2] x86: mmu.h: move mm_context_t::ia32_compat member a bit down Rasmus Villemoes
@ 2019-10-07 8:56 ` Rasmus Villemoes
1 sibling, 0 replies; 3+ messages in thread
From: Rasmus Villemoes @ 2019-10-07 8:56 UTC (permalink / raw)
To: Rasmus Villemoes, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
H. Peter Anvin, x86
Cc: linux-kernel
On 28/08/2019 21.38, Rasmus Villemoes wrote:
> The placement of the lock member in mm_context_t suggests that it is
> used to protect the vdso* members, but AFAICT, it is only ever used
> under #ifdef CONFIG_MODIFY_LDT_SYSCALL. So guarding the member by the
> same config option is a cheap way to reduce sizeof(mm_struct) by 32
> bytes (only for !CONFIG_MODIFY_LDT_SYSCALL kernels, of course).
Ping
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-10-07 8:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-28 19:38 [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
2019-08-28 19:38 ` [PATCH 2/2] x86: mmu.h: move mm_context_t::ia32_compat member a bit down Rasmus Villemoes
2019-10-07 8:56 ` [PATCH 1/2] x86: mmu.h: move mm_context_t::lock member inside CONFIG_MODIFY_LDT_SYSCALL Rasmus Villemoes
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®