From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796237498; b=M7ZOiDsKrh8JnmSQIMKmczx87XGarVrxqtkaG6AsxPXQyHrGsKYUBqUpqaVmemeDPdfz BdknGJAOeBptDubM7L45665Aer10O8KxRx+bOd7YLrnaR5RFsJoW3c0MP2+p3IAEJdmB6 v+WscFSQRjWo4LRmtWMPNbvJF6wdlOvrLUa5k5y2a7jOOvbLr8OWlK4TQVG0rggVmpOLN t+GPfXKH0+h8eWMIfwCwIIf3wtw5HSWYYdAH/KLvmn6EROWK8tRDxjVHy0qxLSq0dnFlT EiMox8Af6zi0pFTK9e6QagDl8wrePHhOHVGj1ShkqZAr13SKFx6kOgb6uU967gWU4bQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796237498; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=il8w3KU1x2HlXxHsH7a/NU94eMJl4Wy+UxN2NWwUHs4=; b=5ElQYO1lypUc8W5Mu9+C0SM6P6G/+ySwtZTN2KSbdwIQDt5y5QK4JHa69WdLzGUcqt9q pnziHMof8PyygXzEmPhnIvzEAaW8DyPev+Y2Uas45TG4A4gj25mynUXhGBnh92Xj0T7N0 lVEpAeuZaLzWHM/80q7lNGkwY7rUGGqXoPiMMe1IPtNQDDsTRppqONGOkTZCBPNZWjYNe 44Wn4h6PqKvFNOmzBnBtd/q332X3Vs2fSvHCUgXBy8ngltw8WMxvdvfqWOVgPjAnPTD0U KVFopjIqkog9n5w52dTmhiPbWJROZgxZ4cLIfxF/fn/wu3ybMoZpfdIxSSQNfL20H0A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k503Jok4; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 21E25606A693; Wed, 2 Dec 2026 18:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=k503Jok4 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9F9531F00893; Wed, 2 Dec 2026 18:51:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796237497; bh=il8w3KU1x2HlXxHsH7a/NU94eMJl4Wy+UxN2NWwUHs4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=k503Jok4B7ILWBXOzJFSiR3Gauqfp/z/C7aqGMexEXJuxQLq97wma6zCQu704tGdX tPB4ufUUOZBqwB2P8fTEDvgguh0iCjtKP1wmRmzD0sJnxdKBk9EegedOJeHMML4yj6 tICnEcbE1zQtfmmgIBiBeORpdd80XCEH4QEpeMI5VaAO5mogCy5pnxdw4uCmgzTv3U LJw/plRjjIPUWDiFpMvRzOcd3eXRYBt8MTC4C+jCsRD4Fm+tt1api/qqDlktkehJPT iQkmCgfamGvRZcQjp66cx9oJE1u55oxl9eR7WlApQhXIg1wfrKSl3XsMlFqCXxfFW0 EyuhzajOQa+cg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 2/5] bpf: Allow importing memfd pages into an arena Reply-To: sashiko-reviews@lists.linux.dev To: "Andrea Righi" Cc: bpf@vger.kernel.org, sched-ext@lists.linux.dev, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org In-Reply-To: <20261202182648.2239421-3-arighi@nvidia.com> References: <20261202182648.2239421-1-arighi@nvidia.com> <20261202182648.2239421-3-arighi@nvidia.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 18:51:37 +0000 X-Mailing-List: linux-cxl@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] bpf: redundant TLB flushes, PTE walks, and VMA zaps in arena_free_range() -- commit d96cf4c4916f7758809e32ec47ce01b90e4ddf99 Author: Andrea Righi bpf: Allow importing memfd pages into an arena This commit allows BPF arenas to map externally supplied pages and adds the bpf_arena_import_memfd() kfunc to pin and import pages from memfd, tmpfs, or hugetlbfs files into an arena. > diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c > index ebe4ac74f2196..3721001fa1a16 100644 > --- a/kernel/bpf/arena.c > +++ b/kernel/bpf/arena.c [ ... ] > @@ -1019,9 +1113,12 @@ static int arena_free_range(struct bpf_arena *aren= a, long uaddr, long page_cnt) > u64 full_uaddr =3D clear_lo32(arena->user_vm_start) + uaddr; > long kaddr =3D bpf_arena_get_kern_vm_start(arena) + uaddr; > long pgoff =3D compute_pgoff(arena, uaddr); > + long first =3D pgoff, last =3D pgoff + page_cnt - 1; > + struct arena_import *imp, *tmp; > struct clear_range_data cdata; > struct llist_node *pos, *t; > LLIST_HEAD(free_pages); > + LIST_HEAD(imports); > unsigned long flags; > struct page *page; > int ret; > @@ -1042,6 +1139,15 @@ static int arena_free_range(struct bpf_arena *aren= a, long uaddr, long page_cnt) > return 0; > } > =20 > + /* Imports are released whole, also the ones that are only partly in th= e range */ > + while ((imp =3D arena_import_it_iter_first(&arena->imports, pgoff, pgof= f + page_cnt - 1))) { > + first =3D min(first, IMPORT_START(imp)); > + last =3D max(last, IMPORT_LAST(imp)); > + arena_import_it_remove(imp, &arena->imports); > + arena_unmap_import(arena, imp); > + list_add(&imp->head, &imports); > + } > + > cdata.arena =3D arena; > cdata.free_pages =3D &free_pages; > /* clear ptes and collect struct pages */ > @@ -1059,6 +1165,8 @@ static int arena_free_range(struct bpf_arena *arena= , long uaddr, long page_cnt) > =20 > /* ensure no stale TLB entries */ > flush_tlb_kernel_range(kaddr, kaddr + (page_cnt * PAGE_SIZE)); > + list_for_each_entry(imp, &imports, head) > + arena_flush_import(arena, imp); > =20 > if (page_cnt > 1) > /* bulk zap if multiple pages being freed */ [Severity: Medium] Does freeing a range that overlaps imported pages issue redundant TLB shootdowns, duplicate PTE walks, and unnecessary VMA zaps? Because the freed range and any overlapping imports form a single contiguous range [first, last], flushing [kaddr, kaddr + page_cnt * PAGE_SIZE) and then calling arena_flush_import() for each import issues overlapping cross-CPU TLB shootdowns instead of one flush across [first, last]. Similarly, arena_map_destroy() calls arena_flush_import() inside its per-import loop rather than unmapping all imports and flushing once. In addition, calling arena_unmap_import() before apply_to_existing_page_range() walks and clears the overlapping import PTEs twice under arena->spinlock, and when page_cnt > 1, zap_pages() still takes arena->lock and mmap_read_lock() across all user VMAs even when free_pages is empty because only imported pages (which are never faulted into arena user VMAs) were unmapped. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202182648.2239= 421-1-arighi@nvidia.com?part=3D2