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: Mon, 31 May 2021 13:14:54 +0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1



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.

If that's guaranteed, the patch looks good to me now.

+        kvm_rate_limit_on_bus_lock();
+    }
/* We need to protect the apic state against concurrent accesses from
       * different threads in case the userspace irqchip is used. */
@@ -4595,6 +4632,10 @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run 
*run)
          ioapic_eoi_broadcast(run->eoi.vector);
          ret = 0;
          break;
+    case KVM_EXIT_X86_BUS_LOCK:
+        /* already handled in kvm_arch_post_run */
+        ret = 0;
+        break;
      default:
          fprintf(stderr, "KVM: unknown exit reason %d\n", run->exit_reason);
          ret = -1;
--
2.17.1





reply via email to

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