Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp623369pxy; Wed, 28 Apr 2021 10:40:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLxN0PQsUdPcmqGd90osfI5ExR6iAC46dsHOkohrHIv0vAt9PYYcXqhtTqsPSbL2JSvdlt X-Received: by 2002:a17:906:3e89:: with SMTP id a9mr29459609ejj.405.1619631636290; Wed, 28 Apr 2021 10:40:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619631636; cv=none; d=google.com; s=arc-20160816; b=fGRPo9fmimFCmfe2o9WAHWsvtPRRDYaBizQGRBIB2+XSAtCi7RtUGs0Ya7JkDAbE7t uYx4m2DEpbS8sKHk2MzI2oQJzPUxNF8+J573o2dlMVN60h74uZJIfybPRd/oHAEGjZlc XSTJ3+kr4rbTRBSiUMQpuyWc5h2bBWAnDIdzl3eWoTwhgZlfxogtEHvAn5Oc3YQSeT7o VeTSoX/G8ZKBpgJBDrhtRDFT8qF2DhGw+IKzrSv4hz1avo9PT4ycCpBg7QlvQbi45SOi 6KyWIeBnBCxM9kSUhzn8/cHaCI6qjcKVjSStTAV2kYu5EJrUQM6Eg2QoaokBPxeeCm4a NZqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=NAIQJbaFQ/18mbKkoum13vKuadvSUXUDgwqjg93SH3A=; b=lFMGMprnofRWhdOdwhmwBh9n3GIbuV49/1DVQ96Jv0FsTBZUurXF14tjl7FcaK/uQQ EO+BFmOaS1SUSiWCAhTCbxFWCV5lpohOjkmHOq/H4saVqJp43+bIFihD0C/dF400QW5U RFkpeY32bpfp3o5cSRROdbZFW4kmSF4WDn0G6BMrAHFrbZfARo3zqyWqm4oliuzdI6UX YacAbhl6Z+KoagTna+WW2NgjUtuWDezOvyhDmEvKgZFeODnHPqYGITnGOJiOuO97Ghsd nPoC7USlEy/BSPvUASodk5WwyOCyZoRej8SGgjGCZy+Nh5CbuUsns72yfxfqszsqiA5f 8rsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GBlHVrPS; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y9si424147edi.0.2021.04.28.10.40.09; Wed, 28 Apr 2021 10:40:36 -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=@redhat.com header.s=mimecast20190719 header.b=GBlHVrPS; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240471AbhD1P5d (ORCPT + 99 others); Wed, 28 Apr 2021 11:57:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45407 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240419AbhD1P53 (ORCPT ); Wed, 28 Apr 2021 11:57:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619625404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=NAIQJbaFQ/18mbKkoum13vKuadvSUXUDgwqjg93SH3A=; b=GBlHVrPSHTaGu7Zi4fPyIqCCC2RIctCNLKUYXyAY5E2ULh2slgM1YMZuhuTIjdw8tNjCSU 18hV74JgAEoYPdnjsDaDUpXRIbTZBsINwaWOFGpd5Kys/ye6b0lhZ7J4C0iL9yExA+YEz6 h7N5wP8X6KrOLqw+8jfEmGKD7KNjXpU= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-519-OErfzvoFNnakiUV5GV1RNQ-1; Wed, 28 Apr 2021 11:56:41 -0400 X-MC-Unique: OErfzvoFNnakiUV5GV1RNQ-1 Received: by mail-qt1-f197.google.com with SMTP id h14-20020ac846ce0000b02901ba21d99130so17542340qto.13 for ; Wed, 28 Apr 2021 08:56:41 -0700 (PDT) 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=NAIQJbaFQ/18mbKkoum13vKuadvSUXUDgwqjg93SH3A=; b=RN2vHW90ighwTA3f/t6eOrs/HEP9h9wvAISNLAs4ZfwcglGjsN73PvJJv1r+njbxh8 yvq+cl+pBEWW6MDqDw+Tgg3VlV56q4MUXhatiyqxucSae8AJ40bfrDett0bsbDtcVOpH UuI5cVyiCTXiO59IyvG+pKrcEWytGOTTwnGrqBgSjosBx4rDWOTd39YxhMgG6UpGgJc1 AoN7JdlZX9nBo8x1RiSVLChVE4bNNguFTsi+9Fo5wjj5Hl/t5gbKozwfitelMKEZObvn RPdamVXNapUSYo5fgEzQQnBmX2AUQp5u3WJJ92G6j68H4VvsqRozlMfaC7LPN3HGW2Cp 747Q== X-Gm-Message-State: AOAM533b4E6t3JVoHv5Hdv4jRv5j5FZGEE0YYjCh50VYJCS4z8uqSG6N oTeijbQCrNDU5kLX2Pkoq/8XN1v9SONn9GIsNSUhL1Y3mKtU3L/cqaY0IgqwqIDsoUwtG3dg6UU UF3ZmhTh4umKoSp/69mwuJ2Hr X-Received: by 2002:a05:622a:1186:: with SMTP id m6mr26871401qtk.319.1619625400931; Wed, 28 Apr 2021 08:56:40 -0700 (PDT) X-Received: by 2002:a05:622a:1186:: with SMTP id m6mr26871356qtk.319.1619625400589; Wed, 28 Apr 2021 08:56:40 -0700 (PDT) Received: from xz-x1 (bras-base-toroon474qw-grc-77-184-145-104-227.dsl.bell.ca. [184.145.104.227]) by smtp.gmail.com with ESMTPSA id e10sm83701qka.56.2021.04.28.08.56.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 08:56:39 -0700 (PDT) Date: Wed, 28 Apr 2021 11:56:38 -0400 From: Peter Xu To: Hugh Dickins Cc: Axel Rasmussen , 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, 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() Message-ID: <20210428155638.GD6584@xz-x1> References: <20210427225244.4326-1-axelrasmussen@google.com> <20210427225244.4326-7-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > > 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)? Thanks, -- Peter Xu