mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: chenyuan  <chenyuan_fl@163.com>
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net,
	andrii@kernel.org, eddyz87@gmail.com, memxor@gmail.com,
	jolsa@kernel.org, linux-kernel@vger.kernel.org,
	"Yuan Chen" <chenyuan@kylinos.cn>
Subject: Re:Re: [PATCH bpf-next] bpf: Roll back freplace link state when bpf_arch_text_poke() fails
Date: Mon, 28 Sep 2026 17:08:39 +0800 (CST)	[thread overview]
Message-ID: <56074a5.8632.1a0e745ffa8.Coremail.chenyuan_fl@163.com> (raw)
In-Reply-To: <d675af17-6b59-44c1-b90f-8fb468cc1d63@linux.dev>


Thanks for the review. v2 adds the be8704ff07d2 Fixes tag and collects your Ack.









At 2026-09-25 14:05:59, "Leon Hwang" <leon.hwang@linux.dev> wrote:
>On 25/9/26 12:35, chenyuan_fl@163.com wrote:
>> From: Yuan Chen <chenyuan@kylinos.cn>
>> 
>> A freplace attach claims the target prog by bumping
>> tgt_prog->aux->freplace_link_cnt and setting tr->extension_prog.
>> bpf_arch_text_poke() then makes the extension take effect.  If the
>> poke fails, the claims are never released: the attach unwinds
>> through bpf_link_cleanup(), which clears link->prog, so
>> bpf_trampoline_unlink_prog() never runs.
>> 
>> Drop the link count under ext_mutex on the error path, and set
>> tr->extension_prog only after the poke succeeded.  The count is
>> still bumped before the poke: it blocks prog_array updates while
>> the entry is patched.
>> 
>> Fixes: d6083f040d5d ("bpf: Prevent tailcall infinite loop caused by freplace")
>
>Your commit msg also says the issue about tr->extension_prog.
>
>An extra Fixes tag for tr->extension_prog should be added.
>
>Fixes: be8704ff07d2 ("bpf: Introduce dynamic program extensions")
>
>The changes below lgtm:
>
>Acked-by: Leon Hwang <leon.hwang@linux.dev>
>
>Thanks,
>Leon
>
>> Suggested-by: Leon Hwang <leon.hwang@linux.dev>
>> Signed-off-by: Yuan Chen <chenyuan@kylinos.cn>
>> ---
>>  kernel/bpf/trampoline.c | 13 ++++++++++---
>>  1 file changed, 10 insertions(+), 3 deletions(-)
>> 
>> diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c
>> index da85bd580ef0..bf4ab0ac264e 100644
>> --- a/kernel/bpf/trampoline.c
>> +++ b/kernel/bpf/trampoline.c
>> @@ -973,10 +973,17 @@ static int __bpf_trampoline_link_prog(struct bpf_tramp_node *node,
>>  		err = bpf_freplace_link_tgt_prog(tgt_prog);
>>  		if (err)
>>  			return err;
>> +		err = bpf_arch_text_poke(tr->func.addr, BPF_MOD_NOP,
>> +					 BPF_MOD_JUMP, NULL,
>> +					 node->link->prog->bpf_func);
>> +		if (err) {
>> +			/* Undo the claim from bpf_freplace_link_tgt_prog(). */
>> +			guard(mutex)(&tgt_prog->aux->ext_mutex);
>> +			tgt_prog->aux->freplace_link_cnt--;
>> +			return err;
>> +		}
>>  		tr->extension_prog = node->link->prog;
>> -		return bpf_arch_text_poke(tr->func.addr, BPF_MOD_NOP,
>> -					  BPF_MOD_JUMP, NULL,
>> -					  node->link->prog->bpf_func);
>> +		return 0;
>>  	}
>>  	err = bpf_trampoline_add_prog(tr, node, cnt);
>>  	if (err)

      reply	other threads:[~2026-09-28  9:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <4669addf.91e8.1a0d2da9b9c.Coremail.chenyuan_fl@163.com>
2026-09-25  4:35 ` chenyuan_fl
2026-09-25  5:18   ` bot+bpf-ci
2026-09-25  6:05   ` Leon Hwang
2026-09-28  9:08     ` chenyuan [this message]

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=56074a5.8632.1a0e745ffa8.Coremail.chenyuan_fl@163.com \
    --to=chenyuan_fl@163.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=chenyuan@kylinos.cn \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=leon.hwang@linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=memxor@gmail.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

all inboxes | Powered by JetHome®