mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Indu Bhagat <indu.bhagat@oracle.com>
To: Puranjay Mohan <puranjay@kernel.org>, Weinan Liu <wnliu@google.com>
Cc: irogers@google.com, joe.lawrence@redhat.com, jpoimboe@kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-toolchains@vger.kernel.org,
	live-patching@vger.kernel.org, mark.rutland@arm.com,
	peterz@infradead.org, roman.gushchin@linux.dev,
	rostedt@goodmis.org, will@kernel.org
Subject: Re: [PATCH 0/8] unwind, arm64: add sframe unwinder for kernel
Date: Thu, 27 Feb 2025 22:47:04 -0800	[thread overview]
Message-ID: <9debc20e-1460-4400-a9ca-50b407948976@oracle.com> (raw)
In-Reply-To: <mb61peczjybg7.fsf@kernel.org>

On 2/27/25 1:38 AM, Puranjay Mohan wrote:
> Indu Bhagat <indu.bhagat@oracle.com> writes:
> 
>> On 2/26/25 2:23 AM, Puranjay Mohan wrote:
>>> Indu Bhagat <indu.bhagat@oracle.com> writes:
>>>
>>>> On 2/25/25 3:54 PM, Weinan Liu wrote:
>>>>> On Tue, Feb 25, 2025 at 11:38 AM Indu Bhagat <indu.bhagat@oracle.com> wrote:
>>>>>>
>>>>>> On Mon, Feb 10, 2025 at 12:30 AM Weinan Liu <wnliu@google.com> wrote:
>>>>>>>> I already have a WIP patch to add sframe support to the kernel module.
>>>>>>>> However, it is not yet working. I had trouble unwinding frames for the
>>>>>>>> kernel module using the current algorithm.
>>>>>>>>
>>>>>>>> Indu has likely identified the issue and will be addressing it from the
>>>>>>>> toolchain side.
>>>>>>>>
>>>>>>>> https://sourceware.org/bugzilla/show_bug.cgi?id=32666
>>>>>>>
>>>>>>> I have a working in progress patch that adds sframe support for kernel
>>>>>>> module.
>>>>>>> https://github.com/heuza/linux/tree/sframe_unwinder.rfc
>>>>>>>
>>>>>>> According to the sframe table values I got during runtime testing, looks
>>>>>>> like the offsets are not correct .
>>>>>>>
>>>>>>
>>>>>> I hope to sanitize the fix for 32666 and post upstream soon (I had to
>>>>>> address other related issues).  Unless fixed, relocating .sframe
>>>>>> sections using the .rela.sframe is expected to generate incorrect output.
>>>>>>
>>>>>>> When unwind symbols init_module(0xffff80007b155048) from the kernel
>>>>>>> module(livepatch-sample.ko), the start_address of the FDE entries in the
>>>>>>> sframe table of the kernel modules appear incorrect.
>>>>>>
>>>>>> init_module will apply the relocations on the .sframe section, isnt it ?
>>>>>>
>>>>>>> For instance, the first FDE's start_addr is reported as -20564. Adding
>>>>>>> this offset to the module's sframe section address (0xffff80007b15a040)
>>>>>>> yields 0xffff80007b154fec, which is not within the livepatch-sample.ko
>>>>>>> memory region(It should be larger than 0xffff80007b155000).
>>>>>>>
>>>>>>
>>>>>> Hmm..something seems off here.  Having tested a potential fix for 32666
>>>>>> locally, I do not expect the first FDE to show this symptom.
>>>>>>
>>>>>
>>>
>>> Hi,
>>>
>>> Sorry for not responding in the past few days.  I was on PTO and was
>>> trying to improve my snowboarding technique, I am back now!!
>>>
>>> I think what we are seeing is expected behaviour:
>>>
>>>    | For instance, the first FDE's start_addr is reported as -20564. Adding
>>>    | this offset to the module's sframe section address (0xffff80007b15a040)
>>>    | yields 0xffff80007b154fec, which is not within the livepatch-sample.ko
>>>    | memory region(It should be larger than 0xffff80007b155000).
>>>
>>>
>>> Let me explain using a __dummy__ example.
>>>
>>> Assume Memory layout before relocation:
>>>
>>>    | Address | Element                                 | Relocation
>>>    |  ....   | ....                                    |
>>>    |   60    | init_module (start address)             |
>>>    |   72    | init_module (end address)               |
>>>    |  ....   | .....                                   |
>>>    |   100   | Sframe section header start address     |
>>>    |   128   | First FDE's start address               | RELOC_OP_PREL -> Put init_module address (60) - current address (128)
>>>
>>> So, after relocation First FDE's start address has value 60 - 128 = -68
>>>
>>
>> For SFrame FDE function start address is :
>>
>> "Signed 32-bit integral field denoting the virtual memory address of the
>> described function, for which the SFrame FDE applies.  The value encoded
>> in the ‘sfde_func_start_address’ field is the offset in bytes of the
>> function’s start address, from the SFrame section."
>>
>> So, in your case, after applying the relocations, you will get:
>> S + A - P = 60 - 128 = -68
>>
>> This is the distance of the function start address (60) from the current
>> location in SFrame section (128)
>>
>> But what we intend to store is the distance of the function start
>> address from the start of the SFrame section.  So we need to do an
>> additional step for SFrame FDE:  Value += r_offset
> 
> Thanks for the explaination, now it makes sense.
> 
> But I couldn't find a relocation type in AARCH64 that does this extra +=
> r_offset along with PREL32.
> 
> The kernel's module loader is only doing the R_AARCH64_PREL32 which is
> why we see this issue.
> 
> How is this working even for the kernel itself? or for that matter, any
> other binary compiled with sframe?
> 

For the usual executables or shared objects, the calculations are 
applied by ld.bfd at this time.  Hence, the issue manifests in 
relocatable files.

>  From my limited undestanding, the way to fix this would be to hack the
> relocator to do this additional step while relocating .sframe sections.
> Or the 'addend' values in .rela.sframe should already have the +r_offset
> added to it, then no change to the relocator would be needed.
> 

Of the two, adjusting the addend values in .rela.sframe may be a 
reasonable way to go about it.  Let me try it out in GAS and ld.bfd.

>> -68 + 28 = -40
>> Where 28 is the r_offset in the RELA.
>>
>> So we really expect a -40 in the relocated SFrame section instead of -68
>> above.  IOW, the RELAs of SFrame section will need an additional step
>> after relocation.
>>
> 
> Thanks,
> Puranjay


  reply	other threads:[~2025-02-28  6:47 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 21:33 Weinan Liu
2025-01-27 21:33 ` [PATCH 1/8] unwind: build kernel with sframe info Weinan Liu
2025-01-30  9:45   ` Prasanna Kumar T S M
2025-02-05  0:22   ` Indu Bhagat
2025-02-07 18:01     ` Josh Poimboeuf
2025-01-27 21:33 ` [PATCH 2/8] arm64: entry: add unwind info for various kernel entries Weinan Liu
2025-01-27 21:33 ` [PATCH 3/8] unwind: add sframe v2 header Weinan Liu
2025-01-30  9:53   ` Prasanna Kumar T S M
2025-02-07 18:05   ` Josh Poimboeuf
2025-01-27 21:33 ` [PATCH 4/8] unwind: Implement generic sframe unwinder library Weinan Liu
2025-01-30 10:22   ` Prasanna Kumar T S M
2025-01-30 10:29     ` Prasanna Kumar T S M
2025-02-02  6:27     ` Weinan Liu
2025-02-02  6:37       ` Weinan Liu
2025-01-27 21:33 ` [PATCH 5/8] unwind: arm64: Add sframe unwinder on arm64 Weinan Liu
2025-01-30 10:34   ` Prasanna Kumar T S M
2025-01-27 21:33 ` [PATCH 6/8] unwind: arm64: add reliable stacktrace support for arm64 Weinan Liu
2025-01-30 10:36   ` Prasanna Kumar T S M
2025-01-27 21:33 ` [PATCH 7/8] arm64: Define TIF_PATCH_PENDING for livepatch Weinan Liu
2025-01-30  9:54   ` Prasanna Kumar T S M
2025-02-27 12:10   ` Miroslav Benes
2025-01-27 21:33 ` [PATCH 8/8] arm64: Enable livepatch for ARM64 Weinan Liu
2025-01-30  9:55   ` Prasanna Kumar T S M
2025-01-31 16:08   ` Prasanna Kumar T S M
2025-02-03 15:16     ` Steven Rostedt
2025-01-28 15:35 ` [PATCH 0/8] unwind, arm64: add sframe unwinder for kernel Indu Bhagat
2025-01-29  7:23   ` Weinan Liu
2025-01-30 17:59 ` Song Liu
2025-01-30 18:34   ` Song Liu
2025-01-30 19:01     ` Roman Gushchin
2025-01-30 19:18       ` Song Liu
2025-02-04 14:49 ` Puranjay Mohan
2025-02-04 23:52   ` Puranjay Mohan
2025-02-06 15:02     ` Weinan Liu
2025-02-07 12:16       ` Puranjay Mohan
2025-02-07 17:52         ` Josh Poimboeuf
2025-02-10  8:30         ` Weinan Liu
2025-02-25  1:02           ` Weinan Liu
2025-02-25 18:13             ` Josh Poimboeuf
2025-02-25 23:01               ` Weinan Liu
2025-02-25 19:38             ` Indu Bhagat
2025-02-25 23:54               ` Weinan Liu
2025-02-26  0:22                 ` Indu Bhagat
2025-02-26 10:23                   ` Puranjay Mohan
2025-02-26 17:40                     ` Indu Bhagat
2025-02-27  9:38                       ` Puranjay Mohan
2025-02-28  6:47                         ` Indu Bhagat [this message]
2025-03-09 14:43                           ` Indu Bhagat
2025-02-12 23:32 ` Song Liu
2025-02-12 23:49   ` Josh Poimboeuf
2025-02-13  2:36     ` Song Liu
2025-02-13  2:45       ` Josh Poimboeuf
2025-02-13  7:25         ` Song Liu
2025-02-13  7:46           ` Puranjay Mohan
2025-02-13 19:40             ` Song Liu
2025-02-14  8:08               ` Josh Poimboeuf
2025-02-14 17:51                 ` Song Liu
2025-02-14 19:34                   ` Josh Poimboeuf
2025-02-14 22:04                     ` Song Liu
2025-02-14 22:33                       ` Josh Poimboeuf
2025-02-14 23:23                       ` Josh Poimboeuf
2025-02-18  4:38                         ` Song Liu
2025-02-18  6:37                           ` Josh Poimboeuf
2025-02-18 18:20                             ` Song Liu
2025-02-18 18:40                               ` Josh Poimboeuf
2025-02-19 17:44                                 ` Song Liu
2025-02-20  4:50                                   ` Song Liu
2025-02-20 18:22                                     ` Josh Poimboeuf
     [not found]                                       ` <CAPhsuW53DK2vFH-BZeUYN-eythX3NQEbcxrYf6jvBDtDmctRgw@mail.gmail.com>
2025-02-25  0:13                                         ` Song Liu
2025-02-13 23:22           ` Indu Bhagat
2025-02-13 23:47             ` Song Liu
2025-02-14  7:57             ` Puranjay Mohan
2025-02-14 17:39               ` Indu Bhagat
2025-02-14 18:41                 ` Indu Bhagat
2025-02-14 18:58                   ` Puranjay Mohan
2025-02-14 19:38                     ` Josh Poimboeuf
2025-02-14 19:42                       ` Josh Poimboeuf
2025-02-13  0:09   ` Indu Bhagat
2025-02-13  2:40     ` Song Liu
2025-02-13  2:52       ` Josh Poimboeuf
2025-02-13  7:26       ` Puranjay Mohan
2025-02-13  7:37         ` Song Liu
2025-02-13  7:53           ` Puranjay Mohan
2025-02-13 19:42             ` Song Liu
2025-02-13  8:37           ` Puranjay Mohan
2025-02-13 20:46             ` Song Liu
2025-02-13 22:21               ` Puranjay Mohan
2025-02-13 23:34                 ` Song Liu
2025-02-14  1:58                 ` Song Liu
2025-02-14  8:56                   ` Puranjay Mohan
2025-02-14 18:10                     ` Song Liu
2025-02-14 18:24                     ` Josh Poimboeuf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9debc20e-1460-4400-a9ca-50b407948976@oracle.com \
    --to=indu.bhagat@oracle.com \
    --cc=irogers@google.com \
    --cc=joe.lawrence@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-toolchains@vger.kernel.org \
    --cc=live-patching@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=peterz@infradead.org \
    --cc=puranjay@kernel.org \
    --cc=roman.gushchin@linux.dev \
    --cc=rostedt@goodmis.org \
    --cc=will@kernel.org \
    --cc=wnliu@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®