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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F14F0C6379F for ; Tue, 17 Jan 2023 21:59:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbjAQV7S (ORCPT ); Tue, 17 Jan 2023 16:59:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229649AbjAQV5r (ORCPT ); Tue, 17 Jan 2023 16:57:47 -0500 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CBBE4F873 for ; Tue, 17 Jan 2023 12:36:42 -0800 (PST) Received: by mail-io1-xd2b.google.com with SMTP id b127so7440618iof.8 for ; Tue, 17 Jan 2023 12:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=QpAHNbvKrocr/gd9vGeih5qNlPxQR4MEXcSF4KR6pVa+PSdw28fgbVUFIbunf7ZNMp Bz+X/7R7YhZTp8QcKnf0rUNp4dHWFtDOn/C2E4pP8Kpox0pG02f+bk7RVlPsuaaQhpeE rR6AvvWD4qsJO0fGm/eLsQBDRj0Za8beePU4FZpa45+qQAtII1R2/dAg+bbznUkadb8m WpMTk5odBTayNIx9c/yS0gJXB6st0uuvpfPLzoL+u+QKqVr4iigyIBml9XmSh6isdaMz QufOUvjdWx/iu+V+o7iSeOPWNnygir8efcpoGOyVnh+WRc4LAfLaTOOuRgiv9PC/HVzz ctzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=Bzy4QK8WeGeV5FQNQhgFDJ7lNI7Vtr7kFxploF2Zue7cIOY/3VM796kHco75XW7RRA MCTvuJ/Zkt9dlAVrSlpp56/esmJJIPiHW3MxeH2P5QGn1GiJ+6/8xDydT3Xn0S3DEn80 XthvVf5p1HXhiBAo/hSFL/me2zYpNwWLNfZRDw/iUI4jSzeTv+6O90g8GFA/Xll3nZ5J 0OFSOPQyAUybjRzhcfd6ZQO8YwWEqoWrksTY9v6s6jmt6xF6VTPuloCpSzkrn63JfN8b JneXnRoPddLYYhHeurSKdYZ7ArqQ5EGVlRBuz2ym3SK7Py5Eq6P0cCVukJ7UbjQswUPY CJsA== X-Gm-Message-State: AFqh2kpzTc9dZUwP8EEXYreo/YCpWSvrMLSpWYW4KPRB233v6DfMjzNp 1x4pJzbzeTaknbdw1fglvUohwlgUUtIRzQwLRVjTYg== X-Google-Smtp-Source: AMrXdXusAVEO39vkcFBYo1YaXglysvZb5hIpl6B/Ane5TCpjdEQi3a24j+bOu8/GXvC7NmQ4pthv5BDs12Jhfzy67zo= X-Received: by 2002:a02:2a4b:0:b0:38c:886a:219a with SMTP id w72-20020a022a4b000000b0038c886a219amr490143jaw.133.1673987801346; Tue, 17 Jan 2023 12:36:41 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-33-surenb@google.com> In-Reply-To: From: Jann Horn Date: Tue, 17 Jan 2023 21:36:05 +0100 Message-ID: Subject: Re: [PATCH 32/41] mm: prevent userfaults to be handled under per-vma lock To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, 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, laurent.dufour@fr.ibm.com, paulmck@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, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 17, 2023 at 8:51 PM Jann Horn wrote: > On Mon, Jan 9, 2023 at 9:55 PM Suren Baghdasaryan wrote: > > 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 | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 20806bc8b4eb..12508f4d845a 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -5273,6 +5273,13 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, > > if (!vma->anon_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)) > > + goto inval; > > This looks racy wrt concurrent userfaultfd_register(). I think you'll > want to do the userfaultfd_armed(vma) check _after_ locking the VMA, I still think this change is needed... > and ensure that the userfaultfd code write-locks the VMA before > changing the __VM_UFFD_FLAGS in vma->vm_flags. Ah, but now I see you already took care of this half of the issue with the reset_vm_flags() change in https://lore.kernel.org/linux-mm/20230109205336.3665937-16-surenb@google.com/ . > > if (!vma_read_trylock(vma)) > > goto inval; > > > > -- > > 2.39.0 > > 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8FF58C3DA78 for ; Tue, 17 Jan 2023 20:37:39 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4NxLL96fdKz3fBp for ; Wed, 18 Jan 2023 07:37:37 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=QpAHNbvK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=google.com (client-ip=2607:f8b0:4864:20::d2f; helo=mail-io1-xd2f.google.com; envelope-from=jannh@google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20210112 header.b=QpAHNbvK; dkim-atps=neutral Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4NxLK967bfz3cdJ for ; Wed, 18 Jan 2023 07:36:44 +1100 (AEDT) Received: by mail-io1-xd2f.google.com with SMTP id p66so15483506iof.1 for ; Tue, 17 Jan 2023 12:36:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=QpAHNbvKrocr/gd9vGeih5qNlPxQR4MEXcSF4KR6pVa+PSdw28fgbVUFIbunf7ZNMp Bz+X/7R7YhZTp8QcKnf0rUNp4dHWFtDOn/C2E4pP8Kpox0pG02f+bk7RVlPsuaaQhpeE rR6AvvWD4qsJO0fGm/eLsQBDRj0Za8beePU4FZpa45+qQAtII1R2/dAg+bbznUkadb8m WpMTk5odBTayNIx9c/yS0gJXB6st0uuvpfPLzoL+u+QKqVr4iigyIBml9XmSh6isdaMz QufOUvjdWx/iu+V+o7iSeOPWNnygir8efcpoGOyVnh+WRc4LAfLaTOOuRgiv9PC/HVzz ctzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=yi8mThC8yeakX+fvoBlFSreTZbtDkoVTK1CqLDyGd2DlImCs8lknKigE0TcmJjk5N6 uJYEP8oukZ4YkK19DBx2ZXGg5BqzGvXLZCVsOr5QXWFTlm8XJL4J+i3yoAj4bapeTRJR ntMlisYl2GylyzxMfUuPgXNcU3fXe4MLYhhtBTF+yFcPtg9lzM7QhzMd1hRPYqp0aWTO mGEoRIX/Hr/ULubNhr/3qMMdsdiWEqBHPtmZLwEJhPZQkpdA6T+kmwsjZ5in7nVGeWzq kNcpI/nPvXeLCK/ypqzXMfrTWKpv8stltcZd7FwVulRSh1FMESbOQz3pfyfwK0JusKje FcIA== X-Gm-Message-State: AFqh2krqWoDGAw/bTeT66QORqTXWAcN/CoMNghAzb2DvxVcJG1dYRkPR 98qggd3tdAuB2Kh2W66bIB1a5wNlH88HRv6HR2C2Cg== X-Google-Smtp-Source: AMrXdXusAVEO39vkcFBYo1YaXglysvZb5hIpl6B/Ane5TCpjdEQi3a24j+bOu8/GXvC7NmQ4pthv5BDs12Jhfzy67zo= X-Received: by 2002:a02:2a4b:0:b0:38c:886a:219a with SMTP id w72-20020a022a4b000000b0038c886a219amr490143jaw.133.1673987801346; Tue, 17 Jan 2023 12:36:41 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-33-surenb@google.com> In-Reply-To: From: Jann Horn Date: Tue, 17 Jan 2023 21:36:05 +0100 Message-ID: Subject: Re: [PATCH 32/41] mm: prevent userfaults to be handled under per-vma lock To: Suren Baghdasaryan Content-Type: text/plain; charset="UTF-8" X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: michel@lespinasse.org, joelaf@google.com, songliubraving@fb.com, mhocko@suse.com, leewalsh@google.com, david@redhat.com, peterz@infradead.org, bigeasy@linutronix.de, peterx@redhat.com, dhowells@redhat.com, linux-mm@kvack.org, edumazet@google.com, jglisse@google.com, punit.agrawal@bytedance.com, arjunroy@google.com, dave@stgolabs.net, minchan@google.com, x86@kernel.org, hughd@google.com, willy@infradead.org, gurua@google.com, laurent.dufour@fr.ibm.com, linux-arm-kernel@lists.infradead.org, rientjes@google.com, axelrasmussen@google.com, kernel-team@android.com, soheil@google.com, paulmck@kernel.org, liam.howlett@oracle.com, shakeelb@google.com, luto@kernel.org, gthelen@google.com, ldufour@linux.ibm.com, vbabka@suse.cz, posk@google.com, lstoakes@gmail.com, peterjung1337@gmail.com, linuxppc-dev@lists.ozlabs.org, kent.overstreet@linux.dev, hughlynch@google.com, linux-kernel@vger.kernel.org, hannes@cmpxchg.org, akpm@linux-foundation.org, tatashin@google.com, mgorman@techsingularity.net Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Tue, Jan 17, 2023 at 8:51 PM Jann Horn wrote: > On Mon, Jan 9, 2023 at 9:55 PM Suren Baghdasaryan wrote: > > 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 | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 20806bc8b4eb..12508f4d845a 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -5273,6 +5273,13 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, > > if (!vma->anon_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)) > > + goto inval; > > This looks racy wrt concurrent userfaultfd_register(). I think you'll > want to do the userfaultfd_armed(vma) check _after_ locking the VMA, I still think this change is needed... > and ensure that the userfaultfd code write-locks the VMA before > changing the __VM_UFFD_FLAGS in vma->vm_flags. Ah, but now I see you already took care of this half of the issue with the reset_vm_flags() change in https://lore.kernel.org/linux-mm/20230109205336.3665937-16-surenb@google.com/ . > > if (!vma_read_trylock(vma)) > > goto inval; > > > > -- > > 2.39.0 > > 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5B98C54E76 for ; Tue, 17 Jan 2023 20:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=xpegzB9paH3bdFW3bYwN7cNb2fU+lExHG4xK9tQXsLo=; b=uE3Yku/UQbDkLD F8FSPvuGMor8HoVZUAdXgX16cCI4Fo0MrRFkmaQunm/rJ4PzTuEOX+VJ8mm9aDnA0PfzEIHvsSqjS KgN8U/Ntv5HGlgmzjkBkjY6CpMKEE89RdjWW6DQ+dkt66iWzGHO4/Y4dqLju4IzG0m2ZuUn2SBccU RAV6n3jU5o+Z5xiRzTrGiV3QNikTSiVuzx3Kd1CeqejWukXu92/O9W2PnRVAsnfVl81jZI8brufYO kPcKfSAbchyw3tFUniOxB+7sUDetWzvCpb5Bet6zzqA4wWryrG2CMQZu5RWUlxuAjQqBcFBrgm/Qn xD8IWX8+lD4PPUDkUJ2g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHshL-00Fmo3-N0; Tue, 17 Jan 2023 20:36:47 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHshH-00Fmm1-Li for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2023 20:36:45 +0000 Received: by mail-io1-xd2f.google.com with SMTP id q130so2502505iod.4 for ; Tue, 17 Jan 2023 12:36:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=QpAHNbvKrocr/gd9vGeih5qNlPxQR4MEXcSF4KR6pVa+PSdw28fgbVUFIbunf7ZNMp Bz+X/7R7YhZTp8QcKnf0rUNp4dHWFtDOn/C2E4pP8Kpox0pG02f+bk7RVlPsuaaQhpeE rR6AvvWD4qsJO0fGm/eLsQBDRj0Za8beePU4FZpa45+qQAtII1R2/dAg+bbznUkadb8m WpMTk5odBTayNIx9c/yS0gJXB6st0uuvpfPLzoL+u+QKqVr4iigyIBml9XmSh6isdaMz QufOUvjdWx/iu+V+o7iSeOPWNnygir8efcpoGOyVnh+WRc4LAfLaTOOuRgiv9PC/HVzz ctzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=gzv/PjbkvkttZs2lXK771JGFBCi9Hf6ZZVadDKoWVOE=; b=GHK1W9nF6SKgrFOInClUnV1IYvEZaD4YpNEs4tzHopMbMzBJgtlgT+yjdjW45oV3+t lWYOjy0R7XWHjRQyUxoniZ+pGkklYm145kmqQWdG4zcfl1sP9eEzWg/ROEjkoIi0LmCK wC8ZeJmWMgTYZCATSsKEfapKGtyIF8Rn29cN0PUnO/r2TBWrLsX39Obi3k8vOLqRMGDr 8nenO5TMmB5iAIXRu6kxQnCPMM5/S0jRnAkhT4osDPZWTB04ggf3RKhsSD3KmN4f0+PY 1Zq/XDA0Mz2gtGsG7jj3HXbf5tUT1aDYdabu5RUvTogi9EsTWxysnJFiBVjhG+vYltKd Z52A== X-Gm-Message-State: AFqh2koB82v2oEtwahsYUAqQTx6g4sDBBXKxEusyQ2KMly45y/A2JjvK O8YklB6LU9uilfFomXglSb0OLwcsaqtEv9inSHXAtw== X-Google-Smtp-Source: AMrXdXusAVEO39vkcFBYo1YaXglysvZb5hIpl6B/Ane5TCpjdEQi3a24j+bOu8/GXvC7NmQ4pthv5BDs12Jhfzy67zo= X-Received: by 2002:a02:2a4b:0:b0:38c:886a:219a with SMTP id w72-20020a022a4b000000b0038c886a219amr490143jaw.133.1673987801346; Tue, 17 Jan 2023 12:36:41 -0800 (PST) MIME-Version: 1.0 References: <20230109205336.3665937-1-surenb@google.com> <20230109205336.3665937-33-surenb@google.com> In-Reply-To: From: Jann Horn Date: Tue, 17 Jan 2023 21:36:05 +0100 Message-ID: Subject: Re: [PATCH 32/41] mm: prevent userfaults to be handled under per-vma lock To: Suren Baghdasaryan Cc: akpm@linux-foundation.org, 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, laurent.dufour@fr.ibm.com, paulmck@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, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230117_123643_740260_DCB852C3 X-CRM114-Status: GOOD ( 21.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jan 17, 2023 at 8:51 PM Jann Horn wrote: > On Mon, Jan 9, 2023 at 9:55 PM Suren Baghdasaryan wrote: > > 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 | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 20806bc8b4eb..12508f4d845a 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -5273,6 +5273,13 @@ struct vm_area_struct *lock_vma_under_rcu(struct mm_struct *mm, > > if (!vma->anon_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)) > > + goto inval; > > This looks racy wrt concurrent userfaultfd_register(). I think you'll > want to do the userfaultfd_armed(vma) check _after_ locking the VMA, I still think this change is needed... > and ensure that the userfaultfd code write-locks the VMA before > changing the __VM_UFFD_FLAGS in vma->vm_flags. Ah, but now I see you already took care of this half of the issue with the reset_vm_flags() change in https://lore.kernel.org/linux-mm/20230109205336.3665937-16-surenb@google.com/ . > > if (!vma_read_trylock(vma)) > > goto inval; > > > > -- > > 2.39.0 > > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel