Message ID | 20231123012234.5783-1-yaolu@kylinos.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:5389:b0:164:83eb:24d7 with SMTP id z9csp7430rwe; Wed, 22 Nov 2023 17:23:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIOMWA06n3YSjalxtz8ZNSxd8aSyWbSS0VRe0GVgcRffsd6IL4+9+RDUOxjllLJ8VPpvHr X-Received: by 2002:a17:902:e80a:b0:1cc:361b:7b10 with SMTP id u10-20020a170902e80a00b001cc361b7b10mr4777296plg.24.1700702600012; Wed, 22 Nov 2023 17:23:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700702599; cv=none; d=google.com; s=arc-20160816; b=MN7cPsdmtoJrtH7nXrUycKfL36HMgvv4zQ2Ix9TehsaEc3/ShYwsI/sVZYeVBOI5Dx lGWZ8X5bAMJ19kGEnTk13OpScDcyWTx5p+vbdiQ17cTTaQcsAi14U67mDsBNytGzBrys v33ROwC2TpUyULKAZzQdrAwR614AIVxg2UMpYkQMtNnPTQgxVpj3OMyH90YU8K5hs/Z5 a1MxjwY31t9iTcJTBKIRWcnGyVHTyNfRVQPfQxk4+4OTMLcn3fwKwwPzOMHUza3uAugO MUVK+aa2RyQebC6+yl+77hTXSRUURSvfMYPT++KWyj3s5k1Ktv0v6HdT9hVuWnRpW4OD GNkw== 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; bh=TG95PxfIYHlanV2XGR23BOqwUpYTMJVALv1rSwO5SGs=; fh=0I9Fs0hz9FnAYUJK30wLjFqYlKg7bITs598AIIhcbfk=; b=yIVwU8ge20EV000XyV54ZSsVRu6eICTVyCiZ+x3guHdkbGrVjVs+u4rNMbhfBJkj4V Ua3dsJ+paqQTcAVsmqiulUpTr1X6xc4MsJcr0dx1M6aAxP2A38lgTej94h7VSYsuXIyu lsxRJyiK1FpC/3Kz/UcoaunyiSlZYx5fZjSbLUQx+u2lzC9heEhDwtrLSCAGl+KxxrTP di2kOkPGkHq+nl3iBrzqNhV2T7tIG7945Pl5+HzKCMMQ0CRWCVJWBd/g0QwBuvVugCy5 wWBUPHDq7OtVHUQS4CCdHtQ0+G2ckom8mbB1aozKLJ5rXuhPuiR+qGk/daE2CkZlToyp +/mw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id ij20-20020a170902ab5400b001c60e273252si120574plb.25.2023.11.22.17.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 17:23:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id B3E9B825BF54; Wed, 22 Nov 2023 17:23:17 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229535AbjKWBXC (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Wed, 22 Nov 2023 20:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjKWBXA (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 22 Nov 2023 20:23:00 -0500 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DF2092 for <linux-kernel@vger.kernel.org>; Wed, 22 Nov 2023 17:22:54 -0800 (PST) X-UUID: 36401da4109c4857a4a59b4b09b53f8d-20231123 X-CID-O-RULE: Release_Ham X-CID-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.32,REQID:0645df19-50f1-4e62-823b-6bbd218f57f0,IP:15, URL:0,TC:0,Content:-5,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACT ION:release,TS:-5 X-CID-INFO: VERSION:1.1.32,REQID:0645df19-50f1-4e62-823b-6bbd218f57f0,IP:15,UR L:0,TC:0,Content:-5,EDM:0,RT:0,SF:-15,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-5 X-CID-META: VersionHash:5f78ec9,CLOUDID:ecb2b495-10ce-4e4b-85c2-c9b5229ff92b,B ulkID:231123092241R6NRFKKH,BulkQuantity:0,Recheck:0,SF:66|38|24|17|19|44|1 02,TC:nil,Content:0,EDM:-3,IP:-2,URL:1,File:nil,Bulk:nil,QS:nil,BEC:nil,CO L:0,OSI:0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_ULS,TF_CID_SPAM_SNR,TF_CID_SPAM_FAS,TF_CID_SPAM_FSD, TF_CID_SPAM_FSI X-UUID: 36401da4109c4857a4a59b4b09b53f8d-20231123 X-User: yaolu@kylinos.cn Received: from localhost.localdomain [(116.128.244.169)] by mailgw (envelope-from <yaolu@kylinos.cn>) (Generic MTA) with ESMTP id 1513233395; Thu, 23 Nov 2023 09:22:38 +0800 From: Lu Yao <yaolu@kylinos.cn> To: airlied@gmail.com, daniel@ffwll.ch Cc: alexander.deucher@amd.com, christian.koenig@amd.com, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Lu Yao <yaolu@kylinos.cn> Subject: [PATCH v2] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer Date: Thu, 23 Nov 2023 09:22:34 +0800 Message-Id: <20231123012234.5783-1-yaolu@kylinos.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231122093509.34302-1-yaolu@kylinos.cn> References: <20231122093509.34302-1-yaolu@kylinos.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 22 Nov 2023 17:23:17 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783256382257312095 X-GMAIL-MSGID: 1783315929294622614 |
Series |
[v2] drm/amdgpu: Fix cat debugfs amdgpu_regs_didt causes kernel null pointer
|
|
Commit Message
Lu Yao
Nov. 23, 2023, 1:22 a.m. UTC
For 'AMDGPU_FAMILY_SI' family cards, in 'si_common_early_init' func, init
'didt_rreg' and 'didt_wreg' to 'NULL'. But in func
'amdgpu_debugfs_regs_didt_read/write', using 'RREG32_DIDT' 'WREG32_DIDT'
lacks of relevant judgment. And other 'amdgpu_ip_block_version' that use
these two definitions won't be added for 'AMDGPU_FAMILY_SI'.
So, add null pointer judgment before calling.
Signed-off-by: Lu Yao <yaolu@kylinos.cn>
---
Changes in v2:
1. Drop dev_err message.
2. Change error code from 'EPERM' to 'EOPNOTSUPP'
Link to v1: https://lore.kernel.org/all/20231122093509.34302-1-yaolu@kylinos.cn/
Thanks Christian for his comments.
---
drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 ++++++
1 file changed, 6 insertions(+)
Comments
Am 23.11.23 um 02:22 schrieb Lu Yao: > For 'AMDGPU_FAMILY_SI' family cards, in 'si_common_early_init' func, init > 'didt_rreg' and 'didt_wreg' to 'NULL'. But in func > 'amdgpu_debugfs_regs_didt_read/write', using 'RREG32_DIDT' 'WREG32_DIDT' > lacks of relevant judgment. And other 'amdgpu_ip_block_version' that use > these two definitions won't be added for 'AMDGPU_FAMILY_SI'. > > So, add null pointer judgment before calling. > > Signed-off-by: Lu Yao <yaolu@kylinos.cn> Reviewed-by: Christian König <christian.koenig@amd.com> > --- > Changes in v2: > 1. Drop dev_err message. > 2. Change error code from 'EPERM' to 'EOPNOTSUPP' > Link to v1: https://lore.kernel.org/all/20231122093509.34302-1-yaolu@kylinos.cn/ > Thanks Christian for his comments. > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > index a53f436fa9f1..e098cd66fa2a 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > @@ -638,6 +638,9 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + if (adev->didt_rreg == NULL) > + return -EOPNOTSUPP; > + > r = pm_runtime_get_sync(adev_to_drm(adev)->dev); > if (r < 0) { > pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); > @@ -694,6 +697,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user > if (size & 0x3 || *pos & 0x3) > return -EINVAL; > > + if (adev->didt_wreg == NULL) > + return -EOPNOTSUPP; > + > r = pm_runtime_get_sync(adev_to_drm(adev)->dev); > if (r < 0) { > pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
Applied. Thanks! Alex On Thu, Nov 23, 2023 at 3:22 AM Christian König <christian.koenig@amd.com> wrote: > > Am 23.11.23 um 02:22 schrieb Lu Yao: > > For 'AMDGPU_FAMILY_SI' family cards, in 'si_common_early_init' func, init > > 'didt_rreg' and 'didt_wreg' to 'NULL'. But in func > > 'amdgpu_debugfs_regs_didt_read/write', using 'RREG32_DIDT' 'WREG32_DIDT' > > lacks of relevant judgment. And other 'amdgpu_ip_block_version' that use > > these two definitions won't be added for 'AMDGPU_FAMILY_SI'. > > > > So, add null pointer judgment before calling. > > > > Signed-off-by: Lu Yao <yaolu@kylinos.cn> > > Reviewed-by: Christian König <christian.koenig@amd.com> > > > --- > > Changes in v2: > > 1. Drop dev_err message. > > 2. Change error code from 'EPERM' to 'EOPNOTSUPP' > > Link to v1: https://lore.kernel.org/all/20231122093509.34302-1-yaolu@kylinos.cn/ > > Thanks Christian for his comments. > > --- > > drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > > index a53f436fa9f1..e098cd66fa2a 100644 > > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c > > @@ -638,6 +638,9 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, > > if (size & 0x3 || *pos & 0x3) > > return -EINVAL; > > > > + if (adev->didt_rreg == NULL) > > + return -EOPNOTSUPP; > > + > > r = pm_runtime_get_sync(adev_to_drm(adev)->dev); > > if (r < 0) { > > pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); > > @@ -694,6 +697,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user > > if (size & 0x3 || *pos & 0x3) > > return -EINVAL; > > > > + if (adev->didt_wreg == NULL) > > + return -EOPNOTSUPP; > > + > > r = pm_runtime_get_sync(adev_to_drm(adev)->dev); > > if (r < 0) { > > pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); >
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c index a53f436fa9f1..e098cd66fa2a 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c @@ -638,6 +638,9 @@ static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf, if (size & 0x3 || *pos & 0x3) return -EINVAL; + if (adev->didt_rreg == NULL) + return -EOPNOTSUPP; + r = pm_runtime_get_sync(adev_to_drm(adev)->dev); if (r < 0) { pm_runtime_put_autosuspend(adev_to_drm(adev)->dev); @@ -694,6 +697,9 @@ static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user if (size & 0x3 || *pos & 0x3) return -EINVAL; + if (adev->didt_wreg == NULL) + return -EOPNOTSUPP; + r = pm_runtime_get_sync(adev_to_drm(adev)->dev); if (r < 0) { pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);