• Marc Zyngier's avatar
    KVM: arm64: Build MPIDR to vcpu index cache at runtime · 5544750e
    Marc Zyngier authored
    The MPIDR_EL1 register contains a unique value that identifies
    the CPU. The only problem with it is that it is stupidly large
    (32 bits, once the useless stuff is removed).
    
    Trying to obtain a vcpu from an MPIDR value is a fairly common,
    yet costly operation: we iterate over all the vcpus until we
    find the correct one. While this is cheap for small VMs, it is
    pretty expensive on large ones, specially if you are trying to
    get to the one that's at the end of the list...
    
    In order to help with this, it is important to realise that
    the MPIDR values are actually structured, and that implementations
    tend to use a small number of significant bits in the 32bit space.
    
    We can use this fact to our advantage by computing a small hash
    table that uses the "compression" of the significant MPIDR bits
    as an index, giving us the vcpu index as a result.
    
    Given that the MPIDR values can be supplied by userspace, and
    that an evil VMM could decide to make *all* bits significant,
    resulting in a 4G-entry table, we only use this method if the
    resulting table fits in a single page. Otherwise, we fallback
    to the good old iterative method.
    
    Nothing uses that table just yet, but keep your eyes peeled.
    Reviewed-by: default avatarJoey Gouly <joey.gouly@arm.com>
    Reviewed-by: default avatarZenghui Yu <yuzenghui@huawei.com>
    Tested-by: default avatarJoey Gouly <joey.gouly@arm.com>
    Tested-by: default avatarShameer Kolothum <shameerali.kolothum.thodi@huawei.com>
    Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
    Link: https://lore.kernel.org/r/20230927090911.3355209-9-maz@kernel.orgSigned-off-by: default avatarOliver Upton <oliver.upton@linux.dev>
    5544750e
arm.c 61.1 KB