Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp24014lqq; Wed, 12 Jun 2024 15:14:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUNWZkO9egdC5HVk1qw7OpQ454gJT1k8NR38AQrCzCKIPiKBv4x5BcgI9+aLH/cnDb4Iv6saeca4R/yeRsORjCL4d2zcmQCWm9Q8ydfHA== X-Google-Smtp-Source: AGHT+IH5QLEqGCUcgrhQei9SDSP8rMFtRZjpgfYnm06QlF5btCvMqaAfdIxWURf4e7/kmBArUNkz X-Received: by 2002:a17:902:e811:b0:1f3:f5c:cd80 with SMTP id d9443c01a7336-1f83b5660d1mr36216535ad.5.1718230451110; Wed, 12 Jun 2024 15:14:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718230451; cv=pass; d=google.com; s=arc-20160816; b=ZL3ft7+E0qUqNIMzh/kCzOVa9gjh5UuaACtIW5pWUC/i/YJXpHJ+u1QOBTQwGoMjOM sYCUBheiW9htY7xlNlej48Bp13T9YIhrk7q1cDMkQEErMXxeaanVRdRxblvYP+dmH2T9 W8++R/576DXg33h4jv/DSz/AabBB3IJtEkA4O9MEQwVka/92cVpXycYkzlxFjKWI2iYH 9N0n7FKwoULfFEiTtTap46pA18+4tUuV2MbQAbxLaWROoE9o2ZI5NjDHIx5r4kKhtNkR PCUVqk433mulnyynacZUxlKq1hY0zY/OIWc7Fg3wN0uwecVfs/D5S3jRzdZzhwxVyUw7 WrrQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=bPX3/Z0GWf3goqQnQ+80IAoevnNEBGSkkJOiBvmG4jY=; fh=uzCrZMsEnMDs/MfHVUnv96LpYzP7XoyfHkNMvKnZn4s=; b=eDNAHeWHA7rliQel3m+bPJsJa/zmiVQfZ6QIINBGHIcwXnHOUkwNbjX9ngeTADBY1f rL3ysrWBjAOZ5bgXp6iHbSGwG2wPlGVVBdnBSW3BvFzUtSN1bngnZ0rKUVxVWnu/qPvp 6SdpIP2e3TJ94ElzE2C93H4q2JDCf63VxlLSI56VdizXo+BhiioHuM4Niiyu/Db2Xz13 Cc//CacviAhoHWvy+YGYl9TNVTrxKLw0qYx7vpVQQXXYlYul3V4xgReCc5V88NpFCMRh /imC7VcMwrszp69L792vr+EkBvyYOYfVuU+8DsRgpCa13M3gifbWXMFYUFPuBHPphK4L 065w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="s//GaH7E"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 d9443c01a7336-1f6bd7d5086si86720905ad.222.2024.06.12.15.14.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 15:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212309-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=@google.com header.s=20230601 header.b="s//GaH7E"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212309-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212309-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 B609D283F16 for ; Wed, 12 Jun 2024 22:14:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1A9C212C46B; Wed, 12 Jun 2024 22:13:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s//GaH7E" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1392F1272A3 for ; Wed, 12 Jun 2024 22:13:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718230437; cv=none; b=YCIS5z2ARHZuy936fiVhkIYqrhoHZQfNzmgYZw1IQQqKvFg6GQwClxoe6Sdii5EsEN8VDkOk1f9iGjDyyXoxzr+fl+SQPqmQcrRmD8C2y0X1SQ5O6XGNUVsRYitTDHFPkv0hGuNeubYsuAm9nWoVncxfMbNyEWUn+rv+qRdJ3xs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718230437; c=relaxed/simple; bh=GwfBCcHjkevNkWnlhNs7s7LtsNgX3NNWwh13LjsHl2k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=bgKdr0Sp+6xeFQNf+RDoVzsIwoYKeJooL1BsoSAwsz/97hH5rZ8Clq781FJBN0V53glleP36cSasWj3QMG/MhjcTL2mTxsnzDDrKB703aUJzlqlRjSqmaTC3cREuQlUyPKnh2yw3MAv/KMAJHA5Gdk6DBBVZz/+W4O3AYyoQiTY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=s//GaH7E; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfeff1ae480so603905276.2 for ; Wed, 12 Jun 2024 15:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718230434; x=1718835234; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bPX3/Z0GWf3goqQnQ+80IAoevnNEBGSkkJOiBvmG4jY=; b=s//GaH7EOLTmaXUl1rmYJN1rO/2MMS3WFL/FmLQy72muCUwpBXJdkimk4Zp+zGmG56 Gad94F4y7yknfrh9EMlah0PXnZfI0yM4yiuEWqCOkvDQkuQsqz7YmRxMB7kG2hpSiTW5 k/5rQYS36eV21ARWug4Xl8y5srpiuW9U3KmaFWunNhB6PQwPswRGB11cwmucIx9Czx4+ +mNaGCiLxeqkHE6yqosioiE0B9T6M4WWaubTjRMNbuymK5tR2G0BE+x/4DDcjGMgwDJT 8P23GTan20gqVn7DbXDn4b2mJGh//PkuDWLHI164cWS5qr+fsYCs+hcAi62efO4tWfMK FfWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718230434; x=1718835234; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bPX3/Z0GWf3goqQnQ+80IAoevnNEBGSkkJOiBvmG4jY=; b=GUcM/GZDcE1nLoKy/ayZ+68iZ5WbLi8n1Aa3aSmc0aoAtdPWSYCLDQIFKP/ziRKFXh EtpVf3NS0QIIXthLJcwqNc0rvGsKhBjr2eUEvSFJ42Um03Ihx1IYdbMZFxdmynYcezGZ uzvYupAMkEVnkcAD6PnyXc6LXU0VC5R8LdZfSlHqYOgRL8J/ODXD/40eNdqmBnpIOTqw +Sh119GjuY5DaX4IPRLlLhHDkrO+H5+WS28gHa8oHjVBqqzmUjATffYLbhSBZBfYjPcX VWHtfOeps/WLNss/dBbXdaqJZsbGfCA8XsFmFsprO3hiThSeE2SGn7SKUhAYgdEqr8QZ gq5w== X-Gm-Message-State: AOJu0YxUXtEJIVH28T1pFf6tnh3ekC3r2IGN3seE+3MFOLrR/pe/rM/A GzQe992wnZAvtfZC4p5GS8u+zUZ3uI8MrcaVrKVUROXSojmPhDz3DAKfuAB0S29UDzSOjIwUztO Rcw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:150f:b0:de5:2694:45ba with SMTP id 3f1490d57ef6-dfe62d1ee23mr813079276.0.1718230434092; Wed, 12 Jun 2024 15:13:54 -0700 (PDT) Date: Wed, 12 Jun 2024 15:13:52 -0700 In-Reply-To: <20240207172646.3981-12-xin3.li@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240207172646.3981-1-xin3.li@intel.com> <20240207172646.3981-12-xin3.li@intel.com> Message-ID: Subject: Re: [PATCH v2 11/25] KVM: x86: Add kvm_is_fred_enabled() From: Sean Christopherson To: Xin Li Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, pbonzini@redhat.com, corbet@lwn.net, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, shuah@kernel.org, vkuznets@redhat.com, peterz@infradead.org, ravi.v.shankar@intel.com, xin@zytor.com Content-Type: text/plain; charset="us-ascii" On Wed, Feb 07, 2024, Xin Li wrote: > Add kvm_is_fred_enabled() to get if FRED is enabled on a vCPU. > > Signed-off-by: Xin Li > Tested-by: Shan Kang > --- > > Change since v1: > * Explain why it is ok to only check CR4.FRED (Chao Gao). > --- > arch/x86/kvm/kvm_cache_regs.h | 17 +++++++++++++++++ > 1 file changed, 17 insertions(+) > > diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h > index 75eae9c4998a..1d431c703fdf 100644 > --- a/arch/x86/kvm/kvm_cache_regs.h > +++ b/arch/x86/kvm/kvm_cache_regs.h > @@ -187,6 +187,23 @@ static __always_inline bool kvm_is_cr4_bit_set(struct kvm_vcpu *vcpu, > return !!kvm_read_cr4_bits(vcpu, cr4_bit); > } > > +/* > + * It's enough to check just CR4.FRED (X86_CR4_FRED) to tell if > + * a vCPU is running with FRED enabled, because: > + * 1) CR4.FRED can be set to 1 only _after_ IA32_EFER.LMA = 1. > + * 2) To leave IA-32e mode, CR4.FRED must be cleared first. > + * > + * More details at FRED Spec 6.0 Section 4.2 Enabling in CR4. > + */ > +static __always_inline bool kvm_is_fred_enabled(struct kvm_vcpu *vcpu) Maybe just is_fred_enabled(), or even just is_fred()? Most helpers in x86.h that wrap CR4/CR0 in similar ways omit the "kvm_", partly for brevity, but also because the check is architectural, not KVM-defined (though the state obviously comes from KVM). > +{ > +#ifdef CONFIG_X86_64 > + return kvm_is_cr4_bit_set(vcpu, X86_CR4_FRED); > +#else > + return false; > +#endif > +} > + > static inline ulong kvm_read_cr3(struct kvm_vcpu *vcpu) > { > if (!kvm_register_is_available(vcpu, VCPU_EXREG_CR3)) > -- > 2.43.0 >