lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMEtUux+sj7o9=57JAaHvGJXJmfuyRKb+dFL_3ZdkmAoHy9XzA@mail.gmail.com>
Date:	Mon, 9 Jun 2014 12:25:21 -0700
From:	Alexei Starovoitov <ast@...mgrid.com>
To:	Daniel Borkmann <dborkman@...hat.com>
Cc:	"David S. Miller" <davem@...emloft.net>,
	Chema Gonzalez <chema@...gle.com>,
	Eric Dumazet <edumazet@...gle.com>,
	Network Development <netdev@...r.kernel.org>
Subject: Re: [PATCH net-next] net: filter: cleanup A/X name usage

On Sun, Jun 8, 2014 at 1:21 PM, Daniel Borkmann <dborkman@...hat.com> wrote:
> On 06/06/2014 11:46 PM, Alexei Starovoitov wrote:
>>
>> The macro 'A' used in internal BPF interpreter:
>>   #define A regs[insn->a_reg]
>> was easily confused with the name of classic BPF register 'A', since
>> 'A' would mean two different things depending on context.
>>
>> This patch is trying to clean up the naming and clarify its usage in the
>> following way:
>>
>> - A and X are names of two classic BPF registers
>>
>> - BPF_REG_A denotes internal BPF register R0 used to map classic register
>> A
>>    in internal BPF programs generated from classic
>>
>> - BPF_REG_X denotes internal BPF register R7 used to map classic register
>> X
>>    in internal BPF programs generated from classic
>>
>> - internal BPF instruction format:
>> struct sock_filter_int {
>>          __u8    code;           /* opcode */
>>          __u8    dst_reg:4;      /* dest register */
>>          __u8    src_reg:4;      /* source register */
>>          __s16   off;            /* signed offset */
>>          __s32   imm;            /* signed immediate constant */
>> };
>>
>> - BPF_X/BPF_K is 1 bit used to encode source operand of instruction
>> In classic:
>>    BPF_X - means use register X as source operand
>>    BPF_K - means use 32-bit immediate as source operand
>> In internal:
>>    BPF_X - means use 'src_reg' register as source operand
>>    BPF_K - means use 32-bit immediate as source operand
>>
>> Suggested-by: Chema Gonzalez <chema@...gle.com>
>> Signed-off-by: Alexei Starovoitov <ast@...mgrid.com>
>
>
> Acked-by: Daniel Borkmann <dborkman@...hat.com>
>
> You could also have mentioned in the changelog that you replace
> direct access to ctx pointer with CTX register, it's valid since
> we emit a mov from ARG1 to CTX at the beginning which contains
> ctx. Anyway, looks good to me.

Point taken. Will do more thorough documentation patch to
explain eBPF instruction set a bit better. Mainly to clarify encoding.
eBPF tried to be as close as possible to classic BPF, since I thought
it will make it easier to understand. That's why I reused A/X in names
and bits in opcode encoding.
In classic, A is accumulator and X is indeX. In eBPF I thought
calling destination register 'a_reg' made sense, since it would
indicate that this 'a_reg' is a register that is used as 'accumulator'
in the instruction. Like in "bpf_add R2, 5", R2 is Accumulator.
In "bpf_add R2, R3", R2  is Accumulator and R3 is indeX
and BPF_X bit in opcode indicates whether 'x_reg' field of the
instruction is used. Unfortunately that decision caused the whole
A/X naming confusion, that this patch is addressing.
src_reg and dst_reg are indeed better names.
The next patch of doc updates hopefully will make encoding clear too.

Thanks guys for reviewing.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ