From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19417318EF4 for ; Sun, 16 Aug 2026 20:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786911188; cv=none; b=XLPvz6Gid1VELvYSjBJt1ycyEFMK8Sxg205sOdIiZegia7HqbdkYUBTEOjek2avRs3LAVKvkJ8XJcvzve1vaCAKjqefi0uEIGTTHUQUG5MkvXA4n51tmL6F3tB2AQ8JwtBXnLZxt7EHh2ih1XGTlo+N8mj79jjIDE52q+IxNjkg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786911188; c=relaxed/simple; bh=eX+GUuAWrqVl6moqpAs1zEAHEY8Ip4ntN01n+ji+fII=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=WFWbth8vDtpjk7RcwITC4zScNFX5gu/WViNm5YT028LYBukmpSkubd3HpoUnhevfvuC9Ep5/Pvg2DjS1O80At13ByW7npB9U9AuG6hfc7ZxgcFv4K+v2f8mHWvpMN43ahOIwpPBHjcweYrs8rJGInDluEoqz53kNwaFu9r5mEk8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Hd5D4nEW; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hd5D4nEW" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-4798bea72f9so1716659f8f.1 for ; Sun, 16 Aug 2026 13:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1786911185; x=1787515985; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=nBTP7IvvyCuNS8293JpE8Ca2O7HvcIrZxpqclQA3eAI=; b=Hd5D4nEWq5tdjvl6s6fbCEDtuu/Cspvp0xiTCb59SCZS89Wm6Vc3MFWE6YCZ+CuPaW xKkIreudzHkrbPc3DiWvHifsprXMk8sur6T0xZMX8Odyo8r0o3NbbodXCaepyvBOB9Do tuTBV6lTEq9cDY5IYE13tk23DfQcvfkUspduziDRcSdsmrbQ5iA5irgJhrEJEm+xXBhx 8DT/3juhwDHO1pBfjsTpJZ/DI81mvhaMTwKO8MqNvCrKQkcr6ykidP3j/5XJ3EHIGhSa iey+YFKNGpQ8e8gxP/iOjUIJDaivnHcOVfGBGCfCCwjaPsMhZgoaZLryu0kRYlN7J5xw ntPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786911185; x=1787515985; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nBTP7IvvyCuNS8293JpE8Ca2O7HvcIrZxpqclQA3eAI=; b=MTKkPcCDEJOsbcJ8ZSbpbroM+eR2JpGdxJLMI7tmaZ0S/vSyXT9GznI0ZZnwL3kj5s 96hT0ArjqBthX5gJAXfL0eJF/fpLOvPKOVpUHvRAr5aYEMHs483vhdypU+2FS0i99cEy jSzO68FeRQBW0OUi7Ujtwz8VnPmRWx/C/oc8LJhtpQHSerduU0Vxpb5a1PNhBXdqoKLO SlI7zMDmytI6rHJXXbYSqNKi1mnKOs0hprdrz179Zd0rcZtGB+XYPCsxOLxdjdUyfdol N18du9DW1J3gSz4RMaRLEGs+1YU7iVD2JbiMquGyaCYmD9ydJB4O4QEgXlqdC6dCiYqK OQaA== X-Forwarded-Encrypted: i=1; AHgh+Rpi9pe/qoL+DVxMxPla12Pfg8rEgAcFEI3ZquEewwiZoKaMxPLqJuLk9tiBHmFmvsujn/Ju5WqZ44Gy7pU=@vger.kernel.org X-Gm-Message-State: AOJu0YxNtKTNpQpw2Mvy4bia73lvAuaiRE6wLKzCUBBGabCHpTPmrlPx Rm9i8EFxFRz0eJNezNE6bhEnOVrhtJatA0ixfUc46qQrybYwGmP3JMmZ X-Gm-Gg: AR+sD11QrZipsqBWG9qTuSm6gtwi2AuRfxUlJnZItliJbXwBE6nWxYACA3Dh0QWURfN T6yyZGIoZkwFqS5/8kSMrJV1LCx8j+YrFX41dfCnHt0gtB9IDSbnX2k1iYCb6qF8u39YKDRip/2 LYwT6lszJc25SabxS3PQorYzdCg1dN+PrQVYpZ9Pv2YYpvPitf/mIcsflP+BkHvjmiIlVCvKQBg b87evn2P7b7bQfMgZqPgGpPviI3tOqignpxVMMZhVfuBrQOj2A8Kap8eMBRM9HCH6HtrbVbNH6u mhFj1+6oAjNZbhi3HoHoEZrFueN/QG1bBmuCRYlrwoRuISkUb9dSMij7WlU7WrImZ0TmKzLxNeM XZbBSMrIhmSU7uGB/1l9MozqemrQzBE6nbYNYBHiNW5KS0Gudy7TuByAaX2bMVc3kRfLvqYRTgT rGmiZK62RgwhMCnYjO6fK3JgfJknBT3GXTtPjB2eTvnBLSzDo= X-Received: by 2002:a05:600c:4e45:b0:499:8fa7:dc52 with SMTP id 5b1f17b1804b1-4998fa7dde2mr193380695e9.16.1786911185055; Sun, 16 Aug 2026 13:13:05 -0700 (PDT) Received: from krava ([176.74.159.170]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4815f15b946sm27429947f8f.0.2026.08.16.13.13.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Aug 2026 13:13:04 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Sun, 16 Aug 2026 22:13:02 +0200 To: Mike Rapoport Cc: Jiri Olsa , Alexei Starovoitov , Andrii Nakryiko , Andy Lutomirski , Borislav Petkov , Daniel Borkmann , Dave Hansen , Eduard Zingerman , Ingo Molnar , Kumar Kartikeya Dwivedi , Peter Zijlstra , Song Liu , Thomas Gleixner , Emil Tsalapatis , John Fastabend , Martin KaFai Lau , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Leon Hwang Subject: Re: [PATCH bpf-next v3 4/5] bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable Message-ID: References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> <20260716-execmem-x86-rox-bpf-v0-v3-4-4e76158c01c5@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sun, Aug 16, 2026 at 11:57:35AM +0300, Mike Rapoport wrote: SNIP > From 14dff78529a9204408a5c14036954df5f2f76431 Mon Sep 17 00:00:00 2001 > From: "Mike Rapoport (Microsoft)" > Date: Sun, 16 Aug 2026 11:27:32 +0300 > Subject: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from > EXECMEM_MODULE_DATA > > Jiri Olsa reports slowdown of tracing_multi benchmark that allocates huge > number of trampolines [1]. > > The slowdown caused by extra protection changes in execmem_alloc_rw() and > execmem_free(). > > With ROX caches enabled, all execmem allocations except EXECMEM_MODULE_DATA > are ROX after the allocation. execmem_alloc_rw() temporarily sets them to > W+NX and execmem_free() resets them back to ROX. > > The only user of bpf_jit_alloc_exec_rw() is x86::arch_bpf_trampoline_size() > that only needs a temporary writable buffer in the modules address space. > > On x86 executable memory and module data are constrained to the same > address range, so x86::arch_bpf_trampoline_size() can directly use > execmem_alloc(EXECMEM_MODULE_DATA) > > Replace the call to bpf_jit_alloc_exec_rw() with a call to > execmem_alloc(EXECMEM_MODULE_DATA) in x86::arch_bpf_trampoline_size() and > drop bpf_jit_alloc_exec_rw() helper. > > Reported-by: Jiri Olsa > Link: https://lore.kernel.org/all/an8r7EODLIL-bZM3@krava > Fixes: f0334294a428 ("bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable") > Signed-off-by: Mike Rapoport (Microsoft) looks good, thanks serial_test_tracing_multi_bench_attach: found 55077 functions serial_test_tracing_multi_bench_attach: attached in 1.470s serial_test_tracing_multi_bench_attach: detached in 0.249s Tested-by: Jiri Olsa jirka > --- > arch/x86/net/bpf_jit_comp.c | 8 +++++--- > include/linux/filter.h | 1 - > kernel/bpf/core.c | 5 ----- > 3 files changed, 5 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c > index b2feec81e231..7d064d3e2788 100644 > --- a/arch/x86/net/bpf_jit_comp.c > +++ b/arch/x86/net/bpf_jit_comp.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -3706,15 +3707,16 @@ int arch_bpf_trampoline_size(const struct btf_func_model *m, u32 flags, > * > * We cannot use kvmalloc here, because we need image to be in > * module memory range. > - * Since it must be writable use bpf_jit_alloc_exec_rw(). > + * Since it must be writable use execmem_alloc(EXECMEM_MODULE_DATA) > + * that returns writable memory in the module address space. > */ > - image = bpf_jit_alloc_exec_rw(PAGE_SIZE); > + image = execmem_alloc(EXECMEM_MODULE_DATA, PAGE_SIZE); > if (!image) > return -ENOMEM; > > ret = __arch_prepare_bpf_trampoline(&im, image, image + PAGE_SIZE, image, > m, flags, tnodes, func_addr); > - bpf_jit_free_exec(image); > + execmem_free(image); > return ret; > } > > diff --git a/include/linux/filter.h b/include/linux/filter.h > index 32d5297c557e..14acb2455746 100644 > --- a/include/linux/filter.h > +++ b/include/linux/filter.h > @@ -1333,7 +1333,6 @@ bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr, > void bpf_jit_binary_free(struct bpf_binary_header *hdr); > u64 bpf_jit_alloc_exec_limit(void); > void *bpf_jit_alloc_exec(unsigned long size); > -void *bpf_jit_alloc_exec_rw(unsigned long size); > void bpf_jit_free_exec(void *addr); > void bpf_jit_free(struct bpf_prog *fp); > struct bpf_binary_header * > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c > index e2076667b245..1b89c18cf246 100644 > --- a/kernel/bpf/core.c > +++ b/kernel/bpf/core.c > @@ -1128,11 +1128,6 @@ void *bpf_jit_alloc_exec(unsigned long size) > return execmem_alloc(EXECMEM_BPF, size); > } > > -void *bpf_jit_alloc_exec_rw(unsigned long size) > -{ > - return execmem_alloc_rw(EXECMEM_BPF, size); > -} > - > void bpf_jit_free_exec(void *addr) > { > execmem_free(addr); > -- > 2.53.0 > > > > thanks, > > jirka > > -- > Sincerely yours, > Mike.