Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966940AbbDXQIs (ORCPT ); Fri, 24 Apr 2015 12:08:48 -0400 Received: from mail-bl2on0118.outbound.protection.outlook.com ([65.55.169.118]:43264 "EHLO na01-bl2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S966397AbbDXQIo (ORCPT ); Fri, 24 Apr 2015 12:08:44 -0400 X-Greylist: delayed 919 seconds by postgrey-1.27 at vger.kernel.org; Fri, 24 Apr 2015 12:08:43 EDT Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; dkim=none (message not signed) header.d=none; From: Bogdan Purcareata To: , , , , , , , , , Subject: [PATCH v2 1/2] powerpc/kvm: Convert openpic lock to raw_spinlock Date: Fri, 24 Apr 2015 15:53:12 +0000 Message-ID: <1429890793-19487-2-git-send-email-bogdan.purcareata@freescale.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1429890793-19487-1-git-send-email-bogdan.purcareata@freescale.com> References: <1429890793-19487-1-git-send-email-bogdan.purcareata@freescale.com> X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.158.2;CTRY:US;IPV:NLI;EFV:NLI;BMV:1;SFV:NSPM;SFS:(10019020)(6009001)(339900001)(199003)(189002)(104016003)(229853001)(107886001)(48376002)(105606002)(36756003)(33646002)(85426001)(106466001)(47776003)(50466002)(50986999)(76176999)(19580395003)(19580405001)(2950100001)(6806004)(77156002)(92566002)(62966003)(15975445007)(77096005)(2201001)(46102003)(87936001)(49486002)(50226001)(5001770100001)(921003)(21314002)(1121003)(4001450100001)(2101003);DIR:OUT;SFP:1102;SCL:1;SRVR:BY2PR03MB315;H:az84smr01.freescale.net;FPR:;SPF:Fail;MLV:sfv;A:1;MX:1;LANG:en; MIME-Version: 1.0 Content-Type: text/plain X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB315; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(601004)(5005006)(5002010)(3002001);SRVR:BY2PR03MB315;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB315; X-Forefront-PRVS: 05568D1FF7 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Apr 2015 15:53:22.0175 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d;Ip=[192.88.158.2];Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR03MB315 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6335 Lines: 200 The lock in the KVM openpic emulation on PPC is a spinlock_t, meaning it becomes a sleeping mutex under PREEMPT_RT_FULL. This yields to a situation where this non-raw lock is grabbed with interrupts already disabled by hard_irq_disable(): kvmppc_prepare_to_enter() hard_irq_disable() kvmppc_core_prepare_to_enter() kvmppc_core_check_exceptions() kvmppc_booke_irqprio_deliver() kvmppc_mpic_set_epr() spin_lock_irqsave() ... This happens for guest interrupts that go through this openpic emulation code. The result is a kernel crash on guest enter (include/linux/kvm_host.h:784). Converting the lock to a raw_spinlock fixes the issue and enables the guest to run I/O intensive workloads in a SMP configuration. A similar fix can be found for the i8254 PIT emulation on x86 [1]. [1] https://lkml.org/lkml/2010/1/11/289 v2: - updated commit message Signed-off-by: Bogdan Purcareata --- arch/powerpc/kvm/mpic.c | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c index 6249cdc..2f70660 100644 --- a/arch/powerpc/kvm/mpic.c +++ b/arch/powerpc/kvm/mpic.c @@ -196,7 +196,7 @@ struct openpic { int num_mmio_regions; gpa_t reg_base; - spinlock_t lock; + raw_spinlock_t lock; /* Behavior control */ struct fsl_mpic_info *fsl; @@ -1103,9 +1103,9 @@ static int openpic_cpu_write_internal(void *opaque, gpa_t addr, mpic_irq_raise(opp, dst, ILR_INTTGT_INT); } - spin_unlock(&opp->lock); + raw_spin_unlock(&opp->lock); kvm_notify_acked_irq(opp->kvm, 0, notify_eoi); - spin_lock(&opp->lock); + raw_spin_lock(&opp->lock); break; } @@ -1180,12 +1180,12 @@ void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) int cpu = vcpu->arch.irq_cpu_id; unsigned long flags; - spin_lock_irqsave(&opp->lock, flags); + raw_spin_lock_irqsave(&opp->lock, flags); if ((opp->gcr & opp->mpic_mode_mask) == GCR_MODE_PROXY) kvmppc_set_epr(vcpu, openpic_iack(opp, &opp->dst[cpu], cpu)); - spin_unlock_irqrestore(&opp->lock, flags); + raw_spin_unlock_irqrestore(&opp->lock, flags); } static int openpic_cpu_read_internal(void *opaque, gpa_t addr, @@ -1386,9 +1386,9 @@ static int kvm_mpic_read(struct kvm_vcpu *vcpu, return -EINVAL; } - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); ret = kvm_mpic_read_internal(opp, addr - opp->reg_base, &u.val); - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); /* * Technically only 32-bit accesses are allowed, but be nice to @@ -1427,10 +1427,10 @@ static int kvm_mpic_write(struct kvm_vcpu *vcpu, return -EOPNOTSUPP; } - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); ret = kvm_mpic_write_internal(opp, addr - opp->reg_base, *(const u32 *)ptr); - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); pr_debug("%s: addr %llx ret %d val %x\n", __func__, addr, ret, *(const u32 *)ptr); @@ -1501,14 +1501,14 @@ static int access_reg(struct openpic *opp, gpa_t addr, u32 *val, int type) if (addr & 3) return -ENXIO; - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); if (type == ATTR_SET) ret = kvm_mpic_write_internal(opp, addr, *val); else ret = kvm_mpic_read_internal(opp, addr, val); - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); pr_debug("%s: type %d addr %llx val %x\n", __func__, type, addr, *val); @@ -1545,9 +1545,9 @@ static int mpic_set_attr(struct kvm_device *dev, struct kvm_device_attr *attr) if (attr32 != 0 && attr32 != 1) return -EINVAL; - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); openpic_set_irq(opp, attr->attr, attr32); - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); return 0; } @@ -1592,9 +1592,9 @@ static int mpic_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) if (attr->attr > MAX_SRC) return -EINVAL; - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); attr32 = opp->src[attr->attr].pending; - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); if (put_user(attr32, (u32 __user *)(long)attr->addr)) return -EFAULT; @@ -1670,7 +1670,7 @@ static int mpic_create(struct kvm_device *dev, u32 type) opp->kvm = dev->kvm; opp->dev = dev; opp->model = type; - spin_lock_init(&opp->lock); + raw_spin_lock_init(&opp->lock); add_mmio_region(opp, &openpic_gbl_mmio); add_mmio_region(opp, &openpic_tmr_mmio); @@ -1743,7 +1743,7 @@ int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, if (cpu < 0 || cpu >= MAX_CPU) return -EPERM; - spin_lock_irq(&opp->lock); + raw_spin_lock_irq(&opp->lock); if (opp->dst[cpu].vcpu) { ret = -EEXIST; @@ -1766,7 +1766,7 @@ int kvmppc_mpic_connect_vcpu(struct kvm_device *dev, struct kvm_vcpu *vcpu, vcpu->arch.epr_flags |= KVMPPC_EPR_KERNEL; out: - spin_unlock_irq(&opp->lock); + raw_spin_unlock_irq(&opp->lock); return ret; } @@ -1796,9 +1796,9 @@ static int mpic_set_irq(struct kvm_kernel_irq_routing_entry *e, struct openpic *opp = kvm->arch.mpic; unsigned long flags; - spin_lock_irqsave(&opp->lock, flags); + raw_spin_lock_irqsave(&opp->lock, flags); openpic_set_irq(opp, irq, level); - spin_unlock_irqrestore(&opp->lock, flags); + raw_spin_unlock_irqrestore(&opp->lock, flags); /* All code paths we care about don't check for the return value */ return 0; @@ -1810,14 +1810,14 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e, struct openpic *opp = kvm->arch.mpic; unsigned long flags; - spin_lock_irqsave(&opp->lock, flags); + raw_spin_lock_irqsave(&opp->lock, flags); /* * XXX We ignore the target address for now, as we only support * a single MSI bank. */ openpic_msi_write(kvm->arch.mpic, MSIIR_OFFSET, e->msi.data); - spin_unlock_irqrestore(&opp->lock, flags); + raw_spin_unlock_irqrestore(&opp->lock, flags); /* All code paths we care about don't check for the return value */ return 0; -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/