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 X-Spam-Level: X-Spam-Status: No, score=-24.8 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E415DC43462 for ; Wed, 28 Apr 2021 00:58:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7BE6F60FDB for ; Wed, 28 Apr 2021 00:58:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BE6F60FDB Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EC3266B0036; Tue, 27 Apr 2021 20:58:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E9B2B6B006E; Tue, 27 Apr 2021 20:58:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D3B856B0070; Tue, 27 Apr 2021 20:58:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0223.hostedemail.com [216.40.44.223]) by kanga.kvack.org (Postfix) with ESMTP id BA0316B0036 for ; Tue, 27 Apr 2021 20:58:22 -0400 (EDT) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id DBCD2181AF5C4 for ; Wed, 28 Apr 2021 00:58:20 +0000 (UTC) X-FDA: 78079964760.06.3F7BC97 Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) by imf29.hostedemail.com (Postfix) with ESMTP id 9D5E0135 for ; Wed, 28 Apr 2021 00:58:16 +0000 (UTC) Received: by mail-qt1-f177.google.com with SMTP id 1so45638403qtb.0 for ; Tue, 27 Apr 2021 17:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=nnLhfKmay2hfrNFLJmZvY1slfDRvS1kILjvcSIZf/mg=; b=Hn5od4nTNCw0oO2WqwOMMft1NWsukPMlQRMrmwYFStQpXM9w0sZauP31fIdtDH/T7P h6jPwZVotyfrbiIrXeMGZ62TkyK6QIwX67ES+gfMl8OiTSmYJuZ52V6nA3KhnyVv4rVw CLhPSfyg0imxrZGzoaYi+sS4g6tNMPJ3cwXA+NwRZiLQFrWWez+EUg+fChxjLjtbljLC SuLpDsBsgIf4kUuDkMscPgXmS7pVdl1eULZREb5iRO8DH7rXP1kkBNdf923GNq8j4Vhg X/HUjp7hcqGBtAi6hqMpCMgABRm2cYcM1xijPrP0MlS4UfszukBRzBa7mfHZOl0IkXsI KAow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=nnLhfKmay2hfrNFLJmZvY1slfDRvS1kILjvcSIZf/mg=; b=LwC1BZ60dPquRCliSLT16ICyokX6IJTnclb29OyQ+O7M4DityiNTKeFSyiYb49/Fg1 Utz3O9ze/I6msWKi6Pty7KNbGmr4L0xPzjcIYgKJ0fqrtw2sEGm5kEJhel+CJV3D8nEZ g42deSB+ZUnS0EeKhk29DmS3u2/wg5BZoWUABZfRaD9phS6StGcT7O117bSFgsey2fRy G0zpaiXL07TskjAVnVlAA13PKLfYYfSOalAfznnASHotkW1wjvw09OOSoez2zi2FXpf5 7BqYUrCisXknR2U9KauC4gy//p8T5tBTDiIukxisRgPVFToGrCFptlinUsixQZQwbC1C sHNQ== X-Gm-Message-State: AOAM530EJiV0V2VK5JWQ7cEwnLzaGvjisOpqA4T3iwlPz6veslHSvnke trt+Li2rsaxsFx3IEq58c9bvXQ== X-Google-Smtp-Source: ABdhPJxU7KyEA/ZmtPQITj+z73ELbtvuZj0UGvuPkYy8R3FVU9mHK9Cn432IolPH4dFuamCDIcAmLA== X-Received: by 2002:ac8:6e89:: with SMTP id c9mr24352036qtv.268.1619571499536; Tue, 27 Apr 2021 17:58:19 -0700 (PDT) Received: from eggly.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id 3sm3869819qko.120.2021.04.27.17.58.17 (version=TLS1 cipher=ECDHE-ECDSA-AES128-SHA bits=128/128); Tue, 27 Apr 2021 17:58:19 -0700 (PDT) Date: Tue, 27 Apr 2021 17:58:16 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@eggly.anvils To: Axel Rasmussen cc: Alexander Viro , Andrea Arcangeli , Andrew Morton , Hugh Dickins , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Peter Xu , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Subject: Re: [PATCH v5 06/10] userfaultfd/shmem: modify shmem_mcopy_atomic_pte to use install_pte() In-Reply-To: <20210427225244.4326-7-axelrasmussen@google.com> Message-ID: References: <20210427225244.4326-1-axelrasmussen@google.com> <20210427225244.4326-7-axelrasmussen@google.com> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 9D5E0135 X-Stat-Signature: hjo8fuhxhen8f34fiaqjww3h41r4hs7r Received-SPF: none (google.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-qt1-f177.google.com; client-ip=209.85.160.177 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1619571496-367975 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 Tue, 27 Apr 2021, Axel Rasmussen wrote: > In a previous commit, we added the mcopy_atomic_install_pte() helper. > This helper does the job of setting up PTEs for an existing page, to map > it into a given VMA. It deals with both the anon and shmem cases, as > well as the shared and private cases. > > In other words, shmem_mcopy_atomic_pte() duplicates a case it already > handles. So, expose it, and let shmem_mcopy_atomic_pte() use it > directly, to reduce code duplication. > > This requires that we refactor shmem_mcopy_atomic_pte() a bit: > > Instead of doing accounting (shmem_recalc_inode() et al) part-way > through the PTE setup, do it afterward. This frees up > mcopy_atomic_install_pte() from having to care about this accounting, > and means we don't need to e.g. shmem_uncharge() in the error path. > > A side effect is this switches shmem_mcopy_atomic_pte() to use > lru_cache_add_inactive_or_unevictable() instead of just lru_cache_add(). > This wrapper does some extra accounting in an exceptional case, if > appropriate, so it's actually the more correct thing to use. > > Signed-off-by: Axel Rasmussen Not quite. Two things. One, in this version, delete_from_page_cache(page) has vanished from the particular error path which needs it. Two, and I think this predates your changes (so needs a separate fix patch first, for backport to stable? a user with bad intentions might be able to trigger the BUG), in pondering the new error paths and that /* don't free the page */ one in particular, isn't it the case that the shmem_inode_acct_block() on entry might succeed the first time, but atomic copy fail so -ENOENT, then something else fill up the tmpfs before the retry comes in, so that retry then fail with -ENOMEM, and hit the BUG_ON(page) in __mcopy_atomic()? (As I understand it, the shmem_inode_unacct_blocks() has to be done before returning, because the caller may be unable to retry.) What the right fix is rather depends on other uses of __mcopy_atomic(): if they obviously cannot hit that BUG_ON(page), you may prefer to leave it in, and fix it here where shmem_inode_acct_block() fails. Or you may prefer instead to delete that "else BUG_ON(page);" - looks as if that would end up doing the right thing. Peter may have a preference. (Or, we could consider doing the shmem_inode_acct_block() only after the page has been copied in: its current placing reflects how shmem.c does it elsewhere, and there's reason for that, but it doesn't always work out right. Don't be surprised if I change the ordering in future, but it's probably best not to mess with that ordering now.) Sorry, if this is a pre-existing issue, then we are taking advantage of you, in asking you to fix it: but I hope that while you're in there, it will make sense to do so. Thanks, Hugh > --- > include/linux/userfaultfd_k.h | 5 ++++ > mm/shmem.c | 48 +++++------------------------------ > mm/userfaultfd.c | 17 +++++-------- > 3 files changed, 18 insertions(+), 52 deletions(-)