[PATCH v9 17/22] KVM: x86: Advertise support for FRED

Xin Li (Intel) posted 22 patches 3 months, 2 weeks ago
[PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Xin Li (Intel) 3 months, 2 weeks ago
From: Xin Li <xin3.li@intel.com>

Advertise support for FRED to userspace after changes required to enable
FRED in a KVM guest are in place.

Signed-off-by: Xin Li <xin3.li@intel.com>
Signed-off-by: Xin Li (Intel) <xin@zytor.com>
Tested-by: Shan Kang <shan.kang@intel.com>
Tested-by: Xuelian Guo <xuelian.guo@intel.com>
---

Change in v5:
* Don't advertise FRED/LKGS together, LKGS can be advertised as an
  independent feature (Sean).
* Add TB from Xuelian Guo.
---
 arch/x86/kvm/cpuid.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index d563a948318b..0bf97b8a3216 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1014,6 +1014,7 @@ void kvm_set_cpu_caps(void)
 		F(FSRS),
 		F(FSRC),
 		F(WRMSRNS),
+		X86_64_F(FRED),
 		X86_64_F(LKGS),
 		F(AMX_FP16),
 		F(AVX_IFMA),
-- 
2.51.0
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Chao Gao 2 months, 4 weeks ago
On Sun, Oct 26, 2025 at 01:19:05PM -0700, Xin Li (Intel) wrote:
>From: Xin Li <xin3.li@intel.com>
>
>Advertise support for FRED to userspace after changes required to enable
>FRED in a KVM guest are in place.

I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().

With this fixed:

Reviewed-by: Chao Gao <chao.gao@intel.com>

>
>Signed-off-by: Xin Li <xin3.li@intel.com>
>Signed-off-by: Xin Li (Intel) <xin@zytor.com>
>Tested-by: Shan Kang <shan.kang@intel.com>
>Tested-by: Xuelian Guo <xuelian.guo@intel.com>
>---
>
>Change in v5:
>* Don't advertise FRED/LKGS together, LKGS can be advertised as an
>  independent feature (Sean).
>* Add TB from Xuelian Guo.
>---
> arch/x86/kvm/cpuid.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
>index d563a948318b..0bf97b8a3216 100644
>--- a/arch/x86/kvm/cpuid.c
>+++ b/arch/x86/kvm/cpuid.c
>@@ -1014,6 +1014,7 @@ void kvm_set_cpu_caps(void)
> 		F(FSRS),
> 		F(FSRC),
> 		F(WRMSRNS),
>+		X86_64_F(FRED),
> 		X86_64_F(LKGS),
> 		F(AMX_FP16),
> 		F(AVX_IFMA),
>-- 
>2.51.0
>
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Xin Li 2 weeks, 6 days ago

> On Nov 11, 2025, at 11:30 PM, Chao Gao <chao.gao@intel.com> wrote:
> 
> I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
> i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().

AMD will support FRED, with ISA level compatibility:

https://www.amd.com/en/blogs/2025/amd-and-intel-celebrate-first-anniversary-of-x86-ecosys.html

Thus we don’t need to clear the bit.
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Chao Gao 2 weeks, 5 days ago
On Mon, Jan 19, 2026 at 10:56:29PM -0800, Xin Li wrote:
>
>
>> On Nov 11, 2025, at 11:30 PM, Chao Gao <chao.gao@intel.com> wrote:
>> 
>> I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
>> i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().
>
>AMD will support FRED, with ISA level compatibility:
>
>https://www.amd.com/en/blogs/2025/amd-and-intel-celebrate-first-anniversary-of-x86-ecosys.html
>
>Thus we don’t need to clear the bit.

In this case, we need to clear FRED for AMD.

The concern is that before AMD's FRED KVM support is implemented, FRED will be
exposed to userspace on AMD FRED-capable hardware. This may cause issues.
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Xin Li 2 weeks, 5 days ago

> On Jan 20, 2026, at 12:07 AM, Chao Gao <chao.gao@intel.com> wrote:
> 
> On Mon, Jan 19, 2026 at 10:56:29PM -0800, Xin Li wrote:
>> 
>> 
>>> On Nov 11, 2025, at 11:30 PM, Chao Gao <chao.gao@intel.com> wrote:
>>> 
>>> I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
>>> i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().
>> 
>> AMD will support FRED, with ISA level compatibility:
>> 
>> https://www.amd.com/en/blogs/2025/amd-and-intel-celebrate-first-anniversary-of-x86-ecosys.html
>> 
>> Thus we don’t need to clear the bit.
> 
> In this case, we need to clear FRED for AMD.
> 
> The concern is that before AMD's FRED KVM support is implemented, FRED will be
> exposed to userspace on AMD FRED-capable hardware. This may cause issues.

Hmm, I think it’s Qemu does that.

We have 2 filters, one in Qemu and one in KVM, only both are set a feature is enabled.

What I have missed?
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Binbin Wu 2 weeks, 5 days ago

On 1/20/2026 5:09 PM, Xin Li wrote:
> 
> 
>> On Jan 20, 2026, at 12:07 AM, Chao Gao <chao.gao@intel.com> wrote:
>>
>> On Mon, Jan 19, 2026 at 10:56:29PM -0800, Xin Li wrote:
>>>
>>>
>>>> On Nov 11, 2025, at 11:30 PM, Chao Gao <chao.gao@intel.com> wrote:
>>>>
>>>> I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
>>>> i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().
>>>
>>> AMD will support FRED, with ISA level compatibility:
>>>
>>> https://www.amd.com/en/blogs/2025/amd-and-intel-celebrate-first-anniversary-of-x86-ecosys.html
>>>
>>> Thus we don’t need to clear the bit.
>>
>> In this case, we need to clear FRED for AMD.
>>
>> The concern is that before AMD's FRED KVM support is implemented, FRED will be
>> exposed to userspace on AMD FRED-capable hardware. This may cause issues.
> 
> Hmm, I think it’s Qemu does that.
> 
> We have 2 filters, one in Qemu and one in KVM, only both are set a feature is enabled.
> 
> What I have missed?

If a newer QEMU (with AMD's FRED support patch) + an older KVM (without AMD's
FRED support, but KVM advertises it), it may cause issues.

I guess it's no safety issue for host though, AMD should also require some
control bit(s) to be set to allow guests to use the feature.

I agree with Chao that it should be cleared for AMD before AMD's FRED KVM
support is implemented.
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Xin Li 2 weeks, 5 days ago
>>> 
>>> In this case, we need to clear FRED for AMD.
>>> 
>>> The concern is that before AMD's FRED KVM support is implemented, FRED will be
>>> exposed to userspace on AMD FRED-capable hardware. This may cause issues.
>> 
>> Hmm, I think it’s Qemu does that.
>> 
>> We have 2 filters, one in Qemu and one in KVM, only both are set a feature is enabled.
>> 
>> What I have missed?
> 
> If a newer QEMU (with AMD's FRED support patch) + an older KVM (without AMD's
> FRED support, but KVM advertises it), it may cause issues.
> 
> I guess it's no safety issue for host though, AMD should also require some
> control bit(s) to be set to allow guests to use the feature.
> 
> I agree with Chao that it should be cleared for AMD before AMD's FRED KVM
> support is implemented.


Damn, I somehow thought the host won’t report FRED on AMD...
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Sean Christopherson 2 weeks, 5 days ago
On Tue, Jan 20, 2026, Binbin Wu wrote:
> On 1/20/2026 5:09 PM, Xin Li wrote:
> >> On Jan 20, 2026, at 12:07 AM, Chao Gao <chao.gao@intel.com> wrote:
> >>
> >> On Mon, Jan 19, 2026 at 10:56:29PM -0800, Xin Li wrote:
> >>>
> >>>
> >>>> On Nov 11, 2025, at 11:30 PM, Chao Gao <chao.gao@intel.com> wrote:
> >>>>
> >>>> I'm not sure if AMD CPUs support FRED, but just in case, we can clear FRED
> >>>> i.e., kvm_cpu_cap_clear(X86_FEATURE_FRED) in svm_set_cpu_caps().
> >>>
> >>> AMD will support FRED, with ISA level compatibility:
> >>>
> >>> https://www.amd.com/en/blogs/2025/amd-and-intel-celebrate-first-anniversary-of-x86-ecosys.html
> >>>
> >>> Thus we don’t need to clear the bit.
> >>
> >> In this case, we need to clear FRED for AMD.
> >>
> >> The concern is that before AMD's FRED KVM support is implemented, FRED will be
> >> exposed to userspace on AMD FRED-capable hardware. This may cause issues.
> > 
> > Hmm, I think it’s Qemu does that.
> > 
> > We have 2 filters, one in Qemu and one in KVM, only both are set a feature is enabled.
> > 
> > What I have missed?

The userspace VMM, e.g. QEMU, is completely irrelevant.  KVM must not advertise
support for features it doesn't actually implement, and more importantly must not
internally treat such features as supported.

> If a newer QEMU (with AMD's FRED support patch) + an older KVM (without AMD's
> FRED support, but KVM advertises it), it may cause issues.

Yep.

> I guess it's no safety issue for host though,

Maybe.  Without fully analyzing the SVM implementation for FRED and its interaction
with KVM, I don't think we can confidently say that incorrectly treating FRED as
supported is benign for the host.  It's a moot point, I just want to emphasize
how it important it is that KVM doesn't over-report features.
Re: [PATCH v9 17/22] KVM: x86: Advertise support for FRED
Posted by Xin Li 2 weeks, 5 days ago
> On Jan 20, 2026, at 7:25 AM, Sean Christopherson <seanjc@google.com> wrote:
> 
>>> 
>>> What I have missed?
> 
> The userspace VMM, e.g. QEMU, is completely irrelevant.  KVM must not advertise
> support for features it doesn't actually implement, and more importantly must not
> internally treat such features as supported.

Right, FRED virtualization is not supported on AMD and obviously SVM will
need to add FRED virtualization in their own fashion later.

> 
>> If a newer QEMU (with AMD's FRED support patch) + an older KVM (without AMD's
>> FRED support, but KVM advertises it), it may cause issues.
> 
> Yep.
> 
>> I guess it's no safety issue for host though,
> 
> Maybe.  Without fully analyzing the SVM implementation for FRED and its interaction
> with KVM, I don't think we can confidently say that incorrectly treating FRED as
> supported is benign for the host.  It's a moot point, I just want to emphasize
> how it important it is that KVM doesn't over-report features.

I will remove it on AMD.