From patchwork Thu Feb 16 05:17:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13142522 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 8536FC636D7 for ; Thu, 16 Feb 2023 05:19:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1B9B56B0078; Thu, 16 Feb 2023 00:19:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 169AD6B00AB; Thu, 16 Feb 2023 00:19:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFE426B00AC; Thu, 16 Feb 2023 00:19:06 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D9BAE6B00AA for ; Thu, 16 Feb 2023 00:19:06 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BD8E214108E for ; Thu, 16 Feb 2023 05:19:06 +0000 (UTC) X-FDA: 80472001092.09.D72D1A3 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf23.hostedemail.com (Postfix) with ESMTP id 130B4140006 for ; Thu, 16 Feb 2023 05:19:04 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sqrDU+BC; spf=pass (imf23.hostedemail.com: domain of 3yLztYwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3yLztYwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.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=1676524745; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=2G5AxmmOVrsRnXlCrW6/hvh5FUxSjD+0mS6LSWzYfho=; b=vhZP/K31DCApeMaZzHGTj4FRP2p9m4dS1jTKb/zp6M1RpnnFq0c3Iyve+jfV7LnUlxnWhJ /Miy3pMbtbVF3togZOG4jboVTZtihrdvpN46g9vLNau56iSdx52CPhbXoikHNJGUOyOChW PeeXfnp2V2KXQCxROxwZIL48xAXuJdg= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=sqrDU+BC; spf=pass (imf23.hostedemail.com: domain of 3yLztYwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3yLztYwYKCB8NPM9I6BJJBG9.7JHGDIPS-HHFQ57F.JMB@flex--surenb.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1676524745; a=rsa-sha256; cv=none; b=vmxhQslFBg1meuq91nH1p7eKa1s3Oi3tp7D/KbDoO3YJPRj3tIe6JoTan+S+TOHeS6T7wz LcRma6QUnmbzRh8bs7l7NN3qPRjPnUAt5r9v+tzi3DFQkoQTO1nPi6K/ldZYv7ENsp7l2k yhJFMMnB+pMLxDu8rceZocB0m4H2QmU= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-52f233aff21so8610067b3.7 for ; Wed, 15 Feb 2023 21:19:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=2G5AxmmOVrsRnXlCrW6/hvh5FUxSjD+0mS6LSWzYfho=; b=sqrDU+BCO7AIuj2EKpC5JjJjchpfs4e7nICzmha43sQtLyfoiEZwLUOwsCD209H5Ui lu0l/EwT0lWrDRHYoglaYWRXNYPJ1g8O+GpgkaLO5UTCsF2sShD98xQNq7PDWtH66r6g ZsB+oua1JfA0KymwRm2/PgdgPfreEDDqnwQyHLX1ndmfndQgCQh8neVqDDo8QNluQIit psaYv9QythR+X2eyBbc1tAjHl/fZRS54lIuiB1Ux7odRjp5k2KlmRL+IIzajgpgWcCV1 agKdJl/mJ1QtI4UVDWAjmp+dEFlVMZYnML3DG7HfRey4EeaADk1hZvmemdIk3Yb/sCoK 4MXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2G5AxmmOVrsRnXlCrW6/hvh5FUxSjD+0mS6LSWzYfho=; b=Z+aMus8eghWmXTSp3n4UJXOL5G0Aapzg/g+7eteaFyIn4dxSj3rzra0DvRySYToyH4 IoUz3Mwc7ooQ/y98t2QcGssOAHy9QoIEghgUgt0KicSqvGx/jnOljc2iuBXeeVXfahLx gC1zs9bNnpY92qos61R7dkYMHBDQrhJ8wANCGdzFgOE/mDx9v6ryOFfcBGbalQeQd7y8 Ls2wFGWVXVOtOV876/I+OkbbRZdscQc9urvge78eQsm2Grpkn+rDCw6CA+iy55cMjb6X DUBhnShxkWcrKnIapChR0c3DLovgI1HIPI83GxxYZbNP+75MOw36LVK4kHGo7+2SU67I Nxrw== X-Gm-Message-State: AO0yUKVvVd7PtICQv4smo/hghR+uzo/S9MwMnC1ZCRHcRnf2Y+XkeBuF WpIh415U8rZt2DrdPYXDUTOkO4TYqF0= X-Google-Smtp-Source: AK7set/QuR9OxnmNolAau/sd0Kj8g/BkdB7enEU88ehNvfonJ32Y6Yzdt5dUleuzBy4yluRtxlQTgtsiJAU= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f781:d5ed:1806:6ebb]) (user=surenb job=sendgmr) by 2002:a05:6902:13c6:b0:8da:3163:224 with SMTP id y6-20020a05690213c600b008da31630224mr7ybu.0.1676524744013; Wed, 15 Feb 2023 21:19:04 -0800 (PST) Date: Wed, 15 Feb 2023 21:17:44 -0800 In-Reply-To: <20230216051750.3125598-1-surenb@google.com> Mime-Version: 1.0 References: <20230216051750.3125598-1-surenb@google.com> X-Mailer: git-send-email 2.39.1.581.gbfd45094c4-goog Message-ID: <20230216051750.3125598-30-surenb@google.com> Subject: [PATCH v3 29/35] mm: prevent userfaults to be handled under per-vma lock From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, chriscli@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, rppt@kernel.org, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, leewalsh@google.com, posk@google.com, michalechner92@googlemail.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, Suren Baghdasaryan X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: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VaBj17ZuLepqOa8BymwRs9se/2iHGKBwphHlm/XsiAbHCwWFpKp9U5ODiLKwM2gf3IlCt80kl2kxYw9w+c/c6Wsrg4wQBSEhFXdYsMCFWr8BDgLJdaUR3mi2XcVhkKhY90Xj8L/dq71j8HRaO1il8s6TZroDUkpxpIwAl6JAqA0DbpvpCCVcCiwKMIERwLU9NnBDUHxMQN/bPblr6sqqJR1LCh/CmgAwzhS0F9B3y7d5mA9z4RMZ+KlbxZGdqSZPiXdMjxbW9x6EGBxky2nrXPqEeJemjj/Se9HN2PsRYX2uJC/28fkIUUjn3BzezhYLuaVFKoSNBKOmULWtfi49xLl+uRgAnIYWGJHGXtVNeoYRJJku2cqRvIR/6wT9NSt8UJuzmbPx/u51/UfkBgC0msRG86UbZtmiLjwmRIgre9HHSGIuHqP++ikeMjD8HgRLbrn+1/VkSJ2eS8esTJPrmCkCQfSb3zzQ8VnJJM9EsE42CJ8vc6DgpDnea8Nn0wfwpwvNwOEu/0q4f5mlaNaZ2CFXeTSnJTnB5qQHqjCKdX4jxuqqqGMkFtntcJKxn2oQo/NuHmZLDIqaKUhpa64krc0VF/q7l/VjiQ9k9stkVW80H3tXU6GGpmp3Su5ys7A27uWiB9MpPv12Dog== 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: Due to the possibility of handle_userfault dropping mmap_lock, avoid fault handling under VMA lock and retry holding mmap_lock. This can be handled more gracefully in the future. Signed-off-by: Suren Baghdasaryan Suggested-by: Peter Xu --- mm/memory.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 555612d153ad..751aebc1b29f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5254,6 +5254,15 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, if (!vma_start_read(vma)) goto inval; + /* + * Due to the possibility of userfault handler dropping mmap_lock, avoid + * it for now and fall back to page fault handling under mmap_lock. + */ + if (userfaultfd_armed(vma)) { + vma_end_read(vma); + goto inval; + } + /* Check since vm_start/vm_end might change before we lock the VMA */ if (unlikely(address < vma->vm_start || address >= vma->vm_end)) { vma_end_read(vma);