irq/urgent for v5.15-rc3
Subsystems (10)
Linus,
please pull the latest irq/urgent branch from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git irq-urgent-2021-09-26
up to: f9bfed3ad5b1: Merge tag 'irqchip-fixes-5.15-1' of git://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms into irq/urgent
A set of fixes for interrupt chip drivers:
- Work around a bad GIC integration on a Renesas platform which can't handle byte-sized MMIO access
- Plug a potential memory leak in the GICv4 driver
- Fix a regression in the Armada 370-XP IPI code which was caused by issuing EOI instack of ACK.
- A couple of small fixes here and there
Thanks,
tglx
------------------>
Bixuan Cui (1):
irqdomain: Change the type of 'size' in __irq_domain_add() to be consistent
Geert Uytterhoeven (1):
irqchip/renesas-rza1: Use semicolons instead of commas
Kaige Fu (1):
irqchip/gic-v3-its: Fix potential VPE leak on error
Marc Zyngier (3):
Documentation: Fix irq-domain.rst build warning irqchip/armada-370-xp: Fix ack/eoi breakage irqchip/gic: Work around broken Renesas integration
Randy Dunlap (2):
irqchip/mbigen: Repair non-kernel-doc notation irqchip/goldfish-pic: Select GENERIC_IRQ_CHIP to fix build
Documentation/core-api/irq/irq-domain.rst | 5 +-- drivers/irqchip/Kconfig | 1 + drivers/irqchip/irq-armada-370-xp.c | 4 +-- drivers/irqchip/irq-gic-v3-its.c | 2 +- drivers/irqchip/irq-gic.c | 52 ++++++++++++++++++++++++++++++- drivers/irqchip/irq-mbigen.c | 6 ++-- drivers/irqchip/irq-renesas-rza1.c | 12 +++---- include/linux/irqdomain.h | 2 +- kernel/irq/irqdomain.c | 2 +- 9 files changed, 69 insertions(+), 17 deletions(-)
Documentation/core-api/irq/irq-domain.rst +3 -2
@@ -175,9 +175,10 @@ for IRQ numbers that are passed to struct device registrations. In that case the Linux IRQ numbers cannot be dynamically assigned and the legacy mapping should be used. -As the name implies, the *_legacy() functions are deprecated and only +As the name implies, the \*_legacy() functions are deprecated and only exist to ease the support of ancient platforms. No new users should be -added. +added. Same goes for the \*_simple() functions when their use results +in the legacy behaviour. The legacy map assumes a contiguous range of IRQ numbers has already been allocated for the controller and that the IRQ number can be
drivers/irqchip/Kconfig +1 -0
@@ -409,6 +409,7 @@ config MESON_IRQ_GPIO config GOLDFISH_PIC bool "Goldfish programmable interrupt controller" depends on MIPS && (GOLDFISH || COMPILE_TEST) + select GENERIC_IRQ_CHIP select IRQ_DOMAIN help Say yes here to enable Goldfish interrupt controller driver used
drivers/irqchip/irq-armada-370-xp.c +2 -2
@@ -359,16 +359,16 @@ static void armada_370_xp_ipi_send_mask(struct irq_data *d, ARMADA_370_XP_SW_TRIG_INT_OFFS); } -static void armada_370_xp_ipi_eoi (struct irq_data *d) +static void armada_370_xp_ipi_ack (struct irq_data *d) {writel (~BIT (d->hwirq), per_cpu_int_base +ARMADA_370_XP_IN_DRBEL_CAUSE_OFFS ); }static struct irq_chip ipi_irqchip = { .name ="IPI" , + .irq_ack = armada_370_xp_ipi_ack, .irq_mask = armada_370_xp_ipi_mask, .irq_unmask = armada_370_xp_ipi_unmask, - .irq_eoi = armada_370_xp_ipi_eoi, .ipi_send_mask = armada_370_xp_ipi_send_mask, };
drivers/irqchip/irq-gic-v3-its.c +1 -1
@@ -4501,7 +4501,7 @@ static int its_vpe_irq_domain_alloc(struct irq_domain *domain, unsigned int virqif (err) {if (i >0 ) -its_vpe_irq_domain_free (domain, virq, i -1 ); +its_vpe_irq_domain_free (domain, virq, i);its_lpi_free (bitmap, base, nr_ids);its_free_prop_table (vprop_page);
drivers/irqchip/irq-gic.c +51 -1
82 lines not on this page · raw message
drivers/irqchip/irq-mbigen.c +3 -3
@@ -25,7 +25,7 @@/* The maximum IRQ pin number of mbigen chip(start from 0) */ #define MAXIMUM_IRQ_PIN_NUM 1407 -/** +/* * In mbigen vector register * bit[21:12]: event id value * bit[11:0]: device id
@@ -39,14 +39,14 @@/* offset of vector register in mbigen node */ #define REG_MBIGEN_VEC_OFFSET 0x200 -/** +/* * offset of clear register in mbigen node * This register is used to clear the status * of interrupt */ #define REG_MBIGEN_CLEAR_OFFSET 0xa000 -/** +/* * offset of interrupt type register * This register is used to configure interrupt * trigger type
drivers/irqchip/irq-renesas-rza1.c +6 -6
@@ -223,12 +223,12 @@ static int rza1_irqc_probe(struct platform_device *pdev) goto out_put_node; } - priv->chip.name ="rza1-irqc" , - priv->chip.irq_mask = irq_chip_mask_parent, - priv->chip.irq_unmask = irq_chip_unmask_parent, - priv->chip.irq_eoi = rza1_irqc_eoi, - priv->chip.irq_retrigger = irq_chip_retrigger_hierarchy, - priv->chip.irq_set_type = rza1_irqc_set_type, + priv->chip.name ="rza1-irqc" ; + priv->chip.irq_mask = irq_chip_mask_parent; + priv->chip.irq_unmask = irq_chip_unmask_parent; + priv->chip.irq_eoi = rza1_irqc_eoi; + priv->chip.irq_retrigger = irq_chip_retrigger_hierarchy; + priv->chip.irq_set_type = rza1_irqc_set_type; priv->chip.flags =IRQCHIP_MASK_ON_SUSPEND |IRQCHIP_SKIP_SET_WAKE ; priv->irq_domain = irq_domain_add_hierarchy(parent, 0, IRQC_NUM_IRQ,
include/linux/irqdomain.h +1 -1
@@ -251,7 +251,7 @@ static inline struct fwnode_handle *irq_domain_alloc_fwnode(phys_addr_t *pa) }void irq_domain_free_fwnode (struct fwnode_handle *fwnode); -struct irq_domain *__irq_domain_add (struct fwnode_handle *fwnode,int size, +struct irq_domain *__irq_domain_add (struct fwnode_handle *fwnode,unsigned int size,irq_hw_number_t hwirq_max,int direct_max,const struct irq_domain_ops *ops,void *host_data);
kernel/irq/irqdomain.c +1 -1
@@ -136,7 +136,7 @@ EXPORT_SYMBOL_GPL(irq_domain_free_fwnode);* Allocates and initializes an irq_domain structure. * Returns pointer to IRQ domain, or NULL on failure. */ -struct irq_domain *__irq_domain_add (struct fwnode_handle *fwnode,int size, +struct irq_domain *__irq_domain_add (struct fwnode_handle *fwnode,unsigned int size,irq_hw_number_t hwirq_max,int direct_max,const struct irq_domain_ops *ops,void *host_data)
[GIT pull] timers/urgent for v5.15-rc3
Linus,
please pull the latest timers/urgent branch from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git timers-urgent-2021-09-26
up to: 8cd9da85d2bd: posix-cpu-timers: Prevent spuriously armed 0-value itimer
A single fix for the recently introduced regression in posix CPU timers which failed to stop the timer when requested. That caused unexpected signals to be sent to the process/thread causing malfunction.
Thanks,
tglx
------------------>
Frederic Weisbecker (1):
posix-cpu-timers: Prevent spuriously armed 0-value itimer
kernel/time/posix-cpu-timers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/time/posix-cpu-timers.c +2 -1
@@ -1404,7 +1404,8 @@ void set_process_cpu_timer(struct task_struct *tsk, unsigned int clkid, } } - *newval += now; +if (*newval) + *newval += now; }/*
Re: [GIT pull] timers/urgent for v5.15-rc3
The pull request you sent on Sun, 26 Sep 2021 12:30:07 +0200 (CEST):
The pull request you sent on Sun, 26 Sep 2021 12:30:07 +0200 (CEST):
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gittimers-urgent-2021-09-26
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/3a398acc56dd7592eba081ce1ea356151ab90e2d
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
[GIT pull] x86/urgent for v5.15-rc3
In reply to Thomas GleixnerLinus,
please pull the latest x86/urgent branch from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git x86-urgent-2021-09-26
up to: 5ba1071f7554: x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses
A set of fixes for X86:
- Prevent sending the wrong signal when protection keys are enabled and the kernel handles a fault in the vsyscall emulation.
- Invoke early_reserve_memory() before invoking e820_memory_setup() which is required to make the Xen dom0 e820 hooks work correctly.
- Use the correct data type for the SETZ operand in the EMQCMDS instruction wrapper.
- Prevent undefined behaviour to the potential unaligned accesss in the instroction decoder library.
Thanks,
tglx
------------------>
Jiashuo Liang (1):
x86/fault: Fix wrong signal when vsyscall fails with pkey
Juergen Gross (1):
x86/setup: Call early_reserve_memory() earlier
Kees Cook (1):
x86/asm: Fix SETZ size enqcmds() build failure
Numfor Mbiziwo-Tiapo (1):
x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses
arch/x86/include/asm/pkeys.h | 2 -- arch/x86/include/asm/special_insns.h | 2 +- arch/x86/kernel/setup.c | 26 ++++++++++++++------------ arch/x86/lib/insn.c | 4 ++-- arch/x86/mm/fault.c | 26 ++++++++++++++++++-------- include/linux/pkeys.h | 2 ++ tools/arch/x86/lib/insn.c | 4 ++-- 7 files changed, 39 insertions(+), 27 deletions(-)
arch/x86/include/asm/pkeys.h +0 -2
@@ -2,8 +2,6 @@#ifndef _ASM_X86_PKEYS_H#define _ASM_X86_PKEYS_H -#define ARCH_DEFAULT_PKEY 0 -/* * If more than 16 keys are ever supported, a thorough audit * will be necessary to ensure that the types that store key
arch/x86/include/asm/special_insns.h +1 -1
@@ -275,7 +275,7 @@ static inline int enqcmds(void __iomem *dst, const void *src) {const struct {char _[64 ]; } *__src = src;struct {char _[64 ]; }__iomem *__dst = dst; -int zf; +bool zf;/* * ENQCMDS %(rdx), rax
arch/x86/kernel/setup.c +14 -12
@@ -830,6 +830,20 @@ void __init setup_arch(char **cmdline_p) x86_init.oem.arch_setup (); +/* +* Do some memory reservations *before* memory is added to memblock, so +* memblock allocations won't overwrite it. +* +* After this point, everything still needed from the boot loader or +* firmware or kernel text should be early reserved or marked not RAM in +* e820. All other memory is free game. +* +* This call needs to happen before e820__memory_setup() which calls the +* xen_memory_setup() on Xen dom0 which relies on the fact that those +* early reservations have happened already. +*/ +early_reserve_memory (); + iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) -1 ;e820__memory_setup ();parse_setup_data ();
@@ -876,18 +890,6 @@ void __init setup_arch(char **cmdline_p)parse_early_param (); -/* -* Do some memory reservations *before* memory is added to -* memblock, so memblock allocations won't overwrite it. -* Do it after early param, so we could get (unlikely) panic from -* serial. -* -* After this point everything still needed from the boot loader or -* firmware or kernel text should be early reserved or marked not -* RAM in e820. All other memory is free game. -*/ -early_reserve_memory (); -#ifdef CONFIG_MEMORY_HOTPLUG /* * Memory used by the kernel cannot be hot-removed because Linux
arch/x86/lib/insn.c +2 -2
@@ -37,10 +37,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
arch/x86/mm/fault.c +18 -8
@@ -710,7 +710,8 @@ page_fault_oops(struct pt_regs *regs, unsigned long error_code, static noinline voidkernelmode_fixup_or_oops (struct pt_regs *regs,unsigned long error_code, -unsigned long address,int signal,int si_code) +unsigned long address,int signal,int si_code, +u32 pkey) {WARN_ON_ONCE (user_mode (regs));
@@ -735,8 +736,12 @@ kernelmode_fixup_or_oops(struct pt_regs *regs, unsigned long error_code,set_signal_archinfo (address, error_code); -/* XXX: hwpoison faults will set the wrong code. */ -force_sig_fault (signal, si_code, (void __user *)address); +if (si_code ==SEGV_PKUERR ) { +force_sig_pkuerr ((void __user *)address, pkey); + }else { +/* XXX: hwpoison faults will set the wrong code. */ +force_sig_fault (signal, si_code, (void __user *)address); + } }/*
@@ -798,7 +803,8 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,struct task_struct *tsk = current;if (!user_mode (regs)) { -kernelmode_fixup_or_oops (regs, error_code, address, pkey, si_code); +kernelmode_fixup_or_oops (regs, error_code, address, +SIGSEGV , si_code, pkey);return ; }
@@ -930,7 +936,8 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address, {/* Kernel mode? Handle exceptions or die: */ if (!user_mode (regs)) { -kernelmode_fixup_or_oops (regs, error_code, address,SIGBUS ,BUS_ADRERR ); +kernelmode_fixup_or_oops (regs, error_code, address, +SIGBUS ,BUS_ADRERR ,ARCH_DEFAULT_PKEY );return ; }
@@ -1396,7 +1403,8 @@ void do_user_addr_fault(struct pt_regs *regs,*/ if (!user_mode (regs))kernelmode_fixup_or_oops (regs, error_code, address, -SIGBUS ,BUS_ADRERR ); +SIGBUS ,BUS_ADRERR , +ARCH_DEFAULT_PKEY );return ; }
@@ -1416,7 +1424,8 @@ void do_user_addr_fault(struct pt_regs *regs,return ;if (fatal_signal_pending (current) && !user_mode (regs)) { -kernelmode_fixup_or_oops (regs, error_code, address,0 ,0 ); +kernelmode_fixup_or_oops (regs, error_code, address, +0 ,0 ,ARCH_DEFAULT_PKEY );return ; }
@@ -1424,7 +1433,8 @@ void do_user_addr_fault(struct pt_regs *regs,/* Kernel mode? Handle exceptions or die: */ if (!user_mode (regs)) {kernelmode_fixup_or_oops (regs, error_code, address, -SIGSEGV ,SEGV_MAPERR ); +SIGSEGV ,SEGV_MAPERR , +ARCH_DEFAULT_PKEY );return ; }
include/linux/pkeys.h +2 -0
@@ -4,6 +4,8 @@#include <linux/mm.h> +#define ARCH_DEFAULT_PKEY 0 +#ifdef CONFIG_ARCH_HAS_PKEYS #include <asm/pkeys.h> #else /* ! CONFIG_ARCH_HAS_PKEYS */
tools/arch/x86/lib/insn.c +2 -2
@@ -37,10 +37,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); leXX_to_cpu(t, r); }) + ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
Re: [GIT pull] x86/urgent for v5.15-rc3
Quoted 3 lines · Thomas Gleixner
- Prevent undefined behaviour to the potential unaligned accesss in the instroction decoder library.
What a horrible fix that is.
This is why we have "get_unaligned()". It might use memcpy() internally on some architectures (it doesn't really any more - Arnd cleaned it all up and now it uses a pointer that is marked unaligned), but more importantly it explains _why_ something is done the way it's done, rather than be an odd memcpy().
Oh well. The memcpy works, and compilers will do the right thing for it, but it's ugly.
In this case, it's actually *doubly* ugly, though, because we literally have functions to "load unaligned data in little-endian format".
So instead of doing a "memcpy()", followed by a magic special macro that does a "switch (sizeof(t))" and does a "le*_to_cpu()" on the result, the code could literally have used the functions that do this all for them.
Ugh. Pulled. But it's ugly.
Linus
Borislav Petkov
maintainerRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 20 lines · Linus Torvalds
Quoted 3 lines · Thomas Gleixner
- Prevent undefined behaviour to the potential unaligned accesss in the instroction decoder library.
What a horrible fix that is.
This is why we have "
get_unaligned()". It might usememcpy()internally on some architectures (it doesn't really any more - Arnd cleaned it all up and now it uses a pointer that is marked unaligned), but more importantly it explains _why_ something is done the way it's done, rather than be an oddmemcpy().Oh well. The memcpy works, and compilers will do the right thing for it, but it's ugly.
In this case, it's actually *doubly* ugly, though, because we literally have functions to "load unaligned data in little-endian format".
Quoted 6 lines
So instead of doing a "
memcpy()", followed by a magic special macro that does a "switch (sizeof(t))" and does a "le*_to_cpu()" on the result, the code could literally have used the functions that do this all for them.Ugh. Pulled. But it's ugly.
Yeah, that came up during review:
https://lore.kernel.org/lkml/CAP-5=fU2XBoOa2=00VCuWYqsLUzMSMzUXY63ZJt9rz-NJ+vYwA@mail.gmail.com/
and the follow-on messages and AFAICT the only hurdle to using get_unaligned() is exporting it into tools/ for use by the version of the insn decoder there in tools/arch/x86/lib/insn.c.
There's this other rather "theoretical" thing of Intel PT decoding being done on any arch but get_unaligned() from include/asm-generic/unaligned.h looks as generic and as arch-agnostic as they get, to me...
But let me add the gents to Cc.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 5 lines · Borislav Petkov
There's this other rather "theoretical" thing of Intel PT decoding being done on any arch but
get_unaligned()frominclude/asm-generic/unaligned.hlooks as generic and as arch-agnostic as they get, to me...
It does now. It used to be a mess where every architecture did their own thing, including nothing (x86) or lots of inline asm (several).
Arnd cleaned it all up fairly recently.
It turns out doing nothing is wrong - not because of architecture issues, but because of compiler issues - and doing inline asms is counter-productive because the compilers will handle the unaligned case for us.
So every architecture uses that <asm-generic/unaligned.h> and is happy about it.
A couple of architectures still have their own <asm/unaligned.h>, but that's just because they have some additional stuff for legacy reasons there. They still use the generic header for the actual unaligned handling.
Linus
Borislav Petkov
maintainerRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 2 lines · Linus Torvalds
So every architecture uses that <
asm-generic/unaligned.h> and is happy about it.
Ok, how does that look?
It looks pretty straight-forward to me but WTH do I know?!
Anyway, it builds and boots fine in a guest here so it must be perfect.
---
arch/x86/lib/insn.c +3 -15
@@ -13,34 +13,22 @@#endif #include <asm/inat.h> /*__ignore_sync_check__ */ #include <asm/insn.h> /* __ignore_sync_check__ */ +#include <asm/unaligned.h> /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h> #include <asm/emulate_prefix.h> /* __ignore_sync_check__ */ -#define leXX_to_cpu (t, r) \ -({ \ - __typeof__(t) v; \ - switch (sizeof(t)) { \ - case 4: v = le32_to_cpu(r); break; \ - case 2: v = le16_to_cpu(r); break; \ - case 1: v = r; break; \ - default: \ - BUILD_BUG(); break; \ - } \ - v; \ -}) -/* Verify next sizeof(t) bytes can be on the same instruction */ #define validate_next (t, insn, n) \ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); r; })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ get_unaligned((t *)(insn)->next_byte + n); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/arch/x86/lib/insn.c +3 -15
@@ -13,34 +13,22 @@#endif #include "../include/asm/inat.h" /* __ignore_sync_check__ */ #include "../include/asm/insn.h" /* __ignore_sync_check__ */ +#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h> #include "../include/asm/emulate_prefix.h" /* __ignore_sync_check__ */ -#define leXX_to_cpu (t, r) \ -({ \ - __typeof__(t) v; \ - switch (sizeof(t)) { \ - case 4: v = le32_to_cpu(r); break; \ - case 2: v = le16_to_cpu(r); break; \ - case 1: v = r; break; \ - default: \ - BUILD_BUG(); break; \ - } \ - v; \ -}) -/* Verify next sizeof(t) bytes can be on the same instruction */ #define validate_next (t, insn, n) \ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); r; })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ get_unaligned((t *)(insn)->next_byte + n); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/include/asm-generic/unaligned.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copied from the kernel sources to tools/perf/: +*/ + +#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H +#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H + +#define __get_unaligned_t (type, ptr) ({ \ + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x; \ +}) + +#define __put_unaligned_t (type, val, ptr) do { \ + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x = (val); \ +} while (0) + +#define get_unaligned (ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) +#define put_unaligned (val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) + +#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 2 lines · Borislav Petkov
Ok, how does that look?
Well, cleaner.
You lost the leXX_to_cpu() part, so now it does the wrong thing if you were to cross-build the tooling side on a BE architecture.
The actual kernel side is fine, of course, since it runs on x86 by definition.
So it's purely the tool side - I assume this instruction decoding is used for objtool or something.
I'm not sure that matters. BE is dead, nobody would ever cross-build tooling that way. But maybe a compile-time error, at least, so that the problem is obvious.
Linus
Borislav Petkov
maintainerRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 4 lines · Linus Torvalds
Well, cleaner.
You lost the
leXX_to_cpu()part, so now it does the wrong thing if you were to cross-build the tooling side on a BE architecture.
Bah, I got carried away with the axe...
And looka here: 1d509f2a6ebc ("x86/insn: Support big endian cross-compiles")
Quoted 3 lines
I'm not sure that matters. BE is dead, nobody would ever cross-build tooling that way. But maybe a compile-time error, at least, so that the problem is obvious.
Yeah, lemme re-add those conversion things - looks like we do use them.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [GIT pull] x86/urgent for v5.15-rc3
Quoted 4 lines · Borislav Petkov
Bah, I got carried away with the axe...
And looka here:
1d509f2a6ebc("x86/insn: Support big endian cross-compiles")
Ahh. s390. For some reason I thought they were LE too, clearly incorrectly. So yeah, there still are serious big BE machines that you might want to cross-compile from.
Linus
Borislav Petkov
maintainerPATCH 1/1 x86/insn: Use get_unaligned() instead of memcpy()
From: Borislav Petkov <[email protected]>
Use get_unaligned() instead of memcpy() to access potentially unaligned memory, which, when accessed through a pointer, leads to undefined behavior. get_unaligned() describes much better what is happening there anyway even if memcpy() does the job.
No functional changes.
--- arch/x86/lib/insn.c | 5 +++-- tools/arch/x86/lib/insn.c | 5 +++-- tools/include/asm-generic/unaligned.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tools/include/asm-generic/unaligned.h
arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include <asm/inat.h> /*__ignore_sync_check__ */ #include <asm/insn.h> /* __ignore_sync_check__ */ +#include <asm/unaligned.h> /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include "../include/asm/inat.h" /* __ignore_sync_check__ */ #include "../include/asm/insn.h" /* __ignore_sync_check__ */ +#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/include/asm-generic/unaligned.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copied from the kernel sources to tools/perf/: +*/ + +#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H +#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H + +#define __get_unaligned_t (type, ptr) ({ \ + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x; \ +}) + +#define __put_unaligned_t (type, val, ptr) do { \ + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x = (val); \ +} while (0) + +#define get_unaligned (ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) +#define put_unaligned (val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) + +#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +
Signature · 8 lines
2.29.2
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteRe: [PATCH] x86/insn: Use get_unaligned() instead of memcpy()
Quoted 8 lines · On Wed, 29 Sep 2021 20:10:42 +0200 Borislav Petkov <[email protected]> wrote:
From: Borislav Petkov <[email protected]>
Use
get_unaligned()instead ofmemcpy()to access potentially unaligned memory, which, when accessed through a pointer, leads to undefined behavior.get_unaligned()describes much better what is happening there anyway even ifmemcpy()does the job.No functional changes.
Thank you very much to fix this! This looks good to me.
Quoted 99 lines
Fixes 5ba1071f7554 ("x86/insn, tools/x86: Fix undefined behavior due to potential unaligned accesses")Suggested-by Linus Torvalds <[email protected]>Signed-off-by Borislav Petkov <[email protected]>--- arch/x86/lib/insn.c | 5 +++-- tools/arch/x86/lib/insn.c | 5 +++-- tools/include/asm-generic/unaligned.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tools/include/asm-generic/unaligned.harch/x86/lib/insn.c +3
-2@@ -13,6 +13,7 @@#endif #include <asm/inat.h> /*__ignore_sync_check__ */ #include <asm/insn.h> /* __ignore_sync_check__ */ +#include <asm/unaligned.h> /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h> @@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })tools/arch/x86/lib/insn.c +3
-2@@ -13,6 +13,7 @@#endif #include "../include/asm/inat.h" /* __ignore_sync_check__ */ #include "../include/asm/insn.h" /* __ignore_sync_check__ */ +#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h> @@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })tools/include/asm-generic/unaligned.h new file +23
-0@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copied from the kernel sources to tools/perf/: +*/ + +#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H +#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H + +#define __get_unaligned_t (type, ptr) ({ \ + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x; \ +}) + +#define __put_unaligned_t (type, val, ptr) do { \ + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x = (val); \ +} while (0) + +#define get_unaligned (ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) +#define put_unaligned (val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) + +#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +Signature · 8 lines
2.29.2 -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette
Signature · 1 line
Masami Hiramatsu <[email protected]>
[tip: x86/misc] x86/insn: Use get_unaligned() instead of memcpy()
In reply to Borislav PetkovThe following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: a1be25a30cf654b3314bc7b26db5e52716833144 Gitweb: https://git.kernel.org/tip/a1be25a30cf654b3314bc7b26db5e52716833144 Author: Borislav Petkov <[email protected]> AuthorDate: Wed, 29 Sep 2021 16:37:53 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Mon, 04 Oct 2021 11:11:58 +02:00
x86/insn: Use get_unaligned() instead of memcpy()
Use get_unaligned() instead of memcpy() to access potentially unaligned memory, which, when accessed through a pointer, leads to undefined behavior. get_unaligned() describes much better what is happening there anyway even if memcpy() does the job.
No functional changes.
--- arch/x86/lib/insn.c | 5 +++-- tools/arch/x86/lib/insn.c | 5 +++-- tools/include/asm-generic/unaligned.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 tools/include/asm-generic/unaligned.h
arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include <asm/inat.h> /*__ignore_sync_check__ */ #include <asm/insn.h> /* __ignore_sync_check__ */ +#include <asm/unaligned.h> /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include "../include/asm/inat.h" /* __ignore_sync_check__ */ #include "../include/asm/insn.h" /* __ignore_sync_check__ */ +#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/include/asm-generic/unaligned.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copied from the kernel sources to tools/perf/: +*/ + +#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H +#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H + +#define __get_unaligned_t (type, ptr) ({ \ + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x; \ +}) + +#define __put_unaligned_t (type, val, ptr) do { \ + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x = (val); \ +} while (0) + +#define get_unaligned (ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) +#define put_unaligned (val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) + +#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +
[tip: x86/misc] x86/insn: Use get_unaligned() instead of memcpy()
In reply to Borislav PetkovThe following commit has been merged into the x86/misc branch of tip:
The following commit has been merged into the x86/misc branch of tip:
Commit-ID: f96b4675839b66168f5a07bf964dde6c2f1c4885 Gitweb: https://git.kernel.org/tip/f96b4675839b66168f5a07bf964dde6c2f1c4885 Author: Borislav Petkov <[email protected]> AuthorDate: Wed, 29 Sep 2021 16:37:53 +02:00 Committer: Borislav Petkov <[email protected]> CommitterDate: Wed, 06 Oct 2021 11:56:37 +02:00
x86/insn: Use get_unaligned() instead of memcpy()
Use get_unaligned() instead of memcpy() to access potentially unaligned memory, which, when accessed through a pointer, leads to undefined behavior. get_unaligned() describes much better what is happening there anyway even if memcpy() does the job.
In addition, since perf tool builds with -Werror, it would fire with:
util/intel-pt-decoder/../../../arch/x86/lib/insn.c: In function '__insn_get_emulate_prefix':
tools/include/../include/asm-generic/unaligned.h:10:15: error: packed attribute is unnecessary [-Werror=packed]
10 | const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \because -Werror=packed would complain if the packed attribute would have no effect on the layout of the structure.
In this case, that is intentional so disable the warning only for that compilation unit.
That part is Reported-by: Stephen Rothwell <[email protected]>
No functional changes.
--- arch/x86/lib/insn.c | 5 +++-- tools/arch/x86/lib/insn.c | 5 +++-- tools/include/asm-generic/unaligned.h | 23 +++++++++++++++++++++++ tools/perf/util/intel-pt-decoder/Build | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 tools/include/asm-generic/unaligned.h
arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include <asm/inat.h> /*__ignore_sync_check__ */ #include <asm/insn.h> /* __ignore_sync_check__ */ +#include <asm/unaligned.h> /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/arch/x86/lib/insn.c +3 -2
@@ -13,6 +13,7 @@#endif #include "../include/asm/inat.h" /* __ignore_sync_check__ */ #include "../include/asm/insn.h" /* __ignore_sync_check__ */ +#include "../include/asm-generic/unaligned.h" /* __ignore_sync_check__ */ #include <linux/errno.h> #include <linux/kconfig.h>
@@ -37,10 +38,10 @@ ((insn)->next_byte + sizeof(t) + n <= (insn)->end_kaddr)#define __get_next (t, insn) \ - ({ t r; memcpy(&r, insn->next_byte, sizeof(t)); insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte); (insn)->next_byte += sizeof(t); leXX_to_cpu(t, r); })#define __peek_nbyte_next (t, insn, n) \ - ({ t r; memcpy(&r, (insn)->next_byte + n, sizeof(t)); leXX_to_cpu(t, r); }) + ({ t r = get_unaligned((t *)(insn)->next_byte + n); leXX_to_cpu(t, r); })#define get_next (t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); })
tools/include/asm-generic/unaligned.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* Copied from the kernel sources to tools/perf/: +*/ + +#ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H +#define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H + +#define __get_unaligned_t (type, ptr) ({ \ + const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x; \ +}) + +#define __put_unaligned_t (type, val, ptr) do { \ + struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \ + __pptr->x = (val); \ +} while (0) + +#define get_unaligned (ptr) __get_unaligned_t(typeof(*(ptr)), (ptr)) +#define put_unaligned (val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr)) + +#endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */ +
tools/perf/util/intel-pt-decoder/Build +2 -0
@@ -18,3 +18,5 @@ CFLAGS_intel-pt-insn-decoder.o += -I$(OUTPUT)util/intel-pt-decoder ifeq ($(CC_NO_CLANG), 1) CFLAGS_intel-pt-insn-decoder.o += -Wno-override-init endif + +CFLAGS_intel-pt-insn-decoder.o += -Wno-packed
Re: [GIT pull] x86/urgent for v5.15-rc3
In reply to Thomas GleixnerThe pull request you sent on Sun, 26 Sep 2021 12:30:09 +0200 (CEST):
The pull request you sent on Sun, 26 Sep 2021 12:30:09 +0200 (CEST):
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitx86-urgent-2021-09-26
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/5bb7b2107f8c8e97750a36a723f3f74f819f6ff1
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html
The pull request you sent on Sun, 26 Sep 2021 12:30:06 +0200 (CEST):
The pull request you sent on Sun, 26 Sep 2021 12:30:06 +0200 (CEST):
Quoted 1 line
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitirq-urgent-2021-09-26
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/dc0f97c2613d09734719ef89d99d06417d92337d
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html