Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp623412pxy; Wed, 28 Apr 2021 10:40:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzKZA+/IR2ofmOvN4wIW0/S3azS4x5G6qYh1xLDIm2mpIvj0Is2O4V8L07nprSCHIMQOeP X-Received: by 2002:a17:906:7942:: with SMTP id l2mr29842979ejo.314.1619631639277; Wed, 28 Apr 2021 10:40:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619631639; cv=none; d=google.com; s=arc-20160816; b=bAENYNnewUlqfhSZACo7B2vAoelUjqW2FxbaDHCPr5g6rYDmYZKt+pxEnqwBZqedQh OvlkcBiGPERp/l84l7h6hy1cKNs4kcStgsuUlLG7QihYG4Gs9dxxALU99QnJ0i4HJ0To 8Vzz4jORzsrJ6YYeeRzqkr2lzRakP6lsNhDnAmRbEQFfS1NOuTqX2Fciy6QK4i9ZG08F bHSnxNLQYR5QpXDVKyxvm5YoNPQmTqYnnE3pwWBL2WJNlG8G/1668SN45gpJQ6dB8CmW QH2q9S3R5/oLb1ycQdOdbMVGqFWL0VgDJUTkJeT4rbk3ME2LbyhbciRSf9h0R/UCqkT4 IbIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=2SuF9mSmF53oX7jF/kwRpkLK22JzuM8F0Omk1lKrm3U=; b=JoVcFRdRi5roGONgA4i65yEt47t649i5OSwIzuhHzpqR9+n98Lz3mKI7hoimUEPOg3 WeTk8NxeTsb7FzG3gKaVFEGZI4yYxhcgT8+Gr2Slv7ZQCUwREX7W+5Nj2gWnvk9fExrR dk5Zc38GlxNbDSCO1U9PF1RNJKqmbkXhL9dU9JYcJ5KPxH5J8vxe2oFjZTIPIhv9ToUp AUq+Ls7+IhjeQuLfdFAO4sXyFcVi5Fk7X0K6/F0ArS81g5X9rtdEcKzJFqqu1csqrRRe SB4nXmFgtMvSU3hesFKna006qJYV97rwLwGqV4OC0cuezOKArM9eiIA7/hSQ5gsz/K/A Tsmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=c91Ohnqm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ha1si604842ejb.743.2021.04.28.10.40.14; Wed, 28 Apr 2021 10:40:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=c91Ohnqm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240632AbhD1QBV (ORCPT + 99 others); Wed, 28 Apr 2021 12:01:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240634AbhD1QBS (ORCPT ); Wed, 28 Apr 2021 12:01:18 -0400 Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5360C06138A for ; Wed, 28 Apr 2021 09:00:32 -0700 (PDT) Received: by mail-qt1-x830.google.com with SMTP id o21so18908504qtp.7 for ; Wed, 28 Apr 2021 09:00:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=2SuF9mSmF53oX7jF/kwRpkLK22JzuM8F0Omk1lKrm3U=; b=c91OhnqmUMdrp5NwBmhDw0TWIKfd7cy5vfjKAMC5+iO+8WsXa/1iWeYeOn3iiAdnee K687+nQwR9YSd0rPz34NBcYSpywzjMxeDXC53/Pb4AEGt7HZEY5Icnr0ahoHBsonGrbg HXyuj//ZVjv22KpBoGWMZ2LFIIXIny1zBaq8Ckc7R2iE49O+5QqGx11lTuePdNiVNZQe kuJ5UJThxkM79QHzgt2Li5You3M+/fDQ8yIHwND0dIhYaufGJNCSGtpVdCHwu6nPhiZQ W8SjrEQQJNQEUo944EZmAwLRIc9DO2ZQpaS+Vg8i61WI8H2F5Vmk/5l5GjuPT/zghXGr DYyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=2SuF9mSmF53oX7jF/kwRpkLK22JzuM8F0Omk1lKrm3U=; b=MXIaVmP53QHIiNlHP/28Z9xzM3s5MNWI39ajGUTG2qNQkwTifLmuXn5Jdp/wdipb+K oW9oNeD0C2FxfHbrS25lXZJ+EWDfiIjztxnnmT7XIgVxRio+M+X/XL5SlRrqy0J4I+Xl 67+0WOC+FnAdeoNtxnujtHvnGNsaJamwtRjbCsn5bCqFqjjlPSqFLkEw9j6rtZ+2oAXR c91CxUrLINmSgjoNiVEzx9DJtHZsZOg3ddf0R1NVTT8l7GBl5K624+xCZn79peQhbNLM VYi+U2iWtif+wQved13ybbHejowxlEni/LdngG9aRHye75Vcu45zVypxWlwtDpueL+g4 LYrw== X-Gm-Message-State: AOAM533fxJ1rp08yCVfea7EngusIyZx8DR5REQNID28HvMJnBy7qsf9W ldU4DsIy8gIuijsblaFikbZ6e7dQ48yoMJ/JPB6SEg== X-Received: by 2002:ac8:51d3:: with SMTP id d19mr26641416qtn.358.1619625629931; Wed, 28 Apr 2021 09:00:29 -0700 (PDT) MIME-Version: 1.0 References: <20210427225244.4326-1-axelrasmussen@google.com> <20210427225244.4326-7-axelrasmussen@google.com> <20210428155638.GD6584@xz-x1> In-Reply-To: <20210428155638.GD6584@xz-x1> From: Axel Rasmussen Date: Wed, 28 Apr 2021 08:59:53 -0700 Message-ID: Subject: Re: [PATCH v5 06/10] userfaultfd/shmem: modify shmem_mcopy_atomic_pte to use install_pte() To: Peter Xu Cc: Hugh Dickins , Alexander Viro , Andrea Arcangeli , Andrew Morton , Jerome Glisse , Joe Perches , Lokesh Gidra , Mike Kravetz , Mike Rapoport , Shaohua Li , Shuah Khan , Stephen Rothwell , Wang Qing , linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, LKML , linux-kselftest@vger.kernel.org, Linux MM , Brian Geffon , "Dr . David Alan Gilbert" , Mina Almasry , Oliver Upton Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 28, 2021 at 8:56 AM Peter Xu wrote: > > On Tue, Apr 27, 2021 at 05:58:16PM -0700, Hugh Dickins wrote: > > 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. > > Agreed. I also spotted that the set_page_dirty() seems to have been overlooked > when reusing mcopy_atomic_install_pte(), which afaiu should be move into the > helper. I think this is covered: we explicitly call SetPageDirty() just before returning in shmem_mcopy_atomic_pte(). If I remember correctly from a couple of revisions ago, we consciously put it here instead of in the helper because it resulted in simpler code (error handling in particular, I think?), and not all callers of the new helper need 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. > > To me, the BUG_ON(page) wanted to guarantee mfill_atomic_pte() should have > consumed the page properly when possible. Removing the BUG_ON() looks good > already, it will just stop covering the case when e.g. ret==0. > > So maybe slightly better to release the page when shmem_inode_acct_block() > fails (so as to still keep some guard on the page)? This second issue, I will take some more time to investigate. :) > > Thanks, > > -- > Peter Xu >