Skip to content

Commit 6df934b

Browse files
joergroedelKAGA-KOKO
authored andcommitted
x86/ldt: Enable LDT user-mapping for PAE
This adds the needed special case for PAE to get the LDT mapped into the user page-table when PTI is enabled. The big difference to the other paging modes is that on PAE there is no full top-level PGD entry available for the LDT, but only a PMD entry. Signed-off-by: Joerg Roedel <jroedel@suse.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Tested-by: Pavel Machek <pavel@ucw.cz> Cc: "H . Peter Anvin" <hpa@zytor.com> Cc: linux-mm@kvack.org Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Juergen Gross <jgross@suse.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Jiri Kosina <jkosina@suse.cz> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Brian Gerst <brgerst@gmail.com> Cc: David Laight <David.Laight@aculab.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: Eduardo Valentin <eduval@amazon.com> Cc: Greg KH <gregkh@linuxfoundation.org> Cc: Will Deacon <will.deacon@arm.com> Cc: aliguori@amazon.com Cc: daniel.gruss@iaik.tugraz.at Cc: hughd@google.com Cc: keescook@google.com Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: Waiman Long <llong@redhat.com> Cc: "David H . Gutteridge" <dhgutteridge@sympatico.ca> Cc: joro@8bytes.org Link: https://lkml.kernel.org/r/1531906876-13451-37-git-send-email-joro@8bytes.org
1 parent 9bae319 commit 6df934b

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

arch/x86/include/asm/mmu_context.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ struct ldt_struct {
7171

7272
static inline void *ldt_slot_va(int slot)
7373
{
74-
#ifdef CONFIG_X86_64
7574
return (void *)(LDT_BASE_ADDR + LDT_SLOT_STRIDE * slot);
76-
#else
77-
BUG();
78-
return (void *)fix_to_virt(FIX_HOLE);
79-
#endif
8075
}
8176

8277
/*

arch/x86/kernel/ldt.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,57 @@ static void do_sanity_check(struct mm_struct *mm,
126126
}
127127
}
128128

129+
#ifdef CONFIG_X86_PAE
130+
131+
static pmd_t *pgd_to_pmd_walk(pgd_t *pgd, unsigned long va)
132+
{
133+
p4d_t *p4d;
134+
pud_t *pud;
135+
136+
if (pgd->pgd == 0)
137+
return NULL;
138+
139+
p4d = p4d_offset(pgd, va);
140+
if (p4d_none(*p4d))
141+
return NULL;
142+
143+
pud = pud_offset(p4d, va);
144+
if (pud_none(*pud))
145+
return NULL;
146+
147+
return pmd_offset(pud, va);
148+
}
149+
150+
static void map_ldt_struct_to_user(struct mm_struct *mm)
151+
{
152+
pgd_t *k_pgd = pgd_offset(mm, LDT_BASE_ADDR);
153+
pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd);
154+
pmd_t *k_pmd, *u_pmd;
155+
156+
k_pmd = pgd_to_pmd_walk(k_pgd, LDT_BASE_ADDR);
157+
u_pmd = pgd_to_pmd_walk(u_pgd, LDT_BASE_ADDR);
158+
159+
if (static_cpu_has(X86_FEATURE_PTI) && !mm->context.ldt)
160+
set_pmd(u_pmd, *k_pmd);
161+
}
162+
163+
static void sanity_check_ldt_mapping(struct mm_struct *mm)
164+
{
165+
pgd_t *k_pgd = pgd_offset(mm, LDT_BASE_ADDR);
166+
pgd_t *u_pgd = kernel_to_user_pgdp(k_pgd);
167+
bool had_kernel, had_user;
168+
pmd_t *k_pmd, *u_pmd;
169+
170+
k_pmd = pgd_to_pmd_walk(k_pgd, LDT_BASE_ADDR);
171+
u_pmd = pgd_to_pmd_walk(u_pgd, LDT_BASE_ADDR);
172+
had_kernel = (k_pmd->pmd != 0);
173+
had_user = (u_pmd->pmd != 0);
174+
175+
do_sanity_check(mm, had_kernel, had_user);
176+
}
177+
178+
#else /* !CONFIG_X86_PAE */
179+
129180
static void map_ldt_struct_to_user(struct mm_struct *mm)
130181
{
131182
pgd_t *pgd = pgd_offset(mm, LDT_BASE_ADDR);
@@ -143,6 +194,8 @@ static void sanity_check_ldt_mapping(struct mm_struct *mm)
143194
do_sanity_check(mm, had_kernel, had_user);
144195
}
145196

197+
#endif /* CONFIG_X86_PAE */
198+
146199
/*
147200
* If PTI is enabled, this maps the LDT into the kernelmode and
148201
* usermode tables for the given mm.

0 commit comments

Comments
 (0)