From patchwork Wed Nov 2 15:25:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3685863wru; Wed, 2 Nov 2022 08:29:40 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vM9GqAKar8lXkWSPpzc8im5Ah9j5wvuFbUNFVK9lsmpU6KFkAg2XhcCR0vfsx5A5so9Xw X-Received: by 2002:a17:90a:8418:b0:214:536f:2743 with SMTP id j24-20020a17090a841800b00214536f2743mr2795758pjn.175.1667402979823; Wed, 02 Nov 2022 08:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667402979; cv=none; d=google.com; s=arc-20160816; b=VUCGXt2pvqQEQQCN4FpeaAPwVz2XzcuJEz7Mx8CDxvbvOS+wPqGtCwxQ+nmCY9fKFA HzgioKNOPl+tmtn648KIscEBKF/KCVVa8TFi19X0AVfhL/FJyWodisikl6iQHT1EtFcY ba0NfEFE/PF2luqnKUbzTsk5oPBwRTRtC5xZheWCTNmQH48pqTrWTu3DZQ1pC0mVZvyS 3BSHI6RXSNG2afheNrVEcCOv7O25J+k9I0oJCBHed5ltt6xyMhlfWd2uKbkTWsQhN7pP B2rDa0BFCUGAgMndeE9dFt9LUfuIel1QK/boYvcsnPQjXe6IxEAiWxsuqX8vDkcCpyEl JD0w== 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:dkim-signature; bh=3bi3uZ85tOrBotZPkPK+DHZefyNQ4HOrG8iiPNJHpgk=; b=Po0Jst6m1VfDVN2v1kfcQoOVAMK/lfBi6tJ4sPI0kqLrpPESuqSqeVP7U5NsnG5O/R XnndY/YpKyACuw5+DWCZhKjinVe8UbiJTJ+ZfpPi8JGgNKIviQ4rmndbJtnUo2LgvuGr kgvyFwgAB4UqDef8pEswsuO0OSqpVvG5Ee87HTjlqJF5s4q401nCP1VNCFpblO52BKNk GqzaD1cFvyKvdlckDELNZVMOeeHYSnqk6fPjJnzwSXi4TcBQQOPBTTeR9wxqYKpH+gJD BGl7c6h0buIpYRR95g0Jm936RBcUvLrMNfo8bRmyNL42L6LU7G3RbNzMAQPMtD0qA8BC l4mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bkmbP53S; 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 s24-20020a056a00179800b0056cb4662b9csi18587646pfg.16.2022.11.02.08.29.06; Wed, 02 Nov 2022 08:29:39 -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=bkmbP53S; 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 S230232AbiKBP0B (ORCPT + 99 others); Wed, 2 Nov 2022 11:26:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbiKBPZ7 (ORCPT ); Wed, 2 Nov 2022 11:25:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA1C41409A for ; Wed, 2 Nov 2022 08:25:58 -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 630E8B8233E for ; Wed, 2 Nov 2022 15:25:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33201C433D7; Wed, 2 Nov 2022 15:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667402756; bh=QqCq9FzEZmwrlGUBhYrSUWsSyKinysXKHWy0D5tQtL4=; h=From:To:Cc:Subject:Date:From; b=bkmbP53Ss3pbEvxROWjwMOfrtTPAoXHyH7DZbjcZSPO5149qw+yo4OoSRbXpgz1Hz wgJA5J2axERwrL6jS30ImQny7gt9cSBwhYch5rOR7jJJIcJbRIcBOl3ia1JJrFZE2a z+Yyo2Wf80QzzzLM7UpMn8kpxIPRogJALrwXuw8XyRsw0/KMdAq5aVJZ2bO90zjrMV o5hBDP2AXXEWdrDJDepWmQBLBZ/2h1HFXjqR1Dh89DJhwMUxFcwdSvIXmM94QbSufC G+DPnXVJP+SVnVNO7IJ5JIXluGDbCMMpD29BK4twyzqa/ze8i5x+t9U5Dqdt7KP+JL NaZT48+juTG+Q== 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 1/2] drm/amdgpu: Fix type of second parameter in trans_msg() callback Date: Wed, 2 Nov 2022 08:25:39 -0700 Message-Id: <20221102152540.2389891-1-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 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?1748398746801632294?= X-GMAIL-MSGID: =?utf-8?q?1748398746801632294?= 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/mxgpu_ai.c:412:15: error: incompatible function pointer types initializing 'void (*)(struct amdgpu_device *, u32, u32, u32, u32)' (aka 'void (*)(struct amdgpu_device *, unsigned int, unsigned int, unsigned int, unsigned int)') with an expression of type 'void (struct amdgpu_device *, enum idh_request, u32, u32, u32)' (aka 'void (struct amdgpu_device *, enum idh_request, unsigned int, unsigned int, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict] .trans_msg = xgpu_ai_mailbox_trans_msg, ^~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. drivers/gpu/drm/amd/amdgpu/mxgpu_nv.c:435:15: error: incompatible function pointer types initializing 'void (*)(struct amdgpu_device *, u32, u32, u32, u32)' (aka 'void (*)(struct amdgpu_device *, unsigned int, unsigned int, unsigned int, unsigned int)') with an expression of type 'void (struct amdgpu_device *, enum idh_request, u32, u32, u32)' (aka 'void (struct amdgpu_device *, enum idh_request, unsigned int, unsigned int, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict] .trans_msg = xgpu_nv_mailbox_trans_msg, ^~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. The type of the second parameter in the prototype should be 'enum idh_request' instead of 'u32'. Update it to clear up the warnings. 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/amdgpu/amdgpu_virt.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) base-commit: 9abf2313adc1ca1b6180c508c25f22f9395cc780 diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h index d94c31e68a14..bc4f079fd48c 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h @@ -74,6 +74,8 @@ struct amdgpu_vf_error_buffer { uint64_t data[AMDGPU_VF_ERROR_ENTRY_SIZE]; }; +enum idh_request; + /** * struct amdgpu_virt_ops - amdgpu device virt operations */ @@ -83,7 +85,8 @@ struct amdgpu_virt_ops { int (*req_init_data)(struct amdgpu_device *adev); int (*reset_gpu)(struct amdgpu_device *adev); int (*wait_reset)(struct amdgpu_device *adev); - void (*trans_msg)(struct amdgpu_device *adev, u32 req, u32 data1, u32 data2, u32 data3); + void (*trans_msg)(struct amdgpu_device *adev, enum idh_request req, + u32 data1, u32 data2, u32 data3); }; /* 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;