Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp894467rdh; Fri, 24 Nov 2023 00:00:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbjKqI6E5zIAfdUiD5pjqCllba17C1BlPbzxuREQEnLXJG321t6FZ3I2lIYl8EJzHGgGLF X-Received: by 2002:a17:90b:3e85:b0:280:29d0:2c6e with SMTP id rj5-20020a17090b3e8500b0028029d02c6emr2162607pjb.11.1700812850648; Fri, 24 Nov 2023 00:00:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700812850; cv=none; d=google.com; s=arc-20160816; b=f4XhxwXE6eALC1EPDOuMyLFsWQkUdpBeQifXxmkbPioEIbPdLw8UzUoaBrrEEtka8m o0qmCo5pNwSsG5/jwBTao/EMk41BnvQpzAT43BkkPBpW4I62F9hrfI0JeiwqELSJsT1F jiQoLj13g8wJH3FeVqxluVM4vndJANLccl7QQrXEp22Eubdh9EkwDN97LUx+FnAB6uLE RHz4x5C57w/bW0DPJ/zIisKg+CVCZIBaWJpp0FdMp+EpFgyyuA9NllO/i1zemXtsbSTm IG5Y9Gr1oR9vFpC53EJBDsS21faAgB1JE0k+XBaEj+YMPVfaKWhkrwdIRNY2S2V3aSZa uLSw== 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=3vmvEVAQ5wTL+a2pWk2uma+6N+w8F92ijt2tlpaaFXQ=; fh=uy0EBGgYIm8+MgsxUvKHUXUo3s9z4H9hdLwRv8YoeJU=; b=cSirm1bvxgGJJFHjH1wfcJL4KP+VNxPRB41BK80nGBGh7qbPfWQKwDcIU8g6Dnb3oc wo2P965VakcaaO2egIfVcaFaxsqltqc21gbc9vuqqhwTnq5QPHxka8rr8M8Q0FRXOGIF 432nwHm17uT5wUUWdp3IrnnrKgILsrSiKPhmzZIRR33pQ230FGiaaov4VvBP584bBJQc jc/uGg77pEABDcrwRKDhYXwq/KDdYd9v9ijy77jhX1zLLE6m0cV8hG4SeC6//vC445g2 x0+hDryUUt8RCKlZ8Kxqyv7gi/Bhsf9PIPUGxjCPdTsJS58SPw9w09I/+iZjk4isG6jv WB1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q728Bu+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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. [23.128.96.34]) by mx.google.com with ESMTPS id qe15-20020a17090b4f8f00b002832041e149si3825093pjb.167.2023.11.24.00.00.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Nov 2023 00:00:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Q728Bu+Q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 BD64380A97CE; Fri, 24 Nov 2023 00:00:40 -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 S232995AbjKXIAA (ORCPT + 99 others); Fri, 24 Nov 2023 03:00:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232787AbjKXH6k (ORCPT ); Fri, 24 Nov 2023 02:58:40 -0500 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A4471726; 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=PcMmXeXNunX7/wx8POI7uKkie1le/Rqx/XX/i5AXSyA=; b=Q728Bu+QB2pjWo6F+y1CicQRtv6O0DRmL6DqjY0HKKHSgitxZcjkQR2q GgklIvIm7sQU5UaCuHmR3xsi5bvfjxkwQ+8xvNUL7AbYZ7QKldqK61SR1 tWARLATJr6qosWQA7xwnD/e7oqp5DJW9C0bKmZmFivmGdOPG1+iP+Pph/ 4BVrBf6XVAJRn8TN3SwHTSEqBaFZEVvgsBKhV5L5LyoDAFCd2PlxWOAMM kIjJxDcCzICUywQU9O3ncYXg3GRyH2b9GiUhRkOrFKDvm2u6OoLe+PQZ2 nOTZx3usS6w7VLGielY0WTROY4v97HfT0RFHSKrPzJ52oj8CcY+cZHzGe Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10902"; a="458872363" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="458872363" 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="833629840" X-IronPort-AV: E=Sophos;i="6.04,223,1695711600"; d="scan'208";a="833629840" 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:40 -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 Subject: [PATCH v7 16/26] KVM: x86: Add fault checks for guest CR4.CET setting Date: Fri, 24 Nov 2023 00:53:20 -0500 Message-Id: <20231124055330.138870-17-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:41 -0800 (PST) Check potential faults for CR4.CET setting per Intel SDM requirements. CET can be enabled if and only if CR0.WP == 1, i.e. setting CR4.CET == 1 faults if CR0.WP == 0 and setting CR0.WP == 0 fails if CR4.CET == 1. Co-developed-by: Sean Christopherson Signed-off-by: Sean Christopherson Signed-off-by: Yang Weijiang Reviewed-by: Chao Gao Reviewed-by: Maxim Levitsky --- arch/x86/kvm/x86.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index fd48b825510c..44b8cf459dfc 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -1006,6 +1006,9 @@ int kvm_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0) (is_64_bit_mode(vcpu) || kvm_is_cr4_bit_set(vcpu, X86_CR4_PCIDE))) return 1; + if (!(cr0 & X86_CR0_WP) && kvm_is_cr4_bit_set(vcpu, X86_CR4_CET)) + return 1; + static_call(kvm_x86_set_cr0)(vcpu, cr0); kvm_post_set_cr0(vcpu, old_cr0, cr0); @@ -1217,6 +1220,9 @@ int kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4) return 1; } + if ((cr4 & X86_CR4_CET) && !kvm_is_cr0_bit_set(vcpu, X86_CR0_WP)) + return 1; + static_call(kvm_x86_set_cr4)(vcpu, cr4); kvm_post_set_cr4(vcpu, old_cr4, cr4); -- 2.27.0