All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tao Cui <cui.tao@linux.dev>
To: Bibo Mao <maobibo@loongson.cn>,
	zhaotianrui@loongson.cn, chenhuacai@kernel.org,
	loongarch@lists.linux.dev
Cc: cui.tao@linux.dev, kernel@xen0n.name, kvm@vger.kernel.org,
	Tao Cui <cuitao@kylinos.cn>
Subject: Re: [PATCH v4 2/3] LoongArch: KVM: Implement guest-side PV TLB flush
Date: Tue, 16 Jun 2026 23:08:14 +0800	[thread overview]
Message-ID: <1bfa4941-b94b-410a-9b64-c13f2712edf9@linux.dev> (raw)
In-Reply-To: <0c47ce21-9a4d-4cdc-9bec-ce749e31512e@loongson.cn>


Hi Bibo,

That's really kind of you. I'd really value the chance to work with you.

在 2026/6/16 09:14, Bibo Mao 写道:
> 
>> +            __cpumask_clear_cpu(cpu, flushmask);
> is it possible that vCPU is running however with KVM_VCPU_PREEMPTED set?

It shouldn't happen with a correct host: the bit is set on vcpu_put
(preempt) and cleared on entry through kvm_update_stolen_time(), so a
running vCPU always has preempted == 0. The guest-side race is closed by
try_cmpxchg(). If the host clears the byte between the guest's READ_ONCE
and the cmpxchg, the cmpxchg fails and the CPU stays in the IPI mask, so
no flush is missed. The only thing that can break the invariant is the
error path from patch 1, which the conservative handling there closes.
Point taken though: the design's correctness rests entirely on the host
honoring this, so I agree the patch-1 fix is necessary rather than
optional.

>> +    }
>> +
>> +    on_each_cpu_mask(flushmask, func, info, 1);
> LoongArch VM does not support post interrupt now, IPI with vCPU will trap to hypervisor.
> 
> There is another PV TLB flush method using hypercall like PV IPI, which will make a request with wait flag such as KVM_REQ_TLB_FLUSH and kick vCPU.
> 
> With this PV TLB flush method, there is not IPI interrupt in VM, and wait is handled in hypervisor, the negative effect is that it flushes all TLBs.
> 
This is the point I most want to get right, and you're correct. Since
LoongArch has no posted interrupts, an IPI to a *running* vCPU still
traps, so the steal-time path only genuinely helps for preempted/idle
vCPUs; for running ones it's no better (a little heavier) than a plain
IPI. The hypercall approach (analogous to our PV IPI) would avoid
in-guest IPIs entirely, at the cost of a full TLB flush and
hypervisor-side wait handling.

Rather than argue from intuition, I'd like to try the hypercall approach
you suggested and measure the performance improvement against the current
path. I'll share the results with you once the testing is done, so we
can decide the direction based on the numbers.

> FYI, another PV TLB flush method in arch/x86/hyperv/mmu.c ...

Thanks for the pointer. The Hyper-V path is a pure hypercall: the guest
hands the hypervisor the address space, an address-range list, and the
target VP set, so the flush stays fine-grained instead of nuking the
whole TLB. That's a good template if the numbers point us toward a
hypercall-based design.

Thanks,
Tao


  reply	other threads:[~2026-06-16 15:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15  8:21 [PATCH v4 0/3] LoongArch: KVM: Add PV TLB flush support Tao Cui
2026-06-15  8:21 ` [PATCH v4 1/3] LoongArch: KVM: Add PV TLB flush support via steal-time shared memory Tao Cui
2026-06-15  8:35   ` sashiko-bot
2026-06-16  1:03   ` Bibo Mao
2026-06-16 14:14     ` Tao Cui
2026-06-15  8:21 ` [PATCH v4 2/3] LoongArch: KVM: Implement guest-side PV TLB flush Tao Cui
2026-06-16  1:14   ` Bibo Mao
2026-06-16 15:08     ` Tao Cui [this message]
2026-06-16  2:19   ` Bibo Mao
2026-06-15  8:21 ` [PATCH v4 3/3] KVM: selftests: loongarch: Add PV TLB flush performance test Tao Cui
2026-06-15  8:29   ` sashiko-bot
2026-06-15  9:24   ` Bibo Mao
2026-06-16 15:42     ` Tao Cui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1bfa4941-b94b-410a-9b64-c13f2712edf9@linux.dev \
    --to=cui.tao@linux.dev \
    --cc=chenhuacai@kernel.org \
    --cc=cuitao@kylinos.cn \
    --cc=kernel@xen0n.name \
    --cc=kvm@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=maobibo@loongson.cn \
    --cc=zhaotianrui@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.