> On Jan 21, 2022, at 10:29 AM, Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> wrote: > > On Fri, Jan 21, 2022 at 9:53 AM Song Liu <songliubraving@xxxxxx> 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