Skip to content

Commit 160729a

Browse files
committed
Merge tag 'x86_misc_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull misc x86 changes from Borislav Petkov: - Use the proper interface for the job: get_unaligned() instead of memcpy() in the insn decoder - A randconfig build fix * tag 'x86_misc_for_v5.16_rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/insn: Use get_unaligned() instead of memcpy() x86/Kconfig: Fix an unused variable error in dell-smm-hwmon
2 parents e0f4c59 + f96b467 commit 160729a

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

arch/x86/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,8 @@ config TOSHIBA
12661266

12671267
config I8K
12681268
tristate "Dell i8k legacy laptop support"
1269-
select HWMON
1269+
depends on HWMON
1270+
depends on PROC_FS
12701271
select SENSORS_DELL_SMM
12711272
help
12721273
This option enables legacy /proc/i8k userspace interface in hwmon

arch/x86/lib/insn.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414
#include <asm/inat.h> /*__ignore_sync_check__ */
1515
#include <asm/insn.h> /* __ignore_sync_check__ */
16+
#include <asm/unaligned.h> /* __ignore_sync_check__ */
1617

1718
#include <linux/errno.h>
1819
#include <linux/kconfig.h>
@@ -37,10 +38,10 @@
3738
((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
3839

3940
#define __get_next(t, insn) \
40-
({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })
41+
({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })
4142

4243
#define __peek_nbyte_next(t, insn, n) \
43-
({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })
44+
({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })
4445

4546
#define get_next(t, insn) \
4647
({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })

tools/arch/x86/lib/insn.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#endif
1414
#include "../include/asm/inat.h" /* __ignore_sync_check__ */
1515
#include "../include/asm/insn.h" /* __ignore_sync_check__ */
16+
#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */
1617

1718
#include <linux/errno.h>
1819
#include <linux/kconfig.h>
@@ -37,10 +38,10 @@
3738
((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)
3839

3940
#define __get_next(t, insn) \
40-
({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })
41+
({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })
4142

4243
#define __peek_nbyte_next(t, insn, n) \
43-
({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })
44+
({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })
4445

4546
#define get_next(t, insn) \
4647
({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })

tools/include/asm-generic/unaligned.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copied from the kernel sources to tools/perf/:
4+
*/
5+
6+
#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
7+
#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
8+
9+
#define __get_unaligned_t(type, ptr) ({ \
10+
const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
11+
__pptr->x; \
12+
})
13+
14+
#define __put_unaligned_t(type, val, ptr) do { \
15+
struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
16+
__pptr->x = (val); \
17+
} while (0)
18+
19+
#define get_unaligned(ptr) __get_unaligned_t(typeof(*(ptr)), (ptr))
20+
#define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
21+
22+
#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
23+

tools/perf/util/intel-pt-decoder/Build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ CFLAGS_intel-pt-insn-decoder.o += -I$(OUTPUT)util/intel-pt-decoder
1818
ifeq ($(CC_NO_CLANG), 1)
1919
CFLAGS_intel-pt-insn-decoder.o += -Wno-override-init
2020
endif
21+
22+
CFLAGS_intel-pt-insn-decoder.o += -Wno-packed

0 commit comments

Comments
 (0)