[PATCH v5 06/15] KVM: arm64: Add support for FEAT_HDBSS

Tian Zheng zhengtian10 at huawei.com
Fri Nov 20 01:41:23 PST 2026



On 11/20/2026 1:27 AM, Leonardo Bras wrote:
> On Thu, Nov 19, 2026 at 03:52:37PM +0800, Tian Zheng wrote:
>>
>>
>> On 10/30/2026 10:15 PM, Leonardo Bras wrote:
>>> On Fri, Oct 30, 2026 at 10:53:57AM +0800, Tian Zheng wrote:
>>>>
>>>>
>>>> On 10/27/2026 2:12 AM, Leonardo Bras wrote:
>>>>> On Tue, Sep 29, 2026 at 06:36:46PM +0800, Tian Zheng wrote:
>>>>>> diff --git a/arch/arm64/kernel/cpufeature.c b/arch/arm64/kernel/cpufeature.c
>>>>>> index 32102c3912fa..12fa37328dd2 100644
>>>>>> --- a/arch/arm64/kernel/cpufeature.c
>>>>>> +++ b/arch/arm64/kernel/cpufeature.c
>>>>>> @@ -2158,6 +2158,11 @@ static bool hvhe_possible(const struct arm64_cpu_capabilities *entry,
>>>>>>     	return arm64_test_sw_feature_override(ARM64_SW_FEATURE_OVERRIDE_HVHE);
>>>>>>     }
>>>>>>
>>>>>> +static bool has_vhe_hdbss(const struct arm64_cpu_capabilities *entry, int scope)
>>>>>> +{
>>>>>> +	return is_kernel_in_hyp_mode() && has_cpuid_feature(entry, scope);
>>>>>> +}
>>>>>> +
>>>>>
>>>>
>>>> Hi leo,
>>>>
>>>>> IIUC you run this on every cpu in the system, to make sure it's matching
>>>>> the feature. Is there any chance the kernel is in EL2 only on some of the
>>>>> cpus here?
>>>>>
>>>>
>>>> It's impossible for the system to have only some CPUs in EL2 and others
>>>>    not.
>>>>
>>>>> If not, maybe we can run it on system_supports_hdbss() instead, which would
>>>>> be easier for the user to understand it only runs in EL2, on top of not
>>>>> needing the above.
>>>>>
>>>>
>>>> However, The question is whether a cap should mean "this system can use
>>>> the feature" or "this hardware supports the feature". If the cap only
>>>> tracks hardware support, users may be confused when the hardware
>>>> supports HDBSS but the system runs in nVHE mode — they would mistakenly
>>>> believe they can use the feature.
>>>>
>>>> So I think we should keep is_kernel_in_hyp_mode() in has_vhe_hdbss(),
>>>> and add a comment in system_supports_hdbss() explaining this.
>>>>
>>>> Does that work for you? Looking forward to your reply.
>>>
>>> Well,
>>> That's just my personal view of this:
>>>
>>> If we have a function called "has_hdbss" it should only report if the
>>> system has the feature available.
>>>
>>> On the "system_supports_*" we have to figure out if the system itself
>>> supports the feature, which checks the feature bits itself and could mean
>>> checking for other features being there, such as hyp_mode.
>>>
>>> What do you think?
>>>
>>> Thx,
>>> Leo
>>
>> Hi Leo,
> 
> Hi Tian,
>   
>> Sorry for the slow reply. I've been looking into how other cpufeatures
>> are configured on arm64, on and off, and that's why it took a while.
> 
> I took some time to study it as well, and to be clear, my previous
> understanding of this was incorrect, and it looks like the has_vhe_hdbss
> (.matches callback) is only called once during boot, and once per hot-added
> cpu.
>   
>> My reading is that detected: HDBSS should mean "this system can use
>> HDBSS", not just "the silicon has it".
>>
>> Several caps already add conditions beyond the ID bits. CNP returns
>> false for kdump and under ARM64_WORKAROUND_DISABLE_CNP, NV and pKVM
>> match on kvm_get_mode(), and can_trap_icv_dir_el1() starts with
>> is_hyp_mode_available(). So in practice a SYSTEM_FEATURE cap answers
>> "can this kernel use it on this system".
> 
> Humm, or maybe "can this kernel, booted as it is, use it on this system"...
>   
>> HDBSS is EL2-only (HDBSSBR_EL2/HDBSSPROD_EL2, VTCR_EL2.HDBSS),
>> implemented only under hyp/vhe, and used only by KVM, so "the hardware
>> is there" is not the same as "this kernel can use it". That is why I'd
>> keep the gate in has_vhe_hdbss() rather than moving it to the consumer.
>>
>> I'd be interested to hear how you see it.
> 
> I agree, that looks better this way.
> 
> I don't think I understand enough of what 'system' means in
> system_supports_*(), but I think your version explains it enough based on
> other similar functions.
> 
> Thanks!
> Leo

Hi leo,

Awesome, thanks for taking the time to study it.

Thanks!
Tian



More information about the linux-arm-kernel mailing list