Subject: Re: [PATCH bpf-next 2/7] set_memory: introduce set_memory_[ro|x]_noalias

From: Peter Zijlstra <[email-masked]>
Date: Thu, 18 Nov 2021 19:58:54 +0100

On Thu, Nov 18, 2021 at 06:39:49PM +0000, Song Liu wrote:

> > You're going to have to do that anyway if you're going to write to the
> > directmap while executing from the alias.
> 
> Not really. If you look at current version 7/7, the logic is mostly 
> straightforward. We just make all the writes to the directmap, while 
> calculate offset from the alias. 

Then you can do the exact same thing but do the writes to a temp buffer,
no different.

> >> The BPF program could have up to 1000000 (BPF_COMPLEXITY_LIMIT_INSNS)
> >> instructions (BPF instructions). So it could easily go beyond a few 
> >> pages. Mapping the 2MB page all together should make the logic simpler. 
> > 
> > Then copy it in smaller chunks I suppose.
> 
> How fast/slow is the __text_poke routine? I guess we cannot do it thousands
> of times per BPF program (in chunks of a few bytes)? 

You can copy in at least 4k chunks since any 4k will at most use 2
pages, which is what it does. If that's not fast enough we can look at
doing bigger chunks.