linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Song Liu <song@kernel.org>, Hari Bathini <hbathini@linux.ibm.com>
Cc: Song Liu <songliubraving@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	"bpf@vger.kernel.org" <bpf@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>
Subject: Re: [PATCH v4 4/5] powerpc/code-patching: introduce patch_instructions()
Date: Tue, 26 Sep 2023 06:51:18 +0000	[thread overview]
Message-ID: <2dffb52c-39f5-4d27-8a51-e5af643c1be4@csgroup.eu> (raw)
In-Reply-To: <CAPhsuW6p1+mqG_soSS8q_FFio7iHGtUyyDfH5cyXs_Py8f-Pmg@mail.gmail.com>



Le 26/09/2023 à 00:50, Song Liu a écrit :
> On Fri, Sep 8, 2023 at 6:28 AM Hari Bathini <hbathini@linux.ibm.com> wrote:
>>
>> patch_instruction() entails setting up pte, patching the instruction,
>> clearing the pte and flushing the tlb. If multiple instructions need
>> to be patched, every instruction would have to go through the above
>> drill unnecessarily. Instead, introduce function patch_instructions()
>> that sets up the pte, clears the pte and flushes the tlb only once per
>> page range of instructions to be patched. This adds a slight overhead
>> to patch_instruction() call while improving the patching time for
>> scenarios where more than one instruction needs to be patched.
>>
>> Signed-off-by: Hari Bathini <hbathini@linux.ibm.com>
> 
> I didn't see this one when I reviewed 1/5. Please ignore that comment.

If I remember correctry, patch 1 introduces a huge performance 
degradation, which gets then improved with this patch.

As I said before, I'd expect patch 4 to go first then get 
bpf_arch_text_copy() be implemented with patch_instructions() directly.

Christophe

> 
> [...]
> 
>> @@ -307,11 +312,22 @@ static int __do_patch_instruction_mm(u32 *addr, ppc_inst_t instr)
>>
>>          orig_mm = start_using_temp_mm(patching_mm);
>>
>> -       err = __patch_instruction(addr, instr, patch_addr);
>> +       while (len > 0) {
>> +               instr = ppc_inst_read(code);
>> +               ilen = ppc_inst_len(instr);
>> +               err = __patch_instruction(addr, instr, patch_addr);
> 
> It appears we are still repeating a lot of work here. For example, with
> fill_insn == true, we don't need to repeat ppc_inst_read().
> 
> Can we do this with a memcpy or memset like functions?
> 
>> +               /* hwsync performed by __patch_instruction (sync) if successful */
>> +               if (err) {
>> +                       mb();  /* sync */
>> +                       break;
>> +               }
>>
>> -       /* hwsync performed by __patch_instruction (sync) if successful */
>> -       if (err)
>> -               mb();  /* sync */
>> +               len -= ilen;
>> +               patch_addr = patch_addr + ilen;
>> +               addr = (void *)addr + ilen;
>> +               if (!fill_insn)
>> +                       code = code + ilen;
> 
> It took me a while to figure out what "fill_insn" means. Maybe call it
> "repeat_input" or something?
> 
> Thanks,
> Song
> 
>> +       }
>>
>>          /* context synchronisation performed by __patch_instruction (isync or exception) */
>>          stop_using_temp_mm(patching_mm, orig_mm);
>> @@ -328,16 +344,21 @@ static int __do_patch_instruction_mm(u32 *addr, ppc_inst_t instr)
>>          return err;
>>   }
>>

  reply	other threads:[~2023-09-26  6:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 13:27 [PATCH v4 0/5] powerpc/bpf: use BPF prog pack allocator Hari Bathini
2023-09-08 13:27 ` [PATCH v4 1/5] powerpc/bpf: implement bpf_arch_text_copy Hari Bathini
2023-09-25 22:01   ` Song Liu
2023-09-08 13:27 ` [PATCH v4 2/5] powerpc/bpf: implement bpf_arch_text_invalidate for bpf_prog_pack Hari Bathini
2023-09-08 13:27 ` [PATCH v4 3/5] powerpc/bpf: use bpf_jit_binary_pack_[alloc|finalize|free] Hari Bathini
2023-09-25 22:15   ` Song Liu
2023-09-08 13:27 ` [PATCH v4 4/5] powerpc/code-patching: introduce patch_instructions() Hari Bathini
2023-09-25 22:50   ` Song Liu
2023-09-26  6:51     ` Christophe Leroy [this message]
2023-09-28 20:09       ` Hari Bathini
2023-09-08 13:27 ` [PATCH v4 5/5] powerpc/bpf: use patch_instructions() Hari Bathini
2023-09-25  6:56 ` [PATCH v4 0/5] powerpc/bpf: use BPF prog pack allocator Hari Bathini

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=2dffb52c-39f5-4d27-8a51-e5af643c1be4@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=hbathini@linux.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=song@kernel.org \
    --cc=songliubraving@fb.com \
    /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;
as well as URLs for NNTP newsgroup(s).