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 1FAC5CCA479 for ; Wed, 13 Jul 2022 14:24:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9F12D94013A; Wed, 13 Jul 2022 10:24:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 979B0940134; Wed, 13 Jul 2022 10:24:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F2D394013A; Wed, 13 Jul 2022 10:24:24 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6A7FC940134 for ; Wed, 13 Jul 2022 10:24:24 -0400 (EDT) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 1ECED80E99 for ; Wed, 13 Jul 2022 14:24:24 +0000 (UTC) X-FDA: 79682296848.27.1CF3B53 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 6937E180035 for ; Wed, 13 Jul 2022 14:24:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657722261; 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=qU+KHYCrnvvC8T5bF7a/9GP4ChOrSrmP53V18b7bwkk=; b=V4QXDa44+lfjhWStdB4k7OPEyqie98VbPIZt2ixrTAfYkLwUbG/FEGbEzlinIde+JTvxYm 9q2xijF/6CzL1bpnXWiM8ZHKXMPgKbalO0RHUsbmRwlLyPMr2JUf8NAI8d1peWshWhyY6R hR3c/Gqakr8ad9kV56+AX9+NYDa4asw= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-428-W6KXJFhEOaalv05hlLd1zw-1; Wed, 13 Jul 2022 10:24:12 -0400 X-MC-Unique: W6KXJFhEOaalv05hlLd1zw-1 Received: by mail-qk1-f199.google.com with SMTP id bp14-20020a05620a458e00b006b59195c391so5896666qkb.19 for ; Wed, 13 Jul 2022 07:24:12 -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=qU+KHYCrnvvC8T5bF7a/9GP4ChOrSrmP53V18b7bwkk=; b=iT53246nX5Ix+wbilfmIm7ghbZubsiOAEXQJwR4fUaEva8pkCZyWovSxg6IbyFqdUf dDtFUoV7liUS9qGO3nCbSzSMkeCbqFQe8W+uA492dX6+1NQOokSByCydak/6h2+ZQ1m8 WedJZLWLI9nF3WLD9mZev0iL/Fx4ei0vmwGt2OAQb4EL24u02UzY4OSUt4JmyrB5cnYf jFb67dlW6zoGMlKfzoA80knR73AKLucdwfwTyDnoerDXqbNUYU+R4d9lJ7YRDj1+1wCg HUSV5cmGZAUzUTpPO3vOWAMC60ihXwQH9HKocAPO423C1RMLbprj3CMRdh46UWSsJPt5 McXQ== X-Gm-Message-State: AJIora9IxNcWYa7G+Y7ETCWl9OTEtqyyYd4IDC5VWBVcxWPpBTJ2jCXN ToSxtguXzPYboisYKWZLeYt6HpeuE2PfAp+zastJAN+hMPPBs7ayXjOIFKkvEePaqctJ3G13Q4s KsXhBDe0cVhs= X-Received: by 2002:a05:620a:1404:b0:6b5:a44b:80f8 with SMTP id d4-20020a05620a140400b006b5a44b80f8mr2541023qkj.380.1657722252469; Wed, 13 Jul 2022 07:24:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tGBes8AqdSXg08o3SbPXKt7aSXWfqI0biomEA3nNuTESP6sI6rucDtPB/jonvg9ke07JhCfA== X-Received: by 2002:a05:620a:1404:b0:6b5:a44b:80f8 with SMTP id d4-20020a05620a140400b006b5a44b80f8mr2541005qkj.380.1657722252224; Wed, 13 Jul 2022 07:24:12 -0700 (PDT) Received: from xz-m1.local (bras-base-aurron9127w-grc-37-74-12-30-48.dsl.bell.ca. [74.12.30.48]) by smtp.gmail.com with ESMTPSA id az30-20020a05620a171e00b006b14b303b37sm11601253qkb.102.2022.07.13.07.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 07:24:11 -0700 (PDT) Date: Wed, 13 Jul 2022 10:24:09 -0400 From: Peter Xu To: Mike Kravetz , Axel Rasmussen Cc: Miaohe Lin , akpm@linux-foundation.org, songmuchun@bytedance.com, Axel Rasmussen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte Message-ID: References: <20220712130542.18836-1-linmiaohe@huawei.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657722262; 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=qU+KHYCrnvvC8T5bF7a/9GP4ChOrSrmP53V18b7bwkk=; b=bxHeVoA/zmRReJsfSe6HbU2JOMfyB4idbJuhQed5MeuUSNy67wwUguHl3P+rw9FrBcN6yr 2lwlx4q1DT7A5RCnEmcw3fsFlEfo1F7C5RO64gmxhyMoYlvsKuCHrvi1SvF+PtHspwCNxB qrQxRIDjyABDH30RlNDwtyy9V8pfnXQ= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V4QXDa44; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657722262; a=rsa-sha256; cv=none; b=FSzEqvqIRALVpA83zhlvAAJUObIzilR4CpykZO/mWIieS5mUYzuktj4aNAkOvA5q1te9FE H1CwHL7PZlGKIcfAgzIU31w5pUFP2nGL1NsX0aMejmHL/rOv+43GJrPPIr+5xi6Io6y69b 52S6RzLHOF0pd9D3lTakJUtD0UiVS2I= X-Stat-Signature: zttpe8r4mqi39ssjgj4b51towp98z8ud X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6937E180035 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=V4QXDa44; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf06.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=peterx@redhat.com X-Rspam-User: X-HE-Tag: 1657722262-928007 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 Tue, Jul 12, 2022 at 10:39:20AM -0700, Mike Kravetz wrote: > On 07/12/22 21:05, Miaohe Lin wrote: > > In MCOPY_ATOMIC_CONTINUE case with a non-shared VMA, pages in the page > > cache are installed in the ptes. But hugepage_add_new_anon_rmap is called > > for them mistakenly because they're not vm_shared. This will corrupt the > > page->mapping used by page cache code. > > > > Fixes: f619147104c8 ("userfaultfd: add UFFDIO_CONTINUE ioctl") > > Signed-off-by: Miaohe Lin > > --- > > mm/hugetlb.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > This looks correct to me. > > Reviewed-by: Mike Kravetz > > However, I am having a hard time wrapping my head around how UFFDIO_CONTINUE > should work on non-anon private mappings. For example, a private mapping of > a hugetlbfs file. I think we just map the page in the file/cache and do not > set the write bit in the pte. So, yes we would want page_dup_file_rmap() > in this case as shown below. > > Adding Axel and Peter on Cc: as they were more involved in adding that code > and the design of UFFDIO_CONTINUE. Yes the change makes sense to me too. There's just one thing to check on whether minor mode should support private mappings at all as it's probably not in the major goal of when it's proposed. I don't see why it can't logically, but I think we should have failed the uffdio-register already somewhere before when the vma was private and registered with minor mode. It's just that I cannot quickly find it in the code anywhere.. ideally it should be checked in vma_can_userfault() but it seems not. Axel? PS: the minor mode man page update seems to be still missing. -- Peter Xu