From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 4183E3ADBB4; Thu, 16 Jul 2026 07:51:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188322; cv=none; b=HGb+jBZBaQi7dl9Ewe9DYIkKMxamINDhhm3sB7yPZk1/qk6E5oyDXiai6IoqkCT8BKHM6o1IqrNaRBR4DZ0OCpdqyWYCNovm+QH62Q8H3uNajIyWRk26akMGqf1Rm31obswKL70mhNNadV/91S4b7IW6vtgB8ehJ3LUMkElJXGc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188322; c=relaxed/simple; bh=KMdENao6bsuzOHvaCM1iOOpBS7g+cu2arpkSzIMQIts=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=NL2z+jU1Yk0IuYVMLSL+Gcdt7x9dHFqvWX+684jdZoVlpvwUhu1mCZNFykEMxMLcMTufBJKr0ZnV5diLF2SQsZ5N90rexwH+hFbZ8v6iBTfhjFibGI3CJ7/FWx+fLGB6ryPpyPYE9hJ5g0qzkLzsVJbE7PoIWjU+Akph3ohBp10= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=k2d4O1mV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="k2d4O1mV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 977211F000E9; Thu, 16 Jul 2026 07:51:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784188310; bh=iVpt+hTdXRr4Os4s4lc7gHEYSJh+NwOMWjHuKRC8z2o=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=k2d4O1mVI/GvrOYKJjFNghBetNfDaX4fwpcx9HfDdFS/d1HxUh+eYM+TWz2eC61cm 9qXhjxNJSgzipDaOReWmBomQwyrGuTazubkr+eJAOrXKCRxN6W8cBK49YMlKOmPyCd iqN69Jk/oRGS6Ybfg2HtN/cDR3hMZTP8r39SL1d4X6rWgJyD55g7t6hTa11dfT3E20 dXwVYz1u5cI366NUZLxOqAqdCtq2TFMyGRh5MLMXIb9r/mzXuYKYip2UmDyy2J/CL3 768jXv3n2unnxHG+F/lYn4Q9OFW1xctr0pcKuoZ/sRpJKYvNK5e0jpRvWBtavIPWAa Jw0TPLb/fWK6A== From: "Mike Rapoport (Microsoft)" Date: Thu, 16 Jul 2026 10:51:35 +0300 Subject: [PATCH bpf-next v3 1/5] bpf: dispatcher: allocate bpf_dispatcher->rw_image with vzalloc() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-execmem-x86-rox-bpf-v0-v3-1-4e76158c01c5@kernel.org> References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> In-Reply-To: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> To: 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 Cc: Emil Tsalapatis , Jiri Olsa , John Fastabend , Martin KaFai Lau , Mike Rapoport , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org X-Mailer: b4 0.16-dev bpf_dispatcher->rw_image is a temporary writable buffer that arch_prepare_bpf_dispatcher() fills and then copies into bpf_dispatcher->image using bpf_arch_text_copy(). The rel32 offsets emitted by emit_bpf_dispatcher() are calculated against ->image, so ->rw_image does not need to live in the module address range. Allocate ->rw_image with vzalloc() to avoid permissions dance when EXECMEM_BPF will be backed by ROX caches. Using vzalloc() rather than vmalloc() ensures that the memory that bpf_dispatcher_update() unconditionally copies into the executable buffer is zeroed, which is not ideal but still better than random memory returned by the existing bpf_jit_alloc_exec() or plain vmalloc(). Switching from bpf_jit_alloc_exec() to vzalloc() also saves a bit of space in the more scarce module address space. Signed-off-by: Mike Rapoport (Microsoft) Acked-by: Song Liu --- kernel/bpf/dispatcher.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/dispatcher.c b/kernel/bpf/dispatcher.c index ea2d60dc1fee..79f0c222c583 100644 --- a/kernel/bpf/dispatcher.c +++ b/kernel/bpf/dispatcher.c @@ -148,7 +148,10 @@ void bpf_dispatcher_change_prog(struct bpf_dispatcher = *d, struct bpf_prog *from, d->image =3D bpf_prog_pack_alloc(PAGE_SIZE, bpf_jit_fill_hole_with_zero,= false); if (!d->image) goto out; - d->rw_image =3D bpf_jit_alloc_exec(PAGE_SIZE); + /* d->rw_image doesn't need to be in module memory range, so we + * can use vzalloc. + */ + d->rw_image =3D vzalloc(PAGE_SIZE); if (!d->rw_image) { bpf_prog_pack_free(d->image, PAGE_SIZE); d->image =3D NULL; --=20 2.53.0 From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 57FAB377ABF; Thu, 16 Jul 2026 07:52:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188326; cv=none; b=OwHQ4qC1WnElb0Nq96PMsBX5QMcHqqrqNagaH5B4zfpzIJ//2bNSejXkqV4X9j3TnekNw+Y1GAkUHoPqYtmAq4wtEtAuU9ny+1U83B3GOXv1NfYLu9Zf6E3GCmpsap1ZHhoicr9sbABRTg7fdMCeUZjIIJg5rJN7Ma7ahZGim9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188326; c=relaxed/simple; bh=lmOTQ1n6pV1wNm2gFyUMrAEiIjEvHHmVFcF+U3WmfnY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=joBeAXlw1EboLouFiXdSCuMGPve0/VRFI/77eDn3EKjorvgrxypmyaTmnlBKiZgW1sr54rr4F1J2zqv1Dj1SnIOY3taqtK5Ob+u3gW0BG4ksff02jLImB6ZkqFlWrbaS1VvKDiQd5fAx8vKogfe+Xc8hiwZ61XTyK/BmfaJ0VoE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lO6Kp4zz; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lO6Kp4zz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7FD41F00A3A; Thu, 16 Jul 2026 07:51:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784188315; bh=CtebRvbxm5uNw/fy+A0iTGr4pHE+6vUMv+Jp05j6/1U=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=lO6Kp4zz8sQhjtJaEIernumceStD+SNT3wTl5uYLcBUMeEdvJeeMQp3hin8tt6t2C DyrvnbR2jRnyi4N/0DifuPrNIBwKVSMDQTlRTkC9XFKtFCraS9U8HGkr5R6kVErao5 ExAVwUR3TAB/3XHPe9fFVf/K+DsI4yMR0xz5SYBCa3wgaKzbUPaBC4xNkjO2PoHXZl SN6erM3bmgI7MGVSWueqaALOK5xdzERhHrdYAccTGXwtJtvlzCPokbWqtH7nDTddzn 1o2WgeMwAsoFQYcbAbd8z7AKryhOCw19Sn2/OxXPCTCzgV3fHwfr3iwc8UX6wLMCTh 2t//Rym0utpYQ== From: "Mike Rapoport (Microsoft)" Date: Thu, 16 Jul 2026 10:51:36 +0300 Subject: [PATCH bpf-next v3 2/5] bpf: drop __weak from bpf_jit_alloc_exec() and bpf_jit_free_exec() 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-execmem-x86-rox-bpf-v0-v3-2-4e76158c01c5@kernel.org> References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> In-Reply-To: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> To: 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 Cc: Emil Tsalapatis , Jiri Olsa , John Fastabend , Martin KaFai Lau , Mike Rapoport , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org X-Mailer: b4 0.16-dev bpf_jit_alloc_exec() and bpf_jit_free_exec() are wrappers for the corresponding execmem APIs. Architectures define the properties of the memory range needed by BPF in their initialization of execmem and don't need to override neither of them. Drop the __weak qualifier from bpf_jit_alloc_exec() and bpf_jit_free_exec(). Signed-off-by: Mike Rapoport (Microsoft) Acked-by: Song Liu --- kernel/bpf/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 47fe047ad30b..fc75625dc951 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1116,12 +1116,12 @@ void bpf_jit_uncharge_modmem(u32 size) atomic_long_sub(size, &bpf_jit_current); } =20 -void *__weak bpf_jit_alloc_exec(unsigned long size) +void *bpf_jit_alloc_exec(unsigned long size) { return execmem_alloc(EXECMEM_BPF, size); } =20 -void __weak bpf_jit_free_exec(void *addr) +void bpf_jit_free_exec(void *addr) { execmem_free(addr); } --=20 2.53.0 From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 A6D023AFAEB; Thu, 16 Jul 2026 07:52:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188329; cv=none; b=u/OXsAO32BuIoMZMGDdnHgZEesLdwPmWy3qRY4clhKZkdaj4kk//Fn8OhEZioHFioWqOjP3r9VNS+sIaxTb82cpT/c+CZXkhuk3s5UviJhcf+vkmU0ze9YlByTjZbQvVh3mvLUdnO/1Ek/iMmpRFKwrz3kI1QrALJdYVKiqE5uU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188329; c=relaxed/simple; bh=5P0sua/71rPK3l5T6jCA12GMKa2j6NT1JAfTkULYULA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=aphTn2r4DPUnTUNPGoFvIrb9jTONBuoaWipPkRJwp6wMiPJyiii5NFvGZDEMidCrO9v/fygIwPGRhGP2HTeJTloJm+bQ6lAEeCNCkFYMYPrFzUIJGtWWnORslmqTN+VpqQikO4Z5K1Kk+oMWQdzaHSuFC76YUL4Vp6ZODpaKbew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=F9HKxYuZ; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="F9HKxYuZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 243B61F00A3F; Thu, 16 Jul 2026 07:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784188320; bh=IatqBvV/RTdCVpUja1LQkhqHsNuZ9wpcED5UwFKZr5M=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=F9HKxYuZjI7mg9CHs1gu6tIuTYVX5BE8bGwTbX/qHgaMj9Z5tKGh4H8gIvEpKgtpJ dBsO1HjtPc3Y7Mbb2+jgbet2IDb2aE+xHeFhb6W6UrUMAVLUOLAoozPTskPSjFAigK zqpZ4EViHeA0YjqG8VOnxC9ojJBpiflZZrPCnXdc/eeXCJt26whX7YKpCT0NIrvoOI nmwxitp71PGGYMEKeZ0srND6WMr/wy3awrOnvfJ8LYykGuIojU+2K2ekK1xKnTKUUK 5TDfqjs9HVtCtqQj6dgYoc4aTJLiErifk5b0xVWDKw3P8Qk0XCeEplLugmUldrfbhL qvXBdy6ohTucg== From: "Mike Rapoport (Microsoft)" Date: Thu, 16 Jul 2026 10:51:37 +0300 Subject: [PATCH bpf-next v3 3/5] bpf: alloc_prog_pack(): skip ROX management for already ROX memory 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-execmem-x86-rox-bpf-v0-v3-3-4e76158c01c5@kernel.org> References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> In-Reply-To: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> To: 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 Cc: Emil Tsalapatis , Jiri Olsa , John Fastabend , Martin KaFai Lau , Mike Rapoport , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org X-Mailer: b4 0.16-dev execmem_alloc() can return ROX memory that is already filled with architecture defined trapping instructions. In preparation for enabling this mode for BPF on x86, make sure that there is no redundant management of the ROX memory. There is no need to fill allocated memory with trapping instructions, to request permissions reset on free and to set ROX permissions as this all is handled by execmem_alloc(). Add bpf_jit_mem_is_rox() wrapper for execmem_is_rox(), use it to check if execmem_alloc() returns ROX memory and skip the redundant steps in that case. Signed-off-by: Mike Rapoport (Microsoft) Acked-by: Song Liu --- kernel/bpf/core.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index fc75625dc951..1b89c18cf246 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -916,6 +916,11 @@ static LIST_HEAD(pack_list); =20 #define BPF_PROG_CHUNK_COUNT (BPF_PROG_PACK_SIZE / BPF_PROG_CHUNK_SIZE) =20 +static bool bpf_jit_mem_is_rox(void) +{ + return execmem_is_rox(EXECMEM_BPF); +} + static struct bpf_prog_pack *alloc_new_pack(bpf_jit_fill_hole_t bpf_fill_i= ll_insns) { struct bpf_prog_pack *pack; @@ -927,16 +932,18 @@ static struct bpf_prog_pack *alloc_new_pack(bpf_jit_f= ill_hole_t bpf_fill_ill_ins pack->ptr =3D bpf_jit_alloc_exec(BPF_PROG_PACK_SIZE); if (!pack->ptr) goto out; - bpf_fill_ill_insns(pack->ptr, BPF_PROG_PACK_SIZE); bitmap_zero(pack->bitmap, BPF_PROG_PACK_SIZE / BPF_PROG_CHUNK_SIZE); =20 if (static_branch_unlikely(&bpf_pred_flush_enabled)) pack->arch_flush_needed =3D true; - set_vm_flush_reset_perms(pack->ptr); - err =3D set_memory_rox((unsigned long)pack->ptr, - BPF_PROG_PACK_SIZE / PAGE_SIZE); - if (err) - goto out; + if (!bpf_jit_mem_is_rox()) { + bpf_fill_ill_insns(pack->ptr, BPF_PROG_PACK_SIZE); + set_vm_flush_reset_perms(pack->ptr); + err =3D set_memory_rox((unsigned long)pack->ptr, + BPF_PROG_PACK_SIZE / PAGE_SIZE); + if (err) + goto out; + } list_add_tail(&pack->list, &pack_list); return pack; =20 @@ -965,7 +972,7 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t= bpf_fill_ill_insns, bool pr_warn_once("BPF: Predictors not flushed for allocations greater than = BPF_PROG_PACK_SIZE\n"); size =3D round_up(size, PAGE_SIZE); ptr =3D bpf_jit_alloc_exec(size); - if (ptr) { + if (ptr && !bpf_jit_mem_is_rox()) { int err; =20 bpf_fill_ill_insns(ptr, size); --=20 2.53.0 From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 350AA353A6B; Thu, 16 Jul 2026 07:52:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188341; cv=none; b=PQAjB2ssdpmzUqBhSDYhhZwcD20nrRxo+UV/0QUIywlntlW4qeAR9ksQ3eqRa2dcuqpF3N6qARZ1XukLl5ezJwRF1Mz6OcIlV2543vTsMdL7TasgVrs4t2EXJiAj5wxXswnuUl96wYci8kgJp0NirG6CNJLwloe0osecQY9kyNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188341; c=relaxed/simple; bh=duHjMvPTKNUsHVFBmk2zASNmPWRBWn/MrKC3CEPM7Rs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JCkJ7B8GsODqqNSEzU44C9LKQCKRYmzO2UJ5xR4ijM8NczWdJLF7q5Rw4tFZSNIdsLQ+hFNM77axH3o13hoBjNJmNWNiuZl9GzF+fEo/JvP4V2JwtoSHPtfFZYIWNGtz7NVUcV5nhiXBmamWo4HW+tFo/B5j9BB5+48kDrVi0QA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ebIEpnRx; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ebIEpnRx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 640691F00A3D; Thu, 16 Jul 2026 07:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784188326; bh=E06Ic3v1YIX7E/Iklh6+E5eIa7VNqBAM63t+V+fmcL8=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=ebIEpnRxXLsx5NWS+3LMX4Z9ujdvhXpyQfiuzDV5s4EMBV6DtiOpKP8hwiA2Jj8Qy W99R3X5sPLfVFrkGo5B27A3fAH2GxnyMEW5S/qZV0xXpW1v5K2Vno7BI3X9DmJ2r+E 2pOgBpekERSV+7GOol8ttGCth/3SB6G+fvQHL7pqnDB6GXGlFYo1wkv4bzBtaT6W2R iL+y1TYW894SNUDhvBmW65z88DTvYhOItKr4sniQ7GcOb6u5lCouYTZGch+6hh6GSa O4N+9XL/sUULaWnipsLUDuZJNeq04NWOJ/rhajN3twBTMV6D2Fha2OOLZePsrrSZff OhHxqROLnmspA== From: "Mike Rapoport (Microsoft)" Date: Thu, 16 Jul 2026 10:51:38 +0300 Subject: [PATCH bpf-next v3 4/5] bpf, x86: make sure allocation in arch_bpf_trampoline_size() is writable 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-execmem-x86-rox-bpf-v0-v3-4-4e76158c01c5@kernel.org> References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> In-Reply-To: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> To: 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 Cc: Emil Tsalapatis , Jiri Olsa , John Fastabend , Martin KaFai Lau , Mike Rapoport , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org X-Mailer: b4 0.16-dev arch_bpf_trampoline_size() allocates a buffer to get actual size required for a trampoline. This buffer must be in the module address space because __arch_prepare_bpf_trampoline() calculates rel32 offsets relatively to that buffer. In preparation for enabling ROX mode for EXECMEM_BPF make sure that the allocated memory is writable. Add bpf_jit_alloc_exec_rw() wrapper for execmem_alloc_rw() and use it for buffer allocation in arch_bpf_trampoline_size(). Signed-off-by: Mike Rapoport (Microsoft) Acked-by: Song Liu --- arch/x86/net/bpf_jit_comp.c | 5 ++--- include/linux/filter.h | 1 + kernel/bpf/core.c | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index de7515ea1bea..b2feec81e231 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -3703,13 +3703,12 @@ int arch_bpf_trampoline_size(const struct btf_func_= model *m, u32 flags, int ret; =20 /* Allocate a temporary buffer for __arch_prepare_bpf_trampoline(). - * This will NOT cause fragmentation in direct map, as we do not - * call set_memory_*() on this buffer. * * 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(). */ - image =3D bpf_jit_alloc_exec(PAGE_SIZE); + image =3D bpf_jit_alloc_exec_rw(PAGE_SIZE); if (!image) return -ENOMEM; =20 diff --git a/include/linux/filter.h b/include/linux/filter.h index 14acb2455746..32d5297c557e 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h @@ -1333,6 +1333,7 @@ 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 1b89c18cf246..e2076667b245 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1128,6 +1128,11 @@ void *bpf_jit_alloc_exec(unsigned long size) return execmem_alloc(EXECMEM_BPF, size); } =20 +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); --=20 2.53.0 From nobody Sat Jul 25 16:19:21 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 84A4E3B9DAE; Thu, 16 Jul 2026 07:52:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188344; cv=none; b=cqZigA++LP3wkpGdHCwwjbnhZ4msQ4ZSpiITjanh8PgbXtDnHp7tdKoIG891ORiwv4A3pyZd4vCFyac4Xj3bFhd3HE+LAPUq2mBH/t+SuvI6PWDLoTYLysINqMVxqXJ3eg4CqENEbLQMZ4Nuld4u0NxgvLOanP4kzEI2Mc4rhZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784188344; c=relaxed/simple; bh=0ezK9nb6wN4qDm7eVfl3gFFuWiuh/XD1Fu96JdsDZY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sjKiaCTKEDxKOiT829sOUpfnDcPoFo5me/wSsJPsrnVRHs7QLyvbv6Qrfps26U98k1GUyEK2Lz8JIyZuOeeiI/hJ8fiynBDpj2168x4WdUHEnY+I1V/HVL3zEbzbTKURGe98IsLosJ6Xg1xFoL001IMqyECPl6/l0eg1UBWCfFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FLqo7RJt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FLqo7RJt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A42F81F000E9; Thu, 16 Jul 2026 07:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1784188331; bh=bsCkJeKP215VVn4x62ogxT2jAVvGPVAbWkkJgMSjygg=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=FLqo7RJtwC07gO35hWIR42JynRXwkaCrCzlN46P8eQEPNFxltJM2mrr1Pb63xqMFT ytcILU7+Yprwnf045Mo/px5ocK+HMSav8TpxQ+lNpOWSH5zCW3le8Da6YaLV34/vVx vDBPSRoJWWJ4JEpJEigG08SphOPRB0AsCPzxmGnDMMlZqwYd63C+WkQ1UAdKziHwZm QpsDvaIKo9BmRR//qVs6G7hiAqNZ5OoRFlGm3r4pkACKPbaPDWFKGSGb8uXGHc0Eb9 47DgLmaEJFzHyBmZR+wcCvLoDC6NouCT7l0oP92cAQK9daeAqUC/5NggniwJXCFKrF 6GWWJcoQZLUUw== From: "Mike Rapoport (Microsoft)" Date: Thu, 16 Jul 2026 10:51:39 +0300 Subject: [PATCH bpf-next v3 5/5] x86/bpf: enable EXECMEM_ROX_CACHE for BPF allocations 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260716-execmem-x86-rox-bpf-v0-v3-5-4e76158c01c5@kernel.org> References: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> In-Reply-To: <20260716-execmem-x86-rox-bpf-v0-v3-0-4e76158c01c5@kernel.org> To: 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 Cc: Emil Tsalapatis , Jiri Olsa , John Fastabend , Martin KaFai Lau , Mike Rapoport , "H. Peter Anvin" , Yonghong Song , bpf@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org X-Mailer: b4 0.16-dev BPF core and x86 JIT use text poking and temporary writable buffers and thus can handle ROX memory. Enable ROX cache for EXECMEM_BPF when configuration and CPU features allow that. Signed-off-by: Mike Rapoport (Microsoft) Acked-by: Song Liu --- arch/x86/mm/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index fb67217fddcd..079f8c7e9e3c 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -1107,10 +1107,10 @@ struct execmem_info __init *execmem_arch_setup(void) .alignment =3D MODULE_ALIGN, }, [EXECMEM_BPF] =3D { - .flags =3D EXECMEM_KASAN_SHADOW, + .flags =3D flags, .start =3D start, .end =3D MODULES_END, - .pgprot =3D PAGE_KERNEL, + .pgprot =3D pgprot, .alignment =3D MODULE_ALIGN, }, [EXECMEM_MODULE_DATA] =3D { --=20 2.53.0