Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp73184iof; Sun, 5 Jun 2022 21:31:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvjQq4BZf48wLgScbvHdLbzUYkKwa34dzOAE7UPts+cjQmvpyncIHBDz0yPIaIKlKwwlLu X-Received: by 2002:a17:90b:1c87:b0:1ca:f4e:4fbe with SMTP id oo7-20020a17090b1c8700b001ca0f4e4fbemr59195568pjb.159.1654489880087; Sun, 05 Jun 2022 21:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654489880; cv=none; d=google.com; s=arc-20160816; b=FvCDbUCl8kqcrrXdJQd4RLX3V1RY+QnSik2LCgjOVJS345Xlgf/V3szw62cQyipDQw dM7wDsoNsE/qx2+8JH1xzKJ1F5KsWbgxFnOn63mufaiByhCqUh9Bw6q7ZhXUGMtrevL0 mI40loVa6bAYIhhoHFTMTr3GsnTKX6Id4wEjnJZd1SxaVGwpzAlpqqRoRiLdKr8ROMZq XzBjkk+MuwlTf4EHh309RVRcPi1BK+P7iJtH1eZXS6i0ABF8IHYjcS1QYmwHHYsrfYZj XECobmaoR9TwKW1uNm3dnp3D9B4kWb6CDrfN5PjHKst8JV0dW+OAY7pGC34x0lJIzeHG vqJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=jWDrrOLl2EZyoh/ovhCu5FFdvKuZyrni45da+0YMjWA=; b=I7STiuT8MCVtK1rzexemXXRNr2Zf0Ot1curGTGOsWYNB+74qDvX2r+1qzrM1TtVam9 fwmQf1D82xzvN5dDRPfq5CIQxxZcr7Uj8ghrOdblVoOKenQidWQHBlTU7s8YE3ubMOpH BFBngYlqpZrD6+7NbrA4auHjTT/xo3tpHlqs34H3povXUae59oU5JeDvAwYupJN2+nBb rCI38egaq50Owbkhu+MbBw0hAfcwqUA3LyS1KJ5q3UiUDY9GVQyuayxHlviOpJtJIvKR dLJOX3Oq6Y40irzJdGp/2AMeG5dT/Yp6RXQXDxvcaxVYeHtQA+E4FurOXjQJBDvQZvnP 4T1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rWCNTJEL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id r23-20020a170902be1700b0015f0bce1a31si17504666pls.558.2022.06.05.21.31.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 21:31:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=rWCNTJEL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 739181183E; Sun, 5 Jun 2022 20:57:53 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243049AbiFEBhh (ORCPT + 99 others); Sat, 4 Jun 2022 21:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233802AbiFEBhg (ORCPT ); Sat, 4 Jun 2022 21:37:36 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DC0E1F61C for ; Sat, 4 Jun 2022 18:37:34 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id y15so8291466qtx.4 for ; Sat, 04 Jun 2022 18:37:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:in-reply-to:message-id:references :mime-version; bh=jWDrrOLl2EZyoh/ovhCu5FFdvKuZyrni45da+0YMjWA=; b=rWCNTJELpwwDenzihOmOGfVi9ACnEEF9ujR1JfnBx/7hfrPrEaIEqDvuJ+oi1GOdVG Ie4keEJmW5Ql4Mye9Qfco/EZ/qgcuQxksdn/6IXUuDoPLzis0Erx3lcC3oyrWAE4wjnr dwJ3G3rHos4YeMui9LytI0yASIdQezPpAt2RvgMlFAAvGBuKryKQTfQrLo1Wcx+24Tzv 2K6JmULWP+YPeni3Mt8AebSbvQrlk7tSwC0urdMiU9HYv/1g0KkgQE1J7YwL+GHQgEwn qjV6skucZRi2OpKJqiBnqYivlubxW3BBHuVgjKBCYQui9cC8xE/MXUeUXvNw2cRsu3/D wsYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:mime-version; bh=jWDrrOLl2EZyoh/ovhCu5FFdvKuZyrni45da+0YMjWA=; b=Zr939EdMve2jrgTVvwuYslwD++QCvF+b64T1vIPdhoOuFc9t4z+bXJ89qRBcH0wx4p JEeo9n5wjY+Xn1qq4yV5F36CGXKxZg2HcvRZ0N1HkBETlXKukPbq28jDgw9FZ3jh/KZy PUlXwalo/J50kTzgia0v/fO/uPrepdPDNyHm1cyKV+hOql0vjYBF2QpVM2nvsT8McfPh Me8hcTLc9CgHi099g3+Y9VBjX+6DE9j1v/4xerwki2ehU8EuUo2g8vXi9C1CFyJ9LpYD 1YcLvBWlz5rtAKLEPTCiHl9lrxAPJhH0rTryfLl7dadfcSrC07F91Yahxt6qGYz2PHvF lPHA== X-Gm-Message-State: AOAM530cOZA93dFW8EatVeTr3b8Zi+tx8+gqCJNI+88bSz+PuBGYwbqj YIm4auAlm7z3P/bFy4+934JKLg== X-Received: by 2002:ac8:7246:0:b0:304:c6a4:cf59 with SMTP id l6-20020ac87246000000b00304c6a4cf59mr13876659qtp.342.1654393053571; Sat, 04 Jun 2022 18:37:33 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id v21-20020a05620a441500b006a6a8ef9f79sm3006777qkp.119.2022.06.04.18.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jun 2022 18:37:32 -0700 (PDT) Date: Sat, 4 Jun 2022 18:37:20 -0700 (PDT) From: Hugh Dickins X-X-Sender: hugh@ripple.anvils To: Axel Rasmussen cc: Andrew Morton , Peter Xu , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: userfaultfd: fix UFFDIO_CONTINUE on fallocated shmem pages In-Reply-To: <20220603205741.12888-1-axelrasmussen@google.com> Message-ID: References: <20220603205741.12888-1-axelrasmussen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 3 Jun 2022, Axel Rasmussen wrote: > When fallocate() is used on a shmem file, the pages we allocate can end > up with !PageUptodate. > > Since UFFDIO_CONTINUE tries to find the existing page the user wants to > map with SGP_READ, we would fail to find such a page, since > shmem_getpage_gfp returns with a "NULL" pagep for SGP_READ if it > discovers !PageUptodate. As a result, UFFDIO_CONTINUE returns -EFAULT, > as it would do if the page wasn't found in the page cache at all. > > This isn't the intended behavior. UFFDIO_CONTINUE is just trying to find > if a page exists, and doesn't care whether it still needs to be cleared > or not. So, instead of SGP_READ, pass in SGP_NOALLOC. This is the same, > except for one critical difference: in the !PageUptodate case, > SGP_NOALLOC will clear the page and then return it. With this change, > UFFDIO_CONTINUE works properly (succeeds) on a shmem file which has been > fallocated, but otherwise not modified. > > Fixes: 153132571f02 ("userfaultfd/shmem: support UFFDIO_CONTINUE for shmem") > Cc: stable@vger.kernel.org > Signed-off-by: Axel Rasmussen Acked-by: Hugh Dickins Yes, that looks like a good improvement, and okay to call it a fix for stable. But note that your original choice of SGP_READ was not wrong: there was no SGP_NOALLOC in v5.14, which arrived in v5.15 (and this is not the first time that it's turned out to be useful since then). Since v5.14-stable reached end-of-life some time ago, marking this patch for stable should not result in any untoward build errors. > --- > mm/userfaultfd.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 4f4892a5f767..c156f7f5b854 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -246,7 +246,7 @@ static int mcontinue_atomic_pte(struct mm_struct *dst_mm, > struct page *page; > int ret; > > - ret = shmem_getpage(inode, pgoff, &page, SGP_READ); > + ret = shmem_getpage(inode, pgoff, &page, SGP_NOALLOC); > if (ret) > goto out; > if (!page) { > -- > 2.36.1.255.ge46751e96f-goog