Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp124244ybz; Tue, 21 Apr 2020 16:46:07 -0700 (PDT) X-Google-Smtp-Source: APiQypKzgnigX1FiCsjB1gyeBPMKzxKs+bVqYVDRZreKs9VazXTedph8pQDYzlTLiXT3YewJCInf X-Received: by 2002:aa7:d306:: with SMTP id p6mr75653edq.35.1587512767062; Tue, 21 Apr 2020 16:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587512767; cv=none; d=google.com; s=arc-20160816; b=0g4eKZWsMPJB3ZFO+ZxRW1VMWKEdbd9almSVFj/tCg6q2LBK2JWnd5d2gj5byzKhuF eegEDCd1PLTOSWTmRObONcHttFDzU1AMah/9daEsi7j2Ioe53ZBY8X0Xzxtas9DYONRX 8fzy9KYr+iAZ6LDBffKJOQhtBAPe3Njptu/7KtYUgHg+4BKXsS3p9ggA7ecr+WIyPOs8 isTRlCGLT/71iIwpQEW67c27mIo9PEL3na55JydvJ7hRky/gHpFSoDJ+Kdv/aqnXVJfv AwmFKmD89nAKfGQqXC4bcYp8PJJAgmRD1fQQVVkKD31ZeRIrH8u7BBQBkvb3VxFPVDJn IOPw== 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=LQhtlsw1+T6reMAEhFyYFr2m8Qv3jouQUXJ8R8StFM8=; b=zCpYF8HVvAWduwssbcrWPQ4rQrV8EZDApACPooOetqOwQ2kYc80s+q2WYDTQ0AujN2 YWgIrsywnQ5usZhjoUL74K05Bf/U0yGh0vjuBPm4jxPK0/LQbIIm9a0uyonZ3iHL0CXp NxpEx6kfABtFiKGF/PvXAEOZmA1HzTWTCR25HNp6OfZZJrBayZWWZBu/bl6WdyvQw/RQ x0sALAL2r6Dvak36jk4qShKYxo+7nu0eYjV7+WxnQOzLEZYpAfyD8oLOYFMoK9+mpxsQ NLB3Bd0Fz0k4jwK2gC2EnaDJm4cjLt5B+7USxJhToX3G4d6AQXHZJ2DuZHCLk89YjgN+ ApIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=S4jVdIKl; 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 h7si1452355eds.336.2020.04.21.16.45.43; Tue, 21 Apr 2020 16:46:07 -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=S4jVdIKl; 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 S1726328AbgDUXog (ORCPT + 99 others); Tue, 21 Apr 2020 19:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726039AbgDUXof (ORCPT ); Tue, 21 Apr 2020 19:44:35 -0400 Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84F87C0610D5 for ; Tue, 21 Apr 2020 16:44:34 -0700 (PDT) Received: by mail-lf1-x143.google.com with SMTP id 198so133581lfo.7 for ; Tue, 21 Apr 2020 16:44:34 -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=LQhtlsw1+T6reMAEhFyYFr2m8Qv3jouQUXJ8R8StFM8=; b=S4jVdIKlRsEiRGbtdIe4araEhiFTR6d+6KJqowgAjs2Aw6i7qWq9+rhzeWPW20Lwyv JhvwC5N0zDc010k/ZQ+WQZZcJc/egZZBd/t6Y4mO8M8oWzOIXkF4OQfuGBD1CUnwuMRh WNQD8NykXmqQHrYCtadUapSWEhcTe8FKW9ISCfS9PMxycykPibhwsI+BAq5OCxBcfoA/ BDaLL2qwtILN6XtP3yNpbDfpYwbZAR7KxfkG2tpluOBDpHiHbgo3jtNFD4cQDT8DQ/BP 2hSEMCAkRz9D49XieNfmFuymeONKUhx54J56YEwvhksgchmHLUUYrKXFeCcwmqD/lex6 z63w== 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=LQhtlsw1+T6reMAEhFyYFr2m8Qv3jouQUXJ8R8StFM8=; b=iyfAH30yQhzNARNSgNkzJivO+2ECN4ghIcUFcVp9XBdLOxoa6ja1pA6qylZ7ha535F UnGKIJE2O3afKC+ir5hb6kXFrIejIfExRg+8Oe0lXJPiOCq7XSfy6IrEhps9/2e2GqhY IjImAtODfdS/hZfaXGovKFxp2rn9rKKkPf2BtMcOM4tpTYp4p203UK1XYc/2KKICaJYZ DO6IYpFAwcGkPVPiJe4D+XVJds6fwXr8YLx9hEvWE1+0pQFqvdfCe17oRJZB3rlVSy2s nUYgAcyMF/5gwbI/vf4KoeC9gMHmegh1MivNIOJNtJYJzUt6S5QN5WtV9oHZ3hKaWkM1 YtXw== X-Gm-Message-State: AGi0PuY1IQ2kYSAZIV3B6rMdR3FOp5dKT2w2dT8u6BkeJhI3vnAjmiwA jUND39JfGw30w3QGIHmAUUkVqrh7AvCg6pu3R8r6Bg== X-Received: by 2002:ac2:5e26:: with SMTP id o6mr14712374lfg.49.1587512672917; Tue, 21 Apr 2020 16:44:32 -0700 (PDT) MIME-Version: 1.0 References: <1587149322-28104-1-git-send-email-alan.mikhak@sifive.com> <20200418122123.10157ddd@why> <8a03b55223b118c6fc605d7204e01460@kernel.org> <20200421093928.4a600662@why> In-Reply-To: <20200421093928.4a600662@why> From: Alan Mikhak Date: Tue, 21 Apr 2020 16:44:21 -0700 Message-ID: Subject: Re: [PATCH] genirq/msi: Check null pointer before copying struct msi_msg To: Marc Zyngier Cc: Gustavo Pimentel , linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, linux-pci , tglx@linutronix.de, Kishon Vijay Abraham I , Paul Walmsley 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 Tue, Apr 21, 2020 at 1:39 AM Marc Zyngier wrote: > > On Mon, 20 Apr 2020 09:08:27 -0700 > Alan Mikhak wrote: > > Alan, > > > On Mon, Apr 20, 2020 at 2:14 AM Marc Zyngier wrote: > > > > > > On 2020-04-18 16:19, Gustavo Pimentel wrote: > > > > Hi Marc and Alan, > > > > > > > >> I'm not convinced by this. If you know that, by construction, these > > > >> interrupts are not associated with an underlying MSI, why calling > > > >> get_cached_msi_msg() the first place? > > > >> > > > >> There seem to be some assumptions in the DW EDMA driver that the > > > >> signaling would be MSI based, so maybe someone from Synopsys > > > >> (Gustavo?) > > > >> could clarify that. From my own perspective, running on an endpoint > > > >> device means that it is *generating* interrupts, and I'm not sure what > > > >> the MSIs represent here. > > > > > > > > Giving a little context to this topic. > > > > > > > > The eDMA IP present on the Synopsys DesignWare PCIe Endpoints can be > > > > configured and triggered *remotely* as well *locally*. > > > > For the sake of simplicity let's assume for now the eDMA was > > > > implemented > > > > on the EP and that is the IP that we want to configure and use. > > > > > > > > When I say *remotely* I mean that this IP can be configurable through > > > > the > > > > RC/CPU side, however, for that, it requires the eDMA registers to be > > > > exposed through a PCIe BAR on the EP. This will allow setting the SAR, > > > > DAR and other settings, also need(s) the interrupt(s) address(es) to be > > > > set as well (MSI or MSI-X only) so that it can signal through PCIe (to > > > > the RC and consecutively the associated EP driver) if the data transfer > > > > has been completed, aborted or if the Linked List consumer algorithm > > > > has > > > > passed in some linked element marked with a watermark. > > > > > > > > It was based on this case that the eDMA driver was exclusively > > > > developed. > > > > > > > > However, Alan, wants to expand a little more this, by being able to use > > > > this driver on the EP side (through > > > > pcitest/pci_endpoint_test/pci_epf_test) so that he can configure this > > > > IP > > > > *locally*. > > > > In fact, when doing this, he doesn't need to configure the interrupt > > > > address (MSI or MSI-X), because this IP provides a local interrupt line > > > > so that be connected to other blocks on the EP side. > > > > > > Right, so this confirms my hunch that the driver is being used in > > > a way that doesn't reflect the expected use case. Rather than > > > papering over the problem by hacking the core code, I'd rather see > > > the eDMA driver be updated to support both host and endpoint cases. > > > This probably boils down to a PCI vs non-PCI set of helpers. > > > > > > Alan, could you confirm whether we got it right? > > > > Thanks Marc and Gustavo. I appreciate all your comments and feedback. > > > > You both got it right. As Gustavo mentioned, I am trying to expand dw-edma > > for additional use cases. > > > > First new use case is for integration of dw-edma with pci-epf-test so the latter > > can initiate dma transfers locally from endpoint memory to host memory over the > > PCIe bus in response to a user command issued from the host-side command > > prompt using the pcitest utility. When the locally-initiated dma > > transfer completes > > in this use case on the endpoint side, dw-edma issues an interrupt to the local > > CPU on the endpoint side by way of a legacy interrupt and pci-epf-test issues > > an interrupt toward the remote host CPU across the PCIe bus by way of legacy, > > MSI, or possibly MSI-X interrupt. > > > > Second new use case is for integration of dw-edma with pci_endpoint_test > > running on the host CPU so the latter can initiate dma transfers locally from > > host-side in response to a user command issued from the host-side command > > prompt using the pcitest utility. This use case is for host systems that have > > Synopsys DesignWare PCI eDMA hardware on the host side. When the > > locally-initiated dma transfer completes in this use case on the host-side, > > dw-edma issues a legacy interrupt to its local host CPU and pci-epf-test running > > on the endpoint side issues a legacy, MSI, or possibly MSI-X interrupt > > across the > > PCIe bus toward the host CPU. > > > > When both the host and endpoint sides have the Synopsys DesignWare PCI > > eDMA hardware, more use cases become possible in which eDMA controllers > > from both systems can be engaged to move data. Embedded DMA controllers > > from other PCIe IP vendors may also be supported with additional dmaengine > > drivers under the Linux PCI Endpoint Framework with pci-epf-test, pcitest, and > > pci_endpoint_test suite as well as new PCI endpoint function drivers for such > > applications that require dma, for example nvme or virtio_net endpoint function > > drivers. > > > > I submitted a recent patch [1] and [2] which Gustavo ACk'd to decouple dw-edma > > from struct pci_dev. This enabled me to exercise dw-edma on some riscv host > > and endpoint systems that I work with. > > > > I will submit another patch to decouple dw-edma from struct msi_msg such > > that it would only call get_cached_msi_msg() on the host-side in its > > original use case with remotely initiated dma transfers using the BAR > > access method. > > > > The crash that I reported in __get_cached_msi_msg() is probably worth > > fixing too. It seems to be low impact since get_cached_msi_msg() > > seems to be called infrequently by a few callers. > > It isn't about the frequency of the calls, nor the overhead of this > function. It is about the fundamental difference between a wired > interrupt (in most case a level triggered one) and a MSI (edge by > definition on PCI). By making get_cached_msi_msg() "safe" to be called > for non-MSI IRQs, you hide a variety of design bugs which would > otherwise be obvious, like the one you are currently dealing with. > > Your eDMA driver uses MSI by construction, and is likely to use the MSI > semantics (edge triggering, coalescing, memory barrier). On the other > hand, your use case is likely to have interrupts with very different > semantics (level triggered, no barrier effect). Papering over these > differences is not the way to go, I'm afraid. > > I would recommend that you adapt the driver to have a separate > interrupt management for the non-MSI case, or at least not blindly use > MSI-specific APIs when not using them. Thanks Marc, I understand that the crash I reported here is to be kept to catch such issues. The design of dw-edma was correct for its original use case. Since I am the one trying to expand its use cases, I accept your recommendation and will see if I can offer patches that would be acceptable there. Regards, Alan > > Thanks, > > M. > -- > Jazz is not dead. It just smells funny...