Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp490825pxf; Wed, 10 Mar 2021 10:13:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJz1A3ZFe4X4C/AItp5jXuJZL87qnRJZ49reUyomQtKJ4TVTjKAT07xaeUlOO41LW39TF3QZ X-Received: by 2002:a05:6402:510f:: with SMTP id m15mr4832110edd.328.1615400016336; Wed, 10 Mar 2021 10:13:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615400016; cv=none; d=google.com; s=arc-20160816; b=Jd+Q1OPg60aedCSo3b8FcCnRiM6UAegFhNspH9+cu5oLJ4886Reoqwwga7ttCUT6Qa xlXV8tgauKd6WfALshG6//8MgDCgRKvtbEbER0mHVziBkbV5vCFX9bqBir6GtTNBRMnr 11DIlVcwluHfwOcooCEt1vwCq7NNMA4k1qxZo5c0Z/QEkHnlR+yrxEl6wiVtcNzaLU1q JqH/5WqWDtAY/wnrU8V8HFQr3rHOhwFs1TmCYhkpO0EgRmzm6GuPb0qYpyl1qfB2rYQL AdZfqzo8TZV2ahCuE/qqmbPnP2sPkN75nU41fuXcTvXhxRUGY0RmR++f9oraDvZbZUXd AQjA== 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=gJAsZyfDCDLDzspGcP+6q6V8qY1kikL05fqsU033Nz4=; b=Lt+qrmk7BwQf3M3lwAQdMkO1/hCusjXA2fQA2Iq5CqrnjVyhanRjdY66vHDZFH027u AV+0mME56S/zyqDfWdIPneZ/hmatMGRa2Cu1hzlYcVUs0Xj4xwtHhAKGDyp7AU+tiSdi zA9v50hiSv84xiuDUerWKDHnOex9EZ7IvB+ngc38FoX78fcCvWfBAc+RsvVxx5Pl5T8l qz1s+0JzjXUIVmapIl7r2MmwGjSLv8rsrcAXtJKvYjWpOgA+NG6egwDMmRgz3XweHI9Q 9cMbr2SFFOn2sQCy1m6Cq2H5gcM1DsGtDBqSubr8erXraCRhKsTnKS1CegtpJTW622iL Xgcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SC7BwuYM; 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 m2si55252ejb.357.2021.03.10.10.13.13; Wed, 10 Mar 2021 10:13:36 -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=SC7BwuYM; 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 S233339AbhCJSKF (ORCPT + 99 others); Wed, 10 Mar 2021 13:10:05 -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-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