From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 A7A1734E766 for ; Tue, 18 Aug 2026 20:51:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787086289; cv=none; b=k2WRb2DLP3QnoHgF9d8q7PKj8CvuSdT8twHh/XbPvoukXT2gQaUSJpbShJgU8OBRXCVLD9SYig0ROIm7OTPO/8k8x1IersNIWtWuUIF9KgBuLMqkCnoefeyKYMjzLIglwA8jvV4/O2DUaXKG3P+1XjvZA0PNQApRqsPaZCHjCKQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787086289; c=relaxed/simple; bh=JKuQcVGNjW0cuTSNBq9vhohu2cO3rx0iEZOmkcrHMLc=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jRzviJizbiH+UDgS3lMMdG7Ylm5ikbkU+9BbtXVb+qZ+3gHg9Z3dCw7C4F0HE5sU/bsKZOPXg1tmJiER6IwbXEWCay6r4DfXyohBRyfRJwxnJM0VZ6+pEu5IllsmqHKcbnUPOEieyiKEPYVOIl1uQaZP/DvBsPr/zEID1Rg+MK8= 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=imXOR2Mt; arc=none smtp.client-ip=209.85.128.41 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="imXOR2Mt" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-49954b88fffso3094845e9.0 for ; Tue, 18 Aug 2026 13:51:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787086286; x=1787691086; 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=dVpYOgo/c1ZhnFeYSDI9ttwce7VHO/ZgOUtefW2QhaM=; b=imXOR2MtYSLSBGJstFu2OPXZDBA6kmBlc+dojQ00Zk7Cn4+qLSXMkLlC/NrjQMl4WC dj85GxbtuOfrQlW1bWFLbRIN4xo+9NU2JACqnN2wuiM8rDN90115jLV9/u00D1tIwz1R 8ojFkMIm6yXehLNR+7wUSkCpoWIDbhr112evc8piTLMOd5y/28SOuoeAZt9ZAoSzJNRu QIlrRtjYufsNGPgziAY0mM1Hsvdulcyq+11zw15vO54w5KZhLmQ7M9qOwummsbmCJCjx Qvygu31XJo3ijhELo/2X1tmOBROJ1q0bwzfgl7guetsZlpvvKYxnC0iOQPQyx6SCvvWV MYEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787086286; x=1787691086; 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=dVpYOgo/c1ZhnFeYSDI9ttwce7VHO/ZgOUtefW2QhaM=; b=TP+rhWs9++YFS6uvsfSI9WIk3Vh8P6CHCH9UOFuuTvv+BNqTeWqKpNXUuoB4DsnU3l vua52tkeGIFUQDoEy3TWARxOcWvn8riPCxRHxFjDdXlZeW6YO+g7z+fDmZcqekMxs6Pg XFq2Dk23xJlE6FnH3MZcQ0cnppI3zCxzOCXjtxM2x61YK4zLzS7cGzTrXvjywPcQ5w5t ZCm6KE6+h/pN3XZ5KWfYiWS2GtbBEo1+zGmQZrgVvkRoueTkTmoliSGY2UNvSBbvGrnI 1aDQ/gXOLj0K1cJbfRM7fvpIjO9uuHVA+j6JL5DAaeXc6rYaVKeQ6avVtmV6zGeHQHsi RiBg== X-Forwarded-Encrypted: i=1; AHgh+RqEw4RN3zWQnzoajOdf50Gl/OeLUCmAUMNU2/KwMEDpoeu3G1kuGvP4cfqgMn7EEciO+u5ucAa70YLlCRs=@vger.kernel.org X-Gm-Message-State: AOJu0YypSU4FgxBAnf3MgMPMfbYHwb4CyotaQARGa6Yics7/FAY3cVTH bQm99fZslngF3UpZXr3Xxd/ELfF5FFN+qlcS4PW+qg4tcn4CGuF+kKL3 X-Gm-Gg: AR+sD11kEIYlXkNO9VfjOHs4U5jeWukswwV6YrEkn8t++7KyisjPtOXy4HQGA+YMF1z exX9NOcw/Djv/hPkgbwh4OpjHUOJ8CWuXyeTRtZXS6RXxSiQyL4NC2z/x4ULt5OK4TwgcgK1mZB llX8FMR1JTUeVIazBpGgoWwcXiB/OgJmrZsrIoHUGGjqLTH545RhRHa5DOAdZtH5OwQAFYJJhGT BT2p5zE4qHRa/Ud63D2/W1pHLBqK0KBULaPC9orBRrfVq/FmGs60QRSAK/+AG/fjL8Y5clpCttQ 50FxqTPsKdTHE4E9GshF59W6LM9nGGUsn66y+6Z1pxuwTuzuiuOjvR2hmJux/FqSRK/MWf6pO5a +rm81Vng/fB3bw3yPN8Tdf2AG4Vx3qnsuRclS0kz2hRl2LKbJl9Y/szhrph6dbVz8MX8MTy2mgU mmvb/23ahLKF7KLPDEUa2m6TGc+QBfNHLmFQ6MZ8SXKBKrfdlHjp9GK7UnRbHLvKEyHCoOqIsYF u+/wBJs4Q== X-Received: by 2002:a05:600c:3e15:b0:499:a5fc:2087 with SMTP id 5b1f17b1804b1-499a8f41991mr12761365e9.6.1787086285696; Tue, 18 Aug 2026 13:51:25 -0700 (PDT) Received: from krava (37-188-219-233.red.o2.cz. [37.188.219.233]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499aa09b199sm179205e9.0.2026.08.18.13.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 Aug 2026 13:51:25 -0700 (PDT) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Tue, 18 Aug 2026 22:51:16 +0200 To: Mike Rapoport Cc: Alexei Starovoitov , Andrii Nakryiko , Borislav Petkov , Daniel Borkmann , Dave Hansen , Eduard Zingerman , Ingo Molnar , Kumar Kartikeya Dwivedi , Song Liu , Thomas Gleixner , Emil Tsalapatis , "H. Peter Anvin" , John Fastabend , Martin KaFai Lau , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, Jiri Olsa Subject: Re: [PATCH] x86/bpf: make arch_bpf_trampoline_size allocate from EXECMEM_MODULE_DATA Message-ID: References: <20260818130510.3110054-1-rppt@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: <20260818130510.3110054-1-rppt@kernel.org> On Tue, Aug 18, 2026 at 04:05:10PM +0300, Mike Rapoport wrote: > From: "Mike Rapoport (Microsoft)" > > 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) Tested-by: Jiri Olsa thanks, jirak > --- > 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); > > base-commit: 07edbd8fe6416f45e9ba6b0edcd3e40770601ebc > -- > 2.53.0 >