Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp173903pxb; Mon, 7 Feb 2022 08:45:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuNzv5GqMMjwMWsvXxXljf2niq1RDTKh4WjzoseNLv4ihyWgXHVj0e7q5Knckr1FcU4aEw X-Received: by 2002:a17:906:dc91:: with SMTP id cs17mr451399ejc.678.1644252310890; Mon, 07 Feb 2022 08:45:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644252310; cv=none; d=google.com; s=arc-20160816; b=boOgY/p42qjMWFOU7n2XAJX47RRY7OKqTIBSFXHmA6qQ7O9xXnfTZKPA4vZj20u3xU iJ1JAuVkJ3F3KpSdew7bKqQf9f0sxwj61mQlWac5jj14jilB1OEhNt+bQc4eG3N4eQFN 8/1vNpKSXrPGTgg7ThGgLT8qOv6Px7ZPBChMn7R+mcwqlwmQfczPZKCjcRLxwNdSPr4u +uPe7Uw9WtbY6aIbdXedahtT2/Bv+9/LvbZvmWH86pHx090p3tSDA7hwOyC1Fly6bSGb kPdZ/pzjTuEllQ6Giosqgh/RlShu72pYSDGr8XIyjVls0A1okblmZZwd9+eKNU5srfaL C5vA== 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=laVS1zO2EThVkNeZ4rz7U7ORBArTWOIiwe6cc14IlZw=; b=UffjcB4Yb3H0PwTGTN+loPL6jG7C5SKv4IicYcqrFlDyErDU9JGKNjwzTkQq08WbMW 19N6FVJf/yaF9aqT8X15b8uIyyhurDmk0FzRHxhhk1vXX/uOhhHcywr1d8XpPVoVVUb6 jUG6Z/5Kvwi5o5IYm2ozNe3hIt47xTF039Avd5cQ3HLZD0rnc3CUtC7t4IDK+OlC9H/e lI7onwysnca2Vseo5YXGswEtcSUqfLNwfTznBM+0uVSP+p0xTpT4SLXPNLWqqItiVHhm gaIbz1QExm4x//bZC892i2T5PXErhDDw97UmxjBoRHpYus2j6sqIrU/oJqAlkoLo6J+v HPEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel-com.20210112.gappssmtp.com header.s=20210112 header.b=fKASpfRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3si7379364ejj.22.2022.02.07.08.44.44; Mon, 07 Feb 2022 08:45:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel-com.20210112.gappssmtp.com header.s=20210112 header.b=fKASpfRn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240129AbiBDVHZ (ORCPT + 99 others); Fri, 4 Feb 2022 16:07:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233239AbiBDVHY (ORCPT ); Fri, 4 Feb 2022 16:07:24 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D53FC061714 for ; Fri, 4 Feb 2022 13:07:22 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id d5so6694647pjk.5 for ; Fri, 04 Feb 2022 13:07:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=laVS1zO2EThVkNeZ4rz7U7ORBArTWOIiwe6cc14IlZw=; b=fKASpfRnI5mOlBRA8i9Z4b37bEGo3GHzIXQ6+R/5YPGFwxi6eWPd5w9PmG8GKtXryd UXOzWsTM8GDlIPgSGk8wW1zyLOEq11WULbps+HAhMpVfo5xuZCOj3I8ZvfEU8QbdIBHs 402dYrnejDaiOt0gzcaxu+fdwi1bBaiF2UfHyieDWcubeYyYK11ZOOZIU1CtX7KZhX7i HblOt2AT4nxKQlg+ITyqcXwGfa15DcGPJkD11mC5CsWToFLbOce2FI0agPRkoHj34kI2 3TS+Krycwx8s2GmXx3v3kLv195RHxhDhZeMGqKL4l4n9ZG2bchMwadyoAViGbntxY1nZ nKMw== 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=laVS1zO2EThVkNeZ4rz7U7ORBArTWOIiwe6cc14IlZw=; b=dLB+TTiy3GHi7K+upgLBjtYb2eAHscyLJnQxQKCNaNyVa5v4eK4Xkej5k7OeqwLmKO kEoSoLgH+z5QN8vXUpafQUgVUGUvuXRWXAl6ofvXTw9fRShP2v+dXsGJvQJX/KJIsLCC bLWxWxfxzuHOuEtF/cAXmDgDtrtLdNBpnjXSzt+CSlEDRt93h322jbn7ygdG1wl9V2Pz B6lCEN/ITzKGEvx0GrTeisgvYoVTUfgy869T48rbGMODWTVg2yVV76v37WUn6sGrGCRy cbmscekTKXrjsd34+vPza8VisWOQG1tet0QPyoRAPGltDV2qAhP35/8Vop4g4AvWUgA6 gNFQ== X-Gm-Message-State: AOAM533YoNTU53SEQjIZBzxBrOKTBSiF9LKpV0PbGfzhKu1bYLLXa3r6 30OjZ2lU5vxThtT8YxG69sv9xubw/N8bKCUBndYfgQ== X-Received: by 2002:a17:902:b20a:: with SMTP id t10mr4924993plr.132.1644008841760; Fri, 04 Feb 2022 13:07:21 -0800 (PST) MIME-Version: 1.0 References: <20220127175505.851391-1-ira.weiny@intel.com> <20220127175505.851391-42-ira.weiny@intel.com> In-Reply-To: <20220127175505.851391-42-ira.weiny@intel.com> From: Dan Williams Date: Fri, 4 Feb 2022 13:07:10 -0800 Message-ID: Subject: Re: [PATCH V8 41/44] kmap: Ensure kmap works for devmap pages To: "Weiny, Ira" Cc: Dave Hansen , "H. Peter Anvin" , Fenghua Yu , Rick Edgecombe , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 27, 2022 at 9:55 AM wrote: > > From: Ira Weiny > > Users of devmap pages should not have to know that the pages they are > operating on are special. How about get straight to the point without any ambiguous references: Today, kmap_{local_page,atomic} handles granting access to HIGHMEM pages without the caller needing to know if the page is HIGHMEM, or not. Use that existing infrastructure to grant access to PKS/PGMAP access protected pages. > Co-opt the kmap_{local_page,atomic}() to mediate access to PKS protected > pages via the devmap facility. kmap_{local_page,atomic}() are both > thread local mappings so they work well with the thread specific > protections available. > > kmap(), on the other hand, allows for global mappings to be established, > Which is incompatible with the underlying PKS facility. Why is kmap incompatible with PKS? I know why, but this is a claim without evidence. If you documented that in a previous patch, there's no harm and copying and pasting into this one. A future git log user will thank you for not making them go to lore to try to find the one patch with the details. Extra credit for creating a PKS theory of operation document with this detail, unless I missed that? > For this reason > kmap() is not supported. Rather than leave the kmap mappings to fault > at random times when users may access them, Is that a problem? This instrumentation is also insufficient for legitimate usages of page_address(). Might as well rely on the kernel developer community being able to debug PKS WARN() splats back to the source because that will need to be done regardless, given kmap() is not the only source of false positive access violations. > call > pgmap_protection_flag_invalid() to show kmap() users the call stack of > where mapping was created. This allows better debugging. > > This behavior is safe because neither of the 2 current DAX-capable > filesystems (ext4 and xfs) perform such global mappings. And known > device drivers that would handle devmap pages are not using kmap(). Any > future filesystems that gain DAX support, or device drivers wanting to > support devmap protected pages will need to use kmap_local_page(). > > Direct-map exposure is already mitigated by default on HIGHMEM systems > because by definition HIGHMEM systems do not have large capacities of > memory in the direct map. And using kmap in those systems actually > creates a separate mapping. Therefore, to reduce complexity HIGHMEM > systems are not supported. It was only at the end of this paragraph did I understand why I was reading this paragraph. The change in topic was buried. I.e. --- Note: HIGHMEM support is mutually exclusive with PGMAP protection. The rationale is mainly to reduce complexity, but also because direct-map exposure is already mitigated by default on HIGHMEM systems because by definition HIGHMEM systems do not have large capacities of memory in the direct map... --- That note and related change should probably go in the same patch that introduces CONFIG_DEVMAP_ACCESS_PROTECTION in the first place. It's an unrelated change to instrumenting kmap() to fail early, which again I don't think is strictly necessary. > > Cc: Dan Williams > Cc: Dave Hansen > Signed-off-by: Ira Weiny > > --- > Changes for V8 > Reword commit message > --- > include/linux/highmem-internal.h | 5 +++++ > mm/Kconfig | 1 + > 2 files changed, 6 insertions(+) > > diff --git a/include/linux/highmem-internal.h b/include/linux/highmem-internal.h > index 0a0b2b09b1b8..1a006558734c 100644 > --- a/include/linux/highmem-internal.h > +++ b/include/linux/highmem-internal.h > @@ -159,6 +159,7 @@ static inline struct page *kmap_to_page(void *addr) > static inline void *kmap(struct page *page) > { > might_sleep(); > + pgmap_protection_flag_invalid(page); > return page_address(page); > } > > @@ -174,6 +175,7 @@ static inline void kunmap(struct page *page) > > static inline void *kmap_local_page(struct page *page) > { > + pgmap_mk_readwrite(page); > return page_address(page); > } > > @@ -197,6 +199,7 @@ static inline void __kunmap_local(void *addr) > #ifdef ARCH_HAS_FLUSH_ON_KUNMAP > kunmap_flush_on_unmap(addr); > #endif > + pgmap_mk_noaccess(kmap_to_page(addr)); > } > > static inline void *kmap_atomic(struct page *page) > @@ -206,6 +209,7 @@ static inline void *kmap_atomic(struct page *page) > else > preempt_disable(); > pagefault_disable(); > + pgmap_mk_readwrite(page); > return page_address(page); > } > > @@ -224,6 +228,7 @@ static inline void __kunmap_atomic(void *addr) > #ifdef ARCH_HAS_FLUSH_ON_KUNMAP > kunmap_flush_on_unmap(addr); > #endif > + pgmap_mk_noaccess(kmap_to_page(addr)); > pagefault_enable(); > if (IS_ENABLED(CONFIG_PREEMPT_RT)) > migrate_enable(); > diff --git a/mm/Kconfig b/mm/Kconfig > index 67e0264acf7d..d537679448ae 100644 > --- a/mm/Kconfig > +++ b/mm/Kconfig > @@ -779,6 +779,7 @@ config ZONE_DEVICE > config DEVMAP_ACCESS_PROTECTION > bool "Access protection for memremap_pages()" > depends on NVDIMM_PFN > + depends on !HIGHMEM > depends on ARCH_HAS_SUPERVISOR_PKEYS > select ARCH_ENABLE_SUPERVISOR_PKEYS > default y > -- > 2.31.1 >