Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4146874ybb; Tue, 7 Apr 2020 01:30:55 -0700 (PDT) X-Google-Smtp-Source: APiQypK6R+7muKvf8jXrhrP4j7YkKLQyXVrXoUWbnhQlVa1wQlqYX7s+IaQ/7JPE8oc35ZSb3tJc X-Received: by 2002:a9d:75d4:: with SMTP id c20mr580825otl.329.1586248255392; Tue, 07 Apr 2020 01:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586248255; cv=none; d=google.com; s=arc-20160816; b=K5Dg3vEtugWGXRJLVTtVCALmsR00uZbnvHZs1HWMmQHScLBpTROi/6S1I/9sg6pwNI qtkntX5VeUVhV2wVqCuC94+YdwUcsWL8xQxMCFkTuMxEqpO02s/dJsjnlOQvmIHHoyZi BHu2c2AvPCSCh+g8ojHJgbWZeWGtidGJer8cPFdMcZEoCiCpqFKR53/2EyDjM2bk9OWE dvPtK3yMtffGxkrLPChujEvpWPZhLW8ooi10f31PR7vZRh2pKnbFROzTS+8M8bwfGBsn NO3nCB1tg+O9mUQw9QPElTv0158/qTIbWf4/UmXTtAV8a6y58onmydhsCoSCbHws3M3G SXyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=QwWmobyOdR5r+7JJZxSrwfB56TjLUl825BwGgH9NRNQ=; b=zH3YcxSuQIHCXQ8JjZLbbvQG7JqhfwloS3F67qHbEA4vfsvSHwCVE/B6ihKYH+Goa6 3uRqFAsOwqoLvRvD5rTstSPFzm37q3JUGz/ACJuS9fGsVz9fZhTQSIl32PNaYJe7D+5B Xy7XeSVG+IkS168cXZYwzykTeYZf0K9T2qa5DnQGwJZdpWWauQ3Jw8PkGCZQ6OK49E8Q biQTBI4gv4PTi0BedimhMH+4MQiaug4zlBDswgMd1OdwSaFYRIkuKqjxJYZtB77hZ6Gj ffSwy0uxZDdZipw3pUeZN8A6AsA0mGmy/ypTcn06tTBWoJCotTgXuNUOG9YH72+ArzIc zZ6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N2Rgae8z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z204si439001oiz.133.2020.04.07.01.30.43; Tue, 07 Apr 2020 01:30:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=N2Rgae8z; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727946AbgDGI2u (ORCPT + 99 others); Tue, 7 Apr 2020 04:28:50 -0400 Received: from mail-pj1-f66.google.com ([209.85.216.66]:50373 "EHLO mail-pj1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbgDGI2t (ORCPT ); Tue, 7 Apr 2020 04:28:49 -0400 Received: by mail-pj1-f66.google.com with SMTP id v13so435997pjb.0; Tue, 07 Apr 2020 01:28:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QwWmobyOdR5r+7JJZxSrwfB56TjLUl825BwGgH9NRNQ=; b=N2Rgae8zms+3LBxcOrnLBU6jO9Vokq7alwIwdkajm2FUP1feOjiHVPKSETTl9o9lJe e7OTGKpv440s5Lfcetiy6u8IiLz7+Y65DDE1Du0iTM9Jc128kZeLDcwZDP2wvDVveaIc 7RE1k4T2JIo9iPgOk01c9xZ9YKhpy340rKlsPtWfXLmi3Rl4PlnuJxanwfKZO6hF/8M1 F74iN54bpM1rgEA+G2heoGYtF9uMSouwpX+N28YAE6gIllNTnzbD3G8DzQ6dtk3f1XX+ Ov0kmUIwGI1h6dIrIBQQX/RiKzAEJqbvWRGeU4xATH0LIQGyIeubVEtJ+ioJT0f5KCDv ZI7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QwWmobyOdR5r+7JJZxSrwfB56TjLUl825BwGgH9NRNQ=; b=bcMP05UarBvvw2ZLczV8sX8k1eoW4D+8Co1Jm3BDnZbseGIaG2D0bF2UU32Itc1Yv+ NcGeXswQhpm/vzWU2E0xv/qYhUAthPgU4FHQhjvwsua81DXCJElScTbvcGEixYkRNMcH /8+r9eR7K6ekeiWwGefsxOWR0KvhCyI7M0H268YamJvWC6jzjhVgNxUpmFT7qfNAF8ZL D/cucOGbHjp1miUo8f0zFvVFU/ymByDwDAaz+2hGocZp+uq/DnnpffBTkst2ZEEnZWMr QX+5yi+JJzaO8twUkUHuSZpg/k4oLP5avbUDvYEm+NO9v+hKUHDW/Pi3zwv/F0YmDQe0 SDgA== X-Gm-Message-State: AGi0PuYiNAA8xo0camTArksjQVK+BSZMumlpUc+bOCzE1lqlpJpUWQIz bkBRGCfCoBraFEyAzAj6byOsIZbq01Y= X-Received: by 2002:a17:902:8ec1:: with SMTP id x1mr1381741plo.325.1586248128475; Tue, 07 Apr 2020 01:28:48 -0700 (PDT) Received: from localhost.localdomain ([103.7.29.6]) by smtp.googlemail.com with ESMTPSA id h2sm13520526pfr.220.2020.04.07.01.28.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Apr 2020 01:28:48 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Haiwei Li Subject: [PATCH] KVM: X86: Ultra fast single target IPI fastpath Date: Tue, 7 Apr 2020 16:28:38 +0800 Message-Id: <1586248118-19607-1-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li IPI and Timer cause the main MSRs write vmexits in cloud environment observation, let's optimize virtual IPI latency more aggressively to inject target IPI as soon as possible. Running kvm-unit-tests/vmexit.flat IPI testing on SKX server, disable adaptive advance lapic timer and adaptive halt-polling to avoid the interference, this patch can give another 7% improvement. w/o fastpath -> fastpath 4238 -> 3543 16.4% fastpath -> ultra fastpath 3543 -> 3293 7% w/o fastpath -> ultra fastpath 4338 -> 3293 24% This also revises the performance data in commit 1e9e2622a1 (KVM: VMX: FIXED+PHYSICAL mode single target IPI fastpath), that testing exposes mwait to kvm-unit-tests guest which is unnecessary. Tested-by: Haiwei Li Cc: Haiwei Li Signed-off-by: Wanpeng Li --- arch/x86/include/asm/kvm_host.h | 6 +++--- arch/x86/kvm/svm.c | 21 ++++++++++++++------- arch/x86/kvm/vmx/vmx.c | 19 +++++++++++++------ arch/x86/kvm/x86.c | 4 ++-- 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 42a2d0d..932162f 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1114,7 +1114,8 @@ struct kvm_x86_ops { */ void (*tlb_flush_gva)(struct kvm_vcpu *vcpu, gva_t addr); - void (*run)(struct kvm_vcpu *vcpu); + void (*run)(struct kvm_vcpu *vcpu, + enum exit_fastpath_completion *exit_fastpath); int (*handle_exit)(struct kvm_vcpu *vcpu, enum exit_fastpath_completion exit_fastpath); int (*skip_emulated_instruction)(struct kvm_vcpu *vcpu); @@ -1164,8 +1165,7 @@ struct kvm_x86_ops { struct x86_instruction_info *info, enum x86_intercept_stage stage, struct x86_exception *exception); - void (*handle_exit_irqoff)(struct kvm_vcpu *vcpu, - enum exit_fastpath_completion *exit_fastpath); + void (*handle_exit_irqoff)(struct kvm_vcpu *vcpu); int (*check_nested_events)(struct kvm_vcpu *vcpu); void (*request_immediate_exit)(struct kvm_vcpu *vcpu); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 851e9cc..683474b 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -5755,7 +5755,18 @@ static void svm_cancel_injection(struct kvm_vcpu *vcpu) svm_complete_interrupts(svm); } -static void svm_vcpu_run(struct kvm_vcpu *vcpu) +static enum exit_fastpath_completion svm_exit_handlers_fastpath(struct kvm_vcpu *vcpu) +{ + if (!is_guest_mode(vcpu) && + to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR && + to_svm(vcpu)->vmcb->control.exit_info_1) + return handle_fastpath_set_msr_irqoff(vcpu); + + return EXIT_FASTPATH_NONE; +} + +static void svm_vcpu_run(struct kvm_vcpu *vcpu, + enum exit_fastpath_completion *exit_fastpath) { struct vcpu_svm *svm = to_svm(vcpu); @@ -5946,6 +5957,7 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu) kvm_load_host_xsave_state(vcpu); stgi(); + *exit_fastpath = svm_exit_handlers_fastpath(vcpu); /* Any pending NMI will happen here */ if (unlikely(svm->vmcb->control.exit_code == SVM_EXIT_NMI)) @@ -6277,13 +6289,8 @@ static int svm_check_intercept(struct kvm_vcpu *vcpu, return ret; } -static void svm_handle_exit_irqoff(struct kvm_vcpu *vcpu, - enum exit_fastpath_completion *exit_fastpath) +static void svm_handle_exit_irqoff(struct kvm_vcpu *vcpu) { - if (!is_guest_mode(vcpu) && - to_svm(vcpu)->vmcb->control.exit_code == SVM_EXIT_MSR && - to_svm(vcpu)->vmcb->control.exit_info_1) - *exit_fastpath = handle_fastpath_set_msr_irqoff(vcpu); } static void svm_sched_in(struct kvm_vcpu *vcpu, int cpu) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 91749f1..14d7a74 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -6279,8 +6279,7 @@ static void handle_external_interrupt_irqoff(struct kvm_vcpu *vcpu) } STACK_FRAME_NON_STANDARD(handle_external_interrupt_irqoff); -static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, - enum exit_fastpath_completion *exit_fastpath) +static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu) { struct vcpu_vmx *vmx = to_vmx(vcpu); @@ -6288,9 +6287,6 @@ static void vmx_handle_exit_irqoff(struct kvm_vcpu *vcpu, handle_external_interrupt_irqoff(vcpu); else if (vmx->exit_reason == EXIT_REASON_EXCEPTION_NMI) handle_exception_nmi_irqoff(vmx); - else if (!is_guest_mode(vcpu) && - vmx->exit_reason == EXIT_REASON_MSR_WRITE) - *exit_fastpath = handle_fastpath_set_msr_irqoff(vcpu); } static bool vmx_has_emulated_msr(int index) @@ -6495,9 +6491,19 @@ void vmx_update_host_rsp(struct vcpu_vmx *vmx, unsigned long host_rsp) } } +static enum exit_fastpath_completion vmx_exit_handlers_fastpath(struct kvm_vcpu *vcpu) +{ + if (!is_guest_mode(vcpu) && + to_vmx(vcpu)->exit_reason == EXIT_REASON_MSR_WRITE) + return handle_fastpath_set_msr_irqoff(vcpu); + + return EXIT_FASTPATH_NONE; +} + bool __vmx_vcpu_run(struct vcpu_vmx *vmx, unsigned long *regs, bool launched); -static void vmx_vcpu_run(struct kvm_vcpu *vcpu) +static void vmx_vcpu_run(struct kvm_vcpu *vcpu, + enum exit_fastpath_completion *exit_fastpath) { struct vcpu_vmx *vmx = to_vmx(vcpu); unsigned long cr3, cr4; @@ -6662,6 +6668,7 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu) vmx->idt_vectoring_info = 0; vmx->exit_reason = vmx->fail ? 0xdead : vmcs_read32(VM_EXIT_REASON); + *exit_fastpath = vmx_exit_handlers_fastpath(vcpu); if ((u16)vmx->exit_reason == EXIT_REASON_MCE_DURING_VMENTRY) kvm_machine_check(); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index b8124b56..99f9a1a 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -8392,7 +8392,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) vcpu->arch.switch_db_regs &= ~KVM_DEBUGREG_RELOAD; } - kvm_x86_ops.run(vcpu); + kvm_x86_ops.run(vcpu, &exit_fastpath); /* * Do this here before restoring debug registers on the host. And @@ -8424,7 +8424,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) vcpu->mode = OUTSIDE_GUEST_MODE; smp_wmb(); - kvm_x86_ops.handle_exit_irqoff(vcpu, &exit_fastpath); + kvm_x86_ops.handle_exit_irqoff(vcpu); /* * Consume any pending interrupts, including the possible source of -- 2.7.4