public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: "Jose E. Marchesi" <jose.marchesi@oracle.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: GCC and binutils support for BPF V4 instructions
Date: Fri, 28 Jul 2023 20:01:31 +0200	[thread overview]
Message-ID: <87pm4bykxw.fsf@oracle.com> (raw)
In-Reply-To: <87v8e4x7cr.fsf@oracle.com> (Jose E. Marchesi's message of "Fri, 28 Jul 2023 19:40:20 +0200")


>> On 7/28/23 9:41 AM, Jose E. Marchesi wrote:
>>> Hello.
>>> Just a heads up regarding the new BPF V4 instructions and their
>>> support
>>> in the GNU Toolchain.
>>> V4 sdiv/smod instructions
>>>    Binutils has been updated to use the V4 encoding of these
>>>    instructions, which used to be part of the xbpf testing dialect used
>>>    in GCC.  GCC generates these instructions for signed division when
>>>    -mcpu=v4 or higher.
>>> V4 sign-extending register move instructions
>>> V4 signed load instructions
>>> V4 byte swap instructions
>>>    Supported in assembler, disassembler and linker.  GCC generates
>>> these
>>>    instructions when -mcpu=v4 or higher.
>>> V4 32-bit unconditional jump instruction
>>>    Supported in assembler and disassembler.  GCC doesn't generate
>>> that
>>>    instruction.
>>>    However, the assembler has been expanded in order to perform the
>>>    following relaxations when the disp16 field of a jump instruction is
>>>    known at assembly time, and is overflown, unless -mno-relax is
>>>    specified:
>>>      JA disp16  -> JAL disp32
>>>      Jxx disp16 -> Jxx +1; JA +1; JAL disp32
>>>    Where Jxx is one of the conditional jump instructions such as
>>> jeq,
>>>    jlt, etc.
>>
>> Sounds great. The above 'JA/Jxx disp16' transformation matches
>> what llvm did as well.
>
> Not by chance ;)
>
> Now what is pending in binutils is to relax these jumps in the linker as
> well.  But it is very low priority, compared to get these kernel
> selftests building and running.  So it will happen, but probably not
> anytime soon.

By the way, for doing things like that (further object transformations
by linkers and the like) we will need to have the ELF files annotated
with:

- The BPF cpu version the object was compiled for: v1, v2, v3, v4, and

- Individual flags specifying the BPF cpu capabilities (alu32, bswap,
  jmp32, etc) required/expected by the code in the object.

Note it is interesting to being able to denote both, for flexibility.

There are 32 bits available for machine-specific flags in e_flags, which
are commonly used for this purpose by other arches.  For BPF I would
suggest something like:

#define EF_BPF_ALU32  0x00000001
#define EF_BPF_JMP32  0x00000002
#define EF_BPF_BSWAP  0x00000004
#define EF_BPF_SDIV   0x00000008
#define EF_BPF_CPUVER 0x00FF0000

>>
>>> So I think we are done with this.  Please let us know if these
>>> instructions ever change.
>>> Relevant binutils bugzillas (all now resolved as fixed):
>>> * Make use of long range calls by relaxation (jal/gotol):
>>>    https://sourceware.org/bugzilla/show_bug.cgi?id=30690
>>> Relevant GCC bugzillas (all now resolved as fixed):
>>> * Make use of signed-load instructions:
>>>    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110782
>>>    * Make use of signed division/modulus:
>>>    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110783
>>> * Make use of signed mov instructions:
>>>    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110784
>>> * Make use of byte swap instructions:
>>>    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110786
>>> Salud!
>>> 

  reply	other threads:[~2023-07-28 18:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28 16:41 GCC and binutils support for BPF V4 instructions Jose E. Marchesi
2023-07-28 16:47 ` Alexei Starovoitov
2023-07-28 17:06   ` Jose E. Marchesi
2023-07-28 16:59 ` Yonghong Song
2023-07-28 17:40   ` Jose E. Marchesi
2023-07-28 18:01     ` Jose E. Marchesi [this message]
2023-07-28 23:49       ` Alexei Starovoitov
2023-07-29  8:29         ` Jose E. Marchesi
2023-07-29 17:56           ` Alexei Starovoitov
2023-07-30  4:54             ` Jose E. Marchesi
2023-07-30 16:12               ` Yonghong Song
2023-07-30 19:11                 ` Jose E. Marchesi
2023-07-30 16:53               ` Alexei Starovoitov
2023-07-30 21:06                 ` Jose E. Marchesi
2023-07-31 18:10                   ` Alexei Starovoitov

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=87pm4bykxw.fsf@oracle.com \
    --to=jose.marchesi@oracle.com \
    --cc=bpf@vger.kernel.org \
    --cc=yonghong.song@linux.dev \
    /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