From patchwork Tue Oct 3 06:24:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Xin3" X-Patchwork-Id: 147677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1899960vqb; Mon, 2 Oct 2023 23:59:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHALv1ge5/fd1e/hYLSkdc3SIRJ/XLUWhbkgE2CH4VjduHhwhRaGBScFdED26rEIYVRpSSB X-Received: by 2002:a17:90a:2ac2:b0:271:ae4f:dd12 with SMTP id i2-20020a17090a2ac200b00271ae4fdd12mr11052164pjg.26.1696316344105; Mon, 02 Oct 2023 23:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696316344; cv=none; d=google.com; s=arc-20160816; b=Fuc4ytApWCg49ac8VyCmJyumLU9T2Yzsv5YEMH4Q7bC4HgPVGT6l4YNNjJxulRFJg7 SAn4ASwBXMSdwGKC43X61+JVBboP3shnMDf0tpqIc0UbvJtYer243MTnsCq98f4JeYoe 9+Y5gqcv3rqGiskeY20U6IMh0+H04HJ6hsetT8+uklNNrerF5dMnBZ6J0HnkCjwBZdHD /GgVEQ3xZqyOcPhbLoAe59RDWae1i4Idm0aJ2QdivH4vSRHlFWMABNuFqbfKMvDwYbyH ZulRJtRgfde/nqdMHUf5L9SGqX2+mqhvQCsFLKwZz9J5fD9V/eDKTalTsfmewHNbmdXs LIGw== 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 Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id np16-20020a17090b4c5000b002749baa2edesi10469527pjb.24.2023.10.02.23.59.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 23:59:04 -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 4B43781393FB; Mon, 2 Oct 2023 23:59:03 -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 S230462AbjJCG6y (ORCPT + 18 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 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:03 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778716606761511012 X-GMAIL-MSGID: 1778716606761511012 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