Skip to content

Commit 8b5abde

Browse files
committed
Merge branch 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 mm updates from Ingo Molnar: "A laundry list of changes: KASAN improvements/fixes for ptdump, a self-test fix, PAT cleanup and wbinvd() avoidance, removal of stale code and documentation updates" * 'x86-mm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/mm/ptdump: Add address marker for KASAN shadow region x86/mm/ptdump: Optimize check for W+X mappings for CONFIG_KASAN=y x86/mm/pat: Use rb_entry() x86/mpx: Re-add MPX to selftests Makefile x86/mm: Remove CONFIG_DEBUG_NX_TEST x86/mm/cpa: Avoid wbinvd() for PREEMPT x86/mm: Improve documentation for low-level device I/O functions
2 parents a25a1d6 + 025205f commit 8b5abde

File tree

8 files changed

+79
-201
lines changed

8 files changed

+79
-201
lines changed

arch/x86/Kconfig.debug

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,6 @@ config DEBUG_SET_MODULE_RONX
120120
against certain classes of kernel exploits.
121121
If in doubt, say "N".
122122

123-
config DEBUG_NX_TEST
124-
tristate "Testcase for the NX non-executable stack feature"
125-
depends on DEBUG_KERNEL && m
126-
---help---
127-
This option enables a testcase for the CPU NX capability
128-
and the software setup of this feature.
129-
If in doubt, say "N"
130-
131123
config DOUBLEFAULT
132124
default y
133125
bool "Enable doublefault exception handler" if EXPERT

arch/x86/include/asm/io.h

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ static inline unsigned int isa_virt_to_bus(volatile void *address)
164164
#define virt_to_bus virt_to_phys
165165
#define bus_to_virt phys_to_virt
166166

167+
/*
168+
* The default ioremap() behavior is non-cached; if you need something
169+
* else, you probably want one of the following.
170+
*/
171+
extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
172+
extern void __iomem *ioremap_uc(resource_size_t offset, unsigned long size);
173+
#define ioremap_uc ioremap_uc
174+
175+
extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
176+
extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size, unsigned long prot_val);
177+
167178
/**
168179
* ioremap - map bus memory into CPU space
169180
* @offset: bus address of the memory
@@ -178,17 +189,6 @@ static inline unsigned int isa_virt_to_bus(volatile void *address)
178189
* If the area you are trying to map is a PCI BAR you should have a
179190
* look at pci_iomap().
180191
*/
181-
extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
182-
extern void __iomem *ioremap_uc(resource_size_t offset, unsigned long size);
183-
#define ioremap_uc ioremap_uc
184-
185-
extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
186-
extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
187-
unsigned long prot_val);
188-
189-
/*
190-
* The default ioremap() behavior is non-cached:
191-
*/
192192
static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
193193
{
194194
return ioremap_nocache(offset, size);
@@ -207,18 +207,42 @@ extern void set_iounmap_nonlazy(void);
207207
*/
208208
#define xlate_dev_kmem_ptr(p) p
209209

210+
/**
211+
* memset_io Set a range of I/O memory to a constant value
212+
* @addr: The beginning of the I/O-memory range to set
213+
* @val: The value to set the memory to
214+
* @count: The number of bytes to set
215+
*
216+
* Set a range of I/O memory to a given value.
217+
*/
210218
static inline void
211219
memset_io(volatile void __iomem *addr, unsigned char val, size_t count)
212220
{
213221
memset((void __force *)addr, val, count);
214222
}
215223

224+
/**
225+
* memcpy_fromio Copy a block of data from I/O memory
226+
* @dst: The (RAM) destination for the copy
227+
* @src: The (I/O memory) source for the data
228+
* @count: The number of bytes to copy
229+
*
230+
* Copy a block of data from I/O memory.
231+
*/
216232
static inline void
217233
memcpy_fromio(void *dst, const volatile void __iomem *src, size_t count)
218234
{
219235
memcpy(dst, (const void __force *)src, count);
220236
}
221237

238+
/**
239+
* memcpy_toio Copy a block of data into I/O memory
240+
* @dst: The (I/O memory) destination for the copy
241+
* @src: The (RAM) source for the data
242+
* @count: The number of bytes to copy
243+
*
244+
* Copy a block of data to I/O memory.
245+
*/
222246
static inline void
223247
memcpy_toio(volatile void __iomem *dst, const void *src, size_t count)
224248
{

arch/x86/kernel/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ obj-$(CONFIG_APB_TIMER) += apb_timer.o
101101

102102
obj-$(CONFIG_AMD_NB) += amd_nb.o
103103
obj-$(CONFIG_DEBUG_RODATA_TEST) += test_rodata.o
104-
obj-$(CONFIG_DEBUG_NX_TEST) += test_nx.o
105104
obj-$(CONFIG_DEBUG_NMI_SELFTEST) += nmi_selftest.o
106105

107106
obj-$(CONFIG_KVM_GUEST) += kvm.o kvmclock.o

arch/x86/kernel/test_nx.c

Lines changed: 0 additions & 173 deletions
This file was deleted.

arch/x86/mm/dump_pagetables.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/sched.h>
1919
#include <linux/seq_file.h>
2020

21+
#include <asm/kasan.h>
2122
#include <asm/pgtable.h>
2223

2324
/*
@@ -51,6 +52,10 @@ enum address_markers_idx {
5152
LOW_KERNEL_NR,
5253
VMALLOC_START_NR,
5354
VMEMMAP_START_NR,
55+
#ifdef CONFIG_KASAN
56+
KASAN_SHADOW_START_NR,
57+
KASAN_SHADOW_END_NR,
58+
#endif
5459
# ifdef CONFIG_X86_ESPFIX64
5560
ESPFIX_START_NR,
5661
# endif
@@ -76,6 +81,10 @@ static struct addr_marker address_markers[] = {
7681
{ 0/* PAGE_OFFSET */, "Low Kernel Mapping" },
7782
{ 0/* VMALLOC_START */, "vmalloc() Area" },
7883
{ 0/* VMEMMAP_START */, "Vmemmap" },
84+
#ifdef CONFIG_KASAN
85+
{ KASAN_SHADOW_START, "KASAN shadow" },
86+
{ KASAN_SHADOW_END, "KASAN shadow end" },
87+
#endif
7988
# ifdef CONFIG_X86_ESPFIX64
8089
{ ESPFIX_BASE_ADDR, "ESPfix Area", 16 },
8190
# endif
@@ -327,18 +336,31 @@ static void walk_pmd_level(struct seq_file *m, struct pg_state *st, pud_t addr,
327336

328337
#if PTRS_PER_PUD > 1
329338

339+
/*
340+
* This is an optimization for CONFIG_DEBUG_WX=y + CONFIG_KASAN=y
341+
* KASAN fills page tables with the same values. Since there is no
342+
* point in checking page table more than once we just skip repeated
343+
* entries. This saves us dozens of seconds during boot.
344+
*/
345+
static bool pud_already_checked(pud_t *prev_pud, pud_t *pud, bool checkwx)
346+
{
347+
return checkwx && prev_pud && (pud_val(*prev_pud) == pud_val(*pud));
348+
}
349+
330350
static void walk_pud_level(struct seq_file *m, struct pg_state *st, pgd_t addr,
331351
unsigned long P)
332352
{
333353
int i;
334354
pud_t *start;
335355
pgprotval_t prot;
356+
pud_t *prev_pud = NULL;
336357

337358
start = (pud_t *) pgd_page_vaddr(addr);
338359

339360
for (i = 0; i < PTRS_PER_PUD; i++) {
340361
st->current_address = normalize_addr(P + i * PUD_LEVEL_MULT);
341-
if (!pud_none(*start)) {
362+
if (!pud_none(*start) &&
363+
!pud_already_checked(prev_pud, start, st->check_wx)) {
342364
if (pud_large(*start) || !pud_present(*start)) {
343365
prot = pud_flags(*start);
344366
note_page(m, st, __pgprot(prot), 2);
@@ -349,6 +371,7 @@ static void walk_pud_level(struct seq_file *m, struct pg_state *st, pgd_t addr,
349371
} else
350372
note_page(m, st, __pgprot(0), 2);
351373

374+
prev_pud = start;
352375
start++;
353376
}
354377
}

arch/x86/mm/pageattr.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,20 @@ static void cpa_flush_array(unsigned long *start, int numpages, int cache,
214214
int in_flags, struct page **pages)
215215
{
216216
unsigned int i, level;
217+
#ifdef CONFIG_PREEMPT
218+
/*
219+
* Avoid wbinvd() because it causes latencies on all CPUs,
220+
* regardless of any CPU isolation that may be in effect.
221+
*
222+
* This should be extended for CAT enabled systems independent of
223+
* PREEMPT because wbinvd() does not respect the CAT partitions and
224+
* this is exposed to unpriviledged users through the graphics
225+
* subsystem.
226+
*/
227+
unsigned long do_wbinvd = 0;
228+
#else
217229
unsigned long do_wbinvd = cache && numpages >= 1024; /* 4M threshold */
230+
#endif
218231

219232
BUG_ON(irqs_disabled());
220233

0 commit comments

Comments
 (0)