From patchwork Sat Sep 23 09:42:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 143932 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp239807vqu; Sat, 23 Sep 2023 08:28:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVL9UyrR6XulsgeHK+MMwHX/pWr/t+rS8wtuBagTw4pwDBLHQHBHwnlTPrIDVOr7APLmH9 X-Received: by 2002:a05:6e02:1aa2:b0:34f:d39d:7a1 with SMTP id l2-20020a056e021aa200b0034fd39d07a1mr3478476ilv.6.1695482939278; Sat, 23 Sep 2023 08:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695482939; cv=none; d=google.com; s=arc-20160816; b=CMpxbJbT48UUSE7BXgkuAW3SAeyol1xx7/vP1dnO/DUESnM0Bfv1i0DCw2BO8yDuPN lhktIR7P4jGg69gpcjjpWhARQB4fCY0nvBlfvX/lsQj9VbEa5iXZLQStNjXjWPywsOWA 8jWDsv9sG43qTDa0CFfpnYppeknrKHZs7F52xT+9w7ugNCQPJj3S8I6jQHFqBbta0fCv 5qz8Ce72/WWQdRLDeDtWMg81wQPkLKTbtRZbF++P8+AjfYpCZ1PoBWYxJdu6F3301B7b qt3Q+PUuWNDcESVsCWti+Xzu+w6byj5hBu+CxaIlSEYP78PawMm/1/pWY4z4eTmy+qhO 0quQ== 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=aHGTO7Nja+CxdM5/sO7I6wEUx8hnERnyHM5oEatUCKU=; fh=Tb1p8S3iOxe/kX/WSNC3xEJzSVgGJ5DaxSrKb+pzH+4=; b=NNpgU2TCic2NxkiRq06CZnaqtBf9YW/J7DNtvfC10xni+9L/S3yjz0kqi1k61g8dTS WgVfHM5pMF52l7M+3hubFelT5g0TKMDiMQwbD2EEKxkaKRNdHNABGB1hjaOJAKxXrTWw UUYr+QdAmAcRwL8W4cSOCvBWVvl6PwPfazDTrh9/0T4zBQrvzWd2qnsVFSnzopvyOt3y KFRI8fndA6vghx6g6gzbGiXPCXs+awhHsSDgxHNjKJ2Cs5n+xZW0KZh6KtNiSjqusNZn oAnBeZuTt55XTd+tbZEjYwNNTedx3Jq/d3fNfXmUbX+1UwRNPAl+b6fs0FKA7fYDwZOH 6YEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cSgCws86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id a21-20020a63e855000000b0057e2432b366si2674575pgk.378.2023.09.23.08.28.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Sep 2023 08:28:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=cSgCws86; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 5616B81F9648; Sat, 23 Sep 2023 03:15:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbjIWKPM (ORCPT + 29 others); Sat, 23 Sep 2023 06:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231533AbjIWKO7 (ORCPT ); Sat, 23 Sep 2023 06:14:59 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE194E5D; Sat, 23 Sep 2023 03:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1695463917; x=1726999917; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/UldAmuJEnsflYS2+cyLAQ4E+J1yAKX8pToUnF0eneI=; b=cSgCws86QNPsjOO5vVLxydRsfm5uymPrqcLO/cLPHAOLmoAx1dwP2l9Y cRK1fqM3UKAxPhRwY7EfH7LC858sWA7bfExQRUyDK/OCDFeWZcg0j/G5F zDjspyIy0nyBnLjn+l2xynn+FEFmrxiCE+GutdSnUObZ4686/pgJB7Tei 5+vw520MNuKuDRykFe3HZVb6+pVNwTXJ3czCMn5TOhj+nh/Bog6zrzwja YUhhLJOaiSljHU1N9iaS1atRAa0itFA6yfKCeu4PNCLPqwtSuyuOVMp4h lvZLaTdnpI9a0Ua5QXlrqcyocZTfygd+0rFtpiygg1jgkcviRh1dRXcr7 g==; X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="447492461" X-IronPort-AV: E=Sophos;i="6.03,171,1694761200"; d="scan'208";a="447492461" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2023 03:11:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10841"; a="813388214" X-IronPort-AV: E=Sophos;i="6.03,171,1694761200"; d="scan'208";a="813388214" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga008.fm.intel.com with ESMTP; 23 Sep 2023 03:11:51 -0700 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 Subject: [PATCH v11 32/37] x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual entry code Date: Sat, 23 Sep 2023 02:42:07 -0700 Message-Id: <20230923094212.26520-33-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230923094212.26520-1-xin3.li@intel.com> References: <20230923094212.26520-1-xin3.li@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no 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: 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]); Sat, 23 Sep 2023 03:15:31 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777842718336864355 X-GMAIL-MSGID: 1777842718336864355 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 f6907627172b..eb57c023d5df 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