Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp880634pxj; Wed, 16 Jun 2021 16:09:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvr6UtQJlMVmy1rrXpUq5Me1KxCH5Mi6+6i2gno9/GE0Ek/0fuKOQPA+E67L46iIdvCetL X-Received: by 2002:a05:6e02:4a5:: with SMTP id e5mr1343117ils.159.1623884991477; Wed, 16 Jun 2021 16:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623884991; cv=none; d=google.com; s=arc-20160816; b=fCcywpYKRo4k292E+87y+4LE7DZ3TUKbu0lXQSPnlkxix3sYFm6N1aNrE6DebGDJg6 FKpB7q/DtX1UBEexATkIijT5qw84fM1d2I7Sa/WIzg4aETgDKRR+RD2W986OSZI+tDTs uLabLFLEw7e5ffT21ElEncCkxluLl7g6BzqTqTlFnkGUAGUWWEbEPYV6vitZ0xusVH6j gFnjSXtPeUjqgaVkBa86QySF8ZP72kCy7E/qhfW/qVQRzrknOb2SIKZ0048xkBCw9efS XjUJyZdEJ7oD9kNYB6QLn+qYdOg/rEr9fQL4Wr6SvBXDRuW8vHKnP1X28HoAa1DjVuxc pAzQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QPw9X8zBMFrvibaRRc9Wqs3meh3YV9sFBHzSG/pf4wY=; b=m9lqvrxTtRs7SJ0xS0KWVqFXA1p6Xh5lG880qrgPSy1SaqcdAUee21Bhi5nm5HLckf +Gpg3fHnP1EBzMPo3M1LNnJxRnYr32n5akrlRu/y0wfv8hW3DytKsPg7puDhrhtFYQH+ yG4CEmhxgj0xgU4SYyIyghxTuIfHZE9wZ2kQd51JECIpxCLwvzOGEZNCwAoe5RMqjel1 Ld+bquTdRuMWz8YKzCqFAAtUfE7rzw9/ZpYTbVtSEqpH9d2cAxZcLywd45iZer4apMLc XPEyGsW9Su5V1lGVy4pJ9dbtH+paJwpHGMGAHcyc1MYqAobxwfOfcpzS/fLcxVMi0NKa nnrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=BiF7FPVQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d15si3410562iln.114.2021.06.16.16.09.40; Wed, 16 Jun 2021 16:09:51 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=BiF7FPVQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235241AbhFPPog (ORCPT + 99 others); Wed, 16 Jun 2021 11:44:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:55752 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235476AbhFPPmA (ORCPT ); Wed, 16 Jun 2021 11:42:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 343E0613BD; Wed, 16 Jun 2021 15:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623857874; bh=KEn+BrAL7HcuxfY0qjHMLmBIi25/yKl2/NG/iX7SUbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BiF7FPVQ0MA5h/eAcS3msx/5e2TWEdWCGjSii8R6+0UkF75ihDJhQLk3OdcpdyXl7 4wR111xn0rm2/vqQuuQpYkgcaBsBvEJOliRkRfOwSCjJ4qBmGh4eZO8S59U6NzGuwg IPxSnZiH0B5ns0MllVqpcneF6QYz9fRUkIkzrNIA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Victor Zhao , Jingwen Chen , Monk Liu , Alex Deucher , Sasha Levin Subject: [PATCH 5.12 44/48] drm/amd/amdgpu:save psp ring wptr to avoid attack Date: Wed, 16 Jun 2021 17:33:54 +0200 Message-Id: <20210616152838.032034749@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210616152836.655643420@linuxfoundation.org> References: <20210616152836.655643420@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Victor Zhao [ Upstream commit 2370eba9f552eaae3d8aa1f70b8e9eec5c560f9e ] [Why] When some tools performing psp mailbox attack, the readback value of register can be a random value which may break psp. [How] Use a psp wptr cache machanism to aovid the change made by attack. v2: unify change and add detailed reason Signed-off-by: Victor Zhao Signed-off-by: Jingwen Chen Reviewed-by: Monk Liu Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h | 1 + drivers/gpu/drm/amd/amdgpu/psp_v11_0.c | 3 ++- drivers/gpu/drm/amd/amdgpu/psp_v3_1.c | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h index cb50ba445f8c..0fd62a8e68c2 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.h @@ -76,6 +76,7 @@ struct psp_ring uint64_t ring_mem_mc_addr; void *ring_mem_handle; uint32_t ring_size; + uint32_t ring_wptr; }; /* More registers may will be supported */ diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c index c325d6f53a71..d39735a89a25 100644 --- a/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c +++ b/drivers/gpu/drm/amd/amdgpu/psp_v11_0.c @@ -720,7 +720,7 @@ static uint32_t psp_v11_0_ring_get_wptr(struct psp_context *psp) struct amdgpu_device *adev = psp->adev; if (amdgpu_sriov_vf(adev)) - data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102); + data = psp->km_ring.ring_wptr; else data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67); @@ -734,6 +734,7 @@ static void psp_v11_0_ring_set_wptr(struct psp_context *psp, uint32_t value) if (amdgpu_sriov_vf(adev)) { WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102, value); WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101, GFX_CTRL_CMD_ID_CONSUME_CMD); + psp->km_ring.ring_wptr = value; } else WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67, value); } diff --git a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c index f2e725f72d2f..908664a5774b 100644 --- a/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c +++ b/drivers/gpu/drm/amd/amdgpu/psp_v3_1.c @@ -379,7 +379,7 @@ static uint32_t psp_v3_1_ring_get_wptr(struct psp_context *psp) struct amdgpu_device *adev = psp->adev; if (amdgpu_sriov_vf(adev)) - data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_102); + data = psp->km_ring.ring_wptr; else data = RREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67); return data; @@ -394,6 +394,7 @@ static void psp_v3_1_ring_set_wptr(struct psp_context *psp, uint32_t value) /* send interrupt to PSP for SRIOV ring write pointer update */ WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_101, GFX_CTRL_CMD_ID_CONSUME_CMD); + psp->km_ring.ring_wptr = value; } else WREG32_SOC15(MP0, 0, mmMP0_SMN_C2PMSG_67, value); } -- 2.30.2