From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A7B62E9EB1 for ; Mon, 10 Nov 2025 11:43:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775041; cv=none; b=UHzgWKOATLSj+mRjXwqQSlCPcu5T5fRlqIVZj8NCRVC7Wo22vkwpCV3RCqyg+rwrTX50kiERb3NcLzvQ3viPPvf+LUP2x4vmzkj9oln88BIHX+yegDaUxSrL0MoZ9Pal+Cljho2piNHgrTFqFdCqKxRgzsOmwb10wjKHatEGynw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762775041; c=relaxed/simple; bh=xWfcsybnbo7UjFAaPYX+npyNBSLMNc5Bg/Ml39RrJtw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uxXfWEX2SWTmMbq7VtNY3wIgpq+JdJN764zlmqDxpJ7A5SqZfyEn/1knR22pJG37hf9XXNmX0yzAHeyvc21g1R1cdD2VR+S9jYUxApZJ05qcI6Bl3XdpPsXqIZZO0zts7F3JqbIDuiAVtpfoaSlq8qE8vJqz4ea4/xiyvD6q+So= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=O/swysKd; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="O/swysKd" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762775035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YuKsG4Jk61M2ECo6srctORcvKOJg3Vp/W9Bx6gZdzsw=; b=O/swysKdnBbI+CzTc4MgeSho7tQxhhih+Bnzb3qlm57yqOlYt80LoNh7cdzFFCnsjkQ2by U6zkqyoNtv09Yrnqmfrvq88322QRUEioNlub040+8SaZTr9XLjXr3v6t6l3t1cqmhjlG+3 JPgKTWPiLjmehL/U5Tn4vC2nkiIS0I8= From: Menglong Dong To: Alexei Starovoitov , sjenning@redhat.com Cc: Peter Zijlstra , Menglong Dong , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , "David S. Miller" , David Ahern , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , jiang.biao@linux.dev, bpf , Network Development , LKML Subject: Re: [PATCH bpf-next] bpf,x86: do RSB balance for trampoline Date: Mon, 10 Nov 2025 19:43:25 +0800 Message-ID: <13884259.uLZWGnKmhe@7950hx> In-Reply-To: References: <20251104104913.689439-1-dongml2@chinatelecom.cn> <2388519.ElGaqSPkdT@7950hx> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" X-Migadu-Flow: FLOW_OUT On 2025/11/6 10:56, Alexei Starovoitov wrote: > On Wed, Nov 5, 2025 at 6:49=E2=80=AFPM Menglong Dong wrote: > > > > On 2025/11/6 09:40, Menglong Dong wrote: > > > On 2025/11/6 07:31, Alexei Starovoitov wrote: > > > > On Tue, Nov 4, 2025 at 11:47=E2=80=AFPM Menglong Dong wrote: [......] > > > > > > > > Here another idea... > > > > hack tr->func.ftrace_managed =3D false temporarily > > > > and use BPF_MOD_JUMP in bpf_arch_text_poke() > > > > when installing trampoline with fexit progs. > > > > and also do: > > > > @@ -3437,10 +3437,6 @@ static int __arch_prepare_bpf_trampoline(str= uct > > > > bpf_tramp_image *im, void *rw_im > > > > > > > > emit_ldx(&prog, BPF_DW, BPF_REG_6, BPF_REG_FP, -rbx_off); > > > > EMIT1(0xC9); /* leave */ > > > > - if (flags & BPF_TRAMP_F_SKIP_FRAME) { > > > > - /* skip our return address and return to parent */ > > > > - EMIT4(0x48, 0x83, 0xC4, 8); /* add rsp, 8 */ > > > > - } > > > > emit_return(&prog, image + (prog - (u8 *)rw_image)); > > > > > > > > Then RSB is perfectly matched without messing up the stack > > > > and/or extra calls. > > > > If it works and performance is good the next step is to > > > > teach ftrace to emit jmp or call in *_ftrace_direct() > > > > After the modification, the performance of fexit increase from > > 76M/s to 137M/s, awesome! >=20 > Nice! much better than double 'ret' :) > _ftrace_direct() next? Hi, all Do you think if it is worth to implement the livepatch with bpf trampoline by introduce the CONFIG_LIVEPATCH_BPF? It's easy to achieve it, I have a POC for it, and the performance of the livepatch increase from 99M/s to 200M/s according to my bench testing. The results above is tested with return-trunk disabled. With the return-trunk enabled, the performance decrease from 58M/s to 52M/s. The main performance improvement comes from the RSB, and the return-trunk will always break the RSB, which makes it has no improvement. The calling to per-cpu-ref get and put make the bpf trampoline based livepatch has a worse performance than ftrace based. Thanks! Menglong Dong >=20