Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp3889371ybz; Mon, 20 Apr 2020 11:17:51 -0700 (PDT) X-Google-Smtp-Source: APiQypJtK+i+JRzdNKe7vAV75P6k8OtjzF+Mvm+HWkI/rsFF88ZUqpiL5opX2uVbOJEsKYE0Ci8L X-Received: by 2002:a05:6402:1b08:: with SMTP id by8mr15449173edb.286.1587406671151; Mon, 20 Apr 2020 11:17:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587406671; cv=none; d=google.com; s=arc-20160816; b=SBKYJxmMFEI9e86W/rmKaA/6lHwqYb8hhqywIXmlPvM8tbPSW5w88ziZETfc7x/BIv D6Ny+CmxRjEJNGGz1M0sfjfON9OUhTgEj/H8XmqObDzABssZOF1n+EjiiVPMLOj1/kGN 3zrjgGU5GpXjX5QT9NlJSUl1yRPyatabsp5bzIWRx2mi9RxPJQ6fe3YCF9j+slP/14Ei 7/HzaKeOAWX1gqGk2mgvOvt/Djwd00KF1wN81BaEquB7UEvvGJ4ynZGVDpHp8rDKCT3D LqHHqbTHSfc5OFIw1aXuyrnGHlQMaVkfaVlZXuFOut4NLk1QX1M7VM6ldairQTQayNJo lzxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=QUQCSO3sl8PGNrXa4jdtXmAY28M49Ft4G5H9JTodPcw=; b=L2Un5YB3YpXH86vwuhtmYbrWvOzMM2tY/rRKfj71utmQwmQW0Ea70EH3Koudek9jav HDqqc6kuVl8v0w3Nswy+W9DvNQGZxiP5KXRcLEK+5X9IWHG8I0aNBKD2ukAh4K12a4to HEOmLmG4fwzD1qAJmDNQfJ37SBcNHV1+ErI9KeWbZM7ah+r/5/Sfuk9pQHeT5tctCbAG RQsKq9a09cvqm24BJ1Vt2lQdw/hU9Wor4cFdhQQ3TRAUjoJLZ6rduk5+2tHuyFIIOzab VO5SHFUBs70pB+p040s/abHP9dfwcO03+cTR+pFkO69n7r/NtViuYYomyeaiQlUZZMDK LgKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=CYie8fSQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 31si136020edp.496.2020.04.20.11.17.19; Mon, 20 Apr 2020 11:17:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=CYie8fSQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726420AbgDTSQR (ORCPT + 99 others); Mon, 20 Apr 2020 14:16:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725891AbgDTSQQ (ORCPT ); Mon, 20 Apr 2020 14:16:16 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9671FC061A0F for ; Mon, 20 Apr 2020 11:16:16 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id y25so5335737pfn.5 for ; Mon, 20 Apr 2020 11:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id; bh=QUQCSO3sl8PGNrXa4jdtXmAY28M49Ft4G5H9JTodPcw=; b=CYie8fSQkf91EabFDU6MKKRA6RXg/CIZ6raAEDtACsf+pAkhaGG3bA/B7ftMPTNAzv PcogpFXonbLQ+YmmSUkglNSbsfn7wqDj82SDGr5L8FhFSAg0MYrfkfx9CStopUgtgm5q 3L/ERws+4oT7z6ZdWKWaWCMBSf8jT3UD1zJOpHfQzDqy4j9DQ2QkluudG3Vl6MAi1Cnc GMciq0L9RcR+K3OlOGAp5F4E4W3lubJ0/CJtYOScGbaomeCpHasbIajOwgHvgt13m71K l5K/vBMgIGr9lwThmMxps+a+zMnWb1rKMDbiFJPqMMvoUkgVfLGC/xMdRcGmyPWoYJTD fsIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QUQCSO3sl8PGNrXa4jdtXmAY28M49Ft4G5H9JTodPcw=; b=Y4uSMutqkaKWO0G/hmrJn4kdEyjJYbtxNOO8k5YM/UkiwIJDqlfk8gIxssdzYpVimo LtrdJFWMnrUMnBCySjv3uArL5jiJZMSAgPIJyUM7ybCFWgfGHapkJjlKHUJhqf2aicCg cjkt+FZLGExguQ35eGTSg1LKvmL0pWp+434/eHBrHSDBVhKl5iOj6caFIHTTzHhdLAjg 6YTtMpzA2kPRoI7JmNLAKSv13TLWIn0GWfRlslpbNzyc6DeaSjZD3ot0B8qG2xIOSPyE znFqUmJMXoEJfhhKQ9jGkVfe6om+dJxBg9XLE9JawHo1hqmBSe+w1tA3K3faX9FL7vrj GlZg== X-Gm-Message-State: AGi0PuYSQz0UDmFnFZ9EupVPhcDRx26wfdqG3VOOwOIftEMesye2mtZC 7VNfhRzKB/MNaYvnIoosSlvUvw== X-Received: by 2002:a62:874e:: with SMTP id i75mr9560713pfe.248.1587406575986; Mon, 20 Apr 2020 11:16:15 -0700 (PDT) Received: from nuc7.sifive.com (c-24-5-48-146.hsd1.ca.comcast.net. [24.5.48.146]) by smtp.gmail.com with ESMTPSA id t6sm150753pfh.98.2020.04.20.11.16.13 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 20 Apr 2020 11:16:14 -0700 (PDT) From: Alan Mikhak X-Google-Original-From: Alan Mikhak < alan.mikhak@sifive.com > To: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, gustavo.pimentel@synopsys.com, dan.j.williams@intel.com, vkoul@kernel.org, kishon@ti.com, maz@kernel.org, paul.walmsley@sifive.com Cc: Alan Mikhak Subject: [PATCH] dmaengine: dw-edma: Check MSI descriptor before copying Date: Mon, 20 Apr 2020 11:16:08 -0700 Message-Id: <1587406568-26592-1-git-send-email-alan.mikhak@sifive.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Mikhak Modify dw_edma_irq_request() to check if a struct msi_desc entry exists before copying the contents of its struct msi_msg pointer. Without this sanity check, __get_cached_msi_msg() crashes when invoked by dw_edma_irq_request() running on a Linux-based PCIe endpoint device. MSI interrupt are not received by PCIe endpoint devices. If irq_get_msi_desc() returns null, then there is no cached struct msi_msg to be copied. This patch depends on the following patch: [PATCH v2] dmaengine: dw-edma: Decouple dw-edma-core.c from struct pci_dev https://patchwork.kernel.org/patch/11491757/ Signed-off-by: Alan Mikhak --- drivers/dma/dw-edma/dw-edma-core.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/dma/dw-edma/dw-edma-core.c b/drivers/dma/dw-edma/dw-edma-core.c index db401eb11322..a5d15f6ed5eb 100644 --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -773,6 +773,7 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, u32 rd_mask = 1; int i, err = 0; u32 ch_cnt; + int irq; ch_cnt = dw->wr_ch_cnt + dw->rd_ch_cnt; @@ -781,16 +782,16 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, if (dw->nr_irqs == 1) { /* Common IRQ shared among all channels */ - err = request_irq(dw->ops->irq_vector(dev, 0), - dw_edma_interrupt_common, + irq = dw->ops->irq_vector(dev, 0); + err = request_irq(irq, dw_edma_interrupt_common, IRQF_SHARED, dw->name, &dw->irq[0]); if (err) { dw->nr_irqs = 0; return err; } - get_cached_msi_msg(dw->ops->irq_vector(dev, 0), - &dw->irq[0].msi); + if (irq_get_msi_desc(irq)) + get_cached_msi_msg(irq, &dw->irq[0].msi); } else { /* Distribute IRQs equally among all channels */ int tmp = dw->nr_irqs; @@ -804,7 +805,8 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, dw_edma_add_irq_mask(&rd_mask, *rd_alloc, dw->rd_ch_cnt); for (i = 0; i < (*wr_alloc + *rd_alloc); i++) { - err = request_irq(dw->ops->irq_vector(dev, i), + irq = dw->ops->irq_vector(dev, i); + err = request_irq(irq, i < *wr_alloc ? dw_edma_interrupt_write : dw_edma_interrupt_read, @@ -815,8 +817,8 @@ static int dw_edma_irq_request(struct dw_edma_chip *chip, return err; } - get_cached_msi_msg(dw->ops->irq_vector(dev, i), - &dw->irq[i].msi); + if (irq_get_msi_desc(irq)) + get_cached_msi_msg(irq, &dw->irq[i].msi); } dw->nr_irqs = i; -- 2.7.4