From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 398DC3396F8 for ; Wed, 21 Jan 2026 20:24:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769027081; cv=none; b=sUD5+E2fPQpEWf78HH8Y8XGfjFcDm1Du/wsEVTh6R6eYU33aT9bW6kWavrT/mgTvUULspSs8aa/J/aryJaxtGT6I2D5tdVOmZqIYMgQ0TyjCnEIvmohFaaiflr+BL0/oo4uP8pV0FZXoO17u3paGoMLqzZoPEdn2NGQrf8/jeyk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769027081; c=relaxed/simple; bh=Jaq2jsRG/r4sZNtPJ8ltyTFCbLArZNy2emYqmWGFUaU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=cna2jns5/7oaLakTyab7Gla3jJk7dA/GEloJf9QP+HD5yDPxq6QuFp6y4Vnd3hZhmYRpAKtruAGy6R0pMO4kQwN8OujZixT/vuTaEUwWTbCEVSeMcLZKlLTXQw+vZGyXCo4r1tuLwsCB6n8eXyG/TFrCsekCl3mvfiNnbrl1mw0= 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=i+BT9swE; arc=none smtp.client-ip=209.85.216.73 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="i+BT9swE" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-352e1a8603bso254662a91.1 for ; Wed, 21 Jan 2026 12:24:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769027078; x=1769631878; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=+MgxcQq5Xqx+GbQCEBAnHK7cTgnKSfyobaM2qHohzJ0=; b=i+BT9swEet3BcYwvpun23CLnOmfL43ZZZW8N5xVlY1Iu9O+4YBbISMYw2ng9czEDIH ciXoYnVPKINZw4o5aGUbHCCHaps6BqB9E02vYE4cQNtseroemksB0RIfCtrSDnHF48To UO1uE7TzSrdYZ8OPUhKkvT2evmp4M3K/3Tfe8bq95iBv4YXRC8u0PbnCjL21P2imZdLK L4vDBxdTUlKEBoVGLlG+MuYscjNw5jO1WjkBLfZGLl8V2Hbx85B4sjh/rASpmxL/Z4WU C7LqMcfwcUkiUIBDxBPxOvuisgkQccqAD83b63g0yk2MeP93Hbm4xjQ2ISrWoxrP1Wqr vJ8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769027078; x=1769631878; h=content-transfer-encoding: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=+MgxcQq5Xqx+GbQCEBAnHK7cTgnKSfyobaM2qHohzJ0=; b=QCvIOp/XQsi16CfBZJ+k8hcKlLBPm52OhTXN20XHKeENM65Um5MQ1ZRkaWLVEpIRRf jG8RUUcQNbDCNiOX0mgWLt/oZ5+Onn8Sy/ethxbzno2GtOw+TE7DrL/2YEYyuceqqiZ8 DrJd4xyj5/zwOQZEXctuFkA6oM2mZc7MhwzPTCeByWZgrFGvqgvZFn3cdeSV5+dHWM5x UY32VEiSNfV2BBYz6OfceXWF/ytZ4ZkesvMzhrJ9kdA7jB/w+BcV/d3BW+LiKMzpg21J oy+2PniHGc3734qd+wLowJwTmxRYZ4kJI1BovZ41q83uQ/VTj4PCMtASi/VzfBTYVlm6 54jw== X-Forwarded-Encrypted: i=1; AJvYcCX8jjpC+uNMmKHWGdrXIh83gICZLrelMdg3C7iwDDELvw2xOz5L2Mfhd5mH/eVziNG5tIIoFzcx/Rs1Vwc=@vger.kernel.org X-Gm-Message-State: AOJu0YzDGNtt6O5YtakVsk2i4q+cDNitB11biOMse6WNRVJiHSAMcJ7N yz2gyv+CIKmwjvQROzNkqXduMCcdCjd/gLtx39H3zai15Vc5JaxB3aPvkW49Uuzm/XBC8Cu8L2j zIzJNtg== X-Received: from pjbca22.prod.google.com ([2002:a17:90a:f316:b0:33b:ba24:b207]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90a:dfce:b0:353:3977:a082 with SMTP id 98e67ed59e1d1-3533977a5ddmr180576a91.1.1769027078236; Wed, 21 Jan 2026 12:24:38 -0800 (PST) Date: Wed, 21 Jan 2026 12:24:36 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251026201911.505204-1-xin@zytor.com> <20251026201911.505204-12-xin@zytor.com> <9a628729-1b4f-4982-a3e6-b9269c91b3c2@linux.intel.com> Message-ID: Subject: Re: [PATCH v9 11/22] KVM: x86: Add a helper to detect if FRED is enabled for a vCPU From: Sean Christopherson To: Xin Li Cc: Binbin Wu , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-doc@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, luto@kernel.org, peterz@infradead.org, andrew.cooper3@citrix.com, chao.gao@intel.com, hch@infradead.org, sohil.mehta@intel.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Wed, Jan 21, 2026, Xin Li wrote: >=20 > > On Jan 21, 2026, at 12:05=E2=80=AFAM, Binbin Wu wrote: > >=20 > >=20 > > Not sure if it's OK with empty change log even though the patch is simp= le and > > the title has already described it. >=20 > IIRC, Sean changed it this way ;) I doubt that. Ha! Found it. From: https://lore.kernel.org/all/ZmszIOsGtN= svqbpI@google.com as an attachment: [-- Attachment #4: 0013-KVM-x86-Add-a-helper-to-detect-if-FRED-is-enabled-f= o.patch --] [-- Type: text/x-diff, Size: 1418 bytes --] >From f38dcc04e334cda572289f05f4be7702bebfc96a Mon Sep 17 00:00:00 2001 From: Xin Li Date: Wed, 7 Feb 2024 09:26:31 -0800 Subject: [PATCH 13/28] KVM: x86: Add a helper to detect if FRED is enabled = for a vCPU Add is_fred_enabled() to detect if FRED is enabled on a vCPU. Signed-off-by: Xin Li Tested-by: Shan Kang Signed-off-by: Sean Christopherson --- arch/x86/kvm/kvm_cache_regs.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/x86/kvm/kvm_cache_regs.h b/arch/x86/kvm/kvm_cache_regs.h index 75eae9c4998a..fe5546efd388 100644 --- a/arch/x86/kvm/kvm_cache_regs.h +++ b/arch/x86/kvm/kvm_cache_regs.h @@ -187,6 +187,21 @@ static __always_inline bool kvm_is_cr4_bit_set(struct = kvm_vcpu *vcpu, return !!kvm_read_cr4_bits(vcpu, cr4_bit); } =20 +/* + * 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 =3D 1. + * 2) To leave IA-32e mode, CR4.FRED must be cleared first. + */ +static inline bool is_fred_enabled(struct kvm_vcpu *vcpu) +{ +#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)) --=20 2.45.2.627.g7a2c4fd464-goog