Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
9245ec0
Documentation
LICENSES
arch
alpha
arc
arm
arm64
csky
hexagon
ia64
loongarch
m68k
microblaze
mips
nios2
openrisc
parisc
powerpc
riscv
s390
sh
sparc
um
x86
boot
coco
configs
crypto
entry
events
hyperv
ia32
include
kernel
kvm
lib
.gitignore
Makefile
atomic64_32.c
atomic64_386_32.S
atomic64_cx8_32.S
cache-smp.c
checksum_32.S
clear_page_64.S
cmdline.c
cmpxchg16b_emu.S
cmpxchg8b_emu.S
copy_mc.c
copy_mc_64.S
copy_page_64.S
copy_user_64.S
cpu.c
csum-copy_64.S
csum-partial_64.c
csum-wrappers_64.c
delay.c
error-inject.c
getuser.S
hweight.S
inat.c
insn-eval.c
insn.c
iomap_copy_64.S
iomem.c
kaslr.c
memcpy_32.c
memcpy_64.S
memmove_64.S
memset_64.S
misc.c
msr-reg-export.c
msr-reg.S
msr-smp.c
msr.c
pc-conf-reg.c
putuser.S
retpoline.S
string_32.c
strstr_32.c
usercopy.c
usercopy_32.c
usercopy_64.c
x86-opcode-map.txt
math-emu
mm
net
pci
platform
power
purgatory
ras
realmode
tools
um
video
virt
xen
.gitignore
Kbuild
Kconfig
Kconfig.assembler
Kconfig.cpu
Kconfig.debug
Makefile
Makefile.um
Makefile_32.cpu
xtensa
.gitignore
Kconfig
block
certs
crypto
drivers
fs
include
init
io_uring
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
arch
/
x86
/
lib
/
iomem.c
Copy path
Blame
Blame
Latest commit
History
History
123 lines (108 loc) · 2.91 KB
Breadcrumbs
linux
/
arch
/
x86
/
lib
/
iomem.c
Top
File metadata and controls
Code
Blame
123 lines (108 loc) · 2.91 KB
Raw
#include <linux/string.h> #include <linux/module.h> #include <linux/io.h> #include <linux/kmsan-checks.h> #define movs(type,to,from) \ asm volatile("movs" type:"=&D" (to), "=&S" (from):"0" (to), "1" (from):"memory") /* Originally from i386/string.h */ static __always_inline void rep_movs(void *to, const void *from, size_t n) { unsigned long d0, d1, d2; asm volatile("rep ; movsl\n\t" "testb $2,%b4\n\t" "je 1f\n\t" "movsw\n" "1:\ttestb $1,%b4\n\t" "je 2f\n\t" "movsb\n" "2:" : "=&c" (d0), "=&D" (d1), "=&S" (d2) : "0" (n / 4), "q" (n), "1" ((long)to), "2" ((long)from) : "memory"); } static void string_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) { if (unlikely(!n)) return; /* Align any unaligned source IO */ if (unlikely(1 & (unsigned long)from)) { movs("b", to, from); n--; } if (n > 1 && unlikely(2 & (unsigned long)from)) { movs("w", to, from); n-=2; } rep_movs(to, (const void *)from, n); /* KMSAN must treat values read from devices as initialized. */ kmsan_unpoison_memory(to, n); } static void string_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) { if (unlikely(!n)) return; /* Make sure uninitialized memory isn't copied to devices. */ kmsan_check_memory(from, n); /* Align any unaligned destination IO */ if (unlikely(1 & (unsigned long)to)) { movs("b", to, from); n--; } if (n > 1 && unlikely(2 & (unsigned long)to)) { movs("w", to, from); n-=2; } rep_movs((void *)to, (const void *) from, n); } static void unrolled_memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) { const volatile char __iomem *in = from; char *out = to; int i; for (i = 0; i < n; ++i) out[i] = readb(&in[i]); } static void unrolled_memcpy_toio(volatile void __iomem *to, const void *from, size_t n) { volatile char __iomem *out = to; const char *in = from; int i; for (i = 0; i < n; ++i) writeb(in[i], &out[i]); } static void unrolled_memset_io(volatile void __iomem *a, int b, size_t c) { volatile char __iomem *mem = a; int i; for (i = 0; i < c; ++i) writeb(b, &mem[i]); } void memcpy_fromio(void *to, const volatile void __iomem *from, size_t n) { if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) unrolled_memcpy_fromio(to, from, n); else string_memcpy_fromio(to, from, n); } EXPORT_SYMBOL(memcpy_fromio); void memcpy_toio(volatile void __iomem *to, const void *from, size_t n) { if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) unrolled_memcpy_toio(to, from, n); else string_memcpy_toio(to, from, n); } EXPORT_SYMBOL(memcpy_toio); void memset_io(volatile void __iomem *a, int b, size_t c) { if (cc_platform_has(CC_ATTR_GUEST_UNROLL_STRING_IO)) { unrolled_memset_io(a, b, c); } else { /* * TODO: memset can mangle the IO patterns quite a bit. * perhaps it would be better to use a dumb one: */ memset((void *)a, b, c); } } EXPORT_SYMBOL(memset_io);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
You can’t perform that action at this time.