Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp239390rwi; Wed, 12 Oct 2022 19:27:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4mGuLe6MXm+DhulFpe/35URko3hMXmxXhnpEsaWsOfu2Z2ceGkGCVnsWGShLDLV7pEtLoi X-Received: by 2002:aa7:d454:0:b0:459:9ae7:725b with SMTP id q20-20020aa7d454000000b004599ae7725bmr29328447edr.165.1665628035896; Wed, 12 Oct 2022 19:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665628035; cv=none; d=google.com; s=arc-20160816; b=qeqkm0n4YeR0RJFoUgJYWKv4s2V7BpBux2B1lupGwwifssz0BYyxE9o6hbjegqwK88 D5aSdavvDAdIqX2jiBJJ/YOayfBLBQYYzsrfVMv//uRc4syZN/SZohBN/9wz4u/wjBaH 1xBECsXPrdy4nNuagqaagNRXQdT92161Hwcm+qtZK3amL0FG+D50013+fvfDHOQJiXs6 csFLqVi6IdHtYdGCFnlwHh24L+VtJCv6zZoI5HgnHD9tp06Zwrcm5RDPNsOWCpA+6SH6 DLGTn01xHgRDFJ+w/wn3e9bb8bhUh9NMgjQlC+cfJLUNP59/EIAZTA8GtAaZ2NKtXpk0 EQmg== 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=CSAhaIolE+VVT56qH11xQFvhjp4Ljhaek3RWxvaPdWI=; b=YgKJMDbNnjEcybg+qMTIOyeww3RBWh7nlYNPIKFeln9zNftKbG6Ll+HaXgCfBMA6DO rZR9BeQsBTMI5GI3CTXZ2VXf9yVuF5xEhKcw0aUyJdNoLVrRAZffm8Bg17bObtUuRV0V 9rDMPeplmPrLISpQDWV/coFU2V2Uil7sRp0wKydr3q9KzqghTPKJMwdwhiHRA44MGxCP frLrqFUqYLH+KSzIYr7vuT07xDuEsbJ/J4foKbr/t2Mqsr0m32RTJCigiVmSCFzOTlBc y5BJKiwHNB2o6mwVzwGhqPWMEcS2vKgF4vSmzKQ2dgkXxDvfhJ1VJpu/hB7LXkDp6NqT 23Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ndM8nn7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f7-20020a1709063f4700b00780cb1272eesi9647256ejj.466.2022.10.12.19.26.51; Wed, 12 Oct 2022 19:27:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ndM8nn7K; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiJMBhm (ORCPT + 99 others); Wed, 12 Oct 2022 21:37:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229646AbiJMBh2 (ORCPT ); Wed, 12 Oct 2022 21:37:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E38A312B37A; Wed, 12 Oct 2022 18:37:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 32B5B616BD; Thu, 13 Oct 2022 00:22:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97F21C43141; Thu, 13 Oct 2022 00:22:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1665620551; bh=CnoPWG8zf2q9zdiKSXsmVeJ9jCHX55ksx2BtQoba0JE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ndM8nn7KCM6W7cNX0yxd3kmjnsLfr8CdEsy7lf82gllEldai4b5ycf7u9mGHUqmjF z0UzQuATRWX9cZqFGv2G9laiOgczguWWeoSTB/k0qWR6qYP/F5d0Ky9zUKl2KkuCYN b1egKf0v5Jx5uP2dz8pYP5ic0MQg6i3Mf7VhH4Oh0LEUTX5Ya+GwqXdJpDT9oDmqdn Ba313nAGi6ha1cfH3TwEuXRpNi/w5xyVQhJs+/FsOIBFrQTIs9MyhAkLgu9I0EH4LD X9ikP51n7yubd8OVUpGrmo7bzBB3ARv6I8otCBhWX1P0q10zMD8NyXqD3W0nJMzaxk XSQLugdBqi6GQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: farah kassabri , Oded Gabbay , Sasha Levin , gregkh@linuxfoundation.org, obitton@habana.ai, osharabi@habana.ai, ttayar@habana.ai, dliberman@habana.ai Subject: [PATCH AUTOSEL 5.15 24/47] habanalabs: remove some f/w descriptor validations Date: Wed, 12 Oct 2022 20:20:59 -0400 Message-Id: <20221013002124.1894077-24-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221013002124.1894077-1-sashal@kernel.org> References: <20221013002124.1894077-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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: farah kassabri [ Upstream commit 6b9b9e244fdd0d6c5ee21b7b9d74282d9e43733a ] To be forward-backward compatible with the firmware in the initial communication during preboot, we need to remove the validation of the header size. This will allow us to add more fields to the lkd_fw_comms_desc structure. Instead of the validation of the header size, we just print warning when some mismatch in descriptor has been revealed, and we calculate the CRC base on descriptor size reported by the firmware instead of calculating it ourselves. Signed-off-by: farah kassabri Reviewed-by: Oded Gabbay Signed-off-by: Oded Gabbay Signed-off-by: Sasha Levin --- drivers/misc/habanalabs/common/firmware_if.c | 43 +++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/misc/habanalabs/common/firmware_if.c b/drivers/misc/habanalabs/common/firmware_if.c index a8e683964ab0..5d08c1f660fd 100644 --- a/drivers/misc/habanalabs/common/firmware_if.c +++ b/drivers/misc/habanalabs/common/firmware_if.c @@ -1638,50 +1638,36 @@ static int hl_fw_dynamic_validate_descriptor(struct hl_device *hdev, u64 addr; int rc; - if (le32_to_cpu(fw_desc->header.magic) != HL_COMMS_DESC_MAGIC) { - dev_err(hdev->dev, "Invalid magic for dynamic FW descriptor (%x)\n", + if (le32_to_cpu(fw_desc->header.magic) != HL_COMMS_DESC_MAGIC) + dev_warn(hdev->dev, "Invalid magic for dynamic FW descriptor (%x)\n", fw_desc->header.magic); - return -EIO; - } - if (fw_desc->header.version != HL_COMMS_DESC_VER) { - dev_err(hdev->dev, "Invalid version for dynamic FW descriptor (%x)\n", + if (fw_desc->header.version != HL_COMMS_DESC_VER) + dev_warn(hdev->dev, "Invalid version for dynamic FW descriptor (%x)\n", fw_desc->header.version); - return -EIO; - } /* - * calc CRC32 of data without header. + * Calc CRC32 of data without header. use the size of the descriptor + * reported by firmware, without calculating it ourself, to allow adding + * more fields to the lkd_fw_comms_desc structure. * note that no alignment/stride address issues here as all structures - * are 64 bit padded + * are 64 bit padded. */ - data_size = sizeof(struct lkd_fw_comms_desc) - - sizeof(struct comms_desc_header); data_ptr = (u8 *)fw_desc + sizeof(struct comms_desc_header); - - if (le16_to_cpu(fw_desc->header.size) != data_size) { - dev_err(hdev->dev, - "Invalid descriptor size 0x%x, expected size 0x%zx\n", - le16_to_cpu(fw_desc->header.size), data_size); - return -EIO; - } + data_size = le16_to_cpu(fw_desc->header.size); data_crc32 = hl_fw_compat_crc32(data_ptr, data_size); - if (data_crc32 != le32_to_cpu(fw_desc->header.crc32)) { - dev_err(hdev->dev, - "CRC32 mismatch for dynamic FW descriptor (%x:%x)\n", - data_crc32, fw_desc->header.crc32); + dev_err(hdev->dev, "CRC32 mismatch for dynamic FW descriptor (%x:%x)\n", + data_crc32, fw_desc->header.crc32); return -EIO; } /* find memory region to which to copy the image */ addr = le64_to_cpu(fw_desc->img_addr); region_id = hl_get_pci_memory_region(hdev, addr); - if ((region_id != PCI_REGION_SRAM) && - ((region_id != PCI_REGION_DRAM))) { - dev_err(hdev->dev, - "Invalid region to copy FW image address=%llx\n", addr); + if ((region_id != PCI_REGION_SRAM) && ((region_id != PCI_REGION_DRAM))) { + dev_err(hdev->dev, "Invalid region to copy FW image address=%llx\n", addr); return -EIO; } @@ -1698,8 +1684,7 @@ static int hl_fw_dynamic_validate_descriptor(struct hl_device *hdev, fw_loader->dynamic_loader.fw_image_size, region); if (rc) { - dev_err(hdev->dev, - "invalid mem transfer request for FW image\n"); + dev_err(hdev->dev, "invalid mem transfer request for FW image\n"); return rc; } -- 2.35.1