Skip to content

Commit b3fec0f

Browse files
committed
Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/vegard/kmemcheck
* 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/vegard/kmemcheck: (39 commits) signal: fix __send_signal() false positive kmemcheck warning fs: fix do_mount_root() false positive kmemcheck warning fs: introduce __getname_gfp() trace: annotate bitfields in struct ring_buffer_event net: annotate struct sock bitfield c2port: annotate bitfield for kmemcheck net: annotate inet_timewait_sock bitfields ieee1394/csr1212: fix false positive kmemcheck report ieee1394: annotate bitfield net: annotate bitfields in struct inet_sock net: use kmemcheck bitfields API for skbuff kmemcheck: introduce bitfield API kmemcheck: add opcode self-testing at boot x86: unify pte_hidden x86: make _PAGE_HIDDEN conditional kmemcheck: make kconfig accessible for other architectures kmemcheck: enable in the x86 Kconfig kmemcheck: add hooks for the page allocator kmemcheck: add hooks for page- and sg-dma-mappings kmemcheck: don't track page tables ...
2 parents e1f5b94 + 722f2a6 commit b3fec0f

71 files changed

Lines changed: 2899 additions & 128 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/kmemcheck.txt‎

Lines changed: 773 additions & 0 deletions
Large diffs are not rendered by default.

‎MAINTAINERS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3406,6 +3406,14 @@ F: drivers/serial/kgdboc.c
34063406
F: include/linux/kgdb.h
34073407
F: kernel/kgdb.c
34083408

3409+
KMEMCHECK
3410+
P: Vegard Nossum
3411+
M: vegardno@ifi.uio.no
3412+
P Pekka Enberg
3413+
M: penberg@cs.helsinki.fi
3414+
L: linux-kernel@vger.kernel.org
3415+
S: Maintained
3416+
34093417
KMEMLEAK
34103418
P: Catalin Marinas
34113419
M: catalin.marinas@arm.com

‎arch/x86/Kconfig‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ config X86
4646
select HAVE_KERNEL_GZIP
4747
select HAVE_KERNEL_BZIP2
4848
select HAVE_KERNEL_LZMA
49+
select HAVE_ARCH_KMEMCHECK
4950

5051
config OUTPUT_FORMAT
5152
string

‎arch/x86/Makefile‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ ifdef CONFIG_CC_STACKPROTECTOR
8181
endif
8282
endif
8383

84+
# Don't unroll struct assignments with kmemcheck enabled
85+
ifeq ($(CONFIG_KMEMCHECK),y)
86+
KBUILD_CFLAGS += $(call cc-option,-fno-builtin-memcpy)
87+
endif
88+
8489
# Stackpointer is addressed different for 32 bit and 64 bit x86
8590
sp-$(CONFIG_X86_32) := esp
8691
sp-$(CONFIG_X86_64) := rsp

‎arch/x86/include/asm/dma-mapping.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Documentation/DMA-API.txt for documentation.
77
*/
88

9+
#include <linux/kmemcheck.h>
910
#include <linux/scatterlist.h>
1011
#include <linux/dma-debug.h>
1112
#include <linux/dma-attrs.h>
@@ -60,6 +61,7 @@ dma_map_single(struct device *hwdev, void *ptr, size_t size,
6061
dma_addr_t addr;
6162

6263
BUG_ON(!valid_dma_direction(dir));
64+
kmemcheck_mark_initialized(ptr, size);
6365
addr = ops->map_page(hwdev, virt_to_page(ptr),
6466
(unsigned long)ptr & ~PAGE_MASK, size,
6567
dir, NULL);
@@ -87,8 +89,12 @@ dma_map_sg(struct device *hwdev, struct scatterlist *sg,
8789
{
8890
struct dma_map_ops *ops = get_dma_ops(hwdev);
8991
int ents;
92+
struct scatterlist *s;
93+
int i;
9094

9195
BUG_ON(!valid_dma_direction(dir));
96+
for_each_sg(sg, s, nents, i)
97+
kmemcheck_mark_initialized(sg_virt(s), s->length);
9298
ents = ops->map_sg(hwdev, sg, nents, dir, NULL);
9399
debug_dma_map_sg(hwdev, sg, nents, ents, dir);
94100

@@ -200,6 +206,7 @@ static inline dma_addr_t dma_map_page(struct device *dev, struct page *page,
200206
dma_addr_t addr;
201207

202208
BUG_ON(!valid_dma_direction(dir));
209+
kmemcheck_mark_initialized(page_address(page) + offset, size);
203210
addr = ops->map_page(dev, page, offset, size, dir, NULL);
204211
debug_dma_map_page(dev, page, offset, size, dir, addr, false);
205212

‎arch/x86/include/asm/kmemcheck.h‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#ifndef ASM_X86_KMEMCHECK_H
2+
#define ASM_X86_KMEMCHECK_H
3+
4+
#include <linux/types.h>
5+
#include <asm/ptrace.h>
6+
7+
#ifdef CONFIG_KMEMCHECK
8+
bool kmemcheck_active(struct pt_regs *regs);
9+
10+
void kmemcheck_show(struct pt_regs *regs);
11+
void kmemcheck_hide(struct pt_regs *regs);
12+
13+
bool kmemcheck_fault(struct pt_regs *regs,
14+
unsigned long address, unsigned long error_code);
15+
bool kmemcheck_trap(struct pt_regs *regs);
16+
#else
17+
static inline bool kmemcheck_active(struct pt_regs *regs)
18+
{
19+
return false;
20+
}
21+
22+
static inline void kmemcheck_show(struct pt_regs *regs)
23+
{
24+
}
25+
26+
static inline void kmemcheck_hide(struct pt_regs *regs)
27+
{
28+
}
29+
30+
static inline bool kmemcheck_fault(struct pt_regs *regs,
31+
unsigned long address, unsigned long error_code)
32+
{
33+
return false;
34+
}
35+
36+
static inline bool kmemcheck_trap(struct pt_regs *regs)
37+
{
38+
return false;
39+
}
40+
#endif /* CONFIG_KMEMCHECK */
41+
42+
#endif

‎arch/x86/include/asm/pgtable.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,11 @@ static inline int pte_present(pte_t a)
317317
return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE);
318318
}
319319

320+
static inline int pte_hidden(pte_t pte)
321+
{
322+
return pte_flags(pte) & _PAGE_HIDDEN;
323+
}
324+
320325
static inline int pmd_present(pmd_t pmd)
321326
{
322327
return pmd_flags(pmd) & _PAGE_PRESENT;

‎arch/x86/include/asm/pgtable_types.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
1919
#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
2020
#define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
21-
#define _PAGE_BIT_UNUSED3 11
21+
#define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
2222
#define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
2323
#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
2424
#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
@@ -41,13 +41,18 @@
4141
#define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
4242
#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
4343
#define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
44-
#define _PAGE_UNUSED3 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
4544
#define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
4645
#define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
4746
#define _PAGE_SPECIAL (_AT(pteval_t, 1) << _PAGE_BIT_SPECIAL)
4847
#define _PAGE_CPA_TEST (_AT(pteval_t, 1) << _PAGE_BIT_CPA_TEST)
4948
#define __HAVE_ARCH_PTE_SPECIAL
5049

50+
#ifdef CONFIG_KMEMCHECK
51+
#define _PAGE_HIDDEN (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
52+
#else
53+
#define _PAGE_HIDDEN (_AT(pteval_t, 0))
54+
#endif
55+
5156
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
5257
#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
5358
#else

‎arch/x86/include/asm/string_32.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,18 @@ static inline void *__memcpy3d(void *to, const void *from, size_t len)
177177
* No 3D Now!
178178
*/
179179

180+
#ifndef CONFIG_KMEMCHECK
180181
#define memcpy(t, f, n) \
181182
(__builtin_constant_p((n)) \
182183
? __constant_memcpy((t), (f), (n)) \
183184
: __memcpy((t), (f), (n)))
185+
#else
186+
/*
187+
* kmemcheck becomes very happy if we use the REP instructions unconditionally,
188+
* because it means that we know both memory operands in advance.
189+
*/
190+
#define memcpy(t, f, n) __memcpy((t), (f), (n))
191+
#endif
184192

185193
#endif
186194

‎arch/x86/include/asm/string_64.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ static __always_inline void *__inline_memcpy(void *to, const void *from, size_t
2727
function. */
2828

2929
#define __HAVE_ARCH_MEMCPY 1
30+
#ifndef CONFIG_KMEMCHECK
3031
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
3132
extern void *memcpy(void *to, const void *from, size_t len);
3233
#else
@@ -42,6 +43,13 @@ extern void *__memcpy(void *to, const void *from, size_t len);
4243
__ret; \
4344
})
4445
#endif
46+
#else
47+
/*
48+
* kmemcheck becomes very happy if we use the REP instructions unconditionally,
49+
* because it means that we know both memory operands in advance.
50+
*/
51+
#define memcpy(dst, src, len) __inline_memcpy((dst), (src), (len))
52+
#endif
4553

4654
#define __HAVE_ARCH_MEMSET
4755
void *memset(void *s, int c, size_t n);

0 commit comments

Comments
 (0)