lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220419170649.1022246-29-ira.weiny@intel.com>
Date:   Tue, 19 Apr 2022 10:06:33 -0700
From:   ira.weiny@...el.com
To:     Dave Hansen <dave.hansen@...ux.intel.com>,
        "H. Peter Anvin" <hpa@...or.com>,
        Dan Williams <dan.j.williams@...el.com>
Cc:     Ira Weiny <ira.weiny@...el.com>, Fenghua Yu <fenghua.yu@...el.com>,
        Rick Edgecombe <rick.p.edgecombe@...el.com>,
        "Shankar, Ravi V" <ravi.v.shankar@...el.com>,
        linux-kernel@...r.kernel.org
Subject: [PATCH V10 28/44] memremap_pages: Introduce devmap_protected()

From: Ira Weiny <ira.weiny@...el.com>

Consumers of protected dev_pagemaps can check the PGMAP_PROTECTION flag to
see if the devmap is protected.  However, most contexts will have a struct
page not the pagemap structure directly.

Define devmap_protected() to determine if a page is part of a
dev_pagemap mapping and if the page is protected by additional
protections.

Signed-off-by: Ira Weiny <ira.weiny@...el.com>

---
Changes for V10
	Move code from mm.h to memremap.h
		Upstream separated memremap.h functionality from mm.h
		dc90f0846df4 ("mm: don't include <linux/memremap.h> in <linux/mm.h>")
---
 include/linux/memremap.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/include/linux/memremap.h b/include/linux/memremap.h
index 02c415b1b278..6325f00096ec 100644
--- a/include/linux/memremap.h
+++ b/include/linux/memremap.h
@@ -223,6 +223,23 @@ static inline bool pgmap_protection_available(void)
 	return pks_available();
 }
 
+DECLARE_STATIC_KEY_FALSE(dev_pgmap_protection_static_key);
+
+/*
+ * devmap_protected() requires a reference on the page to ensure there is no
+ * races with dev_pagemap tear down.
+ */
+static inline bool devmap_protected(struct page *page)
+{
+	if (!static_branch_unlikely(&dev_pgmap_protection_static_key))
+		return false;
+	if (!is_zone_device_page(page))
+		return false;
+	if (page->pgmap->flags & PGMAP_PROTECTION)
+		return true;
+	return false;
+}
+
 #else
 
 static inline bool pgmap_protection_available(void)
-- 
2.35.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ