Re: [PATCH 1/1] s390/virtio_ccw: fix config change notifications
On Thu, Jun 13, 2024 at 03:21:15PM +0200, Halil Pasic wrote: > On Wed, 12 Jun 2024 16:04:15 +0200 > Thomas Huth wrote: > > > On 11/06/2024 23.47, Halil Pasic wrote: > > > Commit e3e9bda38e6d ("s390/virtio_ccw: use DMA handle from DMA API") > > > broke configuration change notifications for virtio-ccw by putting the > > > DMA address of *indicatorp directly into ccw->cda disregarding the fact > > > that if !!(vcdev->is_thinint) then the function > > > virtio_ccw_register_adapter_ind() will overwrite that ccw->cda value > > > with the address of the virtio_thinint_area so it can actually set up > > > the adapter interrupts via CCW_CMD_SET_IND_ADAPTER. Thus we end up > > > pointing to the wrong object for both CCW_CMD_SET_IND if setting up the > > > adapter interrupts fails, and for CCW_CMD_SET_CONF_IND regardless > > > whether it succeeds or fails. > > > > > > To fix this, let us save away the dma address of *indicatorp in a local > > > variable, and copy it to ccw->cda after the "vcdev->is_thinint" branch. > > > > > > Reported-by: Boqiao Fu > > > Reported-by: Sebastian Mitterle > > > Fixes: e3e9bda38e6d ("s390/virtio_ccw: use DMA handle from DMA API") > > > Signed-off-by: Halil Pasic > > > --- > > > I know that checkpatch.pl complains about a missing 'Closes' tag. > > > Unfortunately I don't have an appropriate URL at hand. @Sebastian, > > > @Boqiao: do you have any suggetions? > > > > Closes: https://issues.redhat.com/browse/RHEL-39983 > > ? > > Yep! That is a public bug tracker bug. Qualifies! > @Vasily: Can you guys pick hat one up when picking the patch? Sure, applied. Thanks!
Re: User stacktrace garbage when USER_STACKTRACE_SUPPORT is not enabled
On Wed, Mar 31, 2021 at 05:09:00PM -0400, Steven Rostedt wrote: > On Wed, 31 Mar 2021 22:51:15 +0200 > Vasily Gorbik wrote: > > > It does! Thanks for the explanation and for the fix. I wonder why nobody > > noticed and complained about that since v5.6. > > Because it didn't lose data, just added extra junk. > > > > > Acked-by: Vasily Gorbik > > Want to give a "tested-by" too? I only tested it on s390 (manually + ftrace selftest), quite frankly. If it qualifies: Tested-by: Vasily Gorbik # s390 only
Re: User stacktrace garbage when USER_STACKTRACE_SUPPORT is not enabled
On Wed, Mar 31, 2021 at 10:37:49AM -0400, Steven Rostedt wrote: > But after writing all of the above, I think I found a bug! It's this: > > size = nr_entries * sizeof(unsigned long); > event = __trace_buffer_lock_reserve(buffer, TRACE_STACK, > sizeof(*entry) + size, trace_ctx); > > > I said the above commit did not play a role in output, but it does play a > role in creating the struct stack_trace entry. And by making it a fixed > array (even though it's not used) it added 8 more entries to the stack! > > This should fix the problem: > > -- Steve > > diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c > index 3c605957bb5c..507a30bf26e4 100644 > --- a/kernel/trace/trace.c > +++ b/kernel/trace/trace.c > @@ -2985,7 +2985,8 @@ static void __ftrace_trace_stack(struct trace_buffer > *buffer, > > size = nr_entries * sizeof(unsigned long); > event = __trace_buffer_lock_reserve(buffer, TRACE_STACK, > - sizeof(*entry) + size, trace_ctx); > + (sizeof(*entry) - sizeof(entry->caller)) + > size, > + trace_ctx); > if (!event) > goto out; > entry = ring_buffer_event_data(event); It does! Thanks for the explanation and for the fix. I wonder why nobody noticed and complained about that since v5.6. Acked-by: Vasily Gorbik
User stacktrace garbage when USER_STACKTRACE_SUPPORT is not enabled
Hi Steven, At least on s390 since commit cbc3b92ce037 ("tracing: Set kernel_stack's caller size properly") kernel stack trace contains 8 garbage values in the end. I assume those are supposed to be filled by ftrace_trace_userstack, which is only implemented on x86. sshd-804 [050] 1997.252608: kernel_stack: => trampoline_probe_handler (549628c94) => kprobe_handler (549629260) => kprobe_exceptions_notify (549629370) => notify_die (549686e5e) => illegal_op (54960d440) => __do_pgm_check (54a106b08) => pgm_check_handler (54a112cc8) => kretprobe_trampoline (549629438) => kretprobe_trampoline (549629436) => do_syscall (549611ee6) => __do_syscall (54a106ccc) => system_call (54a112b5a) => 76901000322 => 22125e4d8 => 22125e8f8 => e54100040100 => _end (322000c) => 2 => 20f892ec0002 => 20f898b80002 kernel/trace/trace_entries.h: 159 #define FTRACE_STACK_ENTRIES8 160 161 FTRACE_ENTRY(kernel_stack, stack_entry, 162 163 TRACE_STACK, 164 165 F_STRUCT( 166 __field(int,size) 167 __array(unsigned long, caller, FTRACE_STACK_ENTRIES) 168 ), Is there any reason to keep those 8 extra values in the caller array if CONFIG_USER_STACKTRACE_SUPPORT is not enabled? Any advice how to fix that gracefully? It seems to work if I simply set FTRACE_STACK_ENTRIES to 0 when CONFIG_USER_STACKTRACE_SUPPORT is not enabled.
Re: Is s390's new generic-using syscall code actually correct?
Hi Andy, On Sat, Mar 20, 2021 at 08:48:34PM -0700, Andy Lutomirski wrote: > Hi all- > > I'm working on my kentry patchset, and I encountered: > > commit 56e62a73702836017564eaacd5212e4d0fa1c01d > Author: Sven Schnelle > Date: Sat Nov 21 11:14:56 2020 +0100 > > s390: convert to generic entry > > As part of this work, I was cleaning up the generic syscall helpers, > and I encountered the goodies in do_syscall() and __do_syscall(). > > I'm trying to wrap my head around the current code, and I'm rather confused. > > 1. syscall_exit_to_user_mode_work() does *all* the exit work, not just > the syscall exit work. So a do_syscall() that gets called twice will > do the loopy part of the exit work (e.g. signal handling) twice. Is > this intentional? If so, why? > > 2. I don't understand how this PIF_SYSCALL_RESTART thing is supposed > to work. Looking at the code in Linus' tree, if a signal is pending > and a syscall returns -ERESTARTSYS, the syscall will return back to > do_syscall(). The work (as in (1)) gets run, calling do_signal(), > which will notice -ERESTARTSYS and set PIF_SYSCALL_RESTART. > Presumably it will also push the signal frame onto the stack and aim > the return address at the svc instruction mentioned in the commit > message from "s390: convert to generic entry". Then __do_syscall() > will turn interrupts back on and loop right back into do_syscall(). > That seems incorrect. > > Can you enlighten me? My WIP tree is here: > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/log/?h=x86/kentry > For all the details to that change we'd have to wait for Sven, who is back next week. > Here are my changes to s390, and I don't think they're really correct: > > > https://git.kernel.org/pub/scm/linux/kernel/git/luto/linux.git/diff/arch/s390/kernel/syscall.c?h=x86/kentry=58a459922be0fb8e0f17aeaebcb0ac8d0575a62c Couple of things: syscall_exit_to_user_mode_prepare is static, and there is another code path in arch/s390/kernel/traps.c using enter_from_user_mode/exit_to_user_mode. Anyhow I gave your branch a spin and got few new failures on strace test suite, in particular on restart_syscall test. I'll try to find time to look into details.
[GIT PULL] s390 patches for the 5.12 merge window #2
Hello Linus, please pull the second round of s390 fixes and features for 5.12. Thank you, Vasily The following changes since commit df24212a493afda0d4de42176bea10d45825e9a0: Merge tag 's390-5.12-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux (2021-02-21 13:40:06 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.12-2 for you to fetch changes up to cf6acb8bdb1d829b85a4daa2944bf9e71c93f4b9: s390/cpumf: Add support for complete counter set extraction (2021-02-24 00:31:23 +0100) s390 updates for the 5.12 merge window #2 - Fix physical vs virtual confusion in some basic mm macros and routines. Caused by __pa == __va on s390 currently. - Get rid of on-stack cpu masks. - Add support for complete CPU counter set extraction. - Add arch_irq_work_raise implementation. - virtio-ccw revision and opcode fixes. Alexander Gordeev (4): s390/mm: make pXd_deref() macros return a pointer s390/mm: fix invalid __pa() usage in pfn_pXd() macros s390/mm: fix phys vs virt confusion in pgtable allocation routines s390/mm: fix phys vs virt confusion in vmem_*() functions family Cornelia Huck (1): virtio/s390: implement virtio-ccw revision 2 correctly Heiko Carstens (5): s390/opcodes: rename selhhhr to selfhr s390/smp: consolidate locking for smp_rescan() s390/smp: __smp_rescan_cpus() - move cpumask away from stack s390/smp: smp_emergency_stop() - move cpumask away from stack s390/topology: move cpumasks away from stack Ilya Leoshkevich (1): s390/smp: implement arch_irq_work_raise() Thomas Richter (1): s390/cpumf: Add support for complete counter set extraction arch/s390/include/asm/irq_work.h | 12 + arch/s390/include/asm/pgalloc.h| 2 +- arch/s390/include/asm/pgtable.h| 16 +- arch/s390/include/uapi/asm/perf_cpum_cf_diag.h | 51 +++ arch/s390/kernel/perf_cpum_cf_diag.c | 548 +++-- arch/s390/kernel/smp.c | 28 +- arch/s390/kernel/topology.c| 25 +- arch/s390/mm/pgalloc.c | 22 +- arch/s390/mm/vmem.c| 30 +- arch/s390/tools/opcodes.txt| 2 +- drivers/s390/virtio/virtio_ccw.c | 4 +- include/linux/cpuhotplug.h | 1 + 12 files changed, 660 insertions(+), 81 deletions(-) create mode 100644 arch/s390/include/asm/irq_work.h create mode 100644 arch/s390/include/uapi/asm/perf_cpum_cf_diag.h
[GIT PULL] s390 patches for the 5.12 merge window
Hello Linus, please pull s390 changes for 5.12. There are small common code and alpha/Kconfig changes caused by 96c0a6a72d18 ("s390,alpha: switch to 64-bit ino_t"). Which has been discussed here: lkml.kernel.org/r/YCV7QiyoweJwvN+m@osiris The following changes since commit 19c329f6808995b142b3966301f217c831e7cf31: Linux 5.11-rc4 (2021-01-17 16:37:05 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.12-1 for you to fetch changes up to 2223318c2862edc7f5b282939b850b19fc934ec4: s390/qdio: remove 'merge_pending' mechanism (2021-02-13 17:17:55 +0100) Thank you, Vasily s390 updates for the 5.12 merge window - Convert to using the generic entry infrastructure. - Add vdso time namespace support. - Switch s390 and alpha to 64-bit ino_t. As discussed here lkml.kernel.org/r/YCV7QiyoweJwvN+m@osiris - Get rid of expensive stck (store clock) usages where possible. Utilize cpu alternatives to patch stckf when supported. - Make tod_clock usage less error prone by converting it to a union and rework code which is using it. - Machine check handler fixes and cleanups. - Drop couple of minor inline asm optimizations to fix clang build. - Default configs changes notably to make libvirt happy. - Various changes to rework and improve qdio code. - Other small various fixes and improvements all over the code. Alexander Egorenkov (2): s390: update defconfigs s390/thread_info.h: fix task_struct declaration warning Alexander Gordeev (1): s390/tlb: make cleared_pXs flags consistent with generic code Chengyang Fan (1): s390/ap: remove unneeded semicolon Colin Ian King (1): s390/tape: Fix spelling mistake in function name tape_3590_erp_succeded Halil Pasic (1): s390/defconfig: add some NFT modules Harald Freudenberger (2): s390/crypto: improve retry logic in case of master key change s390/zcrypt: return EIO when msg retry limit reached Heiko Carstens (34): s390/atomic: remove small optimization to fix clang build s390/bitops: remove small optimization to fix clang build s390: update defconfigs s390/vdso: remove VDSO32_LBASE compat leftover s390/vdso: fix vdso data page definition s390/vdso: convert vdso_init() to arch_initcall s390/vdso: simplify vdso size calculation s390/vdso: remove BUG_ON() s390/vdso: remove superfluous check s390/vdso: remove superfluous variables s390/vdso: misc simple code changes s390/vdso: get rid of vdso_fault s390/vdso: put vdso datapage in a separate vma s390/vdso: move data page before code pages s390/vdso: simplify __arch_get_hw_counter() s390/vdso: implement generic vdso time namespace support s390/vdso: on timens page fault prefault also VVAR page s390/vtime: fix inline assembly clobber list s390/cpum_cf_diag: use get_tod_clock_fast() s390/time: use stcke instead of stck s390/entry: use cpu alternative for stck/stckf s390/alternatives: add alternative_input() / alternative_io() s390/vtime: use cpu alternative for stck/stckf s390,alpha: switch to 64-bit ino_t s390/time: introduce union tod_clock s390/time: rename store_tod_clock_ext() and use union tod_clock s390/time: introduce new store_tod_clock_ext() s390/time: convert tod_clock_base to union s390/vdso: use union tod_clock s390/kvm: use union tod_clock s390/debug: use union tod_clock s390/hypfs: use store_tod_clock_ext() s390/crypto: use store_tod_clock_ext() s390/time: remove get_tod_clock_ext() Jan Höppner (1): Documentations: scsi, kvm: Update s390-tools GitHub URL Jiapeng Zhong (1): s390: Simplify the calculation of variables Julian Wiedmann (11): s390/cio: remove ccw_device_add() wrapper s390/cio: use dma helpers for setting masks s390/qdio: remove Input tasklet code s390/qdio: remove qdio_inbound_q_moved() wrapper s390/qdio: adopt new tasklet API s390/qdio: make thinint registration symmetric s390/qdio: track time of last data IRQ for each device s390/qdio: inline qdio_kick_handler() s390/qdio: rework q->qdio_error indication s390/qdio: improve handling of PENDING buffers for QEBSM devices s390/qdio: remove 'merge_pending' mechanism Marc Hartmayer (1): s390/debug_config: enable kmemleak detector Niklas Schnelle (2): s390/pci: remove superfluous zdev->zbus check s390/pci: refactor zpci_create_device() Sven Schnelle (10): s390: convert to generic entry s390: remove asmlinkage s390: pass struct pt_regs instead of registers to syscalls s390: add missing include to arch/s390/kernel/signal.c s390: open code SWITCH_KERNEL macro s390: use
[GIT PULL] s390 updates for 5.11-rc6
Hello Linus, please pull s390 fixes for 5.11-rc6. Thank you, Vasily The following changes since commit 6ee1d745b7c9fd573fba142a2efdad76a9f1cb04: Linux 5.11-rc5 (2021-01-24 16:47:14 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.11-4 for you to fetch changes up to e82080e1f456467cc185fe65ee69fe9f9bd0b576: s390: uv: Fix sysfs max number of VCPUs reporting (2021-01-27 13:00:04 +0100) - Fix max number of VCPUs reported via ultravisor information sysfs interface. - Fix memory leaks during vfio-ap resources clean up on KVM pointer invalidation notification. - Fix potential specification exception by avoiding unnecessary interrupts disable after queue reset in vfio-ap. Janosch Frank (1): s390: uv: Fix sysfs max number of VCPUs reporting Tony Krowiak (2): s390/vfio-ap: clean up vfio_ap resources when KVM pointer invalidated s390/vfio-ap: No need to disable IRQ after queue reset arch/s390/boot/uv.c | 2 +- arch/s390/include/asm/uv.h| 4 +- arch/s390/kernel/uv.c | 2 +- drivers/s390/crypto/vfio_ap_drv.c | 6 +- drivers/s390/crypto/vfio_ap_ops.c | 149 -- drivers/s390/crypto/vfio_ap_private.h | 12 +-- 6 files changed, 101 insertions(+), 74 deletions(-)
Re: [PATCH] s390/tape: Fix spelling mistake in function name tape_3590_erp_succeded
On Mon, Jan 18, 2021 at 11:32:22AM +, Colin King wrote: > From: Colin Ian King > > Rename tape_3590_erp_succeded to tape_3590_erp_succeeded to fix a > spelling mistake in the function name. > > Signed-off-by: Colin Ian King > --- > drivers/s390/char/tape_3590.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) Applied, thanks.
Re: [PATCH] stacktrace: Move documentation for arch_stack_walk_reliable() to header
On Mon, Jan 18, 2021 at 09:10:21PM +, Mark Brown wrote: > Currently arch_stack_wallk_reliable() is documented with an identical > comment in both x86 and S/390 implementations which is a bit redundant. > Move this to the header and convert to kerneldoc while we're at it. > > Cc: Thomas Gleixner > Cc: Ingo Molnar > Cc: Borislav Petkov > Cc: "H. Peter Anvin" > Cc: Heiko Carstens > Cc: Vasily Gorbik > Cc: Christian Borntraeger > Cc: Josh Poimboeuf > Cc: Jiri Kosina > Cc: Miroslav Benes > Cc: Petr Mladek > Cc: Joe Lawrence > Cc: x...@kernel.org > Cc: linux-s...@vger.kernel.org > Cc: live-patch...@vger.kernel.org > Signed-off-by: Mark Brown > --- > arch/s390/kernel/stacktrace.c | 6 -- > arch/x86/kernel/stacktrace.c | 6 -- > include/linux/stacktrace.h| 19 +++++++++++ > 3 files changed, 19 insertions(+), 12 deletions(-) Acked-by: Vasily Gorbik
[tip: objtool/core] objtool: Rework header include paths
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 7786032e52cb02982a7154993b5d88c9c7a31ba5 Gitweb: https://git.kernel.org/tip/7786032e52cb02982a7154993b5d88c9c7a31ba5 Author:Vasily Gorbik AuthorDate:Fri, 13 Nov 2020 00:03:32 +01:00 Committer: Josh Poimboeuf CommitterDate: Wed, 13 Jan 2021 18:13:14 -06:00 objtool: Rework header include paths Currently objtool headers are being included either by their base name or included via ../ from a parent directory. In case of a base name usage: #include "warn.h" #include "arch_elf.h" it does not make it apparent from which directory the file comes from. To make it slightly better, and actually to avoid name clashes some arch specific files have "arch_" suffix. And files from an arch folder have to revert to including via ../ e.g: #include "../../elf.h" With additional architectures support and the code base growth there is a need for clearer headers naming scheme for multiple reasons: 1. to make it instantly obvious where these files come from (objtool itself / objtool arch|generic folders / some other external files), 2. to avoid name clashes of objtool arch specific headers, potential obtool arch generic headers and the system header files (there is /usr/include/elf.h already), 3. to avoid ../ includes and improve code readability. 4. to give a warm fuzzy feeling to developers who are mostly kernel developers and are accustomed to linux kernel headers arranging scheme. Doesn't this make it instantly obvious where are these files come from? #include #include And doesn't it look nicer to avoid ugly ../ includes? Which also guarantees this is elf.h from the objtool and not /usr/include/elf.h. #include This patch defines and implements new objtool headers arranging scheme. Which is: - all generic headers go to include/objtool (similar to include/linux) - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch prefix). This is similar to linux arch specific "asm/*" headers but we are not abusing "asm" name and calling it what it is. This also helps to prevent name clashes (arch is not used in system headers or kernel exports). To bring objtool to this state the following things are done: 1. current top level tools/objtool/ headers are moved into include/objtool/ subdirectory, 2. arch specific headers, currently only arch/x86/include/ are moved into arch/x86/include/arch/ and were stripped of "arch_" suffix, 3. new -I$(srctree)/tools/objtool/include include path to make includes like possible, 4. rewriting file includes, 5. make git not to ignore include/objtool/ subdirectory. Signed-off-by: Vasily Gorbik Acked-by: Peter Zijlstra (Intel) Acked-by: Masami Hiramatsu Signed-off-by: Josh Poimboeuf --- tools/objtool/.gitignore | 2 +- tools/objtool/Makefile | 1 +- tools/objtool/arch.h | 93 +- tools/objtool/arch/x86/decode.c | 8 +- tools/objtool/arch/x86/include/arch/cfi_regs.h | 25 ++- tools/objtool/arch/x86/include/arch/elf.h| 6 +- tools/objtool/arch/x86/include/arch/endianness.h | 9 +- tools/objtool/arch/x86/include/arch/special.h| 20 ++- tools/objtool/arch/x86/include/arch_elf.h| 6 +- tools/objtool/arch/x86/include/arch_endianness.h | 9 +- tools/objtool/arch/x86/include/arch_special.h| 20 +-- tools/objtool/arch/x86/include/cfi_regs.h| 25 +-- tools/objtool/arch/x86/special.c | 4 +- tools/objtool/builtin-check.c| 4 +- tools/objtool/builtin-orc.c | 4 +- tools/objtool/builtin.h | 16 +- tools/objtool/cfi.h | 38 + tools/objtool/check.c| 16 +- tools/objtool/check.h| 69 +-- tools/objtool/elf.c | 6 +- tools/objtool/elf.h | 150 +-- tools/objtool/endianness.h | 38 + tools/objtool/include/objtool/arch.h | 93 +- tools/objtool/include/objtool/builtin.h | 16 +- tools/objtool/include/objtool/cfi.h | 38 - tools/objtool/include/objtool/check.h| 69 ++- tools/objtool/include/objtool/elf.h | 150 ++- tools/objtool/include/objtool/endianness.h | 38 - tools/objtool/include/objtool/objtool.h | 32 +++- tools/objtool/include/objtool/special.h | 41 - tools/objtool/include/objtool/warn.h | 66 ++- tools/objtool/objtool.c | 6 +- tools/objtool/objtool.h | 32 +--- tools/objtool/orc_dump.c | 6 +- tools/objtoo
[tip: objtool/core] x86/tools: Use tools headers for instruction decoder selftests
The following commit has been merged into the objtool/core branch of tip: Commit-ID: c8d7b7e592f471ec1da39d872dc6bbf767a812e7 Gitweb: https://git.kernel.org/tip/c8d7b7e592f471ec1da39d872dc6bbf767a812e7 Author:Vasily Gorbik AuthorDate:Fri, 13 Nov 2020 00:03:20 +01:00 Committer: Josh Poimboeuf CommitterDate: Wed, 13 Jan 2021 18:13:11 -06:00 x86/tools: Use tools headers for instruction decoder selftests Currently the x86 instruction decoder is used from: - the kernel itself, - from tools like objtool and perf, - within x86 tools, i.e. instruction decoder selftests. The first two cases are similar, because tools headers try to mimic kernel headers. Instruction decoder selftests include some of the kernel headers directly, including uapi headers. This works until headers dependencies are kept to a minimum and tools are not cross-compiled. Since the goal of the x86 instruction decoder selftests is not to verify uapi headers, move it to using tools headers, like is already done for vdso2c tool, mkpiggy and other tools in arch/x86/boot/. Signed-off-by: Vasily Gorbik Acked-by: Peter Zijlstra (Intel) Acked-by: Masami Hiramatsu Signed-off-by: Josh Poimboeuf --- arch/x86/tools/Makefile | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile index 55b1ab3..bddfc9a 100644 --- a/arch/x86/tools/Makefile +++ b/arch/x86/tools/Makefile @@ -29,14 +29,14 @@ posttest: $(obj)/insn_decoder_test vmlinux $(obj)/insn_sanity hostprogs += insn_decoder_test insn_sanity # -I needed for generated C source and C source which in the kernel tree. -HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/uapi/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/uapi/ +HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ -HOSTCFLAGS_insn_sanity.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/ +HOSTCFLAGS_insn_sanity.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ # Dependencies are also needed. -$(obj)/insn_decoder_test.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_decoder_test.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c -$(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_sanity.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c HOST_EXTRACFLAGS += -I$(srctree)/tools/include hostprogs += relocs
[tip: objtool/core] x86/insn: Fix vector instruction decoding on big endian cross-compiles
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 5ed934e57e712b676ca62e1904ad672a9fa1505a Gitweb: https://git.kernel.org/tip/5ed934e57e712b676ca62e1904ad672a9fa1505a Author:Vasily Gorbik AuthorDate:Fri, 13 Nov 2020 17:09:54 +01:00 Committer: Josh Poimboeuf CommitterDate: Wed, 13 Jan 2021 18:13:17 -06:00 x86/insn: Fix vector instruction decoding on big endian cross-compiles Running instruction decoder posttest on an s390 host with an x86 target with allyesconfig shows errors. Instructions used in a couple of kernel objects could not be correctly decoded on big endian system. insn_decoder_test: warning: objdump says 6 bytes, but insn_get_length() says 5 insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this. insn_decoder_test: warning: 831eb4e1:62 d1 fd 48 7f 04 24 vmovdqa64 %zmm0,(%r12) insn_decoder_test: warning: objdump says 7 bytes, but insn_get_length() says 6 insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this. insn_decoder_test: warning: 831eb4e8:62 51 fd 48 7f 44 24 01 vmovdqa64 %zmm8,0x40(%r12) insn_decoder_test: warning: objdump says 8 bytes, but insn_get_length() says 6 This is because in a few places instruction field bytes are set directly with further usage of "value". To address that introduce and use a insn_set_byte() helper, which correctly updates "value" on big endian systems. Signed-off-by: Vasily Gorbik Acked-by: Masami Hiramatsu Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/insn.h | 12 arch/x86/lib/insn.c | 18 +- tools/arch/x86/include/asm/insn.h | 12 tools/arch/x86/lib/insn.c | 18 +- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 090863c..95a448f 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -30,6 +30,12 @@ static inline void insn_field_set(struct insn_field *p, insn_value_t v, p->nbytes = n; } +static inline void insn_set_byte(struct insn_field *p, unsigned char n, +insn_byte_t v) +{ + p->bytes[n] = v; +} + #else struct insn_field { @@ -51,6 +57,12 @@ static inline void insn_field_set(struct insn_field *p, insn_value_t v, p->nbytes = n; } +static inline void insn_set_byte(struct insn_field *p, unsigned char n, +insn_byte_t v) +{ + p->bytes[n] = v; + p->value = __le32_to_cpu(p->little); +} #endif struct insn { diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 520b31f..435630a 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -161,9 +161,9 @@ found: b = insn->prefixes.bytes[3]; for (i = 0; i < nb; i++) if (prefixes->bytes[i] == lb) - prefixes->bytes[i] = b; + insn_set_byte(prefixes, i, b); } - insn->prefixes.bytes[3] = lb; + insn_set_byte(>prefixes, 3, lb); } /* Decode REX prefix */ @@ -194,13 +194,13 @@ found: if (X86_MODRM_MOD(b2) != 3) goto vex_end; } - insn->vex_prefix.bytes[0] = b; - insn->vex_prefix.bytes[1] = b2; + insn_set_byte(>vex_prefix, 0, b); + insn_set_byte(>vex_prefix, 1, b2); if (inat_is_evex_prefix(attr)) { b2 = peek_nbyte_next(insn_byte_t, insn, 2); - insn->vex_prefix.bytes[2] = b2; + insn_set_byte(>vex_prefix, 2, b2); b2 = peek_nbyte_next(insn_byte_t, insn, 3); - insn->vex_prefix.bytes[3] = b2; + insn_set_byte(>vex_prefix, 3, b2); insn->vex_prefix.nbytes = 4; insn->next_byte += 4; if (insn->x86_64 && X86_VEX_W(b2)) @@ -208,7 +208,7 @@ found: insn->opnd_bytes = 8; } else if (inat_is_vex3_prefix(attr)) { b2 = peek_nbyte_next(insn_byte_t, insn, 2); - insn->vex_prefix.bytes[2] = b2; + insn_set_byte(>vex_prefix, 2, b2); insn->vex_prefix.nbytes = 3; insn->next_byte += 3; if (insn->x86_64 && X86_VEX_W(b2)) @@ -220,7 +220,7 @@ found: * Makes it easier to decode vex.W, vex., * vex.L and vex.pp. M
[tip: objtool/core] objtool: Fix x86 orc generation on big endian cross-compiles
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 8bfe273238d77d3cee18e4c03b2f26ae360b5661 Gitweb: https://git.kernel.org/tip/8bfe273238d77d3cee18e4c03b2f26ae360b5661 Author:Vasily Gorbik AuthorDate:Fri, 13 Nov 2020 00:03:29 +01:00 Committer: Josh Poimboeuf CommitterDate: Wed, 13 Jan 2021 18:13:13 -06:00 objtool: Fix x86 orc generation on big endian cross-compiles Correct objtool orc generation endianness problems to enable fully functional x86 cross-compiles on big endian hardware. Introduce bswap_if_needed() macro, which does a byte swap if target endianness doesn't match the host, i.e. cross-compilation for little endian on big endian and vice versa. The macro is used for conversion of multi-byte values which are read from / about to be written to a target native endianness ELF file. Signed-off-by: Vasily Gorbik Acked-by: Peter Zijlstra (Intel) Acked-by: Masami Hiramatsu Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/orc_types.h | 10 - tools/arch/x86/include/asm/orc_types.h | 10 - tools/objtool/arch/x86/include/arch_endianness.h | 9 - tools/objtool/check.c| 5 +- tools/objtool/endianness.h | 38 +++- tools/objtool/orc_dump.c | 5 +- tools/objtool/orc_gen.c | 3 +- tools/objtool/special.c | 6 +- 8 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec..5a2baf2 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec..5a2baf2 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/include/arch_endianness.h b/tools/objtool/arch/x86/include/arch_endianness.h new file mode 100644 index 000..7c36252 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch_endianness.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ARCH_ENDIANNESS_H +#define _ARCH_ENDIANNESS_H + +#include + +#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN + +#endif /* _ARCH_ENDIANNESS_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 270adc3..8cda0ef 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include "special.h" #include "warn.h" #include "arch_elf.h" +#include "endianness.h" #include #include @@ -1435,7 +1436,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = bswap_if_needed(hint->sp_offset); continue; } @@ -1447,7 +1448,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa-
[GIT PULL] s390 updates for 5.11-rc2
Hello Linus, please pull s390 changes for 5.11-rc2. Thank you, Vasily The following changes since commit 5c8fe583cce542aa0b84adc939ce85293de36e5e: Linux 5.11-rc1 (2020-12-27 15:30:22 -0800) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.11-3 for you to fetch changes up to 129975e75b9a2ba528d7f58be2e338cd644f6ed8: s390/Kconfig: sort config S390 select list once again (2020-12-30 17:08:53 +0100) - Update defconfigs and sort config select list. Heiko Carstens (2): s390: update defconfigs s390/Kconfig: sort config S390 select list once again arch/s390/Kconfig| 31 +-- arch/s390/configs/debug_defconfig| 12 +--- arch/s390/configs/defconfig | 11 +++ arch/s390/configs/zfcpdump_defconfig | 2 ++ 4 files changed, 35 insertions(+), 21 deletions(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index e84bdd15150b..c72874f09741 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -54,17 +54,23 @@ config KASAN_SHADOW_OFFSET config S390 def_bool y + # + # Note: keep this list sorted alphabetically + # + imply IMA_SECURE_AND_OR_TRUSTED_BOOT select ARCH_BINFMT_ELF_STATE select ARCH_HAS_DEBUG_VM_PGTABLE select ARCH_HAS_DEBUG_WX select ARCH_HAS_DEVMEM_IS_ALLOWED select ARCH_HAS_ELF_RANDOMIZE + select ARCH_HAS_FORCE_DMA_UNENCRYPTED select ARCH_HAS_FORTIFY_SOURCE select ARCH_HAS_GCOV_PROFILE_ALL select ARCH_HAS_GIGANTIC_PAGE select ARCH_HAS_KCOV select ARCH_HAS_MEM_ENCRYPT select ARCH_HAS_PTE_SPECIAL + select ARCH_HAS_SCALED_CPUTIME select ARCH_HAS_SET_MEMORY select ARCH_HAS_STRICT_KERNEL_RWX select ARCH_HAS_STRICT_MODULE_RWX @@ -111,8 +117,10 @@ config S390 select ARCH_WANT_IPC_PARSE_VERSION select BUILDTIME_TABLE_SORT select CLONE_BACKWARDS2 + select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES select DMA_OPS if PCI select DYNAMIC_FTRACE if FUNCTION_TRACER + select GENERIC_ALLOCATOR select GENERIC_CPU_AUTOPROBE select GENERIC_CPU_VULNERABILITIES select GENERIC_FIND_FIRST_BIT @@ -126,22 +134,21 @@ config S390 select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_ARCH_KASAN select HAVE_ARCH_KASAN_VMALLOC - select CPU_NO_EFFICIENT_FFS if !HAVE_MARCH_Z9_109_FEATURES select HAVE_ARCH_SECCOMP_FILTER select HAVE_ARCH_SOFT_DIRTY select HAVE_ARCH_TRACEHOOK select HAVE_ARCH_TRANSPARENT_HUGEPAGE select HAVE_ARCH_VMAP_STACK select HAVE_ASM_MODVERSIONS - select HAVE_EBPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES select HAVE_CMPXCHG_DOUBLE select HAVE_CMPXCHG_LOCAL select HAVE_DEBUG_KMEMLEAK select HAVE_DMA_CONTIGUOUS select HAVE_DYNAMIC_FTRACE select HAVE_DYNAMIC_FTRACE_WITH_REGS - select HAVE_FAST_GUP + select HAVE_EBPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES select HAVE_EFFICIENT_UNALIGNED_ACCESS + select HAVE_FAST_GUP select HAVE_FENTRY select HAVE_FTRACE_MCOUNT_RECORD select HAVE_FUNCTION_ERROR_INJECTION @@ -163,16 +170,15 @@ config S390 select HAVE_KRETPROBES select HAVE_KVM select HAVE_LIVEPATCH - select HAVE_PERF_REGS - select HAVE_PERF_USER_STACK_DUMP select HAVE_MEMBLOCK_PHYS_MAP - select MMU_GATHER_NO_GATHER select HAVE_MOD_ARCH_SPECIFIC + select HAVE_NMI select HAVE_NOP_MCOUNT select HAVE_OPROFILE select HAVE_PCI select HAVE_PERF_EVENTS - select MMU_GATHER_RCU_TABLE_FREE + select HAVE_PERF_REGS + select HAVE_PERF_USER_STACK_DUMP select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_RELIABLE_STACKTRACE select HAVE_RSEQ @@ -181,6 +187,8 @@ config S390 select HAVE_VIRT_CPU_ACCOUNTING_IDLE select IOMMU_HELPER if PCI select IOMMU_SUPPORTif PCI + select MMU_GATHER_NO_GATHER + select MMU_GATHER_RCU_TABLE_FREE select MODULES_USE_ELF_RELA select NEED_DMA_MAP_STATE if PCI select NEED_SG_DMA_LENGTH if PCI @@ -190,17 +198,12 @@ config S390 select PCI_MSI if PCI select PCI_MSI_ARCH_FALLBACKS if PCI_MSI select SPARSE_IRQ + select SWIOTLB select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TTY select VIRT_CPU_ACCOUNTING - select ARCH_HAS_SCALED_CPUTIME - select HAVE_NMI - select ARCH_HAS_FORCE_DMA_UNENCRYPTED - select SWIOTLB - select GENERIC_ALLOCATOR -
Re: [PATCH] x86/insn: Fix vector instructions decoding on big endian
On Fri, Nov 13, 2020 at 11:30:52AM -0600, Josh Poimboeuf wrote: > On Fri, Nov 13, 2020 at 05:09:54PM +0100, Vasily Gorbik wrote: > > Running instruction decoder posttest on s390 with allyesconfig shows > > errors. Instructions used in couple of kernel objects could not be > > correctly decoded on big endian system. > > > > insn_decoder_test: warning: objdump says 6 bytes, but insn_get_length() > > says 5 > > insn_decoder_test: warning: Found an x86 instruction decoder bug, please > > report this. > > insn_decoder_test: warning: 831eb4e1:62 d1 fd 48 7f 04 24 > > vmovdqa64 %zmm0,(%r12) > > insn_decoder_test: warning: objdump says 7 bytes, but insn_get_length() > > says 6 > > insn_decoder_test: warning: Found an x86 instruction decoder bug, please > > report this. > > insn_decoder_test: warning: 831eb4e8:62 51 fd 48 7f 44 24 01 > > vmovdqa64 %zmm8,0x40(%r12) > > insn_decoder_test: warning: objdump says 8 bytes, but insn_get_length() > > says 6 > > > > This is because in few places instruction field bytes are set directly > > with further usage of "value". To address that introduce and use > > insn_set_byte() helper, which correctly updates "value" on big endian > > systems. > > > > Signed-off-by: Vasily Gorbik > > --- > > Please let me know if this patch is good as it is or I should squash it > > into the patch 2 of my patch series and resend it again. > > It all looks good to me, thanks! > > Masami, does this patch look good, and also patches 1-2 of the series? > (I think you previously ACKed patch 2). > Friendly ping...
Re: [PATCH] scripts/sorttable: Fix ORC unwind table sorting on big endian
On Sat, Nov 14, 2020 at 01:53:10PM +0100, Vasily Gorbik wrote: > Currently when x86_64 kernel is cross compiled on big endian hardware > ORC unwind table is not sorted correctly. Due to missing byte swaps and > treating size as 4-byte value ORC sections sizes end up as 0 and the > problem is silently ignored. > > Make ORC unwind table sorting endianness aware. > > Signed-off-by: Vasily Gorbik > --- > This goes on top of the patch series: > > http://lkml.kernel.org/r/cover.thread-1e2854.your-ad-here.call-01605220128-ext-6070@work.hours > > scripts/sorttable.h | 20 +++- > 1 file changed, 11 insertions(+), 9 deletions(-) Friendly ping...
[PATCH] scripts/sorttable: Fix ORC unwind table sorting on big endian
Currently when x86_64 kernel is cross compiled on big endian hardware ORC unwind table is not sorted correctly. Due to missing byte swaps and treating size as 4-byte value ORC sections sizes end up as 0 and the problem is silently ignored. Make ORC unwind table sorting endianness aware. Signed-off-by: Vasily Gorbik --- This goes on top of the patch series: http://lkml.kernel.org/r/cover.thread-1e2854.your-ad-here.call-01605220128-ext-6070@work.hours scripts/sorttable.h | 20 +++- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/scripts/sorttable.h b/scripts/sorttable.h index a2baa2fefb13..99f3fa1767d1 100644 --- a/scripts/sorttable.h +++ b/scripts/sorttable.h @@ -59,6 +59,8 @@ # define uint_tuint64_t # define _rr8 # define _ww8 +# define _r4 r +# define _w4 w #else # define extable_ent_size 8 # define compare_extable compare_extable_32 @@ -80,6 +82,8 @@ # define uint_tuint32_t # define _rr # define _ww +# define _r4 r +# define _w4 w #endif #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) @@ -98,7 +102,7 @@ pthread_t orc_sort_thread; static inline unsigned long orc_ip(const int *ip) { - return (unsigned long)ip + *ip; + return (unsigned long)ip + (int)_r4((uint32_t *)ip); } static int orc_sort_cmp(const void *_a, const void *_b) @@ -158,7 +162,7 @@ static void *sort_orctable(void *arg) /* initialize indices array, convert ip_table to absolute address */ for (i = 0; i < num_entries; i++) { idxs[i] = i; - tmp_orc_ip_table[i] = g_orc_ip_table[i] + i * sizeof(int); + tmp_orc_ip_table[i] = (int)_r4((uint32_t *)_orc_ip_table[i]) + i * sizeof(int); } memcpy(tmp_orc_table, g_orc_table, orc_size); @@ -169,7 +173,7 @@ static void *sort_orctable(void *arg) continue; /* convert back to relative address */ - g_orc_ip_table[i] = tmp_orc_ip_table[idxs[i]] - i * sizeof(int); + _w4(tmp_orc_ip_table[idxs[i]] - i * sizeof(int), (uint32_t *)_orc_ip_table[i]); g_orc_table[i] = tmp_orc_table[idxs[i]]; } @@ -256,14 +260,12 @@ static int do_sort(Elf_Ehdr *ehdr, #if defined(SORTTABLE_64) && defined(UNWINDER_ORC_ENABLED) /* locate the ORC unwind tables */ if (!strcmp(secstrings + idx, ".orc_unwind_ip")) { - orc_ip_size = s->sh_size; - g_orc_ip_table = (int *)((void *)ehdr + - s->sh_offset); + orc_ip_size = _r(>sh_size); + g_orc_ip_table = (int *)((void *)ehdr + _r(>sh_offset)); } if (!strcmp(secstrings + idx, ".orc_unwind")) { - orc_size = s->sh_size; - g_orc_table = (struct orc_entry *)((void *)ehdr + -s->sh_offset); + orc_size = _r(>sh_size); + g_orc_table = (struct orc_entry *)((void *)ehdr + _r(>sh_offset)); } #endif } /* for loop */ -- 2.25.4
[PATCH] x86/insn: Fix vector instructions decoding on big endian
Running instruction decoder posttest on s390 with allyesconfig shows errors. Instructions used in couple of kernel objects could not be correctly decoded on big endian system. insn_decoder_test: warning: objdump says 6 bytes, but insn_get_length() says 5 insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this. insn_decoder_test: warning: 831eb4e1:62 d1 fd 48 7f 04 24 vmovdqa64 %zmm0,(%r12) insn_decoder_test: warning: objdump says 7 bytes, but insn_get_length() says 6 insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this. insn_decoder_test: warning: 831eb4e8:62 51 fd 48 7f 44 24 01 vmovdqa64 %zmm8,0x40(%r12) insn_decoder_test: warning: objdump says 8 bytes, but insn_get_length() says 6 This is because in few places instruction field bytes are set directly with further usage of "value". To address that introduce and use insn_set_byte() helper, which correctly updates "value" on big endian systems. Signed-off-by: Vasily Gorbik --- Please let me know if this patch is good as it is or I should squash it into the patch 2 of my patch series and resend it again. arch/x86/include/asm/insn.h | 12 arch/x86/lib/insn.c | 18 +- tools/arch/x86/include/asm/insn.h | 12 tools/arch/x86/lib/insn.c | 18 +- 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 004e27bdf121..3710a809db5d 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -30,6 +30,12 @@ static inline void insn_field_set(struct insn_field *p, insn_value_t v, p->nbytes = n; } +static inline void insn_set_byte(struct insn_field *p, unsigned char n, +insn_byte_t v) +{ + p->bytes[n] = v; +} + #else struct insn_field { @@ -51,6 +57,12 @@ static inline void insn_field_set(struct insn_field *p, insn_value_t v, p->nbytes = n; } +static inline void insn_set_byte(struct insn_field *p, unsigned char n, +insn_byte_t v) +{ + p->bytes[n] = v; + p->value = __le32_to_cpu(p->little); +} #endif struct insn { diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 520b31fc1f1a..435630a6ec97 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -161,9 +161,9 @@ void insn_get_prefixes(struct insn *insn) b = insn->prefixes.bytes[3]; for (i = 0; i < nb; i++) if (prefixes->bytes[i] == lb) - prefixes->bytes[i] = b; + insn_set_byte(prefixes, i, b); } - insn->prefixes.bytes[3] = lb; + insn_set_byte(>prefixes, 3, lb); } /* Decode REX prefix */ @@ -194,13 +194,13 @@ void insn_get_prefixes(struct insn *insn) if (X86_MODRM_MOD(b2) != 3) goto vex_end; } - insn->vex_prefix.bytes[0] = b; - insn->vex_prefix.bytes[1] = b2; + insn_set_byte(>vex_prefix, 0, b); + insn_set_byte(>vex_prefix, 1, b2); if (inat_is_evex_prefix(attr)) { b2 = peek_nbyte_next(insn_byte_t, insn, 2); - insn->vex_prefix.bytes[2] = b2; + insn_set_byte(>vex_prefix, 2, b2); b2 = peek_nbyte_next(insn_byte_t, insn, 3); - insn->vex_prefix.bytes[3] = b2; + insn_set_byte(>vex_prefix, 3, b2); insn->vex_prefix.nbytes = 4; insn->next_byte += 4; if (insn->x86_64 && X86_VEX_W(b2)) @@ -208,7 +208,7 @@ void insn_get_prefixes(struct insn *insn) insn->opnd_bytes = 8; } else if (inat_is_vex3_prefix(attr)) { b2 = peek_nbyte_next(insn_byte_t, insn, 2); - insn->vex_prefix.bytes[2] = b2; + insn_set_byte(>vex_prefix, 2, b2); insn->vex_prefix.nbytes = 3; insn->next_byte += 3; if (insn->x86_64 && X86_VEX_W(b2)) @@ -220,7 +220,7 @@ void insn_get_prefixes(struct insn *insn) * Makes it easier to decode vex.W, vex., * vex.L and vex.pp. Masking with 0x7f sets vex.W == 0. */ - insn->vex_prefix.bytes[2] = b2 & 0x7f; + insn_set_byte(>vex_prefix, 2, b2 & 0x7f); insn->vex_prefix.nbytes = 2; ins
[PATCH v5 5/5] objtool: Rework header include paths
Currently objtool headers are being included either by their base name or included via ../ from a parent directory. In case of a base name usage: #include "warn.h" #include "arch_elf.h" it does not make it apparent from which directory the file comes from. To make it slightly better, and actually to avoid name clashes some arch specific files have "arch_" suffix. And files from an arch folder have to revert to including via ../ e.g: #include "../../elf.h" With additional architectures support and the code base growth there is a need for clearer headers naming scheme for multiple reasons: 1. to make it instantly obvious where these files come from (objtool itself / objtool arch|generic folders / some other external files), 2. to avoid name clashes of objtool arch specific headers, potential obtool arch generic headers and the system header files (there is /usr/include/elf.h already), 3. to avoid ../ includes and improve code readability. 4. to give a warm fuzzy feeling to developers who are mostly kernel developers and are accustomed to linux kernel headers arranging scheme. Doesn't this make it instantly obvious where are these files come from? #include #include And doesn't it look nicer to avoid ugly ../ includes? Which also guarantees this is elf.h from the objtool and not /usr/include/elf.h. #include This patch defines and implements new objtool headers arranging scheme. Which is: - all generic headers go to include/objtool (similar to include/linux) - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch prefix). This is similar to linux arch specific "asm/*" headers but we are not abusing "asm" name and calling it what it is. This also helps to prevent name clashes (arch is not used in system headers or kernel exports). To bring objtool to this state the following things are done: 1. current top level tools/objtool/ headers are moved into include/objtool/ subdirectory, 2. arch specific headers, currently only arch/x86/include/ are moved into arch/x86/include/arch/ and were stripped of "arch_" suffix, 3. new -I$(srctree)/tools/objtool/include include path to make includes like possible, 4. rewriting file includes, 5. make git not to ignore include/objtool/ subdirectory. Signed-off-by: Vasily Gorbik --- tools/objtool/.gitignore | 2 +- tools/objtool/Makefile | 1 + tools/objtool/arch/x86/decode.c | 8 .../arch/x86/include/{ => arch}/cfi_regs.h | 0 .../arch/x86/include/{arch_elf.h => arch/elf.h} | 0 .../{arch_endianness.h => arch/endianness.h} | 0 .../include/{arch_special.h => arch/special.h} | 0 tools/objtool/arch/x86/special.c | 4 ++-- tools/objtool/builtin-check.c| 4 ++-- tools/objtool/builtin-orc.c | 4 ++-- tools/objtool/check.c| 16 tools/objtool/elf.c | 6 +++--- tools/objtool/{ => include/objtool}/arch.h | 4 ++-- tools/objtool/{ => include/objtool}/builtin.h| 0 tools/objtool/{ => include/objtool}/cfi.h| 2 +- tools/objtool/{ => include/objtool}/check.h | 4 ++-- tools/objtool/{ => include/objtool}/elf.h| 0 tools/objtool/{ => include/objtool}/endianness.h | 2 +- tools/objtool/{ => include/objtool}/objtool.h| 2 +- tools/objtool/{ => include/objtool}/special.h| 4 ++-- tools/objtool/{ => include/objtool}/warn.h | 2 +- tools/objtool/objtool.c | 6 +++--- tools/objtool/orc_dump.c | 6 +++--- tools/objtool/orc_gen.c | 6 +++--- tools/objtool/special.c | 10 +- tools/objtool/weak.c | 2 +- 26 files changed, 48 insertions(+), 47 deletions(-) rename tools/objtool/arch/x86/include/{ => arch}/cfi_regs.h (100%) rename tools/objtool/arch/x86/include/{arch_elf.h => arch/elf.h} (100%) rename tools/objtool/arch/x86/include/{arch_endianness.h => arch/endianness.h} (100%) rename tools/objtool/arch/x86/include/{arch_special.h => arch/special.h} (100%) rename tools/objtool/{ => include/objtool}/arch.h (96%) rename tools/objtool/{ => include/objtool}/builtin.h (100%) rename tools/objtool/{ => include/objtool}/cfi.h (96%) rename tools/objtool/{ => include/objtool}/check.h (96%) rename tools/objtool/{ => include/objtool}/elf.h (100%) rename tools/objtool/{ => include/objtool}/endianness.h (97%) rename tools/objtool/{ => include/objtool}/objtool.h (96%) rename tools/objtool/{ => include/objtool}/special.h (94%) rename tools/objtool/{ => include/objtool}/warn.h (98%) diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore index 45cefda24c7b..14236db36
[PATCH v5 2/5] x86/insn: Support big endian cross-compiles
From: Martin Schwidefsky x86 instruction decoder code is shared across the kernel source and the tools. Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. Make the x86 instruction decoder build host endianness agnostic to support x86 cross compilation and enable objtool to implement endianness awareness for big endian architectures support. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 33 ++ arch/x86/lib/insn.c | 101 ++ arch/x86/tools/insn_sanity.c | 4 -- tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/lib/insn.c | 101 ++ 5 files changed, 160 insertions(+), 112 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..004e27bdf121 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -7,9 +7,12 @@ * Copyright (C) IBM Corporation, 2009 */ +#include /* insn_attr_t is defined in inat.h */ #include +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +23,36 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->little = __cpu_to_le32(v); + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..520b31fc1f1a 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -5,6 +5,7 @@ * Copyright (C) IBM Corporation, 2002, 2004, 2009 */ +#include #ifdef __KERNEL__ #include #else @@ -15,15 +16,28 @@ #include +#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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(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); }) @@ -157,8 +171,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +308,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); - modrm->value = mod; - modrm->nbytes = 1; + insn_field_set(modrm, mod, 1); if (inat_is_group(insn->attr)) { pfx_id = insn_last_prefix_id(insn);
[PATCH v5 3/5] objtool: Fix reloc generation on big endian cross compiles
From: Martin Schwidefsky Currently relocations generated in elf_rebuild_rel_reloc_section/ elf_rebuild_rela_reloc_section functions are broken if the objtool is built and run on big endian system. E.g. the following errors pop up during x86 cross compilation: x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x200 >= 0x22) for offset 0 in section `.orc_unwind_ip' x86_64-9.1.0-ld: final link failed: bad value To address that convert those functions to do things similar to elf_write_reloc(), reuse gelf_update_rel/gelf_update_rela libelf library functions. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- tools/objtool/elf.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..5c0341b0cde3 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -829,25 +829,27 @@ static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rel *relocs; + void *buf; /* Allocate a buffer for relocations */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rel); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_REL; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rel.r_offset = reloc->offset; + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rel(sec->data, idx, >rel); idx++; } @@ -858,26 +860,28 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rela *relocs; + void *buf; /* Allocate a buffer for relocations with addends */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rela); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_RELA; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_addend = reloc->addend; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rela.r_offset = reloc->offset; + reloc->rela.r_addend = reloc->addend; + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rela(sec->data, idx, >rela); idx++; } -- 2.25.4
[PATCH v5 0/5] objtool and cross compilation
The patch series is resent with additional patch for the instruction decoder selftest, since it has been dropped from the tip/objtool/core due to instruction decoder selftest build failure. Previous version can be found here: https://lore.kernel.org/lkml/cover.thread-b2a547.your-ad-here.call-01601912612-ext-9766@work.hours/ rfc v4 - v5: - original patch 1 has been merged. It has been replaced with the patch which moves instruction decoder selftests to tools headers usage. This effectively fixes x86 kernel cross-compilation with CONFIG_X86_DECODER_SELFTEST=y. And posttests are run successfully at least on s390 (with entire patch series applied). - patch 2 has instruction decoder selftest fixup added. - also includes patch 5 for objtool header include paths rework. - patches 2-5 titles changed to those with which they were picked up into tip/objtool/core. rfc v3 - rfc v4: - patch 4: objtool: fix x86 orc generation on big endian cross compiles - introduced "bswap_if_needed()" macro for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. - patch 2: x86/insn: instruction decoder and big endian cross compiles - changed subject prefix from objtool to x86/insn - reformated leXX_to_cpu macro make it easier to read rfc v2 - rfc v3: - reused __*_ENDIAN_BITFIELD and dropped unneeded byteswap if __KERNEL__ is defined following David's suggestions, - re-splitted changes and made x86 instruction decoder a separate patch, - extra patch to add -Wno-nested-externs build flag to enable BUILD_BUG() usage, - added a safer and more readable leXX_to_cpu macro in x86 instruction decoder, - simplified includes. Switched to using leXX_to_cpu/cpu_to_leXX in the objtool and x86 instruction decoder since is included in the objtool already. rfc v1 - rfc v2: - rebased onto tip/objtool/core - reformatted couple of lines Currently objtool seems to be the only tool from all the build tools needed for x86 build which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. This patch series points to endianness problems which should be addressed. Recent "other architectures support" patches currently moved only some problematic parts into x86 arch specific folder. Besides that even though big endian stuff is only needed for the objtool arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, so changes are applied to both. Martin Schwidefsky (2): x86/insn: Support big endian cross-compiles objtool: Fix reloc generation on big endian cross compiles Vasily Gorbik (3): x86/tools: Use tools headers for instruction decoder selftests objtool: Fix x86 orc generation on big endian cross compiles objtool: Rework header include paths arch/x86/include/asm/insn.h | 33 ++ arch/x86/include/asm/orc_types.h | 10 ++ arch/x86/lib/insn.c | 101 -- arch/x86/tools/Makefile | 8 +- arch/x86/tools/insn_sanity.c | 4 - tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/include/asm/orc_types.h| 10 ++ tools/arch/x86/lib/insn.c | 101 -- tools/objtool/.gitignore | 2 +- tools/objtool/Makefile| 1 + tools/objtool/arch/x86/decode.c | 8 +- .../arch/x86/include/{ => arch}/cfi_regs.h| 0 .../x86/include/{arch_elf.h => arch/elf.h}| 0 .../arch/x86/include/arch/endianness.h| 9 ++ .../{arch_special.h => arch/special.h}| 0 tools/objtool/arch/x86/special.c | 4 +- tools/objtool/builtin-check.c | 4 +- tools/objtool/builtin-orc.c | 4 +- tools/objtool/check.c | 19 ++-- tools/objtool/elf.c | 40 +++ tools/objtool/{ => include/objtool}/arch.h| 4 +- tools/objtool/{ => include/objtool}/builtin.h | 0 tools/objtool/{ => include/objtool}/cfi.h | 2 +- tools/objtool/{ => include/objtool}/check.h | 4 +- tools/objtool/{ => include/objtool}/elf.h | 0 tools/objtool/include/objtool/endianness.h| 38 +++ tools/objtool/{ => include/objtool}/objtool.h | 2 +- tools/objtool/{ => include/objtool}/special.h | 4 +- tools/objtool/{ => include/objtool}/warn.h| 2 +- tools/objtool/objtool.c | 6 +- tools/objtool/or
[PATCH v5 4/5] objtool: Fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Introduces bswap_if_needed macro which does a byte swap if target endianness doesn't match the host, i.e. cross compilation for little endian on big endian and vice versa. To be used for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/orc_types.h | 10 + tools/arch/x86/include/asm/orc_types.h| 10 + .../arch/x86/include/arch_endianness.h| 9 + tools/objtool/check.c | 5 ++- tools/objtool/endianness.h| 38 +++ tools/objtool/orc_dump.c | 5 ++- tools/objtool/orc_gen.c | 3 ++ tools/objtool/special.c | 6 ++- 8 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/include/arch_endianness.h b/tools/objtool/arch/x86/include/arch_endianness.h new file mode 100644 index ..7c362527da20 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch_endianness.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ARCH_ENDIANNESS_H +#define _ARCH_ENDIANNESS_H + +#include + +#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN + +#endif /* _ARCH_ENDIANNESS_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 3d14134c4e97..f48430d81bae 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include "special.h" #include "warn.h" #include "arch_elf.h" +#include "endianness.h" #include #include @@ -1372,7 +1373,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = bswap_if_needed(hint->sp_offset); continue; } @@ -1384,7 +1385,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa->offset = bswap_if_needed(hint->sp_offset); insn->cfi.type = hint->type; insn->cfi.end = hint->end; } diff --git a/tools/objtool/endianness.h b/tools/objtool/endianness.h new file mode 100644 index ..ebece3191b58 --- /dev/null +++ b/tools/objtool/endianness.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _OBJTOOL_ENDIANNESS_H +#define _OBJTOOL_ENDIANNESS_H + +#include +#include +#include "arch_endianne
[PATCH v5 1/5] x86/tools: Use tools headers for instruction decoder selftests
Currently x86 instruction decoder is used from: - the kernel itself, - from tools like objtool and perf, - within x86 tools, i.e. instruction decoder selftests. The first two cases are similar, because tools headers try to mimic kernel headers. Instruction decoder selftests include some of the kernel headers directly, including uapi headers. This works until headers dependencies are kept to minimum and tools are not cross-compiled. Since the goal of the x86 instruction decoder selftests is not to verify uapi headers move it to using tools headers, like this is already done for vdso2c tool, mkpiggy and other tools in arch/x86/boot/. Signed-off-by: Vasily Gorbik --- arch/x86/tools/Makefile | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile index 55b1ab378974..bddfc9a46645 100644 --- a/arch/x86/tools/Makefile +++ b/arch/x86/tools/Makefile @@ -29,14 +29,14 @@ posttest: $(obj)/insn_decoder_test vmlinux $(obj)/insn_sanity hostprogs += insn_decoder_test insn_sanity # -I needed for generated C source and C source which in the kernel tree. -HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/uapi/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/uapi/ +HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ -HOSTCFLAGS_insn_sanity.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/ +HOSTCFLAGS_insn_sanity.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ # Dependencies are also needed. -$(obj)/insn_decoder_test.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_decoder_test.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c -$(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_sanity.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c HOST_EXTRACFLAGS += -I$(srctree)/tools/include hostprogs += relocs -- 2.25.4
Re: [PATCH v7 16/41] kasan: rename KASAN_SHADOW_* to KASAN_GRANULE_*
On Wed, Nov 04, 2020 at 08:22:07PM +0100, Andrey Konovalov wrote: > On Wed, Nov 4, 2020 at 8:11 PM Vasily Gorbik wrote: > > > > On Mon, Nov 02, 2020 at 05:03:56PM +0100, Andrey Konovalov wrote: > > > This is a preparatory commit for the upcoming addition of a new hardware > > > tag-based (MTE-based) KASAN mode. > > > > > > The new mode won't be using shadow memory, but will still use the concept > > > of memory granules. Each memory granule maps to a single metadata entry: > > > 8 bytes per one shadow byte for generic mode, 16 bytes per one shadow byte > > > for software tag-based mode, and 16 bytes per one allocation tag for > > > hardware tag-based mode. > > > > > > Rename KASAN_SHADOW_SCALE_SIZE to KASAN_GRANULE_SIZE, and > > > KASAN_SHADOW_MASK > > > to KASAN_GRANULE_MASK. > > > > > > Also use MASK when used as a mask, otherwise use SIZE. > > > > > > No functional changes. > > > > > > Signed-off-by: Andrey Konovalov > > > Signed-off-by: Vincenzo Frascino > > > Reviewed-by: Marco Elver > > > --- > > > Change-Id: Iac733e2248aa9d29f6fc425d8946ba07cca73ecf > > > --- > > > Documentation/dev-tools/kasan.rst | 2 +- > > > lib/test_kasan.c | 2 +- > > > mm/kasan/common.c | 39 --- > > > mm/kasan/generic.c| 14 +-- > > > mm/kasan/generic_report.c | 8 +++ > > > mm/kasan/init.c | 8 +++ > > > mm/kasan/kasan.h | 4 ++-- > > > mm/kasan/report.c | 10 > > > mm/kasan/tags_report.c| 2 +- > > > 9 files changed, 45 insertions(+), 44 deletions(-) > > > > hm, this one got escaped somehow > > > > lib/test_kasan_module.c: > > 18 #define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : > > KASAN_SHADOW_SCALE_SIZE) > > You mean it's not on the patch? It is, almost at the very top. lib/test_kasan_module.c != lib/test_kasan.c I fetched your branch. And I had to fix it up to build old good kasan test module CONFIG_TEST_KASAN_MODULE=m
Re: [PATCH v7 13/41] s390/kasan: include asm/page.h from asm/kasan.h
On Mon, Nov 02, 2020 at 05:03:53PM +0100, Andrey Konovalov wrote: > asm/kasan.h relies on pgd_t type that is defined in asm/page.h. Include > asm/page.h from asm/kasan.h. > > Signed-off-by: Andrey Konovalov > --- > Change-Id: I369a8f9beb442b9d05733892232345c3f4120e0a > --- > arch/s390/include/asm/kasan.h | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/s390/include/asm/kasan.h b/arch/s390/include/asm/kasan.h > index e9bf486de136..a0ea4158858b 100644 > --- a/arch/s390/include/asm/kasan.h > +++ b/arch/s390/include/asm/kasan.h > @@ -2,6 +2,8 @@ > #ifndef __ASM_KASAN_H > #define __ASM_KASAN_H > > +#include Could you please include #include instead? This file is also using _REGION1_SHIFT which is defined there. And I have some s390 kasan changes pending, which include asm/pgtable.h as well, so this would make merging simpler. Thank you. With that changed Acked-by: Vasily Gorbik > + > #ifdef CONFIG_KASAN > > #define KASAN_SHADOW_SCALE_SHIFT 3
Re: [PATCH v7 34/41] kasan, x86, s390: update undef CONFIG_KASAN
On Mon, Nov 02, 2020 at 05:04:14PM +0100, Andrey Konovalov wrote: > With the intoduction of hardware tag-based KASAN some kernel checks of > this kind: > > ifdef CONFIG_KASAN > > will be updated to: > > if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) > > x86 and s390 use a trick to #undef CONFIG_KASAN for some of the code > that isn't linked with KASAN runtime and shouldn't have any KASAN > annotations. > > Also #undef CONFIG_KASAN_GENERIC with CONFIG_KASAN. > > Signed-off-by: Andrey Konovalov > Signed-off-by: Vincenzo Frascino > Reviewed-by: Marco Elver > --- > Change-Id: I2a622db0cb86a8feb60c30d8cb09190075be2a90 > --- > arch/s390/boot/string.c | 1 + > arch/x86/boot/compressed/misc.h | 1 + > 2 files changed, 2 insertions(+) > > diff --git a/arch/s390/boot/string.c b/arch/s390/boot/string.c > index b11e8108773a..faccb33b462c 100644 > --- a/arch/s390/boot/string.c > +++ b/arch/s390/boot/string.c > @@ -3,6 +3,7 @@ > #include > #include > #undef CONFIG_KASAN > +#undef CONFIG_KASAN_GENERIC > #include "../lib/string.c" for s390 part Acked-by: Vasily Gorbik
Re: [PATCH v7 16/41] kasan: rename KASAN_SHADOW_* to KASAN_GRANULE_*
On Mon, Nov 02, 2020 at 05:03:56PM +0100, Andrey Konovalov wrote: > This is a preparatory commit for the upcoming addition of a new hardware > tag-based (MTE-based) KASAN mode. > > The new mode won't be using shadow memory, but will still use the concept > of memory granules. Each memory granule maps to a single metadata entry: > 8 bytes per one shadow byte for generic mode, 16 bytes per one shadow byte > for software tag-based mode, and 16 bytes per one allocation tag for > hardware tag-based mode. > > Rename KASAN_SHADOW_SCALE_SIZE to KASAN_GRANULE_SIZE, and KASAN_SHADOW_MASK > to KASAN_GRANULE_MASK. > > Also use MASK when used as a mask, otherwise use SIZE. > > No functional changes. > > Signed-off-by: Andrey Konovalov > Signed-off-by: Vincenzo Frascino > Reviewed-by: Marco Elver > --- > Change-Id: Iac733e2248aa9d29f6fc425d8946ba07cca73ecf > --- > Documentation/dev-tools/kasan.rst | 2 +- > lib/test_kasan.c | 2 +- > mm/kasan/common.c | 39 --- > mm/kasan/generic.c| 14 +-- > mm/kasan/generic_report.c | 8 +++ > mm/kasan/init.c | 8 +++ > mm/kasan/kasan.h | 4 ++-- > mm/kasan/report.c | 10 > mm/kasan/tags_report.c| 2 +- > 9 files changed, 45 insertions(+), 44 deletions(-) hm, this one got escaped somehow lib/test_kasan_module.c: 18 #define OOB_TAG_OFF (IS_ENABLED(CONFIG_KASAN_GENERIC) ? 0 : KASAN_SHADOW_SCALE_SIZE)
Re: [PATCH 1/1] x86/tools: Use tools headers for instruction decoder selftests
On Wed, Nov 04, 2020 at 05:11:28PM +0800, kernel test robot wrote: > Hi Vasily, > > I love your patch! Yet something to improve: > > [auto build test ERROR on tip/x86/core] > [also build test ERROR on v5.10-rc2 next-20201103] > [If your patch is applied to the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch] > > url: > https://github.com/0day-ci/linux/commits/Vasily-Gorbik/x86-tools-Use-tools-headers-for-instruction-decoder-selftests/20201104-043600 > base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git > 238c91115cd05c71447ea071624a4c9fe661f970 > config: x86_64-randconfig-a005-20201104 (attached as .config) > compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project > 1fcd5d5655e29f85e12b402e32974f207cfedf32) > reproduce (this is a W=1 build): > wget > https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O > ~/bin/make.cross > chmod +x ~/bin/make.cross > # install x86_64 cross compiling tool for clang build > # apt-get install binutils-x86-64-linux-gnu > # > https://github.com/0day-ci/linux/commit/ab4952becdfae8a76a6f0e0fb4ec7d078e80d5d6 > git remote add linux-review https://github.com/0day-ci/linux > git fetch --no-tags linux-review > Vasily-Gorbik/x86-tools-Use-tools-headers-for-instruction-decoder-selftests/20201104-043600 > git checkout ab4952becdfae8a76a6f0e0fb4ec7d078e80d5d6 > # save the attached .config to linux build tree > COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross > ARCH=x86_64 > > If you fix the issue, kindly add following tag as appropriate > Reported-by: kernel test robot > > All error/warnings (new ones prefixed by >>): > >In file included from arch/x86/tools/insn_sanity.c:19: > >> tools/arch/x86/lib/insn.c:72:7: warning: implicit declaration of function > >> 'unlikely' [-Wimplicit-function-declaration] >if (peek_nbyte_next(insn_byte_t, insn, i) != prefix[i]) >^ >tools/arch/x86/lib/insn.c:32:9: note: expanded from macro 'peek_nbyte_next' >({ if (unlikely(!validate_next(t, insn, n))) goto err_out; > __peek_nbyte_next(t, insn, n); }) > ^ >tools/arch/x86/lib/insn.c:115:6: warning: implicit declaration of function > 'unlikely' [-Wimplicit-function-declaration] >b = peek_next(insn_byte_t, insn); >^ >tools/arch/x86/lib/insn.c:34:28: note: expanded from macro 'peek_next' >#define peek_next(t, insn) peek_nbyte_next(t, insn, 0) >^ >tools/arch/x86/lib/insn.c:32:9: note: expanded from macro 'peek_nbyte_next' >({ if (unlikely(!validate_next(t, insn, n))) goto err_out; > __peek_nbyte_next(t, insn, n); }) > ^ >tools/arch/x86/lib/insn.c:140:7: warning: implicit declaration of function > 'unlikely' [-Wimplicit-function-declaration] >b = peek_next(insn_byte_t, insn); >^ >tools/arch/x86/lib/insn.c:34:28: note: expanded from macro 'peek_next' >#define peek_next(t, insn) peek_nbyte_next(t, insn, 0) >^ >tools/arch/x86/lib/insn.c:32:9: note: expanded from macro 'peek_nbyte_next' >({ if (unlikely(!validate_next(t, insn, n))) goto err_out; > __peek_nbyte_next(t, insn, n); }) > ^ >tools/arch/x86/lib/insn.c:145:7: warning: implicit declaration of function > 'unlikely' [-Wimplicit-function-declaration] >if (unlikely(insn->prefixes.bytes[3])) { >^ >tools/arch/x86/lib/insn.c:157:7: warning: implicit declaration of function > 'unlikely' [-Wimplicit-function-declaration] >b = peek_next(insn_byte_t, insn); >^ >tools/arch/x86/lib/insn.c:34:28: note: expanded from macro 'peek_next' >#define peek_next(t, insn) peek_nbyte_next(t, insn, 0) >^ >tools/arch/x86/lib/insn.c:32:9: note: expanded from macro 'peek_nbyte_next' >({ if (unlikely(!validate_next(t, insn, n))) goto err_out; > __peek_nbyte_next(t, insn, n); }) > ^ >tools/arch/x86/lib/insn.c:171:6: warning: implicit declaration of function > 'unlikely' [-Wimplicit-function-declaration] >b = peek_next(insn_byte_t, insn); >^ >tools/arch/x86/lib/insn.c:34:28: note: expanded from macro 'peek_next' >#define peek_next(t, insn) peek_nbyte_next(t, insn, 0) >
Re: [tip: objtool/core] x86/insn: Support big endian cross-compiles
On Wed, Oct 14, 2020 at 04:28:59PM +0900, Masami Hiramatsu wrote: > On Mon, 12 Oct 2020 10:39:49 -0500 > Josh Poimboeuf wrote: > > > On Mon, Oct 12, 2020 at 09:12:36AM +0900, Masami Hiramatsu wrote: > > > On Sat, 10 Oct 2020 12:44:15 -0500 > > > Josh Poimboeuf wrote: > > > > > > > On Fri, Oct 09, 2020 at 10:49:21PM +0200, Borislav Petkov wrote: > > > > > On Fri, Oct 09, 2020 at 10:38:22PM +0200, Peter Zijlstra wrote: > > > > > > On Wed, Oct 07, 2020 at 04:20:19PM -, tip-bot2 for Martin > > > > > > Schwidefsky wrote: > > > > > > > The following commit has been merged into the objtool/core branch > > > > > > > of tip: > > > > > > > > > > > > > > Commit-ID: 2a522b53c47051d3bf98748418f4f8e5f20d2c04 > > > > > > > Gitweb: > > > > > > > https://git.kernel.org/tip/2a522b53c47051d3bf98748418f4f8e5f20d2c04 > > > > > > > Author:Martin Schwidefsky > > > > > > > AuthorDate:Mon, 05 Oct 2020 17:50:31 +02:00 > > > > > > > Committer: Josh Poimboeuf > > > > > > > CommitterDate: Tue, 06 Oct 2020 09:32:29 -05:00 > > > > > > > > > > > > > > x86/insn: Support big endian cross-compiles > > > > > > > > > > > > > > x86 instruction decoder code is shared across the kernel source > > > > > > > and the > > > > > > > tools. Currently objtool seems to be the only tool from build > > > > > > > tools needed > > > > > > > which breaks x86 cross compilation on big endian systems. Make > > > > > > > the x86 > > > > > > > instruction decoder build host endianness agnostic to support x86 > > > > > > > cross > > > > > > > compilation and enable objtool to implement endianness awareness > > > > > > > for > > > > > > > big endian architectures support. > > > > > > > > > > > > > > Signed-off-by: Martin Schwidefsky > > > > > > > Co-developed-by: Vasily Gorbik > > > > > > > Signed-off-by: Vasily Gorbik > > > > > > > Acked-by: Masami Hiramatsu > > > > > > > Signed-off-by: Josh Poimboeuf > > > > > > > > > > > > This commit breaks the x86 build with CONFIG_X86_DECODER_SELFTEST=y. > > > > > > > > > > > > I've asked Boris to truncate tip/objtool/core. > > > > > > > > > > Yeah, top 4 are gone until this is resolved. > > > > > > > > Masami, I wonder if we even need these selftests anymore? Objtool > > > > already decodes the entire kernel. > > > > > > No, they have different roles. The selftest checks if the decoder > > > works correctly by comparing with the output of objdump. > > > > > > As far as I can see, the objtool relies on the sanity of the decoder > > > (it trusts the output of the decoder). > > > > Ok. I wonder if we should move the decoder selftest to the 'tools' > > subdirectory. > > It is in the arch/x86/tools, so it is already in a kind of tools :) > But yeah, it was considered to be used only on x86. But if someone > start trying to run it on non-x86, cross compiling, we need to > reconsider that. I actually tried to move it to tools/testing/selftests and encountered several problems with kselftest build in general: - out of source build is broken if path is relative, - out of source build headers partially installed in $(srcdir)arch/x86/include/generated/ instead of $(objdir), when kselftests are called from the kbuild, - out of source test runs is broken, - kernel headers are installed unconditionally. These things impede moving decoder selftests to kselftests. On the other hand making the decoder selftest work "in place" seems trivial. The following fix on top of jpoimboe/objtool/core fixes the build, as well as cross-compilation. With that I can cross-compile x86 kernel on s390 with CONFIG_X86_DECODER_SELFTEST=y and posttest runs just fine. Vasily Gorbik (1): x86/tools: Use tools headers for instruction decoder selftests arch/x86/tools/Makefile | 8 arch/x86/tools/insn_sanity.c | 4 2 files changed, 4 insertions(+), 8 deletions(-) -- 2.25.4
[PATCH 1/1] x86/tools: Use tools headers for instruction decoder selftests
Currently x86 instruction decoder is used from: - the kernel itself - from tools like objtool and perf - within x86 tools, i.e. instruction decoder selftests The first two cases are similar, because tools headers try to mimic kernel headers. Instruction decoder selftests include some of the kernel headers directly, including uapi headers. This works until headers dependencies are kept to minimum and tools are not cross-compiled. Since the goal of the x86 instruction decoder selftests is not to verify uapi headers move it to using tools headers, like this is already done for vdso2c tool, mkpiggy and other tools in arch/x86/boot/. This effectively fixes x86 kernel cross-compilation with CONFIG_X86_DECODER_SELFTEST=y. And posttests are run successfully at least on s390. Fixes: 2a522b53c470 ("x86/insn: Support big endian cross-compiles") Signed-off-by: Vasily Gorbik --- Based on jpoimboe/objtool/core arch/x86/tools/Makefile | 8 arch/x86/tools/insn_sanity.c | 4 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile index 55b1ab378974..bddfc9a46645 100644 --- a/arch/x86/tools/Makefile +++ b/arch/x86/tools/Makefile @@ -29,14 +29,14 @@ posttest: $(obj)/insn_decoder_test vmlinux $(obj)/insn_sanity hostprogs += insn_decoder_test insn_sanity # -I needed for generated C source and C source which in the kernel tree. -HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/uapi/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/uapi/ +HOSTCFLAGS_insn_decoder_test.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ -HOSTCFLAGS_insn_sanity.o := -Wall -I$(objtree)/arch/x86/lib/ -I$(srctree)/arch/x86/include/ -I$(srctree)/arch/x86/lib/ -I$(srctree)/include/ +HOSTCFLAGS_insn_sanity.o := -Wall -I$(srctree)/tools/arch/x86/lib/ -I$(srctree)/tools/arch/x86/include/ -I$(objtree)/arch/x86/lib/ # Dependencies are also needed. -$(obj)/insn_decoder_test.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_decoder_test.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c -$(obj)/insn_sanity.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/inat.c $(srctree)/arch/x86/include/asm/inat_types.h $(srctree)/arch/x86/include/asm/inat.h $(srctree)/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c +$(obj)/insn_sanity.o: $(srctree)/tools/arch/x86/lib/insn.c $(srctree)/tools/arch/x86/lib/inat.c $(srctree)/tools/arch/x86/include/asm/inat_types.h $(srctree)/tools/arch/x86/include/asm/inat.h $(srctree)/tools/arch/x86/include/asm/insn.h $(objtree)/arch/x86/lib/inat-tables.c HOST_EXTRACFLAGS += -I$(srctree)/tools/include hostprogs += relocs diff --git a/arch/x86/tools/insn_sanity.c b/arch/x86/tools/insn_sanity.c index 185ceba9d289..c6aae635 100644 --- a/arch/x86/tools/insn_sanity.c +++ b/arch/x86/tools/insn_sanity.c @@ -14,10 +14,6 @@ #include #include #include - -#define unlikely(cond) (cond) -#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0])) - #include #include #include -- 2.25.4
Re: [Regression] s390x build broken with 5.10-rc1 (bisected)
On Mon, Oct 26, 2020 at 11:48:11AM +0100, Michal Kubecek wrote: > Hello, > > 5.10-rc1 builds on s390x fail with > > make -f ./scripts/Makefile.build obj=arch/s390/boot arch/s390/boot/bzImage > make -f ./scripts/Makefile.modpost > make -f ./scripts/Makefile.modfinal > make -f ./scripts/Makefile.build obj=arch/s390/boot/compressed > arch/s390/boot/compressed/vmlinux > s1=`s390x-suse-linux-objdump -t -j ".boot.data" "vmlinux" | sort | > sed -n "//! s/.*\s.boot.data\s\+//p" | sha256sum`; > s2=`s390x-suse-linux-objdump -t -j ".boot.data" > "arch/s390/boot/compressed/vmlinux" | sort | sed -n "//! > s/.*\s.boot.data\s\+//p" | sha256sum`; if [ "$s1" != "$s2" ]; then echo > "error: section .boot.data differs between vmlinux and > arch/s390/boot/compressed/vmlinux" >&2; exit 1; fi; touch > arch/s390/boot/section_cmp.boot.data > s1=`s390x-suse-linux-objdump -t -j ".boot.preserved.data" "vmlinux" > | sort | sed -n "//! s/.*\s.boot.preserved.data\s\+//p" | > sha256sum`; s2=`s390x-suse-linux-objdump -t -j ".boot.preserved.data" > "arch/s390/boot/compressed/vmlinux" | sort | sed -n "//! > s/.*\s.boot.preserved.data\s\+//p" | sha256sum`; if [ "$s1" != "$s2" ]; then > echo "error: section .boot.preserved.data differs between vmlinux and > arch/s390/boot/compressed/vmlinux" >&2; exit 1; fi; touch > arch/s390/boot/section_cmp.boot.preserved.data > error: section .boot.data differs between vmlinux and > arch/s390/boot/compressed/vmlinux > make[1]: *** [arch/s390/boot/Makefile:65: > arch/s390/boot/section_cmp.boot.data] Error 1 > make[1]: *** Waiting for unfinished jobs > error: section .boot.preserved.data differs between vmlinux and > arch/s390/boot/compressed/vmlinux > make[1]: *** [arch/s390/boot/Makefile:65: > arch/s390/boot/section_cmp.boot.preserved.data] Error 1 > make: *** [arch/s390/Makefile:153: bzImage] Error 2 > make: *** Waiting for unfinished jobs > > Bisect identified commit 33def8498fdd ("treewide: Convert macro and uses > of __section(foo) to __section("foo")"), i.e. the very last commit > before tagging v5.10-rc1. > > I can reproduce this with e.g. defconfig and both native s390x build and > build on x86_64 using cross compiler. I used gcc 10.2.1 and binutils 2.34. > > Michal Hello Michal, I've already fixed that. The fix will appear shortly on s390/fixes Thank you for reporting! Vasily Gorbik (1): s390: correct __bootdata / __bootdata_preserved macros arch/s390/include/asm/sections.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.25.4
[PATCH 1/1] s390: correct __bootdata / __bootdata_preserved macros
Currently s390 build is broken. SECTCMP .boot.data error: section .boot.data differs between vmlinux and arch/s390/boot/compressed/vmlinux make[2]: *** [arch/s390/boot/section_cmp.boot.data] Error 1 SECTCMP .boot.preserved.data error: section .boot.preserved.data differs between vmlinux and arch/s390/boot/compressed/vmlinux make[2]: *** [arch/s390/boot/section_cmp.boot.preserved.data] Error 1 make[1]: *** [bzImage] Error 2 Commit 33def8498fdd ("treewide: Convert macro and uses of __section(foo) to __section("foo")") converted all __section(foo) to __section("foo"). This is wrong for __bootdata / __bootdata_preserved macros which want variable names to be a part of intermediate section names .boot.data. and .boot.preserved.data.. Those sections are later sorted by alignment + name and merged together into final .boot.data / .boot.preserved.data sections. Those sections must be identical in the decompressor and the decompressed kernel (that is checked during the build). Fixes: 33def8498fdd ("treewide: Convert macro and uses of __section(foo) to __section("foo")") Signed-off-by: Vasily Gorbik --- arch/s390/include/asm/sections.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/s390/include/asm/sections.h b/arch/s390/include/asm/sections.h index a996d3990a02..0c2151451ba5 100644 --- a/arch/s390/include/asm/sections.h +++ b/arch/s390/include/asm/sections.h @@ -26,14 +26,14 @@ static inline int arch_is_kernel_initmem_freed(unsigned long addr) * final .boot.data section, which should be identical in the decompressor and * the decompressed kernel (that is checked during the build). */ -#define __bootdata(var) __section(".boot.data.var") var +#define __bootdata(var) __section(".boot.data." #var) var /* * .boot.preserved.data is similar to .boot.data, but it is not part of the * .init section and thus will be preserved for later use in the decompressed * kernel. */ -#define __bootdata_preserved(var) __section(".boot.preserved.data.var") var +#define __bootdata_preserved(var) __section(".boot.preserved.data." #var) var extern unsigned long __sdma, __edma; extern unsigned long __stext_dma, __etext_dma; -- 2.25.4
[PATCH 2/2] s390/decompressor: support link map saving
Produce arch/s390/boot/compressed/vmlinux.map link map for the decompressor, when CONFIG_SAVE_LINK_MAP option is enabled. Signed-off-by: Vasily Gorbik --- arch/s390/boot/compressed/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/s390/boot/compressed/Makefile b/arch/s390/boot/compressed/Makefile index b235ed95a3d8..859a5c7c9ca7 100644 --- a/arch/s390/boot/compressed/Makefile +++ b/arch/s390/boot/compressed/Makefile @@ -21,7 +21,9 @@ OBJCOPYFLAGS := OBJECTS := $(addprefix $(obj)/,$(obj-y)) -LDFLAGS_vmlinux := --oformat $(LD_BFD) -e startup -T +clean-files += vmlinux.map + +LDFLAGS_vmlinux := --oformat $(LD_BFD) -e startup $(if $(CONFIG_SAVE_LINK_MAP),-Map=$(obj)/vmlinux.map) -T $(obj)/vmlinux: $(obj)/vmlinux.lds $(objtree)/arch/s390/boot/startup.a $(OBJECTS) FORCE $(call if_changed,ld) -- 2.25.4
[PATCH 1/2] kbuild: add config option to save link map file(s)
Add CONFIG_SAVE_LINK_MAP config option, which would make linker to save link map to vmlinux.map file. Link map is quite useful during making kernel changes related to how the kernel is composed and debugging linker scripts. It also provides information about discarded sections and symbols. Architectures supporting compressed kernel images might respect CONFIG_SAVE_LINK_MAP option and produce arch/*/boot/compressed/vmlinux.map for the decompressor code as well. Signed-off-by: Vasily Gorbik --- .gitignore| 1 + Makefile | 6 +- lib/Kconfig.debug | 13 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d01cda8e1177..81ba7416a0b6 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ Module.symvers modules.builtin modules.order +vmlinux.map # # Top-level generic files diff --git a/Makefile b/Makefile index e71979882e4f..d35a59f98e83 100644 --- a/Makefile +++ b/Makefile @@ -984,6 +984,10 @@ ifeq ($(CONFIG_RELR),y) LDFLAGS_vmlinux+= --pack-dyn-relocs=relr endif +ifeq ($(CONFIG_SAVE_LINK_MAP),y) +LDFLAGS_vmlinux+= -Map=vmlinux.map +endif + # Align the bit size of userspace programs with the kernel KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS)) @@ -1461,7 +1465,7 @@ endif # CONFIG_MODULES # make distclean Remove editor backup files, patch leftover files and the like # Directories & files removed with 'make clean' -CLEAN_FILES += include/ksym vmlinux.symvers \ +CLEAN_FILES += include/ksym vmlinux.symvers vmlinux.map \ modules.builtin modules.builtin.modinfo modules.nsdeps \ compile_commands.json diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug index d7a7bc3b6098..1ac4234ad879 100644 --- a/lib/Kconfig.debug +++ b/lib/Kconfig.debug @@ -363,6 +363,19 @@ config SECTION_MISMATCH_WARN_ONLY If unsure, say Y. +config SAVE_LINK_MAP + bool "Save vmlinux link map file(s)" + default n + help + If you say Y here, vmlinux link map will be saved into + vmlinux.map. The link map is quite useful during making kernel + changes related to how the kernel is composed and linker + scripts debugging. + + In addition to that architectures supporting compressed kernel + images might also produce arch/*/boot/compressed/vmlinux.map + for the decompressor code as well. + config DEBUG_FORCE_FUNCTION_ALIGN_32B bool "Force all function address 32B aligned" if EXPERT help -- 2.25.4
[PATCH] kbuild: remove unused OBJSIZE
The "size" tool has been solely used by s390 to enforce .bss section usage restrictions in early startup code. Since commit 980d5f9ab36b ("s390/boot: enable .bss section for compressed kernel") and commit 2e83e0eb85ca ("s390: clean .bss before running uncompressed kernel") these restrictions have been lifted for the decompressor and uncompressed kernel and the size tool is now unused. Signed-off-by: Vasily Gorbik --- Documentation/kbuild/llvm.rst | 5 ++--- Makefile | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Documentation/kbuild/llvm.rst b/Documentation/kbuild/llvm.rst index cf3ca236d2cc..21c847890d03 100644 --- a/Documentation/kbuild/llvm.rst +++ b/Documentation/kbuild/llvm.rst @@ -57,9 +57,8 @@ to enable them. :: They can be enabled individually. The full list of the parameters: :: make CC=clang LD=ld.lld AR=llvm-ar NM=llvm-nm STRIP=llvm-strip \ - OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump OBJSIZE=llvm-size \ - READELF=llvm-readelf HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar \ - HOSTLD=ld.lld + OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump READELF=llvm-readelf \ + HOSTCC=clang HOSTCXX=clang++ HOSTAR=llvm-ar HOSTLD=ld.lld Currently, the integrated assembler is disabled by default. You can pass ``LLVM_IAS=1`` to enable it. diff --git a/Makefile b/Makefile index d35a59f98e83..d2123c2c829a 100644 --- a/Makefile +++ b/Makefile @@ -433,7 +433,6 @@ NM = llvm-nm OBJCOPY= llvm-objcopy OBJDUMP= llvm-objdump READELF= llvm-readelf -OBJSIZE= llvm-size STRIP = llvm-strip else CC = $(CROSS_COMPILE)gcc @@ -443,7 +442,6 @@ NM = $(CROSS_COMPILE)nm OBJCOPY= $(CROSS_COMPILE)objcopy OBJDUMP= $(CROSS_COMPILE)objdump READELF= $(CROSS_COMPILE)readelf -OBJSIZE= $(CROSS_COMPILE)size STRIP = $(CROSS_COMPILE)strip endif PAHOLE = pahole @@ -509,7 +507,7 @@ KBUILD_LDFLAGS := CLANG_FLAGS := export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC -export CPP AR NM STRIP OBJCOPY OBJDUMP OBJSIZE READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL +export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE -- 2.25.4
[PATCH 0/2] add option to save vmlinux link map
Linker -Map option allows to save detailed link map which provides far more information then the objdump tool might extract. Discarded input sections .text.__s390_indirect_jump_r14 0x0xc arch/s390/kernel/process.o Detailed information on sections, objects and symbols. .init.data 0x012760000x671f0 *(SORT_BY_NAME(___kentry+*)) *(.init.data init.data.*) .init.data 0x01276000 0x31b8 init/main.o 0x01276128late_time_init 0x012781b8boot_command_line .init.data 0x012791b8 0x60 init/do_mounts.o .init.data 0x012792180x4 init/do_mounts_rd.o 0x01279218rd_image_start *fill* 0x0127921c0x4 .init.data 0x01279220 0x18 init/do_mounts_initrd.o 0x01279228phys_initrd_start 0x01279230phys_initrd_size It helps to bring the light on linker decisions and debug linker scripts. FILL mask 0xff 0x0082f000. = ALIGN (0x1000) *fill* 0x0082e3fa 0xc06 ff 0x0082f000_end = . Resulting vmlinux.map is currently 8.8M for s390. And 48K for the decompressor's arch/s390/boot/compressed/vmlinux.map - First patch introduces CONFIG_SAVE_LINK_MAP option, which enables link map and is arch independent. - Second patch is s390 specific and additionally enables decompressor's link map saving if CONFIG_SAVE_LINK_MAP is enabled. It is probably better if both changes would go via kbuild tree. Vasily Gorbik (2): kbuild: add config option to save link map file(s) s390/decompressor: support link map saving .gitignore | 1 + Makefile | 6 +- arch/s390/boot/compressed/Makefile | 4 +++- lib/Kconfig.debug | 13 + 4 files changed, 22 insertions(+), 2 deletions(-) -- 2.25.4
[PATCH] lib/crc32test: remove extra local_irq_disable/enable
Commit 4d004099a668 ("lockdep: Fix lockdep recursion") uncovered the following issue in lib/crc32test reported on s390: BUG: using __this_cpu_read() in preemptible [] code: swapper/0/1 caller is lockdep_hardirqs_on_prepare+0x48/0x270 CPU: 6 PID: 1 Comm: swapper/0 Not tainted 5.9.0-next-20201015-15164-g03d992bd2de6 #19 Hardware name: IBM 3906 M04 704 (LPAR) Call Trace: [<00d54870>] show_stack+0x90/0xf8 [<00d675d2>] dump_stack+0xa2/0xd8 [<00d6c9ac>] check_preemption_disabled+0xe4/0xe8 [<001d6098>] lockdep_hardirqs_on_prepare+0x48/0x270 [<002ac274>] trace_hardirqs_on+0x9c/0x1b8 [<01441430>] crc32_test.isra.0+0x170/0x1c0 [<01441764>] crc32test_init+0x1c/0x40 [<00100cd0>] do_one_initcall+0x40/0x130 [<01411586>] do_initcalls+0x126/0x150 [<01411826>] kernel_init_freeable+0x1f6/0x230 [<00d6cc92>] kernel_init+0x22/0x150 [<00d7bcc4>] ret_from_fork+0x24/0x2c no locks held by swapper/0/1. Remove extra local_irq_disable/local_irq_enable helpers calls. Fixes: 5fb7f87408f1 ("lib: add module support to crc32 tests") Signed-off-by: Vasily Gorbik --- lib/crc32test.c | 4 1 file changed, 4 deletions(-) diff --git a/lib/crc32test.c b/lib/crc32test.c index 97d6a57cefcc..61ddce2cff77 100644 --- a/lib/crc32test.c +++ b/lib/crc32test.c @@ -683,7 +683,6 @@ static int __init crc32c_test(void) /* reduce OS noise */ local_irq_save(flags); - local_irq_disable(); nsec = ktime_get_ns(); for (i = 0; i < 100; i++) { @@ -694,7 +693,6 @@ static int __init crc32c_test(void) nsec = ktime_get_ns() - nsec; local_irq_restore(flags); - local_irq_enable(); pr_info("crc32c: CRC_LE_BITS = %d\n", CRC_LE_BITS); @@ -768,7 +766,6 @@ static int __init crc32_test(void) /* reduce OS noise */ local_irq_save(flags); - local_irq_disable(); nsec = ktime_get_ns(); for (i = 0; i < 100; i++) { @@ -783,7 +780,6 @@ static int __init crc32_test(void) nsec = ktime_get_ns() - nsec; local_irq_restore(flags); - local_irq_enable(); pr_info("crc32: CRC_LE_BITS = %d, CRC_BE BITS = %d\n", CRC_LE_BITS, CRC_BE_BITS); -- 2.25.4
[GIT PULL] s390 patches for the 5.10 merge window
cases for __put_user_fn()/__get_user_fn() s390/uaccess: fix indentation Janosch Frank (1): s390/uv: add destroy page call Jason J. Herne (1): s390: nvme dump support Julian Wiedmann (5): s390/qdio: make qdio_handle_aobs() more robust s390/qdio: clean up QDR setup s390/qdio: always use dev_name() for device name in QIB s390/lib: fix kernel doc for memcmp() s390/sie: fix typo in SIGP code description Liu Shixin (1): s390/diag: convert to use DEFINE_SEQ_ATTRIBUTE macro Niklas Schnelle (6): s390/pci: Implement ioremap_wc/prot() with MIO s390/pci: consolidate SR-IOV specific code s390/pci: remove unused function zpci_rescan() s390/pci: remove clp_rescan_pci_devices() s390/pci: remove clp_rescan_pci_devices_simple() s390/pci: add missing pci_iov.h include Qinglang Miao (2): s390/ap: remove unnecessary spin_lock_init() s390/3215: simplify the return expression of tty3215_open() Sven Schnelle (9): s390: convert to GENERIC_VDSO s390: disable branch profiling for vdso s390/stp: add locking to sysfs functions s390/stp: use __packed s390/stp: use u32 instead of unsigned int s390/stp: add support for leap seconds s390/stp: add sysfs file to show scheduled leap seconds s390/stp: unify stp_work_mutex and clock_sync_mutex s390: remove cad commandline option Vasily Gorbik (24): s390/kasan: make shadow memory noexec s390/mm,ptdump: add couple of additional markers s390/mm,ptdump: sort markers s390/kasan: avoid unnecessary moving of vmemmap s390/protvirt: parse prot_virt option in the decompressor s390/protvirt: support ultravisor without secure storage limit s390/kasan: support protvirt with 4-level paging s390/boot: avoid unnecessary zeroing of .bss section s390/sclp: clean up unneeded .data section usage s390/sclp: remove unused sclp_early_printk_forced s390/kaslr: avoid mixing valid random value and an error code s390/kaslr: correct and explain randomization base generation s390: remove unused _swsusp_reset_dma s390/startup: avoid save_area_sync overflow s390/cio: remove unused channel_subsystem_reinit s390/vdso: remove orphaned declarations s390/startup: correct "dfltcc" option parsing s390/sclp_sdias: remove unused sclp_sdias_exit s390/sclp: remove orphaned sclp_set_columns and sclp_set_htab s390/startup: add kaslr_offset to pgm check info print s390: remove orphaned function declarations s390/kasan: make sure int handler always run with DAT on s390: remove orphaned extern variables declarations s390/startup: correct early pgm check info formatting .../features/vm/ioremap_prot/arch-support.txt | 2 +- arch/s390/Kconfig | 5 + arch/s390/Kconfig.debug| 12 - arch/s390/boot/Makefile| 4 - arch/s390/boot/compressed/Makefile | 4 - arch/s390/boot/compressed/decompressor.c | 1 - arch/s390/boot/compressed/vmlinux.lds.S| 22 +- arch/s390/boot/head.S | 21 +- arch/s390/boot/ipl_parm.c | 60 ++- arch/s390/boot/kaslr.c | 138 --- arch/s390/boot/pgm_check_info.c| 11 +- arch/s390/boot/startup.c | 5 +- arch/s390/boot/text_dma.S | 17 - arch/s390/boot/uv.c| 3 + arch/s390/configs/debug_defconfig | 3 +- arch/s390/configs/defconfig| 3 +- arch/s390/include/asm/checksum.h | 111 +++--- arch/s390/include/asm/cio.h| 2 +- arch/s390/include/asm/clocksource.h| 7 + arch/s390/include/asm/clp.h| 3 + arch/s390/include/asm/gmap.h | 2 - arch/s390/include/asm/io.h | 8 + arch/s390/include/asm/ipl.h| 7 + arch/s390/include/asm/kasan.h | 1 + arch/s390/include/asm/pci.h| 6 +- arch/s390/include/asm/pci_clp.h| 19 + arch/s390/include/asm/pgalloc.h| 2 - arch/s390/include/asm/pgtable.h| 10 +- arch/s390/include/asm/ptdump.h | 14 + arch/s390/include/asm/qdio.h | 10 +- arch/s390/include/asm/sclp.h | 5 +- arch/s390/include/asm/set_memory.h | 4 + arch/s390/include/asm/setup.h | 7 +- arch/s390/include/asm/smp.h| 1 - arch/s390/include/asm/stp.h| 100 +++-- arch/s390/include/asm/tlbflush.h | 2
[tip: objtool/core] perf build: Allow nested externs to enable BUILD_BUG() usage
The following commit has been merged into the objtool/core branch of tip: Commit-ID: ab0a40ea88204e1291b56da8128e2845fec8ee88 Gitweb: https://git.kernel.org/tip/ab0a40ea88204e1291b56da8128e2845fec8ee88 Author:Vasily Gorbik AuthorDate:Fri, 09 Oct 2020 14:25:23 +02:00 Committer: Ingo Molnar CommitterDate: Tue, 13 Oct 2020 12:08:32 +02:00 perf build: Allow nested externs to enable BUILD_BUG() usage Currently the BUILD_BUG() macro is expanded to the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this would obviously produce build errors with -Wnested-externs and -Werror. To enable BUILD_BUG() usage in tools/arch/x86/lib/insn.c which perf includes in intel-pt-decoder, build perf without -Wnested-externs. Reported-by: Stephen Rothwell Tested-by: Stephen Rothwell # build tested Signed-off-by: Vasily Gorbik Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/patch-1.thread-251403.git-2514037e9477.your-ad-here.call-01602244460-ext-7088@work.hours --- tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 190be4f..8137a60 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -16,7 +16,7 @@ $(shell printf "" > $(OUTPUT).config-detected) detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) -CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) +CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) include $(srctree)/tools/scripts/Makefile.arch
Re: [tip: objtool/core] x86/insn: Support big endian cross-compiles
On Fri, Oct 09, 2020 at 10:49:21PM +0200, Borislav Petkov wrote: > On Fri, Oct 09, 2020 at 10:38:22PM +0200, Peter Zijlstra wrote: > > On Wed, Oct 07, 2020 at 04:20:19PM -, tip-bot2 for Martin Schwidefsky > > wrote: > > > The following commit has been merged into the objtool/core branch of tip: > > > > > > Commit-ID: 2a522b53c47051d3bf98748418f4f8e5f20d2c04 > > > Gitweb: > > > https://git.kernel.org/tip/2a522b53c47051d3bf98748418f4f8e5f20d2c04 > > > > > > x86/insn: Support big endian cross-compiles > > > > This commit breaks the x86 build with CONFIG_X86_DECODER_SELFTEST=y. > > > > I've asked Boris to truncate tip/objtool/core. > > Yeah, top 4 are gone until this is resolved. > > What I would suggest is to have a look at how tools/ headers are kept > separate from kernel proper ones, see tools/include/ and how those > headers there are full of dummy definitions just so it builds. > > And then including a global one like linux/kernel.h is just looking for > trouble: > > In file included from ./include/uapi/linux/byteorder/little_endian.h:12, > from ./include/linux/byteorder/little_endian.h:5, > from /usr/include/x86_64-linux-gnu/asm/byteorder.h:5, > from ./arch/x86/include/asm/insn.h:10, > from arch/x86/tools/insn_sanity.c:21: > ./tools/include/linux/types.h:30:18: error: conflicting types for ‘u64’ >30 | typedef uint64_t u64; Sigh... I have not realized there are more usages of insn.c which are conditionally compiled. It's not like you grep *.c files to find who includes them regularity. Looks like there is no way to find common byte swapping helpers for the kernel and tools then. Even though tools provide quite a bunch of them in tools/include/. So, completely avoiding mixing "kernel" and "userspace" headers would look like the following (delta to commit mentioned above): --- diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 004e27bdf121..68197fe18a11 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -7,7 +7,13 @@ * Copyright (C) IBM Corporation, 2009 */ +#ifdef __KERNEL__ #include +#define insn_cpu_to_le32 cpu_to_le32 +#else +#include +#define insn_cpu_to_le32 htole32 +#endif /* insn_attr_t is defined in inat.h */ #include @@ -47,7 +53,7 @@ static inline void insn_field_set(struct insn_field *p, insn_value_t v, unsigned char n) { p->value = v; - p->little = __cpu_to_le32(v); + p->little = insn_cpu_to_le32(v); p->nbytes = n; } diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 520b31fc1f1a..003f32ff7798 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -5,7 +5,6 @@ * Copyright (C) IBM Corporation, 2002, 2004, 2009 */ -#include #ifdef __KERNEL__ #include #else @@ -16,15 +15,23 @@ #include +#ifdef __KERNEL__ +#define insn_le32_to_cpu le32_to_cpu +#define insn_le16_to_cpu le16_to_cpu +#else +#define insn_le32_to_cpu le32toh +#define insn_le16_to_cpu le16toh +#endif + #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 4: v = insn_le32_to_cpu(r); break; \ + case 2: v = insn_le16_to_cpu(r); break; \ case 1: v = r; break; \ - default:\ - BUILD_BUG(); break; \ + default: /* relying on -Wuninitialized to report this */\ + break; \ } \ v; \ }) -- And the same for the tools/* No linux/kernel.h means no BUILD_BUG(), but -Wuninitialized actually does a decent job in this case: arch/x86/../../../arch/x86/lib/insn.c:605:37: error: variable 'v' is uninitialized when used here [-Werror,-Wuninitialized] insn_field_set(>immediate2, get_next(long, insn), 1); ^~~~ Masami, Josh, would that be acceptable? Should I resent the entire patch series again with these changes squashed? Or just as a separate commit which would go on top?
[PATCH RESEND 1/1] perf build: Allow nested externs to enable BUILD_BUG() usage
Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. To enable BUILD_BUG() usage in tools/arch/x86/lib/insn.c which perf includes in intel-pt-decoder, build perf without -Wnested-externs. Reported-by: Stephen Rothwell Signed-off-by: Vasily Gorbik --- Resend with no fancy signatures. tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 854da830b5ca..834061e94e7c 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -16,7 +16,7 @@ $(shell printf "" > $(OUTPUT).config-detected) detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) -CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) +CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) include $(srctree)/tools/scripts/Makefile.arch -- 2.25.4
Re: [PATCH 1/1] perf build: Allow nested externs to enable BUILD_BUG() usage
On Fri, Oct 09, 2020 at 01:23:27PM +0200, Jiri Olsa wrote: > On Fri, Oct 09, 2020 at 08:47:45AM +0200, Vasily Gorbik wrote: > > Currently BUILD_BUG() macro is expanded to smth like the following: ...snip... > > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config > > index 190be4fa5c21..8137a6046a47 100644 > > --- a/tools/perf/Makefile.config > > +++ b/tools/perf/Makefile.config > > @@ -16,7 +16,7 @@ $(shell printf "" > $(OUTPUT).config-detected) > > detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) > > detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) > > > > -CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) > > +CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) > > looks good, but I can't apply the patch with 'git am' > > Applying: perf build: Allow nested externs to enable BUILD_BUG() usage > error: patch failed: tools/perf/Makefile.config:16 > error: tools/perf/Makefile.config: patch does not apply > Patch failed at 0001 perf build: Allow nested externs to enable > BUILD_BUG() usage > hint: Use 'git am --show-current-patch=diff' to see the failed patch > When you have resolved this problem, run "git am --continue". > If you prefer to skip this patch, run "git am --skip" instead. > To restore the original branch and stop patching, run "git am --abort". > > I wonder it's that picture at the bottom ;-) > > jirka > > > > > > include $(srctree)/tools/scripts/Makefile.arch > > > > -- > > ⢋⡀⣀⠹ > > ⠠⣶⡦⠀ > > ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ > > ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ > > ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ > > ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿ > What? This makes tux and blind people very unhappy. Those are nothing else but braille utf-8 characters. And I've seen people on lkml are using those, i.e. debian icon in a signature. Oh, well... I'll avoid using this signature in future. BTW which branch did you try to apply it on? I've just checked perf/core and there should be no conflicts as well. But I assume this should go via objtool together with other changes which introduced that BUILD_BUG() usage. Anyhow I've resent the patch without fancy signatures included.
Re: linux-next: build failure after merge of the tip tree
On Fri, Oct 09, 2020 at 03:28:46PM +1100, Stephen Rothwell wrote: > Hi all, > > After merging the tip tree, today's linux-next build (perf) failed > like this: > > In file included from tools/include/linux/build_bug.h:5, > from tools/include/linux/kernel.h:8, > from util/intel-pt-decoder/intel-pt-insn-decoder.c:7: > util/intel-pt-decoder/../../../arch/x86/lib/insn.c: In function > '__insn_get_emulate_prefix': > tools/include/linux/compiler.h:37:38: error: nested extern declaration of > '__compiletime_assert_0' [-Werror=nested-externs] >37 | _compiletime_assert(condition, msg, __compiletime_assert_, > __COUNTER__) > | ^ ...snip... > > Caused by commit > > 2a522b53c470 ("x86/insn: Support big endian cross-compiles") > > I have reverted commits > > a23b701ae9b3 objtool: Rework header include paths > 1b4998c364bc objtool: Fix x86 orc generation on big endian cross compiles > 317664a7fcc9 objtool: Fix reloc generation on big endian cross compiles > 2a522b53c470 x86/insn: Support big endian cross-compiles > 2486baae2cf6 objtool: Allow nested externs to enable BUILD_BUG() > > for today. > > This is a PowerPC LE native build of tools/perf. Oh, I missed that. Sorry about that. Obviously x86 instruction decoder is also used in perf. The question is, should we just disable -Wnested-externs for perf like we did for the objtool. Or since we got BUILD_BUG() implementation in tools simply disable -Wnested-externs for all tools altogether? By throwing it out of EXTRA_WARNINGS. Vasily Gorbik (1): perf build: Allow nested externs to enable BUILD_BUG() usage tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[PATCH 1/1] perf build: Allow nested externs to enable BUILD_BUG() usage
Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. To enable BUILD_BUG() usage in tools/arch/x86/lib/insn.c which perf includes in intel-pt-decoder, build perf without -Wnested-externs. Reported-by: Stephen Rothwell Signed-off-by: Vasily Gorbik --- tools/perf/Makefile.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 190be4fa5c21..8137a6046a47 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -16,7 +16,7 @@ $(shell printf "" > $(OUTPUT).config-detected) detected = $(shell echo "$(1)=y" >> $(OUTPUT).config-detected) detected_var = $(shell echo "$(1)=$($(1))" >> $(OUTPUT).config-detected) -CFLAGS := $(EXTRA_CFLAGS) $(EXTRA_WARNINGS) +CFLAGS := $(EXTRA_CFLAGS) $(filter-out -Wnested-externs,$(EXTRA_WARNINGS)) include $(srctree)/tools/scripts/Makefile.arch -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[tip: objtool/core] objtool: Fix x86 orc generation on big endian cross compiles
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 1b4998c364bcfd7fe3442820b0f3064b1f7b3a77 Gitweb: https://git.kernel.org/tip/1b4998c364bcfd7fe3442820b0f3064b1f7b3a77 Author:Vasily Gorbik AuthorDate:Mon, 05 Oct 2020 17:50:38 +02:00 Committer: Josh Poimboeuf CommitterDate: Tue, 06 Oct 2020 09:36:57 -05:00 objtool: Fix x86 orc generation on big endian cross compiles Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Introduces bswap_if_needed macro which does a byte swap if target endianness doesn't match the host, i.e. cross compilation for little endian on big endian and vice versa. To be used for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. Signed-off-by: Vasily Gorbik Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/orc_types.h | 10 - tools/arch/x86/include/asm/orc_types.h | 10 - tools/objtool/arch/x86/include/arch_endianness.h | 9 - tools/objtool/check.c| 5 +- tools/objtool/endianness.h | 38 +++- tools/objtool/orc_dump.c | 5 +- tools/objtool/orc_gen.c | 3 +- tools/objtool/special.c | 6 +- 8 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec..5a2baf2 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec..5a2baf2 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/include/arch_endianness.h b/tools/objtool/arch/x86/include/arch_endianness.h new file mode 100644 index 000..7c36252 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch_endianness.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ARCH_ENDIANNESS_H +#define _ARCH_ENDIANNESS_H + +#include + +#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN + +#endif /* _ARCH_ENDIANNESS_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 3d14134..f48430d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include "special.h" #include "warn.h" #include "arch_elf.h" +#include "endianness.h" #include #include @@ -1372,7 +1373,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = bswap_if_needed(hint->sp_offset); continue; } @@ -1384,7 +1385,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa->offset = bswap_if_needed(hint->sp_offset); insn->cfi.typ
[tip: objtool/core] objtool: Rework header include paths
The following commit has been merged into the objtool/core branch of tip: Commit-ID: a23b701ae9b334f86aabdcba5dd57fc0e81b51b6 Gitweb: https://git.kernel.org/tip/a23b701ae9b334f86aabdcba5dd57fc0e81b51b6 Author:Vasily Gorbik AuthorDate:Mon, 05 Oct 2020 17:50:41 +02:00 Committer: Josh Poimboeuf CommitterDate: Tue, 06 Oct 2020 09:37:57 -05:00 objtool: Rework header include paths Currently objtool headers are being included either by their base name or included via ../ from a parent directory. In case of a base name usage: #include "warn.h" #include "arch_elf.h" it does not make it apparent from which directory the file comes from. To make it slightly better, and actually to avoid name clashes some arch specific files have "arch_" suffix. And files from an arch folder have to revert to including via ../ e.g: #include "../../elf.h" With additional architectures support and the code base growth there is a need for clearer headers naming scheme for multiple reasons: 1. to make it instantly obvious where these files come from (objtool itself / objtool arch|generic folders / some other external files), 2. to avoid name clashes of objtool arch specific headers, potential obtool arch generic headers and the system header files (there is /usr/include/elf.h already), 3. to avoid ../ includes and improve code readability. 4. to give a warm fuzzy feeling to developers who are mostly kernel developers and are accustomed to linux kernel headers arranging scheme. Doesn't this make it instantly obvious where are these files come from? #include #include And doesn't it look nicer to avoid ugly ../ includes? Which also guarantees this is elf.h from the objtool and not /usr/include/elf.h. #include This patch defines and implements new objtool headers arranging scheme. Which is: - all generic headers go to include/objtool (similar to include/linux) - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch prefix). This is similar to linux arch specific "asm/*" headers but we are not abusing "asm" name and calling it what it is. This also helps to prevent name clashes (arch is not used in system headers or kernel exports). To bring objtool to this state the following things are done: 1. current top level tools/objtool/ headers are moved into include/objtool/ subdirectory, 2. arch specific headers, currently only arch/x86/include/ are moved into arch/x86/include/arch/ and were stripped of "arch_" suffix, 3. new -I$(srctree)/tools/objtool/include include path to make includes like possible, 4. rewriting file includes, 5. make git not to ignore include/objtool/ subdirectory. Signed-off-by: Vasily Gorbik Signed-off-by: Josh Poimboeuf --- tools/objtool/.gitignore | 2 +- tools/objtool/Makefile | 1 +- tools/objtool/arch.h | 93 +- tools/objtool/arch/x86/decode.c | 8 +- tools/objtool/arch/x86/include/arch/cfi_regs.h | 25 ++- tools/objtool/arch/x86/include/arch/elf.h| 6 +- tools/objtool/arch/x86/include/arch/endianness.h | 9 +- tools/objtool/arch/x86/include/arch/special.h| 20 ++- tools/objtool/arch/x86/include/arch_elf.h| 6 +- tools/objtool/arch/x86/include/arch_endianness.h | 9 +- tools/objtool/arch/x86/include/arch_special.h| 20 +-- tools/objtool/arch/x86/include/cfi_regs.h| 25 +-- tools/objtool/arch/x86/special.c | 4 +- tools/objtool/builtin-check.c| 4 +- tools/objtool/builtin-orc.c | 4 +- tools/objtool/builtin.h | 16 +-- tools/objtool/cfi.h | 38 + tools/objtool/check.c| 16 +- tools/objtool/check.h| 69 +--- tools/objtool/elf.c | 6 +- tools/objtool/elf.h | 148 +-- tools/objtool/endianness.h | 38 + tools/objtool/include/objtool/arch.h | 93 +- tools/objtool/include/objtool/builtin.h | 16 ++- tools/objtool/include/objtool/cfi.h | 38 - tools/objtool/include/objtool/check.h| 69 +++- tools/objtool/include/objtool/elf.h | 148 ++- tools/objtool/include/objtool/endianness.h | 38 - tools/objtool/include/objtool/objtool.h | 32 +++- tools/objtool/include/objtool/special.h | 41 - tools/objtool/include/objtool/warn.h | 66 ++- tools/objtool/objtool.c | 6 +- tools/objtool/objtool.h | 32 +--- tools/objtool/orc_dump.c | 6 +- tools/objtool/orc_gen.c | 6 +- tools/objtoo
[tip: objtool/core] objtool: Allow nested externs to enable BUILD_BUG()
The following commit has been merged into the objtool/core branch of tip: Commit-ID: 2486baae2cf6df73554144d0a4e40ae8809b54d4 Gitweb: https://git.kernel.org/tip/2486baae2cf6df73554144d0a4e40ae8809b54d4 Author:Vasily Gorbik AuthorDate:Mon, 05 Oct 2020 17:50:28 +02:00 Committer: Josh Poimboeuf CommitterDate: Tue, 06 Oct 2020 09:32:13 -05:00 objtool: Allow nested externs to enable BUILD_BUG() Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. Build objtool with -Wno-nested-externs to enable BUILD_BUG() usage. Signed-off-by: Vasily Gorbik Signed-off-by: Josh Poimboeuf --- tools/objtool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 33d1e3c..4ea9a83 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -37,7 +37,7 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include -WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed +WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS)
Re: [RFC PATCH v4 4/4] objtool: fix x86 orc generation on big endian cross compiles
On Mon, Oct 05, 2020 at 09:03:28AM -0500, Josh Poimboeuf wrote: > On Sun, Oct 04, 2020 at 04:30:54PM +0200, Vasily Gorbik wrote: > > @@ -77,8 +78,9 @@ static int get_alt_entry(struct elf *elf, struct > > special_entry *entry, > > if (entry->feature) { > > unsigned short feature; > > > > - feature = *(unsigned short *)(sec->data->d_buf + offset + > > - entry->feature); > > + feature = bswap_if_needed(*(unsigned short *)(sec->data->d_buf + > > + offset + > > + entry->feature)); > > arch_handle_alternative(feature, alt); > > } > > --- > > arch/x86/include/asm/orc_types.h | 10 + > > tools/arch/x86/include/asm/orc_types.h| 10 + > > .../arch/x86/include/arch_endianness.h| 9 + > > This patch is misformatted. Almost like it was concatenated with > itself? Indeed. I wonder how that could have happened. Sorry for that. I've resent patches with rebased patch "objtool: avoid ../ headers includes and name clashes" on top. This time I checked patches could be applied from outgoing mailbox before sending it.
[RFC PATCH RESEND v4 3/4] objtool: correct rebuilding of reloc sections
From: Martin Schwidefsky Currently relocations generated in elf_rebuild_rel_reloc_section/ elf_rebuild_rela_reloc_section functions are broken if the objtool is built and run on big endian system. E.g. the following errors pop up during x86 cross compilation: x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x200 >= 0x22) for offset 0 in section `.orc_unwind_ip' x86_64-9.1.0-ld: final link failed: bad value To address that convert those functions to do things similar to elf_write_reloc(), reuse gelf_update_rel/gelf_update_rela libelf library functions. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- tools/objtool/elf.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..5c0341b0cde3 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -829,25 +829,27 @@ static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rel *relocs; + void *buf; /* Allocate a buffer for relocations */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rel); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_REL; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rel.r_offset = reloc->offset; + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rel(sec->data, idx, >rel); idx++; } @@ -858,26 +860,28 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rela *relocs; + void *buf; /* Allocate a buffer for relocations with addends */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rela); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_RELA; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_addend = reloc->addend; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rela.r_offset = reloc->offset; + reloc->rela.r_addend = reloc->addend; + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rela(sec->data, idx, >rela); idx++; } -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH RESEND v4 2/4] x86/insn: instruction decoder and big endian cross compiles
From: Martin Schwidefsky x86 instruction decoder code is shared across the kernel source and the tools. Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. Make the x86 instruction decoder build host endianness agnostic to support x86 cross compilation and enable objtool to implement endianness awareness for big endian architectures support. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 33 ++ arch/x86/lib/insn.c | 101 ++ tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/lib/insn.c | 101 ++ 4 files changed, 160 insertions(+), 108 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..004e27bdf121 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -7,9 +7,12 @@ * Copyright (C) IBM Corporation, 2009 */ +#include /* insn_attr_t is defined in inat.h */ #include +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +23,36 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->little = __cpu_to_le32(v); + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..520b31fc1f1a 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -5,6 +5,7 @@ * Copyright (C) IBM Corporation, 2002, 2004, 2009 */ +#include #ifdef __KERNEL__ #include #else @@ -15,15 +16,28 @@ #include +#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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(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); }) @@ -157,8 +171,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +308,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); - modrm->value = mod; - modrm->nbytes = 1; + insn_field_set(modrm, mod, 1); if (inat_is_group(insn->attr)) { pfx_id = insn_last_prefix_id(insn); insn->attr = inat_get_group_attribu
[RFC PATCH RESEND v4 0/4] objtool and cross compilation
Sorry for the extra noise. Patches has been resent because one of them has been corrupted. That's what you get for post-editing mailbox in vim, few wrong extra strokes and your wife wants to divorce you because you just copied and pretty-formatted her threatening message to your internet service provider from another buffer. rfc v1 - rfc v2: - rebased onto tip/objtool/core - reformatted couple of lines rfc v2 - rfc v3: - reused __*_ENDIAN_BITFIELD and dropped unneeded byteswap if __KERNEL__ is defined following David's suggestions, - re-splitted changes and made x86 instruction decoder a separate patch, - extra patch to add -Wno-nested-externs build flag to enable BUILD_BUG() usage, - added a safer and more readable leXX_to_cpu macro in x86 instruction decoder, - simplified includes. Switched to using leXX_to_cpu/cpu_to_leXX in the objtool and x86 instruction decoder since is included in the objtool already. rfc v3 - rfc v4: - patch 4: objtool: fix x86 orc generation on big endian cross compiles - introduced "bswap_if_needed()" macro for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. - patch 2: x86/insn: instruction decoder and big endian cross compiles - changed subject prefix from objtool to x86/insn - reformated leXX_to_cpu macro make it easier to read Currently objtool seems to be the only tool from all the build tools needed for x86 build which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. This patch series points to endianness problems which should be addressed. Recent "other architectures support" patches currently moved only some problematic parts into x86 arch specific folder. Besides that even though big endian stuff is only needed for the objtool arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, so changes are applied to both. Any suggestions how to make patches more acceptable are welcome. Martin Schwidefsky (2): x86/insn: instruction decoder and big endian cross compiles objtool: correct rebuilding of reloc sections Vasily Gorbik (2): objtool: allow nested externs to enable BUILD_BUG() objtool: fix x86 orc generation on big endian cross compiles arch/x86/include/asm/insn.h | 33 ++ arch/x86/include/asm/orc_types.h | 10 ++ arch/x86/lib/insn.c | 101 -- tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/include/asm/orc_types.h| 10 ++ tools/arch/x86/lib/insn.c | 101 -- tools/objtool/Makefile| 2 +- .../arch/x86/include/arch_endianness.h| 9 ++ tools/objtool/check.c | 5 +- tools/objtool/elf.c | 34 +++--- tools/objtool/endianness.h| 38 +++ tools/objtool/orc_dump.c | 5 +- tools/objtool/orc_gen.c | 3 + tools/objtool/special.c | 6 +- 14 files changed, 260 insertions(+), 130 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH RESEND v4 1/4] objtool: allow nested externs to enable BUILD_BUG()
Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. Build objtool with -Wno-nested-externs to enable BUILD_BUG() usage. Signed-off-by: Vasily Gorbik --- tools/objtool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 33d1e3ca8efd..4ea9a833dde7 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -37,7 +37,7 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include -WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed +WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH RESEND v4 4/4] objtool: fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Introduces bswap_if_needed macro which does a byte swap if target endianness doesn't match the host, i.e. cross compilation for little endian on big endian and vice versa. To be used for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/orc_types.h | 10 + tools/arch/x86/include/asm/orc_types.h| 10 + .../arch/x86/include/arch_endianness.h| 9 + tools/objtool/check.c | 5 ++- tools/objtool/endianness.h| 38 +++ tools/objtool/orc_dump.c | 5 ++- tools/objtool/orc_gen.c | 3 ++ tools/objtool/special.c | 6 ++- 8 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/include/arch_endianness.h b/tools/objtool/arch/x86/include/arch_endianness.h new file mode 100644 index ..7c362527da20 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch_endianness.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ARCH_ENDIANNESS_H +#define _ARCH_ENDIANNESS_H + +#include + +#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN + +#endif /* _ARCH_ENDIANNESS_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2df9f769412e..fd892b77e98f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include "special.h" #include "warn.h" #include "arch_elf.h" +#include "endianness.h" #include #include @@ -1370,7 +1371,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = bswap_if_needed(hint->sp_offset); continue; } @@ -1382,7 +1383,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa->offset = bswap_if_needed(hint->sp_offset); insn->cfi.type = hint->type; insn->cfi.end = hint->end; } diff --git a/tools/objtool/endianness.h b/tools/objtool/endianness.h new file mode 100644 index ..ebece3191b58 --- /dev/null +++ b/tools/objtool/endianness.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _OBJTOOL_ENDIANNESS_H +#define _OBJTOOL_ENDIANNESS_H + +#include +#include +#include "arch_endianne
[PATCH v2] objtool: avoid ../ headers includes and name clashes
Currently objtool headers are being included either by their base name or included via ../ from a parent directory. In case of a base name usage: #include "warn.h" #include "arch_elf.h" it does not make it apparent from which directory the file comes from. To make it slightly better, and actually to avoid name clashes some arch specific files have "arch_" suffix. And files from an arch folder have to revert to including via ../ e.g: #include "../../elf.h" With additional architectures support and the code base growth there is a need for clearer headers naming scheme for multiple reasons: 1. to make it instantly obvious where these files come from (objtool itself / objtool arch|generic folders / some other external files), 2. to avoid name clashes of objtool arch specific headers, potential obtool arch generic headers and the system header files (there is /usr/include/elf.h already), 3. to avoid ../ includes and improve code readability. 4. to give a warm fuzzy feeling to developers who are mostly kernel developers and are accustomed to linux kernel headers arranging scheme. Doesn't this make it instantly obvious where are these files come from? #include #include And doesn't it look nicer to avoid ugly ../ includes? Which also guarantees this is elf.h from the objtool and not /usr/include/elf.h. #include This patch defines and implements new objtool headers arranging scheme. Which is: - all generic headers go to include/objtool (similar to include/linux) - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch prefix). This is similar to linux arch specific "asm/*" headers but we are not abusing "asm" name and calling it what it is. This also helps to prevent name clashes (arch is not used in system headers or kernel exports). To bring objtool to this state the following things are done: 1. current top level tools/objtool/ headers are moved into include/objtool/ subdirectory, 2. arch specific headers, currently only arch/x86/include/ are moved into arch/x86/include/arch/ and were stripped of "arch_" suffix, 3. new -I$(srctree)/tools/objtool/include include path to make includes like possible, 4. rewriting file includes, 5. make git not to ignore include/objtool/ subdirectory. Signed-off-by: Vasily Gorbik --- v1 - v2: patch is rebased on top of [RFC PATCH RESEND v4] objtool and cross compilation patch series. tools/objtool/.gitignore | 2 +- tools/objtool/Makefile | 1 + tools/objtool/arch/x86/decode.c | 8 .../arch/x86/include/{ => arch}/cfi_regs.h | 0 .../arch/x86/include/{arch_elf.h => arch/elf.h} | 0 .../{arch_endianness.h => arch/endianness.h} | 0 .../include/{arch_special.h => arch/special.h} | 0 tools/objtool/arch/x86/special.c | 4 ++-- tools/objtool/builtin-check.c| 4 ++-- tools/objtool/builtin-orc.c | 4 ++-- tools/objtool/check.c| 16 tools/objtool/elf.c | 6 +++--- tools/objtool/{ => include/objtool}/arch.h | 4 ++-- tools/objtool/{ => include/objtool}/builtin.h| 0 tools/objtool/{ => include/objtool}/cfi.h| 2 +- tools/objtool/{ => include/objtool}/check.h | 4 ++-- tools/objtool/{ => include/objtool}/elf.h| 0 tools/objtool/{ => include/objtool}/endianness.h | 2 +- tools/objtool/{ => include/objtool}/objtool.h| 2 +- tools/objtool/{ => include/objtool}/special.h| 4 ++-- tools/objtool/{ => include/objtool}/warn.h | 2 +- tools/objtool/objtool.c | 6 +++--- tools/objtool/orc_dump.c | 6 +++--- tools/objtool/orc_gen.c | 6 +++--- tools/objtool/special.c | 10 +- tools/objtool/weak.c | 2 +- 26 files changed, 48 insertions(+), 47 deletions(-) rename tools/objtool/arch/x86/include/{ => arch}/cfi_regs.h (100%) rename tools/objtool/arch/x86/include/{arch_elf.h => arch/elf.h} (100%) rename tools/objtool/arch/x86/include/{arch_endianness.h => arch/endianness.h} (100%) rename tools/objtool/arch/x86/include/{arch_special.h => arch/special.h} (100%) rename tools/objtool/{ => include/objtool}/arch.h (96%) rename tools/objtool/{ => include/objtool}/builtin.h (100%) rename tools/objtool/{ => include/objtool}/cfi.h (96%) rename tools/objtool/{ => include/objtool}/check.h (96%) rename tools/objtool/{ => include/objtool}/elf.h (100%) rename tools/objtool/{ => include/objtool}/endianness.h (97%) rename tools/objtool/{ => include/objtool}/objtool.h (96%) rename tools/objtool/{ => include/objtool}/special.h (94%) rename tools/objtool/{ => include
[RFC PATCH v4 3/4] objtool: correct rebuilding of reloc sections
From: Martin Schwidefsky Currently relocations generated in elf_rebuild_rel_reloc_section/ elf_rebuild_rela_reloc_section functions are broken if the objtool is built and run on big endian system. E.g. the following errors pop up during x86 cross compilation: x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x200 >= 0x22) for offset 0 in section `.orc_unwind_ip' x86_64-9.1.0-ld: final link failed: bad value To address that convert those functions to do things similar to elf_write_reloc(), reuse gelf_update_rel/gelf_update_rela libelf library functions. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- tools/objtool/elf.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..5c0341b0cde3 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -829,25 +829,27 @@ static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rel *relocs; + void *buf; /* Allocate a buffer for relocations */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rel); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_REL; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rel.r_offset = reloc->offset; + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rel(sec->data, idx, >rel); idx++; } @@ -858,26 +860,28 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rela *relocs; + void *buf; /* Allocate a buffer for relocations with addends */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rela); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_RELA; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_addend = reloc->addend; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rela.r_offset = reloc->offset; + reloc->rela.r_addend = reloc->addend; + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rela(sec->data, idx, >rela); idx++; } -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v4 4/4] objtool: fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Introduces bswap_if_needed macro which does a byte swap if target endianness doesn't match the host, i.e. cross compilation for little endian on big endian and vice versa. To be used for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. Signed-off-by: Vasily Gorbik diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/include/arch_endianness.h b/tools/objtool/arch/x86/include/arch_endianness.h new file mode 100644 index ..7c362527da20 --- /dev/null +++ b/tools/objtool/arch/x86/include/arch_endianness.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ARCH_ENDIANNESS_H +#define _ARCH_ENDIANNESS_H + +#include + +#define __TARGET_BYTE_ORDER __LITTLE_ENDIAN + +#endif /* _ARCH_ENDIANNESS_H */ diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2df9f769412e..fd892b77e98f 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -13,6 +13,7 @@ #include "special.h" #include "warn.h" #include "arch_elf.h" +#include "endianness.h" #include #include @@ -1370,7 +1371,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = bswap_if_needed(hint->sp_offset); continue; } @@ -1382,7 +1383,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa->offset = bswap_if_needed(hint->sp_offset); insn->cfi.type = hint->type; insn->cfi.end = hint->end; } diff --git a/tools/objtool/endianness.h b/tools/objtool/endianness.h new file mode 100644 index ..ebece3191b58 --- /dev/null +++ b/tools/objtool/endianness.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _OBJTOOL_ENDIANNESS_H +#define _OBJTOOL_ENDIANNESS_H + +#include +#include +#include "arch_endianness.h" + +#ifndef __TARGET_BYTE_ORDER +#error undefined arch __TARGET_BYTE_ORDER +#endif + +#if __BYTE_ORDER != __TARGET_BYTE_ORDER +#define __NEED_BSWAP 1 +#else +#define __NEED_BSWAP 0 +#endif + +/* + * Does a byte swap if target endianness doesn't match the host, i.e. cross + * compilation for little endian on big endian and vice versa. + * To be used for multi-byte values conversion, which are read from / about + * to be written to a target native endianness ELF file. + */ +#define bswap_if_needed(val) \ +({ \ +
[RFC PATCH v4 2/4] x86/insn: instruction decoder and big endian cross compiles
From: Martin Schwidefsky x86 instruction decoder code is shared across the kernel source and the tools. Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. Make the x86 instruction decoder build host endianness agnostic to support x86 cross compilation and enable objtool to implement endianness awareness for big endian architectures support. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 33 ++ arch/x86/lib/insn.c | 101 ++ tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/lib/insn.c | 101 ++ 4 files changed, 160 insertions(+), 108 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..004e27bdf121 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -7,9 +7,12 @@ * Copyright (C) IBM Corporation, 2009 */ +#include /* insn_attr_t is defined in inat.h */ #include +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +23,36 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->little = __cpu_to_le32(v); + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..520b31fc1f1a 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -5,6 +5,7 @@ * Copyright (C) IBM Corporation, 2002, 2004, 2009 */ +#include #ifdef __KERNEL__ #include #else @@ -15,15 +16,28 @@ #include +#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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(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); }) @@ -157,8 +171,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +308,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); - modrm->value = mod; - modrm->nbytes = 1; + insn_field_set(modrm, mod, 1); if (inat_is_group(insn->attr)) { pfx_id = insn_last_prefix_id(insn); insn->attr = inat_get_group_attribu
[RFC PATCH v4 1/4] objtool: allow nested externs to enable BUILD_BUG()
Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. Build objtool with -Wno-nested-externs to enable BUILD_BUG() usage. Signed-off-by: Vasily Gorbik --- tools/objtool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 33d1e3ca8efd..4ea9a833dde7 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -37,7 +37,7 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include -WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed +WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v4 0/4] objtool and cross compilation
rfc v1 - rfc v2: - rebased onto tip/objtool/core - reformatted couple of lines rfc v2 - rfc v3: - reused __*_ENDIAN_BITFIELD and dropped unneeded byteswap if __KERNEL__ is defined following David's suggestions, - re-splitted changes and made x86 instruction decoder a separate patch, - extra patch to add -Wno-nested-externs build flag to enable BUILD_BUG() usage, - added a safer and more readable leXX_to_cpu macro in x86 instruction decoder, - simplified includes. Switched to using leXX_to_cpu/cpu_to_leXX in the objtool and x86 instruction decoder since is included in the objtool already. rfc v3 - rfc v4: - patch 4: objtool: fix x86 orc generation on big endian cross compiles - introduced "bswap_if_needed()" macro for multi-byte values conversion, which are read from / about to be written to a target native endianness ELF file. - patch 2: x86/insn: instruction decoder and big endian cross compiles - changed subject prefix from objtool to x86/insn - reformated leXX_to_cpu macro make it easier to read Currently objtool seems to be the only tool from all the build tools needed for x86 build which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. This patch series points to endianness problems which should be addressed. Recent "other architectures support" patches currently moved only some problematic parts into x86 arch specific folder. Besides that even though big endian stuff is only needed for the objtool arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, so changes are applied to both. Any suggestions how to make patches more acceptable are welcome. Martin Schwidefsky (2): x86/insn: instruction decoder and big endian cross compiles objtool: correct rebuilding of reloc sections Vasily Gorbik (2): objtool: allow nested externs to enable BUILD_BUG() objtool: fix x86 orc generation on big endian cross compiles arch/x86/include/asm/insn.h | 33 ++ arch/x86/include/asm/orc_types.h | 10 ++ arch/x86/lib/insn.c | 101 -- tools/arch/x86/include/asm/insn.h | 33 ++ tools/arch/x86/include/asm/orc_types.h| 10 ++ tools/arch/x86/lib/insn.c | 101 -- tools/objtool/Makefile| 2 +- .../arch/x86/include/arch_endianness.h| 9 ++ tools/objtool/check.c | 5 +- tools/objtool/elf.c | 34 +++--- tools/objtool/endianness.h| 38 +++ tools/objtool/orc_dump.c | 5 +- tools/objtool/orc_gen.c | 3 + tools/objtool/special.c | 6 +- 14 files changed, 260 insertions(+), 130 deletions(-) create mode 100644 tools/objtool/arch/x86/include/arch_endianness.h create mode 100644 tools/objtool/endianness.h -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[PATCH] objtool: avoid ../ headers includes and name clashes
Currently objtool headers are being included either by their base name or included via ../ from a parent directory. In case of a base name usage: #include "warn.h" #include "arch_elf.h" it does not make it apparent from which directory the file comes from. To make it slightly better, and actually to avoid name clashes some arch specific files have "arch_" suffix. And files from an arch folder have to revert to including via ../ e.g: #include "../../elf.h" With additional architectures support and the code base growth there is a need for clearer headers naming scheme for multiple reasons: 1. to make it instantly obvious where these files come from (objtool itself / objtool arch|generic folders / some other external files), 2. to avoid name clashes of objtool arch specific headers, potential obtool arch generic headers and the system header files (there is /usr/include/elf.h already), 3. to avoid ../ includes and improve code readability. 4. to give a warm fuzzy feeling to developers who are mostly kernel developers and are accustomed to linux kernel headers arranging scheme. Doesn't this make it instantly obvious where are these files come from? #include #include And doesn't it look nicer to avoid ugly ../ includes? Which also guarantees this is elf.h from the objtool and not /usr/include/elf.h. #include This patch defines and implements new objtool headers arranging scheme. Which is: - all generic headers go to include/objtool (similar to include/linux) - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch prefix). This is similar to linux arch specific "asm/*" headers but we are not abusing "asm" name and calling it what it is. This also helps to prevent name clashes (arch is not used in system headers or kernel exports). To bring objtool to this state the following things are done: 1. current top level tools/objtool/ headers are moved into include/objtool/ subdirectory, 2. arch specific headers, currently only arch/x86/include/ are moved into arch/x86/include/arch/ and were stripped of "arch_" suffix, 3. new -I$(srctree)/tools/objtool/include include path to make includes like possible, 4. rewriting file includes, 5. make git not to ignore include/objtool/ subdirectory. Signed-off-by: Vasily Gorbik --- tools/objtool/.gitignore | 2 +- tools/objtool/Makefile | 1 + tools/objtool/arch/x86/decode.c| 8 .../objtool/arch/x86/include/{ => arch}/cfi_regs.h | 0 .../arch/x86/include/{arch_elf.h => arch/elf.h}| 0 .../x86/include/{arch_special.h => arch/special.h} | 0 tools/objtool/arch/x86/special.c | 4 ++-- tools/objtool/builtin-check.c | 4 ++-- tools/objtool/builtin-orc.c| 4 ++-- tools/objtool/check.c | 14 +++--- tools/objtool/elf.c| 6 +++--- tools/objtool/{ => include/objtool}/arch.h | 4 ++-- tools/objtool/{ => include/objtool}/builtin.h | 0 tools/objtool/{ => include/objtool}/cfi.h | 2 +- tools/objtool/{ => include/objtool}/check.h| 4 ++-- tools/objtool/{ => include/objtool}/elf.h | 0 tools/objtool/{ => include/objtool}/objtool.h | 2 +- tools/objtool/{ => include/objtool}/special.h | 4 ++-- tools/objtool/{ => include/objtool}/warn.h | 2 +- tools/objtool/objtool.c| 6 +++--- tools/objtool/orc_dump.c | 4 ++-- tools/objtool/orc_gen.c| 4 ++-- tools/objtool/special.c| 8 tools/objtool/weak.c | 2 +- 24 files changed, 43 insertions(+), 42 deletions(-) rename tools/objtool/arch/x86/include/{ => arch}/cfi_regs.h (100%) rename tools/objtool/arch/x86/include/{arch_elf.h => arch/elf.h} (100%) rename tools/objtool/arch/x86/include/{arch_special.h => arch/special.h} (100%) rename tools/objtool/{ => include/objtool}/arch.h (96%) rename tools/objtool/{ => include/objtool}/builtin.h (100%) rename tools/objtool/{ => include/objtool}/cfi.h (96%) rename tools/objtool/{ => include/objtool}/check.h (96%) rename tools/objtool/{ => include/objtool}/elf.h (100%) rename tools/objtool/{ => include/objtool}/objtool.h (96%) rename tools/objtool/{ => include/objtool}/special.h (94%) rename tools/objtool/{ => include/objtool}/warn.h (98%) diff --git a/tools/objtool/.gitignore b/tools/objtool/.gitignore index 45cefda24c7b..14236db3677f 100644 --- a/tools/objtool/.gitignore +++ b/tools/objtool/.gitignore @@ -1,4 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only arch/x86/lib/inat-tables.c -objtool +/objtool fixdep diff --git a/tools/objtool/Makefile b/tools/objtool/Mak
[RFC PATCH v3 4/4] objtool: fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/orc_types.h | 10 ++ tools/arch/x86/include/asm/orc_types.h | 10 ++ tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 4 ++-- tools/objtool/orc_dump.c | 4 ++-- tools/objtool/orc_gen.c| 2 ++ 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec4cfde..5a2baf28a1dc 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,8 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#include + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -51,10 +53,18 @@ struct orc_entry { s16 sp_offset; s16 bp_offset; +#if defined(__LITTLE_ENDIAN_BITFIELD) unsignedsp_reg:4; unsignedbp_reg:4; unsignedtype:2; unsignedend:1; +#elif defined(__BIG_ENDIAN_BITFIELD) + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +#endif } __packed; #endif /* __ASSEMBLY__ */ diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/special.c index fd4af88c0ea5..8349842aac82 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -9,7 +9,7 @@ void arch_handle_alternative(unsigned short feature, struct special_alt *alt) { - switch (feature) { + switch (le16_to_cpu(feature)) { case X86_FEATURE_SMAP: /* * If UACCESS validation is enabled; force that alternative; diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 2df9f769412e..f20a4be2fb22 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1370,7 +1370,7 @@ static int read_unwind_hints(struct objtool_file *file) cfa = >cfi.cfa; if (hint->type == UNWIND_HINT_TYPE_RET_OFFSET) { - insn->ret_offset = hint->sp_offset; + insn->ret_offset = le16_to_cpu(hint->sp_offset); continue; } @@ -1382,7 +1382,7 @@ static int read_unwind_hints(struct objtool_file *file) return -1; } - cfa->offset = hint->sp_offset; + cfa->offset = le16_to_cpu(hint->sp_offset); insn->cfi.type = hint->type; insn->cfi.end = hint->end; } diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c index 5e6a95368d35..4cea20520ca7 100644 --- a/tools/objtool/orc_dump.c +++ b/tools/objtool/orc_dump.c @@ -197,11 +197,11 @@ int orc_dump(const char *_objname) printf(" sp:"); - print_reg(orc[i].sp_reg, orc[i].sp_offset); + print_reg(orc[i].sp_reg, (s16)le16_to_cpu(orc[i].sp_offset)); printf(" bp:"); - print_reg(orc[i].bp_reg, orc[i].bp_offset); + print_reg(orc[i].bp_reg, (s16)le16_to_cpu(orc[i].bp_offset)); printf(" type:%s end:%d\n", orc_type_name(orc[i].type), orc[i].end); diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index 235663b96adc..123fd718ea9a 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -96,6 +96,8 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti /* populate ORC data */ orc = (struct orc_entry *)u_sec->data->d_buf + idx;
[RFC PATCH v3 0/4] objtool and cross compilation
rfc v1 - rfc v2: - rebased onto tip/objtool/core - reformatted couple of lines rfc v2 - rfc v3: - reused __*_ENDIAN_BITFIELD and dropped unneeded byteswap if __KERNEL__ is defined following David's suggestions, - re-splitted changes and made x86 instruction decoder a separate patch, - extra patch to add -Wno-nested-externs build flag to enable BUILD_BUG() usage, - added a safer and more readable leXX_to_cpu macro in x86 instruction decoder, - simplified includes. Switched to using leXX_to_cpu/cpu_to_leXX in the objtool and x86 instruction decoder since is included in the objtool already. Currently objtool seems to be the only tool from all the build tools needed for x86 build which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. This patch series points to endianness problems which should be addressed. Recent "other architectures support" patches currently moved only some problematic parts into x86 arch specific folder. Besides that even though big endian stuff is only needed for the objtool arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, so changes are applied to both. Any suggestions how to make patches more acceptable are welcome. Martin Schwidefsky (2): objtool: x86 instruction decoder and big endian cross compiles objtool: correct rebuilding of reloc sections Vasily Gorbik (2): objtool: allow nested externs to enable BUILD_BUG() objtool: fix x86 orc generation on big endian cross compiles arch/x86/include/asm/insn.h| 35 arch/x86/include/asm/orc_types.h | 10 +++ arch/x86/lib/insn.c| 108 - tools/arch/x86/include/asm/insn.h | 35 tools/arch/x86/include/asm/orc_types.h | 10 +++ tools/arch/x86/lib/insn.c | 108 - tools/objtool/Makefile | 2 +- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 4 +- tools/objtool/elf.c| 34 tools/objtool/orc_dump.c | 4 +- tools/objtool/orc_gen.c| 2 + 12 files changed, 225 insertions(+), 129 deletions(-) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v3 3/4] objtool: correct rebuilding of reloc sections
From: Martin Schwidefsky Currently relocations generated in elf_rebuild_rel_reloc_section/ elf_rebuild_rela_reloc_section functions are broken if the objtool is built and run on big endian system. E.g. the following errors pop up during x86 cross compilation: x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x200 >= 0x22) for offset 0 in section `.orc_unwind_ip' x86_64-9.1.0-ld: final link failed: bad value To address that convert those functions to do things similar to elf_write_reloc(), reuse gelf_update_rel/gelf_update_rela libelf library functions. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- tools/objtool/elf.c | 34 +++--- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c index 4e1d7460574b..5c0341b0cde3 100644 --- a/tools/objtool/elf.c +++ b/tools/objtool/elf.c @@ -829,25 +829,27 @@ static int elf_rebuild_rel_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rel *relocs; + void *buf; /* Allocate a buffer for relocations */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rel); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_REL; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rel.r_offset = reloc->offset; + reloc->rel.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rel(sec->data, idx, >rel); idx++; } @@ -858,26 +860,28 @@ static int elf_rebuild_rela_reloc_section(struct section *sec, int nr) { struct reloc *reloc; int idx = 0, size; - GElf_Rela *relocs; + void *buf; /* Allocate a buffer for relocations with addends */ - size = nr * sizeof(*relocs); - relocs = malloc(size); - if (!relocs) { + size = nr * sizeof(GElf_Rela); + buf = malloc(size); + if (!buf) { perror("malloc"); return -1; } - sec->data->d_buf = relocs; + sec->data->d_buf = buf; sec->data->d_size = size; + sec->data->d_type = ELF_T_RELA; sec->sh.sh_size = size; idx = 0; list_for_each_entry(reloc, >reloc_list, list) { - relocs[idx].r_offset = reloc->offset; - relocs[idx].r_addend = reloc->addend; - relocs[idx].r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + reloc->rela.r_offset = reloc->offset; + reloc->rela.r_addend = reloc->addend; + reloc->rela.r_info = GELF_R_INFO(reloc->sym->idx, reloc->type); + gelf_update_rela(sec->data, idx, >rela); idx++; } -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v3 1/4] objtool: allow nested externs to enable BUILD_BUG()
Currently BUILD_BUG() macro is expanded to smth like the following: do { extern void __compiletime_assert_0(void) __attribute__((error("BUILD_BUG failed"))); if (!(!(1))) __compiletime_assert_0(); } while (0); If used in a function body this obviously would produce build errors with -Wnested-externs and -Werror. Build objtool with -Wno-nested-externs to enable BUILD_BUG() usage. Signed-off-by: Vasily Gorbik --- tools/objtool/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/objtool/Makefile b/tools/objtool/Makefile index 33d1e3ca8efd..4ea9a833dde7 100644 --- a/tools/objtool/Makefile +++ b/tools/objtool/Makefile @@ -37,7 +37,7 @@ INCLUDES := -I$(srctree)/tools/include \ -I$(srctree)/tools/arch/$(HOSTARCH)/include/uapi \ -I$(srctree)/tools/arch/$(SRCARCH)/include \ -I$(srctree)/tools/objtool/arch/$(SRCARCH)/include -WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed +WARNINGS := $(EXTRA_WARNINGS) -Wno-switch-default -Wno-switch-enum -Wno-packed -Wno-nested-externs CFLAGS := -Werror $(WARNINGS) $(KBUILD_HOSTCFLAGS) -g $(INCLUDES) $(LIBELF_FLAGS) LDFLAGS += $(LIBELF_LIBS) $(LIBSUBCMD) $(KBUILD_HOSTLDFLAGS) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v3 2/4] objtool: x86 instruction decoder and big endian cross compiles
From: Martin Schwidefsky Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. Make the x86 instruction decoder of the objtool usable on big endian machines. Signed-off-by: Martin Schwidefsky Co-developed-by: Vasily Gorbik Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 35 ++ arch/x86/lib/insn.c | 108 +++--- tools/arch/x86/include/asm/insn.h | 35 ++ tools/arch/x86/lib/insn.c | 108 +++--- 4 files changed, 178 insertions(+), 108 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..bff79b22da54 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -7,9 +7,12 @@ * Copyright (C) IBM Corporation, 2009 */ +#include /* insn_attr_t is defined in inat.h */ #include +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +23,38 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; +#ifndef __KERNEL__ + p->little = __bswap_32(v); +#endif + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..bbd4a5f15d83 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -5,6 +5,7 @@ * Copyright (C) IBM Corporation, 2002, 2004, 2009 */ +#include #ifdef __KERNEL__ #include #else @@ -15,15 +16,35 @@ #include +#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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); leXX_to_cpu(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(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); }) @@ -157,8 +178,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +315,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->
[RFC PATCH v2 1/2] objtool: x86 instruction decoder and big endian cross compiles
From: Martin Schwidefsky Make the x86 instruction decoder of the objtool usable on big endian machines. This is useful for compile tests on non x86, big endian hardware. Co-developed-by: Vasily Gorbik [ gor: more endianness problems findings fixes / rebasing ] Signed-off-by: Martin Schwidefsky Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 42 ++ arch/x86/lib/insn.c | 95 +-- tools/arch/x86/include/asm/insn.h | 42 ++ tools/arch/x86/lib/insn.c | 95 +-- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 4 +- tools/objtool/elf.c | 34 ++- 7 files changed, 188 insertions(+), 126 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..e5a2bcc41ac4 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -8,8 +8,16 @@ */ /* insn_attr_t is defined in inat.h */ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif #include +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +28,40 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; +#ifdef __KERNEL__ + p->little = __swap32(v); +#else + p->little = __bswap_32(v); +#endif + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..9150bdc8a6d6 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -15,15 +15,23 @@ #include +#ifdef __KERNEL__ +#define letoh(t, r) \ + ((sizeof(t) == 4) ? le32_to_cpu(r) : (sizeof(t) == 2) ? le16_to_cpu(r) : r) +#else +#define letoh(t, r) \ + ((sizeof(t) == 4) ? le32toh(r) : (sizeof(t) == 2) ? le16toh(r) : r) +#endif + /* 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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); letoh(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(t*)((insn)->next_byte + n); letoh(t, r); }) #define get_next(t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); }) @@ -157,8 +165,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +302,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); - modrm->value = mod; - modrm->nbytes = 1; + insn_field_set(modrm, mod, 1); if (inat_is_group(insn->attr)) { pfx_id = insn_last_prefix_id(insn); insn->attr = inat_get_group_attribute(mod, pfx_id, @@ -334,7 +340,7 @@ int insn_rip_relative(struct insn *insn) * For rip-relative instructions, the mod field (top 2 bits) * is zero and the r/m field (bottom 3 bits) is 0x5. */ - return (modrm->nbytes && (modrm->value & 0xc7) == 0x5); + return (modrm->nbytes && (modrm->bytes[0] & 0xc7) == 0x5); } /** @@ -353,11 +359,11 @@ void insn_get_sib(struct insn *insn) if (!insn->modrm.got) insn_get_modrm(insn); if (insn->modrm.nbytes) { - modrm = (insn_byte_t)insn->modrm.value; + modrm = insn->modrm.bytes[0]
[RFC PATCH v2 0/2] objtool and cross compilation
rfc v1 - rfc v2: - rebased onto tip/objtool/core - reformatted couple of lines Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. These 2 patches point to endianness problems which should be addressed. And I'd be glad to get any ideas how to make them less ugly. New "other architectures support" patches currently move only some problematic parts into x86 arch specific folder. But the main problem is that arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, and there is no common way to address endianness problems. Since big endian stuff is only needed for the objtool and not for the kernel I can try to hide alternative big endian definitions in tools only header which is included only if __KERNEL__ is not defined. But that kind of defeats the idea of sharing those files 1 to 1 with tools. Thoughts? Any suggestions are welcome. Martin Schwidefsky (1): objtool: x86 instruction decoder and big endian cross compiles Vasily Gorbik (1): objtool: fix x86 orc generation on big endian cross compiles arch/x86/include/asm/insn.h| 42 arch/x86/include/asm/orc_types.h | 24 +++ arch/x86/lib/insn.c| 95 +++--- tools/arch/x86/include/asm/insn.h | 42 tools/arch/x86/include/asm/orc_types.h | 24 +++ tools/arch/x86/lib/insn.c | 95 +++--- tools/objtool/arch/x86/special.c | 2 +- tools/objtool/check.c | 4 +- tools/objtool/elf.c| 34 + tools/objtool/orc_dump.c | 4 +- tools/objtool/orc_gen.c| 2 + 11 files changed, 240 insertions(+), 128 deletions(-) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH v2 2/2] objtool: fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/orc_types.h | 24 tools/arch/x86/include/asm/orc_types.h | 24 tools/objtool/orc_dump.c | 4 ++-- tools/objtool/orc_gen.c| 2 ++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index fdbffec4cfde..c72bee8e6ec0 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -40,6 +40,13 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -48,6 +55,9 @@ * the stack for a given code address. Each instance of the struct corresponds * to one or more code locations. */ + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct orc_entry { s16 sp_offset; s16 bp_offset; @@ -57,6 +67,20 @@ struct orc_entry { unsignedend:1; } __packed; +#else + +struct orc_entry { + s16 sp_offset; + s16 bp_offset; + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +} __packed; + +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ORC_TYPES_H */ diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index fdbffec4cfde..c72bee8e6ec0 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -40,6 +40,13 @@ #define ORC_REG_MAX15 #ifndef __ASSEMBLY__ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -48,6 +55,9 @@ * the stack for a given code address. Each instance of the struct corresponds * to one or more code locations. */ + +#if defined(__BYTE_ORDER) ? __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct orc_entry { s16 sp_offset; s16 bp_offset; @@ -57,6 +67,20 @@ struct orc_entry { unsignedend:1; } __packed; +#else + +struct orc_entry { + s16 sp_offset; + s16 bp_offset; + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +} __packed; + +#endif + #endif /* __ASSEMBLY__ */ #endif /* _ORC_TYPES_H */ diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c index 5e6a95368d35..19fa6f65040e 100644 --- a/tools/objtool/orc_dump.c +++ b/tools/objtool/orc_dump.c @@ -197,11 +197,11 @@ int orc_dump(const char *_objname) printf(" sp:"); - print_reg(orc[i].sp_reg, orc[i].sp_offset); + print_reg(orc[i].sp_reg, (s16)le16toh(orc[i].sp_offset)); printf(" bp:"); - print_reg(orc[i].bp_reg, orc[i].bp_offset); + print_reg(orc[i].bp_reg, (s16)le16toh(orc[i].bp_offset)); printf(" type:%s end:%d\n", orc_type_name(orc[i].type), orc[i].end); diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index 235663b96adc..ab9cff93fabd 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -96,6 +96,8 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti /* populate ORC data */ orc = (struct orc_entry *)u_sec->data->d_buf + idx; memcpy(orc, o, sizeof(*orc)); + orc->sp_offset = htole16(orc->sp_offset); + orc->bp_offset = htole16(orc->bp_offset); /* populate reloc for ip */ reloc = malloc(sizeof(*reloc)); -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH 2/2] objtool: fix x86 orc generation on big endian cross compiles
Correct objtool orc generation endianness problems to enable fully functional x86 cross compiles on big endian hardware. Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/orc_types.h | 24 tools/arch/x86/include/asm/orc_types.h | 24 tools/objtool/orc_dump.c | 4 ++-- tools/objtool/orc_gen.c| 2 ++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/orc_types.h b/arch/x86/include/asm/orc_types.h index d25534940bde..931f99b70af3 100644 --- a/arch/x86/include/asm/orc_types.h +++ b/arch/x86/include/asm/orc_types.h @@ -61,6 +61,13 @@ #define UNWIND_HINT_TYPE_RET_OFFSET3 #ifndef __ASSEMBLY__ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -69,6 +76,9 @@ * the stack for a given code address. Each instance of the struct corresponds * to one or more code locations. */ +#if defined(__BYTE_ORDER) ? \ + __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct orc_entry { s16 sp_offset; s16 bp_offset; @@ -78,6 +88,20 @@ struct orc_entry { unsignedend:1; } __packed; +#else + +struct orc_entry { + s16 sp_offset; + s16 bp_offset; + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +} __packed; + +#endif + /* * This struct is used by asm and inline asm code to manually annotate the * location of registers on the stack for the ORC unwinder. diff --git a/tools/arch/x86/include/asm/orc_types.h b/tools/arch/x86/include/asm/orc_types.h index d25534940bde..931f99b70af3 100644 --- a/tools/arch/x86/include/asm/orc_types.h +++ b/tools/arch/x86/include/asm/orc_types.h @@ -61,6 +61,13 @@ #define UNWIND_HINT_TYPE_RET_OFFSET3 #ifndef __ASSEMBLY__ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif + /* * This struct is more or less a vastly simplified version of the DWARF Call * Frame Information standard. It contains only the necessary parts of DWARF @@ -69,6 +76,9 @@ * the stack for a given code address. Each instance of the struct corresponds * to one or more code locations. */ +#if defined(__BYTE_ORDER) ? \ + __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct orc_entry { s16 sp_offset; s16 bp_offset; @@ -78,6 +88,20 @@ struct orc_entry { unsignedend:1; } __packed; +#else + +struct orc_entry { + s16 sp_offset; + s16 bp_offset; + unsignedbp_reg:4; + unsignedsp_reg:4; + unsignedunused:5; + unsignedend:1; + unsignedtype:2; +} __packed; + +#endif + /* * This struct is used by asm and inline asm code to manually annotate the * location of registers on the stack for the ORC unwinder. diff --git a/tools/objtool/orc_dump.c b/tools/objtool/orc_dump.c index fca46e006fc2..0fbf8521c891 100644 --- a/tools/objtool/orc_dump.c +++ b/tools/objtool/orc_dump.c @@ -196,11 +196,11 @@ int orc_dump(const char *_objname) printf(" sp:"); - print_reg(orc[i].sp_reg, orc[i].sp_offset); + print_reg(orc[i].sp_reg, (s16)le16toh(orc[i].sp_offset)); printf(" bp:"); - print_reg(orc[i].bp_reg, orc[i].bp_offset); + print_reg(orc[i].bp_reg, (s16)le16toh(orc[i].bp_offset)); printf(" type:%s end:%d\n", orc_type_name(orc[i].type), orc[i].end); diff --git a/tools/objtool/orc_gen.c b/tools/objtool/orc_gen.c index 968f55e6dd94..b3978fad93e6 100644 --- a/tools/objtool/orc_gen.c +++ b/tools/objtool/orc_gen.c @@ -90,6 +90,8 @@ static int create_orc_entry(struct elf *elf, struct section *u_sec, struct secti /* populate ORC data */ orc = (struct orc_entry *)u_sec->data->d_buf + idx; memcpy(orc, o, sizeof(*orc)); + orc->sp_offset = htole16(orc->sp_offset); + orc->bp_offset = htole16(orc->bp_offset); /* populate reloc for ip */ reloc = malloc(sizeof(*reloc)); -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[RFC PATCH 1/2] objtool: x86 instruction decoder and big endian cross compiles
From: Martin Schwidefsky Make the x86 instruction decoder of the objtool usable on big endian machines. This is useful for compile tests on non x86, big endian hardware. Co-developed-by: Vasily Gorbik [ gor: more endianness problems findings fixes / rebasing ] Signed-off-by: Martin Schwidefsky Signed-off-by: Vasily Gorbik --- arch/x86/include/asm/insn.h | 43 ++ arch/x86/lib/insn.c | 95 +-- tools/arch/x86/include/asm/insn.h | 43 ++ tools/arch/x86/lib/insn.c | 95 +-- tools/objtool/check.c | 4 +- tools/objtool/elf.c | 34 ++- tools/objtool/special.c | 4 +- 7 files changed, 191 insertions(+), 127 deletions(-) diff --git a/arch/x86/include/asm/insn.h b/arch/x86/include/asm/insn.h index 5c1ae3eff9d4..8d9864b09552 100644 --- a/arch/x86/include/asm/insn.h +++ b/arch/x86/include/asm/insn.h @@ -8,8 +8,17 @@ */ /* insn_attr_t is defined in inat.h */ +#ifdef __KERNEL__ +#include +#include +#else +#include +#endif #include +#if defined(__BYTE_ORDER) ? \ + __BYTE_ORDER == __LITTLE_ENDIAN : defined(__LITTLE_ENDIAN) + struct insn_field { union { insn_value_t value; @@ -20,6 +29,40 @@ struct insn_field { unsigned char nbytes; }; +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; + p->nbytes = n; +} + +#else + +struct insn_field { + insn_value_t value; + union { + insn_value_t little; + insn_byte_t bytes[4]; + }; + /* !0 if we've run insn_get_xxx() for this field */ + unsigned char got; + unsigned char nbytes; +}; + +static inline void insn_field_set(struct insn_field *p, insn_value_t v, + unsigned char n) +{ + p->value = v; +#ifdef __KERNEL__ + p->little = __swap32(v); +#else + p->little = __bswap_32(v); +#endif + p->nbytes = n; +} + +#endif + struct insn { struct insn_field prefixes; /* * Prefixes diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c index 404279563891..9150bdc8a6d6 100644 --- a/arch/x86/lib/insn.c +++ b/arch/x86/lib/insn.c @@ -15,15 +15,23 @@ #include +#ifdef __KERNEL__ +#define letoh(t, r) \ + ((sizeof(t) == 4) ? le32_to_cpu(r) : (sizeof(t) == 2) ? le16_to_cpu(r) : r) +#else +#define letoh(t, r) \ + ((sizeof(t) == 4) ? le32toh(r) : (sizeof(t) == 2) ? le16toh(r) : r) +#endif + /* 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 = *(t*)insn->next_byte; insn->next_byte += sizeof(t); r; }) + ({ t r = *(t*)insn->next_byte; insn->next_byte += sizeof(t); letoh(t, r); }) #define __peek_nbyte_next(t, insn, n) \ - ({ t r = *(t*)((insn)->next_byte + n); r; }) + ({ t r = *(t*)((insn)->next_byte + n); letoh(t, r); }) #define get_next(t, insn) \ ({ if (unlikely(!validate_next(t, insn, 0))) goto err_out; __get_next(t, insn); }) @@ -157,8 +165,7 @@ void insn_get_prefixes(struct insn *insn) b = peek_next(insn_byte_t, insn); attr = inat_get_opcode_attribute(b); if (inat_is_rex_prefix(attr)) { - insn->rex_prefix.value = b; - insn->rex_prefix.nbytes = 1; + insn_field_set(>rex_prefix, b, 1); insn->next_byte++; if (X86_REX_W(b)) /* REX.W overrides opnd_size */ @@ -295,8 +302,7 @@ void insn_get_modrm(struct insn *insn) if (inat_has_modrm(insn->attr)) { mod = get_next(insn_byte_t, insn); - modrm->value = mod; - modrm->nbytes = 1; + insn_field_set(modrm, mod, 1); if (inat_is_group(insn->attr)) { pfx_id = insn_last_prefix_id(insn); insn->attr = inat_get_group_attribute(mod, pfx_id, @@ -334,7 +340,7 @@ int insn_rip_relative(struct insn *insn) * For rip-relative instructions, the mod field (top 2 bits) * is zero and the r/m field (bottom 3 bits) is 0x5. */ - return (modrm->nbytes && (modrm->value & 0xc7) == 0x5); + return (modrm->nbytes && (modrm->bytes[0] & 0xc7) == 0x5); } /** @@ -353,11 +359,11 @@ void insn_get_sib(struct insn *insn) if (!insn->modrm.got) insn_get_modrm(insn); if (insn->modrm.nbytes) { - modrm = (insn_byte_t)insn->modrm.value; + modrm = insn->modrm.by
[RFC PATCH 0/2] objtool and cross compilation
This is based on v5.9-rc7, before "other architectures support" patches starting pouring in. Currently objtool seems to be the only tool from build tools needed which breaks x86 cross compilation on big endian systems. But besides x86 cross compilation, endianness awareness is also needed for big endian architectures objtool support in general. We have working prototype of objtool support and orc unwinder for s390 made originally by Martin Schwidefsky. I'm trying to bring it in shape again and refactor to share more code with "generic" part. But first things first. These 2 patches point to endianness problems which should be addressed. And I'd be glad to get any ideas how to make them less ugly. New "other architectures support" patches currently move only some problematic parts into x86 arch specific folder. But the main problem is that arch/x86/lib/insn.c and arch/x86/include/asm/insn.h are shared across the kernel source and the tools, and there is no common way to address endianness problems. Since big endian stuff is only needed for the objtool and not for the kernel I can try to hide alternative big endian definitions in tools only header which is included only if __KERNEL__ is not defined. But that kind of defeats the idea of sharing those files 1 to 1 with tools. Thoughts? Any suggestions are welcome. Martin Schwidefsky (1): objtool: x86 instruction decoder and big endian cross compiles Vasily Gorbik (1): objtool: fix x86 orc generation on big endian cross compiles arch/x86/include/asm/insn.h| 43 arch/x86/include/asm/orc_types.h | 24 +++ arch/x86/lib/insn.c| 95 +++--- tools/arch/x86/include/asm/insn.h | 43 tools/arch/x86/include/asm/orc_types.h | 24 +++ tools/arch/x86/lib/insn.c | 95 +++--- tools/objtool/check.c | 4 +- tools/objtool/elf.c| 34 + tools/objtool/orc_dump.c | 4 +- tools/objtool/orc_gen.c| 2 + tools/objtool/special.c| 4 +- 11 files changed, 243 insertions(+), 129 deletions(-) -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
Re: [PATCH -next] s390/3215: simplify the return expression of tty3215_open()
On Mon, Sep 21, 2020 at 09:11:01PM +0800, Qinglang Miao wrote: > Simplify the return expression. > > Signed-off-by: Qinglang Miao > --- > drivers/s390/char/con3215.c | 7 +-- > 1 file changed, 1 insertion(+), 6 deletions(-) > > diff --git a/drivers/s390/char/con3215.c b/drivers/s390/char/con3215.c > index 92757f9bd..d8acabbb1 100644 > --- a/drivers/s390/char/con3215.c > +++ b/drivers/s390/char/con3215.c > @@ -978,7 +978,6 @@ static int tty3215_install(struct tty_driver *driver, > struct tty_struct *tty) > static int tty3215_open(struct tty_struct *tty, struct file * filp) > { > struct raw3215_info *raw = tty->driver_data; > - int retval; > > tty_port_tty_set(>port, tty); > > @@ -986,11 +985,7 @@ static int tty3215_open(struct tty_struct *tty, struct > file * filp) > /* >* Start up 3215 device >*/ > - retval = raw3215_startup(raw); > - if (retval) > - return retval; > - > - return 0; > + return raw3215_startup(raw); > } Applied, thank you.
Re: [patch V2 34/46] PCI/MSI: Make arch_.*_msi_irq[s] fallbacks selectable
On Fri, Sep 25, 2020 at 09:54:52AM -0400, Qian Cai wrote: > On Wed, 2020-08-26 at 13:17 +0200, Thomas Gleixner wrote: > > From: Thomas Gleixner > > > > The arch_.*_msi_irq[s] fallbacks are compiled in whether an architecture > > requires them or not. Architectures which are fully utilizing hierarchical > > irq domains should never call into that code. > > > > It's not only architectures which depend on that by implementing one or > > more of the weak functions, there is also a bunch of drivers which relies > > on the weak functions which invoke msi_controller::setup_irq[s] and > > msi_controller::teardown_irq. > > > > Make the architectures and drivers which rely on them select them in Kconfig > > and if not selected replace them by stub functions which emit a warning and > > fail the PCI/MSI interrupt allocation. > > > > Signed-off-by: Thomas Gleixner > > Today's linux-next will have some warnings on s390x: > > .config: https://gitlab.com/cailca/linux-mm/-/blob/master/s390.config > > WARNING: unmet direct dependencies detected for PCI_MSI_ARCH_FALLBACKS > Depends on [n]: PCI [=n] > Selected by [y]: > - S390 [=y] > > WARNING: unmet direct dependencies detected for PCI_MSI_ARCH_FALLBACKS > Depends on [n]: PCI [=n] > Selected by [y]: > - S390 [=y] > Yes, as well as on mips and sparc which also don't FORCE_PCI. This seems to work for s390: diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index b0b7acf07eb8..41136fbe909b 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -192,3 +192,3 @@ config S390 select PCI_MSI if PCI - select PCI_MSI_ARCH_FALLBACKS + select PCI_MSI_ARCH_FALLBACKS if PCI select SET_FS
[GIT PULL] s390 updates for 5.9-rc7
Hello Linus, please pull s390 changes for 5.9-rc7. Thank you, Vasily The following changes since commit ba4f184e126b751d1bffad5897f263108befc780: Linux 5.9-rc6 (2020-09-20 16:33:55 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.9-7 for you to fetch changes up to f7e80983f0cf470bb82036e73bff4d5a7daf8fc2: s390/zcrypt: Fix ZCRYPT_PERDEV_REQCNT ioctl (2020-09-24 09:57:24 +0200) s390 fixes for 5.9-rc7 - Fix truncated ZCRYPT_PERDEV_REQCNT ioctl result. Copy entire reqcnt list. Christian Borntraeger (1): s390/zcrypt: Fix ZCRYPT_PERDEV_REQCNT ioctl drivers/s390/crypto/zcrypt_api.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/s390/crypto/zcrypt_api.c b/drivers/s390/crypto/zcrypt_api.c index 4dbbfd88262c..f314936b5462 100644 --- a/drivers/s390/crypto/zcrypt_api.c +++ b/drivers/s390/crypto/zcrypt_api.c @@ -1449,7 +1449,8 @@ static long zcrypt_unlocked_ioctl(struct file *filp, unsigned int cmd, if (!reqcnt) return -ENOMEM; zcrypt_perdev_reqcnt(reqcnt, AP_DEVICES); - if (copy_to_user((int __user *) arg, reqcnt, sizeof(reqcnt))) + if (copy_to_user((int __user *) arg, reqcnt, +sizeof(u32) * AP_DEVICES)) rc = -EFAULT; kfree(reqcnt); return rc;
[GIT PULL] s390 updates for 5.9-rc6
Hello Linus, please pull s390 changes for 5.9-rc6. Thank you, Vasily The following changes since commit 856deb866d16e29bd65952e0289066f6078af773: Linux 5.9-rc5 (2020-09-13 16:06:00 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.9-6 for you to fetch changes up to cd4d3d5f21ddbfae3f686ac0ff405f21f7847ad3: s390: add 3f program exception handler (2020-09-14 10:08:07 +0200) s390 fixes for 5.9-rc6 - Fix order in trace_hardirqs_off_caller() to make locking state consistent even if the IRQ tracer calls into lockdep again. Touches common code. Acked-by Peter Zijlstra. - Correctly handle secure storage violation exception to avoid kernel panic triggered by user space misbehaviour. - Switch the idle->seqcount over to using raw_write_*() to avoid "suspicious RCU usage". - Fix memory leaks on hard unplug in pci code. - Use kvmalloc instead of kmalloc for larger allocations in zcrypt. - Add few missing __init annotations to static functions to avoid section mismatch complains when functions are not inlined. Harald Freudenberger (1): s390/zcrypt: fix kmalloc 256k failure Ilya Leoshkevich (1): s390/init: add missing __init annotations Janosch Frank (1): s390: add 3f program exception handler Niklas Schnelle (1): s390/pci: fix leak of DMA tables on hard unplug Peter Zijlstra (1): s390/idle: fix suspicious RCU usage Sven Schnelle (1): lockdep: fix order in trace_hardirqs_off_caller() arch/s390/kernel/entry.h | 1 + arch/s390/kernel/idle.c | 5 ++--- arch/s390/kernel/pgm_check.S | 2 +- arch/s390/kernel/setup.c | 6 +++--- arch/s390/mm/fault.c | 20 arch/s390/pci/pci.c | 4 arch/s390/pci/pci_event.c| 2 ++ drivers/s390/crypto/zcrypt_ccamisc.c | 8 kernel/trace/trace_preemptirq.c | 4 ++-- 9 files changed, 39 insertions(+), 13 deletions(-) diff --git a/arch/s390/kernel/entry.h b/arch/s390/kernel/entry.h index faca269d5f27..a44ddc2f2dec 100644 --- a/arch/s390/kernel/entry.h +++ b/arch/s390/kernel/entry.h @@ -26,6 +26,7 @@ void do_protection_exception(struct pt_regs *regs); void do_dat_exception(struct pt_regs *regs); void do_secure_storage_access(struct pt_regs *regs); void do_non_secure_storage_access(struct pt_regs *regs); +void do_secure_storage_violation(struct pt_regs *regs); void addressing_exception(struct pt_regs *regs); void data_exception(struct pt_regs *regs); diff --git a/arch/s390/kernel/idle.c b/arch/s390/kernel/idle.c index c73f50649e7e..f7f1e64e0d98 100644 --- a/arch/s390/kernel/idle.c +++ b/arch/s390/kernel/idle.c @@ -39,14 +39,13 @@ void enabled_wait(void) local_irq_restore(flags); /* Account time spent with enabled wait psw loaded as idle time. */ - /* XXX seqcount has tracepoints that require RCU */ - write_seqcount_begin(>seqcount); + raw_write_seqcount_begin(>seqcount); idle_time = idle->clock_idle_exit - idle->clock_idle_enter; idle->clock_idle_enter = idle->clock_idle_exit = 0ULL; idle->idle_time += idle_time; idle->idle_count++; account_idle_time(cputime_to_nsecs(idle_time)); - write_seqcount_end(>seqcount); + raw_write_seqcount_end(>seqcount); } NOKPROBE_SYMBOL(enabled_wait); diff --git a/arch/s390/kernel/pgm_check.S b/arch/s390/kernel/pgm_check.S index 2c27907a5ffc..9a92638360ee 100644 --- a/arch/s390/kernel/pgm_check.S +++ b/arch/s390/kernel/pgm_check.S @@ -80,7 +80,7 @@ PGM_CHECK(do_dat_exception) /* 3b */ PGM_CHECK_DEFAULT /* 3c */ PGM_CHECK(do_secure_storage_access)/* 3d */ PGM_CHECK(do_non_secure_storage_access)/* 3e */ -PGM_CHECK_DEFAULT /* 3f */ +PGM_CHECK(do_secure_storage_violation) /* 3f */ PGM_CHECK(monitor_event_exception) /* 40 */ PGM_CHECK_DEFAULT /* 41 */ PGM_CHECK_DEFAULT /* 42 */ diff --git a/arch/s390/kernel/setup.c b/arch/s390/kernel/setup.c index e600f6953d7c..c2c1b4e723ea 100644 --- a/arch/s390/kernel/setup.c +++ b/arch/s390/kernel/setup.c @@ -619,7 +619,7 @@ static struct notifier_block kdump_mem_nb = { /* * Make sure that the area behind memory_end is protected */ -static void reserve_memory_end(void) +static void __init reserve_memory_end(void) { if (memory_end_set) memblock_reserve(memory_end, ULONG_MAX); @@ -628,7 +628,7 @@ static void reserve_memory_end(void) /* * Make sure that oldmem, where the dump is stored, is protected */ -static void reserve_oldmem(void) +static void __init reserve_oldmem(void) { #ifdef CONFIG_CRASH_DUMP if (OLDMEM_BASE) @@ -640,7 +640,7 @@ static void reserve_oldmem(void) /* * Make
Re: [PATCH v2] mm/gup: fix gup_fast with dynamic page table folding
On Fri, Sep 11, 2020 at 10:36:43PM +0200, Vasily Gorbik wrote: > Currently to make sure that every page table entry is read just once > gup_fast walks perform READ_ONCE and pass pXd value down to the next > gup_pXd_range function by value e.g.: ...snip... > --- > v2: added brackets -> &(pgd) > > arch/s390/include/asm/pgtable.h | 42 +++-- > include/linux/pgtable.h | 10 > mm/gup.c| 18 +++--- > 3 files changed, 49 insertions(+), 21 deletions(-) Andrew, any chance you would pick this up? There is an Ack from Linus. And I haven't seen any objections from Jason or John. This seems to be as safe for other architectures as possible. @Jason and John Any acks/nacks? Thank you, Vasily
[PATCH v2] mm/gup: fix gup_fast with dynamic page table folding
Currently to make sure that every page table entry is read just once gup_fast walks perform READ_ONCE and pass pXd value down to the next gup_pXd_range function by value e.g.: static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) ... pudp = pud_offset(, addr); This function passes a reference on that local value copy to pXd_offset, and might get the very same pointer in return. This happens when the level is folded (on most arches), and that pointer should not be iterated. On s390 due to the fact that each task might have different 5,4 or 3-level address translation and hence different levels folded the logic is more complex and non-iteratable pointer to a local copy leads to severe problems. Here is an example of what happens with gup_fast on s390, for a task with 3-levels paging, crossing a 2 GB pud boundary: // addr = 0x1007000, end = 0x10080001000 static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) { unsigned long next; pud_t *pudp; // pud_offset returns itself (a pointer to a value on stack) pudp = pud_offset(, addr); do { // on second iteratation reading "random" stack value pud_t pud = READ_ONCE(*pudp); // next = 0x1008000, due to PUD_SIZE/MASK != PGDIR_SIZE/MASK on s390 next = pud_addr_end(addr, end); ... } while (pudp++, addr = next, addr != end); // pudp++ iterating over stack return 1; } This happens since s390 moved to common gup code with commit d1874a0c2805 ("s390/mm: make the pxd_offset functions more robust") and commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast code"). s390 tried to mimic static level folding by changing pXd_offset primitives to always calculate top level page table offset in pgd_offset and just return the value passed when pXd_offset has to act as folded. What is crucial for gup_fast and what has been overlooked is that PxD_SIZE/MASK and thus pXd_addr_end should also change correspondingly. And the latter is not possible with dynamic folding. To fix the issue in addition to pXd values pass original pXdp pointers down to gup_pXd_range functions. And introduce pXd_offset_lockless helpers, which take an additional pXd entry value parameter. This has already been discussed in https://lkml.kernel.org/r/20190418100218.0a4afd51@mschwideX1 Cc: # 5.2+ Fixes: 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast code") Reviewed-by: Gerald Schaefer Reviewed-by: Alexander Gordeev Signed-off-by: Vasily Gorbik --- v2: added brackets -> &(pgd) arch/s390/include/asm/pgtable.h | 42 +++-- include/linux/pgtable.h | 10 mm/gup.c| 18 +++--- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 7eb01a5459cd..b55561cc8786 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1260,26 +1260,44 @@ static inline pgd_t *pgd_offset_raw(pgd_t *pgd, unsigned long address) #define pgd_offset(mm, address) pgd_offset_raw(READ_ONCE((mm)->pgd), address) -static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) +static inline p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, unsigned long address) { - if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1) - return (p4d_t *) pgd_deref(*pgd) + p4d_index(address); - return (p4d_t *) pgd; + if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1) + return (p4d_t *) pgd_deref(pgd) + p4d_index(address); + return (p4d_t *) pgdp; } +#define p4d_offset_lockless p4d_offset_lockless -static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) +static inline p4d_t *p4d_offset(pgd_t *pgdp, unsigned long address) { - if ((p4d_val(*p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2) - return (pud_t *) p4d_deref(*p4d) + pud_index(address); - return (pud_t *) p4d; + return p4d_offset_lockless(pgdp, *pgdp, address); +} + +static inline pud_t *pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, unsigned long address) +{ + if ((p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2) + return (pud_t *) p4d_deref(p4d) + pud_index(address); + return (pud_t *) p4dp; +} +#define pud_offset_lockless pud_offset_lockless + +static inline pud_t *pud_offset(p4d_t *p4dp, unsigned long address) +{ + return pud_offset_lockless(p4dp, *p4dp, address); } #define pud_offset pud_offset -static inline pmd_t *pmd_offset(pud_t *pud, unsigned
[PATCH] mm/gup: fix gup_fast with dynamic page table folding
Currently to make sure that every page table entry is read just once gup_fast walks perform READ_ONCE and pass pXd value down to the next gup_pXd_range function by value e.g.: static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) ... pudp = pud_offset(, addr); This function passes a reference on that local value copy to pXd_offset, and might get the very same pointer in return. This happens when the level is folded (on most arches), and that pointer should not be iterated. On s390 due to the fact that each task might have different 5,4 or 3-level address translation and hence different levels folded the logic is more complex and non-iteratable pointer to a local copy leads to severe problems. Here is an example of what happens with gup_fast on s390, for a task with 3-levels paging, crossing a 2 GB pud boundary: // addr = 0x1007000, end = 0x10080001000 static int gup_pud_range(p4d_t p4d, unsigned long addr, unsigned long end, unsigned int flags, struct page **pages, int *nr) { unsigned long next; pud_t *pudp; // pud_offset returns itself (a pointer to a value on stack) pudp = pud_offset(, addr); do { // on second iteratation reading "random" stack value pud_t pud = READ_ONCE(*pudp); // next = 0x1008000, due to PUD_SIZE/MASK != PGDIR_SIZE/MASK on s390 next = pud_addr_end(addr, end); ... } while (pudp++, addr = next, addr != end); // pudp++ iterating over stack return 1; } This happens since s390 moved to common gup code with commit d1874a0c2805 ("s390/mm: make the pxd_offset functions more robust") and commit 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast code"). s390 tried to mimic static level folding by changing pXd_offset primitives to always calculate top level page table offset in pgd_offset and just return the value passed when pXd_offset has to act as folded. What is crucial for gup_fast and what has been overlooked is that PxD_SIZE/MASK and thus pXd_addr_end should also change correspondingly. And the latter is not possible with dynamic folding. To fix the issue in addition to pXd values pass original pXdp pointers down to gup_pXd_range functions. And introduce pXd_offset_lockless helpers, which take an additional pXd entry value parameter. This has already been discussed in https://lkml.kernel.org/r/20190418100218.0a4afd51@mschwideX1 Cc: # 5.2+ Fixes: 1a42010cdc26 ("s390/mm: convert to the generic get_user_pages_fast code") Reviewed-by: Gerald Schaefer Reviewed-by: Alexander Gordeev Signed-off-by: Vasily Gorbik --- arch/s390/include/asm/pgtable.h | 42 +++-- include/linux/pgtable.h | 10 mm/gup.c| 18 +++--- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h index 7eb01a5459cd..b55561cc8786 100644 --- a/arch/s390/include/asm/pgtable.h +++ b/arch/s390/include/asm/pgtable.h @@ -1260,26 +1260,44 @@ static inline pgd_t *pgd_offset_raw(pgd_t *pgd, unsigned long address) #define pgd_offset(mm, address) pgd_offset_raw(READ_ONCE((mm)->pgd), address) -static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) +static inline p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, unsigned long address) { - if ((pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1) - return (p4d_t *) pgd_deref(*pgd) + p4d_index(address); - return (p4d_t *) pgd; + if ((pgd_val(pgd) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R1) + return (p4d_t *) pgd_deref(pgd) + p4d_index(address); + return (p4d_t *) pgdp; } +#define p4d_offset_lockless p4d_offset_lockless -static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) +static inline p4d_t *p4d_offset(pgd_t *pgdp, unsigned long address) { - if ((p4d_val(*p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2) - return (pud_t *) p4d_deref(*p4d) + pud_index(address); - return (pud_t *) p4d; + return p4d_offset_lockless(pgdp, *pgdp, address); +} + +static inline pud_t *pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, unsigned long address) +{ + if ((p4d_val(p4d) & _REGION_ENTRY_TYPE_MASK) >= _REGION_ENTRY_TYPE_R2) + return (pud_t *) p4d_deref(p4d) + pud_index(address); + return (pud_t *) p4dp; +} +#define pud_offset_lockless pud_offset_lockless + +static inline pud_t *pud_offset(p4d_t *p4dp, unsigned long address) +{ + return pud_offset_lockless(p4dp, *p4dp, address); } #define pud_offset pud_offset -static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address) +static inline pm
[GIT PULL] s390 updates for 5.9-rc4
Hello Linus, please pull s390 changes for 5.9-rc4. Thank you, Vasily The following changes since commit f75aef392f869018f78cfedf3c320a6b3fcfda6b: Linux 5.9-rc3 (2020-08-30 16:01:54 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.9-5 for you to fetch changes up to 5c60ed283e1d87e161441bb273541a948ee96f6a: s390: update defconfigs (2020-09-02 13:17:05 +0200) s390 fixes for 5.9-rc4 - Fix GENERIC_LOCKBREAK dependency on PREEMPTION in Kconfig broken because of a typo. - Update defconfigs. Eric Farman (1): s390: fix GENERIC_LOCKBREAK dependency typo in Kconfig Heiko Carstens (1): s390: update defconfigs arch/s390/Kconfig| 2 +- arch/s390/configs/debug_defconfig| 4 arch/s390/configs/defconfig | 3 +++ arch/s390/configs/zfcpdump_defconfig | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig index 3d86e12e8e3c..b29fcc66ec39 100644 --- a/arch/s390/Kconfig +++ b/arch/s390/Kconfig @@ -30,7 +30,7 @@ config GENERIC_BUG_RELATIVE_POINTERS def_bool y config GENERIC_LOCKBREAK - def_bool y if PREEMPTTION + def_bool y if PREEMPTION config PGSTE def_bool y if KVM diff --git a/arch/s390/configs/debug_defconfig b/arch/s390/configs/debug_defconfig index 0cf9a82326a8..7228aabe9da6 100644 --- a/arch/s390/configs/debug_defconfig +++ b/arch/s390/configs/debug_defconfig @@ -626,6 +626,7 @@ CONFIG_NTFS_RW=y CONFIG_PROC_KCORE=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y +CONFIG_TMPFS_INODE64=y CONFIG_HUGETLBFS=y CONFIG_CONFIGFS_FS=m CONFIG_ECRYPT_FS=m @@ -807,6 +808,7 @@ CONFIG_DEBUG_NOTIFIERS=y CONFIG_BUG_ON_DATA_CORRUPTION=y CONFIG_DEBUG_CREDENTIALS=y CONFIG_RCU_TORTURE_TEST=m +CONFIG_RCU_REF_SCALE_TEST=m CONFIG_RCU_CPU_STALL_TIMEOUT=300 # CONFIG_RCU_TRACE is not set CONFIG_LATENCYTOP=y @@ -818,6 +820,7 @@ CONFIG_PREEMPT_TRACER=y CONFIG_SCHED_TRACER=y CONFIG_FTRACE_SYSCALLS=y CONFIG_BLK_DEV_IO_TRACE=y +CONFIG_BPF_KPROBE_OVERRIDE=y CONFIG_HIST_TRIGGERS=y CONFIG_S390_PTDUMP=y CONFIG_NOTIFIER_ERROR_INJECTION=m @@ -829,6 +832,7 @@ CONFIG_FAIL_MAKE_REQUEST=y CONFIG_FAIL_IO_TIMEOUT=y CONFIG_FAIL_FUTEX=y CONFIG_FAULT_INJECTION_DEBUG_FS=y +CONFIG_FAIL_FUNCTION=y CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y CONFIG_LKDTM=m CONFIG_TEST_LIST_SORT=y diff --git a/arch/s390/configs/defconfig b/arch/s390/configs/defconfig index 5df9759e8ff6..fab03b7a6932 100644 --- a/arch/s390/configs/defconfig +++ b/arch/s390/configs/defconfig @@ -617,6 +617,7 @@ CONFIG_NTFS_RW=y CONFIG_PROC_KCORE=y CONFIG_TMPFS=y CONFIG_TMPFS_POSIX_ACL=y +CONFIG_TMPFS_INODE64=y CONFIG_HUGETLBFS=y CONFIG_CONFIGFS_FS=m CONFIG_ECRYPT_FS=m @@ -763,6 +764,7 @@ CONFIG_PANIC_ON_OOPS=y CONFIG_TEST_LOCKUP=m CONFIG_BUG_ON_DATA_CORRUPTION=y CONFIG_RCU_TORTURE_TEST=m +CONFIG_RCU_REF_SCALE_TEST=m CONFIG_RCU_CPU_STALL_TIMEOUT=60 CONFIG_LATENCYTOP=y CONFIG_BOOTTIME_TRACING=y @@ -771,6 +773,7 @@ CONFIG_STACK_TRACER=y CONFIG_SCHED_TRACER=y CONFIG_FTRACE_SYSCALLS=y CONFIG_BLK_DEV_IO_TRACE=y +CONFIG_BPF_KPROBE_OVERRIDE=y CONFIG_HIST_TRIGGERS=y CONFIG_S390_PTDUMP=y CONFIG_LKDTM=m diff --git a/arch/s390/configs/zfcpdump_defconfig b/arch/s390/configs/zfcpdump_defconfig index 4091c50449cd..8f67c55625f9 100644 --- a/arch/s390/configs/zfcpdump_defconfig +++ b/arch/s390/configs/zfcpdump_defconfig @@ -74,5 +74,6 @@ CONFIG_DEBUG_KERNEL=y CONFIG_PANIC_ON_OOPS=y # CONFIG_SCHED_DEBUG is not set CONFIG_RCU_CPU_STALL_TIMEOUT=60 +# CONFIG_RCU_TRACE is not set # CONFIG_FTRACE is not set # CONFIG_RUNTIME_TESTING_MENU is not set
[GIT PULL] s390 updates for 5.9-rc3
Hello Linus, please pull s390 changes for 5.9-rc3. Thank you, Vasily The following changes since commit d012a7190fc1fd72ed48911e77ca97ba4521bccd: Linux 5.9-rc2 (2020-08-23 14:08:43 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.9-4 for you to fetch changes up to bffc2f7aa96343f91931272d7a8a2d8d925e1ab2: s390/vmem: fix vmem_add_range for 4-level paging (2020-08-26 18:07:05 +0200) s390 fixes for 5.9-rc3 - Disable preemption trace in percpu macros since the lockdep code itself uses percpu variables now and it causes recursions. - Fix kernel space 4-level paging broken by recent vmem rework. Sven Schnelle (1): s390: don't trace preemption in percpu macros Vasily Gorbik (1): s390/vmem: fix vmem_add_range for 4-level paging arch/s390/include/asm/percpu.h | 28 ++-- arch/s390/mm/vmem.c| 1 + 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/arch/s390/include/asm/percpu.h b/arch/s390/include/asm/percpu.h index 50b4ce8cddfd..918f0ba4f4d2 100644 --- a/arch/s390/include/asm/percpu.h +++ b/arch/s390/include/asm/percpu.h @@ -29,7 +29,7 @@ typedef typeof(pcp) pcp_op_T__; \ pcp_op_T__ old__, new__, prev__;\ pcp_op_T__ *ptr__; \ - preempt_disable(); \ + preempt_disable_notrace(); \ ptr__ = raw_cpu_ptr(&(pcp));\ prev__ = *ptr__;\ do {\ @@ -37,7 +37,7 @@ new__ = old__ op (val); \ prev__ = cmpxchg(ptr__, old__, new__); \ } while (prev__ != old__); \ - preempt_enable(); \ + preempt_enable_notrace(); \ new__; \ }) @@ -68,7 +68,7 @@ typedef typeof(pcp) pcp_op_T__; \ pcp_op_T__ val__ = (val); \ pcp_op_T__ old__, *ptr__; \ - preempt_disable(); \ + preempt_disable_notrace(); \ ptr__ = raw_cpu_ptr(&(pcp));\ if (__builtin_constant_p(val__) && \ ((szcast)val__ > -129) && ((szcast)val__ < 128)) { \ @@ -84,7 +84,7 @@ : [val__] "d" (val__) \ : "cc");\ } \ - preempt_enable(); \ + preempt_enable_notrace(); \ } #define this_cpu_add_4(pcp, val) arch_this_cpu_add(pcp, val, "laa", "asi", int) @@ -95,14 +95,14 @@ typedef typeof(pcp) pcp_op_T__; \ pcp_op_T__ val__ = (val); \ pcp_op_T__ old__, *ptr__; \ - preempt_disable(); \ + preempt_disable_notrace(); \ ptr__ = raw_cpu_ptr(&(pcp));\ asm volatile( \ op "%[old__],%[val__],%[ptr__]\n" \ : [old__] "=d" (old__), [ptr__] "+Q" (*ptr__) \ : [val__] "d" (val__) \ : "cc");\ - preempt_enable(); \ + preempt_enable_notrace(); \ old__ + val__; \ }) @@ -114,14 +114,14 @@ typedef typeof(pcp) pcp_op_T__; \ pcp_op_T__ val__ = (val); \ pcp_op_T__ old__, *ptr__; \ - preempt_disable();
[GIT PULL] s390 updates for 5.9-rc2
Hello Linus, please pull s390 changes for 5.9-rc2. Thank you, Vasily The following changes since commit 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5: Linux 5.9-rc1 (2020-08-16 13:04:57 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.9-3 for you to fetch changes up to b97bf44f99155e57088e16974afb1f2d7b5287aa: s390/pci: fix PF/VF linking on hot plug (2020-08-17 13:17:34 +0200) s390 fixes for 5.9-rc2 - Couple of fixes for storage key handling relevant for debugging. - Add cond_resched into potentially slow subchannels scanning loop. - Fixes for PF/VF linking and to ignore stale PCI configuration request events. Heiko Carstens (2): s390/runtime_instrumentation: fix storage key handling s390/ptrace: fix storage key handling Niklas Schnelle (4): s390/pci: ignore stale configuration request event s390/pci: fix zpci_bus_link_virtfn() s390/pci: re-introduce zpci_remove_device() s390/pci: fix PF/VF linking on hot plug Vineeth Vijayan (1): s390/cio: add cond_resched() in the slow_eval_known_fn() loop arch/s390/kernel/ptrace.c | 7 +++-- arch/s390/kernel/runtime_instr.c | 2 +- arch/s390/pci/pci.c| 22 +++- arch/s390/pci/pci_bus.c| 52 ++ arch/s390/pci/pci_bus.h| 13 ++ arch/s390/pci/pci_event.c | 7 +++-- drivers/pci/hotplug/s390_pci_hpc.c | 12 - drivers/s390/cio/css.c | 5 8 files changed, 79 insertions(+), 41 deletions(-)
Re: linux plumbers + clang + s390 virtualized testing
On Thu, Aug 06, 2020 at 12:02:52PM -0700, Nick Desaulniers wrote: > On Wed, Jul 29, 2020 at 6:51 AM Vasily Gorbik wrote: > > > > > > We were very excited to see your patches going by for enabling Clang > > > > support for s390. Since then, we've added s390 builds to our > > > > continuous integration setup. > > > > > > > > We've been running into a few issues with doing virtualized boot tests > > > > of our kernels on s390. > > > > > > > > I was curious if you'll both be attending Linux plumbers conf? If we > > > > carve out time for an s390+clang talk, would this be of interest to > > > > you to attend? > > I will attend and it would surely be interesting to me and other > > s390 folks. Your efforts are greatly appreciated! > > Cool, so our MC has been approved: > https://www.linuxplumbersconf.org/event/7/page/80-accepted-microconferences#llvm-cr > > But we're super tight on time and probably won't be able to do a > session on s390 at the MC. That said, I have just submitted a BoF > proposal since we have more topics internal to our group we'd like to > have more time to discuss. I've added s390 testing to the list of > potential topics, too. I'll re-ping this thread once I hear back > about whether it gets approved or not. > > That said, we do meet once every other week virtually online, see > links: https://clangbuiltlinux.github.io/. > > > > > BTW I believe basic Clang support for s390 came earlier in 5.2 with > > a lot of efforts from Arnd Bergmann. > > > > My part was fixing recent breakages and bugging our s390 clang team > > (which did all the great work) to get kernel specific features support > > in clang 10 and 11 to reach features parity with gcc. And eventually > > doing few adjustments so that features which came with clang 10 and > > 11 are working smoothly. That is s390 "asm goto" support and specific > > compiler flags for ftrace support and stack packing. > > That's awesome; I'd love to get the chance to meet your s390 LLVM > team; in general it can take a while to get bugs routed to folks most > empowered to fix them until you know who they are. > > Would you, any fellow s390 kernel and LLVM folks be interested in > attending one of our virtual meetings, even if it's just to say "hi" > quickly? Next one is next Wednesday. > > Usually we go over whatever firedrills we've been running the past two > weeks, but sometimes have presentations of folks projects and > research. I think it would be cool to get more background on s390 and > work out the issues we're running into with testing. I've added few more people in To. We'll try to make it next Wednesday, but no promises since we are based in Germany and this is quite late for us.
Re: linux plumbers + clang + s390 virtualized testing
On Thu, Jul 16, 2020 at 01:28:40PM +0200, Heiko Carstens wrote: > Hi Nick, > > > We were very excited to see your patches going by for enabling Clang > > support for s390. Since then, we've added s390 builds to our > > continuous integration setup. > > > > We've been running into a few issues with doing virtualized boot tests > > of our kernels on s390. > > > > I was curious if you'll both be attending Linux plumbers conf? If we > > carve out time for an s390+clang talk, would this be of interest to > > you to attend? > > I will not attend, however cannot speak for Vasily. He will have to > answer as soon as he returns - besides that enabling Clang support for > s390 was done by Vasily anyway :) I will attend and it would surely be interesting to me and other s390 folks. Your efforts are greatly appreciated! BTW I believe basic Clang support for s390 came earlier in 5.2 with a lot of efforts from Arnd Bergmann. My part was fixing recent breakages and bugging our s390 clang team (which did all the great work) to get kernel specific features support in clang 10 and 11 to reach features parity with gcc. And eventually doing few adjustments so that features which came with clang 10 and 11 are working smoothly. That is s390 "asm goto" support and specific compiler flags for ftrace support and stack packing.
Re: [PATCH] mm/page_alloc: silence a KASAN false positive
On Wed, Jun 10, 2020 at 08:26:00AM -0400, Qian Cai wrote: > On Wed, Jun 10, 2020 at 07:54:50AM +0200, Dmitry Vyukov wrote: > > On Wed, Jun 10, 2020 at 7:22 AM Qian Cai wrote: > > > > > > kernel_init_free_pages() will use memset() on s390 to clear all pages > > > from kmalloc_order() which will override KASAN redzones because a > > > redzone was setup from the end of the allocation size to the end of the > > > last page. Silence it by not reporting it there. An example of the > > > report is, > > > > Interesting. The reason why we did not hit it on x86_64 is because > > clear_page is implemented in asm (arch/x86/lib/clear_page_64.S) and > > thus is not instrumented. Arm64 probably does the same. However, on > > s390 clear_page is defined to memset. > > clear_[high]page are pretty extensively used in the kernel. > > We can either do this, or make clear_page non instrumented on s390 as > > well to match the existing implicit assumption. The benefit of the > > current approach is that we can find some real use-after-free's and > > maybe out-of-bounds on clear_page. The downside is that we may need > > more of these annotations. Thoughts? > > Since we had already done the same thing in poison_page(), I suppose we > could do the same here. Also, clear_page() has been used in many places > on s390, and it is not clear to me if those are all safe like this. > > There might be more annotations required, so it probably up to s390 > maintainers (CC'ed) if they prefer not instrumenting clear_page() like > other arches. > Sorry for delay. I assume you tested it without CONFIG_JUMP_LABEL. I had to fix couple of things before I was able to use init_on_alloc=1 and init_on_free=1 boot options on s390 to reproduce KASAN problem: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v5.8-rc3=998f5bbe3dbdab81c1cfb1aef7c3892f5d24f6c7 https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=fixes=95e61b1b5d6394b53d147c0fcbe2ae70fbe09446 https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=fixes=d6df52e9996dcc2062c3d9c9123288468bb95b52 Back to clear_page - we could certainly make it non-instrumented. But it didn't cause any problems so far. And as Dmitry pointed out we could potentially find additional bugs with it. So, I'm leaning towards original solution proposed. For that you have my Acked-by: Vasily Gorbik Tested-by: Vasily Gorbik Thank you for looking into this! Andrew, would you pick this change up? Thank you Vasily
[GIT PULL] s390 updates for 5.8-rc2
Hello Linus, please pull s390 changes for 5.8-rc2. Thank you, Vasily The following changes since commit b3a9e3b9622ae10064826dccb4f7a52bd88c7407: Linux 5.8-rc1 (2020-06-14 12:45:04 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.8-2 for you to fetch changes up to b3583fca5fb654af2cfc1c08259abb9728272538: s390: fix syscall_get_error for compat processes (2020-06-17 23:05:05 +0200) s390 fixes for 5.8-rc2 - Few ptrace fixes mostly for strace and seccomp_bpf kernel tests findings. - Cleanup unused pm callbacks in virtio ccw. - Replace kmalloc + memset with kzalloc in crypto. - Use $(LD) for vDSO linkage to make clang happy. - Fix vDSO clock_getres() to preserve the same behaviour as posix_get_hrtimer_res(). - Fix workqueue cpumask warning when NUMA=n and nr_node_ids=2. - Reduce SLSB writes during input processing, improve warnings and cleanup qdio_data usage in qdio. - Few fixes to use scnprintf() instead of snprintf(). Chen Zhou (3): s390/crypto: use scnprintf() instead of snprintf() s390: use scnprintf() in sys_##_prefix##_##_name##_show s390/protvirt: use scnprintf() instead of snprintf() Cornelia Huck (1): s390/virtio: remove unused pm callbacks Dmitry V. Levin (1): s390: fix syscall_get_error for compat processes Heiko Carstens (1): s390/numa: let NODES_SHIFT depend on NEED_MULTIPLE_NODES Julian Wiedmann (4): s390/qdio: fine-tune SLSB update s390/qdio: reduce SLSB writes during Input Queue processing s390/qdio: clean up usage of qdio_data s390/qdio: warn about unexpected SLSB states Nathan Chancellor (1): s390/vdso: Use $(LD) instead of $(CC) to link vDSO Sven Schnelle (5): s390/seccomp: pass syscall arguments via seccomp_data s390/ptrace: return -ENOSYS when invalid syscall is supplied s390/ptrace: pass invalid syscall numbers to tracing s390/ptrace: fix setting syscall number selftests/seccomp: s390 shares the syscall and return value register Vincenzo Frascino (1): s390/vdso: fix vDSO clock_getres() Zou Wei (1): s390/zcrypt: use kzalloc arch/s390/Kconfig | 1 + arch/s390/crypto/prng.c | 14 ++-- arch/s390/include/asm/syscall.h | 12 ++- arch/s390/include/asm/vdso.h | 1 + arch/s390/kernel/asm-offsets.c| 2 +- arch/s390/kernel/entry.S | 2 +- arch/s390/kernel/ipl.c| 2 +- arch/s390/kernel/ptrace.c | 83 + arch/s390/kernel/time.c | 1 + arch/s390/kernel/uv.c | 8 +- arch/s390/kernel/vdso64/Makefile | 10 +-- arch/s390/kernel/vdso64/clock_getres.S| 10 +-- drivers/s390/cio/qdio.h | 7 +- drivers/s390/cio/qdio_debug.c | 4 +- drivers/s390/cio/qdio_main.c | 101 +++--- drivers/s390/crypto/zcrypt_ep11misc.c | 3 +- drivers/s390/virtio/virtio_ccw.c | 26 --- tools/testing/selftests/seccomp/seccomp_bpf.c | 1 + 18 files changed, 154 insertions(+), 134 deletions(-)
Re: [GIT PULL] s390 patches for the 5.8 merge window
On Mon, Jun 08, 2020 at 12:12:57PM -0700, Linus Torvalds wrote: > On Mon, Jun 8, 2020 at 12:09 PM Linus Torvalds > wrote: > > > > On Mon, Jun 8, 2020 at 8:35 AM Vasily Gorbik wrote: > > > > > > Please note 2 minor merge conflict resolutions below: > > > > There was a third because of the iommu tree I merged today. Looks fine, thank you. > Oh, and please don't post the whole patch in your pull request. Yes, this was not intentional. Sorry about that. Vasily
Re: [PATCH 1/1] s390/pci: Log new handle in clp_disable_fh()
On Thu, May 28, 2020 at 12:01:45PM +0200, Pierre Morel wrote: > > On 2020-05-28 11:08, Petr Tesarik wrote: > > Hi all, > > > > just a gentle ping. > > > > If the current behaviour (logging the original handle) was intended, > > then it was worth mentioning in the commit message for 17cdec960cf77, > > which made the change, but since that's no longer an option, I'd be > > happy with an explanation in email. > > > > Petr T > > > > On Fri, 22 May 2020 20:39:22 +0200 > > Petr Tesarik wrote: > > > > > After disabling a function, the original handle is logged instead of > > > the disabled handle. > > Hi Petr, > > Sorry for the delay, no doubt, you are right, the fh in zpci_dbg is the old > one and we should use the one in the zdev struct. > > Thanks, > Pierre > > Reviewed-by: Pierre Morel Applied, thanks
[GIT PULL] s390 updates for 5.7-rc7
Hello Linus, please pull s390 changes for 5.7-rc7. Thank you, Vasily The following changes since commit 2ef96a5bb12be62ef75b5828c0aab838ebb29cb8: Linux 5.7-rc5 (2020-05-10 15:16:58 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.7-4 for you to fetch changes up to 4c1cbcbd6c56c79de2c07159be4f55386bb0bef2: s390/kaslr: add support for R_390_JMP_SLOT relocation type (2020-05-20 10:13:27 +0200) s390 updates for 5.7-rc7 - Add missing R_390_JMP_SLOT relocation type in KASLR code. - Fix set_huge_pte_at for empty ptes issue which has been uncovered with arch page table helper tests. - Correct initrd location for kdump kernel. - Fix s390_mmio_read/write with MIO in PCI code. Gerald Schaefer (2): s390/mm: fix set_huge_pte_at() for empty ptes s390/kaslr: add support for R_390_JMP_SLOT relocation type Niklas Schnelle (1): s390/pci: Fix s390_mmio_read/write with MIO Philipp Rudo (1): s390/kexec_file: fix initrd location for kdump kernel arch/s390/include/asm/pci_io.h | 10 +- arch/s390/kernel/machine_kexec_file.c | 2 +- arch/s390/kernel/machine_kexec_reloc.c | 1 + arch/s390/mm/hugetlbpage.c | 9 +- arch/s390/pci/pci_mmio.c | 213 - 5 files changed, 227 insertions(+), 8 deletions(-) diff --git a/arch/s390/include/asm/pci_io.h b/arch/s390/include/asm/pci_io.h index cd060b5dd8fd..e4dc64cc9c55 100644 --- a/arch/s390/include/asm/pci_io.h +++ b/arch/s390/include/asm/pci_io.h @@ -8,6 +8,10 @@ #include #include +/* I/O size constraints */ +#define ZPCI_MAX_READ_SIZE 8 +#define ZPCI_MAX_WRITE_SIZE128 + /* I/O Map */ #define ZPCI_IOMAP_SHIFT 48 #define ZPCI_IOMAP_ADDR_BASE 0x8000UL @@ -140,7 +144,8 @@ static inline int zpci_memcpy_fromio(void *dst, while (n > 0) { size = zpci_get_max_write_size((u64 __force) src, - (u64) dst, n, 8); + (u64) dst, n, + ZPCI_MAX_READ_SIZE); rc = zpci_read_single(dst, src, size); if (rc) break; @@ -161,7 +166,8 @@ static inline int zpci_memcpy_toio(volatile void __iomem *dst, while (n > 0) { size = zpci_get_max_write_size((u64 __force) dst, - (u64) src, n, 128); + (u64) src, n, + ZPCI_MAX_WRITE_SIZE); if (size > 8) /* main path */ rc = zpci_write_block(dst, src, size); else diff --git a/arch/s390/kernel/machine_kexec_file.c b/arch/s390/kernel/machine_kexec_file.c index 8415ae7d2a23..f9e4baa64b67 100644 --- a/arch/s390/kernel/machine_kexec_file.c +++ b/arch/s390/kernel/machine_kexec_file.c @@ -151,7 +151,7 @@ static int kexec_file_add_initrd(struct kimage *image, buf.mem += crashk_res.start; buf.memsz = buf.bufsz; - data->parm->initrd_start = buf.mem; + data->parm->initrd_start = data->memsz; data->parm->initrd_size = buf.memsz; data->memsz += buf.memsz; diff --git a/arch/s390/kernel/machine_kexec_reloc.c b/arch/s390/kernel/machine_kexec_reloc.c index d5035de9020e..b7182cec48dc 100644 --- a/arch/s390/kernel/machine_kexec_reloc.c +++ b/arch/s390/kernel/machine_kexec_reloc.c @@ -28,6 +28,7 @@ int arch_kexec_do_relocs(int r_type, void *loc, unsigned long val, break; case R_390_64: /* Direct 64 bit. */ case R_390_GLOB_DAT: + case R_390_JMP_SLOT: *(u64 *)loc = val; break; case R_390_PC16:/* PC relative 16 bit. */ diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c index f01daddcbc5e..4632d4e26b66 100644 --- a/arch/s390/mm/hugetlbpage.c +++ b/arch/s390/mm/hugetlbpage.c @@ -159,10 +159,13 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, rste &= ~_SEGMENT_ENTRY_NOEXEC; /* Set correct table type for 2G hugepages */ - if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) - rste |= _REGION_ENTRY_TYPE_R3 | _REGION3_ENTRY_LARGE; - else + if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) { + if (likely(pte_present(pte))) + rste |= _REGION3_ENTRY_LARGE; + rste |= _REGION_ENTRY_TYPE_R3; + } else if (likely(pte_present(pte))) rste |= _SEGMENT_ENTRY_LARGE; + clear_huge_pte_skeys(mm, rste); pte_val(*ptep) = rste; } diff --git
Re: [PATCH] s390: ptrace: hard-code "s390x" instead of UTS_MACHINE
On Mon, Apr 13, 2020 at 10:31:13AM +0900, Masahiro Yamada wrote: > s390 uses the UTS_MACHINE defined arch/s390/Makefile as follows: > > UTS_MACHINE := s390x > > We do not need to pass the fixed string from the command line. > Hard-code user_regset_view::name, like many other architectures do. > > Signed-off-by: Masahiro Yamada > --- > > arch/s390/kernel/Makefile | 5 - > arch/s390/kernel/ptrace.c | 2 +- > 2 files changed, 1 insertion(+), 6 deletions(-) Yes, since we don't have 31-bit kernel build support for s390 anymore this makes sense. Applied, thanks.
[GIT PULL] s390 updates for 5.4-rc3
Hello Linus, please pull s390 changes for 5.4-rc3. Thank you, Vasily The following changes since commit da0c9ea146cbe92b832f1b0f694840ea8eb33cce: Linux 5.4-rc2 (2019-10-06 14:27:30 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.4-4 for you to fetch changes up to 062795fcdcb2d22822fb42644b1d76a8ad8439b3: s390/uaccess: avoid (false positive) compiler warnings (2019-10-11 12:27:25 +0200) s390 updates for 5.4-rc3 - Fix virtio-ccw DMA regression. - Fix compiler warnings in uaccess. Christian Borntraeger (1): s390/uaccess: avoid (false positive) compiler warnings Halil Pasic (1): s390/cio: fix virtio-ccw DMA without PV arch/s390/include/asm/uaccess.h | 4 ++-- drivers/s390/cio/cio.h | 1 + drivers/s390/cio/css.c | 7 ++- drivers/s390/cio/device.c | 2 +- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h index bd2fd9a7821d..a470f1fa9f2a 100644 --- a/arch/s390/include/asm/uaccess.h +++ b/arch/s390/include/asm/uaccess.h @@ -83,7 +83,7 @@ raw_copy_to_user(void __user *to, const void *from, unsigned long n); __rc; \ }) -static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) +static __always_inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) { unsigned long spec = 0x01UL; int rc; @@ -113,7 +113,7 @@ static inline int __put_user_fn(void *x, void __user *ptr, unsigned long size) return rc; } -static inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size) +static __always_inline int __get_user_fn(void *x, const void __user *ptr, unsigned long size) { unsigned long spec = 0x01UL; int rc; diff --git a/drivers/s390/cio/cio.h b/drivers/s390/cio/cio.h index ba7d2480613b..dcdaba689b20 100644 --- a/drivers/s390/cio/cio.h +++ b/drivers/s390/cio/cio.h @@ -113,6 +113,7 @@ struct subchannel { enum sch_todo todo; struct work_struct todo_work; struct schib_config config; + u64 dma_mask; char *driver_override; /* Driver name to force a match */ } __attribute__ ((aligned(8))); diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c index 1fbfb0a93f5f..831850435c23 100644 --- a/drivers/s390/cio/css.c +++ b/drivers/s390/cio/css.c @@ -232,7 +232,12 @@ struct subchannel *css_alloc_subchannel(struct subchannel_id schid, * belong to a subchannel need to fit 31 bit width (e.g. ccw). */ sch->dev.coherent_dma_mask = DMA_BIT_MASK(31); - sch->dev.dma_mask = >dev.coherent_dma_mask; + /* +* But we don't have such restrictions imposed on the stuff that +* is handled by the streaming API. +*/ + sch->dma_mask = DMA_BIT_MASK(64); + sch->dev.dma_mask = >dma_mask; return sch; err: diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c index 131430bd48d9..0c6245fc7706 100644 --- a/drivers/s390/cio/device.c +++ b/drivers/s390/cio/device.c @@ -710,7 +710,7 @@ static struct ccw_device * io_subchannel_allocate_dev(struct subchannel *sch) if (!cdev->private) goto err_priv; cdev->dev.coherent_dma_mask = sch->dev.coherent_dma_mask; - cdev->dev.dma_mask = >dev.coherent_dma_mask; + cdev->dev.dma_mask = sch->dev.dma_mask; dma_pool = cio_gp_dma_create(>dev, 1); if (!dma_pool) goto err_dma_pool;
[GIT PULL] s390 updates for 5.4-rc2
Hello Linus, please pull s390 changes for 5.4-rc2. Thank you, Vasily The following changes since commit 54ecb8f7028c5eb3d740bb82b0f1d90f2df63c5c: Linux 5.4-rc1 (2019-09-30 10:35:40 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.4-3 for you to fetch changes up to d0dea733f60efe94257d08ae6eba81d0b511d0a9: KVM: s390: mark __insn32_query() as __always_inline (2019-10-05 13:51:22 +0200) s390 updates for 5.4-rc2 - Default configs updates. - Fix build errors with CC_OPTIMIZE_FOR_SIZE due to usage of "i" constraint for function arguments. Two kvm changes acked-by Christian Borntraeger. - Fix -Wunused-but-set-variable warnings in mm code. - Avoid a constant misuse in qdio. - Handle a case when cpumf is temporarily unavailable. Heiko Carstens (8): s390/atomic,bitops: mark function(s) __always_inline s390/cpu_mf: mark function(s) __always_inline s390/jump_label: mark function(s) __always_inline s390/mm: mark function(s) __always_inline s390/pci: mark function(s) __always_inline s390: update defconfigs KVM: s390: fix __insn32_query() inline assembly KVM: s390: mark __insn32_query() as __always_inline Jiri Kosina (1): s390: mark __cpacf_query() as __always_inline Julian Wiedmann (1): s390/qdio: clarify size of the QIB parm area Qian Cai (1): s390/mm: fix -Wunused-but-set-variable warnings Thomas Richter (3): s390/cpumf: Use consistant debug print format s390/cpumsf: Check for CPU Measurement sampling s390/cpumf: Fix indentation in sampling device driver arch/s390/configs/debug_defconfig| 24 arch/s390/configs/defconfig | 25 - arch/s390/configs/zfcpdump_defconfig | 2 +- arch/s390/include/asm/atomic_ops.h | 2 +- arch/s390/include/asm/bitops.h | 8 arch/s390/include/asm/cpacf.h| 2 +- arch/s390/include/asm/cpu_mf.h | 8 ++-- arch/s390/include/asm/hugetlb.h | 9 +++-- arch/s390/include/asm/jump_label.h | 4 ++-- arch/s390/include/asm/pgtable.h | 25 + arch/s390/include/asm/qdio.h | 2 +- arch/s390/kernel/perf_cpum_cf_diag.c | 4 ++-- arch/s390/kernel/perf_cpum_sf.c | 8 +++- arch/s390/kvm/kvm-s390.c | 6 +++--- arch/s390/pci/pci_clp.c | 2 +- drivers/s390/cio/qdio_setup.c| 2 +- drivers/s390/net/qeth_core_main.c| 3 +-- 17 files changed, 83 insertions(+), 53 deletions(-)
[GIT PULL] s390 patches for the 5.4 merge window #2
Hello Linus, please pull the second round of s390 fixes and features for 5.4. Thank you, Vasily The following changes since commit d590284419b1d7cc2dc646e9bdde4da19061cf0f: Merge tag 's390-5.4-1' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux (2019-09-17 14:04:43 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git tags/s390-5.4-2 for you to fetch changes up to ab5758848039de9a4b249d46e4ab591197eebaf2: s390/cio: exclude subchannels with no parent from pseudo check (2019-09-23 23:27:53 +0200) s390 updates for the 5.4 merge window #2 - Fix 3 kasan findings. - Add PERF_EVENT_IOC_PERIOD ioctl support. - Add Crypto Express7S support and extend sysfs attributes for pkey. - Minor common I/O layer documentation corrections. Cornelia Huck (1): s390/cio: fix intparm documentation Harald Freudenberger (1): s390/zcrypt: CEX7S exploitation support Ingo Franzki (1): s390/pkey: Add sysfs attributes to emit AES CIPHER key blobs Thomas Richter (2): s390/cpum_sf: Support ioctl PERF_EVENT_IOC_PERIOD s390/cpumf: Remove mixed white space Vasily Gorbik (3): s390/topology: avoid firing events before kobjs are created s390/cio: avoid calling strlen on null pointer s390/cio: exclude subchannels with no parent from pseudo check arch/s390/include/asm/cpu_mf.h | 10 +-- arch/s390/include/asm/perf_event.h | 2 + arch/s390/include/uapi/asm/zcrypt.h | 4 +- arch/s390/kernel/perf_cpum_sf.c | 165 +++- arch/s390/kernel/topology.c | 3 +- drivers/s390/cio/ccwgroup.c | 2 +- drivers/s390/cio/css.c | 2 + drivers/s390/cio/device_ops.c | 23 +++-- drivers/s390/crypto/ap_bus.c| 12 +-- drivers/s390/crypto/ap_bus.h| 3 +- drivers/s390/crypto/pkey_api.c | 113 drivers/s390/crypto/vfio_ap_drv.c | 2 + drivers/s390/crypto/zcrypt_api.h| 3 +- drivers/s390/crypto/zcrypt_cex4.c | 72 +++- 14 files changed, 334 insertions(+), 82 deletions(-)
[GIT PULL] s390 patches for the 5.4 merge window
nt_t for reference counters for couple of places in mm code. - Logging improvements and return code fix in vfio-ccw code. - Couple of zpci fixes and minor refactoring. - Remove some outdated documentation. - Fix secure boot detection. - Other various minor code clean ups. Chuhong Yuan (2): s390/extmem: use refcount_t for refcount s390/mm: use refcount_t for refcount Cornelia Huck (1): vfio-ccw: add some logging Denis Efremov (1): s390/pci: PCI_IOV_RESOURCES loop refactoring in zpci_map_resources Halil Pasic (1): s390: vfio-ap: fix warning reset not completed Harald Freudenberger (10): s390/zcrypt: move cca misc functions to new code file s390/zcrypt: add base code for cca crypto card info support s390/zcrypt: new sysfs attributes serialnr and mkvps s390/pkey: pkey cleanup: narrow in-kernel API, fix some variable types s390/zcrypt: extend cca_findcard function and helper s390/zcrypt: Add low level functions for CCA AES cipher keys s390/pkey: add CCA AES cipher key support s390/paes: Prepare paes functions for large key blobs s390/zcrypt: fix wrong handling of cca cipher keygenflags s390/crypto: xts-aes-s390 fix extra run-time crypto self tests finding Heiko Carstens (2): Documentation/s390: remove outdated dasd documentation Documentation/s390: remove outdated debugging390 documentation Joerg Schmidbauer (1): s390/crypto: Support for SHA3 via CPACF (MSA6) Martin Schwidefsky (1): s390: add support for IBM z15 machines Masahiro Yamada (1): s390: remove pointless drivers-y in drivers/s390/Makefile Philipp Rudo (1): s390/sclp: Fix bit checked for has_sipl Sebastian Ott (1): s390/pci: fix MSI message data Thomas Richter (1): s390/cpum_sf: Fix line length and format string Vasily Gorbik (25): s390: move vmalloc option parsing to startup code s390/startup: add initial pgm check handler s390/startup: purge obsolete .gitignore patterns s390: clean .bss before running uncompressed kernel s390/kasan: provide uninstrumented __strlen s390/process: avoid potential reading of freed stack s390/kasan: avoid report in get_wchan s390/stacktrace: use common arch_stack_walk infrastructure s390/startup: adjust _sdma and _edma to page boundaries s390/startup: round down "mem" option to page boundary s390/numa: correct early_param handling s390/vmcp: correct early_param handling s390/startup: correct command line options parsing s390/vdso: reuse kstrtobool for option value parsing s390/cmma: reuse kstrtobool for option value parsing s390/mem_detect: provide single get_mem_detect_end s390/kaslr: reserve memory for kasan usage s390/pci: avoid using strncmp with hardcoded length s390/module: avoid using strncmp with hardcoded length s390/sclp: avoid using strncmp with hardcoded length s390/setup: avoid using strncmp with hardcoded length s390/kasan: add kdump support Merge tag 'vfio-ccw-20190828' of https://git.kernel.org/.../kvms390/vfio-ccw into features s390/base: remove unused s390_base_mcck_handler s390/startup: add pgm check info printing Wei Yongjun (1): vfio-ccw: fix error return code in vfio_ccw_sch_init() Documentation/s390/dasd.rst | 84 - Documentation/s390/debugging390.rst | 2613 --- Documentation/s390/index.rst|2 - arch/s390/Kconfig | 19 + arch/s390/Makefile |2 + arch/s390/boot/Makefile |2 +- arch/s390/boot/boot.h |1 + arch/s390/boot/compressed/.gitignore|3 - arch/s390/boot/compressed/vmlinux.lds.S |3 +- arch/s390/boot/head.S | 32 +- arch/s390/boot/ipl_parm.c | 11 +- arch/s390/boot/kaslr.c | 41 +- arch/s390/boot/mem_detect.c |7 - arch/s390/boot/pgm_check_info.c | 90 ++ arch/s390/boot/startup.c|6 + arch/s390/configs/debug_defconfig |2 + arch/s390/configs/defconfig |2 + arch/s390/crypto/Makefile |2 + arch/s390/crypto/aes_s390.c |6 + arch/s390/crypto/paes_s390.c| 184 ++- arch/s390/crypto/sha.h | 12 +- arch/s390/crypto/sha3_256_s390.c| 147 ++ arch/s390/crypto/sha3_512_s390.c| 155 ++ arch/s390/crypto/sha_common.c | 75 +- arch/s390/include/asm/cpacf.h |8 + arch/s390/include/asm/gmap.h|4 +- arch/s390/include/asm/mem_detect.h | 12 + arch/s390/include/asm/pgtable.h |1 + arch/s390/include/asm/pkey.h| 114 +- arch/s390/include/asm/processor.h |2 - arch/s390/include/
Re: linux-next: Tree for Aug 13
On Tue, Aug 13, 2019 at 10:56:45AM -0400, Steven Rostedt wrote: > > This looks related to what Marek posted. > > > https://lore.kernel.org/linux-security-module/3028ed35-3b6d-459f-f3c8-103c5636f...@samsung.com/ > > Care to apply the change he suggested to see if it fixes the issue for > you. If it does, Marek, can you make an official patch? > > -- Steve Right, same issue - same fix. Oh well, at least I got a bit more familiar with the code. -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
[PATCH] tracefs: avoid crash when open callback is not set
Some tracefs files, e.g. tracing/events/syscalls/*/id do not define "open" file operation. Yet commit 757ff7244358 ("tracefs: Restrict tracefs when the kernel is locked down") introduces "open" proxy which unconditionally calls original open callback, which causes kernel crash when the callback is 0. Fix that by simply returning 0, if open callback is not set. Fixes: 757ff7244358 ("tracefs: Restrict tracefs when the kernel is locked down") Signed-off-by: Vasily Gorbik --- fs/tracefs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/tracefs/inode.c b/fs/tracefs/inode.c index 12a325fb4cbd..77407632c916 100644 --- a/fs/tracefs/inode.c +++ b/fs/tracefs/inode.c @@ -43,7 +43,9 @@ static int default_open_file(struct inode *inode, struct file *filp) return ret; real_fops = dentry->d_fsdata; - return real_fops->open(inode, filp); + if (real_fops->open) + return real_fops->open(inode, filp); + return 0; } static ssize_t default_read_file(struct file *file, char __user *buf, -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿ ⣿⣿⡏⢰⣿⠖⣠⣿⡆⠈⣿⣿ ⣿⢛⣵⣄⠙⣶⣶⡟⣅⣠⠹⣿ ⣿⣜⣛⠻⢎⣉⣉⣀⠿⣫⣵⣿
Re: linux-next: Tree for Aug 13
On Tue, Aug 13, 2019 at 02:41:55PM +0200, Vasily Gorbik wrote: > On Tue, Aug 13, 2019 at 07:19:24PM +1000, Stephen Rothwell wrote: > > Merging security/next-testing (a4848e06f9af Merge branch 'next-lockdown' > > into next-testing) > > CONFLICT (content): Merge conflict in kernel/trace/trace_kprobe.c > > CONFLICT (content): Merge conflict in fs/tracefs/inode.c > > Applying: early_security_init() needs a stub got !CONFIG_SECURITY > > Hi all, > > next-lockdown causes panic on s390 when doing: > cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/id > > [ 3972.384027] Unable to handle kernel pointer dereference in virtual kernel > address space > [ 3972.384031] Failing address: TEID: 0887 > [ 3972.384032] Fault in home space mode while using kernel ASCE. > [ 3972.384033] AS:744cc007 R3:0001fffd0007 S:0001fffd6000 > P:013d > [ 3972.384051] Oops: 0004 ilc:1 [#1] SMP > [ 3972.384053] Modules linked in: binfmt_misc(E) dm_crypt(E) lcs(E) ctcm(E) > fsm(E) algif_skcipher(E) af_alg(E) nfsv3(E) nfs_acl(E) nfs(E) lockd(E) > grace(E) sctp(E) quota_v2(E) quota_tree(E) ntfs(E) vfat(E) fat(E) overlay(E) > loop(E) dm_service_time(E) kvm(E) xt_CHECKSUM(E) xt_MASQUERADE(E) > xt_tcpudp(E) ip6t_rpfilter(E) ip6t_REJECT(E) nf_reject_ipv6(E) ipt_REJECT(E) > nf_reject_ipv4(E) xt_conntrack(E) ip6table_nat(E) ip6table_mangle(E) > ip6table_raw(E) tun(E) ip6table_security(E) bridge(E) iptable_nat(E) > nf_nat(E) stp(E) llc(E) iptable_mangle(E) iptable_raw(E) iptable_security(E) > nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) ip_set(E) nfnetlink(E) > ip6table_filter(E) ip6_tables(E) iptable_filter(E) ip_tables(E) x_tables(E) > sunrpc(E) dm_multipath(E) dm_mod(E) scsi_dh_rdac(E) scsi_dh_emc(E) > scsi_dh_alua(E) s390_trng(E) ghash_s390(E) prng(E) aes_s390(E) des_s390(E) > des_generic(E) sha512_s390(E) sha1_s390(E) vfio_ccw(E) vfio_mdev(E) mdev(E) > vfio_iommu_type1(E) vfio(E) eadm_sch(E) sch_fq_codel(E) > [ 3972.384076] sha256_s390(E) sha_common(E) pkey(E) zcrypt(E) rng_core(E) > autofs4(E) [last unloaded: dummy_del_mod] > [ 3972.384084] CPU: 17 PID: 45118 Comm: psvc-ioctl-bpf1 Tainted: G > OE 5.3.0-20190813.rc4.git0.8e72ac275c63.301.fc30.s390x+next #1 > [ 3972.384086] Hardware name: IBM 3906 M04 704 (LPAR) > [ 3972.384087] Krnl PSW : 0704c0018000 (0x0) > [ 3972.384090]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 > RI:0 EA:3 > [ 3972.384103] Krnl GPRS: 03e004c0fb90 0001f912abf0 > 000197b36800 > [ 3972.384104]000197b36810 0001 0001 > 000197b36810 > [ 3972.384105]736ae3a0 0001 0001f912abf0 > 000197b36800 > [ 3972.384106]00013aff 73c625a8 734a1486 > 03e004c0fbc8 > [ 3972.384110] Krnl Code:>: illegal > 0002: illegal > 0004: illegal > 0006: illegal > 0008: illegal > 000a: illegal > 000c: illegal > 000e: illegal > [ 3972.384116] Call Trace: > [ 3972.384122] ([<734a1486>] do_dentry_open+0x206/0x3c0) > [ 3972.384125] [<734b8c1e>] do_last+0x16e/0x918 > [ 3972.384126] [<734b944e>] path_openat+0x86/0x2b8 > [ 3972.384128] [<734baa64>] do_filp_open+0x7c/0xf8 > [ 3972.384129] [<734a3484>] do_sys_open+0x18c/0x258 > [ 3972.384134] [<73c457cc>] system_call+0xd8/0x2c8 > [ 3972.384135] Last Breaking-Event-Address: > [ 3972.384139] [<736ae3fa>] default_open_file+0x5a/0x78 > [ 3972.384141] Kernel panic - not syncing: Fatal exception: panic_on_oops > > Which correspond to: > fs/tracefs/inode.c:46 > static int default_open_file(struct inode *inode, struct file *filp) > 45 real_fops = dentry->d_fsdata; > 46 return real_fops->open(inode, filp); > > Commit which introduces the problem: > commit 757ff7244358406dd16a7f5f623ca40ed27c603c > Author: Matthew Garrett > AuthorDate: Wed Aug 7 17:07:19 2019 -0700 > Commit: James Morris > CommitDate: Fri Aug 9 22:23:58 2019 -0700 > > tracefs: Restrict tracefs when the kernel is locked down > > Tracefs may release mo
Re: linux-next: Tree for Aug 13
On Tue, Aug 13, 2019 at 07:19:24PM +1000, Stephen Rothwell wrote: > Merging security/next-testing (a4848e06f9af Merge branch 'next-lockdown' into > next-testing) > CONFLICT (content): Merge conflict in kernel/trace/trace_kprobe.c > CONFLICT (content): Merge conflict in fs/tracefs/inode.c > Applying: early_security_init() needs a stub got !CONFIG_SECURITY Hi all, next-lockdown causes panic on s390 when doing: cat /sys/kernel/debug/tracing/events/syscalls/sys_enter_read/id [ 3972.384027] Unable to handle kernel pointer dereference in virtual kernel address space [ 3972.384031] Failing address: TEID: 0887 [ 3972.384032] Fault in home space mode while using kernel ASCE. [ 3972.384033] AS:744cc007 R3:0001fffd0007 S:0001fffd6000 P:013d [ 3972.384051] Oops: 0004 ilc:1 [#1] SMP [ 3972.384053] Modules linked in: binfmt_misc(E) dm_crypt(E) lcs(E) ctcm(E) fsm(E) algif_skcipher(E) af_alg(E) nfsv3(E) nfs_acl(E) nfs(E) lockd(E) grace(E) sctp(E) quota_v2(E) quota_tree(E) ntfs(E) vfat(E) fat(E) overlay(E) loop(E) dm_service_time(E) kvm(E) xt_CHECKSUM(E) xt_MASQUERADE(E) xt_tcpudp(E) ip6t_rpfilter(E) ip6t_REJECT(E) nf_reject_ipv6(E) ipt_REJECT(E) nf_reject_ipv4(E) xt_conntrack(E) ip6table_nat(E) ip6table_mangle(E) ip6table_raw(E) tun(E) ip6table_security(E) bridge(E) iptable_nat(E) nf_nat(E) stp(E) llc(E) iptable_mangle(E) iptable_raw(E) iptable_security(E) nf_conntrack(E) nf_defrag_ipv6(E) nf_defrag_ipv4(E) ip_set(E) nfnetlink(E) ip6table_filter(E) ip6_tables(E) iptable_filter(E) ip_tables(E) x_tables(E) sunrpc(E) dm_multipath(E) dm_mod(E) scsi_dh_rdac(E) scsi_dh_emc(E) scsi_dh_alua(E) s390_trng(E) ghash_s390(E) prng(E) aes_s390(E) des_s390(E) des_generic(E) sha512_s390(E) sha1_s390(E) vfio_ccw(E) vfio_mdev(E) mdev(E) vfio_iommu_type1(E) vfio(E) eadm_sch(E) sch_fq_codel(E) [ 3972.384076] sha256_s390(E) sha_common(E) pkey(E) zcrypt(E) rng_core(E) autofs4(E) [last unloaded: dummy_del_mod] [ 3972.384084] CPU: 17 PID: 45118 Comm: psvc-ioctl-bpf1 Tainted: G OE 5.3.0-20190813.rc4.git0.8e72ac275c63.301.fc30.s390x+next #1 [ 3972.384086] Hardware name: IBM 3906 M04 704 (LPAR) [ 3972.384087] Krnl PSW : 0704c0018000 (0x0) [ 3972.384090]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:0 PM:0 RI:0 EA:3 [ 3972.384103] Krnl GPRS: 03e004c0fb90 0001f912abf0 000197b36800 [ 3972.384104]000197b36810 0001 0001 000197b36810 [ 3972.384105]736ae3a0 0001 0001f912abf0 000197b36800 [ 3972.384106]00013aff 73c625a8 734a1486 03e004c0fbc8 [ 3972.384110] Krnl Code:>: illegal 0002: illegal 0004: illegal 0006: illegal 0008: illegal 000a: illegal 000c: illegal 000e: illegal [ 3972.384116] Call Trace: [ 3972.384122] ([<734a1486>] do_dentry_open+0x206/0x3c0) [ 3972.384125] [<734b8c1e>] do_last+0x16e/0x918 [ 3972.384126] [<734b944e>] path_openat+0x86/0x2b8 [ 3972.384128] [<734baa64>] do_filp_open+0x7c/0xf8 [ 3972.384129] [<734a3484>] do_sys_open+0x18c/0x258 [ 3972.384134] [<73c457cc>] system_call+0xd8/0x2c8 [ 3972.384135] Last Breaking-Event-Address: [ 3972.384139] [<736ae3fa>] default_open_file+0x5a/0x78 [ 3972.384141] Kernel panic - not syncing: Fatal exception: panic_on_oops Which correspond to: fs/tracefs/inode.c:46 static int default_open_file(struct inode *inode, struct file *filp) 45 real_fops = dentry->d_fsdata; 46 return real_fops->open(inode, filp); Commit which introduces the problem: commit 757ff7244358406dd16a7f5f623ca40ed27c603c Author: Matthew Garrett AuthorDate: Wed Aug 7 17:07:19 2019 -0700 Commit: James Morris CommitDate: Fri Aug 9 22:23:58 2019 -0700 tracefs: Restrict tracefs when the kernel is locked down Tracefs may release more information about the kernel than desirable, so restrict it when the kernel is locked down in confidentiality mode by preventing open(). Signed-off-by: Matthew Garrett Reviewed-by: Steven Rostedt (VMware) Signed-off-by: James Morris --- fs/tracefs/inode.c | 40 +++- include/linux/security.h | 1 + security/lockdown/lockdown.c | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) Using default s390 config, where # CONFIG_SECURITY_LOCKDOWN_LSM is not set -- ⢋⡀⣀⠹ ⠠⣶⡦⠀ ⣿⣿⣿⠏⣴⣮⣴⣧⠈⢿⣿⣿
Re: [PATCH v3 1/3] kasan: support backing vmalloc space with real shadow memory
On Wed, Jul 31, 2019 at 05:15:48PM +1000, Daniel Axtens wrote: > Hook into vmalloc and vmap, and dynamically allocate real shadow > memory to back the mappings. > > Most mappings in vmalloc space are small, requiring less than a full > page of shadow space. Allocating a full shadow page per mapping would > therefore be wasteful. Furthermore, to ensure that different mappings > use different shadow pages, mappings would have to be aligned to > KASAN_SHADOW_SCALE_SIZE * PAGE_SIZE. > > Instead, share backing space across multiple mappings. Allocate > a backing page the first time a mapping in vmalloc space uses a > particular page of the shadow region. Keep this page around > regardless of whether the mapping is later freed - in the mean time > the page could have become shared by another vmalloc mapping. > > This can in theory lead to unbounded memory growth, but the vmalloc > allocator is pretty good at reusing addresses, so the practical memory > usage grows at first but then stays fairly stable. > > This requires architecture support to actually use: arches must stop > mapping the read-only zero page over portion of the shadow region that > covers the vmalloc space and instead leave it unmapped. > > This allows KASAN with VMAP_STACK, and will be needed for architectures > that do not have a separate module space (e.g. powerpc64, which I am > currently working on). It also allows relaxing the module alignment > back to PAGE_SIZE. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=202009 > Signed-off-by: Daniel Axtens > > --- Acked-by: Vasily Gorbik I've added s390 specific kasan init part and the whole thing looks good! Unfortunately I also had to make additional changes in s390 code, so s390 part would go later through s390 tree. But looking forward seeing your patch series upstream.