From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6531C71157 for ; Tue, 17 Jun 2025 23:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63A316B007B; Tue, 17 Jun 2025 19:10:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 612376B0088; Tue, 17 Jun 2025 19:10:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 527B86B0089; Tue, 17 Jun 2025 19:10:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 440976B007B for ; Tue, 17 Jun 2025 19:10:35 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D01941612BD for ; Tue, 17 Jun 2025 23:10:34 +0000 (UTC) X-FDA: 83566438788.17.3406307 Received: from mx0b-00364e01.pphosted.com (mx0b-00364e01.pphosted.com [148.163.139.74]) by imf22.hostedemail.com (Postfix) with ESMTP id C3A2CC0015 for ; Tue, 17 Jun 2025 23:10:32 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=columbia.edu header.s=pps01 header.b=oEhhXgwt; spf=pass (imf22.hostedemail.com: domain of tz2294@columbia.edu designates 148.163.139.74 as permitted sender) smtp.mailfrom=tz2294@columbia.edu; dmarc=pass (policy=none) header.from=columbia.edu ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1750201832; a=rsa-sha256; cv=none; b=KchYQpNbQ+N9zNqOhL4vA/HPEEqTkDXavmkKXPyfllsk7magTvN8PxDyCEu9PJYqJgfyiv EbQsJSUEbAm+hbNr/JRdbHAXxwIAwpi8mLu1eXwJ25PGTB2302xGeWQr2W91IiqZWPPw9w HzNtGniFUcTNwsI/F+Gfq57FfAFB5xw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=columbia.edu header.s=pps01 header.b=oEhhXgwt; spf=pass (imf22.hostedemail.com: domain of tz2294@columbia.edu designates 148.163.139.74 as permitted sender) smtp.mailfrom=tz2294@columbia.edu; dmarc=pass (policy=none) header.from=columbia.edu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1750201832; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PPIlybKNdm4yIUURr7WS1HfyttFDFu0B0++M/LaRTs0=; b=07BBIi5SaUTuUfccw/dpNDQaK8nAVYlCgJTDfQJaH6zGX9y69XCVBHGwUWCsNE+4oIRghw rqsu3KVudewozQ9AQU65VnluFXW/P+8yBrn0eq/Rjf3ygi/oE8s6jrDK1B+UlcE6yUxPrU mY9dcMP3pmXqswQVNX88bo9dtX6/0X4= Received: from pps.filterd (m0167074.ppops.net [127.0.0.1]) by mx0b-00364e01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 55HMjGpA025743 for ; Tue, 17 Jun 2025 19:10:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=columbia.edu; h=cc : content-transfer-encoding : content-type : date : from : in-reply-to : message-id : mime-version : references : subject : to; s=pps01; bh=PPIlybKNdm4yIUURr7WS1HfyttFDFu0B0++M/LaRTs0=; b=oEhhXgwtMdtGkxaZplg5vPgoi6ApdWz+EMAofe1hVO+8xKkhQV/3owORzGoV+iIduk5x YOdvAs5xdha8DaIjug++WKJaYcpFRYixOL6ah5V2vuM0skOUCz6ke3icihGaRP3pUcMB PfJqo+BUV+JszgmcXZKPWWgscl4bUKr0znbOxHsK4oQm6MvTUSOINmEjUVY4s6T2XqAp 5Ok/ZhD2hgFlPf9j7+CQo5M1r8eV9lQ58cIiAbhMqm12y0zrKpG9uYpeOtXmYpEFlTc7 JMmZ25CB5CBl2P1i9FTmIRXR3bcXXwMog+FGahzvriHF6jjNLWXdpNBcgUyv9+GfoZc1 Gg== Received: from mail-yw1-f197.google.com (mail-yw1-f197.google.com [209.85.128.197]) by mx0b-00364e01.pphosted.com (PPS) with ESMTPS id 47924h4cxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 17 Jun 2025 19:10:31 -0400 Received: by mail-yw1-f197.google.com with SMTP id 00721157ae682-70e4bd6510eso85048647b3.0 for ; Tue, 17 Jun 2025 16:10:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750201831; x=1750806631; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PPIlybKNdm4yIUURr7WS1HfyttFDFu0B0++M/LaRTs0=; b=BEmj9JuSkXqVr9YIw5QPsk6GWeMFLRJRcpoSC+Hfpnxg991cw6G55Vv2x5hDNhTUM0 RqGj+ASWLCjMDLo2niFWbBjwm9AVUgUt2kA3ark7p0oWgGjMuJOBltqZILhRkQ43eXd1 BXbvH0espBH0iLPDYGoR2XyLI2NhE0fbdrUrKQ+9USah4zUf2SbjdB7czydGCpdTu3xu k+vrLpd2ly53vduN8sL8+CTkbwk7q5OPOluhtQ9EllFdFdC9ot3HJR7BbGmwPuonga2F w3VetY/3TpLyStpSopHavs7tMGO4D4iHB7a5xgbJSLWi23li317QaxUYbWe6FkZbP7z9 NB7g== X-Forwarded-Encrypted: i=1; AJvYcCWarSSJ5vmrFnZoklkdSDlbQa9SWu+lzmEqK7ru4zBqTRugUoMNbzWifa5+rHIj5/lWaVY/cUBc7A==@kvack.org X-Gm-Message-State: AOJu0Yw/4dlnQaEHR9twnMcIRzjAqvhPw9Vqek/C9AVVm7tDS3zLHK3p LQ2VZyTMRuZHBAaqNnWBxAD9Aogc3bcqppuB74l8Jd17VFPPUHZj6JvGOB1yxT6ddFXHgJ+rAu/ kUBmxFowstlbeygaAk2lZeASJOrgg/jBq/WZkEJpzKDXuETTuTJ1yqU8iT5M7qGxWZq2t/vw1iG KTN9BETjc27IGu9TTzhdB6uVY= X-Gm-Gg: ASbGncvKbtjZIBE/XMA2RFGLkU8K74gb6mxwAYdxhFGDToBW/PMaHH04m8WBLHMfkbh Nb7/fnWYWWrJV6ZnB5O/5Rz0ahEysOQQTlIv3PyY9rKg6p9SEZY0yuDvU9lyiP/7LHJyIk2CpGp QajIFv X-Received: by 2002:a05:690c:39a:b0:70e:2ba2:659d with SMTP id 00721157ae682-71175508e9fmr212259597b3.23.1750201830714; Tue, 17 Jun 2025 16:10:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1MaV6Rrl4NS52+ptXzrJWizfrxcqVttjZ4z6G//Vqhsn2sOORf/ikGlXkhM2uf2ZCmVQQKfsMabSKiWjkcII= X-Received: by 2002:a05:690c:39a:b0:70e:2ba2:659d with SMTP id 00721157ae682-71175508e9fmr212259297b3.23.1750201830365; Tue, 17 Jun 2025 16:10:30 -0700 (PDT) MIME-Version: 1.0 References: <20250607-uffd-fixes-v2-0-339dafe9a2fe@columbia.edu> <20250607-uffd-fixes-v2-2-339dafe9a2fe@columbia.edu> In-Reply-To: From: Tal Zussman Date: Tue, 17 Jun 2025 19:10:19 -0400 X-Gm-Features: Ac12FXzaafrz6_SjU1Auy6iU7reT4WBtzzTB9t9DBfTU53fTcxWKGcC7DGMVbzU Message-ID: Subject: Re: [PATCH v2 2/4] userfaultfd: remove (VM_)BUG_ON()s To: David Hildenbrand Cc: Andrew Morton , Peter Xu , "Jason A. Donenfeld" , Alexander Viro , Christian Brauner , Jan Kara , Andrea Arcangeli , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-ORIG-GUID: GdL8KGQmMM9D3OdBINevmrZssr511m50 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNjE3MDE4OSBTYWx0ZWRfX2Z+bkEEyl6BT 3tRgtLQL0HCRV2bk3J+TIndl4T1WUKu+iHv3kxYe317YjjHmLdd90w0jCG9j3LViz2DtOwiwWkW 0wIXLGbWZaadn33cu+iKjA+V/EWXXP2cMrUI3nwu+P8LEz1fPhMMs9Hb52trNOoSRUCRSlm2nhV ENjiN0EIhxzxgRoLdLkPXBbOGEDt5cQvwKbxh5na/Dtf9B/xzfABZvYq70nRrrL72dlAE4LMBFQ fMxcutoRKdCjyOi9+KDg2RSmzbF+Ie3ouuoYCdGMjKATcYOdQPkSMUMlU6hIucEBu8HlCne10FX xsgs4GzNaHdy4kM/rUoggiDzwcXwEmzLbBOqDYGAaIwzSZqxSJ+lshfEL4X4WJ6OhYiA3ZQctG5 OZF3G0zq X-Proofpoint-GUID: GdL8KGQmMM9D3OdBINevmrZssr511m50 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-06-17_09,2025-06-13_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 spamscore=0 lowpriorityscore=10 bulkscore=10 clxscore=1015 adultscore=0 phishscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2505160000 definitions=main-2506170189 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: C3A2CC0015 X-Stat-Signature: geuosabwognepk7tuz6ndptuy9n4r5wo X-Rspam-User: X-HE-Tag: 1750201832-406566 X-HE-Meta: U2FsdGVkX1+5Cq0S86En4NbOxl5xwFxa6X+lovnmS5hMNizN+0cKBD2O4LeYG5PnsiS0i8CtM9fsqPT57GWquakXhEQ6Sv5qI2uDWzLw+YUUwHVeEM6nl/ENtUAp9oUUr174nOUY+LvhmlrIfmViDaTb3QaszHh5R8pEaZEFkuzCMJFZX4hFAzJsdJ/9Q6yq1A8Xld2RTPBKf9YG0ZaLRNNfv6zXtMUcfAtCnLyAMGA6PxUm72umqMlNd609IiyO0jZMIJbl+HjTB/g+8Pr09WK9yciqDgYhAhBx2N7LwJR8tlnIlxCsne8n9x8gzfNYDvxIsmQn16QoZjc7w8nUvz4sVNEOYbj9AAM2EWltx3DlJy82X5C7zqvvMfCJhzwRuTnYBnKAgdWv/Is3clot7JQ5Kd+KBbG7NSYAge6y0YUIBCSvhJs2Ugy/nFYC768tTYAuSybLmhuB641nBheNbO8hFXvkrduazTb0smWhlpS86DML2mQIglpddt3gAgCEWteKS+p4UMGE8HMgqOKn7uMsxEomciAv3UBTE2bNN507KaRbxJGazcj40ftheA9r+b4rxv9UHy+dKm6zNlq2i6P+inyuIXH0BPPSJ+pls7pnySIs5I/pmfYL7giFHjlVPBvMiQQrQc8n4Gki1/5f+JOmHLRAdH8WSOsgEyKzIOI3RinrWuya0hjpHTM7a0kpRL1yAEmpruhJLZdep2WhQcSEfEiyZqhpNs3J8j5VBdUGSyJE38yLmhSa3d8DV/MTAb3B3G+9VDS0qyAqKyv9TbqZFT3qGh3rOQyeOX8HIiOINMcJk3O9UXxXHdvrq/DD6Em2DKZ8SszPBZhfNlutL0EGJm/0IpyHLLRtaPJIgzbrSXjCtXd/sWPgKTuLTzmpSXy1RgKhvgjS8wdpNy5Shl/3Bc+qjYfRkqZmMumfPX9zN+OSuxAC2FJhQU51CrhAn8DQq8KHA6uQ1t/T/0n aMA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jun 10, 2025 at 3:26=E2=80=AFAM David Hildenbrand wrote: > > On 07.06.25 08:40, Tal Zussman wrote: > > > > if (ctx->features & UFFD_FEATURE_SIGBUS) > > goto out; > > @@ -411,12 +411,11 @@ vm_fault_t handle_userfault(struct vm_fault *vmf,= unsigned long reason) > > * to be sure not to return SIGBUS erroneously on > > * nowait invocations. > > */ > > - BUG_ON(vmf->flags & FAULT_FLAG_RETRY_NOWAIT); > > + VM_WARN_ON_ONCE(vmf->flags & FAULT_FLAG_RETRY_NOWAIT); > > #ifdef CONFIG_DEBUG_VM > > if (printk_ratelimit()) { > > - printk(KERN_WARNING > > - "FAULT_FLAG_ALLOW_RETRY missing %x\n", > > - vmf->flags); > > + pr_warn("FAULT_FLAG_ALLOW_RETRY missing %x\n", > > + vmf->flags); > > You didn't cover that in the patch description. > > I do wonder if we really still want the dump_stack() here and could > simplify to > > pr_warn_ratelimited(). > > But I recall that the stack was helpful at least once for me (well, I > was able to reproduce and could have figured it out differently.). I'll include this in the description as well. Given that you found the stac= k helpful before, I'll leave it as-is for now. > [...] > > > err =3D uffd_move_lock(mm, dst_start, src_start, &dst_vma, &src_vma); > > if (err) > > @@ -1867,9 +1865,9 @@ ssize_t move_pages(struct userfaultfd_ctx *ctx, u= nsigned long dst_start, > > up_read(&ctx->map_changing_lock); > > uffd_move_unlock(dst_vma, src_vma); > > out: > > - VM_WARN_ON(moved < 0); > > - VM_WARN_ON(err > 0); > > - VM_WARN_ON(!moved && !err); > > + VM_WARN_ON_ONCE(moved < 0); > > + VM_WARN_ON_ONCE(err > 0); > > + VM_WARN_ON_ONCE(!moved && !err); > > return moved ? moved : err; > > > Here you convert VM_WARN_ON to VM_WARN_ON_ONCE without stating it in the > description (including the why). Will update in the description. These checks represent impossible condition= s and are analogous to the BUG_ON()s in move_pages(), but were added later. So instead of BUG_ON(), they use VM_WARN_ON() as a replacement when VM_WARN_ON_ONCE() is likely a better fit, as per other conversions. > > @@ -1956,9 +1954,9 @@ int userfaultfd_register_range(struct userfaultfd= _ctx *ctx, > > for_each_vma_range(vmi, vma, end) { > > cond_resched(); > > > > - BUG_ON(!vma_can_userfault(vma, vm_flags, wp_async)); > > - BUG_ON(vma->vm_userfaultfd_ctx.ctx && > > - vma->vm_userfaultfd_ctx.ctx !=3D ctx); > > + VM_WARN_ON_ONCE(!vma_can_userfault(vma, vm_flags, wp_async)); > > + VM_WARN_ON_ONCE(vma->vm_userfaultfd_ctx.ctx && > > + vma->vm_userfaultfd_ctx.ctx !=3D ctx); > > WARN_ON(!(vma->vm_flags & VM_MAYWRITE)); > > Which raises the question, why this here should still be a WARN After checking it, it looks like the relevant condition is enforced in the registration path, so this can be converted to a debug check. I'll update the patch accordingly. However, I think the checks in userfaultfd_register() may be redundant. First, it checks !(cur->vm_flags & VM_MAYWRITE). Then, after a hugetlb check, it checks ((vm_flags & VM_UFFD_WP) && !(cur->vm_flags & VM_MAYWRITE)), which should never be hit. Am I missing something? Additionally, the comment above the first !(cur->vm_flags & VM_MAYWRITE) check is a bit confusing. It seems to be based on the fact that file-backed MAP_SHARED mappings without write permissions will not have VM_MAYWRITE set= , while MAP_PRIVATE mappings will always(?) have it set, but doesn't say it a= s explicitly. Am I understanding this check correctly? Thanks for the review! > -- > Cheers, > > David / dhildenb >