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 15A62C4829A for ; Tue, 13 Feb 2024 19:18:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 885898D0011; Tue, 13 Feb 2024 14:18:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 835658D000E; Tue, 13 Feb 2024 14:18:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6AEED8D0011; Tue, 13 Feb 2024 14:18:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 574FB8D000E for ; Tue, 13 Feb 2024 14:18:31 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id EA4CE140C9B for ; Tue, 13 Feb 2024 19:18:30 +0000 (UTC) X-FDA: 81787741980.21.96F7554 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by imf20.hostedemail.com (Postfix) with ESMTP id 1F37B1C0022 for ; Tue, 13 Feb 2024 19:18:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bQcwA55C; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of lokeshgidra@google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=lokeshgidra@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1707851909; 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=yCX6UoytF2NcZYARqpkHqcF31HoM7Upx7WmM/K8jfRI=; b=wD/jf5bAxw5p0+H5w5SQst+3PZFWRTCSG5xYD3/8xdHNFDsq85aCSkEfOYQrkk3+NPl6YH Wi/K4QqoXhlvvzWLXQapm7kvHAlbOhVVe6tcpE8FSMmCufJ/0LFumwbVM35pnMHCDn3ZXT ixPqPsYBxtG3VHSLopeDTU4JWPmpe6M= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=bQcwA55C; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf20.hostedemail.com: domain of lokeshgidra@google.com designates 209.85.128.51 as permitted sender) smtp.mailfrom=lokeshgidra@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1707851909; a=rsa-sha256; cv=none; b=IegVeuPa1EKPM9Q0LSuvOIeR/95WYltXorWbDphKq1PVCL18O7c5J/XL67s5Ud+bR3xPSM 24A94pUN3AfhkvL2tFbMX2Zo18LUrhO45THXO+D+7/UEFflmhjre4+7LfvtGoTXm2hR28Q GSDZCy4MEFFBEPpME838mxVGSS8D6eE= Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-411c779ab2dso6490905e9.0 for ; Tue, 13 Feb 2024 11:18:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707851907; x=1708456707; darn=kvack.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=bQcwA55C7pte6JlIq1qEVWI2TPamE31jt6RK9M8C5OKMJE/l/2PtnSld2Q6SDvoJYw /yxK9bjVlOFPmzRk0XOzRCN0sEa26ydDhollVOSBckCMTB8KdR1bwUfZzw9k/KIi4Jg9 m7Bx/iLC22ZdqPRJ91LX9pYbHkjfJ0QffLYFC7OEQf0lCogtAtKRlvmPiGpOwFh3wvYV c5uQc5zfwvH4KPkYstkVV1GIbJFdi08ezHPNKzxvj/RzLHZR91nCQk6eTV7V1jDRR8Dl VsrnfQd85wluXSHvFOqKaiiAnP+vkoz2I+XCnu4QZfyYzFmfbo3zs17frCmYZUBDkZkX jGjw== 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=YiyDroC1mY+y3tFUCMvt/ZnwwzoxTDp9nQLW67tp2iXjxBm/7IR2Mdkls7Vxhzh9/m w9JsGaANPF+b5rhNiHMRqusomipe+nsVmno52WkbPwfB0PiUOhlS2tzLpULFQX+Z6kqJ HxQxunAM5ukU27Jdm1GIYF+Q/FF+Kft0zs5f2U9mGAl04AZn9a/91zedZMZ5UQGoaShr 74mCCWzasvgSTRKLj2+X/nUjKadisESc43jkV2WsGw7KEkJKmv976myG48hweWpDlJ3D m9baNes45xg1scWcYYLgiQrZJOnQVDW2wS+kPlEjcPVozHjxvMv/3RsTbMKh1Uc5x5HR eIdA== X-Forwarded-Encrypted: i=1; AJvYcCVGUho7keJ4PwVa7IEz8NiJN8pezG4FTyPgFm/dAUkQdjgtTslEdecGTEUKqQguBSVk6j+H1hmav4+lOhzirUq10cc= X-Gm-Message-State: AOJu0YzR95dyyKzDXZKI4cqhCkbsz0F1P1oZN0g/FaO6/W9bF/8+mNmD eOtTd4uRnicFBGslPc8EsPXAYscq8Pga5l7RomicImia6V6NlqtXoSP2JH4WRsmBrxhicBaDmtE YznrCMxkDr+6dt8ei5AJE9PyHpSgvvAfhtbq1 X-Google-Smtp-Source: AGHT+IEMHwkro+xsqN6z9qNfjrhRyFhmvQhXDoENBJPQ6ipKebPJrHzy8YnGUaSmsX5qm/wdi6FYHsoNKdwoTN72x5c= 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) 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 X-Rspam-User: X-Stat-Signature: xahk9wkudz4xz9mx5i7qm9jsztxduc78 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 1F37B1C0022 X-HE-Tag: 1707851908-147484 X-HE-Meta: U2FsdGVkX19y+2XIgYS7f/0zb8EThNcPChr/J2yVcyApA4Q1NJ7Y2R9S0aJ2hbMBXPVU8d5o3aLYcH6rikZ1sCgRpzLIF2WLjB/a0CPmQDD/10MCR88sj3NK6CR7nH1v/G/ggSNtWlp5c18Wva+gaZXvCEkKPhWsCquFDPEG89gIWk1KCc8XVA823GsX0V5vo5F9Uvf8T5a6+Rwq+HwYz1zWTOsHjz/gB5f7qHb4jXVtERKNaKnQgQL8PQvbNaOrfBT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.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. > >