Re: [PATCH v2 0/6] LoongArch: KVM: Set max VM supported FPU type with FPU exception

From: Xi Ruoyao

Date: Tue Apr 07 2026 - 21:14:58 EST


On Wed, 2026-04-08 at 09:01 +0800, Bibo Mao wrote:
>
>
> On 2026/4/7 下午8:41, Huacai Chen wrote:
> > On Mon, Mar 30, 2026 at 6:00 PM Huacai Chen <chenhuacai@xxxxxxxxxx> wrote:
> > >
> > > Hi, Bibo,
> > >
> > >
> > > On Mon, Mar 30, 2026 at 11:58 AM Bibo Mao <maobibo@xxxxxxxxxxx> wrote:
> > > >
> > > > With FPU save and restore flow, the cost is the same with different
> > > > FPU width 8/16/32 bytes, whatever from CPU cycle and cache line impaction.
> > > >
> > > > Here is to enable FPU with max VM supported type, for example if
> > > > VM supports LASX instrction, enable FPU with LASX type even with FPU
> > > > exeception. So it can avoid possible LSX/LASX exception in future.
> > > >
> > > > With context switch microbench which may touch FPU and LASX, there is 9%
> > > > improvement when halt_poll_ns is disabled. The command is
> > > > "./context --test=pipe" and source code located at:
> > > >    https://github.com/bibo-mao/context_switch/blob/main/context.c
> > > >
> > > > Original     Wih patch      improvement
> > > > 75232        82440          9%
> > > >
> > > > Signed-off-by: Bibo Mao <maobibo@xxxxxxxxxxx>
> > > > ---
> > > > v1 ... v2:
> > > >    1. Enable FPU with max VM supported FPU type, rather than max used type.
> > > >    2. Add new request bit KVM_REQ_LBT_LOAD for LBT restore
> > > >    3. Rename KVM_REQ_AUX_LOAD with KVM_REQ_FPU_LOAD
> > > >    3. Remove aux_ldtype and KVM_LARCH_LSX/KVM_LARCH_LSX
> > > >    4. Remove middle FPU state handling in kvm_own_lsx() and kvm_own_lasx(),
> > > >       directly enable LSX or LASX from FPU none state.
> > > > ---
> > > > Bibo Mao (6):
> > > >    LoongArch: KVM: Add separate KVM_REQ_LBT_LOAD request bit
> > > >    LoongArch: KVM: Enable FPU with max VM supported FPU type
> > > >    LoongArch: KVM: Rename KVM_REQ_AUX_LOAD with KVM_REQ_FPU_LOAD
> > > Patch-1 add KVM_REQ_LBT_LOAD, then KVM_REQ_AUX_LOAD is only for FPU,
> > > so I think Patch-3 should be squashed into Patch-1.
> > >
> > > >    LoongArch: KVM: Remove some middle FPU states
> > > >    LoongArch: KVM: Use vm_guest_has_fpu API in kvm_lose_fpu()
> > > >    LoongArch: KVM: Remove KVM_LARCH_LASX and KVM_LARCH_LSX
> > > Patch-5 remove the consumer side of KVM_LARCH_LASX / KVM_LARCH_LSX and
> > > Patch-6 remove the provider side of KVM_LARCH_LASX / KVM_LARCH_LSX, so
> > > I think Patch-6 should be squashed into Patch-5, too.
> > And could you please test the power consumption where there are many
> > VMs that only use FPU rather than LSX/LASX? As far as I know, the
> Hi Huacai,
>
> Thanks for reviewing this patch
> Could you help me to test the power consumption with this patch?
> > power consumption of LASX is significantly more than FPU, which is a
> Could the describe the detail scenery wheree LASX instruction is
> frequently used by application or LASX  EUEN enabled?

FWIW in the most common real scenarios, the ifunc resolving mechanism of
glibc immediately invokes LASX on program startup if CPU supports LASX
(see _dl_runtime_resolve_lasx in glibc/sysdeps/loongarch/dl-
trampoline.h). Thus for almost all user-space processes LASX is enabled
in EUEN as long as the CPU supports LASX. Relying on disabling LASX in
EUEN for power-saving just doesn't work.


--
Xi Ruoyao <xry111@xxxxxxxxxxx>