Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3839730rdb; Thu, 14 Sep 2023 04:31:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGe9Jh/VLxbW6/XAZ5lFowpXIA4ChuUwBZtKjN1iSDl7LY3h+fb3DibTMzEXR/UBAHnmHXY X-Received: by 2002:a05:6e02:1062:b0:349:36e1:10fb with SMTP id q2-20020a056e02106200b0034936e110fbmr4598816ilj.18.1694691092532; Thu, 14 Sep 2023 04:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694691092; cv=none; d=google.com; s=arc-20160816; b=UhtfvXLk5u7fcDcWI75jaeclae9GxgVuFECEeItrfrOlqUxxMH+lg7BXuX7D9+9I/a ItUDS+YA7V6hHQg/KtL6hbNSKDf11/ACxHVFJ7sj9KTuAXiLQZ2q0Y4U07EHkMfRQoY2 5v06HUT3fitJWxMc4niyG21mXChCv/Pc9LScJBe1PV1ttkckGd7shxP19fxIPW9RaWHQ 36xiE0RiKoroysk2+tElKjC/QBcb1Ga5EkwfrHzES8juYzg/g+Lp0ztkD8yM1tC4YfZ/ +n2Js0GqQn4hugYR3iQQpq0Jfk800FDQ6MnkiINbtyZs/VRKc//McISam7lsa4lGhh3L V/4g== 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=jqCbnajAXgJ+s7A1aA7DOHJD13/+EpD442pw8d+Ofss=; b=d5HhSZSoE8OsHo8II3Wo7WFzO/Omk6fiw0845GYDDKW6JOjmo2NmizwcF2fFlKIJOg v7KHmwe4J7RO6kfPs8FGX2TI9RXCEO+l/mI7TdtuLGm94AgsdiEsyKo5HML5jsVNiaA6 A/KeH8eYoKfTR1UwWJyUVvcWSxHdgoljtytr4//yZU7EqJbCOA+B4AlYqoXp7ZnVwv2h FffPyUc51kF3wbL+SiVTF/JUAwo3LGGrL2k3MEAq1JI6KsvUnXWk/CKiKxtej6O8horK nEtHp7lCbbakPy7wJPYHcO7kDMUq1rlcQZavQ5ChVh7UapBr1aDNKF9+6LzYoUfawagH VVeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TaqSvYNn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id cn15-20020a056a00340f00b0068fce6a86acsi1409056pfb.121.2023.09.14.04.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 04:31:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TaqSvYNn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id B858E806533F; Wed, 13 Sep 2023 22:21:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235856AbjINFUz (ORCPT + 99 others); Thu, 14 Sep 2023 01:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235541AbjINFT4 (ORCPT ); Thu, 14 Sep 2023 01:19:56 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 734BE1BDC; Wed, 13 Sep 2023 22:19:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694668765; x=1726204765; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/UldAmuJEnsflYS2+cyLAQ4E+J1yAKX8pToUnF0eneI=; b=TaqSvYNn4Heg6xWEoZQghBw7imXmV6uvN9jLDbnvrSAS14kGbc0sl49L wzusu0pNQ5pWIKbeqsLuG+wyoL5lTPdtuYXkn+mxtbRAhPHH6aU8F5wdE mp25g8eVOe0QYfKWmARmCrQ35ROiX977LaD8CsY9tZLGsAH/xPpQi/jhP NW94FQP2kM9F6EnKUVvLjHV2KIUVby3DOcjLLy82wyP8cKqiLokW7Bky7 g5hj12MCJIW9o5+yS7WCJ30ptwLJFmq9B7d3UniULqUTs1YZ3yGe1tCVL LUXVzwxOepASpAi4Z72pZOuEHIw2cBQJd8AEKICHCkYjppVjK+A9+40Mj w==; X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="382661484" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="382661484" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Sep 2023 22:17:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10832"; a="779488835" X-IronPort-AV: E=Sophos;i="6.02,145,1688454000"; d="scan'208";a="779488835" Received: from unknown (HELO fred..) ([172.25.112.68]) by orsmga001.jf.intel.com with ESMTP; 13 Sep 2023 22:17:45 -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 Subject: [PATCH v10 32/38] x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual entry code Date: Wed, 13 Sep 2023 21:47:59 -0700 Message-Id: <20230914044805.301390-33-xin3.li@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230914044805.301390-1-xin3.li@intel.com> References: <20230914044805.301390-1-xin3.li@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 22:21:49 -0700 (PDT) X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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