public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Marchevsky <davemarchevsky@meta.com>
To: Grant Seltzer Richman <grantseltzer@gmail.com>,
	Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf <bpf@vger.kernel.org>
Subject: Re: [Question] How can I get floating point registers on arm64
Date: Wed, 8 Mar 2023 22:54:29 -0500	[thread overview]
Message-ID: <fc8de596-aa8c-a92b-a288-d2bba2e08ff7@meta.com> (raw)
In-Reply-To: <CAO658oVAMKPZT0cbAUmB82nXrj1StyawEJFSLPbWi8ZPtrVY+Q@mail.gmail.com>

On 3/8/23 9:20 AM, Grant Seltzer Richman wrote:
> On Tue, Mar 7, 2023 at 7:28 PM Andrii Nakryiko
> <andrii.nakryiko@gmail.com> wrote:
>>
>> On Thu, Mar 2, 2023 at 11:06 AM Grant Seltzer Richman
>> <grantseltzer@gmail.com> wrote:
>>>
>>> Hi everyone,
>>>
>>> I'm writing a uprobe program that I'm attaching to a function in a go
>>> program on arm64. The function takes a float and as such loads the
>>> parameters via 64-bit floating point registers i.e. `D0`.
>>>
>>> However, the struct pt_regs context that uprobe programs have access
>>> to only has a single set of 31 64-bit registers. These appear to be
>>> the regular general purpose integer registers. My question is - how do
>>> I access the second set of registers? If this question doesn't make
>>> sense, am I misunderstanding how arm64 works?
>>>
>>
>> cc'ing Dave, as he was looking at this problem in the past (in the
>> context of accessing xmm registers, but similar problem).
>>
>> The conclusion was that we'd need to add a new helper (kfunc nowadays)
>> that would do it for BPF program. Few things to consider:
>>
>>   - designing generic enough interface to allow reading various
>> families of registers (FPU, XMM, etc) in some generic way
>>   - consider whether do platform-specific or platform-agnostic
>> interface (both possible)
>>   - and most annoyingly, we'd need to handle kernel potentially
>> modifying FPU state without (yet) restoring it. Dave investigated
>> this, and in some recent kernels it seems like kernel code doesn't
>> necessarily restore FPU state right after it's done with it, and
>> rather sets some special flag to restore FPU state as kernel exits to
>> user-space.
> 
> Thanks for this info Andrii! I think your first couple points are
> manageable but I'm not familiar with FPU context switching. Will read
> up on it, and Dave if you're willing to give some guidance I'd happily
> put in the work to get this helper introduced!
> 

Hi Grant,

I attempted to tackle this in a patchset a while back [0]. Had to abandon it to
focus on other things, please feel free to use it as a starting point.

Happy to elaborate on Andrii's 3rd point above, there's definitely some nuance
there that the series may not explain well. But need a day or so to page it back
in :). Will update this thread with details.

  [0]: https://lore.kernel.org/bpf/20220512074321.2090073-1-davemarchevsky@fb.com/

>>
>> Hopefully Dave can correct me and fill in details.
>>
>>
>>> Thanks so much,
>>> Grant

  reply	other threads:[~2023-03-09  3:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-02 19:05 [Question] How can I get floating point registers on arm64 Grant Seltzer Richman
2023-03-08  0:28 ` Andrii Nakryiko
2023-03-08 14:20   ` Grant Seltzer Richman
2023-03-09  3:54     ` Dave Marchevsky [this message]
2023-03-09 18:36       ` Grant Seltzer Richman

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=fc8de596-aa8c-a92b-a288-d2bba2e08ff7@meta.com \
    --to=davemarchevsky@meta.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=grantseltzer@gmail.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