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=unavailable 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 65CC4C433DB for ; Wed, 10 Mar 2021 18:10:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B2E664FB2 for ; Wed, 10 Mar 2021 18:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233406AbhCJSKG (ORCPT ); Wed, 10 Mar 2021 13:10:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232915AbhCJSJt (ORCPT ); Wed, 10 Mar 2021 13:09:49 -0500 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 315E8C061760 for ; Wed, 10 Mar 2021 10:09:45 -0800 (PST) Received: by mail-ej1-x62a.google.com with SMTP id jt13so40617046ejb.0 for ; Wed, 10 Mar 2021 10:09:45 -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=gJAsZyfDCDLDzspGcP+6q6V8qY1kikL05fqsU033Nz4=; b=SC7BwuYMthuL7KnQIhtiddqRok9XAh9gcjM97rHzKdVXjJpoh6TkW0z0O+K8Zudu8x JPZTUm5toVVXQGCslw/S1cHIfiE36I8q0tGDT+YUSeqev1f6ry4L/RmPVaOTBefWmXSo VJ6sLW9YJ11CsRbnwn8LMwY0qDXVBCq24MmN+vSBu/GArQoA0cFoaPxoGeSRIjBDDt3v i7ujukCxirP5KWnulJ/he7BEN4ok063e0yjjW6fabwUtF11T98Is57KmdWXULwDKO9ba sMPY67YmABfaj67e/ifXPkGu86Md7n+sRzOqGMvtAmbqKBJuZWIvrW0ZabkxH7Yrh0kY 8pEg== 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=gJAsZyfDCDLDzspGcP+6q6V8qY1kikL05fqsU033Nz4=; b=PwpMmVRQ4KvJjDtadRjoi041b5aPqyMycEY36RcvccLVS0Jb09yOag5lfhbOCpIN+t ZEwMTyYADeFhzLrFUY9if4HR35RrrRQUE4xcogJo/SK4o7Vao5ZQCgeoeF+zne3J++KC 51IwP1X5Mj+d+MX8XEBqKBEFviflTYMU5uJfi2rYjxkmmUzg26C9t3bP2AAoQkU3FLut M+4ZiLiegMg6JH7R7Z+VbWOqfyfQkzTlvwQkj4ngL48KglKdzvWtB0+qAO9OQDGt+xR3 rcWsQacg9u75ufYUW6kReLc7tbOMErqBI/Y8FUeI5xwflFFwn4A9qnjkdogVyTpCllUA j8Rg== X-Gm-Message-State: AOAM531AFhqKNMhyw1cZgiFDSQ1oDNU3f6jxnXJCwGQH9F/padnD1lCU jar265461H5FGpiiglIdu7zzx6zwFiBWNre87edoiw== X-Google-Smtp-Source: ABdhPJz7X8EAeavYVAMuOixYYEkGqm/ao9bUZTWDvbUa0pzwfhRvQpKr+aPzlD7TsVVjXIoYOXXFZ88PdEVAqY4wc8U= X-Received: by 2002:a17:906:a052:: with SMTP id bg18mr5034455ejb.18.1615399783815; Wed, 10 Mar 2021 10:09:43 -0800 (PST) MIME-Version: 1.0 References: <20210218230633.15028-1-peterx@redhat.com> <20210218231202.15426-1-peterx@redhat.com> <20210310165713.GB6530@xz-x1> In-Reply-To: <20210310165713.GB6530@xz-x1> From: Naresh Kamboju Date: Wed, 10 Mar 2021 23:39:32 +0530 Message-ID: Subject: Re: [PATCH v4 2/4] hugetlb/userfaultfd: Forbid huge pmd sharing when uffd enabled To: Peter Xu Cc: Linux-Next Mailing List , 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 On Wed, 10 Mar 2021 at 22:27, Peter Xu wrote: > > On Wed, Mar 10, 2021 at 01:18:42PM +0530, Naresh Kamboju wrote: > > Hi Peter, > > Hi, Naresh, > > > > > 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 > > Sorry for the issue & thanks for the report. Would you please check whether > the patch attached could fix the issue? The attached patch build tested and build pass for arm64 including 64k pages config. CONFIG_ARM64_64K_PAGES=y - Naresh 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 43907C433E0 for ; Wed, 10 Mar 2021 18:09:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CC6D164FB2 for ; Wed, 10 Mar 2021 18:09:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CC6D164FB2 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 480198D01F5; Wed, 10 Mar 2021 13:09:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 42F398D01ED; Wed, 10 Mar 2021 13:09:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A94D8D01F5; Wed, 10 Mar 2021 13:09:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0116.hostedemail.com [216.40.44.116]) by kanga.kvack.org (Postfix) with ESMTP id 0A2D68D01ED for ; Wed, 10 Mar 2021 13:09:46 -0500 (EST) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id BC97C181AF5C4 for ; Wed, 10 Mar 2021 18:09:45 +0000 (UTC) X-FDA: 77904752730.19.0D5C7D6 Received: from mail-ej1-f43.google.com (mail-ej1-f43.google.com [209.85.218.43]) by imf04.hostedemail.com (Postfix) with ESMTP id 5D7BA3C2 for ; Wed, 10 Mar 2021 18:09:44 +0000 (UTC) Received: by mail-ej1-f43.google.com with SMTP id r17so40523441ejy.13 for ; Wed, 10 Mar 2021 10:09:44 -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=gJAsZyfDCDLDzspGcP+6q6V8qY1kikL05fqsU033Nz4=; b=SC7BwuYMthuL7KnQIhtiddqRok9XAh9gcjM97rHzKdVXjJpoh6TkW0z0O+K8Zudu8x JPZTUm5toVVXQGCslw/S1cHIfiE36I8q0tGDT+YUSeqev1f6ry4L/RmPVaOTBefWmXSo VJ6sLW9YJ11CsRbnwn8LMwY0qDXVBCq24MmN+vSBu/GArQoA0cFoaPxoGeSRIjBDDt3v i7ujukCxirP5KWnulJ/he7BEN4ok063e0yjjW6fabwUtF11T98Is57KmdWXULwDKO9ba sMPY67YmABfaj67e/ifXPkGu86Md7n+sRzOqGMvtAmbqKBJuZWIvrW0ZabkxH7Yrh0kY 8pEg== 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=gJAsZyfDCDLDzspGcP+6q6V8qY1kikL05fqsU033Nz4=; b=HcHjFCurxoUzrdNxZ1nV3tmjcIEOt83BymcWhpiLei5yIOMpWrvDlolbVoSch+9tNR L2Cxbhce6V3NhV3YGGAvVapNlLmWUlRwDq+i7E7YQfi3pSGmKqr0bbew92vS2NZQjk/d O2Zm/NnGmZmArYEBN7X9hZaclsgY4UM11aH1XMlqju0OYQaH25rTJXV18oqXjQtqepzx /B9SluQkalLpNBi9ZF9AJexD6MUmWf10W1QH3TdqMHZ8jSK7CzXPoUizxDtnSXIARJqb wiKegcwfTHlk1vEMd3EkmS3su0MDL65GHMx9eSAy0Q5KqgdWBh7Yh+une2wuWGPPIdXo I0Hg== X-Gm-Message-State: AOAM530xjSq/yYHbofKT0JhLVzHtBOa2sUCtya7G2qdqRmF1OeBYKHmK u1k7v/V64991+rAPL6lrhc/GeGV3h/GZZ0iCq0IjbQ== X-Google-Smtp-Source: ABdhPJz7X8EAeavYVAMuOixYYEkGqm/ao9bUZTWDvbUa0pzwfhRvQpKr+aPzlD7TsVVjXIoYOXXFZ88PdEVAqY4wc8U= X-Received: by 2002:a17:906:a052:: with SMTP id bg18mr5034455ejb.18.1615399783815; Wed, 10 Mar 2021 10:09:43 -0800 (PST) MIME-Version: 1.0 References: <20210218230633.15028-1-peterx@redhat.com> <20210218231202.15426-1-peterx@redhat.com> <20210310165713.GB6530@xz-x1> In-Reply-To: <20210310165713.GB6530@xz-x1> From: Naresh Kamboju Date: Wed, 10 Mar 2021 23:39:32 +0530 Message-ID: Subject: Re: [PATCH v4 2/4] hugetlb/userfaultfd: Forbid huge pmd sharing when uffd enabled To: Peter Xu Cc: Linux-Next Mailing List , 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-Stat-Signature: fzeimw8ra7k4aw4hwxttxxzpaqik339s X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 5D7BA3C2 Received-SPF: none (linaro.org>: No applicable sender policy available) receiver=imf04; identity=mailfrom; envelope-from=""; helo=mail-ej1-f43.google.com; client-ip=209.85.218.43 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1615399784-637232 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, 10 Mar 2021 at 22:27, Peter Xu wrote: > > On Wed, Mar 10, 2021 at 01:18:42PM +0530, Naresh Kamboju wrote: > > Hi Peter, > > Hi, Naresh, > > > > > 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 > > Sorry for the issue & thanks for the report. Would you please check whether > the patch attached could fix the issue? The attached patch build tested and build pass for arm64 including 64k pages config. CONFIG_ARM64_64K_PAGES=y - Naresh