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 5DF37C43334 for ; Thu, 14 Jul 2022 00:20:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8FAC1940165; Wed, 13 Jul 2022 20:20:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8AA53940134; Wed, 13 Jul 2022 20:20:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 74D4F940165; Wed, 13 Jul 2022 20:20:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 6474D940134 for ; Wed, 13 Jul 2022 20:20:45 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3571634D09 for ; Thu, 14 Jul 2022 00:20:45 +0000 (UTC) X-FDA: 79683799650.19.3624332 Received: from mail-io1-f41.google.com (mail-io1-f41.google.com [209.85.166.41]) by imf28.hostedemail.com (Postfix) with ESMTP id D2479C007C for ; Thu, 14 Jul 2022 00:20:44 +0000 (UTC) Received: by mail-io1-f41.google.com with SMTP id p81so136044iod.2 for ; Wed, 13 Jul 2022 17:20:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=CDf7ponVtSwiyUmUKyQv1LkgIIKuEWvKXkEsaaBEY2Y=; b=HggXnN/J0acz+YkhI6q06LHQzBUWx4SyERrzbFwCiDcE1fGxZ9FojgYvQAp4NPNlg2 BqZiTqxFrRGHT0j6lzha6tR6mO9YtCc0lOQ7cdQT7HJX7GZwEhMBTC0Vd/vBeHY8XlXP PClWPE2NT3hxcPxu088W1BXA1sCkVtwqhUZKXuuB0W1NX6UD9ZM4tbfDTmZhEFjaqvu9 VFImIZ5m8BP6JXevrJ4dAbhax590AiWG3V5ykKC0B/qyA4+rvunzJMdr/c6A/K5OZRHy h/hLRQKqpSGh6iq+PkJhgpIKPafI7SNvj4eAGdpIY0P6U+Cetrq/UNIj1SiI1FET4OLg MHgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CDf7ponVtSwiyUmUKyQv1LkgIIKuEWvKXkEsaaBEY2Y=; b=kzgDeKvVUEZFdQLu2INYeR+5ias/7zOYbPLbPOS8QHDc5aybhKtY7aJGoYuEnxdC8O sYaaO8uVXaOpRyo5Ui+KXTa912NqEkmpc9aORf0B/jA686PSCBf8YOdhsC2W8Yr6VRvm QL9bAUA5boPthJjtHHNu2chtPR3Vq2GKi0+JhexiC5NRWYyGcuBdoLsTMaCdquBZdVGD lAm4iCkaq3iGfAIyVydX2dS86pMojUP+rYrACiKel1EX0+pazSQWJ3gUz6HZTTI0YY/P FULjqdFFlEddI9R0qisL6KjFSpbQqyVDQ8lQ8qV7RrotGZFxwayfxvZC/IDlcHgOUEwv eBPg== X-Gm-Message-State: AJIora8vxA0wuCVJpCc3FSZCxQOKSljz/b7AKJS4T+bXns0s3YJte7H7 GuEWS6ru/SZLLOsfSViY7YyxvlCFZtDu1+nQCKQ1Iw== X-Google-Smtp-Source: AGRyM1utcceOTJGlb4M5/bFD4LjtpLOqEpDwdFZ5zX7llLQO/pbiz4LcSPnGu54S1lGVOngExwZQefuHXR0jsKyVbOw= X-Received: by 2002:a05:6638:349f:b0:33f:68a2:5eb5 with SMTP id t31-20020a056638349f00b0033f68a25eb5mr3415957jal.167.1657758044032; Wed, 13 Jul 2022 17:20:44 -0700 (PDT) MIME-Version: 1.0 References: <20220712130542.18836-1-linmiaohe@huawei.com> In-Reply-To: From: Axel Rasmussen Date: Wed, 13 Jul 2022 17:20:07 -0700 Message-ID: Subject: Re: [PATCH] mm/hugetlb: avoid corrupting page->mapping in hugetlb_mcopy_atomic_pte To: Mike Kravetz Cc: Peter Xu , Miaohe Lin , Andrew Morton , Muchun Song , Linux MM , LKML Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657758044; a=rsa-sha256; cv=none; b=Ws/Pv/bL0Yf6wjj0Dfxnorp4An6t0B01l0O6uyRZTWlSxWjU5dojT17SOVBa0hkAvfX+j7 N26YeiBmbgbtanxgSY237/Mf8jc8kIpTRBKDoivGdYUTOxfkM/UsuU00TlMErrtWXcfOBw GgXZzG9l7YLYaCxeWR85XndUZVXWlQo= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="HggXnN/J"; spf=pass (imf28.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.41 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657758044; 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=CDf7ponVtSwiyUmUKyQv1LkgIIKuEWvKXkEsaaBEY2Y=; b=StSCPwbAbIJVKeuKBRHUnaicSOOdw7xSmlqXQE2MXuRIh6B/3Z1ExcSljybu2N2FoLWz86 VgZOvtQVWpCdf3VSltVKQ7Gw/ync8hjyfNrAjpwROpEUI4GNs3QeED7iDLU5DAZUuoPyXS ps1sCK9J/hnicEYkzwqjKIF/EhBZR7k= X-Rspamd-Queue-Id: D2479C007C Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b="HggXnN/J"; spf=pass (imf28.hostedemail.com: domain of axelrasmussen@google.com designates 209.85.166.41 as permitted sender) smtp.mailfrom=axelrasmussen@google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam02 X-Rspam-User: X-Stat-Signature: bidb47gswabii8r9i6q7cij9ju95nywb X-HE-Tag: 1657758044-937694 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 Wed, Jul 13, 2022 at 4:36 PM Mike Kravetz wrote: > > On 07/13/22 15:46, Axel Rasmussen wrote: > > I think there is a small mistake in this patch. > > > > Consider the non-minor-fault case. We have this block: > > > > /* Add shared, newly allocated pages to the page cache. */ > > if (vm_shared && !is_continue) { > > /* ... */ > > } > > > > In here, we've added the newly allocated page to the page cache, and > > we've set this page_in_pagecache flag to true. But we *do not* setup > > rmap for this page in this block. I think in this case, the patch will > > cause us to do the wrong thing: we should hugepage_add_new_anon_rmap() > > further down, but with this patch we dup instead. > > I am not sure I follow. The patch from Miaohe Lin would not change any > behavior in the 'if (vm_shared && !is_continue)' case. In this case > both vm_shared and page_in_pagecache are true. > > IIUC, the patch would address the case where !vm_shared && is_continue. Ah, you're right, my interpretation of the various flags got mixed up somewhere along the way. page_in_pagecache is equivalent to vm_shared in this function, *except* when we have is_continue. Given that, I think this patch is correct in the vm_shared case (no behavior change). In case of !vm_shared && is_continue, I agree the patch is a correction to the previous behavior. > > 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(-) > > > > diff --git a/mm/hugetlb.c b/mm/hugetlb.c > > index 8d379e03f672..b232e1508e49 100644 > > --- a/mm/hugetlb.c > > +++ b/mm/hugetlb.c > > @@ -6038,7 +6038,7 @@ int hugetlb_mcopy_atomic_pte(struct mm_struct *dst_mm, > > if (!huge_pte_none_mostly(huge_ptep_get(dst_pte))) > > goto out_release_unlock; > > > > - if (vm_shared) { > > + if (page_in_pagecache) { > > page_dup_file_rmap(page, true); > > } else { > > ClearHPageRestoreReserve(page); > > -- > Mike Kravetz