From patchwork Wed Nov 2 15:25:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3686023wru; Wed, 2 Nov 2022 08:29:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4MeB/Jemi2hY5gUehGHJ3Anma9F/zcEHdf3KWhfBkmi6CZjiLAmESQdmi48npgYAucby+9 X-Received: by 2002:a17:902:f546:b0:186:c6d7:6556 with SMTP id h6-20020a170902f54600b00186c6d76556mr25035325plf.109.1667402999638; Wed, 02 Nov 2022 08:29:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667402999; cv=none; d=google.com; s=arc-20160816; b=Ky9fTK3WTWgRml/Mb8aKh6wT+gHQ6U9JiLiLHnMOPkHHumABCKXqHbCTGYPu/dRkca AWzzQvfMQT7dD7kLW3a436sVdvyey6T8snfJtEoyFJqho4ELrVlGWCkZLkuY/SspMld8 X+ie/3rNLAPbbLnr0uY5S0p6DnIzSXgBim73NFe2yYc6J0pAK5OatydxQHl3vRfBt8dG JmIhHQM3aJhjEfKFAahro/qEYOZmq5h11WBcQqCi0cHYx9YfeAhqvTN3ajhxn2DPCe95 k1Kuu1+qHd3oCmw/zUd9wASGq70/4g6m0A/Vax2IuvQeLdZ5OqPYXWCR/99lFzRuTEjw NMrg== 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=EeHaweQVjV2g+Chur1J9fO/EeAwRBcp0n47Oq2nHUe4=; b=DXNS4unXHDe85jSYmjpTQnguF4W0P+ABNK5xluh8HSrokcUxfQR5DZUtOUm/hNli7u G7z4aFPVc2rDCmPEjlIRsvcHWt5V8F/qsDa3aqAoXzWoibXj62ByOaZslaHldCGGIani +OL1gB2Cro0TAUHSnJ3S4rqVtW7KJpFsIWzWIMgEkJilOazlEqEvRWtcn14MDpKasXBx Mt9v077J6NvEIFZKiY4qnT2Mmbr3oQM6PRq0kR18B8eRjgMpk6ndtI5qa1cE4pMJgZAO i30/TbktLl60Rf8wtw0odRgDQFHxugX42w1mJ8bJKV8lV/NGc8R4Jp4VCe2w5kUodYeV XwzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lZqy94Pq; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a656b93000000b00454649777ddsi15823613pgw.601.2022.11.02.08.29.27; Wed, 02 Nov 2022 08:29:59 -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=lZqy94Pq; 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 S230280AbiKBP0F (ORCPT + 99 others); Wed, 2 Nov 2022 11:26:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbiKBP0B (ORCPT ); Wed, 2 Nov 2022 11:26:01 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE991409A for ; Wed, 2 Nov 2022 08:26:00 -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 ams.source.kernel.org (Postfix) with ESMTPS id E21B6B8233D for ; Wed, 2 Nov 2022 15:25:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD4FAC433B5; Wed, 2 Nov 2022 15:25:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667402757; bh=hGx+6YDUsiGnguDXLfFqKT39GRFMP/Uu3APqDdfj8VI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lZqy94Pqj8EW3jOLG3l7Bn5qWcflGeeQrQ2aXEPTTLim/2BOfS84/XDX9hZ1CA5MF 07J5fQoAf+GOtybBC0b7RRqNwEGASwUUsX9zN89OaS3S8Mq/QHVCAhVcyxoeNL+jV8 ZXhn+p49r1Sp/gTlBogoGPdabtwT+XPsZdevJsh1QbiGgQSXRQQr0lPu8IA1sijYlm 4UAXUZlyNRyvgBxm+xrASJGTAvejkT9j4qn9ujsoVP/Z8nPSqG+R7aYQhDKbHJuWlU h3NOW80DaL+c/FOS47MxZJ+YOAJdo6Xnerom5o85kIdyH0JsaWVMGg211ndQfpn+DN 4Ul89CjYwfcnw== From: Nathan Chancellor To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , "Pan, Xinhui" Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, patches@lists.linux.dev, Nathan Chancellor Subject: [PATCH 2/2] drm/amdgpu: Fix type of second parameter in odn_edit_dpm_table() callback Date: Wed, 2 Nov 2022 08:25:40 -0700 Message-Id: <20221102152540.2389891-2-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102152540.2389891-1-nathan@kernel.org> References: <20221102152540.2389891-1-nathan@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748398767914117879?= X-GMAIL-MSGID: =?utf-8?q?1748398767914117879?= With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals: drivers/gpu/drm/amd/amdgpu/../pm/swsmu/amdgpu_smu.c:3008:29: error: incompatible function pointer types initializing 'int (*)(void *, uint32_t, long *, uint32_t)' (aka 'int (*)(void *, unsigned int, long *, unsigned int)') with an expression of type 'int (void *, enum PP_OD_DPM_TABLE_COMMAND, long *, uint32_t)' (aka 'int (void *, enum PP_OD_DPM_TABLE_COMMAND, long *, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict] .odn_edit_dpm_table = smu_od_edit_dpm_table, ^~~~~~~~~~~~~~~~~~~~~ 1 error generated. There are only two implementations of ->odn_edit_dpm_table() in 'struct amd_pm_funcs': smu_od_edit_dpm_table() and pp_odn_edit_dpm_table(). One has a second parameter type of 'enum PP_OD_DPM_TABLE_COMMAND' and the other uses 'u32'. Ultimately, smu_od_edit_dpm_table() calls ->od_edit_dpm_table() from 'struct pptable_funcs' and pp_odn_edit_dpm_table() calls ->odn_edit_dpm_table() from 'struct pp_hwmgr_func', which both have a second parameter type of 'enum PP_OD_DPM_TABLE_COMMAND'. Update the type parameter in both the prototype in 'struct amd_pm_funcs' and pp_odn_edit_dpm_table() to 'enum PP_OD_DPM_TABLE_COMMAND', which cleans up the warning. Link: https://github.com/ClangBuiltLinux/linux/issues/1750 Reported-by: Sami Tolvanen Signed-off-by: Nathan Chancellor Reviewed-by: Kees Cook --- drivers/gpu/drm/amd/include/kgd_pp_interface.h | 3 ++- drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/amd/include/kgd_pp_interface.h b/drivers/gpu/drm/amd/include/kgd_pp_interface.h index a40ead44778a..d18162e9ed1d 100644 --- a/drivers/gpu/drm/amd/include/kgd_pp_interface.h +++ b/drivers/gpu/drm/amd/include/kgd_pp_interface.h @@ -354,7 +354,8 @@ struct amd_pm_funcs { int (*get_power_profile_mode)(void *handle, char *buf); int (*set_power_profile_mode)(void *handle, long *input, uint32_t size); int (*set_fine_grain_clk_vol)(void *handle, uint32_t type, long *input, uint32_t size); - int (*odn_edit_dpm_table)(void *handle, uint32_t type, long *input, uint32_t size); + int (*odn_edit_dpm_table)(void *handle, enum PP_OD_DPM_TABLE_COMMAND type, + long *input, uint32_t size); int (*set_mp1_state)(void *handle, enum pp_mp1_state mp1_state); int (*smu_i2c_bus_access)(void *handle, bool acquire); int (*gfx_state_change_set)(void *handle, uint32_t state); diff --git a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c index ec055858eb95..1159ae114dd0 100644 --- a/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c +++ b/drivers/gpu/drm/amd/pm/powerplay/amd_powerplay.c @@ -838,7 +838,8 @@ static int pp_set_fine_grain_clk_vol(void *handle, uint32_t type, long *input, u return hwmgr->hwmgr_func->set_fine_grain_clk_vol(hwmgr, type, input, size); } -static int pp_odn_edit_dpm_table(void *handle, uint32_t type, long *input, uint32_t size) +static int pp_odn_edit_dpm_table(void *handle, enum PP_OD_DPM_TABLE_COMMAND type, + long *input, uint32_t size) { struct pp_hwmgr *hwmgr = handle;