qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4] i386: Add ratelimit for bus locks acquired in guest


From: Chenyi Qiang
Subject: Re: [PATCH v4] i386: Add ratelimit for bus locks acquired in guest
Date: Wed, 2 Jun 2021 09:26:43 +0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1



On 6/2/2021 4:10 AM, Eduardo Habkost wrote:
On Tue, Jun 01, 2021 at 02:18:37PM -0400, Eduardo Habkost wrote:
On Mon, May 31, 2021 at 01:14:54PM +0800, Chenyi Qiang wrote:


On 5/28/2021 5:19 AM, Eduardo Habkost wrote:
On Fri, May 21, 2021 at 12:38:20PM +0800, Chenyi Qiang wrote:
[...]
@@ -4222,6 +4247,15 @@ void kvm_arch_pre_run(CPUState *cpu, struct kvm_run *run)
       }
   }
+static void kvm_rate_limit_on_bus_lock(void)
+{
+    uint64_t delay_ns = ratelimit_calculate_delay(&bus_lock_ratelimit_ctrl, 1);
+
+    if (delay_ns) {
+        g_usleep(delay_ns / SCALE_US);
+    }
+}
+
   MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct kvm_run *run)
   {
       X86CPU *x86_cpu = X86_CPU(cpu);
@@ -4237,6 +4271,9 @@ MemTxAttrs kvm_arch_post_run(CPUState *cpu, struct 
kvm_run *run)
       } else {
           env->eflags &= ~IF_MASK;
       }
+    if (run->flags & KVM_RUN_X86_BUS_LOCK) {

Does the KVM API guarantee that KVM_RUN_X86_BUS_LOCK will never
be set if KVM_BUS_LOCK_DETECTION_EXIT isn't enabled?  (Otherwise
we risk crashing in ratelimit_calculate_delay() above if rate
limiting is disabled).


Yes. KVM_RUN_X86_BUS_LOCK flag is set when bus lock VM exit happens. Bus
lock VM exit is disabled by default and can only be enabled through the
KVM_BUS_LOCK_DETECTION_EXIT capability.

I'm queueing on x86-next, thanks!

This breaks the build.  Is there a linux-headers update patch I've missed?


Thanks for the queue and sorry for forgetting to submit the linux-headers update patch.

../target/i386/kvm/kvm.c: In function 'kvm_arch_init':
../target/i386/kvm/kvm.c:2322:42: error: 'KVM_CAP_X86_BUS_LOCK_EXIT' undeclared 
(first use in this function); did you mean 'KVM_CAP_X86_DISABLE_EXITS'?
              ret = kvm_check_extension(s, KVM_CAP_X86_BUS_LOCK_EXIT);
                                           ^~~~~~~~~~~~~~~~~~~~~~~~~
                                           KVM_CAP_X86_DISABLE_EXITS




reply via email to

[Prev in Thread] Current Thread [Next in Thread]