From mboxrd@z Thu Jan 1 00:00:00 1970 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 C1DF53FE356; Tue, 21 Jul 2026 19:16:20 +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=1784661382; cv=none; b=nrriEC7HN9ZbXhbvzhwUGb25MATeQZT37WFUNH+71jRarv69/DqNfgf7yQWQIpukZbg1xbMQ6Omg+zLs2Caw1tlCWYRbKNwmDprGREmcNfkor0dw6O1rfPOmhP3aBoQGXk3+MzQ5chVqd5zwh0S4s+pkJwYzSDUDvXEkurbSnKs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784661382; c=relaxed/simple; bh=UUYk8oRNk2CMgEoNB9c+qXr/tDRmaCbOMW58CcNykKg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G4bBy+lWh62OEpVTOJS4T4dcMm9FsX6ILC9UekM6X45f3DrdSACoZcYGrstxhGfOgsIovCw9V358gbpsoZFQ0QkWWj6pZf9DoypBkxbbyf+b8Rfsd9AieJiARmWl72tb+8IRE7wOs9qWGRjShOK0TAY+RqK30iLA6gHoPqCovOQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Awm7GbVW; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Awm7GbVW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32ABF1F000E9; Tue, 21 Jul 2026 19:16:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784661380; bh=3gSSyL99iR9SIT3jhALtmi/+qFTvk0YQmEIhWBWwo+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Awm7GbVWOx2QN5jICMyfA/wYhPB5HHBWwbFEBlDJL7/d2mnoXzaLVnNK4Wg+6IHeL BO0IYnsx5cD/af0c62G62MU7BJWUpzdLl5arkV63rTMYqcWh38FdzU49fBMauc01SQ YUn9WytGVx0I8rmZ8s6+2w07ec6aCDpIY8lY/ClQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Pawan Gupta , Daniel Borkmann , Sasha Levin Subject: [PATCH 6.12 0009/1276] bpf: Prefer dirty packs for eBPF allocations Date: Tue, 21 Jul 2026 17:07:32 +0200 Message-ID: <20260721152446.284390045@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152446.065700225@linuxfoundation.org> References: <20260721152446.065700225@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Pawan Gupta commit b72e29e0f7ee329d89f86db8700c8ea99b4a370a upstream. The pack allocator only flushes predictors when reusing a dirty pack for cBPF, eBPF allocations never trigger a flush. Currently, eBPF picks the first free pack, which could be a clean pack. As an optimization, leaving a clean pack for cBPF can avoid flushes. Prefer dirty packs for eBPF and keep clean packs free for cBPF. This mirrors the existing cBPF preference for clean packs: each program kind prefers the pack that avoids an extra flush, and falls back to the other kind only when no preferred pack has room. eBPF reuse of a dirty pack is harmless since eBPF being privileged does not flush. Signed-off-by: Pawan Gupta Acked-by: Daniel Borkmann Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin --- kernel/bpf/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 665f8423b76004..d9131b235f7974 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -998,10 +998,10 @@ void *bpf_prog_pack_alloc(u32 size, bpf_jit_fill_hole_t bpf_fill_ill_insns, bool goto found_free_area; /* * cBPF reuse of a dirty pack triggers a flush, so prefer a - * clean pack for cBPF. eBPF never flushes, so pick the first - * free pack, dirty or clean. + * clean pack for cBPF. eBPF never flushes, so steer it to a + * dirty pack and keep clean packs free for cBPF. */ - if (!was_classic || !pack->arch_flush_needed) + if (was_classic ^ pack->arch_flush_needed) goto found_free_area; if (!fallback_pack) { fallback_pack = pack; -- 2.53.0