From patchwork Tue Dec 5 10:50:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 173997 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3359546vqy; Tue, 5 Dec 2023 03:23:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjpB9vcVkGfT1eDTUmYmYxqI/NDHxf4jbVAyfxGbRvQ8VIVPDI9km0XHJKpTltwhIFnM9y X-Received: by 2002:a05:6a00:399c:b0:6c3:75e1:9dcd with SMTP id fi28-20020a056a00399c00b006c375e19dcdmr710676pfb.18.1701775407251; Tue, 05 Dec 2023 03:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701775407; cv=none; d=google.com; s=arc-20160816; b=N2hg/W/6wZR/XxZmjx72W6fCwOmvLC16nrkfGRgd8dr1XLiZgHe7aXlhgfAkftriLP 2r4INkimuN4m6+zO8+/FDG3vrJGam7k20QBfye1cY5RHalBUYRsITrBi0EooLc9zYUt4 pVDi5Qbx0W1w4QFNXSx1NFzn1SmMloyz64yPH8uLJnm0K+FkBjwXiwdYmHByL9qTbqGC seuFwXdtNJYISsu3VMyeLjHAmIEEWmTmT5/sRpjRI6CKxNT2ubacOtec4he/vLlPrz8C pKpx6hsvSc+bylVexM/IXFSiHjwJyFcxqVhkgIKPUOsKJzF+T3RMMh6ysUQBgnvpmo55 bp2g== 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=Y0xe+ufaECrNB2PMsEx7aO4W6T+kd8sVy4ATB1RxDEo=; fh=uCCWEUVpLc/xDP/D3WvGY/BxHU9d0NQYu/T71GEsNmA=; b=BTJQVEp1dkyWmwIaXPrPuAbUpnpGjOMNFXRFXgCesN7Jj8f2tLILV+HpNKP7WvUnuM jEToi/l+/n0HxiQpyIQy/x4J+UgBK3RgsJdyUrhaCeJCVJ+PkAr/6PyJOGSh7UjP3snt APqHJjghmWgDWBoIHWpVraUMakH6n91QDVU2+84VNKL2Zm+iWbEyrjhDjJGqmAGI3jSw xIZU3PCLf4hqmPXkbCnOns2QtBgJDwZMOFDPGfSpONR96bRn8K7I7jfTm2hI59u9WBHk X7X1BT/7Tca8Zfz/94sZMRTRf/DXjIHVuBK+XLftMycexI5xcnlLUyof3jS1Oq/lCVOp 1QWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i6iNEMia; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id t2-20020a63f342000000b005b92d41764dsi9178354pgj.794.2023.12.05.03.23.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 03:23:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i6iNEMia; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E4AB580C1135; Tue, 5 Dec 2023 03:23:25 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442292AbjLELW6 (ORCPT + 99 others); Tue, 5 Dec 2023 06:22:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377010AbjLELVl (ORCPT ); Tue, 5 Dec 2023 06:21:41 -0500 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E10ED4C; Tue, 5 Dec 2023 03:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1701775297; x=1733311297; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uIZltVBi8wI2fdlt/Uk1Bni3bjv6/HHLxi0uq5CIvWc=; b=i6iNEMiaEK0spK+TcD7AUm/WImr6AQexme4vVfpnpURZ9KS+JllcbghF EPJEdVnbUuUELT4PkDH9sXmQOvLyhn0AZjc6vtKK9eFmBY03si7DEo5/o T913qVfd4L1//WaI1WxrNcZmIDbsE69WB0fiP4cVbQwkMp6pe4cMXwF/6 gn1TANM9FRil97Xl8q/GXxTosYPTll6/Ovhe1HojiBGUI3RAUUBA2XtIM KHovAw4lBsf58xYLTfYKVW/dYtxZb+raIGVobfVduaX1F2fuubPUt0eoe Ahy4OpCP1ylI+0Rj2KQf6INyQdjgP+3xhh6LdNaTgvQwwMI5pXK8g5st2 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="942693" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="942693" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Dec 2023 03:21:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10914"; a="1018193005" X-IronPort-AV: E=Sophos;i="6.04,252,1695711600"; d="scan'208";a="1018193005" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga006.fm.intel.com with ESMTP; 05 Dec 2023 03:21:25 -0800 From: Xin Li To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org, linux-hyperv@vger.kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, luto@kernel.org, pbonzini@redhat.com, seanjc@google.com, peterz@infradead.org, jgross@suse.com, ravi.v.shankar@intel.com, mhiramat@kernel.org, andrew.cooper3@citrix.com, jiangshanlai@gmail.com, nik.borisov@suse.com, shan.kang@intel.com Subject: [PATCH v13 30/35] x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual entry code Date: Tue, 5 Dec 2023 02:50:19 -0800 Message-ID: <20231205105030.8698-31-xin3.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231205105030.8698-1-xin3.li@intel.com> References: <20231205105030.8698-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE,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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 05 Dec 2023 03:23:26 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784440849523979408 X-GMAIL-MSGID: 1784440849523979408 From: "Peter Zijlstra (Intel)" PUSH_AND_CLEAR_REGS could be used besides actual entry code; in that case %rbp shouldn't be cleared (otherwise the frame pointer is destroyed) and UNWIND_HINT shouldn't be added. Signed-off-by: Peter Zijlstra (Intel) Tested-by: Shan Kang Signed-off-by: Xin Li --- arch/x86/entry/calling.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/arch/x86/entry/calling.h b/arch/x86/entry/calling.h index e59d3073e7cf..a023d9a97cd2 100644 --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -65,7 +65,7 @@ For 32-bit we have the following conventions - kernel is built with * for assembly code: */ -.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 +.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 unwind_hint=1 .if \save_ret pushq %rsi /* pt_regs->si */ movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */ @@ -87,14 +87,17 @@ For 32-bit we have the following conventions - kernel is built with pushq %r13 /* pt_regs->r13 */ pushq %r14 /* pt_regs->r14 */ pushq %r15 /* pt_regs->r15 */ + + .if \unwind_hint UNWIND_HINT_REGS + .endif .if \save_ret pushq %rsi /* return address on top of stack */ .endif .endm -.macro CLEAR_REGS +.macro CLEAR_REGS clear_bp=1 /* * Sanitize registers of values that a speculation attack might * otherwise want to exploit. The lower registers are likely clobbered @@ -109,7 +112,9 @@ For 32-bit we have the following conventions - kernel is built with xorl %r10d, %r10d /* nospec r10 */ xorl %r11d, %r11d /* nospec r11 */ xorl %ebx, %ebx /* nospec rbx */ + .if \clear_bp xorl %ebp, %ebp /* nospec rbp */ + .endif xorl %r12d, %r12d /* nospec r12 */ xorl %r13d, %r13d /* nospec r13 */ xorl %r14d, %r14d /* nospec r14 */ @@ -117,9 +122,9 @@ For 32-bit we have the following conventions - kernel is built with .endm -.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 - PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret - CLEAR_REGS +.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 clear_bp=1 unwind_hint=1 + PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret unwind_hint=\unwind_hint + CLEAR_REGS clear_bp=\clear_bp .endm .macro POP_REGS pop_rdi=1