From patchwork Mon Feb 27 17:36:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13153990 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 D1558C64ED6 for ; Mon, 27 Feb 2023 17:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AEAE28000B; Mon, 27 Feb 2023 12:37:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 65FAA280001; Mon, 27 Feb 2023 12:37:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 526B228000B; Mon, 27 Feb 2023 12:37:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 44C4B280001 for ; Mon, 27 Feb 2023 12:37:44 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 15F3C1A0AF3 for ; Mon, 27 Feb 2023 17:37:44 +0000 (UTC) X-FDA: 80513779248.24.D118886 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf12.hostedemail.com (Postfix) with ESMTP id 470EB40015 for ; Mon, 27 Feb 2023 17:37:42 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ltU27wOg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3Zer8YwYKCFQEGD09x2AA270.yA8749GJ-886Hwy6.AD2@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Zer8YwYKCFQEGD09x2AA270.yA8749GJ-886Hwy6.AD2@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677519462; 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=GQTFxYC9vfA9jf0qnv7gyPX3j3jACtIk3rCkUF/FJDY=; b=peinB+J8lGzTjuei8KTNZHEWXGSf7WUmrH2w6lusATvoHoXFePyUH90R3U0f1IvGVhS2D9 MySljc64troWJFQXebogJshdigR/MHObnAtZTkm7E0h9LX8rCF/6aXmXaMkdM/oBnD7IUq CvjtVC2hsrOfsuRQMzEI2MJ/1xqVq2o= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=ltU27wOg; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf12.hostedemail.com: domain of 3Zer8YwYKCFQEGD09x2AA270.yA8749GJ-886Hwy6.AD2@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3Zer8YwYKCFQEGD09x2AA270.yA8749GJ-886Hwy6.AD2@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677519462; a=rsa-sha256; cv=none; b=dGi2dVwF4NogdC2BJZroop85+o529wkXV+g5IVmSv+j0xDrlEY+lYUJLRwUwdi47Yv7I5F YrIuhpfaQWqvRWfqjEzxn4JXm3IjV1ywvq8I130nuQVektRvuWUVDzXvepxi/nui+qyhoF 2vYUK56/LJV9CJ3+8aVws7tLQ8vo6O8= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536e8d6d9ceso153598797b3.12 for ; Mon, 27 Feb 2023 09:37:42 -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=GQTFxYC9vfA9jf0qnv7gyPX3j3jACtIk3rCkUF/FJDY=; b=ltU27wOgGhATSjAgpKpsKxT2cYCgBXmJjPP7Vlf66xgvCPyy9Y+Q9/fs6W0SzgF7Jz AXhDZAKO1i4O/EUJVs8bawuizzatT9I4VypR9NCPeHEKAKGbhmDhab1/2DAQYWqdJDRL SlVcHXqIAb6AFOFtWd+XMHyyClJx99DPXWU2Oc6Hu8D9kLp3zMzECqCZ3BlXkfECm7ag vCaq44G6you6yfY7K1dBcUrSymqL5XjWSs2bzGHgp5mJNuIzmcdPLIfUbaNclxIn5eWy D+XKgbxlwvwdAgDoeqhoNS8X6MSQFy0GYxkz6nxN9qX46TIoCwJZF4rSw2+QWBYvnyX8 AYFA== 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=GQTFxYC9vfA9jf0qnv7gyPX3j3jACtIk3rCkUF/FJDY=; b=tGA93NK92jq9OGjibvIsI/XLOZ2jfR6sxJUSbJXXd9KEF7yNVb4jNwKgLDBrXjmhrl UhqYMumSHmBGtgT+tzTzTm7XxogQc08qjX4OYr9rZxsPqanXNbfReZfpuTa/y/Q470yQ kBrFHVskDyHxtAX4JlQ2PXHRfcPu6WeUccq3FBgvw3/Vjd7apWba9kzaFAFtl2dzcqui P9raAc13nWZKbOxbOd/7axyZ0McfdOO52VsfQgidhTJYywqTlztTpG/M+Wy4/1EtC0zJ ZKT9zJt80CJIOi5FOre4yNHDIlLfh2CoQmfXeZNu77L9/4JOT8wQJqBDtaqlUhggzm7z mmAA== X-Gm-Message-State: AO0yUKWvmKp6Hxf5U46Vpeo54FcyWzkkf+XFWnG+7NZ0zyKVA9nL8F6z X70pFXn8g31g84IRwbB57ELNiRS6or8= X-Google-Smtp-Source: AK7set9z2RIB1+MnUTCI+d6tD2+X/XlUvgLJksvCvzE5szG4B6uXrDxC8Bbk9Da1F9i9cjnu9YsjeU4IwLs= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:e1f6:21d1:eead:3897]) (user=surenb job=sendgmr) by 2002:a0d:ca10:0:b0:52e:e6ed:3094 with SMTP id m16-20020a0dca10000000b0052ee6ed3094mr727498ywd.532.1677519461069; Mon, 27 Feb 2023 09:37:41 -0800 (PST) Date: Mon, 27 Feb 2023 09:36:26 -0800 In-Reply-To: <20230227173632.3292573-1-surenb@google.com> Mime-Version: 1.0 References: <20230227173632.3292573-1-surenb@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227173632.3292573-28-surenb@google.com> Subject: [PATCH v4 27/33] 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: rspam02 X-Rspamd-Queue-Id: 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rJwLPQ7xH6cuD4ZGxGkJ9pYT09EecBnk5QH4rI+bIenbhxHliRZTJZAk9kxUiJhi/gsodpYvvCPZpYSu7bqPJyb6iimpm1OJHN3w17NPARipsX1Um+4uHQQCbvbPcon2WIpaSagmPR7U9YohDNoeA7Urn1BqpiExiHn20kmyK8+S3sgnlwfS/YWDSvyEwZRvHi6jFVe20uqquFaeW72qscTunxylh/KeEQs02EOfDxEnR2Ybnq2UqLXfOefGO9S+eJygGygl6aobk2Ny1s3Z3AoPnynDpSUwSfU7HeuBSxiqYy8nzJ6Cxi0w0nHJg6x2y97TapYawBi7yiWBcCbFMqdGmoVEaYhmMjrlKV7GgKGZs9cjdH/X14BsNood9lID1YkIFh7ULodTMI40J5V7ak82eubFVTTmenMhaqoQRNcxkkHNq9zVmUHsGpjGvstWiNDRHrUspIP0NohAvcblcULLHYwlwoVq2QIIoECC6duA6JmSx0QWXbzWFRjKFUKKDTJ61IOOd7DLN5bjpJmvO4iiFAnc/aNesW0PaRqxhDwm4t/akzD8dN/uIRn50nDqovKaJ/QtGywt6Xcnfx44rsvBh2HXtibGKvEn9GtT+7QduiCsxFHXkJPn5H4Q6lHe0bQ== 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 af3c2c59cd11..f734f80d28ca 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5255,6 +5255,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);