From patchwork Mon Feb 1 15:21:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059181 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 61140C433E0 for ; Mon, 1 Feb 2021 15:07:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36F2F64DA5 for ; Mon, 1 Feb 2021 15:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229981AbhBAPGw (ORCPT ); Mon, 1 Feb 2021 10:06:52 -0500 Received: from mga06.intel.com ([134.134.136.31]:33902 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231144AbhBAPGK (ORCPT ); Mon, 1 Feb 2021 10:06:10 -0500 IronPort-SDR: kRHU/rf+XAHfqn6X5Im+DoJhRmUG4zRFSdI+WbqAQvPYJ9Okj7aWaZhB43arBxASI/XD/20+m5 PFNGVCyvP8tw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214665" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214665" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:30 -0800 IronPort-SDR: 3WsIeX/Q2pmr/wZF9wkrifAuukjJmjr7IwEPyYfIUXzBlHrFIn9JkzdOUiAQFaNJZRKuTA7JYv c9vcSZIE7h6g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891561" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:30 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 1/6] firmware: stratix10-svc: add COMMAND_AUTHENTICATE_BITSTREAM flag Date: Mon, 1 Feb 2021 09:21:54 -0600 Message-Id: <1612192919-4069-2-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Add COMMAND_AUTHENTICATE_BITSTREAM command flag for new added bitstream authentication feature. Authenticating a bitstream is to make sure a signed bitstream has the valid signatures. Except for the actual configuration of the device, the bitstream authentication works the same way as FPGA configuration does. If the authentication passes, the signed bitstream will be programmed into QSPI flash memory and will be expected to boot without issues. Signed-off-by: Richard Gong --- v4: remove change at COMMAND_RECONFIG_FLAG_PARTIAL flag & add that to a separate commit 27ad5309c247b6bde8a098e17e9bd9b1576b7f71. v3: no change v2: new added --- include/linux/firmware/intel/stratix10-svc-client.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/linux/firmware/intel/stratix10-svc-client.h index f843c6a..fa9581d 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -55,8 +55,13 @@ * * COMMAND_RECONFIG_FLAG_PARTIAL: * Set to FPGA configuration type (full or partial). + * + * COMMAND_AUTHENTICATE_BITSTREAM: + * Set for bitstream authentication, which makes sure a signed bitstream + * has valid signatures before committing it to device. */ #define COMMAND_RECONFIG_FLAG_PARTIAL 0 +#define COMMAND_AUTHENTICATE_BITSTREAM 1 /** * Timeout settings for service clients: From patchwork Mon Feb 1 15:21:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059175 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 19E34C433DB for ; Mon, 1 Feb 2021 15:06:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BF0FC64E08 for ; Mon, 1 Feb 2021 15:06:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbhBAPEa (ORCPT ); Mon, 1 Feb 2021 10:04:30 -0500 Received: from mga06.intel.com ([134.134.136.31]:33902 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229564AbhBAPDv (ORCPT ); Mon, 1 Feb 2021 10:03:51 -0500 IronPort-SDR: 9BU6t/cpytIJFfXfhSNdsD3s7jKDC97dP8K3DKZRTJYsOXcsJFNVbgX+wjI9iYqfWsRCpHf5M6 K0FBagt5q+HQ== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214670" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214670" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:31 -0800 IronPort-SDR: 520AdKfstm6cO2961kyYfdX02Kh46W6qy+Tl6Dm+yAtosVDO5wbp+/Ljd0pJKE0Tcnz6XQv8/2 tu3r96TWWw5g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891566" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:30 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 2/6] firmware: stratix10-svc: extend SVC driver to get the firmware version Date: Mon, 1 Feb 2021 09:21:55 -0600 Message-Id: <1612192919-4069-3-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Extend Intel service layer driver to get the firmware version running at FPGA device. Therefore FPGA manager driver, one of Intel service layer driver's client, can decide whether to handle the newly added bitstream authentication function based on the retrieved firmware version. Signed-off-by: Richard Gong --- v4: no change v3: new added, changes for getting firmware version --- drivers/firmware/stratix10-svc.c | 12 ++++++++++-- include/linux/firmware/intel/stratix10-smc.h | 21 +++++++++++++++++++-- include/linux/firmware/intel/stratix10-svc-client.h | 4 ++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/firmware/stratix10-svc.c b/drivers/firmware/stratix10-svc.c index 3aa489d..1443bbd 100644 --- a/drivers/firmware/stratix10-svc.c +++ b/drivers/firmware/stratix10-svc.c @@ -306,6 +306,7 @@ static void svc_thread_recv_status_ok(struct stratix10_svc_data *p_data, break; case COMMAND_RSU_RETRY: case COMMAND_RSU_MAX_RETRY: + case COMMAND_FIRMWARE_VERSION: cb_data->status = BIT(SVC_STATUS_OK); cb_data->kaddr1 = &res.a1; break; @@ -422,6 +423,11 @@ static int svc_normal_to_secure_thread(void *data) a1 = 0; a2 = 0; break; + case COMMAND_FIRMWARE_VERSION: + a0 = INTEL_SIP_SMC_FIRMWARE_VERSION; + a1 = 0; + a2 = 0; + break; default: pr_warn("it shouldn't happen\n"); break; @@ -487,11 +493,13 @@ static int svc_normal_to_secure_thread(void *data) /* * be compatible with older version firmware which - * doesn't support RSU notify or retry + * doesn't support RSU notify, retry or bitstream + * authentication. */ if ((pdata->command == COMMAND_RSU_RETRY) || (pdata->command == COMMAND_RSU_MAX_RETRY) || - (pdata->command == COMMAND_RSU_NOTIFY)) { + (pdata->command == COMMAND_RSU_NOTIFY) || + (pdata->command == COMMAND_FIRMWARE_VERSION)) { cbdata->status = BIT(SVC_STATUS_NO_SUPPORT); cbdata->kaddr1 = NULL; diff --git a/include/linux/firmware/intel/stratix10-smc.h b/include/linux/firmware/intel/stratix10-smc.h index c3e5ab0..505fcca 100644 --- a/include/linux/firmware/intel/stratix10-smc.h +++ b/include/linux/firmware/intel/stratix10-smc.h @@ -321,8 +321,6 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_ECC_DBE \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_ECC_DBE) -#endif - /** * Request INTEL_SIP_SMC_RSU_NOTIFY * @@ -404,3 +402,22 @@ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FPGA_CONFIG_COMPLETED_WRITE) #define INTEL_SIP_SMC_FUNCID_RSU_MAX_RETRY 18 #define INTEL_SIP_SMC_RSU_MAX_RETRY \ INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_RSU_MAX_RETRY) + +/** + * Request INTEL_SIP_SMC_FIRMWARE_VERSION + * + * Sync call used to query the version of running firmware + * + * Call register usage: + * a0 INTEL_SIP_SMC_FIRMWARE_VERSION + * a1-a7 not used + * + * Return status: + * a0 INTEL_SIP_SMC_STATUS_OK or INTEL_SIP_SMC_STATUS_ERROR + * a1 running firmware version + */ +#define INTEL_SIP_SMC_FUNCID_FIRMWARE_VERSION 31 +#define INTEL_SIP_SMC_FIRMWARE_VERSION \ + INTEL_SIP_SMC_FAST_CALL_VAL(INTEL_SIP_SMC_FUNCID_FIRMWARE_VERSION) + +#endif diff --git a/include/linux/firmware/intel/stratix10-svc-client.h b/include/linux/firmware/intel/stratix10-svc-client.h index fa9581d..193a2cf 100644 --- a/include/linux/firmware/intel/stratix10-svc-client.h +++ b/include/linux/firmware/intel/stratix10-svc-client.h @@ -109,6 +109,9 @@ struct stratix10_svc_chan; * * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status * is SVC_STATUS_OK or SVC_STATUS_ERROR + * + * @COMMAND_FIRMWARE_VERSION: query running firmware version, return status + * is SVC_STATUS_OK or SVC_STATUS_ERROR */ enum stratix10_svc_command_code { COMMAND_NOOP = 0, @@ -122,6 +125,7 @@ enum stratix10_svc_command_code { COMMAND_RSU_RETRY, COMMAND_RSU_MAX_RETRY, COMMAND_RSU_DCMF_VERSION, + COMMAND_FIRMWARE_VERSION, }; /** From patchwork Mon Feb 1 15:21:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059189 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 98E3FC433DB for ; Mon, 1 Feb 2021 15:11:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 680FF64DAD for ; Mon, 1 Feb 2021 15:11:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231269AbhBAPLA (ORCPT ); Mon, 1 Feb 2021 10:11:00 -0500 Received: from mga06.intel.com ([134.134.136.31]:33931 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229786AbhBAPEA (ORCPT ); Mon, 1 Feb 2021 10:04:00 -0500 IronPort-SDR: E0FLsjojSzS9M617j7D5VNPdrkyCnrB4gIO9ax4yLMq9vahepIhouUfU6bwKC1yj2Wd0s3MS8w pqbyZDulhRPA== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214675" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214675" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:31 -0800 IronPort-SDR: 2ARkCyIwXa+X+eu0ld0ayvFlJlLt0OEvdfW1qzsXICfxmEdOvOLHRoS6SnwNqwLD/1sGy7L9ui w/nn0OxQTjEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891571" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:31 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 3/6] fpga: fpga-mgr: add FPGA_MGR_BITSTREAM_AUTHENTICATE flag Date: Mon, 1 Feb 2021 09:21:56 -0600 Message-Id: <1612192919-4069-4-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Add FPGA_MGR_BITSTREAM_AUTHENTICATE flag for FPGA bitstream authentication, which makes sure a signed bitstream has valid signatures. Except for the actual configuration of the device, the authentication works the same way as FPGA configuration does. If the authentication passes, the bitstream will be programmed into QSPI flash and will be expected to boot without issues. Signed-off-by: Richard Gong --- v4: s/FPGA_MGR_BITSTREM_AUTHENTICATION/FPGA_MGR_BITSTREAM_AUTHENTICATE v3: no change v2: align all FPGA_MGR_* flags update the commit messages --- include/linux/fpga/fpga-mgr.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/fpga/fpga-mgr.h b/include/linux/fpga/fpga-mgr.h index 2bc3030..a81b3a7 100644 --- a/include/linux/fpga/fpga-mgr.h +++ b/include/linux/fpga/fpga-mgr.h @@ -67,12 +67,15 @@ enum fpga_mgr_states { * %FPGA_MGR_BITSTREAM_LSB_FIRST: SPI bitstream bit order is LSB first * * %FPGA_MGR_COMPRESSED_BITSTREAM: FPGA bitstream is compressed + * + * %FPGA_MGR_BITSTREAM_AUTHENTICATE: do FPGA bitstream authentication only */ #define FPGA_MGR_PARTIAL_RECONFIG BIT(0) #define FPGA_MGR_EXTERNAL_CONFIG BIT(1) #define FPGA_MGR_ENCRYPTED_BITSTREAM BIT(2) #define FPGA_MGR_BITSTREAM_LSB_FIRST BIT(3) #define FPGA_MGR_COMPRESSED_BITSTREAM BIT(4) +#define FPGA_MGR_BITSTREAM_AUTHENTICATE BIT(5) /** * struct fpga_image_info - information specific to a FPGA image From patchwork Mon Feb 1 15:21:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059183 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 63CBBC4332D for ; Mon, 1 Feb 2021 15:08:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2188764E06 for ; Mon, 1 Feb 2021 15:08:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230469AbhBAPG4 (ORCPT ); Mon, 1 Feb 2021 10:06:56 -0500 Received: from mga06.intel.com ([134.134.136.31]:33905 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231145AbhBAPGK (ORCPT ); Mon, 1 Feb 2021 10:06:10 -0500 IronPort-SDR: hT1p50H6dFYeoxBfyQvqS1990ehXj8+iLezFHiSPAkUl0m5qinOCLtEdNVfCg7dfwQGdBMxc94 R5cu2/qNJVBg== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214682" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214682" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:32 -0800 IronPort-SDR: 3vXLgtQeRyuKoXukZd7xaTR2EL4ACw0mYIM4eZ0PtTG76DyRQA9xM1znI4Ki0QyoWFaDKX6PdZ PRYpqVZ9FkTw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891577" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:31 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 4/6] fpga: of-fpga-region: add authenticate-fpga-config property Date: Mon, 1 Feb 2021 09:21:57 -0600 Message-Id: <1612192919-4069-5-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Add authenticate-fpga-config property to support FPGA bitstream authentication, which makes sure a signed bitstream has valid signatures. Signed-off-by: Richard Gong --- v4: add additional checks to make sure *only* authenticate v3: no change v2: changed in alphabetical order --- drivers/fpga/of-fpga-region.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/fpga/of-fpga-region.c b/drivers/fpga/of-fpga-region.c index e405309..5074479 100644 --- a/drivers/fpga/of-fpga-region.c +++ b/drivers/fpga/of-fpga-region.c @@ -218,15 +218,25 @@ static struct fpga_image_info *of_fpga_region_parse_ov( info->overlay = overlay; - /* Read FPGA region properties from the overlay */ - if (of_property_read_bool(overlay, "partial-fpga-config")) - info->flags |= FPGA_MGR_PARTIAL_RECONFIG; + /* + * Read FPGA region properties from the overlay. + * + * First check the integrity of the bitstream. If the + * authentication is passed, the user can perform other + * operations. + */ + if (of_property_read_bool(overlay, "authenticate-fpga-config")) { + info->flags |= FPGA_MGR_BITSTREAM_AUTHENTICATE; + } else { + if (of_property_read_bool(overlay, "partial-fpga-config")) + info->flags |= FPGA_MGR_PARTIAL_RECONFIG; - if (of_property_read_bool(overlay, "external-fpga-config")) - info->flags |= FPGA_MGR_EXTERNAL_CONFIG; + if (of_property_read_bool(overlay, "external-fpga-config")) + info->flags |= FPGA_MGR_EXTERNAL_CONFIG; - if (of_property_read_bool(overlay, "encrypted-fpga-config")) - info->flags |= FPGA_MGR_ENCRYPTED_BITSTREAM; + if (of_property_read_bool(overlay, "encrypted-fpga-config")) + info->flags |= FPGA_MGR_ENCRYPTED_BITSTREAM; + } if (!of_property_read_string(overlay, "firmware-name", &firmware_name)) { From patchwork Mon Feb 1 15:21:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059187 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 B9E01C433E0 for ; Mon, 1 Feb 2021 15:09:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8DFBA64DAD for ; Mon, 1 Feb 2021 15:09:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231226AbhBAPGo (ORCPT ); Mon, 1 Feb 2021 10:06:44 -0500 Received: from mga06.intel.com ([134.134.136.31]:33931 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231148AbhBAPGK (ORCPT ); Mon, 1 Feb 2021 10:06:10 -0500 IronPort-SDR: ADi6PMLT1KjDh7N4qkspEeQShaMMLBAAHebCCljW2HldSNOk7geNgJ3Ku2Tb1RB1VbCOcN+iXh jSP5RlUSUuBA== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214687" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214687" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:32 -0800 IronPort-SDR: LY2JnlmMixwS3/SkzphMnCYhTbiRUHt8M0luCyNzR5k8v2fPsvrAEUjfWzwnQWib5ryNurluD1 Hu8xg4lm/v/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891580" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:32 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 5/6] dt-bindings: fpga: add authenticate-fpga-config property Date: Mon, 1 Feb 2021 09:21:58 -0600 Message-Id: <1612192919-4069-6-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Add authenticate-fpga-config property for FPGA bitstream authentication, which makes sure a signed bitstream has valid signatures. Signed-off-by: Richard Gong --- v4: explain authenticate-fpga-config flag further v3: no change v2: put authenticate-fpga-config above partial-fpga-config update commit messages --- Documentation/devicetree/bindings/fpga/fpga-region.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/fpga/fpga-region.txt b/Documentation/devicetree/bindings/fpga/fpga-region.txt index e811cf8..e2740b6 100644 --- a/Documentation/devicetree/bindings/fpga/fpga-region.txt +++ b/Documentation/devicetree/bindings/fpga/fpga-region.txt @@ -182,6 +182,10 @@ Optional properties: This property is optional if the FPGA Manager handles the bridges. If the fpga-region is the child of a fpga-bridge, the list should not contain the parent bridge. +- authenticate-fpga-config : boolean, set if do bitstream authentication only. + flag authenticate-fpga-config is used to first check the integrity of + the bitstream. If the authentication is passed, the user can perform + other operations. - partial-fpga-config : boolean, set if partial reconfiguration is to be done, otherwise full reconfiguration is done. - external-fpga-config : boolean, set if the FPGA has already been configured From patchwork Mon Feb 1 15:21:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Gong X-Patchwork-Id: 12059185 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=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,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 9A331C433DB for ; Mon, 1 Feb 2021 15:08:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AAC064DAD for ; Mon, 1 Feb 2021 15:08:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231419AbhBAPIk (ORCPT ); Mon, 1 Feb 2021 10:08:40 -0500 Received: from mga06.intel.com ([134.134.136.31]:33905 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231423AbhBAPI0 (ORCPT ); Mon, 1 Feb 2021 10:08:26 -0500 IronPort-SDR: phvDUMW2mBS2AUWremSqHGyT9chhi8hObLT8FljAjrOnkwPMZp8AO1KQRsDgyov87p25BDSYws VZZVNLQGCvXw== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="242214691" X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="242214691" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 07:02:33 -0800 IronPort-SDR: BGsvKW673ilgXMvy1mKx8OOo8EIcUDcfBRzsnP/z64p7GS1ndIFY4xaxABY4YA28oP4dYVFToD H0p4DaAfmSkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,392,1602572400"; d="scan'208";a="369891585" Received: from marshy.an.intel.com ([10.122.105.143]) by fmsmga008.fm.intel.com with ESMTP; 01 Feb 2021 07:02:32 -0800 From: richard.gong@linux.intel.com To: mdf@kernel.org, trix@redhat.com, gregkh@linuxfoundation.org, linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Richard Gong Subject: [PATCHv4 6/6] fpga: stratix10-soc: extend driver for bitstream authentication Date: Mon, 1 Feb 2021 09:21:59 -0600 Message-Id: <1612192919-4069-7-git-send-email-richard.gong@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> References: <1612192919-4069-1-git-send-email-richard.gong@linux.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org From: Richard Gong Extend FPGA manager driver to support FPGA bitstream authentication on Intel SocFPGA platforms. Signed-off-by: Richard Gong --- v4: s/FPGA_MGR_BITSTREM_AUTHENTICATION/FPGA_MGR_BITSTREAM_AUTHENTICATE v3: add handle to retriev the firmware version to keep driver back compatible v2: use flag defined in stratix10-svc driver --- drivers/fpga/stratix10-soc.c | 62 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/drivers/fpga/stratix10-soc.c b/drivers/fpga/stratix10-soc.c index 657a70c..9ab7afd 100644 --- a/drivers/fpga/stratix10-soc.c +++ b/drivers/fpga/stratix10-soc.c @@ -24,6 +24,10 @@ #define S10_BUFFER_TIMEOUT (msecs_to_jiffies(SVC_RECONFIG_BUFFER_TIMEOUT_MS)) #define S10_RECONFIG_TIMEOUT (msecs_to_jiffies(SVC_RECONFIG_REQUEST_TIMEOUT_MS)) +#define INVALID_FIRMWARE_VERSION 0xFFFF +typedef void (*s10_callback)(struct stratix10_svc_client *client, + struct stratix10_svc_cb_data *data); + /* * struct s10_svc_buf * buf: virtual address of buf provided by service layer @@ -40,11 +44,13 @@ struct s10_priv { struct completion status_return_completion; struct s10_svc_buf svc_bufs[NUM_SVC_BUFS]; unsigned long status; + unsigned int fw_version; }; static int s10_svc_send_msg(struct s10_priv *priv, enum stratix10_svc_command_code command, - void *payload, u32 payload_length) + void *payload, u32 payload_length, + s10_callback callback) { struct stratix10_svc_chan *chan = priv->chan; struct device *dev = priv->client.dev; @@ -57,6 +63,7 @@ static int s10_svc_send_msg(struct s10_priv *priv, msg.command = command; msg.payload = payload; msg.payload_length = payload_length; + priv->client.receive_cb = callback; ret = stratix10_svc_send(chan, &msg); dev_dbg(dev, "stratix10_svc_send returned status %d\n", ret); @@ -134,6 +141,29 @@ static void s10_unlock_bufs(struct s10_priv *priv, void *kaddr) } /* + * s10_fw_version_callback - callback for the version of running firmware + * @client: service layer client struct + * @data: message from service layer + */ +static void s10_fw_version_callback(struct stratix10_svc_client *client, + struct stratix10_svc_cb_data *data) +{ + struct s10_priv *priv = client->priv; + unsigned int *version = (unsigned int *)data->kaddr1; + + if (data->status == BIT(SVC_STATUS_OK)) + priv->fw_version = *version; + else if (data->status == BIT(SVC_STATUS_NO_SUPPORT)) + dev_warn(client->dev, + "FW doesn't support bitstream authentication\n"); + else + dev_err(client->dev, "Failed to get FW version %lu\n", + BIT(data->status)); + + complete(&priv->status_return_completion); +} + +/* * s10_receive_callback - callback for service layer to use to provide client * (this driver) messages received through the mailbox. * client: service layer client struct @@ -186,13 +216,22 @@ static int s10_ops_write_init(struct fpga_manager *mgr, if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { dev_dbg(dev, "Requesting partial reconfiguration.\n"); ctype.flags |= BIT(COMMAND_RECONFIG_FLAG_PARTIAL); + } else if (info->flags & FPGA_MGR_BITSTREAM_AUTHENTICATE) { + if (priv->fw_version == INVALID_FIRMWARE_VERSION) { + dev_err(dev, "FW doesn't support\n"); + return -EINVAL; + } + + dev_dbg(dev, "Requesting bitstream authentication.\n"); + ctype.flags |= BIT(COMMAND_AUTHENTICATE_BITSTREAM); } else { dev_dbg(dev, "Requesting full reconfiguration.\n"); } reinit_completion(&priv->status_return_completion); ret = s10_svc_send_msg(priv, COMMAND_RECONFIG, - &ctype, sizeof(ctype)); + &ctype, sizeof(ctype), + s10_receive_callback); if (ret < 0) goto init_done; @@ -259,7 +298,7 @@ static int s10_send_buf(struct fpga_manager *mgr, const char *buf, size_t count) svc_buf = priv->svc_bufs[i].buf; memcpy(svc_buf, buf, xfer_sz); ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_DATA_SUBMIT, - svc_buf, xfer_sz); + svc_buf, xfer_sz, s10_receive_callback); if (ret < 0) { dev_err(dev, "Error while sending data to service layer (%d)", ret); @@ -303,7 +342,7 @@ static int s10_ops_write(struct fpga_manager *mgr, const char *buf, ret = s10_svc_send_msg( priv, COMMAND_RECONFIG_DATA_CLAIM, - NULL, 0); + NULL, 0, s10_receive_callback); if (ret < 0) break; } @@ -357,7 +396,8 @@ static int s10_ops_write_complete(struct fpga_manager *mgr, do { reinit_completion(&priv->status_return_completion); - ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_STATUS, NULL, 0); + ret = s10_svc_send_msg(priv, COMMAND_RECONFIG_STATUS, + NULL, 0, s10_receive_callback); if (ret < 0) break; @@ -411,8 +451,9 @@ static int s10_probe(struct platform_device *pdev) if (!priv) return -ENOMEM; + priv->fw_version = INVALID_FIRMWARE_VERSION; priv->client.dev = dev; - priv->client.receive_cb = s10_receive_callback; + priv->client.receive_cb = NULL; priv->client.priv = priv; priv->chan = stratix10_svc_request_channel_byname(&priv->client, @@ -440,6 +481,15 @@ static int s10_probe(struct platform_device *pdev) goto probe_err; } + /* get the running firmware version */ + ret = s10_svc_send_msg(priv, COMMAND_FIRMWARE_VERSION, + NULL, 0, s10_fw_version_callback); + if (ret) { + dev_err(dev, "couldn't get firmware version\n"); + fpga_mgr_free(mgr); + goto probe_err; + } + platform_set_drvdata(pdev, mgr); return ret;