Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp8753pxb; Thu, 27 Jan 2022 13:47:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJzZPHywWZilfPno0q/cE8X7AT3kDe9fRJy6ZL8EkZvNMI5qlYP952wedOJK9MFsaFcvgLQV X-Received: by 2002:aa7:c0d4:: with SMTP id j20mr5308547edp.319.1643320021889; Thu, 27 Jan 2022 13:47:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643320021; cv=none; d=google.com; s=arc-20160816; b=pZYNkYyFqWymVd0KeDuzRd70DScCkO2TcKdScqYdTL+5IEJKw4qGsPRybqRpZFGlZz qYvvyWCMUzEgg4ZV6BkHAIf00XWrTD9pO36PcWl7N71ZeSQbb+EKVEN/snxmhFUEPgO6 lXiuAfG4VbPeFO7ou4pqZyYO+lGGv3c7j/svNn5sdSfi4zHQjNWWc6vSGSCnrToeFCwk pRG9Ba8Uq5Aj53U6H8gb+Aijo2AGgB+WVaqGDaaE9Ey7mDZS0OdpFCyBK/tbSC00RLOg lp4DlxNVMnpY3vL4bRay8cFA88rXJN/lSOUxk5K7eEf2Bfrbsf5H+gPfH+tIH85pDfbt AtSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=AnBkWt5deZuhC1Fz3DpTdYww8NN67IJRqQ6qQw7zoh0=; b=0ulnrX33RrUtLXV1/2zgcHTn94g32DQnnzlLoUs723LZNEVMY4QEs5UxQIn0DSGoR5 gIBS5zYouEt6YB0y1jebWk1zAskjJNR71D5ATT7tPYQ16QQn4v1lK+0kYc7RguKj5nu8 gnMR7z0TGcwJadaQXzH0TUI4bQ2xE79xspp3eUlXcdHqdO50txZkoSDkCFeQgBMWW63z uiGCQVXLPiCmSM+7QLxDkh9FL/3FKYY0dFHrvKYVGhwUUKyyHFwtN1qp0ejl+WIcxZae +mYGcxlBUU+tsO/6RxFrte5iXm8HJqzcQkrk64/r2svGMahFsRfR+2SP0rj5qWo0YCMS suDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QfZ+Fu5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u8si1912491eds.8.2022.01.27.13.46.37; Thu, 27 Jan 2022 13:47:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QfZ+Fu5t; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236148AbiA0MDv (ORCPT + 99 others); Thu, 27 Jan 2022 07:03:51 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:41450 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229801AbiA0MDu (ORCPT ); Thu, 27 Jan 2022 07:03:50 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 18DF8B82235 for ; Thu, 27 Jan 2022 12:03:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFAB8C36AE2 for ; Thu, 27 Jan 2022 12:03:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643285027; bh=xGDXqFT+sTURaSr+QBu/K1uI9pZRK5lLohJEBpgGPlo=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QfZ+Fu5tzdQICZMBq8TgJQ8neP7I0JjPfwsRyQmclfpoNwhSV6Cik6g+/46N4Ehh4 sqrNbE+Fjm0rERj8BG74BDNBaVv1uQchlKQ8KK0GeyixGy8P+Og/AGpek+5vW9pWE9 5jX7Gr3cu+2pVtpXgABq73ZUAay0FiDhZFbLm2v2NJYm28BF6+fFXIXTdcy0UYlYSV /LX4d1dNGEaseRHV+qbqkQdUJMn2KB8adRlQLQhyXHTBOaVs4nIC1xBJhHHiUbwFXk 3KpY8YaQ8z73i6levRBtoZT/+8K4ozahHhKFxnhzW2EyLJU8WFkexBhVeTQr02q4e4 QqzVM6j0juYWw== Received: by mail-wm1-f45.google.com with SMTP id r2-20020a1c2b02000000b0034f7b261169so1715413wmr.2 for ; Thu, 27 Jan 2022 04:03:47 -0800 (PST) X-Gm-Message-State: AOAM531ieIiFjFKv82XIn3Sdu3HxFgzT7v2t4AFZtUC2+xOSL/eH51OZ wUKwGUWPjvoQkNOVfON/bkkPV/B9lDh6Zsk80jY= X-Received: by 2002:a1c:a90d:: with SMTP id s13mr2962114wme.32.1643285025905; Thu, 27 Jan 2022 04:03:45 -0800 (PST) MIME-Version: 1.0 References: <944D10DA-8200-4BA9-8D0A-3BED9AA99F82@linux.ibm.com> <20220124114548.30241947@gandalf.local.home> <0fa0daec-881a-314b-e28b-3828e80bbd90@linux.alibaba.com> In-Reply-To: From: Ard Biesheuvel Date: Thu, 27 Jan 2022 13:03:34 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [powerpc] ftrace warning kernel/trace/ftrace.c:2068 with code-patching selftests To: Mark Rutland Cc: Yinan Liu , Steven Rostedt , "open list:LINUX FOR POWERPC (32-BIT AND 64-BIT)" , Sachin Sant , Linux Kernel Mailing List , Kees Cook Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 27 Jan 2022 at 12:47, Mark Rutland wrote: > > [adding LKML so this is easier for others to find] > > If anyone wants to follow the thread from the start, it's at: > > https://lore.kernel.org/linuxppc-dev/944D10DA-8200-4BA9-8D0A-3BED9AA99F82@linux.ibm.com/ > > Ard, I was under the impression that the 32-bit arm kernel was (virtually) > relocatable, but I couldn't spot where, and suspect I'm mistaken. Do you know > whether it currently does any boot-time dynamic relocation? > No, it does not. .. > > Steve pointed me at this thread over IRC -- I'm not subscribed to this list so > > grabbed a copy of the thread thus far via b4. > > > > On Tue, Jan 25, 2022 at 11:20:27AM +0800, Yinan Liu wrote: > > > > Yeah, I think it's time to opt in, instead of opting out. > > > > I agree this must be opt-in rather than opt-out. > > > > However, I think most architectures were broken (in at least some > > configurations) by commit: > > > > 72b3942a173c387b ("scripts: ftrace - move the sort-processing in ftrace_init") > > > > ... and so I don't think this fix is correct as-is, and we might want to revert > > that or at least mark is as BROKEN for now. > > Steve asked for a bit more detail on IRC, so the below is an attempt to explain > what's actually going on here. > > The short answer is that relocatable kernels (e.g. those with KASLR support) > need to handle the kernel being loaded at (somewhat) arbitrary virtual > addresses. Even where code can be position-independent, any pointers in the > kernel image (e.g. the contents of the mcount_loc table) need to be updated to > account for the specific VA the kernel was loaded at -- arch code does this > early at boot time by applying dynamic (ELF) relocations. > These architectures use place-relative extables for the same reason: place relative references are resolved at build time rather than at runtime during relocation, making a build time sort feasible. arch/alpha/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/arm64/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/ia64/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/parisc/include/asm/uaccess.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/powerpc/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/riscv/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/s390/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE arch/x86/include/asm/extable.h:#define ARCH_HAS_RELATIVE_EXTABLE Note that the swap routine becomes something like the below, given that the relative references need to be fixed up after the entry changes place in the sorted list. static void swap_ex(void *a, void *b, int size) { struct exception_table_entry *x = a, *y = b, tmp; int delta = b - a; tmp = *x; x->insn = y->insn + delta; y->insn = tmp.insn - delta; ... } As a bonus, the resulting footprint of the table in the image is reduced by 8x, given that every 8 byte pointer has an accompanying 24 byte RELA record, so we go from 32 bytes to 4 bytes for every call to __gnu_mcount_mc. > Walking through how we get there, considering arm64 specifically: > > 1) When an object is created with traceable functions: > > The compiler records the addresses of the callsites into a section. Those > are absolute virtual addresses, but the final virtual addresses are not yet > known, so the compiler generates ELF relocations to tell the linker how to > fill these in later. > > On arm64, since the compiler doesn't know the final value yet, it fills the > actual values with zero for now. Other architectures might do differently. > > For example, per `objdump -r init/main.o`: > > | RELOCATION RECORDS FOR [__patchable_function_entries]: > | OFFSET TYPE VALUE > | 0000000000000000 R_AARCH64_ABS64 .text+0x0000000000000028 > | 0000000000000008 R_AARCH64_ABS64 .text+0x0000000000000088 > | 0000000000000010 R_AARCH64_ABS64 .text+0x00000000000000e8 > > 2) When vmlinux is linked: > > The linker script accumulates the callsite pointers from all the object > files into the mcount_loc table. Since the kernel is relocatable, the > runtime absolute addresses are still not yet known, but the offset relative > to the kernel base is known, and so the linker consumes the absolute > relocations created by the compiler and generates new relocations relative > to the kernel's default load address so that these can be adjusted at boot > time. > > On arm64, those are RELA and/or RELR relocations, which our vmlinux.lds.S > accumulates those into a location in the initdata section that the kernel > can find at boot time: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/vmlinux.lds.S?h=v5.17-rc1#n252 > > For example, per `objdump -s vmlinux -j .rela.dyn`: > > | vmlinux: file format elf64-littleaarch64 > | > | Contents of section .rela.dyn: > | ffff800009beb0d0 b01a0b09 0080ffff 03040000 00000000 ................ > | ffff800009beb0e0 00600b09 0080ffff b81a0b09 0080ffff .`.............. > | ffff800009beb0f0 03040000 00000000 80710b09 0080ffff .........q...... > | ffff800009beb100 e8670b09 0080ffff 03040000 00000000 .g.............. > | ffff800009beb110 48e60809 0080ffff f0670b09 0080ffff H........g...... > | ffff800009beb120 03040000 00000000 ec190b09 0080ffff ................ > > Each of the relocations in .rela.dyn consists of 3 64-bit little-endian > values: > > * The first (e.g. 0xffff8000090b1ab0) is the VA of the pointer to write to, > assuming the kernel's default load address (e.g. 0xffff800008000000). An > offset must be applied to this depending on where the kernel was actually > loaded relative to that default load address. > > * The second (e.g. 0x0000000000000403) is the ELF relocation type (1027, AKA > R_AARCH64_RELATIVE). > > * The third, (e.g. 0xffff8000090b6000) is the VA to write to the pointer, > assuming the kernel's default load address (e.g. 0xffff800008000000). An > offset must be applied to this depending on where the kernel was actually > loaded relative to that default load address. > > The AArch64 ELF spec defines our relocations, e.g. > > https://github.com/ARM-software/abi-aa/blob/main/aaelf64/aaelf64.rst#5712dynamic-relocations > > In general, relocations might depend on the default value that was > initialized (e.g. OR-ing in high bits assuming the low bits are already > correct). I'm not sure if any of the architectures we support uses such > relocations for relocatable kernels, but they could in theory. > > 3) When the vmlinux mcount_loc table is sorted: > > The sorttable code sorts the data values within the mcount_loc table, but it > doesn't read the relocations to resolve the VA of each entry, nor does it > update the relocations when it swaps entries. > > For arm64, where entries were all initialized to zero at compile time and > have not been updated since, the sort does nothing. When the relocations are > applied later, the result will be an unsorted table. > > In general, where sorting *does* swap entries, it doesn't update the > corresponding relocations. Where entries A and B get swapped by the sort, > any relocation(s) for entry A will apply to the location of entry B, and > vice-versa. Depending on the specific relocation used, that may or may not > be a problem (e.g. the example of OR-ing in high bits would be broken). > > 4) When relocations are applied at boot time: > > On arm64, to account for KASLR or any other virtual offset we might have to > account for, we apply the relocations early in boot in the > __relocate_kernel() assembly function: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/arm64/kernel/head.S?h=v5.17-rc1#n753 > > Since we didn't update the relocations during the build-time sort, and the > mcount_loc table was not sorted to begin with, applying all the relocations > for the mcount_loc table results in an unsorted table. Hence things go > wrong later for any code relying on this having been sorted already. > > IIUC the s390 and powerpc cases are structurally similar, though the fine > detail might differ a bit. > > I'm not sure how x86 works here; AFAICT the relocations are performed during > decompression, but it looks like there's some special build-time processing > associated with that, and the vmlinux doesn't contain standard ELF relocations. > > Kees, IIUC you added the x86_64 support there, can you shed any light on if/how > this works on x86? > > > > In practice, building v5.17-rc1 with CONFIG_FTRACE_SORT_STARTUP_TEST=y I see > the following splat: > > | ------------[ cut here ]------------ > | [14] unknown_bootoption+0x4/0x1c8 at ffffa1a861200738 is not sorted with trace_initcall_finish_cb+0x4/0x6c at ffffa1a85f8130b8 > | WARNING: CPU: 0 PID: 0 at kernel/trace/ftrace.c:6403 ftrace_process_locs.isra.0+0x370/0x440 > | Modules linked in: > | CPU: 0 PID: 0 Comm: swapper Not tainted 5.17.0-rc1 #2 > | Hardware name: linux,dummy-virt (DT) > | pstate: 600000c5 (nZCv daIF -PAN -UAO -TCO -DIT -SSBS BTYPE=--) > | pc : ftrace_process_locs.isra.0+0x370/0x440 > | lr : ftrace_process_locs.isra.0+0x370/0x440 > | sp : ffffa1a861b23d90 > | x29: ffffa1a861b23d90 x28: 0000000000000000 x27: 0000000000000000 > | x26: 0000000000000000 x25: 0000000000000000 x24: ffffa1a8612c0008 > | x23: ffffa1a861302ea8 x22: ffffa1a861374320 x21: 0000000000000001 > | x20: 000000000000e28f x19: 000000000000000e x18: ffffffffffffffff > | x17: 726f7320746f6e20 x16: 7369203833373030 x15: 3231363861316166 > | x14: 6666662074612038 x13: 3862303331386635 x12: 3861316166666666 > | x11: 2074612063367830 x10: ffffa1a861b4b1d0 x9 : ffffa1a861b4b1d0 > | x8 : 00000000ffffefff x7 : ffffa1a861ba31d0 x6 : ffffa1a861ba31d0 > | x5 : 000000000000bff4 x4 : 0000000000000000 x3 : 0000000000000000 > | x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffa1a861b33e80 > | Call trace: > | ftrace_process_locs.isra.0+0x370/0x440 > | ftrace_init+0xb4/0x15c > | start_kernel+0x40c/0x6d4 > | __primary_switched+0xc0/0xc8 > | ---[ end trace 0000000000000000 ]--- > > Where those symbol adddresses are: > > | [mark@lakrids:~/src/linux]% usekorg 11.1.0 aarch64-linux-objdump -t vmlinux | grep -w unknown_bootoption > | ffff800009a00734 l F .init.text 00000000000001c8 unknown_bootoption > | [mark@lakrids:~/src/linux]% usekorg 11.1.0 aarch64-linux-objdump -t vmlinux | grep -w trace_initcall_finish_cb > | ffff8000080130b4 l F .text 0000000000000064 trace_initcall_finish_cb > > ... and are obviously not sorted. > > Further, the ftrace tests fail quite horribly, e.g. > > | # ./ftracetest > | === Ftrace unit tests === > | [1] Basic trace file check [PASS] > | [2] Basic test for tracers[ 38.979280] ------------[ ftrace bug ]------------ > | [ 38.980225] ftrace faulted on modifying > | [ 38.980227] [] set_reset_devices+0x8/0x24 > | [ 38.982078] Setting ftrace call site to call ftrace function > | [ 38.983160] ftrace record flags: 80000001 > | [ 38.983921] (1) > | [ 38.983921] expected tramp: ffffa8ebbcc2ba20 > | [ 38.985132] ------------[ cut here ]------------ > | [ 38.986013] WARNING: CPU: 3 PID: 265 at kernel/trace/ftrace.c:2068 ftrace_bug+0x284/0x2b4 > | [ 38.987649] Modules linked in: > | [ 38.988275] CPU: 3 PID: 265 Comm: ftracetest Tainted: G W 5.17.0-rc1-dirty #4 > | [ 38.989979] Hardware name: linux,dummy-virt (DT) > | [ 38.990916] pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) > | [ 38.992318] pc : ftrace_bug+0x284/0x2b4 > | [ 38.993111] lr : ftrace_bug+0x284/0x2b4 > | [ 38.993893] sp : ffff80000888bb00 > | [ 38.994566] x29: ffff80000888bb00 x28: 0000000000000020 x27: ffffa8ebbefcaa70 > | [ 38.996002] x26: ffffa8ebbefcb7e0 x25: ffffa8ebbf36723c x24: ffffa8ebbf364000 > | [ 38.997447] x23: 00000000fffffff2 x22: ffffa8ebbe38f6e8 x21: ffffa8ebbef29c78 > | [ 38.998885] x20: ffff5ec380080030 x19: ffffa8ebbef29000 x18: ffffffffffffffff > | [ 39.000316] x17: 0000000000000000 x16: 0000000000000000 x15: ffff80008888b827 > | [ 39.001758] x14: 0000000000000000 x13: 3032616232636362 x12: 6265386166666666 > | [ 39.003202] x11: 203a706d61727420 x10: ffffa8ebbef4b1d0 x9 : ffffa8ebbcd0dff0 > | [ 39.004645] x8 : 00000000ffffefff x7 : ffffa8ebbefa31d0 x6 : ffffa8ebbefa31d0 > | [ 39.006092] x5 : ffff5ec4befa29d8 x4 : 0000000000000000 x3 : 0000000000000000 > | [ 39.007538] x2 : 0000000000000000 x1 : ffff5ec380cf5580 x0 : 0000000000000022 > | [ 39.008982] Call trace: > | [ 39.009495] ftrace_bug+0x284/0x2b4 > | [ 39.010212] ftrace_replace_code+0x9c/0xa4 > | [ 39.011054] ftrace_modify_all_code+0xe4/0x14c > | [ 39.011964] arch_ftrace_update_code+0x18/0x24 > | [ 39.012874] ftrace_run_update_code+0x24/0x7c > | [ 39.013770] ftrace_startup+0xf8/0x1b0 > | [ 39.014541] register_ftrace_graph+0x2dc/0x324 > | [ 39.015449] graph_trace_init+0x6c/0x74 > | [ 39.016232] tracing_set_tracer+0xec/0x17c > | [ 39.017071] tracing_set_trace_write+0xe8/0x150 > | [ 39.017989] vfs_write+0xfc/0x2a0 > | [ 39.018671] ksys_write+0x74/0x100 > | [ 39.019370] __arm64_sys_write+0x28/0x3c > | [ 39.020172] invoke_syscall+0x50/0x120 > | [ 39.020947] el0_svc_common.constprop.0+0xdc/0x100 > | [ 39.021935] do_el0_svc+0x34/0xa0 > | [ 39.022620] el0_svc+0x28/0x80 > | [ 39.023253] el0t_64_sync_handler+0xa8/0x130 > | [ 39.024121] el0t_64_sync+0x1a0/0x1a4 > | [ 39.024874] ---[ end trace 0000000000000000 ]--- > | [PASS] > | [3] Basic trace clock test [FAIL] > | [4] Basic event tracing check [FAIL] > | [5] Change the ringbuffer size [FAIL] > > Thanks, > Mark. > > > > > More on that below. > > > > > > > > > > Something like this: > > > > > > > > -- Steve > > > > > > > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > > > > index c2724d986fa0..5256ebe57451 100644 > > > > --- a/arch/arm/Kconfig > > > > +++ b/arch/arm/Kconfig > > > > @@ -82,6 +82,7 @@ config ARM > > > > select HAVE_EBPF_JIT if !CPU_ENDIAN_BE32 > > > > select HAVE_CONTEXT_TRACKING > > > > select HAVE_C_RECORDMCOUNT > > > > + select HAVE_BUILDTIME_MCOUNT_SORT > > > > select HAVE_DEBUG_KMEMLEAK if !XIP_KERNEL > > > > select HAVE_DMA_CONTIGUOUS if MMU > > > > select HAVE_DYNAMIC_FTRACE if !XIP_KERNEL && !CPU_ENDIAN_BE32 && MMU > > > > IIUC the 32-bit arm kernel can be relocated at boot time, so I don't believe > > this is correct, and I believe any relocatable arm kernel has been broken since > > htat was introduced. > > > > > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > > > > index c4207cf9bb17..7996548b2b27 100644 > > > > --- a/arch/arm64/Kconfig > > > > +++ b/arch/arm64/Kconfig > > > > @@ -166,6 +166,7 @@ config ARM64 > > > > select HAVE_ASM_MODVERSIONS > > > > select HAVE_EBPF_JIT > > > > select HAVE_C_RECORDMCOUNT > > > > + select HAVE_BUILDTIME_MCOUNT_SORT > > > > select HAVE_CMPXCHG_DOUBLE > > > > select HAVE_CMPXCHG_LOCAL > > > > select HAVE_CONTEXT_TRACKING > > > > The arm64 kernel is relocatable by default, and has been broken since the > > build-time sort was introduced -- I see ftrace test failures, and the > > CONFIG_FTRACE_SORT_STARTUP_TEST screams at boot time. > > > > > > diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig > > > > index 7399327d1eff..46080dea5dba 100644 > > > > --- a/arch/x86/Kconfig > > > > +++ b/arch/x86/Kconfig > > > > @@ -186,6 +186,7 @@ config X86 > > > > select HAVE_CONTEXT_TRACKING_OFFSTACK if HAVE_CONTEXT_TRACKING > > > > select HAVE_C_RECORDMCOUNT > > > > select HAVE_OBJTOOL_MCOUNT if STACK_VALIDATION > > > > + select HAVE_BUILDTIME_MCOUNT_SORT > > > > Isn't x86 relocatable in some configurations (e.g. for KASLR)? > > > > I can't see how the sort works for those cases, because the mcount_loc entries > > are absolute, and either: > > > > * The sorted entries will get overwritten by the unsorted relocation entries, > > and won't be sorted. > > > > * The sorted entries won't get overwritten, but then the absolute address will > > be wrong since they hadn't been relocated. > > > > How does that work? > > > > Thanks, > > Mark. > > > > > > select HAVE_DEBUG_KMEMLEAK > > > > select HAVE_DMA_CONTIGUOUS > > > > select HAVE_DYNAMIC_FTRACE > > > > diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig > > > > index 752ed89a293b..7e5b92090faa 100644 > > > > --- a/kernel/trace/Kconfig > > > > +++ b/kernel/trace/Kconfig > > > > @@ -70,10 +70,16 @@ config HAVE_C_RECORDMCOUNT > > > > help > > > > C version of recordmcount available? > > > > +config HAVE_BUILDTIME_MCOUNT_SORT > > > > + bool > > > > + help > > > > + An architecture selects this if it sorts the mcount_loc section > > > > + at build time. > > > > + > > > > config BUILDTIME_MCOUNT_SORT > > > > bool > > > > default y > > > > - depends on BUILDTIME_TABLE_SORT && !S390 > > > > + depends on HAVE_BUILDTIME_MCOUNT_SORT > > > > help > > > > Sort the mcount_loc section at build time. > > > > > > LGTM. This will no longer destroy ftrace on other architectures. > > > Those arches that we are not sure about can test and enable this function by > > > themselves. > > > > > > > > > Best regards > > > --yinan > > >