Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp790502imm; Mon, 2 Jul 2018 23:23:34 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJyrQgRNYxx2YE5nGy6pp0n4BdANvEEZ3Ey9+zZvKKZyMBz/3GJWXJ52I56a47EOqFU55Td X-Received: by 2002:a17:902:76c4:: with SMTP id j4-v6mr28421145plt.19.1530599014004; Mon, 02 Jul 2018 23:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530599013; cv=none; d=google.com; s=arc-20160816; b=xQUQ5UrWauHLIHloEJzY+zRZq53enKd9b67Vdzlf7bGbw8/YEgFZGg5OoYC0QgNEB5 ecRNSqbNzp5B7p0LChpHw6lb8O93ya7PGsZDCqgG1hbzmBdMJu0nU2YNk1Y8ipLn/op1 Uet6CBR7oOlRYgE4/o9BozfYqy3gemd4iQqTHxD/nNJkwkhBBfM5VSdn6oL0Msu9tgtQ M3ygQAOw1E26ptA8b/SjLzcFy7idppRwPZSPZS7YBoZCB2bssF8XN/PndP5bG+E4pP/B FKOlfF8WSOwzjt0lYXSpZKElVAfcbeUfvD0OAbauiw5dW6F2zmAsEhL4SqeRlIvdqSlK xB7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=T0Gr9ejuqBU5gH3HhPH6aITKeIKdA6uQcfzNPk8llIw=; b=KXCYbYQD0rUxdYH+WUnrTGs+lui+M6Gh7a18uyqAEHVw8i49IvuS2mh8caeNv63QUW jYg7QJ87VTAuM2AY11/tUSjrI8tRlLcEfLXn5+gHpqJ8fEMq3B45fLFy+iinJbtHGNSU 5lhntj85d5DuXu/qScj1xnf9bECxZXISlsZzhzLwqAXYMAdhLzteHYaoeUHLu6JQwnnI HGapvhenvCXczGiPx/E6Jz5GBP5xwiMC3t/pX9JDtCtK6AkfMA8NzidhanI+X+W+fsei LI6D3ZGHHj54lJ9r8vABrpnRvT6aSL5dP7iGgYH5Ob2JNGoI3gWjHgTiYR3la6P3rNTw 4MtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fEsq7EhQ; 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 n34-v6si404628pgm.28.2018.07.02.23.23.19; Mon, 02 Jul 2018 23:23:33 -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=fEsq7EhQ; 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 S932778AbeGCGVq (ORCPT + 99 others); Tue, 3 Jul 2018 02:21:46 -0400 Received: from mail-pl0-f65.google.com ([209.85.160.65]:42277 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932767AbeGCGVo (ORCPT ); Tue, 3 Jul 2018 02:21:44 -0400 Received: by mail-pl0-f65.google.com with SMTP id y15-v6so505296pll.9; Mon, 02 Jul 2018 23:21:44 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=T0Gr9ejuqBU5gH3HhPH6aITKeIKdA6uQcfzNPk8llIw=; b=fEsq7EhQICL0B8lWgquPXLaz0srYocryxquzN1YZNJSejaIfX3vGTwH7X3RaxppY2H iO27lHvKIrS3r8QGhfLTmXaCM/e5BeHrIglKhzob3UpTRq4+3neK28jeAsfmVlQdeUqa s/UcgQ08fmjmV3PpYLFRzig0CE1ulcoT4AQIxzwTvjecyvXxxmF364MRTuhK6U3goInJ Ps2iMyD+ZAkV4h2WTRKEXvvjLVdQkZsIrPhOlx6a2clGli4ejuFzopcT1HXvgeFNjVzq cQ5RoYt5yeNxY3IsskkfgJd6JSzcFgG/Jgzn3YUhnVfvFQwwegq1PzyhBKOMIxbkE85B nUiQ== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=T0Gr9ejuqBU5gH3HhPH6aITKeIKdA6uQcfzNPk8llIw=; b=No+rQFKSw4aa3n0oke5/61fGo7jIZhBujDLSRNYjzVg2d6slDvKi6OWDqVH/7XYBHM rf8vK0yPSu4ZK8TJ+BNEDdHATN8h22mSQrEJmtPeLa5KF7IlFqEJWGsKKVSXziPYQScN WUIjazZPMqTUbNSQyIOSCnbav9VI2F84OcR4hS1VgqkXijlD4y3nVlLziOp2HZCe3FoE qTefOMilXkx1ZZzWqXCJdfopEmn2e379NqsqsBKeCqJx46Gz6s1Ek/6Zarmj4iGNKA/W 8AuYg4E3XcB+MiNx97EF+dGuz0wJb4oc5lgb8OoMo+Oz5MM0wejkVkLpk2iMNyRd4WdL fFVA== X-Gm-Message-State: APt69E3W7XVNevgwIG8KbYjYJvPPlJAE9cqrogRKwCHLaRlfUeU0Vqyt zOJ9iCIcb7k8uU29vDfGEASNKg== X-Received: by 2002:a17:902:a9ca:: with SMTP id b10-v6mr28811471plr.275.1530598903817; Mon, 02 Jul 2018 23:21:43 -0700 (PDT) Received: from localhost.localdomain ([203.205.141.123]) by smtp.googlemail.com with ESMTPSA id v89-v6sm1766427pfd.64.2018.07.02.23.21.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 02 Jul 2018 23:21:43 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Vitaly Kuznetsov Subject: [PATCH v3 4/6] KVM: X86: Implement PV IPIs send hypercall Date: Tue, 3 Jul 2018 14:21:29 +0800 Message-Id: <1530598891-21370-5-git-send-email-wanpengli@tencent.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530598891-21370-1-git-send-email-wanpengli@tencent.com> References: <1530598891-21370-1-git-send-email-wanpengli@tencent.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wanpeng Li Using hypercall to send IPIs by one vmexit instead of one by one for xAPIC/x2APIC physical mode and one vmexit per-cluster for x2APIC cluster mode. Intel guest can enter x2apic cluster mode when interrupt remmaping is enabled in qemu, however, latest AMD EPYC still just supports xapic mode which can get great improvement by PV IPIs. Hardware: Xeon Skylake 2.5GHz, 2 sockets, 40 cores, 80 threads, the VM is 80 vCPUs, IPI microbenchmark(https://lkml.org/lkml/2017/12/19/141): x2apic cluster mode, vanilla Dry-run: 0, 2392199 ns Self-IPI: 6907514, 15027589 ns Normal IPI: 223910476, 251301666 ns Broadcast IPI: 0, 9282161150 ns Broadcast lock: 0, 8812934104 ns x2apic cluster mode, pv-ipi Dry-run: 0, 2449341 ns Self-IPI: 6720360, 15028732 ns Normal IPI: 228643307, 255708477 ns Broadcast IPI: 0, 7572293590 ns => 22% performance boost Broadcast lock: 0, 8316124651 ns x2apic physical mode, vanilla Dry-run: 0, 3135933 ns Self-IPI: 8572670, 17901757 ns Normal IPI: 226444334, 255421709 ns Broadcast IPI: 0, 19845070887 ns Broadcast lock: 0, 19827383656 ns x2apic physical mode, pv-ipi Dry-run: 0, 2446381 ns Self-IPI: 6788217, 15021056 ns Normal IPI: 219454441, 249583458 ns Broadcast IPI: 0, 7806540019 ns => 154% performance boost Broadcast lock: 0, 9143618799 ns Cc: Paolo Bonzini Cc: Radim Krčmář Cc: Vitaly Kuznetsov Signed-off-by: Wanpeng Li --- Documentation/virtual/kvm/hypercalls.txt | 6 ++++++ arch/x86/kvm/x86.c | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Documentation/virtual/kvm/hypercalls.txt b/Documentation/virtual/kvm/hypercalls.txt index a890529..a771ee8 100644 --- a/Documentation/virtual/kvm/hypercalls.txt +++ b/Documentation/virtual/kvm/hypercalls.txt @@ -121,3 +121,9 @@ compute the CLOCK_REALTIME for its clock, at the same instant. Returns KVM_EOPNOTSUPP if the host does not use TSC clocksource, or if clock type is different than KVM_CLOCK_PAIRING_WALLCLOCK. + +6. KVM_HC_SEND_IPI +------------------------ +Architecture: x86 +Status: active +Purpose: Hypercall used to send IPIs. diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 0046aa7..46657ef 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6689,6 +6689,39 @@ static void kvm_pv_kick_cpu_op(struct kvm *kvm, unsigned long flags, int apicid) kvm_irq_delivery_to_apic(kvm, NULL, &lapic_irq, NULL); } +/* + * Return 0 if successfully added and 1 if discarded. + */ +static int kvm_pv_send_ipi(struct kvm *kvm, unsigned long ipi_bitmap_low, + unsigned long ipi_bitmap_high, int vector) +{ + int i; + struct kvm_apic_map *map; + struct kvm_vcpu *vcpu; + struct kvm_lapic_irq irq = { + .delivery_mode = APIC_DM_FIXED, + .vector = vector, + }; + + rcu_read_lock(); + map = rcu_dereference(kvm->arch.apic_map); + + for_each_set_bit(i, &ipi_bitmap_low, BITS_PER_LONG) { + vcpu = map->phys_map[i]->vcpu; + if (!kvm_apic_set_irq(vcpu, &irq, NULL)) + return 1; + } + + for_each_set_bit(i, &ipi_bitmap_high, BITS_PER_LONG) { + vcpu = map->phys_map[i + BITS_PER_LONG]->vcpu; + if (!kvm_apic_set_irq(vcpu, &irq, NULL)) + return 1; + } + + rcu_read_unlock(); + return 0; +} + void kvm_vcpu_deactivate_apicv(struct kvm_vcpu *vcpu) { vcpu->arch.apicv_active = false; @@ -6737,6 +6770,9 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu) case KVM_HC_CLOCK_PAIRING: ret = kvm_pv_clock_pairing(vcpu, a0, a1); break; + case KVM_HC_SEND_IPI: + ret = kvm_pv_send_ipi(vcpu->kvm, a0, a1, a2); + break; #endif default: ret = -KVM_ENOSYS; -- 2.7.4