Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp951272pxb; Tue, 9 Feb 2021 17:46:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjlvCHE+ldtW7tTf2EPUQGF3VmnnxJgl1xvC/v+qzRr7CbPre4ddmlML3etWZrd/p5btOa X-Received: by 2002:a17:907:35cb:: with SMTP id ap11mr534838ejc.459.1612921617426; Tue, 09 Feb 2021 17:46:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612921617; cv=none; d=google.com; s=arc-20160816; b=fTapaAP4EIxhkFuIjgQScGuaiehp8MaK8rfFjvqXY8k/hyRvbq/FvyS6FpUDtEF3qc Tlw6pnACRh9/pUwbzhXx4GGwPt9cUiUhjmXMsC33i87bMRKPg23Bkz/yTMcCB43+oYOc fWk7as6XWZtya/nomgd7fN/wjBxRYe3wQ0BSxT6MLWn2ugAE9AUsSP8RcZ1WGa8Y0gs2 MVxNvzZvXJ+/1nk2MiJsVWGdknMKaaH3gAcxG1qApNyorLT+bQGQmhycDMLz9XWIM/7c AiP6z8WGQjfxWQXWwiZ67EtyC5XVN/DVSAvOwnpZhvXVKm3hkDXluQ9zcR1bJXuwS1yI ZB3g== 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 :message-id:date:subject:cc:to:from:dmarc-filter:sender :dkim-signature; bh=m4sOxKBKLmTi6eZIh2OP00gB5CPUIiEGD54N02UPzOI=; b=fIH62iYKI21c26WqXpjHAR9sUdmiT48E/EpwVSLIK6S2iUFjVq0886KQsW35oEZ3be ZSVhOTrO58NYCDR6cefm/nU9Wq3y4n5njn4dH4fc1a8fASZDX97b/qsimejen0zhkmbA EEmjzA3HjKNIACJUqg05gGjqrmLMqNufGD9dA8SQrdAaaLPwU4FVzj5Wih/fioZxaE6B sw2zVxPeNCBqR70DBVW1FBP479Y5xvhC4Ln55v9DKoLBg4o6Z+XVDpL/raJ71dI3KlzH 4ipYdtdtcMGJI3U515E9Fe+NtvRj7jgeJVf2kbMj/8HSD4ohuOnmJaI0htG4BkZIihld nXyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=T2gicHjB; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de1si283974edb.555.2021.02.09.17.46.33; Tue, 09 Feb 2021 17:46:57 -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=@mg.codeaurora.org header.s=smtp header.b=T2gicHjB; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234513AbhBJBqF (ORCPT + 99 others); Tue, 9 Feb 2021 20:46:05 -0500 Received: from mail29.static.mailgun.info ([104.130.122.29]:25337 "EHLO mail29.static.mailgun.info" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234575AbhBIX7H (ORCPT ); Tue, 9 Feb 2021 18:59:07 -0500 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1612915084; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=m4sOxKBKLmTi6eZIh2OP00gB5CPUIiEGD54N02UPzOI=; b=T2gicHjBlnSPvL/iL1gJjSrFodxcYGHcH0nzi0We8bccaHwkBmWSs3mk70HLmnpfHZGOXK0k BBHWvTz2cZ3k8HtvAIFJx7CAHgma/iLFlz+lkku8MTh8Nk85QL3oxYaje8eos60X6lIvbk45 jCLLZ2oh4GqWjkhHwVR/WZQeEFk= X-Mailgun-Sending-Ip: 104.130.122.29 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n06.prod.us-west-2.postgun.com with SMTP id 60232164f112b7872c40c476 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Tue, 09 Feb 2021 23:57:24 GMT Sender: jcrouse=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 7E43CC43461; Tue, 9 Feb 2021 23:57:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from jordan-laptop.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: jcrouse) by smtp.codeaurora.org (Postfix) with ESMTPSA id 315C8C433CA; Tue, 9 Feb 2021 23:57:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 315C8C433CA Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=jcrouse@codeaurora.org From: Jordan Crouse To: linux-arm-msm@vger.kernel.org Cc: Akhil P Oommen , Daniel Vetter , David Airlie , Eric Anholt , Jonathan Marek , Rob Clark , Sai Prakash Ranjan , Sean Paul , Sharat Masetty , dri-devel@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] drm/msm: a6xx: Make sure the SQE microcode is safe Date: Tue, 9 Feb 2021 16:57:17 -0700 Message-Id: <20210209235717.768010-1-jcrouse@codeaurora.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Most a6xx targets have security issues that were fixed with new versions of the microcode(s). Make sure that we are booting with a safe version of the microcode for the target and print a message and error if not. Signed-off-by: Jordan Crouse --- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 67 +++++++++++++++++++++------ 1 file changed, 54 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c index ba8e9d3cf0fe..cfb0d5f63784 100644 --- a/drivers/gpu/drm/msm/adreno/a6xx_gpu.c +++ b/drivers/gpu/drm/msm/adreno/a6xx_gpu.c @@ -522,28 +522,61 @@ static int a6xx_cp_init(struct msm_gpu *gpu) return a6xx_idle(gpu, ring) ? 0 : -EINVAL; } -static void a6xx_ucode_check_version(struct a6xx_gpu *a6xx_gpu, +/* + * Check that the microcode version is new enough to include several key + * security fixes. Return true if the ucode is safe. + */ +static bool a6xx_ucode_check_version(struct a6xx_gpu *a6xx_gpu, struct drm_gem_object *obj) { + struct adreno_gpu *adreno_gpu = &a6xx_gpu->base; u32 *buf = msm_gem_get_vaddr(obj); + bool ret = false; if (IS_ERR(buf)) - return; + return false; /* - * If the lowest nibble is 0xa that is an indication that this microcode - * has been patched. The actual version is in dword [3] but we only care - * about the patchlevel which is the lowest nibble of dword [3] - * - * Otherwise check that the firmware is greater than or equal to 1.90 - * which was the first version that had this fix built in + * Targets up to a640 (a618, a630 and a640) need to check for a + * microcode version that is patched to support the whereami opcode or + * one that is new enough to include it by default. */ - if (((buf[0] & 0xf) == 0xa) && (buf[2] & 0xf) >= 1) - a6xx_gpu->has_whereami = true; - else if ((buf[0] & 0xfff) > 0x190) - a6xx_gpu->has_whereami = true; + if (adreno_is_a618(adreno_gpu) || adreno_is_a630(adreno_gpu) || + adreno_is_a640(adreno_gpu)) { + /* + * If the lowest nibble is 0xa that is an indication that this + * microcode has been patched. The actual version is in dword + * [3] but we only care about the patchlevel which is the lowest + * nibble of dword [3] + * + * Otherwise check that the firmware is greater than or equal + * to 1.90 which was the first version that had this fix built + * in + */ + if ((((buf[0] & 0xf) == 0xa) && (buf[2] & 0xf) >= 1) || + (buf[0] & 0xfff) > 0x190) { + a6xx_gpu->has_whereami = true; + ret = true; + } + } else { + /* + * a650 tier targets don't need whereami but still need to be + * equal to or newer than 1.95 for other security fixes + */ + if (adreno_is_a640(adreno_gpu)) { + if ((buf[0] & 0xfff) >= 0x195) + ret = true; + } + + /* + * When a660 is added those targets should return true here + * since those have all the critiical security fixes built in + * from the start + */ + } msm_gem_put_vaddr(obj); + return ret; } static int a6xx_ucode_init(struct msm_gpu *gpu) @@ -566,7 +599,15 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) } msm_gem_object_set_name(a6xx_gpu->sqe_bo, "sqefw"); - a6xx_ucode_check_version(a6xx_gpu, a6xx_gpu->sqe_bo); + if (!a6xx_ucode_check_version(a6xx_gpu, a6xx_gpu->sqe_bo)) { + DRM_DEV_ERROR(&gpu->pdev->dev, + "SQE ucode version is too old. It is likely unsafe\n"); + msm_gem_unpin_iova(a6xx_gpu->sqe_bo, gpu->aspace); + drm_gem_object_put(a6xx_gpu->sqe_bo); + + a6xx_gpu->sqe_bo = NULL; + return -EPERM; + } } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO, -- 2.25.1