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 7F643EB64D9 for ; Fri, 30 Jun 2023 02:08:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 24A588D0005; Thu, 29 Jun 2023 22:08:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1FC7B8D0001; Thu, 29 Jun 2023 22:08:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0CC998D0005; Thu, 29 Jun 2023 22:08:14 -0400 (EDT) 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 F07928D0001 for ; Thu, 29 Jun 2023 22:08:13 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C195A1205C9 for ; Fri, 30 Jun 2023 02:08:13 +0000 (UTC) X-FDA: 80957779266.27.B3D9900 Received: from mail-yb1-f177.google.com (mail-yb1-f177.google.com [209.85.219.177]) by imf30.hostedemail.com (Postfix) with ESMTP id DC8E48000C for ; Fri, 30 Jun 2023 02:08:11 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=gwBmbPur; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688090891; 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=kh9IVshRgKbatuJLHHRKBuSrhlgLbtUglR9X5QKFVAU=; b=iTKMD+Ra+qQ+nATCvrzPVfpSnOSeoobnxuVvvh2BK3f9eSTLIwDWP9e6DEwqoepzHV9RfD GUfj7yKsQBFwNNCxOWXqpsBpvfgDwKtP/k1opheN+BaqW1IN34O03C/IyCV7Xza7v00b8C oxFRUiGHO+QZIYZ+w9NskM63HSpPHHI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688090891; a=rsa-sha256; cv=none; b=mMkl2PEHfbuOMqYZ7kOrTDmZm6PEsa2SDQQ0wEnI36eTHT07CZ8EWa+AkRAtdVK1ZBAu0M Bmf4m4gu7S/0LilZ46yZV3fdvwIG1CzlgDjCRmXGgALMTgofKUmC8SUuipMchO+QqfHA28 6fNM63TZKxyZuO5tk1o6Ioy42OnQp4c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=gwBmbPur; spf=pass (imf30.hostedemail.com: domain of surenb@google.com designates 209.85.219.177 as permitted sender) smtp.mailfrom=surenb@google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f177.google.com with SMTP id 3f1490d57ef6-bff4f1e93caso1269505276.0 for ; Thu, 29 Jun 2023 19:08:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1688090891; x=1690682891; 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=kh9IVshRgKbatuJLHHRKBuSrhlgLbtUglR9X5QKFVAU=; b=gwBmbPurzkfYes2MIljJwdoCAcB+If6Ml+DMB5DLexuSd0XcB8hBYwx+v5h4cF3hnQ HG4+3YBFyz/37nNw7ib3I4+3kxDQZi3QiERxlSkP/0doMfFOHo911JPrF5XTr133Rnht zBuXrJaxnjL3sxAw8kmPwu57qFZHMNkwL0ja8n0txeTR6tA1sKjnUieu+yNutkVSjcbk ffjXGKgTQisJz2ui3CL/8D0O7xAKIf16vX6tSPA/Kc9MMweV0CsWv9xXeYMswGsWkwIJ L8ZMFeJD9AgqqRh7w6hX4pL54FgJb1wGuRXbunzzRGfzgDlPAVWfo9HlJuPNLEhBhsIE Ay3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688090891; x=1690682891; 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=kh9IVshRgKbatuJLHHRKBuSrhlgLbtUglR9X5QKFVAU=; b=C1KByUFHZRjzOia/gVdGaLuKeMW40FiouqwJeBduliIUFkhK84AVulKJm9LkCtdHJB jj6csZvAaCWwZqeSNgv7UfBcRDJQvqO/1GTz2QUW+ok8hD8VDuaNu1/zl1labVT0WUMQ loltI7AmjeC4ZClDeDJXKZhnid/aGklJ2PxwfAhBo1Tm9drKsvjlcjaWZGBVfphKXnq2 AlllJDRshdOshwSkTScZFDPU8ZbyP+96z0Xl6+HbrwH5fHczsFu6vlig8MJYufslX06q Pmx8+t22SOBW0bn4G+2ZtEkHcnuFv157rE9oSEK8i5ptR0tNf5TbbxuxOK5fjVGT2Cce GjtQ== X-Gm-Message-State: ABy/qLbNnxsKldJ2sSzh1bqJDSKVifB+T7JWPPGZHtVLYyvaRe+K8kZ1 JX4IaLy4HqnH+A0GKA2Y+iP9Xz9Bx256fuzpJauiMA== X-Google-Smtp-Source: APBJJlHGkt0t9d4kMIkTr5ZsvGG4e7Epya0TCKGzmPViHhBAkeKAn71oAque5IgOgZWTHT+L1N9H59qQMlaw92G/lD0= X-Received: by 2002:a25:d112:0:b0:c02:7c99:629 with SMTP id i18-20020a25d112000000b00c027c990629mr1519896ybg.34.1688090890831; Thu, 29 Jun 2023 19:08:10 -0700 (PDT) MIME-Version: 1.0 References: <20230628172529.744839-1-surenb@google.com> <20230628172529.744839-7-surenb@google.com> In-Reply-To: From: Suren Baghdasaryan Date: Thu, 29 Jun 2023 19:07:59 -0700 Message-ID: Subject: Re: [PATCH v5 6/6] mm: handle userfaults under VMA lock To: Peter Xu Cc: akpm@linux-foundation.org, willy@infradead.org, hannes@cmpxchg.org, mhocko@suse.com, josef@toxicpanda.com, jack@suse.cz, ldufour@linux.ibm.com, laurent.dufour@fr.ibm.com, michel@lespinasse.org, liam.howlett@oracle.com, jglisse@google.com, vbabka@suse.cz, minchan@google.com, dave@stgolabs.net, punit.agrawal@bytedance.com, lstoakes@gmail.com, hdanton@sina.com, apopple@nvidia.com, ying.huang@intel.com, david@redhat.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, viro@zeniv.linux.org.uk, brauner@kernel.org, pasha.tatashin@soleen.com, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: j5qjnh567zffht9axfdjhytd77hog6mo X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: DC8E48000C X-Rspam-User: X-HE-Tag: 1688090891-32719 X-HE-Meta: U2FsdGVkX1++Br2kqpTge8/pzbtxDr6+TigE33f6B0m51etNpwpxvxbo0ubMh7TmBSj1NOJnunK6O2riyc6ZmrQEPiExmdFbOQVqyQSGYJK6tWdbe8EEkbcxFDKu9FutAlfkppoUw1676UWvMxR+x6FbyEL3CGoZ939rH47YNVKcWkz3MpgRhSI5AYzOiWIBmjviknfG9xqIBPG4KEg/r4ZhWGoI7+yWuqQ99adQu0bVRksCfAn5x9gvlUXeAFdFV9HKzO9WQRUXvjdheu3Nx3zgnO+m/1yJ7y+MqObv2EhF23dvKsWQXhnnnamEWbEVAUDQpvyJWFuGwpHfnQQrC7zSTTxiWJ+OIx4J61Zzy4tiq6Z11667XG+zsVwJqwvdsUYCQN/Kc1UXQaHFjrXN9RZjveLHsp48dqLkSjDxwpewJ21tm9MLExEtmKIX1+DWqX8ndkxZFj6Ysz9AAcysxKi3GNSs2q7OgSvZsJQEquUIUFs45CTfP6mPQtdZcbTHIpxnrcmuOmyf5M5aLsffRpdUQ0+Pcp/6nCyygfUp52b+wi9M24fF5WiLr7ZYhV0LdrnKWzN45q8LnVPBSLj1+riNDxmulOC0iXgaWOwjEe9EBOQtRRyCh1DSgO3HXz3pqFnsZucEr4MoGdVkupUjJVPNrlQFBzED8YHWqWVjq61bL3eCifsPTq07A0TvfSpeR35WCZ9+d0THVHrxBenQhs//e5ZC1uMoyFnkshN6b0pXDBWBTFAVbrzB0Z7K6PvF83HqkeH7tK8pgdg+y4aDCqq8LYn9xgFypG4REarQ9w2RvGpkTirBR8gm5eFG9HoDc6in+sPMOVqgIKsgFz2nViUvmUAaWYLTjH8RqaGovnBdV3yU1kTWwWJ2Ea8YBLapBv67MBLMDj7jRvwvmL7UeJZBCyodbqS7X4Sty595KJ5H27rp5t+l0WPhZT0RGWJ4UCMcTSQ22GxKZ3hiP10 td7qu2Ks 3FZYYPxh2itOG2GEeLxvTT+PVPjT2Pl0BO+7VovqVV+w9qe5taU4l369ipDHalhEF+QWrqbre299fk6wuNRqmUYot2e2oFwYGhhQCX8sct2NVdSPM9V7uqkY+ZmYVDTIhAFhvISzwgxhrVQuwaA6EmhWjPRDAuyNK+5uwjrjk6h4mugKH0kZrYi//kCEHnz1B9L7zAfQgwPEdZCGKwXjK3sLh2ZCICiI5cLGN+wcZKS2FlgwAtFyGNHZLCM3gJahd2Pqw6wsPjBDxODLiiZ2wjVa810fveIZJapW9SEWlZFV8K/cImjIIHHwDPbpmoOLHQLp0v/f5kGL/1Uk= 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: On Thu, Jun 29, 2023 at 9:39=E2=80=AFAM Suren Baghdasaryan wrote: > > On Thu, Jun 29, 2023 at 9:33=E2=80=AFAM Peter Xu wrot= e: > > > > On Wed, Jun 28, 2023 at 05:19:31PM -0700, Suren Baghdasaryan wrote: > > > On Wed, Jun 28, 2023 at 10:32=E2=80=AFAM Peter Xu = wrote: > > > > > > > > On Wed, Jun 28, 2023 at 10:25:29AM -0700, Suren Baghdasaryan wrote: > > > > > Enable handle_userfault to operate under VMA lock by releasing VM= A lock > > > > > instead of mmap_lock and retrying. Note that FAULT_FLAG_RETRY_NOW= AIT > > > > > should never be used when handling faults under per-VMA lock prot= ection > > > > > because that would break the assumption that lock is dropped on r= etry. > > > > > > > > > > Signed-off-by: Suren Baghdasaryan > > > > > > > > Maybe the sanitize_fault_flags() changes suite more in patch 3, but= not a > > > > big deal I guess. > > > > > > IIUC FAULT_FLAG_RETRY_NOWAIT comes into play in this patchset only in > > > the context of uffds, therefore that check seems to be needed when we > > > enable per-VMA lock uffd support, which is this patch. Does that make > > > sense? > > > > I don't see why uffd is special in this regard, as e.g. swap also check= s > > NOWAIT when folio_lock_or_retry() so I assume it's also used there. > > > > IMHO the "NOWAIT should never apply with VMA_LOCK so far" assumption st= arts > > from patch 3 where it conditionally releases the vma lock when > > !(RETRY|COMPLETE); that is the real place where it can start to go wron= g if > > anyone breaks the assumption. > > Um, yes, you are right as usual. It was clear to me from the code that > NOWAIT is not used with swap under VMA_LOCK, that's why I didn't > consider this check earlier. Yeah, patch 3 seems like a more > appropriate place for it. I'll move it and post a new patchset later > today or tomorrow morning with your Acks. Posted v6 at https://lore.kernel.org/all/20230630020436.1066016-1-surenb@go= ogle.com/ > Thanks, > Suren. > > > > > Thanks, > > > > -- > > Peter Xu > >