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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D1B6C433F5 for ; Tue, 19 Apr 2022 17:08:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355912AbiDSRLJ (ORCPT ); Tue, 19 Apr 2022 13:11:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355657AbiDSRJ4 (ORCPT ); Tue, 19 Apr 2022 13:09:56 -0400 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95728EA5 for ; Tue, 19 Apr 2022 10:07:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650388032; x=1681924032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8HY8BDua6BN4XkwHxR01tuvztdYTdoms4hurcP8Ocpo=; b=U6qi3nPgQlvWwHsJBPyCKGZ8EofngQ1XOE7OJmb7mH2+kzbVocAl6DmN rT9+sYjxZhaMldriTek4uZoqm6szYSe/O0i79U3mWa6FZuJCSzZdqgnij TF7tEXAAGWSvzFgFefCqFY8XxQzicIc8prhsWvuwFnMCCA9cKLuB1zL/m 9wHEnZcx6CkgCfM+6Sy1G3/YNXDvYjpp7MftpQ6OP/2Yxz4/WrcTb3gSc 3W1VBHTvnX+ZXRMMB9KuktVABofp+AviJrJTT2lBVA2M6oBta7fGVRCUC knzrc6Qlhvq/vrO//Cir670VKGO+Tp41tUKp4m24p98aNz8+3Qfkkis+e Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10322"; a="350267610" X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="350267610" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:12 -0700 X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="510207192" Received: from ajacosta-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.11.4]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:11 -0700 From: ira.weiny@intel.com To: Dave Hansen , "H. Peter Anvin" , Dan Williams Cc: Ira Weiny , Fenghua Yu , Rick Edgecombe , "Shankar, Ravi V" , linux-kernel@vger.kernel.org Subject: [PATCH V10 26/44] memremap_pages: Introduce pgmap_protection_available() Date: Tue, 19 Apr 2022 10:06:31 -0700 Message-Id: <20220419170649.1022246-27-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220419170649.1022246-1-ira.weiny@intel.com> References: <20220419170649.1022246-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ira Weiny PMEM will flag additional dev_pagemap protection through (struct dev_pagemap)->flags. However, it is more efficient to know if that protection is available prior to requesting it and failing the mapping. Define pgmap_protection_available() to check if protection is available prior to being requested. The name of pgmap_protection_available() was specifically chosen to isolate the implementation of the protection from higher level users. Signed-off-by: Ira Weiny --- Changes for V10 Move code from mm.h to memremap.h Upstream separated memremap.h functionality from mm.h dc90f0846df4 ("mm: don't include in ") Changes for V9 Clean up commit message From Dan Williams make call stack static inline throughout this call and pks_available() such that callers calls cpu_feature_enabled() directly Changes for V8 Split this out to it's own patch. s/pgmap_protection_enabled/pgmap_protection_available --- include/linux/memremap.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/memremap.h b/include/linux/memremap.h index 8af304f6b504..7980d0db8617 100644 --- a/include/linux/memremap.h +++ b/include/linux/memremap.h @@ -6,6 +6,7 @@ #include #include #include +#include struct resource; struct device; @@ -214,4 +215,20 @@ static inline void put_dev_pagemap(struct dev_pagemap *pgmap) percpu_ref_put(&pgmap->ref); } +#ifdef CONFIG_DEVMAP_ACCESS_PROTECTION + +static inline bool pgmap_protection_available(void) +{ + return pks_available(); +} + +#else + +static inline bool pgmap_protection_available(void) +{ + return false; +} + +#endif /* CONFIG_DEVMAP_ACCESS_PROTECTION */ + #endif /* _LINUX_MEMREMAP_H_ */ -- 2.35.1