Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp60118pxf; Tue, 9 Mar 2021 23:50:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJzNqpmUkBDsaFWR+wRfppgc0FOK4gedo2aY5TSnHsDiQ7pF9Sn8UhRs1dHOxqn+ErBzIKPp X-Received: by 2002:aa7:d98b:: with SMTP id u11mr1882622eds.352.1615362658277; Tue, 09 Mar 2021 23:50:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615362658; cv=none; d=google.com; s=arc-20160816; b=crfdqEYKPe/+bUz5gxCn19gKRj9fkoQlLCvs3KOZvcUFs7Spy8oqOW54wmU2PxSVJq ibsUNjNBOwAZITL0XhwpB1qRUD+824JYG706uSedjfAQNS9rC4oT/4emV6lL1dJIr55T IbxdTIJnYlAWUH45XV7AodTOECE4OQoycqxFaqBxnm9yzo3GTGLv0m6p4l5w6rli1Ukl 69LVYj8Sv+fyh1XY4u1eoM8cdMzIwMi46IwKafsw6UPaB9uAjq/DaALf00P5XoU6vlLk gv2alWa+EIduIguP4eUZTNDBsUTno081sFF3t05Qzw2ZJ/UHZguR18MojWPkqU8R7ECo /XVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UYIAYFhn9jv5jndPR2ePIIH3j9f4IGqFq4xY6Rn35ck=; b=r3Drip92DwrAIMEQJ1J+tQvGIZY/nirrrgANgk62VUOjKWmTY8cOCNLE7jXAGHstcI yXBmP8pL/26npHjuc2iJbwfdvLmUKyMKQV8qW1DrYSdr9A/VA2fjdT+4T9V7Igv1Q5kN 9hmXEbBzEuOK3Yik6oLJC8NzRDQ8wjQNfx/o1uNdXIXk+V5ODnZVEWE79RZAo7tBMWOa gvLXYSdvN7AXe7dt2BNCZ2ealekE+rEVXWhZeusnvAUI/D9hFq/rh5VEHyG/kxxj0Kzx qUTK3WjADamPeLX3rwqGc9QdOiS/Q6kGfPwIzIsoeQ4LyK6+vFEqSeT8yX/+WJR1ShQ6 ulWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=braAeI90; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw1si11864800edb.412.2021.03.09.23.50.35; Tue, 09 Mar 2021 23:50:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=braAeI90; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232055AbhCJHtH (ORCPT + 99 others); Wed, 10 Mar 2021 02:49:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229900AbhCJHsz (ORCPT ); Wed, 10 Mar 2021 02:48:55 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10A71C06174A for ; Tue, 9 Mar 2021 23:48:55 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id mm21so36517715ejb.12 for ; Tue, 09 Mar 2021 23:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UYIAYFhn9jv5jndPR2ePIIH3j9f4IGqFq4xY6Rn35ck=; b=braAeI90Nb4I9UfvR7erd8SSxj9A/vwLm6IcYkkdG1V8lsbJfUXqxxNVPxmc1o2zD5 USyRAFdzI2rzcYdxKTw36cbczuQyPUTpiyNmXacEQhRR/2f9JaBlI+w8quQrllcBespS e1eb1VJDP0R0U0TweLlfRbY6WqtAnRfwOL0zM4vPGXuKY+u/C8ivpxjjsc0PMnc4QkxF TgEK1Bg4dgHt6rGP/Z58bhy3XUGCU5HG56UTok8bezkvdLHj2xMFJ8NZxf9FX5bnFD4m kEEdyNinARJBnWD5V9I+tMJAm1t/HgRpNZbNBglhRIwxapMl7FqUbUGscWgAjojWh3e3 h9+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UYIAYFhn9jv5jndPR2ePIIH3j9f4IGqFq4xY6Rn35ck=; b=l+GTejUBpU/HsmlSNAb8CMt5WlCTQftMb+MBrXgmRRA6LLny5ag88OKQh1AvcVG8aH v0N3Y2fmT+bb3Ocu96q4ieWx+Oc9I5BcVZDGYbxeodH6h0kl94qewI6cMK03N/sd6+cT tl0uKijYYNjIdyR32UM4D6K3Ao+SEG8sQkYZN92YGZVlvhYHHKHTT/PwB4lL8KwgteB1 AXYyomx41mOkyiap05KdH5DjbsOfJpF1U1Caw/YC1E3KG9VvZvlLIAsBVi14A/rax2/n DbslSSJNcgGTitsGjpdub+6WPO/c308LxDDLw+UcZ3LSyhAnawTrlIoBshTINNxezEf/ OVtA== X-Gm-Message-State: AOAM530FXKKSttyV89YrNFIYLuJse5a2P93NLZESIqrjMDm+XhzB2Zw9 jl74K3N1H5MVuxgNsIAJJIe7sPEOgKW2DS7J8XJb2Q== X-Received: by 2002:a17:906:229b:: with SMTP id p27mr2327796eja.287.1615362533619; Tue, 09 Mar 2021 23:48:53 -0800 (PST) MIME-Version: 1.0 References: <20210218230633.15028-1-peterx@redhat.com> <20210218231202.15426-1-peterx@redhat.com> In-Reply-To: <20210218231202.15426-1-peterx@redhat.com> From: Naresh Kamboju Date: Wed, 10 Mar 2021 13:18:42 +0530 Message-ID: Subject: Re: [PATCH v4 2/4] hugetlb/userfaultfd: Forbid huge pmd sharing when uffd enabled To: Peter Xu , Linux-Next Mailing List Cc: open list , linux-mm , Andrea Arcangeli , Axel Rasmussen , Mike Rapoport , "Kirill A . Shutemov" , Andrew Morton , Matthew Wilcox , Mike Kravetz , lkft-triage@lists.linaro.org, Arnd Bergmann , Stephen Rothwell Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Fri, 19 Feb 2021 at 04:43, Peter Xu wrote: > > Huge pmd sharing could bring problem to userfaultfd. The thing is that > userfaultfd is running its logic based on the special bits on page table > entries, however the huge pmd sharing could potentially share page table > entries for different address ranges. That could cause issues on either: > > - When sharing huge pmd page tables for an uffd write protected range, the > newly mapped huge pmd range will also be write protected unexpectedly, or, > > - When we try to write protect a range of huge pmd shared range, we'll first > do huge_pmd_unshare() in hugetlb_change_protection(), however that also > means the UFFDIO_WRITEPROTECT could be silently skipped for the shared > region, which could lead to data loss. > > Since at it, a few other things are done altogether: > > - Move want_pmd_share() from mm/hugetlb.c into linux/hugetlb.h, because > that's definitely something that arch code would like to use too > > - ARM64 currently directly check against CONFIG_ARCH_WANT_HUGE_PMD_SHARE when > trying to share huge pmd. Switch to the want_pmd_share() helper. > > Since at it, move vma_shareable() from huge_pmd_share() into want_pmd_share(). > > Reviewed-by: Mike Kravetz > Reviewed-by: Axel Rasmussen > Signed-off-by: Peter Xu > --- > arch/arm64/mm/hugetlbpage.c | 3 +-- > include/linux/hugetlb.h | 2 ++ > include/linux/userfaultfd_k.h | 9 +++++++++ > mm/hugetlb.c | 20 ++++++++++++++------ > 4 files changed, 26 insertions(+), 8 deletions(-) > > diff --git a/arch/arm64/mm/hugetlbpage.c b/arch/arm64/mm/hugetlbpage.c > index 6e3bcffe2837..58987a98e179 100644 > --- a/arch/arm64/mm/hugetlbpage.c > +++ b/arch/arm64/mm/hugetlbpage.c > @@ -284,8 +284,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, > */ > ptep = pte_alloc_map(mm, pmdp, addr); > } else if (sz == PMD_SIZE) { > - if (IS_ENABLED(CONFIG_ARCH_WANT_HUGE_PMD_SHARE) && > - pud_none(READ_ONCE(*pudp))) > + if (want_pmd_share(vma, addr) && pud_none(READ_ONCE(*pudp))) While building Linux next 20210310 tag for arm64 architecture with - CONFIG_ARM64_64K_PAGES=y enabled the build failed due to below errors / warnings make --silent --keep-going --jobs=8 O=/home/tuxbuild/.cache/tuxmake/builds/1/tmp ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- 'CC=sccache aarch64-linux-gnu-gcc' 'HOSTCC=sccache gcc' aarch64-linux-gnu-ld: Unexpected GOT/PLT entries detected! aarch64-linux-gnu-ld: Unexpected run-time procedure linkages detected! aarch64-linux-gnu-ld: arch/arm64/mm/hugetlbpage.o: in function `huge_pte_alloc': hugetlbpage.c:(.text+0x7d8): undefined reference to `want_pmd_share' Reported-by: Naresh Kamboju Steps to reproduce: ---------------------------- # TuxMake is a command line tool and Python library that provides # portable and repeatable Linux kernel builds across a variety of # architectures, toolchains, kernel configurations, and make targets. # # TuxMake supports the concept of runtimes. # See https://docs.tuxmake.org/runtimes/, for that to work it requires # that you install podman or docker on your system. # # To install tuxmake on your system globally: # sudo pip3 install -U tuxmake # # See https://docs.tuxmake.org/ for complete documentation. tuxmake --runtime podman --target-arch arm64 --toolchain gcc-9 --kconfig defconfig --kconfig-add https://builds.tuxbuild.com/1pYCSoc1oGtPWlPgLAJxbHx07kL/config Build link, https://builds.tuxbuild.com/1pYCSoc1oGtPWlPgLAJxbHx07kL/ -- Linaro LKFT https://lkft.linaro.org