From patchwork Thu Aug 17 08:21:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Zyngier X-Patchwork-Id: 9905297 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 309736038C for ; Thu, 17 Aug 2017 08:21:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F852286B6 for ; Thu, 17 Aug 2017 08:21:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1449428AD2; Thu, 17 Aug 2017 08:21:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8174286B6 for ; Thu, 17 Aug 2017 08:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbdHQIVd (ORCPT ); Thu, 17 Aug 2017 04:21:33 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:45700 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750857AbdHQIVc (ORCPT ); Thu, 17 Aug 2017 04:21:32 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DED5780D; Thu, 17 Aug 2017 01:21:31 -0700 (PDT) Received: from [10.1.207.16] (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id CED083F483; Thu, 17 Aug 2017 01:21:30 -0700 (PDT) Subject: Re: PCIe oops for NULL pointer dereference during next-20170807 and next-20170815 To: Joerg Roedel , Shawn Lin Cc: Robin Murphy , "linux-pci@vger.kernel.org" , iommu@lists.linux-foundation.org, Bjorn Helgaas References: <2ac52f40-c34f-6c31-b8db-868c40a977a3@rock-chips.com> <20170817075825.GR30515@8bytes.org> From: Marc Zyngier Organization: ARM Ltd Message-ID: <94b7e141-362d-02f3-1403-af7a1dfc8c4e@arm.com> Date: Thu, 17 Aug 2017 09:21:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: <20170817075825.GR30515@8bytes.org> Content-Language: en-GB Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 17/08/17 08:58, Joerg Roedel wrote: > On Thu, Aug 17, 2017 at 03:02:31PM +0800, Shawn Lin wrote: >> So should we revert this commit or maybe we could add some checking >> into gic-v2m and gic-v3-its to see if the dev is iommu-capable? If not, >> we should create another routine to map MSI msg. > > Yes, fixing this in gic code is the right approach. I usually don't > revert patches to hide problems somewhere else. Here's what it would look like: I'm not convinced that playing with the group refcount in an irqchip is the right approach... Thanks, M. diff --git a/drivers/irqchip/irq-gic-v3-its.c b/drivers/irqchip/irq-gic-v3-its.c index b47097a3e4b4..5e81ad62c801 100644 --- a/drivers/irqchip/irq-gic-v3-its.c +++ b/drivers/irqchip/irq-gic-v3-its.c @@ -1125,6 +1125,8 @@ static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg) { struct its_device *its_dev = irq_data_get_irq_chip_data(d); struct its_node *its; + struct iommu_group *group; + struct device *dev; u64 addr; its = its_dev->its; @@ -1134,7 +1136,12 @@ static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg) msg->address_hi = upper_32_bits(addr); msg->data = its_get_event_id(d); - iommu_dma_map_msi_msg(d->irq, msg); + dev = msi_desc_to_dev(irq_get_msi_desc(d->irq)); + group = iommu_group_get(dev); + if (group) { + iommu_dma_map_msi_msg(d->irq, msg); + iommu_group_put(group); + } } static int its_irq_set_irqchip_state(struct irq_data *d,