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 X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CE4CC64E75 for ; Sat, 14 Nov 2020 01:46:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ED7C32225D for ; Sat, 14 Nov 2020 01:45:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ED7C32225D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3937B6E8CC; Sat, 14 Nov 2020 01:45:49 +0000 (UTC) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by gabe.freedesktop.org (Postfix) with ESMTPS id 780FD6E8A4 for ; Sat, 14 Nov 2020 01:45:41 +0000 (UTC) IronPort-SDR: /APnnckbo867lzitnWr2RV/kACjGuvqToECxwWAH7BSRLqeBTsKoe2yipp+OmASkxzwsdyvWuv 4w8n6fT7I0Sg== X-IronPort-AV: E=McAfee;i="6000,8403,9804"; a="158332220" X-IronPort-AV: E=Sophos;i="5.77,477,1596524400"; d="scan'208";a="158332220" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Nov 2020 17:45:39 -0800 IronPort-SDR: hmaYLzEbi/FrOt3LAW6C1S7LEF6CwktpCOI/dxEx4i/ZdJA4mwK7EyMxaoS/X4IjJw7LcEdgbd 6YeCdAD4vjdQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,477,1596524400"; d="scan'208";a="361524770" Received: from sean-virtualbox.fm.intel.com ([10.105.158.96]) by fmsmga002.fm.intel.com with ESMTP; 13 Nov 2020 17:45:38 -0800 From: Sean Z Huang To: Intel-gfx@lists.freedesktop.org Date: Fri, 13 Nov 2020 17:45:18 -0800 Message-Id: <20201114014537.25495-8-sean.z.huang@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201114014537.25495-1-sean.z.huang@intel.com> References: <20201114014537.25495-1-sean.z.huang@intel.com> Subject: [Intel-gfx] [PATCH 08/27] drm/i915/pxp: Read register to check hardware session state X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Huang, Sean Z" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: "Huang, Sean Z" Implement the functions to check the hardware protected session state via reading the hardware register session in play. Signed-off-by: Huang, Sean Z --- drivers/gpu/drm/i915/pxp/intel_pxp.h | 3 + drivers/gpu/drm/i915/pxp/intel_pxp_sm.c | 189 ++++++++++++++++++++++++ drivers/gpu/drm/i915/pxp/intel_pxp_sm.h | 51 +++++++ 3 files changed, 243 insertions(+) diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp.h b/drivers/gpu/drm/i915/pxp/intel_pxp.h index 21a6964fc64e..95d3deba7ade 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp.h +++ b/drivers/gpu/drm/i915/pxp/intel_pxp.h @@ -12,6 +12,9 @@ #define PXP_IRQ_VECTOR_DISPLAY_APP_TERM_PER_FW_REQ BIT(2) #define PXP_IRQ_VECTOR_PXP_DISP_STATE_RESET_COMPLETE BIT(3) +#define pxp_session_list(i915, session_type) (((session_type) == SESSION_TYPE_TYPE0) ? \ + &(i915)->pxp.r0ctx->active_pxp_type0_sessions : &(i915)->pxp.r0ctx->active_pxp_type1_sessions) + #define MAX_TYPE0_SESSIONS 16 #define MAX_TYPE1_SESSIONS 6 diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c index 75e4b229d9f8..3dd5a9e3926b 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c +++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.c @@ -10,6 +10,25 @@ #include "intel_pxp_sm.h" #include "intel_pxp_context.h" +int pxp_sm_reg_read(struct drm_i915_private *i915, u32 offset, u32 *regval) +{ + intel_wakeref_t wakeref; + int err = 0; + + if (!i915 || !regval) { + err = -EINVAL; + drm_dbg(&i915->drm, "Failed to %s bad params\n", __func__); + goto end; + } + + with_intel_runtime_pm(&i915->runtime_pm, wakeref) { + i915_reg_t reg_offset = {offset}; + *regval = intel_uncore_read(&i915->uncore, reg_offset); + } +end: + return err; +} + static int pxp_reg_write(struct drm_i915_private *i915, u32 offset, u32 regval) { intel_wakeref_t wakeref; @@ -30,6 +49,176 @@ static int pxp_reg_write(struct drm_i915_private *i915, u32 offset, u32 regval) return err; } +/** + * is_sw_session_active - Check if the given sw session id is active. + * @i915: i915 device handle. + * @session_type: Specified session type + * @session_index: Numeric session identifier. + * @is_in_play: Set false to return true if the specified session is active. + * Set true to also check if the session is active and in_play. + * @protection_mode: get the protection mode of specified session. + * + * The caller needs to use ctx_mutex lock to protect the session_list + * inside this function. + * + * Return : true if session with the same identifier is active (and in_play). + */ +static bool is_sw_session_active(struct drm_i915_private *i915, int session_type, + int session_index, bool is_in_play, int *protection_mode) +{ + struct pxp_protected_session *current_session; + + lockdep_assert_held(&i915->pxp.r0ctx->ctx_mutex); + + list_for_each_entry(current_session, pxp_session_list(i915, session_type), session_list) { + if (current_session->session_index == session_index) { + if (protection_mode) + *protection_mode = current_session->protection_mode; + + if (is_in_play && !current_session->session_is_in_play) + return false; + + return true; + } + } + + /* session id not found. return false */ + return false; +} + +static bool is_hw_type0_session_in_play(struct drm_i915_private *i915, int session_index) +{ + u32 regval_sip = 0; + u32 reg_session_id_mask; + bool hw_session_is_in_play = false; + int ret = 0; + + if (!i915 || session_index < 0 || session_index >= MAX_TYPE0_SESSIONS) { + drm_dbg(&i915->drm, "Failed to %s due to invalid params", __func__); + goto end; + } + + ret = pxp_sm_reg_read(i915, GEN12_KCR_SIP.reg, ®val_sip); + if (ret) { + drm_dbg(&i915->drm, "Failed to read()\n"); + goto end; + } + + reg_session_id_mask = (1 << session_index); + hw_session_is_in_play = (bool)(regval_sip & reg_session_id_mask); +end: + return hw_session_is_in_play; +} + +static bool is_hw_type1_session_in_play(struct drm_i915_private *i915, int session_index) +{ + int ret = 0; + u32 regval_tsip_low = 0; + u32 regval_tsip_high = 0; + u64 reg_session_id_mask; + u64 regval_tsip; + bool hw_session_is_in_play = false; + + if (!i915 || session_index < 0 || session_index >= MAX_TYPE1_SESSIONS) { + drm_dbg(&i915->drm, "Failed to %s due to invalid params", __func__); + goto end; + } + + ret = pxp_sm_reg_read(i915, GEN12_KCR_TSIP_LOW.reg, ®val_tsip_low); + if (ret) { + drm_dbg(&i915->drm, "Failed to pxp_sm_reg_read()\n"); + goto end; + } + + ret = pxp_sm_reg_read(i915, GEN12_KCR_TSIP_HIGH.reg, ®val_tsip_high); + if (ret) { + drm_dbg(&i915->drm, "Failed to pxp_sm_reg_read()\n"); + goto end; + } + + reg_session_id_mask = (1 << session_index); + regval_tsip = ((u64)regval_tsip_high << 32) | regval_tsip_low; + hw_session_is_in_play = (bool)(regval_tsip & reg_session_id_mask); +end: + return hw_session_is_in_play; +} + +static bool is_hw_session_in_play(struct drm_i915_private *i915, + int session_type, int session_index) +{ + bool is_in_play = false; + + if (session_type == SESSION_TYPE_TYPE0) + is_in_play = is_hw_type0_session_in_play(i915, session_index); + else if (session_type == SESSION_TYPE_TYPE1) + is_in_play = is_hw_type1_session_in_play(i915, session_index); + else + drm_dbg(&i915->drm, "Failed to %s invalid session_type=[%d]\n", __func__, session_type); + + return is_in_play; +} + +/* check hw session in play reg if match the current sw state */ +static int sync_hw_sw_state(struct drm_i915_private *i915, int session_index, int session_type) +{ + const int max_retry = 10; + const int ms_delay = 10; + int retry = 0; + int ret; + + if (!i915 || session_type >= SESSION_TYPE_MAX) { + ret = -EINVAL; + drm_dbg(&i915->drm, "Failed to %s, bad params\n", __func__); + goto end; + } + + ret = -EINVAL; + for (retry = 0; retry < max_retry; retry++) { + if (is_hw_session_in_play(i915, session_type, session_index) == + is_sw_session_active(i915, session_type, session_index, true, NULL)) { + ret = 0; + break; + } + + msleep(ms_delay); + } +end: + return ret; +} + +/** + * check_if_protected_type0_sessions_are_attacked - To check if type0 active sessions are attacked. + * @i915: i915 device handle. + * + * Return: true if HW shows protected sessions are attacked, false otherwise. + */ +static bool check_if_protected_type0_sessions_are_attacked(struct drm_i915_private *i915) +{ + i915_reg_t kcr_status_reg = KCR_STATUS_1; + u32 reg_value = 0; + u32 mask = 0x80000000; + int ret; + + if (!i915) { + drm_dbg(&i915->drm, "Failed to %s, bad params\n", __func__); + goto end; + } + + if (i915->pxp.r0ctx->global_state_attacked) + return true; + + ret = pxp_sm_reg_read(i915, kcr_status_reg.reg, ®_value); + if (ret) { + drm_dbg(&i915->drm, "Failed to pxp_sm_reg_read\n"); + goto end; + } + + if (reg_value & mask) + return true; +end: + return false; +} + int pxp_sm_set_kcr_init_reg(struct drm_i915_private *i915) { int ret; diff --git a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h index 59ce2394b590..a3149c18c831 100644 --- a/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h +++ b/drivers/gpu/drm/i915/pxp/intel_pxp_sm.h @@ -14,6 +14,57 @@ /* Setting KCR Init bit is required after system boot */ #define KCR_INIT_ALLOW_DISPLAY_ME_WRITES (BIT(14) | (BIT(14) << KCR_INIT_MASK_SHIFT)) +#define KCR_STATUS_1 _MMIO(0x320f4) +#define GEN12_KCR_SIP _MMIO(0x32260) /* KCR type0 session in play 0-31 */ +#define GEN12_KCR_TSIP_LOW _MMIO(0x32264) /* KCR type1 session in play 0-31 */ +#define GEN12_KCR_TSIP_HIGH _MMIO(0x32268) /* KCR type1 session in play 32-63 */ + +enum pxp_session_types { + SESSION_TYPE_TYPE0 = 0, + SESSION_TYPE_TYPE1 = 1, + + SESSION_TYPE_MAX +}; + +enum pxp_protection_modes { + PROTECTION_MODE_NONE = 0, + PROTECTION_MODE_LM = 2, + PROTECTION_MODE_HM = 3, + PROTECTION_MODE_SM = 6, + + PROTECTION_MODE_ALL +}; + +/** + * struct pxp_protected_session - linked list to track all active sessions. + */ +struct pxp_protected_session { + /** @session_list: linked list infrastructure, do not change its order. */ + struct list_head session_list; + + /** @session_index: Numeric identifier for this protected session */ + int session_index; + /** @session_type: Type of session */ + int session_type; + /** @protection_mode: mode of protection requested */ + int protection_mode; + /** @context_id: context identifier of the protected session requestor */ + int context_id; + /** @pid: pid of this session's creator */ + int pid; + /** @drmfile: pointer to drm_file, which is allocated on device file open() call */ + struct drm_file *drmfile; + + /** + * @session_is_in_play: indicates whether the session has been established + * in the HW root of trust if this flag is false, it + * indicates an application has reserved this session, + * but has not * established the session in the + * hardware yet. + */ + bool session_is_in_play; +}; + int pxp_sm_set_kcr_init_reg(struct drm_i915_private *i915); #endif /* __INTEL_PXP_SM_H__ */ -- 2.17.1 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx