From patchwork Fri Feb 28 04:06:17 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gabriel L. Somlo" X-Patchwork-Id: 3738441 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2AA68BF13A for ; Fri, 28 Feb 2014 04:06:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46F552024D for ; Fri, 28 Feb 2014 04:06:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B738420240 for ; Fri, 28 Feb 2014 04:06:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751066AbaB1EG0 (ORCPT ); Thu, 27 Feb 2014 23:06:26 -0500 Received: from mail-qa0-f44.google.com ([209.85.216.44]:61860 "EHLO mail-qa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750942AbaB1EG0 (ORCPT ); Thu, 27 Feb 2014 23:06:26 -0500 Received: by mail-qa0-f44.google.com with SMTP id f11so168173qae.17 for ; Thu, 27 Feb 2014 20:06:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=zyz9ITBEKGcYM6ZkpBTWAzhtseRsgii3No8SQJVMK3M=; b=DMR8dhtzFyEEQcyKYdVuka3+g5dPDIkBy2zT4lBzN3pkewjlWhZevcfmKTrHvF+qGJ R5Akb+m/pkZvHhFgfSyMU3V1IFd1Vmm18PrvyrflCbgMWzJuXo+anliz2MeeiFgoNJaE lPyj8bCVgEs7Lw9Uby23/CZoUs0gAUKsGAgRteWPm4nEJ0+u5GgVEG91mdLuSb44vGXH dGs1IhnOnonxSkdOoG19quT9Sxg87n/vzOgPLlk7Rofp3uTdqkzKHirzAJxlwK6EJG9W C+1Zr2rBRow5ScgThPKVs36qSVD6nwbhpc0mLYH1AQ77VRwRTpjkJc4NS6+o8hq5mKG+ z7og== X-Received: by 10.224.57.142 with SMTP id c14mr681971qah.55.1393560385071; Thu, 27 Feb 2014 20:06:25 -0800 (PST) Received: from crash.ini.cmu.edu (pool-72-77-40-177.pitbpa.fios.verizon.net. [72.77.40.177]) by mx.google.com with ESMTPSA id z18sm1659746qab.5.2014.02.27.20.06.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Feb 2014 20:06:24 -0800 (PST) Date: Thu, 27 Feb 2014 23:06:17 -0500 From: "Gabriel L. Somlo" To: kvm@vger.kernel.org Cc: mst@redhat.com, pbonzini@redhat.com, alex.williamson@redhat.com, eddie.dong@intel.com, agraf@suse.de, qemu-devel@nongnu.org Subject: [RFC PATCH v2] kvm: x86: ignore ioapic polarity Message-ID: <20140228040617.GA22103@crash.ini.cmu.edu> References: <20140214220600.GI29329@ERROL.INI.CMU.EDU> <2CEB9F8C-E983-4182-A514-44EC568E18D8@suse.de> <20140216114151.GB30056@redhat.com> <1392562020.15608.437.camel@ul30vt.home> <20140216162300.GI30056@redhat.com> <20140227170549.GA23037@redhat.com> <20140227214102.GG17184@ERROL.INI.CMU.EDU> <530FBC9F.8080800@redhat.com> <20140227231312.GH17184@ERROL.INI.CMU.EDU> <530FCACF.40100@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <530FCACF.40100@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham 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 Both QEMU and KVM have already accumulated a significant number of optimizations based on the hard-coded assumption that ioapic polarity will always use the ActiveHigh convention, where the logical and physical states of level-triggered irq lines always match (i.e., active(asserted) == high == 1, inactive == low == 0). QEMU guests are expected to follow directions given via ACPI and configure the ioapic with polarity 0 (ActiveHigh). However, even when misbehaving guests (e.g. OS X <= 10.9) set the ioapic polarity to 1 (ActiveLow), QEMU will still use the ActiveHigh signaling convention when interfacing with KVM. This patch modifies KVM to completely ignore ioapic polarity as set by the guest OS, enabling misbehaving guests to work alongside those which comply with the ActiveHigh polarity specified by QEMU's ACPI tables. Signed-off-by: Michael S. Tsirkin Signed-off-by: Gabriel L. Somlo Acked-by: Michael S. Tsirkin --- On Fri, Feb 28, 2014 at 12:31:27AM +0100, Paolo Bonzini wrote: >>>This is a much better description. Can you turn it into a patch to >>>Documentation/virtual/kvm/api.txt and a more complete commit >>>message? OK, let me know what you all think of this version. > If you change ACPI tables to ActiveLow, and leave the polarity > inversion in hw/intc/ioapic.c, then it will matter. I only changed ACPI to ActiveLow to cause Linux to misbehave in the same way OS X does, it was a temporary/test hack. ACPI should stay ActiveHigh to reflect the rest of QEMU/KVM, and misbehaving guest OSs should ignore it at their own peril :) > >(Hmmm, maybe this one of the reasons I never got OS X to boot without > >-enable-kvm... I should look at the QEMU hw/intc/ioapic*.c, and see > >if *it* cares about guest-configured polarity, and maybe get it to > >*stop* caring :) > Exactly my point. :) So this patch gets the accelerated path to work regardless of how well-behaved a guest OS may or may not be w.r.t. ACPI and polarity. I'll try to find out whether it's possible to be *extra* nice to these types of guests by also allowing them to ignore ACPI polarity when not using acceleration :) Thanks again, Gabriel Documentation/virtual/kvm/api.txt | 18 ++++++++++++++++++ include/uapi/linux/kvm.h | 1 + virt/kvm/ioapic.c | 1 - 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 6cd63a9..0492a94 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -1365,6 +1365,24 @@ struct kvm_irq_routing_msi { __u32 pad; }; +NOTE: For each level-triggered interrupt managed by a virtual ioapic, +the guest OS may set a polarity value (bit 13 of each corresponding I/O +redirection table register). The polarity bit defines the relationship +between an irq line's logical state (active/asserted = 1, inactive = 0) +and its physical state (high = 1, low = 0). When the polarity bit is 0 +(ActiveHigh), logical and physical states are matched (active == high == 1, +inactive == low == 0). When polarity is set to 1 (ActiveLow), logical and +physical state are opposites (logical == !physical). Typically, guests are +expected to use the same polarity across all level-triggered interrupts, +as directed by ACPI. Historically, both KVM and QEMU have accumulated a +significant number of optimizations based on the hard-coded assumption +that polarity will always be set to ActiveHigh. When interfacing with KVM, +QEMU will use the ActiveHigh convention for all level-triggered irqs, +regardless of how the guest OS has configured the polarity bits in the +ioapic registers. As such, KVM must also ignore these bits, and always act +as if the logical and physical states of an irq line exactly match each +other (i.e., follow the ActiveHigh convention regardless of polarity). + 4.53 KVM_ASSIGN_SET_MSIX_NR diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 932d7f2..5bfc0e6 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -675,6 +675,7 @@ struct kvm_ppc_smmu_info { #define KVM_CAP_SPAPR_MULTITCE 94 #define KVM_CAP_EXT_EMUL_CPUID 95 #define KVM_CAP_HYPERV_TIME 96 +#define KVM_CAP_X86_IOAPIC_POLARITY_IGNORED 97 #ifdef KVM_CAP_IRQ_ROUTING diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index ce9ed99..1539d37 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c @@ -328,7 +328,6 @@ int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_id, irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq], irq_source_id, level); entry = ioapic->redirtbl[irq]; - irq_level ^= entry.fields.polarity; if (!irq_level) { ioapic->irr &= ~mask; ret = 1;