From patchwork Fri Jan 9 14:37:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFkaW0gS3LEjW3DocWZ?= X-Patchwork-Id: 5600341 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DDC01C058D for ; Fri, 9 Jan 2015 14:38:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29A552056E for ; Fri, 9 Jan 2015 14:38:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3BE5B204E4 for ; Fri, 9 Jan 2015 14:38:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756541AbbAIOiW (ORCPT ); Fri, 9 Jan 2015 09:38:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:39072 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750989AbbAIOiU (ORCPT ); Fri, 9 Jan 2015 09:38:20 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t09EcGjl012819 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Jan 2015 09:38:17 -0500 Received: from potion (dhcp-1-126.brq.redhat.com [10.34.1.126]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t09EcDiu003874; Fri, 9 Jan 2015 09:38:14 -0500 Received: by potion (sSMTP sendmail emulation); Fri, 09 Jan 2015 15:38:13 +0100 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= To: linux-kernel@vger.kernel.org Cc: kvm@vger.kernel.org, Paolo Bonzini , Gleb Natapov , Feng Wu Subject: [PATCH] KVM: x86: amend APIC lowest priority arbitration Date: Fri, 9 Jan 2015 15:37:26 +0100 Message-Id: <1420814246-19033-1-git-send-email-rkrcmar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Lowest priority should take the task priority into account. SDM 10.6.2.4 Lowest Priority Delivery Mode. (Too long to quote; second and last paragraphs are relevant.) Before this patch, we strived to have the same amount of handled lowest-priority interrupts on all VCPUs. This is only a complication, but kept for compatibility. Real modern Intels can't send lowest priority IPIs and the chipset directs external ones using processors' TPR. AMD still has rough edges. Signed-off-by: Radim Kr?má? --- arch/x86/kvm/lapic.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index a688fbffb34e..5b9d8c589bba 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -833,7 +833,15 @@ static int __apic_accept_irq(struct kvm_lapic *apic, int delivery_mode, int kvm_apic_compare_prio(struct kvm_vcpu *vcpu1, struct kvm_vcpu *vcpu2) { - return vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio; + /* XXX: AMD (2:16.6.2 Lowest Priority Messages and Arbitration) + * - uses the APR register (which also considers ISR and IRR), + * - chooses the highest APIC ID when APRs are identical, + * - and allows a focus processor. + * XXX: pseudo-balancing with apic_arb_prio is a KVM-specific feature + */ + int tpr = kvm_apic_get_reg(vcpu1->arch.apic, APIC_TASKPRI) - + kvm_apic_get_reg(vcpu2->arch.apic, APIC_TASKPRI); + return tpr ? : vcpu1->arch.apic_arb_prio - vcpu2->arch.apic_arb_prio; } static void kvm_ioapic_send_eoi(struct kvm_lapic *apic, int vector)