From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FAKE_REPLY_C,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC308C43603 for ; Tue, 10 Dec 2019 22:37:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9DA8B2077B for ; Tue, 10 Dec 2019 22:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576017479; bh=pmltaW9LsjEuTpeKbuA3I4m6I9tXYKuy+WxPnOiBySg=; h=Date:From:To:Cc:Subject:In-Reply-To:List-ID:From; b=sqMNXuds+thOTEsgjMQG67L6VqSA0HEZCYNxau0TKy1SCxEglvo7LJ+2jnUyHrD3f mZEXe/4X99+UTxFz3WwoJ3H7Wq77NifQLFn4/5zjAZdWoa/tvR8frqRcaV2Q90tg0f yqbXAxtw6ZCr4ZmBonj8NDOuD5TazjpyGAXleXOM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730490AbfLJWh5 (ORCPT ); Tue, 10 Dec 2019 17:37:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:59282 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730355AbfLJWhr (ORCPT ); Tue, 10 Dec 2019 17:37:47 -0500 Received: from localhost (mobile-166-170-223-177.mycingular.net [166.170.223.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B6617214D8; Tue, 10 Dec 2019 22:37:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576017467; bh=pmltaW9LsjEuTpeKbuA3I4m6I9tXYKuy+WxPnOiBySg=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=GpF77bDRMYOZMzZUsc1xfZBNt0grHZ4wf9ahTXpwyB/3gWFtElsyCOKqPj3U1bJFM F12G87CHzuPAb/bUPdSWsiVx1FaP+i8FGPXzpLIMlG9rGYgTSbaTbyG8VW14eyc8d+ yP9jUwAsNzCNQ3sJ/NVKANDpE4MxAYItUWmqRpYM= Date: Tue, 10 Dec 2019 16:37:45 -0600 From: Bjorn Helgaas To: James Sewart Cc: linux-pci@vger.kernel.org, Logan Gunthorpe , Christoph Hellwig , Dmitry Safonov <0x7f454c46@gmail.com>, iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Dmitry Safonov , Alex Williamson , Joerg Roedel Subject: Re: [PATCH v6 2/3] PCI: Add parameter nr_devfns to pci_add_dma_alias Message-ID: <20191210223745.GA167002@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [+cc Joerg] On Tue, Dec 03, 2019 at 03:43:53PM +0000, James Sewart wrote: > pci_add_dma_alias can now be used to create a dma alias for a range of > devfns. > > Reviewed-by: Logan Gunthorpe > Signed-off-by: James Sewart > --- > drivers/pci/pci.c | 22 +++++++++++++++++----- > drivers/pci/quirks.c | 14 +++++++------- > include/linux/pci.h | 2 +- > 3 files changed, 25 insertions(+), 13 deletions(-) Heads up Joerg: I also updated drivers/iommu/amd_iommu.c (this is the one reported by the kbuild test robot) and removed the printk there that prints the same thing as the one in pci_add_dma_alias(), and I updated a PCI quirk that was merged after this patch was posted. > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index d3c83248f3ce..dbb01aceafda 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5857,7 +5857,8 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode, > /** > * pci_add_dma_alias - Add a DMA devfn alias for a device > * @dev: the PCI device for which alias is added > - * @devfn: alias slot and function > + * @devfn_from: alias slot and function > + * @nr_devfns: Number of subsequent devfns to alias > * > * This helper encodes an 8-bit devfn as a bit number in dma_alias_mask > * which is used to program permissible bus-devfn source addresses for DMA > @@ -5873,8 +5874,13 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode, > * cannot be left as a userspace activity). DMA aliases should therefore > * be configured via quirks, such as the PCI fixup header quirk. > */ > -void pci_add_dma_alias(struct pci_dev *dev, u8 devfn) > +void pci_add_dma_alias(struct pci_dev *dev, u8 devfn_from, unsigned nr_devfns) > { > + int devfn_to; > + > + nr_devfns = min(nr_devfns, (unsigned)MAX_NR_DEVFNS); > + devfn_to = devfn_from + nr_devfns - 1; I made this look like: + devfn_to = min(devfn_from + nr_devfns - 1, + (unsigned) MAX_NR_DEVFNS - 1); so devfn_from=0xf0, nr_devfns=0x20 doesn't cause devfn_to to wrap around. I did keep Logan's reviewed-by, so let me know if I broke something. > if (!dev->dma_alias_mask) > dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL); > if (!dev->dma_alias_mask) { > @@ -5882,9 +5888,15 @@ void pci_add_dma_alias(struct pci_dev *dev, u8 devfn) > return; > } > > - set_bit(devfn, dev->dma_alias_mask); > - pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n", > - PCI_SLOT(devfn), PCI_FUNC(devfn)); > + bitmap_set(dev->dma_alias_mask, devfn_from, nr_devfns); > + > + if (nr_devfns == 1) > + pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n", > + PCI_SLOT(devfn_from), PCI_FUNC(devfn_from)); > + else if(nr_devfns > 1) > + pci_info(dev, "Enabling fixed DMA alias for devfn range from %02x.%d to %02x.%d\n", > + PCI_SLOT(devfn_from), PCI_FUNC(devfn_from), > + PCI_SLOT(devfn_to), PCI_FUNC(devfn_to)); > }