Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp864002rdb; Tue, 23 Jan 2024 18:49:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGVCG37fl0H/o4JbJUk7cgD9WAMkkjlCjSoWgNFmdCZcJ0GEBU65HgTa5HB/a7h+sRwDqDS X-Received: by 2002:a17:90a:a002:b0:28e:7af9:80aa with SMTP id q2-20020a17090aa00200b0028e7af980aamr749432pjp.0.1706064552537; Tue, 23 Jan 2024 18:49:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706064552; cv=pass; d=google.com; s=arc-20160816; b=Qts4FvchXl5bCRzyKgdPPRUNBgkp2iAccV+ynCR0IXfVskhAUOCW8YD5Ctftm9f05H JpDAdgJoFVeKP0y+6wbu7lwinNv5FQ93D3t5lxBUcB4fa/rJG+xn3arDQVWuF1GU/yG+ YgVUxVebwTHRKfGME570j8ouoAzMTFpbKtKX4Uh1xq57xqs+JrTPIKg5qMe6On1hdi+P 6KnLKKuZY13qbFk8e/EvDQlRRAUPVQ3+hBYmtrUJ4DZ39FLMVDyGxya9wegYsVj8dIFq AgN2iBoUoYODXPvSd5uMEkefKhlhsKPpSit1EpyihxD2yixMtq8kUyDQ6ffWLuqu+lht XXqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=rcWaR+yiGdoTGspD+NvygDz+Rk8ahPn5psAm2Get8vo=; fh=D+u40KSnYgjUYLGDRdXdD62xsMHg3nFDmpf3sEnyojA=; b=bXQCp+ISSlck9RLdiXpeaTKBPdBrlbJoo8VGWNUzajRhzd4NYfjbJ82YbUCxshUFEE AgShSYMKo8drG27XYCqL/l/pk/XDUaU+ljRoFh5/IMrENVdn5GIO/jMcYSIeV4lFN7sg 0OXnRNqglBYmxxZH4GF85/90vuOJO1f1YRX0xXY2kLIeHl5CnDV/p1Shi/CzVkEI3IC2 bZhPhVVLWsAaEzNPyqUyWgmZCAgNM65clynrRAiIHQpqIsoKS6oRWoCqHLRWzVGhbYEP pWFXtYhrd+vc+YXWzKNc6BZzr4/1iVnkm177Jvbj9lSVnNQ0jsTbR8Wck8s4va01bLco pVqg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jt25OZLY; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36337-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q18-20020a17090aa01200b0028caf24a3cbsi4011863pjp.100.2024.01.23.18.49.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 18:49:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=jt25OZLY; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-36337-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36337-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D51FA28D6C2 for ; Wed, 24 Jan 2024 02:48:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 16ED618651; Wed, 24 Jan 2024 02:42:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="jt25OZLY" Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76F0C17BA3; Wed, 24 Jan 2024 02:42:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.55.52.120 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064165; cv=none; b=n7k27sgtNiUf0JXz9QcepDjvRMNpmoW8+2MGuZgTSLs75nvddF+qxlrEBeqPOPl/pQDuEvw0VvfRRLUSFLcVPSwBHdPW/eYf809LlND3ZPoKykIvYOjkdZgx9TH8Ir8jtArda2y/nXu7t6IiGLuOHt4lNGlbPT3dNvUk+l9bgNI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706064165; c=relaxed/simple; bh=ky/X9OZtJn3bDUIMsiZj6Q/CKpBiasfn5wmoF4H7EIQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XRsRUCZW0z6RfaiVDKVls62MmasF9gnz7Fzl22/tp6qlsQb69szWOJSLt7yXexHAJMRig4GSc+rPa6bPITgm3ZJoennBch12rvf94zqiMy8gN2kGrsjfa+mIWzfk/Ghvm+lLv5c4IpCk0P+TYcqkRL1ReaAhzUkLYjmcj103Xo0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=jt25OZLY; arc=none smtp.client-ip=192.55.52.120 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706064163; x=1737600163; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ky/X9OZtJn3bDUIMsiZj6Q/CKpBiasfn5wmoF4H7EIQ=; b=jt25OZLYS7LpZOu5zHqGSROrwMt/7ISLhFBLOB9hapQwFZFSrylUm+Gt b/jswxurHGf7uUEfbg6FPArDWW1jzBr3RkCHK5of4Bm8SEAxaPWmj6FLC 0uFHUpc/8uwIH6gLtCmvjHahBwXpaMa9g0OunD0RxO9bxgd0TYMQjd3lD o5Kw99Ci0kXhso6DQfNduh6jTmlZOmS3+NJoGY1WeWQ/1YHWyuZk9u6rW E6+4OsUfax8enofYiXXbrKGpMUUb7odN3Vk4tRW3YiCybc9vLi0wEQa2a 7bVqyvlD/XW0f3BQa/kdMzOQvVn7uK0gbPVGfAVkjCPbgECYUvtoUIrsr g==; X-IronPort-AV: E=McAfee;i="6600,9927,10962"; a="400586525" X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="400586525" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:39 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,215,1701158400"; d="scan'208";a="1825885" Received: from 984fee00a5ca.jf.intel.com ([10.165.9.183]) by fmviesa003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Jan 2024 18:42:39 -0800 From: Yang Weijiang To: seanjc@google.com, pbonzini@redhat.com, dave.hansen@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, x86@kernel.org, yuan.yao@linux.intel.com 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 v9 16/27] KVM: x86: Add fault checks for guest CR4.CET setting Date: Tue, 23 Jan 2024 18:41:49 -0800 Message-Id: <20240124024200.102792-17-weijiang.yang@intel.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240124024200.102792-1-weijiang.yang@intel.com> References: <20240124024200.102792-1-weijiang.yang@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 bde780ae69bf..b418e4f5277b 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.39.3