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=1796443880; b=HPEuvHBInpVUkX58QrVpUw5ZYLcJXedvqysbrYYB5uxx1qzKd1MxjMwIkxqjVFfQBl0o UxWOdpRBlmizvNhzSZm9mQ0B26yGGgu8BIJW3bgCRRHGx8ckGRROnVdFBZ0Jbmq1rJp0k PMi1dsh35I1uIEYSGPF3fxrgz/nKK7/ugo6jR2ZQgl0i5grdnEdauYUo8Yge4X51dyPnG kINAZb4M/xgDzbBu7fM3pgbslkNBeTenDgsoowtyw7BF8w+KvuNROe+CFGnxUgZcxPiEG R7XFREHWK3GruTsyEFZBQSoz17Tv5Hl60qO1EF2RnUuWLbRiRXKfoys42OejdCvzfIA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796443880; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=pv+aSrTvEU07lrNNKR1k5ksgQdYugW3tMqh4P+CUvmE=; b=QIFANOnGG1l61Ie+j+hrE5ltCXXmIVRrjMJkIqLli5RfQJWyog7zuMYvXoxUNKM3jFMl fCO3tbtcIBBWDl9b/MqYzrIK9BiLETXvpKPkUCkEMX6HSkZdBdKTjEzYQ+Td4x4hBLM1+ +mXjkP6VsnchehAwYHcCwZ/seK/HDmyPDEyUJdhKzWHo3kpA/h6O33fWnqokglAZIV6R/ U4XdYdRf9odrMPoTpT4ucDAjyynvF0MVHBwqRemOxavpAm8D6MPeKRktN9EINzOQFyUDZ pFhlifaLwJxRXZzYR7/eHu/SwHKSExi/fZNBuaTBzfsKKVSAECS1ujUZNKcMuWKkYAg== 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=Jowi8pWA; 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 C00CD606A322 for ; Sat, 5 Dec 2026 04:11:20 +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=Jowi8pWA Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88CFC1F0092B; Sat, 5 Dec 2026 04:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796443880; bh=pv+aSrTvEU07lrNNKR1k5ksgQdYugW3tMqh4P+CUvmE=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Jowi8pWArTUGNGa+w2vMOQqMItVNQTDSkm8VqyMlkKrtiP5oXkk9FT6BXmabDwecG gPfiTT6/WhavpVN41+KiZVahcBko7jDQCdwouyXG9NPYx5Lb/LoJcS2FDebg3ivXCn zUlnBTOwTn+NJkQl1piHDg+6RlCt5whqqTWTt02KI9SRi4xfvgIQ9vcQkXXxxcgAI6 yfco9RsIol92vT0Y/f6zOFgPDVD+i9CWSp3Bk+uV0h0/8IT/dUxrl06Zn4qpd3OOJt 93DVPCvMi+H1majh4F9/G5l1YggjGh5eoyhwctRFFs4cP+sMRvUZAWiIP3WzBJcWt1 vKmLiUqMmK09w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH 2/2] bpf: use try_lock_next_vma() in the task_vma iterator Reply-To: sashiko-reviews@lists.linux.dev To: "Chuanhua Han" , "Suren Baghdasaryan" , "Lorenzo Stoakes" , "Liam R. Howlett" , "Andrew Morton" , "Yonghong Song" , "Alexei Starovoitov" , "Daniel Borkmann" , "Andrii Nakryiko" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" Cc: "Chuanhua Han" , "Vlastimil Babka" , "Shakeel Butt" , "Pedro Falcato" , "David Hildenbrand" , "Jann Horn" , "Martin KaFai Lau" , "Song Liu" , "Jiri Olsa" , "Emil Tsalapatis" , "Ihor Solodrai" , "Barry Song" , linux-mm@kvack.org, bpf@vger.kernel.org In-Reply-To: <20261205033951.1811578-3-hanchuanhua802@gmail.com> References: <20261205033951.1811578-1-hanchuanhua802@gmail.com> <20261205033951.1811578-3-hanchuanhua802@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 04:11:19 +0000 X-Mailing-List: bpf@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 2 potential issues to consider: - [High] bpf: try_lock_next_vma() runs synchronous __mmdrop() inside RCU read lock - [Low] bpf: 32-bit truncation of next_addr in bpf_iter_task_vma_find_next() -- commit 775b83d9ac0b9c4a11b6a270f1f445469d3c8aa0 Author: Chuanhua Han bpf: use try_lock_next_vma() in the task_vma iterator This commit replaces the open-coded RCU maple tree walk and lock_vma_under_rcu() retry loop in bpf_iter_task_vma_find_next() with a call to try_lock_next_vma(). > diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c > index 2ee7b3b3c10be..a12c125eef9d1 100644 > --- a/kernel/bpf/task_iter.c > +++ b/kernel/bpf/task_iter.c > @@ -941,53 +941,17 @@ __bpf_kfunc int bpf_iter_task_vma_new(struct bpf_it= er_task_vma *it, [ ... ] > +/* Find and lock the next VMA at or after data->next_addr. */ > static struct vm_area_struct * > bpf_iter_task_vma_find_next(struct bpf_iter_task_vma_kern_data *data) > { > + VMA_ITERATOR(vmi, data->mm, data->next_addr); > struct vm_area_struct *vma; > - struct vma_iterator vmi; > - unsigned long start, end; > =20 > -retry: > rcu_read_lock(); > - vma_iter_init(&vmi, data->mm, data->next_addr); > - vma =3D vma_next(&vmi); > - if (!vma) { > - rcu_read_unlock(); > - return NULL; > - } > - start =3D vma->vm_start; > - end =3D vma->vm_end; > + vma =3D try_lock_next_vma(data->mm, &vmi, data->next_addr, ULONG_MAX); > rcu_read_unlock(); [Severity: High] Can calling try_lock_next_vma() under rcu_read_lock() run synchronous __mmdrop() inside an RCU read-side critical section? Commit "mm/mmap_lock: add try_lock_next_vma()" takes a nested rcu_read_lock() around vma_start_read(), assuming commit 44926897b6c2 ("mm/vma: drop mm asynchronously in vma_start_read()") is present. In this tree, vma_start_read() still calls synchronous mmdrop(): mm/mmap_lock.c:vma_start_read() { ... /* __mmdrop() is a heavy operation, do it after dropping RCU lock. */ rcu_read_unlock(); mmgrab(other_mm); vma_refcount_put(vma); mmdrop(other_mm); ... } When a SLAB_TYPESAFE_BY_RCU VMA is reused by another mm and that mm drops its last mm_count reference here, vma_start_read()'s single rcu_read_unlock() leaves the outer rcu_read_lock() held across __mmdrop(). Because bpf_iter_task_vma_new() only rejects irqs_disabled(), a softirq BPF program on x86 can deadlock on pgd_lock: pgd_alloc() spin_lock(&pgd_lock) bpf_iter_task_vma_find_next() rcu_read_lock() try_lock_next_vma() -> vma_start_read() mmdrop() -> __mmdrop() -> pgd_dtor() spin_lock(&pgd_lock) <-- deadlock Under CONFIG_MMU_LAZY_TLB_SHOOTDOWN, __mmdrop() -> cleanup_lazy_tlbs() -> on_each_cpu_mask(..., wait=3D1) also hits WARN_ON_ONCE(!in_task()) in smp_call_function_many_cond(). Applying commit 44926897b6c2 ("mm/vma: drop mm asynchronously in vma_start_read()") as a prerequisite would keep __mmdrop() out of this path. [ ... ] > - if (unlikely(vma->vm_end <=3D data->next_addr)) { > - data->next_addr +=3D PAGE_SIZE; > - vma_end_read(vma); > - goto retry; > - } > - > return vma; > } [Severity: Low] Does removing this check introduce a 32-bit wrap-around regression when data->next_addr exceeds ULONG_MAX? bpf_iter_task_vma_new() stores the caller-supplied u64 addr directly into data->next_addr, which is implicitly truncated to unsigned long in VMA_ITERATOR() and try_lock_next_vma(). On 32-bit kernels, passing an addr >=3D (1ULL << 32) now wraps to a low address and returns VMAs below addr instead of NULL, whereas the removed 64-bit vma->vm_end <=3D data->next_addr check previously prevented returning them. Guarding data->next_addr >=3D ULONG_MAX (or rejecting out-of-range addr in bpf_iter_task_vma_new()) would avoid the truncation. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205033951.1811= 578-1-hanchuanhua802@gmail.com?part=3D2