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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C929CDB474 for ; Mon, 23 Oct 2023 06:08:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229631AbjJWGIw (ORCPT ); Mon, 23 Oct 2023 02:08:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229450AbjJWGIu (ORCPT ); Mon, 23 Oct 2023 02:08:50 -0400 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BAE1D65 for ; Sun, 22 Oct 2023 23:08:49 -0700 (PDT) Received: by verein.lst.de (Postfix, from userid 2407) id CC75468AA6; Mon, 23 Oct 2023 08:08:45 +0200 (CEST) Date: Mon, 23 Oct 2023 08:08:45 +0200 From: Christoph Hellwig To: Jia He Cc: Christoph Hellwig , Marek Szyprowski , Robin Murphy , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, nd@arm.com Subject: Re: [PATCH v3 2/2] dma-mapping: fix dma_addressing_limited() if dma_range_map can't cover all system RAM Message-ID: <20231023060845.GA11907@lst.de> References: <20231016125254.1875-1-justin.he@arm.com> <20231016125254.1875-3-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231016125254.1875-3-justin.he@arm.com> User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > + */ > +static int check_ram_in_range_map(unsigned long start_pfn, > + unsigned long nr_pages, void *data) > +{ > + unsigned long end_pfn = start_pfn + nr_pages; > + struct device *dev = (struct device *)data; No need for the cast here. > + struct bus_dma_region *bdr = NULL; > + const struct bus_dma_region *m; > + > + while (start_pfn < end_pfn) { > + for (m = dev->dma_range_map; PFN_DOWN(m->size); m++) { > + unsigned long cpu_start_pfn = PFN_DOWN(m->cpu_start); > + > + if (start_pfn >= cpu_start_pfn > + && start_pfn - cpu_start_pfn < PFN_DOWN(m->size)) { Linux coding style keeps the && on the previous line. > + bdr = (struct bus_dma_region *)m; If you also declared bdr as const this should be able to do away with the cast. > bool dma_addressing_limited(struct device *dev) > { > - return min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < > - dma_get_required_mask(dev); > + if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < > + dma_get_required_mask(dev)) > + return true; > + > + return !all_ram_in_dma_range_map(dev); So, all the dma range map thing is really a dma-direct concept. So I think here in dma_addressing_limited we should just do a: if (likely(!ops)) return !dma_direct_all_ram_mapped(dev)); return false with dma_direct_all_ram_mapped move to dma-direct.c.