[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ACCB0C73-9968-4DB8-9B8D-97560B32D8DD@fb.com>
Date: Fri, 21 Jan 2022 18:56:39 +0000
From: Song Liu <songliubraving@...com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
CC: Song Liu <song@...nel.org>, bpf <bpf@...r.kernel.org>,
Network Development <netdev@...r.kernel.org>,
LKML <linux-kernel@...r.kernel.org>,
"Alexei Starovoitov" <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
"Andrii Nakryiko" <andrii@...nel.org>,
Kernel Team <Kernel-team@...com>,
"Peter Zijlstra" <peterz@...radead.org>, X86 ML <x86@...nel.org>
Subject: Re: [PATCH v5 bpf-next 7/7] bpf, x86_64: use bpf_prog_pack allocator
> On Jan 21, 2022, at 10:29 AM, Alexei Starovoitov <alexei.starovoitov@...il.com> wrote:
>
> On Fri, Jan 21, 2022 at 9:53 AM Song Liu <songliubraving@...com> wrote:
>>>
>>> the header->size could be just below 2MB.
>>> I don't think kzalloc() can handle that.
>>
>> Technically, kzalloc can handle 2MB allocation via:
>> kzalloc() => kmalloc() => kmalloc_large() => kmalloc_order()
>>
>> But this would fail when the memory is fragmented. I guess we should use
>> kvmalloc() instead?
>
> Contiguous 2MB allocation?
Yeah, I tried that both kzalloc() and kvmalloc() could get 2MB memory.
I think kzalloc will fail when the memory is fragmented, but I haven't
confirmed it yet.
>
>>>
>>>> + if (!tmp_header) {
>>>> + bpf_jit_binary_free_pack(header);
>>>> + header = NULL;
>>>> + prog = orig_prog;
>>>> + goto out_addrs;
>>>> + }
>>>> + tmp_header->size = header->size;
>>>> + tmp_image = (void *)tmp_header + ((void *)image - (void *)header);
>>>
>>> Why is 'tmp_image' needed at all?
>>> The above math can be done where necessary.
>>
>> We pass both image and tmp_image to do_jit(), as it needs both of them.
>> I think maintaining a tmp_image variable makes the logic cleaner. We can
>> remove it from x64_jit_data, I guess.
>
> I'd remove from x64_jit_data. The recompute is cheap.
Will do.
>
> Speaking of tmp_header name... would be great to come up
> with something more descriptive.
> Here both tmp_header/tmp_image and header/image are used at the same time.
> My initial confusion with the patch was due to the name 'tmp'.
> The "tmp" prefix implies that the tmp_image will be used first
> and then it will become an image.
> But it's not the case.
> Maybe call it 'rw_header' and add a comment that 'header/image'
> are not writeable directly ?
> Or call it 'poke_header' ?
> Other ideas?
I think rw_header/rw_image is good. poke_header is confusing, as we will
text_poke "header".
Thanks,
Song
Powered by blists - more mailing lists