Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp934829pxb; Fri, 22 Apr 2022 14:45:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoO1OSBzaC9Om6PW4GAgDpA8ohHcACt9f4kF9KM6n1Dr4KNauDMpLqOSLnA8ZuoUr8nn8e X-Received: by 2002:a17:902:8684:b0:154:af35:82ce with SMTP id g4-20020a170902868400b00154af3582cemr6411851plo.137.1650663905503; Fri, 22 Apr 2022 14:45:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650663905; cv=none; d=google.com; s=arc-20160816; b=Dh5siLCrbfeLo9LGOOAiLD7OGfRGM+UiZEXC4C4IZlHTf/tucN2VN6PjWUAgOnerDU pneGRT4CFLxwgMVUQSHDzJuQB6oog/PkXIrPQlq4frc9+e0JZYqFtQUgJhFqXjzIFnwO loJhTEY62SlzZ/cY++6++rFXnmhE5JJPNpuPDr1+BMHPGctjGoCGnwP6xabMFy2lzd8U //Q7+aaQEwWeeTGrwt+nXJ9MkuMHVa226VpHMrq8BlPK/V04OdMc4zLKWMqDU8ZktR1/ OE2gXZqX1fh15WZRN/mtZgJ7fJWwBhgy5xRa1as0GjYNNwMfdoS2jDs+NGcGzo5fMUqM 3YCQ== 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=nOE6Z5kkqgk35r9gWLUQBdeCgT0F+plSt5Ju66amkJA=; b=XAGQyxGAxovH10Q04aUKu6h5y58Ezp54QjKvqq+C/XXr9S9uoWxjdmJFDss1EQ8uJq fzOAFM56qGEhr9Lb7yiInieYUoa5D/9A75x25Dc5KbC4x+mR/KiAiPgRZ6dZV0aupt3n bVQLTg5TUhdrtnsC6jAtlgAFj9+grmw1yErtEvmvJvOfuvA4DiOTzy5wWkuL7GLOQ0zw 5uRwJwgvIAYLepqQAtxVIGKjw13Eg+jOHYBQ1gRPH+yJ53FlW8twwLp4jl37SCqEHkcx HdXZgFRSHt0YI3yqgDGVyGyOVQAnoJ1DCtoDJSdgaWEMrp7m9qfvqTeNYuYB8BNRiFcZ HDcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RizUCaLo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id ot9-20020a17090b3b4900b001bd14e0302csi10046971pjb.4.2022.04.22.14.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 14:45:05 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RizUCaLo; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F1ED32A9CC; Fri, 22 Apr 2022 12:53:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356126AbiDSRM6 (ORCPT + 99 others); Tue, 19 Apr 2022 13:12:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355644AbiDSRJ4 (ORCPT ); Tue, 19 Apr 2022 13:09:56 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECAAF10FE0 for ; Tue, 19 Apr 2022 10:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650388030; x=1681924030; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3BionnZDsSMnuwX2BAiBk9rbYY0AKD+hMHLH+ghigtE=; b=RizUCaLobAXEIIzFcRfC/9OpC5TnNc2hI89tZacGy49twPIFfV/TKwHb T56ABHZNiHjw+hilhDmRTGGtZNj5ghMowEY0rFGiTcSuhAFwPSmUxifpr w/rw1gAM+0lLLRsRifk2o0dC0KtDQEbvk24YVDTUJFl2gIiR6AUeB5FAr 10Jtb9dUeWG64PgRvZZ7gtq2SEks4AKSbtsrqwaD+2ZQnfmUmOBd9P/Kh 792HPcmUNRaqVJVlJ6LszN0XkM1U39+Qvi3tVAaiMkkK9cu2Y2vTV1RfJ t1wF5FI3Y4eQf2jyk3GyL3FdJPOXnAHFckdBeSSTgOPL6lDqlcG2VZQDX g==; X-IronPort-AV: E=McAfee;i="6400,9594,10322"; a="263991861" X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="263991861" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:10 -0700 X-IronPort-AV: E=Sophos;i="5.90,273,1643702400"; d="scan'208";a="804734133" Received: from ajacosta-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.11.4]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Apr 2022 10:07:10 -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 24/44] mm/pkeys: Add pks_available() Date: Tue, 19 Apr 2022 10:06:29 -0700 Message-Id: <20220419170649.1022246-25-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 X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable 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 From: Ira Weiny If PKS is configured within the kernel but the CPU does not support PKS, the PKS calls remain safe to execute even without protection. However, adding the overhead of these calls on CPUs which don't support PKS is inefficient and best avoided. Define pks_available() to allow users to check if PKS is enabled on the current system. The implementation of pks_available() is placed in the asm headers while being directly exported via linux/pks.h to allow for the inline calling of cpu_feature_enabled() by consumers outside of the architecture. Signed-off-by: Ira Weiny --- Changes for V9 Driven by a request by Dan Williams to make this static inline Place this in pks.h to avoid header conflicts while allowing for an optimized call to cpu_feature_enabled() Changes for V8 s/pks_enabled/pks_available --- Documentation/core-api/protection-keys.rst | 3 +++ arch/x86/include/asm/pks.h | 12 ++++++++++++ include/linux/pks.h | 8 ++++++++ 3 files changed, 23 insertions(+) diff --git a/Documentation/core-api/protection-keys.rst b/Documentation/core-api/protection-keys.rst index c5f0f5d39929..47bcb38fff4f 100644 --- a/Documentation/core-api/protection-keys.rst +++ b/Documentation/core-api/protection-keys.rst @@ -152,6 +152,9 @@ Changing permissions of individual keys .. kernel-doc:: arch/x86/mm/pkeys.c :identifiers: pks_update_exception +.. kernel-doc:: arch/x86/include/asm/pks.h + :identifiers: pks_available + Overriding Default Fault Behavior --------------------------------- diff --git a/arch/x86/include/asm/pks.h b/arch/x86/include/asm/pks.h index de67d5b5a2af..cab42aadea07 100644 --- a/arch/x86/include/asm/pks.h +++ b/arch/x86/include/asm/pks.h @@ -2,8 +2,20 @@ #ifndef _ASM_X86_PKS_H #define _ASM_X86_PKS_H +#include + #ifdef CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS +/** + * pks_available() - Is PKS available on this system + * + * Return if PKS is currently supported and enabled on this system. + */ +static inline bool pks_available(void) +{ + return cpu_feature_enabled(X86_FEATURE_PKS); +} + void pks_setup(void); void x86_pkrs_load(struct thread_struct *thread); void pks_save_pt_regs(struct pt_regs *regs); diff --git a/include/linux/pks.h b/include/linux/pks.h index 2ea5fb57f2dc..151a3fda9de4 100644 --- a/include/linux/pks.h +++ b/include/linux/pks.h @@ -8,6 +8,9 @@ #include +#include + +bool pks_available(void); void pks_update_protection(u8 pkey, u8 protection); void pks_update_exception(struct pt_regs *regs, u8 pkey, u8 protection); @@ -40,6 +43,11 @@ typedef bool (*pks_key_callback)(struct pt_regs *regs, unsigned long address, #else /* !CONFIG_ARCH_ENABLE_SUPERVISOR_PKEYS */ +static inline bool pks_available(void) +{ + return false; +} + static inline void pks_set_noaccess(u8 pkey) {} static inline void pks_set_readwrite(u8 pkey) {} static inline void pks_update_exception(struct pt_regs *regs, -- 2.35.1