Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1777597rdb; Mon, 2 Oct 2023 23:59:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG1pLDD5IKrVpiAxEaDemipMB1eJB2EHcQczduU8b1Xzey5yslOMIBrHRGd1N+W+SnjL5tJ X-Received: by 2002:a17:902:f54c:b0:1c7:2476:c977 with SMTP id h12-20020a170902f54c00b001c72476c977mr12939617plf.33.1696316342069; Mon, 02 Oct 2023 23:59:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696316342; cv=none; d=google.com; s=arc-20160816; b=PE+7vPK2FxYwzAynG/i1UfDAtJBjrO2kSZ0GMkUewT/s54ctDhTc0bov5Kd4TCSaHF TrWuWuwVLdOaCZIZf87yKZbLGd4m37vNtRkSCgQGhO53/yRk2yQfEAPCqPAkAJN4TozA gsQ1jBwLYLuBwUFCkEL6zzmqWM+tZLl6zIuHj9GPX0OrXrjoGu7bG+iA37nSld8TM4Gj MPjRfBsbhJoFSlcpT1Nzvxh+eQoCO8aKwkzVC4ILaHPCq7u060m11Qy5N6MG3pe1fupF N2doViC8Novs69zhoYJDdcPu36U9Z9wQiiPey0fzcdE8e2qYCDcqHTlxfKs+/x07wLdA XVXw== 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=J3u3ifolzO1ZtOmgoqugAejfCdW11U3/wUSOn18OoWqLYOlOtHkW0QGYLlch+vUBbh 8BMz7WNiir6rDx92ZHaJMnEZ1wJZfHNN1cCtMjkVaHxZeb37suD7Dkm6KZ2CrFYtR/M5 pVUqnL7iXPxs6QnwvzK6z1FBSFE3JEd6exhanuqnmM9T7ptLSLFItu7XsejQ4kw1R+LM 2869ka4C2J4utfmwOYzdNIRivEKWHAAOVxbkM6wdyF4aS2kPnD5QFA7TQjJTlj9XSrfV BGs4hKHa9SnYwLIzDJhUprpy3FZbinEWX4JNTYZBlM0Kb9e9Mr3Ct1pPRTOxe0siXyYw PPxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=mzyYokYv; 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 Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l8-20020a170902f68800b001c60ee79b6esi897393plg.0.2023.10.02.23.59.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:59:02 -0700 (PDT) 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=mzyYokYv; 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 2F3AC81393DA; Mon, 2 Oct 2023 23:59:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239597AbjJCG6y (ORCPT + 99 others); Tue, 3 Oct 2023 02:58:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239187AbjJCG6h (ORCPT ); Tue, 3 Oct 2023 02:58:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.126]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8A312721; Mon, 2 Oct 2023 23:55:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696316147; x=1727852147; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/UldAmuJEnsflYS2+cyLAQ4E+J1yAKX8pToUnF0eneI=; b=mzyYokYvPpfU+XH4AQorFYfpIEOHM6rXxgiUlcxEAn6yqCRrt6yzMoLC M3gdwzho3vwZmBLsB1rjHq723tRSgYDK6lRZuQQU+TCiR50g7EQKF4avt 6oEixQ3Sc/55SioaPfoDKUmadMddzGVrxu8GDzUgYOHuEGPFqZPnnkYBg b+ALdUhPF1V51fxjRl94kYODRKDwhqHzg79olq7MYwJwFAf0BzpvTSv7A txmFEnLYXPNQTfrGYwjlynqoMHfU6T9jvRA59YvxLjFqUgEVhgfuIM+KS ie5Nk2c1o5rq3ilIu5yskAYXjcbOXnretxnsBPr9WlwNJ3FwCAHd/KIvz Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="367858304" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="367858304" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 23:54:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10851"; a="1081901004" X-IronPort-AV: E=Sophos;i="6.03,196,1694761200"; d="scan'208";a="1081901004" Received: from unknown (HELO fred..) ([172.25.112.68]) by fmsmga005.fm.intel.com with ESMTP; 02 Oct 2023 23:54:50 -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 v12 32/37] x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual entry code Date: Mon, 2 Oct 2023 23:24:53 -0700 Message-Id: <20231003062458.23552-33-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231003062458.23552-1-xin3.li@intel.com> References: <20231003062458.23552-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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]); Mon, 02 Oct 2023 23:59:01 -0700 (PDT) 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 -- 2.34.1