Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp125582rdh; Tue, 13 Feb 2024 11:18:40 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWz8+lJ+82JtcKPiivLqy16zQeNUQEzKFszvaATwrV5snYW1ndLrPsJ7fAW1SPcvOF11JrMm2gGXLMIwxV6Aynkhqlb9Ty7stu1uyclNQ== X-Google-Smtp-Source: AGHT+IEcQAkyRCWupVnNOOnevy3lWfxKeacjDdr5YJFA7pPYalqMK+x9mM7RIdzQwtADPMP9aMU1 X-Received: by 2002:a17:90a:9b8c:b0:298:c136:2ffc with SMTP id g12-20020a17090a9b8c00b00298c1362ffcmr349026pjp.45.1707851920001; Tue, 13 Feb 2024 11:18:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707851919; cv=pass; d=google.com; s=arc-20160816; b=Ei423nSKaDjAPq1CJSM7Z6/v3fV3IoNbZ5sew/pknGE7mHg8JANNGSyfm3CVHbZ+pC UcQlyDYb3MXqGIgJnMyDhqK04JURI6/JefxVhmky1ODsO39qn6C4aoK6JC/v/dRiCWHx sYqF9ukjsWUpmv4lWlWxG44m3i5apX6XvpQ3KgQpUp86b1A0Sggqg/6DhE5WNltLKvth JZjriq/rZUs1qRrxCjM57SD/f49INbfBFTFRYMkrCMMnwVvM+27mw6vaNEUX7/rgMPG6 kAFt678+qLy6E8k6P+RdoR9USNC+4qTA5t5YGgGLDosQW0Z19bbnoWealHrvTabnC9fm Vkfw== 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=yCX6UoytF2NcZYARqpkHqcF31HoM7Upx7WmM/K8jfRI=; fh=NwS29oGC/uesuFZy8w94nGZjZnInXuE6WYeSxRsKl6s=; b=s0kckSujDm94GFXJrcECF+WgIlpIrCDZDwEVLPfkxf90L48aB07z4+Ly/9DRQChn09 BqzYBYyVq7nXN9gA2U08nepItUhSYGYunp/duAEOLrKF126oqfgQitERCkErVPiKu4// 9B++Hj9J9lUYtBYMLlB3ddu4JC6gCBD1A9Ov9C3xyWMfgSo6i2ddQiCnwAf/SlELUKaA p/HfFX60E4W9vm7Ce1wsVpnaTAVhXqAX4sv2c2bVuDzQqw0DlteAKwSImBnCgw14RZTk qO2vlpubmOhTinxSjMwl3abxqDJaasFxFe/N3XKVzhKoNuqodx7SbUAwl8NYxB9OO+H3 5oxQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hZEvGTPT; 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-64149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCXEP4Oc4h2ytP2IsYFdHBnZlB2oSZh3tSrp5gfZMrGemY8qNXdIy4dn7un/j6FIKJbZDH/LBJ6mEPoBZVJw82FO9QnAP/7YVnJBd4ohtw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bx23-20020a17090af49700b002931b3873dasi2402223pjb.22.2024.02.13.11.18.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:18:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=hZEvGTPT; 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-64149-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64149-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A4F0828288A for ; Tue, 13 Feb 2024 19:18:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 327CB376FA; Tue, 13 Feb 2024 19:18:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="hZEvGTPT" Received: from mail-wm1-f42.google.com (mail-wm1-f42.google.com [209.85.128.42]) (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 641711CD10 for ; Tue, 13 Feb 2024 19:18:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707851911; cv=none; b=V5uHQuaN0meldFtHwP9wAOeuwndI6A9EEpkdxykRCpfs3SpI7m+9jLq9IVpag7FBOxGzivfgNqkLpP+u/sLHNHqAjE16pKWRabJZd/Cpe+JZ2iovEM/U2yaAXfE5RIfHL2uUj82c9zPayXGSeC2iX0mGXSy8S6CSWas3KJ1PMyA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707851911; c=relaxed/simple; bh=a5mMRWzTFO8UllGnXCIR+TWz9Xn1DAwcV6AGubTqrF8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=cSbEZP2/SrF/8JT+58ke0JC7ogRQidNLQENh66OXjB9kZrmpaO4qJ22cJ2YGWOA6fPlMx+kTy5GWNfAg+qaeLq2v+uERgjxYTP1XzJFX46+BEjZoK3JtFuMJ8OeAvbxi9cqAk8/cSpM3y/4oX7h9xzDhya8UI4D6iCbxnaHBTEg= 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=hZEvGTPT; arc=none smtp.client-ip=209.85.128.42 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-wm1-f42.google.com with SMTP id 5b1f17b1804b1-411d5dd7924so3106155e9.2 for ; Tue, 13 Feb 2024 11:18:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707851907; x=1708456707; 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=yCX6UoytF2NcZYARqpkHqcF31HoM7Upx7WmM/K8jfRI=; b=hZEvGTPTsxHkB4dexv/sIqnOe39nr2IK+1KSjy+5wlC6NXB5D4H/iQBMPMjFm6R6ry D4whKsYpLIse8I87XO2rHNZbP3htNbrLCBDgo/SblGeJVFMX6vg+3CKjkfHW++yI+b0M evkWPApR2niJA5qnsNlQ5CpmoaOUBd5wUsRZUlC+I8y3pt0pGz/zrfuck2MgqLghf4rn ojtiyUer4WDDvRFRnPyJG53g5FT4uqXHN3yfDUZP0nwUOY0GVgWKrefJ3obLVNWmN8Id 8/kmfHi9NAVoe65+BRuhEDyV0O/II9lTfMOA4gXyhhMJqIEE1QT2M028LuCzj1vQlA9+ ek2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707851907; x=1708456707; 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=yCX6UoytF2NcZYARqpkHqcF31HoM7Upx7WmM/K8jfRI=; b=LJrmKhFWSX+L+wWctfSLEx8WSDRnX15VNmyEJI1SQx+CCbyc2bEFOED3bYINc1qO8d g5aiibyog/O0lltUtpt73P/7UAXO6Z/MZrObpuhZLXEBahjq6H1/SglQoY/jy9tbHkR9 OFvgDnfPnCRJ8sE+rY5DJz5sdInhtmocr3yHU58I8v7aiWyEBjIBj6T1Lp1zjgaEyr6y 0SqD0Pyf1h9z4g2dNTAw4KDd1Frqh6nHJnVJtSh4zku0GMUu5N/i0bdORP2HzzmHEQVJ qCimYS+0d0hvHiw3+ft+kyg/oplixRAt4fgelE8IZf1ZpbJ5raHzoyMUZcqVnXGt/0W6 caQg== X-Forwarded-Encrypted: i=1; AJvYcCVj1PulxJ7omMDL2tWAP37QguUi/frzyJgb+yDRTpPp83rdTs0sLqHaDRTNxfWcJgAijJAZjZDfEmOyZtw/VSSEOrGUQzum/rn4kGFS X-Gm-Message-State: AOJu0YwYLr89LSi3XiR69dobMr1oIhaTR8ZodmqAha2CRQE52niK1oO7 xVo+LsGrcu1RxXkZo3gIDWlIGW4ITqcKSoxBobei3LrOctp51ZRSwOQoIZP3REhGOQvr55RL+an J/b/T+k6YaCjRyOR98eD//GdZa2V7UrJnfarp X-Received: by 2002:a5d:54cc:0:b0:33b:45b6:b589 with SMTP id x12-20020a5d54cc000000b0033b45b6b589mr160513wrv.66.1707851907393; Tue, 13 Feb 2024 11:18:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240213001920.3551772-1-lokeshgidra@google.com> <20240213001920.3551772-4-lokeshgidra@google.com> <20240213033307.zbhrpjigco7vl56z@revolver> <20240213170609.s3queephdyxzrz7j@revolver> <20240213184905.tp4i2ifbglfzlwi6@revolver> In-Reply-To: From: Lokesh Gidra Date: Tue, 13 Feb 2024 11:18:15 -0800 Message-ID: Subject: Re: [PATCH v5 3/3] userfaultfd: use per-vma locks in userfaultfd operations To: Suren Baghdasaryan Cc: "Liam R. Howlett" , akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com, david@redhat.com, axelrasmussen@google.com, bgeffon@google.com, willy@infradead.org, jannh@google.com, kaleshsingh@google.com, ngeoffray@google.com, timmurray@google.com, rppt@kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 13, 2024 at 10:57=E2=80=AFAM Suren Baghdasaryan wrote: > > On Tue, Feb 13, 2024 at 10:49=E2=80=AFAM Liam R. Howlett > wrote: > > > > * Suren Baghdasaryan [240213 13:25]: > > > On Tue, Feb 13, 2024 at 10:14=E2=80=AFAM Lokesh Gidra wrote: > > > > > > > > On Tue, Feb 13, 2024 at 9:06=E2=80=AFAM Liam R. Howlett wrote: > > > > > > > > > > * Lokesh Gidra [240213 06:25]: > > > > > > On Mon, Feb 12, 2024 at 7:33=E2=80=AFPM Liam R. Howlett wrote: > > > > > > > > > > > > > > * Lokesh Gidra [240212 19:19]: > > > > > > > > All userfaultfd operations, except write-protect, opportuni= stically use > > > > > > > > per-vma locks to lock vmas. On failure, attempt again insid= e mmap_lock > > > > > > > > critical section. > > > > > > > > > > > > > > > > Write-protect operation requires mmap_lock as it iterates o= ver multiple > > > > > > > > vmas. > > > > > > > > > > > > > > > > Signed-off-by: Lokesh Gidra > > > > > > > > --- > > > > > > > > fs/userfaultfd.c | 13 +- > > > > > > > > include/linux/userfaultfd_k.h | 5 +- > > > > > > > > mm/userfaultfd.c | 392 ++++++++++++++++++++++= ++++-------- > > > > > > > > 3 files changed, 312 insertions(+), 98 deletions(-) > > > > > > > > > > > > > > > ... > > > > > > > > > > I just remembered an issue with the mmap tree that exists today t= hat you > > > > > needs to be accounted for in this change. > > > > > > > > > > If you hit a NULL VMA, you need to fall back to the mmap_lock() s= cenario > > > > > today. > > > > > > > > Unless I'm missing something, isn't that already handled in the pat= ch? > > > > We get the VMA outside mmap_lock critical section only via > > > > lock_vma_under_rcu() (in lock_vma() and find_and_lock_vmas()) and i= n > > > > both cases if we get NULL in return, we retry in mmap_lock critical > > > > section with vma_lookup(). Wouldn't that suffice? > > > > > > I think that case is handled correctly by lock_vma(). > > > > Yeah, it looks good. I had a bit of a panic as I forgot to check that > > and I was thinking of a previous version. I rechecked and v5 looks > > good. > > > > > > > > Sorry for coming back a bit late. The overall patch looks quite good > > > but the all these #ifdef CONFIG_PER_VMA_LOCK seem unnecessary to me. > > > Why find_and_lock_vmas() and lock_mm_and_find_vmas() be called the > > > same name (find_and_lock_vmas()) and in one case it would lock only > > > the VMA and in the other case it takes mmap_lock? Similarly > > > unlock_vma() would in one case unlock the VMA and in the other drop > > > the mmap_lock? That would remove all these #ifdefs from the code. > > > Maybe this was already discussed? > > > > Yes, I don't think we should be locking the mm in lock_vma(), as it > > makes things hard to follow. > > > > We could use something like uffd_prepare(), uffd_complete() but I > > thought of those names rather late in the cycle, but I've already cause= d > > many iterations of this patch set and that clean up didn't seem as vita= l > > as simplicity and clarity of the locking code. I anyway have to send another version to fix the error handling that you reported earlier. I can take care of this in that version. mfill_atomic...() functions (annoyingly) have to sometimes unlock and relock. Using prepare/complete in that context seems incompatible. > > Maybe lock_vma_for_uffd()/unlock_vma_for_uffd()? Whatever name is > better I'm fine with it but all these #ifdef's sprinkled around don't > contribute to the readability. I'll wait for an agreement on this because I too don't like using so many ifdef's either. Since these functions are supposed to have prototype depending on mfill/move, how about the following names: uffd_lock_mfill_vma()/uffd_unlock_mfill_vma() uffd_lock_move_vmas()/uffd_unlock_move_vmas() Of course, I'm open to other suggestions as well. > Anyway, I don't see this as a blocker, just nice to have. > > > > > Thanks, > > Liam > > > > -- > > To unsubscribe from this group and stop receiving emails from it, send = an email to kernel-team+unsubscribe@android.com. > >