From nobody Tue Apr 28 06:25:54 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB895C43334 for ; Fri, 3 Jun 2022 20:57:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348639AbiFCU54 (ORCPT ); Fri, 3 Jun 2022 16:57:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347000AbiFCU5y (ORCPT ); Fri, 3 Jun 2022 16:57:54 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C186231DC9 for ; Fri, 3 Jun 2022 13:57:52 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id k73-20020a25244c000000b0065ca88b381aso7835332ybk.2 for ; Fri, 03 Jun 2022 13:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=rLWu+mkuMiZJwNpdLayTrCXX3MnKK+cmNqmcZ/mBvwY=; b=OBEwrNSluEd0bNvqaMjphL7UKxoam5UzDjKcYtfrt3UGHt3Qi+VteT1dPI86v82gxo 7iD9PmFt/LmOhUWsfiNZAxJHTwT84Xp3h+lC6zdjUIeW2k0oqndllnhpQyv11QEirI/G kE/r0HZXFRlKMsdZyMdnv35UVZisCr5fXdGOkf23c6VBxC8j6aSHLvKkrU1JqEZCUDSW 6txWhhL5DQYMAb4pepUqYRJaz6RlhnkKWBCRWSnNnEspIxSU98Jn73KP6f/4++sNOriK omKdxky4CMNnpADLPvSRq1sqBvreuVQ01WClJEU0YNUIoeJeRjlw3n6DGlbzXrkFMkGR XrWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=rLWu+mkuMiZJwNpdLayTrCXX3MnKK+cmNqmcZ/mBvwY=; b=zS1xHYOW803b5Dtm9bPqvfzCz6rnx8apjiF6hda5t4h+JLwn9Fzj6Q9hNd2V1vVkZj nPNdWjfOkKYbq+ZDjr3euhdCJ2Jw3etvZdySAVj5WCrP2EDqc9v4U/KLc7VqcxbQVmmP WMzxBAkTOOh6yAwzPzCK6Euqh/H/oAu9oAS2fq+xCoBvVwJFR7JDn0dFp347CjdjfmR8 LJqpGZb2pfbUYhhSpdtV9e53eQFYRoPrd1Ot4RsiRpuUFYhhL8lbSw1HrlS0ajYY76vm YAqCdzwhHxQ5gM8pCA3n8CtEWAh0RBODGBPu5z2LgsgP0HTn3ZwQ1tsKpJglGmOZJCxa OePg== X-Gm-Message-State: AOAM5332RhRbUeyAFR+ATCS+WJ1dKLuTePst+vF2TzYpuCCpg76zMyfF tafwDUEyjS/awNa1BHM3aLutTRgpohpPtv+NODDa X-Google-Smtp-Source: ABdhPJwriWQgdUK7gB2ED+zM3smPBkANF/4W6Hz3s3ybmUltLgXLxLrOFBaxoeax8EHhui11zuzLSibrLNZ5aDNy7w5B X-Received: from ajr0.svl.corp.google.com ([2620:15c:2cd:203:fbb0:d120:cc2e:23c1]) (user=axelrasmussen job=sendgmr) by 2002:a25:c883:0:b0:64e:a298:304 with SMTP id y125-20020a25c883000000b0064ea2980304mr13114666ybf.38.1654289871981; Fri, 03 Jun 2022 13:57:51 -0700 (PDT) Date: Fri, 3 Jun 2022 13:57:41 -0700 Message-Id: <20220603205741.12888-1-axelrasmussen@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH] mm: userfaultfd: fix UFFDIO_CONTINUE on fallocated shmem pages From: Axel Rasmussen To: Andrew Morton , Peter Xu , Hugh Dickins Cc: Axel Rasmussen , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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_m= m, struct page *page; int ret; =20 - ret =3D shmem_getpage(inode, pgoff, &page, SGP_READ); + ret =3D shmem_getpage(inode, pgoff, &page, SGP_NOALLOC); if (ret) goto out; if (!page) { --=20 2.36.1.255.ge46751e96f-goog