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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 580BCC43334 for ; Sun, 5 Jun 2022 01:37:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E2066B0071; Sat, 4 Jun 2022 21:37:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4905F6B0073; Sat, 4 Jun 2022 21:37:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A20E6B0074; Sat, 4 Jun 2022 21:37:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 2B1926B0071 for ; Sat, 4 Jun 2022 21:37:35 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id E33C36BA for ; Sun, 5 Jun 2022 01:37:34 +0000 (UTC) X-FDA: 79542470028.26.A5EC593 Received: from mail-qt1-f175.google.com (mail-qt1-f175.google.com [209.85.160.175]) by imf29.hostedemail.com (Postfix) with ESMTP id 52B1F120004 for ; Sun, 5 Jun 2022 01:37:20 +0000 (UTC) Received: by mail-qt1-f175.google.com with SMTP id x18so5420665qtj.3 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=Mweg4xe9r8FefFJefTs2Aji8TSpERhKI+mb8gn5spYMGK1W0sm7CErxirBds/BKCq3 twyYPenHNo++9hQp4lv6WxMBQJuaEZ+N9ZBuTL9e17GK76y/dRM27wIFHnoBGSRBCkmk qwlcP7XxKS3mKdFUVCO5X2tsMmPkdJGWwjqxdf6riVBwv/NTot5xZ7k7BP/R2NO2/wqw YRfo76bboB6emB5ZQ7SA7Bh7hL9ReXBjPsmxEe/1JkiF28GLq6t6/kXbtBklXc2ayjXX x6MBR5d/JqpNqZrggUo5h/Q9IeX+Y7KTgxr9QaaUzrZtZVq4msbCMFtSQXrYdtNoiB95 rPmQ== X-Gm-Message-State: AOAM531tdZCTNdLa9dD52rpjj1iumxfWt2JSrQ4Ji4UCm8CRs01ugXFv xicMVS/jc9zSz3RzGbC23MVf0Q== X-Google-Smtp-Source: ABdhPJwPYAhWq2x9goD/zXPaA2zuifl2cNIABizKdgTYleJS43dQnHaWkJv1vxERld71KUWWPY6hVw== 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 52B1F120004 X-Stat-Signature: wor7eqypwfp7d4tsp8imguq14mta95jg X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=rWCNTJEL; spf=pass (imf29.hostedemail.com: domain of hughd@google.com designates 209.85.160.175 as permitted sender) smtp.mailfrom=hughd@google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1654393040-756857 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 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