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 B38AAC433EF for ; Fri, 10 Jun 2022 18:06:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3ACE58D00D4; Fri, 10 Jun 2022 14:06:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 35D3B8D00CB; Fri, 10 Jun 2022 14:06:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1FD758D00D4; Fri, 10 Jun 2022 14:06:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 1286A8D00CB for ; Fri, 10 Jun 2022 14:06:03 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id C628E60468 for ; Fri, 10 Jun 2022 18:06:02 +0000 (UTC) X-FDA: 79563104964.06.E6BA7CC Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 19724A0082 for ; Fri, 10 Jun 2022 18:06:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654884361; 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=+YSOp7OVxLF72vh/zJwUtYoBADG1yurDFuxv9zOncC8=; b=EEHnTKIbwYDi9+pPINHtITED5HizHMpNwQ7W3qlhSlf4O09f6LpcZB55Fs3TMk28DszqkF u78rRuE5LpzZrrRIAFoL9WycJ8Bvu11Pie1uMKUcCsX2fc3UqHWQx9YmFCcye83eqTq7Ye S6n40nbsIjps5BZBgYPOjU8W7aX1SEg= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-umobh8lRPlmuAHcrmEUZbQ-1; Fri, 10 Jun 2022 14:05:58 -0400 X-MC-Unique: umobh8lRPlmuAHcrmEUZbQ-1 Received: by mail-il1-f197.google.com with SMTP id i18-20020a926d12000000b002d1b13b896cso20039271ilc.7 for ; Fri, 10 Jun 2022 11:05:58 -0700 (PDT) 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:message-id:references :mime-version:content-disposition:in-reply-to; bh=+YSOp7OVxLF72vh/zJwUtYoBADG1yurDFuxv9zOncC8=; b=YUcsi4aryG7dtOqgNiA4pZ0OmgXwQJg6wAXVnW+xHeGKLAd2DYY6Pw/PRd733RLh8U lmP9m6EPS8xgjI17vGwZniyXCh7qivJCE4jx8GpyNfblPfAbIyzh6/SLOe7ditSDuggd gb0kXsVm83PUDoyAXbL4zw1OT2fcnuyxAYoUABemtzhgX5hRoAvAEYa2GKbg+YEO5aXp AgPGSo9tMK13l8XOqMQU5PFx3xCsX3UUTAkSKtDMS4VxH/gOr970hArA7543PM+4Wp1W 2OJpYplWMSl/Kd3tFJvvupk7qlaM1E5gi8avgcqX0TdDph2B0uT2/AnY6njrKJPrUH0U AJjQ== X-Gm-Message-State: AOAM5314pqh4antO4tmkyRxLVuVzVd8GpCyDUaPKoyzcFR6vuUOBWVK/ 65wj2H6IxjS/zRAwWQ1TLddP5R5Rt58fWb9U5oAUpn0lv20FXE6fw46hnBhBlODCDRGW3WptHZT OcZbseBI3Qmo= X-Received: by 2002:a05:6e02:552:b0:2d1:db28:5434 with SMTP id i18-20020a056e02055200b002d1db285434mr26259377ils.115.1654884358026; Fri, 10 Jun 2022 11:05:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweN9LCXIbV5RCAndNmWIQkh4tD+Sg78vRKNfgWb1sUjYk+ID4hSP1WDUwkF+/PbrZ6jYMBNw== X-Received: by 2002:a05:6e02:552:b0:2d1:db28:5434 with SMTP id i18-20020a056e02055200b002d1db285434mr26259369ils.115.1654884357736; Fri, 10 Jun 2022 11:05:57 -0700 (PDT) Received: from xz-m1.local (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id a21-20020a056638059500b0032e0a9d63e6sm11104941jar.118.2022.06.10.11.05.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jun 2022 11:05:57 -0700 (PDT) Date: Fri, 10 Jun 2022 14:05:55 -0400 From: Peter Xu To: Axel Rasmussen Cc: Andrew Morton , Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] mm: userfaultfd: fix UFFDIO_CONTINUE on fallocated shmem pages Message-ID: References: <20220610173812.1768919-1-axelrasmussen@google.com> MIME-Version: 1.0 In-Reply-To: <20220610173812.1768919-1-axelrasmussen@google.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654884362; a=rsa-sha256; cv=none; b=k057ckyMxE24jwmUErvDqEBoULTDmUF5zZMcgCaRlANQhjXDkY6FWlDA6ldX9cFpFZyFlK lbNqXsAlJa6C7ZtGVoysPtcU20XPpIoUrlbSJoIKvPqSjoWQuKqt9apRt8hjCeR/92ueUv 37Rv7zQ5XpgLa1v8mJKLzo1fq9pJdhU= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EEHnTKIb; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654884362; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=+YSOp7OVxLF72vh/zJwUtYoBADG1yurDFuxv9zOncC8=; b=JSUCgo8rODOwj6JuMZzM+wcXcd1DfhyN0+LgU8LBZEBQywoIQ4LT/VLeOXHgK6QSm+ceBF smmRqV9Mxap31qbpECiocz9OEB2sqGigp9qVqH+gTsbqr26k95uhsK+EFi/LPEUVNLSgPZ Am+eeDR3Q6ety5FRsCx9CQIf721KtHA= X-Rspamd-Queue-Id: 19724A0082 Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=EEHnTKIb; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspam-User: X-Rspamd-Server: rspam06 X-Stat-Signature: 7osfox9ojw9ebcng51yxup5a4gqfzd75 X-HE-Tag: 1654884361-84143 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, Jun 10, 2022 at 10:38:12AM -0700, 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 > --- > mm/userfaultfd.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c > index 4f4892a5f767..07d3befc80e4 100644 > --- a/mm/userfaultfd.c > +++ b/mm/userfaultfd.c > @@ -246,7 +246,10 @@ 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); > + /* Our caller expects us to return -EFAULT if we failed to find page. */ > + if (ret == -ENOENT) > + ret = -EFAULT; I checked shmem_getpage_gfp() and it only returns -ENOENT in one place where is the missing case for SGP_NOALLOC, then this looks correct to me. Acked-by: Peter Xu Thanks, -- Peter Xu