From patchwork Mon Jun 5 16:12:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 103388 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2812392vqr; Mon, 5 Jun 2023 09:37:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ47LQVV49WHwTY64vpZU5dY//kzm0QTzDdSwG4zbrjaGbzI/spHz59m9aonvnVi044jSjbW X-Received: by 2002:a17:902:ce83:b0:1aa:d545:462e with SMTP id f3-20020a170902ce8300b001aad545462emr8740072plg.13.1685983023596; Mon, 05 Jun 2023 09:37:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685983023; cv=none; d=google.com; s=arc-20160816; b=sBmPf/wQCEftIU1Yeo6BKrwWm3Ri3ITFsZ/sC7nQ7X67SDSg8Gy9sdY3X8XiP0/+Ai 4nBsOUgGKh+JaJxCwm++n/7aRED2b5AZWbLU/QhqfhRlFDo8Bf46Nl8/iezPVZE42GUD RdVEIUH5EvfzLvyqtR4YqTmbwHsTL1sqdU3w34/Ndxgiq9sUMDIME0GmtRGBzzG1Zd7R qomj0rp73jpRSVIuq0kiLg9XnfmBGb8ppyahoageoWpJRW9DGIgG+TCoNAsz8wZsvybH WTRmK3NZGUH7jB38gsAmnPJW+wy2Vb19rriU5JdCKwdZdB89slXmntwOWiX6xmDxO4Jv 3aVw== 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=0Xz0jFabxOwGj3tju/EW2nEXpkermFnu9e9Ec199qZ0=; b=HjUit05zc8zmpgRk0dIclofG1gAacBaR+a0s6sxeIVUHxtAOCqXNJKLlkPiyt476w9 3PiiIOgCNH8bW4VW5G1KfcVgHzzT15/CZCJoeGXYnLu4YNAANqReBGFrfjyLtEQkAEMd F0dGuBlSoSM1eNGr5WZdiMBp9UR8FEl+ZJkFY832n017xvw/qb3qUbhf8qKjc66ApjLe 3efOkHOfRc5ADUnon9b2OlSBMFWfKRPfcsTkaJti5OJB8fpZrJsTL2sAyN6Hlj5Cy889 oBEaCPQ1mrbYwdY4gmk6mxsD43MkmiqVFT0pfGYO4PrSt+a7luZqYXe1yhpKWEJ0xpqY M6eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=RpTmJiA3; 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 i6-20020a17090332c600b001ae42afbf93si5794212plr.450.2023.06.05.09.36.51; Mon, 05 Jun 2023 09:37:03 -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=RpTmJiA3; 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 S234603AbjFEQMg (ORCPT + 99 others); Mon, 5 Jun 2023 12:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231881AbjFEQMc (ORCPT ); Mon, 5 Jun 2023 12:12:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A467FB7 for ; Mon, 5 Jun 2023 09:12:31 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 38D0F6209E for ; Mon, 5 Jun 2023 16:12:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 573E6C4339B; Mon, 5 Jun 2023 16:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685981550; bh=Y/CZjNZo+1qpj5wP4ui+d4BljXqVHm12WzlCqm4DwWg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RpTmJiA3wvYc3nJFc3onPNTivqFIDK+4LergCSsq9dPrr2QukzMLRXUwmKxWyMx/H Kkn0zIevs/BE+n6arqBaKP/vrpzIbPzm6NJ9Fn3o4g111hZ+gJD47MzGI0V7lmqiBV L1VewThgnel9XuN25rqbCWprkFBl6SmPbrkVmqUB7df7eRty4T8vlbWjr3aBkVb2hF TLgyeBrq90lX1Gk892f1CWYrdgG10NVby5EkQ3K2g8dT+IkvTSO5DU2EuvWzXXjq+3 duqvTR/JO0GIIYbA3ko+Ms1+R+i18UT4kn3tTFKjnJolDLIhK0Bt/0qTPuMwKwcrNI qeMZLS20qxwPg== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , linux-graphics-maintainer@vmware.com, Zack Rusin Subject: [PATCH v2 1/2] objtool: Allow stack operations in UNWIND_HINT_UNDEFINED regions Date: Mon, 5 Jun 2023 09:12:21 -0700 Message-Id: <820c5b433f17c84e8761fb7465a8d319d706b1cf.1685981486.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767881334807929224?= X-GMAIL-MSGID: =?utf-8?q?1767881334807929224?= If the code specified UNWIND_HINT_UNDEFINED, skip the "undefined stack state" warning due to a stack operation. Just ignore the stack op and continue to propagate the undefined state. Signed-off-by: Josh Poimboeuf --- tools/objtool/check.c | 12 ++++++++++++ tools/objtool/include/objtool/cfi.h | 1 + 2 files changed, 13 insertions(+) diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4b869de7e827..b11c25a715ac 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -33,6 +33,7 @@ static unsigned long nr_cfi, nr_cfi_reused, nr_cfi_cache; static struct cfi_init_state initial_func_cfi; static struct cfi_state init_cfi; static struct cfi_state func_cfi; +static struct cfi_state force_undefined_cfi; struct instruction *find_insn(struct objtool_file *file, struct section *sec, unsigned long offset) @@ -2240,6 +2241,11 @@ static int read_unwind_hints(struct objtool_file *file) insn->hint = true; + if (hint->type == UNWIND_HINT_TYPE_UNDEFINED) { + insn->cfi = &force_undefined_cfi; + continue; + } + if (hint->type == UNWIND_HINT_TYPE_SAVE) { insn->hint = false; insn->save = true; @@ -2793,6 +2799,10 @@ static int update_cfi_state(struct instruction *insn, struct cfi_reg *cfa = &cfi->cfa; struct cfi_reg *regs = cfi->regs; + /* ignore UNWIND_HINT_UNDEFINED regions */ + if (cfi->force_undefined) + return 0; + /* stack operations don't make sense with an undefined CFA */ if (cfa->base == CFI_UNDEFINED) { if (insn_func(insn)) { @@ -4607,6 +4617,8 @@ int check(struct objtool_file *file) init_cfi_state(&init_cfi); init_cfi_state(&func_cfi); set_func_state(&func_cfi); + init_cfi_state(&force_undefined_cfi); + force_undefined_cfi.force_undefined = true; if (!cfi_hash_alloc(1UL << (file->elf->symbol_bits - 3))) goto out; diff --git a/tools/objtool/include/objtool/cfi.h b/tools/objtool/include/objtool/cfi.h index b1258e79a1b7..c8a6bec4f6b9 100644 --- a/tools/objtool/include/objtool/cfi.h +++ b/tools/objtool/include/objtool/cfi.h @@ -36,6 +36,7 @@ struct cfi_state { bool drap; bool signal; bool end; + bool force_undefined; }; #endif /* _OBJTOOL_CFI_H */ From patchwork Mon Jun 5 16:12:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Poimboeuf X-Patchwork-Id: 103379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2805804vqr; Mon, 5 Jun 2023 09:26:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54qO1Lj3rppQeDO+4Pc7AYF6fwnjw2Rj3HP1R+4AZMZ92DvwSmDoYgF07hmkPE2Xn4P15z X-Received: by 2002:a05:6a21:9991:b0:10f:7e62:3806 with SMTP id ve17-20020a056a21999100b0010f7e623806mr9183692pzb.22.1685982386188; Mon, 05 Jun 2023 09:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685982386; cv=none; d=google.com; s=arc-20160816; b=wu9n7mUGNDcTGc71HIWgkTZkomb1bsCX50s52kbaXsVlLDkDsDr2y6Ns44DUp38NnY 77dRTT8N2DdULLm0yricOgHkI/BkTQ7GSbt0gwZEzUIF38dmcGcWtArhhywl1GXQBNwn LlxL8wDqjva8BJ/UqOCamfX9UOSv3TA/O/5Xvzt2eInj22n0hDIto7cBh/K7hF0e/nvt fiPoFYl3LJcR8DW0FqIV2ObnVwuDIjtJVMXKvaqxhzlwPrz846amuMsFeXPVk6hu33t5 rzAMgXhoJCIC0zD4zQR13pT0u/7wn90NmRBnWNexAvxxAc3nWCt1gOmSNRC3efb0TABG NxQw== 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=d3R7T6ZGsk/setHnRATwshWCDNjsw90xXFeLu0+FoWQ=; b=xX2ONUpDbNuJuzuQiNK9SMOWgKgn9lP+4QtxfJe4h5LAFX4pzMoNcwj18wpDZQDxPZ 7ilS4zD7jhIHFnlJrPEEiJpwY6NgrbUCVnk5dLlOi9IuiIy+Alw8E5v8jFY9GMZAKbDE h7ybMcd6HHUr3Xg83Of2y+eKmalEyTTFLmNd/Wpnm3sYGyGiljPG3EPPIHtbA68Nb226 NIOFzVCx70dZPMhzzKRdqyNtWPeKhnuECKI+Dhl5qtos0BZ/bFjtPs+9Dgk8U0eQ/mwh 7sJz5C4u30yh6mH7j3bS9PyCocfFV5HA/KlokV5IVx3CXv3vnnHq1cBKBEVGE66+deTm UROw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PhicJi3E; 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 y14-20020aa79e0e000000b0064d5e97d4acsi5506976pfq.346.2023.06.05.09.26.11; Mon, 05 Jun 2023 09:26:26 -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=PhicJi3E; 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 S234864AbjFEQMj (ORCPT + 99 others); Mon, 5 Jun 2023 12:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233545AbjFEQMc (ORCPT ); Mon, 5 Jun 2023 12:12:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3510BBD for ; Mon, 5 Jun 2023 09:12:32 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 9C1EC627F4 for ; Mon, 5 Jun 2023 16:12:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB561C433A4; Mon, 5 Jun 2023 16:12:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1685981551; bh=GbiswfqlPKxb8y7Cgh7d9fzBotuGBKD2mu+cvUJpcr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PhicJi3EulNDmKVT5zOxoXSJn8Gf9Ok6AcSu2Q4X/qtJ8svD2SxRIhxqV4QoEQ7Jz mslv+YWbWjpGC5c2mluIh5YPn3aPAhYOwO/Au2IRgxV6VttYqBGKllB1kTCG39R1Yn uRcrWyMFVUW8b3VPBeQC3DG3e8PKNxfAb5q9pOZEnSfQz2RRop8Pmh/bOAkvEe7r3x b/ntM4UQ1nPaMtPZU+8QYXS1ofomme3x9xrfOp91VnInn4jW7cI4mWvNiXE+/1MXae ZwofIIPgM/E1kdH1c7+LL9v1uw7odHN165s4CPspOItUOu5Lq8lUG1cc3ec8c2phdR JLhSV/jb4B7xw== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , linux-graphics-maintainer@vmware.com, Zack Rusin , kernel test robot Subject: [PATCH v2 2/2] drm/vmwgfx: Add unwind hints around RBP clobber Date: Mon, 5 Jun 2023 09:12:22 -0700 Message-Id: <4c795f2d87bc0391cf6543bcb224fa540b55ce4b.1685981486.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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?1767880666128786396?= X-GMAIL-MSGID: =?utf-8?q?1767880666128786396?= VMware high-bandwidth hypercalls take the RBP register as input. This breaks basic frame pointer convention, as RBP should never be clobbered. So frame pointer unwinding is broken for the instructions surrounding the hypercalls. Fortunately this doesn't break live patching with CONFIG_FRAME_POINTER, as it only unwinds from blocking tasks, and stack traces from preempted tasks are already marked unreliable anyway. However, for live patching with ORC, this could actually be a theoretical problem if vmw_port_hb_{in,out}() were still compiled with a frame pointer due to having an aligned stack. In practice that hasn't seemed to be an issue since the objtool warnings have only been seen with CONFIG_FRAME_POINTER. Add unwind hint annotations to tell the ORC unwinder to mark stack traces as unreliable. Fixes the following warnings: vmlinux.o: warning: objtool: vmw_port_hb_in+0x1df: return with modified stack frame vmlinux.o: warning: objtool: vmw_port_hb_out+0x1dd: return with modified stack frame Fixes: 89da76fde68d ("drm/vmwgfx: Add VMWare host messaging capability") Reported-by: kernel test robot Link: https://lore.kernel.org/oe-kbuild-all/202305160135.97q0Elax-lkp@intel.com/ Signed-off-by: Josh Poimboeuf --- arch/x86/include/asm/unwind_hints.h | 9 +++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/unwind_hints.h b/arch/x86/include/asm/unwind_hints.h index 01cb9692b160..85cc57cb6539 100644 --- a/arch/x86/include/asm/unwind_hints.h +++ b/arch/x86/include/asm/unwind_hints.h @@ -76,9 +76,18 @@ #else +#define UNWIND_HINT_UNDEFINED \ + UNWIND_HINT(UNWIND_HINT_TYPE_UNDEFINED, 0, 0, 0) + #define UNWIND_HINT_FUNC \ UNWIND_HINT(UNWIND_HINT_TYPE_FUNC, ORC_REG_SP, 8, 0) +#define UNWIND_HINT_SAVE \ + UNWIND_HINT(UNWIND_HINT_TYPE_SAVE, 0, 0, 0) + +#define UNWIND_HINT_RESTORE \ + UNWIND_HINT(UNWIND_HINT_TYPE_RESTORE, 0, 0, 0) + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_UNWIND_HINTS_H */ diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h index 0b74ca2dfb7b..23899d743a90 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_msg_x86.h @@ -105,10 +105,14 @@ flags, magic, bp, \ eax, ebx, ecx, edx, si, di) \ ({ \ - asm volatile ("push %%rbp;" \ + asm volatile ( \ + UNWIND_HINT_SAVE \ + "push %%rbp;" \ + UNWIND_HINT_UNDEFINED \ "mov %12, %%rbp;" \ VMWARE_HYPERCALL_HB_OUT \ - "pop %%rbp;" : \ + "pop %%rbp;" \ + UNWIND_HINT_RESTORE : \ "=a"(eax), \ "=b"(ebx), \ "=c"(ecx), \ @@ -130,10 +134,14 @@ flags, magic, bp, \ eax, ebx, ecx, edx, si, di) \ ({ \ - asm volatile ("push %%rbp;" \ + asm volatile ( \ + UNWIND_HINT_SAVE \ + "push %%rbp;" \ + UNWIND_HINT_UNDEFINED \ "mov %12, %%rbp;" \ VMWARE_HYPERCALL_HB_IN \ - "pop %%rbp" : \ + "pop %%rbp;" \ + UNWIND_HINT_RESTORE : \ "=a"(eax), \ "=b"(ebx), \ "=c"(ecx), \