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 X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C135C433DB for ; Wed, 10 Mar 2021 07:48:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1B22D64DAE for ; Wed, 10 Mar 2021 07:48:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B22D64DAE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 849C18D017D; Wed, 10 Mar 2021 02:48:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2758D0148; Wed, 10 Mar 2021 02:48:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5FD858D017D; Wed, 10 Mar 2021 02:48:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0157.hostedemail.com [216.40.44.157]) by kanga.kvack.org (Postfix) with ESMTP id 40CD38D0148 for ; Wed, 10 Mar 2021 02:48:56 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id EC75975B5 for ; Wed, 10 Mar 2021 07:48:55 +0000 (UTC) X-FDA: 77903188230.13.59EB44C Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf19.hostedemail.com (Postfix) with ESMTP id BA10390009EA for ; Wed, 10 Mar 2021 07:48:53 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id lr13so36627036ejb.8 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=enMhz/HEHRJpkWM0lMB7wTjSrHL4yGiRXOahmXBddls/hwltZjORTUroLHZ6Wzsqb5 ph+AZkSgOd+G7+ornj+eshGOWm2IvEae12quUoPS7Cs0YG1yGeMYyjVdRgzLKeBFrYTD HcJXRNYmJ/+IwA9weEMhkW1/u6JgudQkvRRxAKIQ/cZIxb3mQu+mFV5xRt0uMUfZIYIW n2ABABQz3n4dn6Q5EpI1WOlM/qRoa0Whl2i3CQfGNcuEHf8qcDJ9fr5xt+l/5BQ9IVlt jLru0jIVPQ98u0lkbijQPpmN8AXIG5Bia9hbyJuTA9kP+ZbShzGYgztkHNeLmRA8nE49 k6qg== X-Gm-Message-State: AOAM5337lx4tA6NUiu05hDdYHIRyNM+VT1w7DLY3TtusJEuIYad3Oo5B 9tv0MzCGipA6hcEFEyEY9yAS70O/WqgMOIgThFxnfA== X-Google-Smtp-Source: ABdhPJzWLk1+GHbweU/Gu0GuvGkG0Dsq0G+OcfGNZanks6CE76sr07/IWmGLcJAyOtypC8yEDdCjY5TeBojPrD04G2o= 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" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: BA10390009EA X-Stat-Signature: 735cmxyzcsr1rwpyunfpumo3fmk1ipt6 Received-SPF: none (linaro.org>: No applicable sender policy available) receiver=imf19; identity=mailfrom; envelope-from=""; helo=mail-ej1-f42.google.com; client-ip=209.85.218.42 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615362533-670522 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: 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