Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp558618pxb; Fri, 28 Jan 2022 05:20:00 -0800 (PST) X-Google-Smtp-Source: ABdhPJx74661FJwpcktokp3YxO+YEuMXCaWbDxxcm0WfMoDbg9Zv+lkZ97AXgxNy5LtyChiJnCMn X-Received: by 2002:a17:90a:4dc9:: with SMTP id r9mr19415225pjl.156.1643375999918; Fri, 28 Jan 2022 05:19:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643375999; cv=none; d=google.com; s=arc-20160816; b=GMuQIbyqDOvtQUPM7KN13WrKE7JrX5Dvhlh9NGColXJbYPTyu3kOB8W/hJAdRir2xw GPVNtXpLH95WSNCGACOh2g7NUQ/Qfy3ZOm3vAcx75hf0uRkEf2dUbZgycq5DePbj3U5d foyA86rJS1gtRPlYpGj4/n+IpligAcXW1tDiFlndohzuLSr5fcyuBVyJ5bJ+mVLrVi8N egQtI8aN1ABK5YCskjUmy2ub3tlGU9sEjRBHhzaBnzEH+Fe3dmDeFZPXmHkY8WfJUQiU 9QdjjADPc1maK6h065paEqbQ6a+vfxUvmivx0ObtT1q3EgBvDZSc+p6/Nzx1uN7Cuouk VBTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=B0XPiMQOjQ/VfeCRaEGbZ+iwI1RK9syUvs79y8wcR+k=; b=mUY1/enfZQ5CNIwl/BJwuysoGampMkz72wO5ch/ls/E6yK1CyHG/XdNmSf0pwWHy7i Mmk+WOnH/ldB8HL0Lm7sBf9UI0YsuIL2sRyL1YWaz1hCZIffWAt9DH8DvMweV7/WuOrt 2Kzwg4Tw/CXpu1vQgCHNZDEyA1K6cfNMDmv4+VxOCUWCbZeHEjGuKr0dAvfCC024vjGc jTtf6Aos7ZJN3PAUJdpgDpIHxLaOL8ZPUZC7nsm6k/GL5nD+i3LVOwqFJ1mxtAHqcvM8 rO19D4HEVRxGocgxvonCgr4+6Zy1FQNE04JTXkG82H4GgFHJ5bvPBUJInMwDDgfVCA0e b7gQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=UCaenWA+; 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y6si5080941pgy.692.2022.01.28.05.19.48; Fri, 28 Jan 2022 05:19:59 -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=@intel.com header.s=Intel header.b=UCaenWA+; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230371AbiA0R6L (ORCPT + 99 others); Thu, 27 Jan 2022 12:58:11 -0500 Received: from mga02.intel.com ([134.134.136.20]:19418 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244940AbiA0R4A (ORCPT ); Thu, 27 Jan 2022 12:56:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643306160; x=1674842160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=h0ELtLaLvU8d5+IR+z+6tOFYz1WyWnwDtWsLq4wETwc=; b=UCaenWA+v6F3cRkgIaOLC83zozXc9GYTcNqeiy3IqeKTX2PfqbWmqtXY VghJyNmu4xpcN5wmB+6N0N18/kePRIwXFumDIF+zVFs7ILT7hUb2TlwHL Sc/K5iLmFwMOz85kL0gqaWi3vuUPKT0MwxjwW7JVovPdsU4y8mHrb33PP MzMqPtFnyESDlmvdu7choSs7lsfOqiTI0aWuFZFtxEF8601fAqPJcz17c 0BF/xnElGfDp0VLSrOGsQPf/vjJrmobe++auVYxnfpCQ+vL7wFYx5tu/C alDMuNunr79HXNkn2BxTL9V36LpRi6MODtoJ6HOkG52ys4xTlDVtgVqfb Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10239"; a="234302451" X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="234302451" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 09:55:12 -0800 X-IronPort-AV: E=Sophos;i="5.88,321,1635231600"; d="scan'208";a="674796169" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2022 09:55:12 -0800 From: ira.weiny@intel.com To: Dave Hansen , "H. Peter Anvin" , Dan Williams Cc: Ira Weiny , Fenghua Yu , Rick Edgecombe , linux-kernel@vger.kernel.org Subject: [PATCH V8 33/44] memremap_pages: Introduce pgmap_protection_available() Date: Thu, 27 Jan 2022 09:54:54 -0800 Message-Id: <20220127175505.851391-34-ira.weiny@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220127175505.851391-1-ira.weiny@intel.com> References: <20220127175505.851391-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 Users will need to specify that they want their dev_pagemap pages protected by specifying a flag in (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() for users to check if protection is available to be used. The name of pgmap_protection_available() was specifically chosen to isolate the implementation of the protection from higher level users. However, the current implementation simply calls pks_available() to determine if it can support protection. It was considered to have users specify the flag and check if the dev_pagemap object returned was protected or not. But this was considered less efficient than a direct check beforehand. Signed-off-by: Ira Weiny --- Changes for V8 Split this out to it's own patch. s/pgmap_protection_enabled/pgmap_protection_available --- include/linux/mm.h | 13 +++++++++++++ mm/memremap.c | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index e1a84b1e6787..2ae99bee6e82 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1143,6 +1143,19 @@ static inline bool is_pci_p2pdma_page(const struct page *page) page->pgmap->type == MEMORY_DEVICE_PCI_P2PDMA; } +#ifdef CONFIG_DEVMAP_ACCESS_PROTECTION + +bool pgmap_protection_available(void); + +#else + +static inline bool pgmap_protection_available(void) +{ + return false; +} + +#endif /* CONFIG_DEVMAP_ACCESS_PROTECTION */ + /* 127: arbitrary random number, small enough to assemble well */ #define folio_ref_zero_or_close_to_overflow(folio) \ ((unsigned int) folio_ref_count(folio) + 127u <= 127u) diff --git a/mm/memremap.c b/mm/memremap.c index 6aa5f0c2d11f..c13b3b8a0048 100644 --- a/mm/memremap.c +++ b/mm/memremap.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -63,6 +64,16 @@ static void devmap_managed_enable_put(struct dev_pagemap *pgmap) } #endif /* CONFIG_DEV_PAGEMAP_OPS */ +#ifdef CONFIG_DEVMAP_ACCESS_PROTECTION + +bool pgmap_protection_available(void) +{ + return pks_available(); +} +EXPORT_SYMBOL_GPL(pgmap_protection_available); + +#endif /* CONFIG_DEVMAP_ACCESS_PROTECTION */ + static void pgmap_array_delete(struct range *range) { xa_store_range(&pgmap_array, PHYS_PFN(range->start), PHYS_PFN(range->end), -- 2.31.1