Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2155891ybz; Thu, 23 Apr 2020 12:35:16 -0700 (PDT) X-Google-Smtp-Source: APiQypI0s1QpoktrLHYWlMk+oM5Z+ZaRx+DGewOMZoZieZnZGU90KdfMTwSZe2zYBibsZi8w8Etn X-Received: by 2002:a50:f98c:: with SMTP id q12mr4375564edn.172.1587670516191; Thu, 23 Apr 2020 12:35:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587670516; cv=none; d=google.com; s=arc-20160816; b=BBnOSkFqdq8XX9sBRe/gUXzPJPPV/o6Db/pQly6dSM3QTWF3vwiLfqItxjI1pZE0oU OZkAAd4WGhC4mV9vgEW3z7anD/vfe0JYlJBN1nOoCHjgn+F+BuSyxq2k3SEdgahbpRGK nhb8jZc8VLRRguqlx7BDOyixYuN2aZpbfLdBwoTiXijJmbK8D+xwqfwZSjdKKHk97hf5 bdIsVnbN4RVGQWa1Lrg+uQbeJEiEdA1DAo7Q+ABRR6CEkMfV1kRqK0EjulZyQSzvwl5i UklNMIX9V0ainv39t5owlb1LpjoF8CFtlsaOF+j522Yi0lYgh3GE4B1ylOekphvpZxcT rZHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tRcc4dh6p+YiX6AX0x9LFumoCa/KOTeSvRHxboIV+LM=; b=rU5LnehyUXxsP+Xvf2yPCJQOMUquG4ARhB6qThXiu8OM53tvuFpBqPF7Hzn7c3hEo6 iClgWDcsqUZ/bBR42RhaaZHZjzWiMsxWPLCX3xM5UG+Si53fN0LGeYBthCeHjfjFBIP5 qByR6tR0xZoQoNP+FbOEmfzC5YbFAmg3qMsw6xWJ6wFUckrbDhIwD5ZJ/i0wxhPbAOuw ka3jSAuBgzxit/5jpEC97QwXIBZGAuYI93mj9tjrDtv/13o6nPmdiPuzXsJ3kZG7UpmY cHn4Ez22mnZcK7WCcUU3wnQn/h2RxfLXYpUy/Vj6QiWuKGATgRDVHr6McbzIKCj1FIqN TVZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=j7pfI9HR; 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 m26si1735018edp.0.2020.04.23.12.34.52; Thu, 23 Apr 2020 12:35:16 -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=j7pfI9HR; 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 S1729821AbgDWQrW (ORCPT + 99 others); Thu, 23 Apr 2020 12:47:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729661AbgDWQrW (ORCPT ); Thu, 23 Apr 2020 12:47:22 -0400 Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE421C09B042 for ; Thu, 23 Apr 2020 09:47:21 -0700 (PDT) Received: by mail-lf1-x144.google.com with SMTP id m2so5300428lfo.6 for ; Thu, 23 Apr 2020 09:47:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tRcc4dh6p+YiX6AX0x9LFumoCa/KOTeSvRHxboIV+LM=; b=j7pfI9HRuHbfl6xDZAoT1l4rmuUPF/dN6vFtceByAi7aVXx7F1IhQrRueEZwe2jLz1 LPlirCZaXLDgzEX7pBzBcH8BRbSUtwv0Fr/Xr7mNnYMI5n+kQPaevi4KoW9j2YpIE//B 4gbwSpLKTsk8a6DjpzFLCRYnmZfFffJuXd7sHUWBrzm2DdCAF+LnMir8CtAVeZNUPhEU o5wYq8dSbv5PpSnJvBS+3XV8BSWMUTvt8MM/+jOXHe9XtwOMnpE3dECt2rI/zXksJFfP 1kIeQP0cTexZxF2UhgelMN3dbj6HEeRfpwsJgbRgWYigveFkQHwaL2ZSdpLI9edvCOU1 jdbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tRcc4dh6p+YiX6AX0x9LFumoCa/KOTeSvRHxboIV+LM=; b=iERMm86kr2TZp7s1AIdfok+7ihOsYAgjiVUqWdv9i6ag5S1GKcOBeEKCSqlHlGOzFU R1a6byIgknXa2e+d8FZsrVoCb52XEJ1oRTIAP7nINto2ffx3qnDT+8FYR/NaN3UUYZz9 Feg9zL2xljqLzCqd80xRXDEMP7+aYxF6LjVuhZiTaUoBT69fyeMNPvxMle+T7j06a0Dm f3akeJFlni42qMuwPoN2Hq8oKluYd55ntAQZtd/jdj0iqZ+tHnwdROBCZP9KrvX3DcBO 1fnb7wsB5HQjCNQX5SrjOZf5oy64RKj/A8spBoVl+oo4aoBF5VuzOYcoFI69sioNyKWR DfIg== X-Gm-Message-State: AGi0PubndTIS+rQfd5RbxzEFHKGoEbXJO78dzdxX9q9wqXvwGeO5zjUf 4fBJolcp7TNGSjBjfOuT88twVN7yNUV026krTnNRTQ== X-Received: by 2002:ac2:4853:: with SMTP id 19mr2882072lfy.171.1587660440070; Thu, 23 Apr 2020 09:47:20 -0700 (PDT) MIME-Version: 1.0 References: <1587607101-31914-1-git-send-email-alan.mikhak@sifive.com> In-Reply-To: From: Alan Mikhak Date: Thu, 23 Apr 2020 09:47:08 -0700 Message-ID: Subject: Re: [PATCH v2][next] dmaengine: dw-edma: Check MSI descriptor before copying To: Gustavo Pimentel Cc: "dmaengine@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" , "dan.j.williams@intel.com" , "vkoul@kernel.org" , "kishon@ti.com" , "maz@kernel.org" , "paul.walmsley@sifive.com" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2020 at 2:28 AM Gustavo Pimentel wrote: > > On Thu, Apr 23, 2020 at 2:58:21, Alan Mikhak > wrote: > > > 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://urldefense.com/v3/__https://patchwork.kernel.org/patch/11491757/__;!!A4F2R9G_pg!L_vf_Tml7Ca4sWVvZp5crRCp7YsMj6B93G9cMAO8Dj3w9I0MArjwuwNKtDz9rr0RlpXiqPg$ > > > > Rebased on linux-next which has above patch applied. > > > > Fixes: Build error with config x86_64-randconfig-f003-20200422 > > Fixes: Build error with config s390-allmodconfig > > Reported-by: kbuild test robot > > Signed-off-by: Alan Mikhak > > --- > > drivers/dma/dw-edma/dw-edma-core.c | 17 ++++++++++------- > > 1 file changed, 10 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..306ab50462be 100644 > > --- a/drivers/dma/dw-edma/dw-edma-core.c > > +++ b/drivers/dma/dw-edma/dw-edma-core.c > > @@ -13,6 +13,7 @@ > > #include > > #include > > #include > > +#include > > #include > > #include > > > > @@ -773,6 +774,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 +783,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 +806,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 +818,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 > > > Acked-by: Gustavo Pimentel Thanks Gustavo for the Ack. FYI, I first considered adding an ops function to decouple dw-edma-core.c from struct msi_msg. However, in a separate use case that I have in mind, dw-edma would run on a host system having Synopsys DesignWare PCI eDMA hardware on the host-side. In this use case, the host system eDMA engines may be used in conjunction with an endpoint device also having the same eDMA hardware. In this use case, dw-edma running on the host would need to call get_cached_msi_msg() just in case the host has an msi_msg cached from the endpoint device. As a result, I opted to not add a new ops function. Regards, Alan > >