From patchwork Tue Feb 11 18:23:31 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: 3628871 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 A8CC7BF418 for ; Tue, 11 Feb 2014 18:25:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BBFE020203 for ; Tue, 11 Feb 2014 18:25:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D2B05200F0 for ; Tue, 11 Feb 2014 18:25:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751313AbaBKSY6 (ORCPT ); Tue, 11 Feb 2014 13:24:58 -0500 Received: from mail-qc0-f181.google.com ([209.85.216.181]:35713 "EHLO mail-qc0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750779AbaBKSY5 (ORCPT ); Tue, 11 Feb 2014 13:24:57 -0500 Received: by mail-qc0-f181.google.com with SMTP id e9so13479800qcy.40 for ; Tue, 11 Feb 2014 10:24:56 -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:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=CcVsmX+bWsnRLS9Y23l67cvvmuv2o7vthTe2ZeWCM9s=; b=JtnmMq3DFHh3vc1p4V72U8KZfxJo4Jpwo8Ax/PqQu+4oQ6ftK1NTICWKqnYsty32vG rgq5nmX2Y+eQ9IdbmPzUdDs54zFkq2w8Snyb37ns3iWolsuoodwvrKtYH0mRI0nfGi/y pGrJch/Xdg60eYp+moyHp1iWh6f9Fj48VNSYkq33XROxTDV4YiBOp4TKemhq9cgTSF9G hVJlI0utaC9eO31mX5CyxO1a+2YnU8R2Tb+Z7DdHCpkN7DhW8unTUO4FoGT9JM2kfXu9 urysOwvS+Adog/2iwils0b0yC5/d4ohaZiQ0WAN7sZ7Kex+DZbfPhFUa9q+JzUmi8JZS lAPg== X-Received: by 10.224.4.5 with SMTP id 5mr60194784qap.61.1392143096684; Tue, 11 Feb 2014 10:24:56 -0800 (PST) Received: from ERROL.INI.CMU.EDU (ERROL.INI.CMU.EDU. [128.2.16.43]) by mx.google.com with ESMTPSA id d7sm55040368qad.10.2014.02.11.10.24.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Feb 2014 10:24:56 -0800 (PST) Date: Tue, 11 Feb 2014 13:23:31 -0500 From: "Gabriel L. Somlo" To: kvm@vger.kernel.org, qemu-devel@nongnu.org Cc: mst@redhat.com, eddie.dong@intel.com, agraf@suse.de Subject: RFC: ioapic polarity vs. qemu os-x guest Message-ID: <20140211182330.GC29329@ERROL.INI.CMU.EDU> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20140130204423.GK29329@ERROL.INI.CMU.EDU> 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=-7.4 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 Hi, I'm trying to get OS X to work as a QEMU guest, and one of the few remaining "mysteries" I need to solve is that the OS X guest hangs during boot, waiting for its boot disk to be available, unless the following KVM patch is applied: --- After digging around the KVM source for a bit, and printk-ing things from Windows 7, Fedora 20, and OS X (10.9), I figured out the following: 1. Edge-triggered interrupts are invariably unaffected by the xor line being removed by the patch. On all three guest types, edge-triggered interrupts have polarity set to 0, so the xor is essentially a no-op, and we can forget about it altogether. 2. Windows and Linux always configure all level-triggered interrupts with polarity 0 (active-high, consistent with QEMU's ACPI/DSDT, in particular q35-acpi-dsdt.dsl, which is what I'm using with -M q35). As such, on Windows and Linux, the xor line in question is still a no-op. 3. OS X (all versions I tried, at least since 10.5/Leopard) always configures all level-triggered interrupts with polarity 1 (active-low), regardless of what the QEMU DSDT says. As such, the xor line acts as a negation of "irq_level", which at first glance sounds reasonable. However: when KVM negates "irq_level" due to "polarity == 1", the OS X guest hangs during boot. OS X works fine when "polarity == 1" is ignored (with the xor line commented out). This may be another instance (similar to how OS X didn't use to check with CPUID regarding monitor/mwait instruction availability) where apple devs know that any of their supported hardware advertises active-low in the DSDT, so no need to check, just hardcode that assumption... :) 4. With s/ActiveHigh/ActiveLow/ in QEMU's q35-acpi-dsdt.dsl, Linux actually switches to "polarity == 1" (active-low), and works fine *with the xor line removed* !!!. With the xor line left intact (i.e. without the above patch), the active-low fedora guest worked extremely poorly, and printed out multiple error messages during boot: irq XX: nobody cared (try booting with the "irqpoll" option) ... Disabling IRQ #XX for XX in [16, 18, 19, ...]. So, right now, I'm wondering about the following: 1. Regarding KVM and the polarity xor line in the patch above: Does anyone have experience with any *other* guests which insist on setting level-triggered interrupt polarity to 1/active-low ? Is that xor line actually doing anything useful in practice, for any other guest, on either QEMU or any other platform ? 2. Is there anything in QEMU (besides the ACPI DSDT .dsl files) which has a hardcoded assumption re. "polarity == 0", or active-high, for level-triggered interrupts? I tried to dig through hw/i386/kvm/ioapic.c and a bunch of other files, but couldn't isolate anything that I could "flip" to fix things in userspace. Any ideas or suggestions about the appropriate way to move forward would be much appreciated !!! Thanks much, --Gabriel -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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;