Received: by 2002:ab2:1c04:0:b0:1f7:53ba:1ebe with SMTP id f4csp60683lqg; Fri, 26 Apr 2024 08:45:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwd97jFxiPG0wJG7aHBBGfXqetNnf7P8/LKTne9FVeF5OoA0CU2K7P6NrDrjB0I+AqsHFUNV/3U8uUHx0BWSU9kZOjp+SaMVaJrF3hQw== X-Google-Smtp-Source: AGHT+IGDihQOnAQBoP2fH+KCWKiwjHhph8ttj4X+QTn1FqsH1FZjQd2Zkdm9Pfzhgu7I0k3OUIZy X-Received: by 2002:a17:903:445:b0:1eb:c70:9575 with SMTP id iw5-20020a170903044500b001eb0c709575mr1924611plb.42.1714146350087; Fri, 26 Apr 2024 08:45:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714146350; cv=pass; d=google.com; s=arc-20160816; b=YMHrdrWPOW9OBPiWQHFJoUwQjUPDR8NnScBERcA22RhquayFn7ymdpYC6Re5R7OI/G uAajRLeAVvzzNzlZtxxLKzqDgK8vv0pV9MPIfQpAd+Sh1mpQ1/4L2N3avzl5TW6F1yZK NsIk/p4Pj4Tg/sm9CaZ3W9qjIhUedTkyHDp5Oa5QD9z1VPnWoHbENn9PFM4eDXJBQEA1 XVsQ0s5+m6JKsTS+4h7B2HRQExNf8jjWMyyjuTCafHC1ZBzvsH1hG920i6+rvRx2rtBz S+Q5XOMz7+q0cZjbj84aez05BCrVwdJEHmVL2azzSMMbugHrZRSFbK3JCOPke/Gv3UJI LDLQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=9S/Vbi1rWTYHkgfpvQ1kviWugUk7qWwPSxIH68nf+es=; fh=iHRnHx0EYWacrZYn43bA/oO1PHRXxzVnwr+kP/XPZYU=; b=tDkl7Fd4pkJuS637jdJ6U9OzH7t7p3ai3VPMxNc2O6rYwj8uL0sIO1wklFe2ygJe3r WyHPwHsKCIsay+vudBWVIVVVHdjxibFT/9/Tr8G9J41SSzniTweuaokGTglxI/co/MG4 hk2dBcAectQes/XFRAjUQ9Fwusd3m3O051H1vT1gi/C4vJXlSdw4/3ra+R9weVZeDMLz WrX9ndp3ZYr2Tn4k23R+EjekYBtjJ/MGfxhW3DcGyLHUqVVHxMc3UeaWnB2xILXgkehs F/bys6H15kRObPCO9GQeedrd9JF6UDM2K2UcC6Tnk2myxNVm1px84ubGMSG4350HoUg2 VTNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=miMaPaWE; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id a24-20020a170902b59800b001eb2fc90b1csi444887pls.51.2024.04.26.08.45.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Apr 2024 08:45:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-160277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=miMaPaWE; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-160277-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-160277-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 87C1FB27197 for ; Fri, 26 Apr 2024 15:25:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A01A14A60A; Fri, 26 Apr 2024 15:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="miMaPaWE" Received: from mail-yw1-f179.google.com (mail-yw1-f179.google.com [209.85.128.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88DCB143886 for ; Fri, 26 Apr 2024 15:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714145011; cv=none; b=Y1fXWnVM90MNEe5A+ivAK+0DAFNRZbfCOsGxqfRQvHGD5qQEx2+qKY637eVE3FNb0wXEoxGDYOYKN1SgYC9WlKEq2++hVZZXRg4TmEu4N69nDgIRJMbTLH1e1nyBrNczY7YALi/WQnIfDN0IguU3W2cJCkzPH6Kpnlhy9lZ28nw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714145011; c=relaxed/simple; bh=iCt18BOvFIOjhGF+HusQ5DL1yCwbZwXLs9IUSPWGpYE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=O/cT7HrzYyc3pPIIwd3hs77UH09xD0/DbX2FZcxyI805Smi6EQK9wOcEz8B3F5rqxjodm4Rgx7FPvijq8az+Cc6uV/bFLE2C8fYkEgaNwnUOqx8/LZdMQ6snaCh3zy2VA+iH8KkDeewYnLeNuiDqGpdGxRCvnlo16ByZNbpBtC8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=miMaPaWE; arc=none smtp.client-ip=209.85.128.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-yw1-f179.google.com with SMTP id 00721157ae682-617ddc988f5so23388457b3.2 for ; Fri, 26 Apr 2024 08:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714145008; x=1714749808; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9S/Vbi1rWTYHkgfpvQ1kviWugUk7qWwPSxIH68nf+es=; b=miMaPaWE17azsm1Ckg1hRwQ99RLnw+3FxzPwYDTwE0QF4VHHyTySIyEXMukzlwDDMq UKTgsr1FoGE81nZkvF3EyhCA3pQn9ORNC+isxM/8/wn1LpPPAnZH2ZyN2QYtGw1256Vx 2FK0IwFtAuTf0e3qC0CnRm4FAOnWoTmQe+2SDXAUDneBa2gJhgTGdKHkLps3Y/guAdvh UZzFL9NPQDU1kHzyJuUe38jUJ+ASAKQ2BCp3uT33XSaF/JL+LyP3ITpSGKTnARHNTBNu HGW3feXzrrqFUtQ1Xtb2XG4QzCgPue+HgEm09KBXm2NO/0WDOeiuhIN8101JvIPRB6Ou 4Fhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714145008; x=1714749808; 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=9S/Vbi1rWTYHkgfpvQ1kviWugUk7qWwPSxIH68nf+es=; b=p0BTGdF2ThXMKCNWH0isdXtIF1lb3I6P7yBxk2KMNEnbyCUau/lbPAA1fo24hYXnbe BoyVA+R66V7WsG71yXrjVcPUsiIHePBy7yTjoGOx2kP2IMoV7QK3+Hb/AXgTvs6T42UG OErl8K0l/W5cfmN2Cma/hXg2HPuRsNoq3JnB852gSw5GrdzNQyNSt3lLt+6WW3oHNJ5B FtYB2J2Wl2YglWnTUHkSLg/s4Es6wtyLGqZxOuLnZQIcmzbgL2PQmp0jJuXEPFCUTxdq z2SidCXZx30rDIDwiZFpG0FM5mEdtJIUNFZ2Trg8TLOZgh+Ky7jW29gNN5njU61phbyt Oxvg== X-Forwarded-Encrypted: i=1; AJvYcCV08POnJmAduMNWHykGe1xSbiteFKWHprOsD96XAgu82OM+LUBl7PP8E/befxznuBjwfdSSUjgjuhiCv0XRk+6SsBfu97WJ6GqnwdjP X-Gm-Message-State: AOJu0YwXsraLiILLFIuoV4MjJgp9jqOWN0LPz3d0bIVFetctpvWgFJZM IBjYJOhuRH8+4nuUo710Fky2xdCoRyH5qN0PlQTUkQGWprnGUne8nJiZWTN+mdyaY4UZValWw6L RNPTgRw6DuDrwF3d+v4enDkKG7m2KbML2uapjj1tFfD0z4gJnGQ== X-Received: by 2002:a05:690c:3706:b0:615:a86:f77b with SMTP id fv6-20020a05690c370600b006150a86f77bmr3177502ywb.26.1714145008244; Fri, 26 Apr 2024 08:23:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240426144506.1290619-1-willy@infradead.org> <20240426144506.1290619-4-willy@infradead.org> In-Reply-To: <20240426144506.1290619-4-willy@infradead.org> From: Suren Baghdasaryan Date: Fri, 26 Apr 2024 08:23:17 -0700 Message-ID: Subject: Re: [PATCH 3/4] mm: Fix some minor per-VMA lock issues in userfaultfd To: "Matthew Wilcox (Oracle)" Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Peter Xu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 26, 2024 at 7:45=E2=80=AFAM Matthew Wilcox (Oracle) wrote: > > Rename lock_vma() to uffd_lock_vma() because it really is uffd specific. > Remove comment referencing unlock_vma() which doesn't exist. > Fix the comment about lock_vma_under_rcu() which I just made incorrect. > > Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan > --- > mm/userfaultfd.c | 20 +++++++++----------- > 1 file changed, 9 insertions(+), 11 deletions(-) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index e6486923263c..defa5109cc62 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -56,17 +56,16 @@ struct vm_area_struct *find_vma_and_prepare_anon(stru= ct mm_struct *mm, > > #ifdef CONFIG_PER_VMA_LOCK > /* > - * lock_vma() - Lookup and lock vma corresponding to @address. > + * uffd_lock_vma() - Lookup and lock vma corresponding to @address. > * @mm: mm to search vma in. > * @address: address that the vma should contain. > * > - * Should be called without holding mmap_lock. vma should be unlocked af= ter use > - * with unlock_vma(). > + * Should be called without holding mmap_lock. > * > * Return: A locked vma containing @address, -ENOENT if no vma is found,= or > * -ENOMEM if anon_vma couldn't be allocated. > */ > -static struct vm_area_struct *lock_vma(struct mm_struct *mm, > +static struct vm_area_struct *uffd_lock_vma(struct mm_struct *mm, > unsigned long address) > { > struct vm_area_struct *vma; > @@ -74,9 +73,8 @@ static struct vm_area_struct *lock_vma(struct mm_struct= *mm, > vma =3D lock_vma_under_rcu(mm, address); > if (vma) { > /* > - * lock_vma_under_rcu() only checks anon_vma for private > - * anonymous mappings. But we need to ensure it is assign= ed in > - * private file-backed vmas as well. > + * We know we're going to need to use anon_vma, so check > + * that early. > */ > if (!(vma->vm_flags & VM_SHARED) && unlikely(!vma->anon_v= ma)) > vma_end_read(vma); > @@ -107,7 +105,7 @@ static struct vm_area_struct *uffd_mfill_lock(struct = mm_struct *dst_mm, > { > struct vm_area_struct *dst_vma; > > - dst_vma =3D lock_vma(dst_mm, dst_start); > + dst_vma =3D uffd_lock_vma(dst_mm, dst_start); > if (IS_ERR(dst_vma) || validate_dst_vma(dst_vma, dst_start + len)= ) > return dst_vma; > > @@ -1436,7 +1434,7 @@ static int uffd_move_lock(struct mm_struct *mm, > struct vm_area_struct *vma; > int err; > > - vma =3D lock_vma(mm, dst_start); > + vma =3D uffd_lock_vma(mm, dst_start); > if (IS_ERR(vma)) > return PTR_ERR(vma); > > @@ -1451,7 +1449,7 @@ static int uffd_move_lock(struct mm_struct *mm, > } > > /* > - * Using lock_vma() to get src_vma can lead to following deadlock= : > + * Using uffd_lock_vma() to get src_vma can lead to following dea= dlock: > * > * Thread1 Thread2 > * ------- ------- > @@ -1473,7 +1471,7 @@ static int uffd_move_lock(struct mm_struct *mm, > err =3D find_vmas_mm_locked(mm, dst_start, src_start, dst_vmap, s= rc_vmap); > if (!err) { > /* > - * See comment in lock_vma() as to why not using > + * See comment in uffd_lock_vma() as to why not using > * vma_start_read() here. > */ > down_read(&(*dst_vmap)->vm_lock->lock); > -- > 2.43.0 >