Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp894569rdh; Fri, 24 Nov 2023 00:00:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6B4uhmCY0mJutrzYhkjPLokoDxofNSLuRcsmUa2lsEMdUmaVy561qQ3+4Z7/QoiW89ZMr X-Received: by 2002:a05:6808:238f:b0:3ae:1298:257a with SMTP id bp15-20020a056808238f00b003ae1298257amr2532765oib.1.1700812858461; Fri, 24 Nov 2023 00:00:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812858; cv=none; d=google.com; s=arc-20160816; b=FI3EwwmUufPsfphXhDn4PAHrBaM7sB2P1NCQpsGzUnHIhc6Coyf7Fp3pk/5snrxl9C fWO8Xk+dj+ECkZdk9QU/5Xl9Fp982nFis93+AM0/AS/hrnVwxqBohqijJBK4yFHhBXkU SkA7IO0ZL+1iYqG1qEq1mbtLd81BAE0X8kYiJUNEXXZ/iJxrhEw1tICyEoLNYmIAxmPi 01eJbpAqGFROm0uYql1YG2cNur/gBnKDTZTnHF2wYHOXv0HuwhBWVCjRvD9XJf30HaY+ PqrtVYxAzvgXiJs+OOtHkhZGqaf++oQGmN/dBIFH62K5l4KOoGM50OdbhGzIOu+2CIiA W1HQ== 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=Yr+oq5r/xRmeXqyJ/6TeihH1xSFT3OB3mmr8/kWQ2Ng=; fh=GH5waOuli6h9Set3ggYc/VU0NXbCWcgfIqnPtXKiONQ=; b=VyJOhtBz0ESprnsKjucJS1m37jisD7qwhawD9yBp/Gv/m4TZY7E8Fp/aOKaHw7lmsE jPxgXGzPQWI43Lc5ty9UasoH5C+PvFczYzHGbagEABRNW35tFYcRoiL0YSSFIEHFdf+y 2EiP9sgbgdlTh1OIDaWedlG+nOsQ5jRbn/vcSS4j1lwz4IG0i5mtK1cuoqjIgqWovw8e xpJhg+2DHOyh3HxeZMNO4ttr1R/TRG9Esji8LT5FlwQIYCiAR/u2dBnypzvMbJj1H7Y3 vy9BPMui14ZSjGFunwttJVrAJ6I4HDwgoPRck28OJ5Awpfej9gM1RutrydV1h2K6BxxC W4Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kBQSqUbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ay37-20020a056808302500b003adcb764425si1156324oib.13.2023.11.24.00.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:00:58 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=kBQSqUbk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id CF66D80A97B5; Fri, 24 Nov 2023 00:00:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232524AbjKXIAP (ORCPT + 99 others); Fri, 24 Nov 2023 03:00:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230245AbjKXH6l (ORCPT ); Fri, 24 Nov 2023 02:58:41 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 805891728; Thu, 23 Nov 2023 23:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700812727; x=1732348727; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7pXFvzIlPBv7YsxlB7MipwWfzAjim4sbbyjzoKX1zCo=; b=kBQSqUbkTsUvH4YyWu1ntAsVTcBNXlEnq4vj712ywpqQAmfESayO+mho t1G4x+3bLFimSt1gQGXEfuYT+/rJTyI5wMDnAkco7bmISpOf9KVp76Hox EjXtfN7INVDIdXkP/Qc5bv+syOIv4n+IXwy4mMc9ROxKKepFL9m+KFq0n Sy0Qh6+r5eUcn2WiSxh01N6cfqR+xFR4dmdxe19xLV1zuCttfh3fsObz7 tnXuMsCPMhWUb/+pHvANMuhcj+ZZbMXeIoMubl75wJtP6gOaTcJsCDSsD pQRhGKe30bUHYf16Pv8PUlrmH70XYmJ6/IpTrC2SqVZEsyB1VyMz/2p2a g==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872370" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872370" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:41 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="833629846" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629846" Received: from unknown (HELO embargo.jf.intel.com) ([10.165.9.183]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2023 23:58:41 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, mlevitsk@redhat.com, john.allen@amd.com, weijiang.yang@intel.com, Zhang Yi Z Subject: [PATCH v7 18/26] KVM: VMX: Introduce CET VMCS fields and control bits Date: Fri, 24 Nov 2023 00:53:22 -0500 Message-Id: <20231124055330.138870-19-weijiang.yang@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20231124055330.138870-1-weijiang.yang@intel.com> References: <20231124055330.138870-1-weijiang.yang@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Fri, 24 Nov 2023 00:00:50 -0800 (PST) Control-flow Enforcement Technology (CET) is a kind of CPU feature used to prevent Return/CALL/Jump-Oriented Programming (ROP/COP/JOP) attacks. It provides two sub-features(SHSTK,IBT) to defend against ROP/COP/JOP style control-flow subversion attacks. Shadow Stack (SHSTK): A shadow stack is a second stack used exclusively for control transfer operations. The shadow stack is separate from the data/normal stack and can be enabled individually in user and kernel mode. When shadow stack is enabled, CALL pushes the return address on both the data and shadow stack. RET pops the return address from both stacks and compares them. If the return addresses from the two stacks do not match, the processor generates a #CP. Indirect Branch Tracking (IBT): IBT introduces instruction(ENDBRANCH)to mark valid target addresses of indirect branches (CALL, JMP etc...). If an indirect branch is executed and the next instruction is _not_ an ENDBRANCH, the processor generates a #CP. These instruction behaves as a NOP on platforms that have no CET. Several new CET MSRs are defined to support CET: MSR_IA32_{U,S}_CET: CET settings for {user,supervisor} CET respectively. MSR_IA32_PL{0,1,2,3}_SSP: SHSTK pointer linear address for CPL{0,1,2,3}. MSR_IA32_INT_SSP_TAB: Linear address of SHSTK pointer table, whose entry is indexed by IST of interrupt gate desc. Two XSAVES state bits are introduced for CET: IA32_XSS:[bit 11]: Control saving/restoring user mode CET states IA32_XSS:[bit 12]: Control saving/restoring supervisor mode CET states. Six VMCS fields are introduced for CET: {HOST,GUEST}_S_CET: Stores CET settings for kernel mode. {HOST,GUEST}_SSP: Stores current active SSP. {HOST,GUEST}_INTR_SSP_TABLE: Stores current active MSR_IA32_INT_SSP_TAB. On Intel platforms, two additional bits are defined in VM_EXIT and VM_ENTRY control fields: If VM_EXIT_LOAD_CET_STATE = 1, host CET states are loaded from following VMCS fields at VM-Exit: HOST_S_CET HOST_SSP HOST_INTR_SSP_TABLE If VM_ENTRY_LOAD_CET_STATE = 1, guest CET states are loaded from following VMCS fields at VM-Entry: GUEST_S_CET GUEST_SSP GUEST_INTR_SSP_TABLE Co-developed-by: Zhang Yi Z Signed-off-by: Zhang Yi Z Signed-off-by: Yang Weijiang Reviewed-by: Chao Gao Reviewed-by: Maxim Levitsky --- arch/x86/include/asm/vmx.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/include/asm/vmx.h b/arch/x86/include/asm/vmx.h index 0e73616b82f3..451fd4f4fedc 100644 --- a/arch/x86/include/asm/vmx.h +++ b/arch/x86/include/asm/vmx.h @@ -104,6 +104,7 @@ #define VM_EXIT_CLEAR_BNDCFGS 0x00800000 #define VM_EXIT_PT_CONCEAL_PIP 0x01000000 #define VM_EXIT_CLEAR_IA32_RTIT_CTL 0x02000000 +#define VM_EXIT_LOAD_CET_STATE 0x10000000 #define VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR 0x00036dff @@ -117,6 +118,7 @@ #define VM_ENTRY_LOAD_BNDCFGS 0x00010000 #define VM_ENTRY_PT_CONCEAL_PIP 0x00020000 #define VM_ENTRY_LOAD_IA32_RTIT_CTL 0x00040000 +#define VM_ENTRY_LOAD_CET_STATE 0x00100000 #define VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR 0x000011ff @@ -345,6 +347,9 @@ enum vmcs_field { GUEST_PENDING_DBG_EXCEPTIONS = 0x00006822, GUEST_SYSENTER_ESP = 0x00006824, GUEST_SYSENTER_EIP = 0x00006826, + GUEST_S_CET = 0x00006828, + GUEST_SSP = 0x0000682a, + GUEST_INTR_SSP_TABLE = 0x0000682c, HOST_CR0 = 0x00006c00, HOST_CR3 = 0x00006c02, HOST_CR4 = 0x00006c04, @@ -357,6 +362,9 @@ enum vmcs_field { HOST_IA32_SYSENTER_EIP = 0x00006c12, HOST_RSP = 0x00006c14, HOST_RIP = 0x00006c16, + HOST_S_CET = 0x00006c18, + HOST_SSP = 0x00006c1a, + HOST_INTR_SSP_TABLE = 0x00006c1c }; /* -- 2.27.0