Message ID | 20230912084002.2168-1-justin.he@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp264678vqx; Tue, 12 Sep 2023 01:48:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGSaszS7LDogYujm4QioX760V6NSm3hZhOYGVM9OdUhDovV77kP68xTeobwRVLQ0p5oHTBe X-Received: by 2002:a17:90b:3695:b0:267:f329:947d with SMTP id mj21-20020a17090b369500b00267f329947dmr9020022pjb.33.1694508479822; Tue, 12 Sep 2023 01:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694508479; cv=none; d=google.com; s=arc-20160816; b=0RDxhzYCzKvcs6VlrBcX0PbAnu8uSXeIN4ck/zVuVHXXPzqlKsBP+/xEtiEW+VoaXR HeIyR08HeNr3p9so1ojEV45APFOQQ8vtjUAYnSu49h1v97Ow41qwS4dCTwof1ekOI5IJ p6tOantla44l4pzdLtnUi4M2Qp/v9lGktx58+dwKmHumctCJlo0lu91Yvl0zn4lJRYuJ ybkkLl496VvFOo77UYgHlthEq2nIJTmMJJc7OqmyWaa3bjcqrfQyM0MQ/sOVkIZleZff ib0Acq4YKlyQhvdD0vtLbVhM8Yg0gLE+Cx4TJGONpBGOXXWd5X0KpPXrJitu0ie9h8BI AXLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=RNFCuor3hmQ2yr5sRDKcIQd/I4H94xFmz/DMsiWOOQM=; fh=Z7JQxSVtwGr/fL148INo1D9UZgQyopYphFpEtCrkQ7g=; b=DeaSPp9qKAilCzaCPifiYL/exOtZ3etlS3xPAJRAa4vh/y8ZS/cJ8xk6JsKsL/yNgG wz0NB+hlCNeDH/Pzt7zy8bws3A5sC9tDi4+zCnJLcK1BeqpKNBH7tWiY3Y8veTNgH0yZ RTRnnBKQ6jd6eMQLDh+qeA5XFkNLx0KlnWK5OA4maj331fqfhkd25v+57pEKZYAwvVW2 6nemhoSRWPynuT0RXJ7AgNFqGeZhtiVGsbsgmdy/hWuJGpBAQmBlnTebSg5GOz2mxC5x ttBvKhRxV8eV655raswjP5oife8DWE9rYqPyJmp/1msUfDS0ojs1MyPCQyP3h+IolKSK wSpQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id v20-20020a17090abb9400b0026b7c4eee42si8579151pjr.66.2023.09.12.01.47.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 01:47:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 303D3801D492; Tue, 12 Sep 2023 01:40:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.8 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232494AbjILIkS (ORCPT <rfc822;pwkd43@gmail.com> + 38 others); Tue, 12 Sep 2023 04:40:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232775AbjILIkQ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 12 Sep 2023 04:40:16 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 41B24E7F for <linux-kernel@vger.kernel.org>; Tue, 12 Sep 2023 01:40:12 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 177E9C15; Tue, 12 Sep 2023 01:40:49 -0700 (PDT) Received: from entos-ampere02.shanghai.arm.com (unknown [10.169.212.213]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BC5663F738; Tue, 12 Sep 2023 01:40:09 -0700 (PDT) From: Jia He <justin.he@arm.com> To: Christoph Hellwig <hch@lst.de>, Marek Szyprowski <m.szyprowski@samsung.com>, Robin Murphy <robin.murphy@arm.com>, iommu@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Jia He <justin.he@arm.com> Subject: [PATCH] dma-mapping: fix dma_addressing_limited if dma_range_map is scanned Date: Tue, 12 Sep 2023 08:40:02 +0000 Message-Id: <20230912084002.2168-1-justin.he@arm.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 01:40:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776820923406396405 X-GMAIL-MSGID: 1776820923406396405 |
Series |
dma-mapping: fix dma_addressing_limited if dma_range_map is scanned
|
|
Commit Message
Justin He
Sept. 12, 2023, 8:40 a.m. UTC
After scanning the dma_range_map, if it is found that not all of the
system RAM ranges are encompassed within it, an incorrect calculation
occurs for dma_addressing_limited(), which prevents the nvme device
dma mapping in the checking path of phys_to_dma().
E.g. On an Armv8 Ampere server, the dsdt ACPI table is:
Method (_DMA, 0, Serialized) // _DMA: Direct Memory Access
{
Name (RBUF, ResourceTemplate ()
{
QWordMemory (ResourceConsumer, PosDecode, MinFixed,
MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000000000000000, // Range Minimum
0x00000000FFFFFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000000100000000, // Length
,, , AddressRangeMemory, TypeStatic)
QWordMemory (ResourceConsumer, PosDecode, MinFixed,
MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000006010200000, // Range Minimum
0x000000602FFFFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x000000001FE00000, // Length
,, , AddressRangeMemory, TypeStatic)
QWordMemory (ResourceConsumer, PosDecode, MinFixed,
MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity
0x00000060F0000000, // Range Minimum
0x00000060FFFFFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000000010000000, // Length
,, , AddressRangeMemory, TypeStatic)
QWordMemory (ResourceConsumer, PosDecode, MinFixed,
MaxFixed, Cacheable, ReadWrite,
0x0000000000000000, // Granularity
0x0000007000000000, // Range Minimum
0x000003FFFFFFFFFF, // Range Maximum
0x0000000000000000, // Translation Offset
0x0000039000000000, // Length
,, , AddressRangeMemory, TypeStatic)
})
But the System RAM ranges are:
cat /proc/iomem |grep -i ram
90000000-91ffffff : System RAM
92900000-fffbffff : System RAM
880000000-fffffffff : System RAM
8800000000-bff5990fff : System RAM
bff59d0000-bff5a4ffff : System RAM
bff8000000-bfffffffff : System RAM
So some RAM ranges are out of dma_range_map.
Fixes it by checking whether each of the system RAM resources can be
properly encompassed within the dma_range_map.
Signed-off-by: Jia He <justin.he@arm.com>
---
include/linux/dma-mapping.h | 8 +++++--
kernel/dma/mapping.c | 45 +++++++++++++++++++++++++++++++++++++
2 files changed, 51 insertions(+), 2 deletions(-)
Comments
On 12/09/2023 9:40 am, Jia He wrote: > After scanning the dma_range_map, if it is found that not all of the > system RAM ranges are encompassed within it, an incorrect calculation > occurs for dma_addressing_limited(), which prevents the nvme device > dma mapping in the checking path of phys_to_dma(). Nit: the subject and this description aren't very clear - the key point here is the unusual case that the range map covers right up to the top of system RAM, but leaves a hole somewhere lower down. There's no issue with the more typical case where some RAM exists above the top of the range map, since bus_dma_limit will capture that and work as expected. > E.g. On an Armv8 Ampere server, the dsdt ACPI table is: > Method (_DMA, 0, Serialized) // _DMA: Direct Memory Access > { > Name (RBUF, ResourceTemplate () > { > QWordMemory (ResourceConsumer, PosDecode, MinFixed, > MaxFixed, Cacheable, ReadWrite, > 0x0000000000000000, // Granularity > 0x0000000000000000, // Range Minimum > 0x00000000FFFFFFFF, // Range Maximum > 0x0000000000000000, // Translation Offset > 0x0000000100000000, // Length > ,, , AddressRangeMemory, TypeStatic) > QWordMemory (ResourceConsumer, PosDecode, MinFixed, > MaxFixed, Cacheable, ReadWrite, > 0x0000000000000000, // Granularity > 0x0000006010200000, // Range Minimum > 0x000000602FFFFFFF, // Range Maximum > 0x0000000000000000, // Translation Offset > 0x000000001FE00000, // Length > ,, , AddressRangeMemory, TypeStatic) > QWordMemory (ResourceConsumer, PosDecode, MinFixed, > MaxFixed, Cacheable, ReadWrite, > 0x0000000000000000, // Granularity > 0x00000060F0000000, // Range Minimum > 0x00000060FFFFFFFF, // Range Maximum > 0x0000000000000000, // Translation Offset > 0x0000000010000000, // Length > ,, , AddressRangeMemory, TypeStatic) > QWordMemory (ResourceConsumer, PosDecode, MinFixed, > MaxFixed, Cacheable, ReadWrite, > 0x0000000000000000, // Granularity > 0x0000007000000000, // Range Minimum > 0x000003FFFFFFFFFF, // Range Maximum > 0x0000000000000000, // Translation Offset > 0x0000039000000000, // Length > ,, , AddressRangeMemory, TypeStatic) > }) > > But the System RAM ranges are: > cat /proc/iomem |grep -i ram > 90000000-91ffffff : System RAM > 92900000-fffbffff : System RAM > 880000000-fffffffff : System RAM > 8800000000-bff5990fff : System RAM > bff59d0000-bff5a4ffff : System RAM > bff8000000-bfffffffff : System RAM > So some RAM ranges are out of dma_range_map. > > Fixes it by checking whether each of the system RAM resources can be > properly encompassed within the dma_range_map. > > Signed-off-by: Jia He <justin.he@arm.com> > --- > include/linux/dma-mapping.h | 8 +++++-- > kernel/dma/mapping.c | 45 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 51 insertions(+), 2 deletions(-) > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > index f0ccca16a0ac..d9d1c67c8579 100644 > --- a/include/linux/dma-mapping.h > +++ b/include/linux/dma-mapping.h > @@ -144,6 +144,7 @@ bool dma_pci_p2pdma_supported(struct device *dev); > int dma_set_mask(struct device *dev, u64 mask); > int dma_set_coherent_mask(struct device *dev, u64 mask); > u64 dma_get_required_mask(struct device *dev); > +bool all_ram_in_dma_range_map(struct device *dev); > size_t dma_max_mapping_size(struct device *dev); > size_t dma_opt_mapping_size(struct device *dev); > bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); > @@ -475,8 +476,11 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) > */ > static inline 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)) Nit: indentation > + return true; > + > + return !all_ram_in_dma_range_map(dev); > } > > static inline unsigned int dma_get_max_seg_size(struct device *dev) > diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c > index e323ca48f7f2..ab407deb81b8 100644 > --- a/kernel/dma/mapping.c > +++ b/kernel/dma/mapping.c > @@ -14,6 +14,7 @@ > #include <linux/of_device.h> > #include <linux/slab.h> > #include <linux/vmalloc.h> > +#include <linux/dma-direct.h> Nit: please keep the includes sorted alphabetically, however I do wonder whether this whole thing shouldn't belong in dma-direct anyway. > #include "debug.h" > #include "direct.h" > > @@ -819,6 +820,50 @@ size_t dma_opt_mapping_size(struct device *dev) > } > EXPORT_SYMBOL_GPL(dma_opt_mapping_size); > > +/* > + * To check whether all ram resource ranges are mapped in dma range map > + * Returns 0 when continuous check is needed > + * Returns 1 if there is some ram range can't be mapped to dma_range_map > + */ > +static int check_ram_in_range_map(unsigned long start_pfn, > + unsigned long nr_pages, void *data) > +{ > + phys_addr_t end_paddr = (start_pfn + nr_pages) << PAGE_SHIFT; This could still wrap to 0 on 32-bit. I think the robust thing to do is either spray some extra -1s and +1s around to make all the "end" values inclusive limits, or maybe just do everything in units of pages rather than bytes (i.e. use PFN_DOWN() on the bus_dma_region entry values). > + phys_addr_t start_paddr = start_pfn << PAGE_SHIFT; > + struct device *dev = (struct device *)data; > + struct bus_dma_region *region = NULL; > + const struct bus_dma_region *m; > + > + while (start_paddr < end_paddr) { > + // find region containing start_paddr Nit: inconsistent comment style (although it's not a particularly valuable comment anyway, IMO the loop itself is clear enough). Thanks, Robin. > + for (m = dev->dma_range_map; m->size; m++) { > + if (start_paddr >= m->cpu_start > + && start_paddr - m->cpu_start < m->size) { > + region = (struct bus_dma_region *)m; > + break; > + } > + } > + if (!region) > + return 1; > + > + start_paddr = region->cpu_start + region->size; > + /* handle overflow of phys_addr_t */ > + if (start_paddr == 0) > + break; > + } > + > + return 0; > +} > + > +bool all_ram_in_dma_range_map(struct device *dev) > +{ > + if (!dev->dma_range_map) > + return 1; > + > + return !walk_system_ram_range(0, ULONG_MAX, dev, check_ram_in_range_map); > +} > +EXPORT_SYMBOL_GPL(all_ram_in_dma_range_map); > + > bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) > { > const struct dma_map_ops *ops = get_dma_ops(dev);
Hi Jia, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.6-rc1 next-20230912] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jia-He/dma-mapping-fix-dma_addressing_limited-if-dma_range_map-is-scanned/20230912-164126 base: linus/master patch link: https://lore.kernel.org/r/20230912084002.2168-1-justin.he%40arm.com patch subject: [PATCH] dma-mapping: fix dma_addressing_limited if dma_range_map is scanned config: um-allyesconfig (https://download.01.org/0day-ci/archive/20230913/202309130234.COIfUg9W-lkp@intel.com/config) compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230913/202309130234.COIfUg9W-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202309130234.COIfUg9W-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from init/main.c:21: In file included from include/linux/syscalls.h:90: In file included from include/trace/syscall.h:7: In file included from include/linux/trace_events.h:9: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from init/main.c:21: In file included from include/linux/syscalls.h:90: In file included from include/trace/syscall.h:7: In file included from include/linux/trace_events.h:9: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from init/main.c:21: In file included from include/linux/syscalls.h:90: In file included from include/trace/syscall.h:7: In file included from include/linux/trace_events.h:9: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ In file included from init/main.c:102: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: implicit declaration of function 'all_ram_in_dma_range_map' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return !all_ram_in_dma_range_map(dev); ^ 12 warnings and 1 error generated. -- In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: implicit declaration of function 'all_ram_in_dma_range_map' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return !all_ram_in_dma_range_map(dev); ^ arch/um/os-Linux/drivers/ethertap_kern.c:66:5: warning: no previous prototype for function 'ethertap_setup' [-Wmissing-prototypes] int ethertap_setup(char *str, char **mac_out, void *data) ^ arch/um/os-Linux/drivers/ethertap_kern.c:66:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int ethertap_setup(char *str, char **mac_out, void *data) ^ static 13 warnings and 1 error generated. -- In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: implicit declaration of function 'all_ram_in_dma_range_map' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return !all_ram_in_dma_range_map(dev); ^ arch/um/os-Linux/drivers/tuntap_kern.c:56:5: warning: no previous prototype for function 'tuntap_setup' [-Wmissing-prototypes] int tuntap_setup(char *str, char **mac_out, void *data) ^ arch/um/os-Linux/drivers/tuntap_kern.c:56:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int tuntap_setup(char *str, char **mac_out, void *data) ^ static 13 warnings and 1 error generated. -- In file included from net/ipv4/route.c:67: In file included from include/linux/memblock.h:13: In file included from arch/um/include/asm/dma.h:5: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __raw_readb(PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) ^ In file included from net/ipv4/route.c:67: In file included from include/linux/memblock.h:13: In file included from arch/um/include/asm/dma.h:5: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) ^ In file included from net/ipv4/route.c:67: In file included from include/linux/memblock.h:13: In file included from arch/um/include/asm/dma.h:5: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writeb(value, PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] readsl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesb(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesw(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] writesl(PCI_IOBASE + addr, buffer, count); ~~~~~~~~~~ ^ In file included from net/ipv4/route.c:71: In file included from include/linux/inet.h:42: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: implicit declaration of function 'all_ram_in_dma_range_map' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return !all_ram_in_dma_range_map(dev); ^ net/ipv4/route.c:880:6: warning: variable 'log_martians' set but not used [-Wunused-but-set-variable] int log_martians; ^ 13 warnings and 1 error generated. .. vim +/all_ram_in_dma_range_map +483 include/linux/dma-mapping.h 468 469 /** 470 * dma_addressing_limited - return if the device is addressing limited 471 * @dev: device to check 472 * 473 * Return %true if the devices DMA mask is too small to address all memory in 474 * the system, else %false. Lack of addressing bits is the prime reason for 475 * bounce buffering, but might not be the only one. 476 */ 477 static inline bool dma_addressing_limited(struct device *dev) 478 { 479 if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < 480 dma_get_required_mask(dev)) 481 return true; 482 > 483 return !all_ram_in_dma_range_map(dev); 484 } 485
Hi Jia, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on hch-configfs/for-next v6.6-rc1 next-20230912] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Jia-He/dma-mapping-fix-dma_addressing_limited-if-dma_range_map-is-scanned/20230912-164126 base: linus/master patch link: https://lore.kernel.org/r/20230912084002.2168-1-justin.he%40arm.com patch subject: [PATCH] dma-mapping: fix dma_addressing_limited if dma_range_map is scanned config: um-randconfig-r012-20230912 (https://download.01.org/0day-ci/archive/20230913/202309130345.xV6bouV1-lkp@intel.com/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20230913/202309130345.xV6bouV1-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202309130345.xV6bouV1-lkp@intel.com/ All errors (new ones prefixed by >>): In file included from block/blk-settings.c:8: In file included from include/linux/bio.h:10: In file included from include/linux/blk_types.h:10: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 547 | val = __raw_readb(PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) | ^ In file included from block/blk-settings.c:8: In file included from include/linux/bio.h:10: In file included from include/linux/blk_types.h:10: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ In file included from block/blk-settings.c:8: In file included from include/linux/bio.h:10: In file included from include/linux/blk_types.h:10: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 584 | __raw_writeb(value, PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 692 | readsb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 700 | readsw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 708 | readsl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 717 | writesb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 726 | writesw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 735 | writesl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ In file included from block/blk-settings.c:16: >> include/linux/dma-mapping.h:483:10: error: call to undeclared function 'all_ram_in_dma_range_map'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 483 | return !all_ram_in_dma_range_map(dev); | ^ 12 warnings and 1 error generated. -- In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 547 | val = __raw_readb(PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) | ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 584 | __raw_writeb(value, PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 692 | readsb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 700 | readsw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 708 | readsl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 717 | writesb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 726 | writesw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 735 | writesl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: call to undeclared function 'all_ram_in_dma_range_map'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 483 | return !all_ram_in_dma_range_map(dev); | ^ arch/um/os-Linux/drivers/tuntap_kern.c:56:5: warning: no previous prototype for function 'tuntap_setup' [-Wmissing-prototypes] 56 | int tuntap_setup(char *str, char **mac_out, void *data) | ^ arch/um/os-Linux/drivers/tuntap_kern.c:56:1: note: declare 'static' if the function is not intended to be used outside of this translation unit 56 | int tuntap_setup(char *str, char **mac_out, void *data) | ^ | static 13 warnings and 1 error generated. -- In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 547 | val = __raw_readb(PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) | ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 584 | __raw_writeb(value, PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 692 | readsb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 700 | readsw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 708 | readsl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 717 | writesb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 726 | writesw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 735 | writesl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: In file included from include/linux/netdevice.h:38: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: call to undeclared function 'all_ram_in_dma_range_map'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 483 | return !all_ram_in_dma_range_map(dev); | ^ arch/um/os-Linux/drivers/ethertap_kern.c:66:5: warning: no previous prototype for function 'ethertap_setup' [-Wmissing-prototypes] 66 | int ethertap_setup(char *str, char **mac_out, void *data) | ^ arch/um/os-Linux/drivers/ethertap_kern.c:66:1: note: declare 'static' if the function is not intended to be used outside of this translation unit 66 | int ethertap_setup(char *str, char **mac_out, void *data) | ^ | static 13 warnings and 1 error generated. -- In file included from net/ipv4/igmp.c:79: In file included from include/linux/inet.h:42: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:547:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 547 | val = __raw_readb(PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:560:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu' 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) | ^ In file included from net/ipv4/igmp.c:79: In file included from include/linux/inet.h:42: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr)); | ~~~~~~~~~~ ^ include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu' 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) | ^ In file included from net/ipv4/igmp.c:79: In file included from include/linux/inet.h:42: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:17: In file included from include/linux/bvec.h:10: In file included from include/linux/highmem.h:12: In file included from include/linux/hardirq.h:11: In file included from arch/um/include/asm/hardirq.h:5: In file included from include/asm-generic/hardirq.h:17: In file included from include/linux/irq.h:20: In file included from include/linux/io.h:13: In file included from arch/um/include/asm/io.h:24: include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 584 | __raw_writeb(value, PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr); | ~~~~~~~~~~ ^ include/asm-generic/io.h:692:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 692 | readsb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:700:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 700 | readsw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:708:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 708 | readsl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:717:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 717 | writesb(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:726:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 726 | writesw(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ include/asm-generic/io.h:735:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] 735 | writesl(PCI_IOBASE + addr, buffer, count); | ~~~~~~~~~~ ^ In file included from net/ipv4/igmp.c:79: In file included from include/linux/inet.h:42: In file included from include/net/net_namespace.h:43: In file included from include/linux/skbuff.h:28: >> include/linux/dma-mapping.h:483:10: error: call to undeclared function 'all_ram_in_dma_range_map'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] 483 | return !all_ram_in_dma_range_map(dev); | ^ net/ipv4/igmp.c:1913:6: warning: variable 'changerec' set but not used [-Wunused-but-set-variable] 1913 | int changerec = 0; | ^ 13 warnings and 1 error generated. .. vim +/all_ram_in_dma_range_map +483 include/linux/dma-mapping.h 468 469 /** 470 * dma_addressing_limited - return if the device is addressing limited 471 * @dev: device to check 472 * 473 * Return %true if the devices DMA mask is too small to address all memory in 474 * the system, else %false. Lack of addressing bits is the prime reason for 475 * bounce buffering, but might not be the only one. 476 */ 477 static inline bool dma_addressing_limited(struct device *dev) 478 { 479 if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < 480 dma_get_required_mask(dev)) 481 return true; 482 > 483 return !all_ram_in_dma_range_map(dev); 484 } 485
> -----Original Message----- > From: kernel test robot <lkp@intel.com> > Sent: Wednesday, September 13, 2023 2:28 AM > To: Justin He <Justin.He@arm.com>; Christoph Hellwig <hch@lst.de>; Marek > Szyprowski <m.szyprowski@samsung.com>; Robin Murphy > <Robin.Murphy@arm.com>; iommu@lists.linux.dev > Cc: llvm@lists.linux.dev; oe-kbuild-all@lists.linux.dev; > linux-kernel@vger.kernel.org; Justin He <Justin.He@arm.com> > Subject: Re: [PATCH] dma-mapping: fix dma_addressing_limited if > dma_range_map is scanned > > Hi Jia, > > kernel test robot noticed the following build errors: > > [auto build test ERROR on linus/master] > [also build test ERROR on v6.6-rc1 next-20230912] [If your patch is applied to > the wrong git tree, kindly drop us a note. > And when submitting patch, we suggest to use '--base' as documented in > https://git-scm.com/docs/git-format-patch#_base_tree_information] > > url: > https://github.com/intel-lab-lkp/linux/commits/Jia-He/dma-mapping-fix-dma_ > addressing_limited-if-dma_range_map-is-scanned/20230912-164126 > base: linus/master > patch link: > https://lore.kernel.org/r/20230912084002.2168-1-justin.he%40arm.com > patch subject: [PATCH] dma-mapping: fix dma_addressing_limited if > dma_range_map is scanned > config: um-allyesconfig > (https://download.01.org/0day-ci/archive/20230913/202309130234.COIfUg9 > W-lkp@intel.com/config) > compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project.git > f28c006a5895fc0e329fe15fead81e37457cb1d1) > reproduce (this is a W=1 build): > (https://download.01.org/0day-ci/archive/20230913/202309130234.COIfUg9 > W-lkp@intel.com/reproduce) > > If you fix the issue in a separate patch/commit (i.e. not just a new version of > the same patch/commit), kindly add following tags > | Reported-by: kernel test robot <lkp@intel.com> > | Closes: > | https://lore.kernel.org/oe-kbuild-all/202309130234.COIfUg9W-lkp@intel. > | com/ > > All errors (new ones prefixed by >>): > > In file included from init/main.c:21: > In file included from include/linux/syscalls.h:90: > In file included from include/trace/syscall.h:7: > In file included from include/linux/trace_events.h:9: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:547:31: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __raw_readb(PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:560:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from > macro '__le16_to_cpu' > #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) > ^ > In file included from init/main.c:21: > In file included from include/linux/syscalls.h:90: > In file included from include/trace/syscall.h:7: > In file included from include/linux/trace_events.h:9: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:573:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from > macro '__le32_to_cpu' > #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) > ^ > In file included from init/main.c:21: > In file included from include/linux/syscalls.h:90: > In file included from include/trace/syscall.h:7: > In file included from include/linux/trace_events.h:9: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:584:33: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writeb(value, PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:594:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:604:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:692:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:700:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:708:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:717:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:726:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:735:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > In file included from init/main.c:102: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:28: > >> include/linux/dma-mapping.h:483:10: error: implicit declaration of > >> function 'all_ram_in_dma_range_map' is invalid in C99 > >> [-Werror,-Wimplicit-function-declaration] > return !all_ram_in_dma_range_map(dev); Seems I need to define a stub when DMA Kconfig is disabled. Thanks -- Cheers, Justin (Jia He) > ^ > 12 warnings and 1 error generated. > -- > In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:547:31: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __raw_readb(PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:560:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from > macro '__le16_to_cpu' > #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) > ^ > In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:573:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from > macro '__le32_to_cpu' > #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) > ^ > In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:584:33: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writeb(value, PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:594:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:604:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:692:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:700:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:708:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:717:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:726:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:735:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > In file included from arch/um/os-Linux/drivers/ethertap_kern.c:10: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:28: > >> include/linux/dma-mapping.h:483:10: error: implicit declaration of > >> function 'all_ram_in_dma_range_map' is invalid in C99 > >> [-Werror,-Wimplicit-function-declaration] > return !all_ram_in_dma_range_map(dev); > ^ > arch/um/os-Linux/drivers/ethertap_kern.c:66:5: warning: no previous > prototype for function 'ethertap_setup' [-Wmissing-prototypes] > int ethertap_setup(char *str, char **mac_out, void *data) > ^ > arch/um/os-Linux/drivers/ethertap_kern.c:66:1: note: declare 'static' if the > function is not intended to be used outside of this translation unit > int ethertap_setup(char *str, char **mac_out, void *data) > ^ > static > 13 warnings and 1 error generated. > -- > In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:547:31: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __raw_readb(PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:560:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from > macro '__le16_to_cpu' > #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) > ^ > In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:573:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from > macro '__le32_to_cpu' > #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) > ^ > In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:17: > In file included from include/linux/bvec.h:10: > In file included from include/linux/highmem.h:12: > In file included from include/linux/hardirq.h:11: > In file included from arch/um/include/asm/hardirq.h:5: > In file included from include/asm-generic/hardirq.h:17: > In file included from include/linux/irq.h:20: > In file included from include/linux/io.h:13: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:584:33: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writeb(value, PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:594:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:604:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:692:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:700:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:708:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:717:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:726:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:735:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > In file included from arch/um/os-Linux/drivers/tuntap_kern.c:6: > In file included from include/linux/netdevice.h:38: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:28: > >> include/linux/dma-mapping.h:483:10: error: implicit declaration of > >> function 'all_ram_in_dma_range_map' is invalid in C99 > >> [-Werror,-Wimplicit-function-declaration] > return !all_ram_in_dma_range_map(dev); > ^ > arch/um/os-Linux/drivers/tuntap_kern.c:56:5: warning: no previous > prototype for function 'tuntap_setup' [-Wmissing-prototypes] > int tuntap_setup(char *str, char **mac_out, void *data) > ^ > arch/um/os-Linux/drivers/tuntap_kern.c:56:1: note: declare 'static' if the > function is not intended to be used outside of this translation unit > int tuntap_setup(char *str, char **mac_out, void *data) > ^ > static > 13 warnings and 1 error generated. > -- > In file included from net/ipv4/route.c:67: > In file included from include/linux/memblock.h:13: > In file included from arch/um/include/asm/dma.h:5: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:547:31: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __raw_readb(PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:560:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from > macro '__le16_to_cpu' > #define __le16_to_cpu(x) ((__force __u16)(__le16)(x)) > ^ > In file included from net/ipv4/route.c:67: > In file included from include/linux/memblock.h:13: > In file included from arch/um/include/asm/dma.h:5: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:573:61: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + > addr)); > > ~~~~~~~~~~ ^ > include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from > macro '__le32_to_cpu' > #define __le32_to_cpu(x) ((__force __u32)(__le32)(x)) > ^ > In file included from net/ipv4/route.c:67: > In file included from include/linux/memblock.h:13: > In file included from arch/um/include/asm/dma.h:5: > In file included from arch/um/include/asm/io.h:24: > include/asm-generic/io.h:584:33: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writeb(value, PCI_IOBASE + addr); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:594:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:604:59: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + > addr); > ~~~~~~~~~~ > ^ > include/asm-generic/io.h:692:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:700:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:708:20: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > readsl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:717:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesb(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:726:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesw(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > include/asm-generic/io.h:735:21: warning: performing pointer arithmetic > on a null pointer has undefined behavior [-Wnull-pointer-arithmetic] > writesl(PCI_IOBASE + addr, buffer, count); > ~~~~~~~~~~ ^ > In file included from net/ipv4/route.c:71: > In file included from include/linux/inet.h:42: > In file included from include/net/net_namespace.h:43: > In file included from include/linux/skbuff.h:28: > >> include/linux/dma-mapping.h:483:10: error: implicit declaration of > >> function 'all_ram_in_dma_range_map' is invalid in C99 > >> [-Werror,-Wimplicit-function-declaration] > return !all_ram_in_dma_range_map(dev); > ^ > net/ipv4/route.c:880:6: warning: variable 'log_martians' set but not used > [-Wunused-but-set-variable] > int log_martians; > ^ > 13 warnings and 1 error generated. > .. > > > vim +/all_ram_in_dma_range_map +483 include/linux/dma-mapping.h > > 468 > 469 /** > 470 * dma_addressing_limited - return if the device is addressing > limited > 471 * @dev: device to check > 472 * > 473 * Return %true if the devices DMA mask is too small to address all > memory in > 474 * the system, else %false. Lack of addressing bits is the prime > reason for > 475 * bounce buffering, but might not be the only one. > 476 */ > 477 static inline bool dma_addressing_limited(struct device *dev) > 478 { > 479 if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) < > 480 dma_get_required_mask(dev)) > 481 return true; > 482 > > 483 return !all_ram_in_dma_range_map(dev); > 484 } > 485 > > -- > 0-DAY CI Kernel Test Service > https://github.com/intel/lkp-tests/wiki
Hi Robin, > -----Original Message----- > From: Robin Murphy <robin.murphy@arm.com> > Sent: Tuesday, September 12, 2023 7:57 PM > To: Justin He <Justin.He@arm.com>; Christoph Hellwig <hch@lst.de>; Marek > Szyprowski <m.szyprowski@samsung.com>; iommu@lists.linux.dev > Cc: linux-kernel@vger.kernel.org > Subject: Re: [PATCH] dma-mapping: fix dma_addressing_limited if > dma_range_map is scanned > > On 12/09/2023 9:40 am, Jia He wrote: > > After scanning the dma_range_map, if it is found that not all of the > > system RAM ranges are encompassed within it, an incorrect calculation > > occurs for dma_addressing_limited(), which prevents the nvme device > > dma mapping in the checking path of phys_to_dma(). > > Nit: the subject and this description aren't very clear - the key point here is the > unusual case that the range map covers right up to the top of system RAM, but > leaves a hole somewhere lower down. There's no issue with the more typical > case where some RAM exists above the top of the range map, since > bus_dma_limit will capture that and work as expected. > Ok, how about dma-mapping: fix dma_addressing_limited if dma_range_map can't cover all system RAM > > E.g. On an Armv8 Ampere server, the dsdt ACPI table is: > > Method (_DMA, 0, Serialized) // _DMA: Direct Memory Access > > { > > Name (RBUF, ResourceTemplate () > > { > > QWordMemory (ResourceConsumer, PosDecode, > > MinFixed, MaxFixed, Cacheable, ReadWrite, > > 0x0000000000000000, // Granularity > > 0x0000000000000000, // Range Minimum > > 0x00000000FFFFFFFF, // Range Maximum > > 0x0000000000000000, // Translation Offset > > 0x0000000100000000, // Length > > ,, , AddressRangeMemory, TypeStatic) > > QWordMemory (ResourceConsumer, PosDecode, > > MinFixed, MaxFixed, Cacheable, ReadWrite, > > 0x0000000000000000, // Granularity > > 0x0000006010200000, // Range Minimum > > 0x000000602FFFFFFF, // Range Maximum > > 0x0000000000000000, // Translation Offset > > 0x000000001FE00000, // Length > > ,, , AddressRangeMemory, TypeStatic) > > QWordMemory (ResourceConsumer, PosDecode, > > MinFixed, MaxFixed, Cacheable, ReadWrite, > > 0x0000000000000000, // Granularity > > 0x00000060F0000000, // Range Minimum > > 0x00000060FFFFFFFF, // Range Maximum > > 0x0000000000000000, // Translation Offset > > 0x0000000010000000, // Length > > ,, , AddressRangeMemory, TypeStatic) > > QWordMemory (ResourceConsumer, PosDecode, > > MinFixed, MaxFixed, Cacheable, ReadWrite, > > 0x0000000000000000, // Granularity > > 0x0000007000000000, // Range Minimum > > 0x000003FFFFFFFFFF, // Range Maximum > > 0x0000000000000000, // Translation Offset > > 0x0000039000000000, // Length > > ,, , AddressRangeMemory, TypeStatic) > > }) > > > > But the System RAM ranges are: > > cat /proc/iomem |grep -i ram > > 90000000-91ffffff : System RAM > > 92900000-fffbffff : System RAM > > 880000000-fffffffff : System RAM > > 8800000000-bff5990fff : System RAM > > bff59d0000-bff5a4ffff : System RAM > > bff8000000-bfffffffff : System RAM > > So some RAM ranges are out of dma_range_map. > > > > Fixes it by checking whether each of the system RAM resources can be > > properly encompassed within the dma_range_map. > > > > Signed-off-by: Jia He <justin.he@arm.com> > > --- > > include/linux/dma-mapping.h | 8 +++++-- > > kernel/dma/mapping.c | 45 > +++++++++++++++++++++++++++++++++++++ > > 2 files changed, 51 insertions(+), 2 deletions(-) > > > > diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h > > index f0ccca16a0ac..d9d1c67c8579 100644 > > --- a/include/linux/dma-mapping.h > > +++ b/include/linux/dma-mapping.h > > @@ -144,6 +144,7 @@ bool dma_pci_p2pdma_supported(struct device > *dev); > > int dma_set_mask(struct device *dev, u64 mask); > > int dma_set_coherent_mask(struct device *dev, u64 mask); > > u64 dma_get_required_mask(struct device *dev); > > +bool all_ram_in_dma_range_map(struct device *dev); > > size_t dma_max_mapping_size(struct device *dev); > > size_t dma_opt_mapping_size(struct device *dev); > > bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); @@ > > -475,8 +476,11 @@ static inline int dma_coerce_mask_and_coherent(struct > device *dev, u64 mask) > > */ > > static inline 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)) > > Nit: indentation > > > + return true; > > + > > + return !all_ram_in_dma_range_map(dev); > > } > > > > static inline unsigned int dma_get_max_seg_size(struct device *dev) > > diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index > > e323ca48f7f2..ab407deb81b8 100644 > > --- a/kernel/dma/mapping.c > > +++ b/kernel/dma/mapping.c > > @@ -14,6 +14,7 @@ > > #include <linux/of_device.h> > > #include <linux/slab.h> > > #include <linux/vmalloc.h> > > +#include <linux/dma-direct.h> > > Nit: please keep the includes sorted alphabetically, however I do wonder > whether this whole thing shouldn't belong in dma-direct anyway. The dma-direct.h is for including struct bus_dma_region only. Maybe I need to move struct bus_dma_region to a proper header file? > > > #include "debug.h" > > #include "direct.h" > > > > @@ -819,6 +820,50 @@ size_t dma_opt_mapping_size(struct device *dev) > > } > > EXPORT_SYMBOL_GPL(dma_opt_mapping_size); > > > > +/* > > + * To check whether all ram resource ranges are mapped in dma range > > +map > > + * Returns 0 when continuous check is needed > > + * Returns 1 if there is some ram range can't be mapped to > > +dma_range_map */ static int check_ram_in_range_map(unsigned long > > +start_pfn, > > + unsigned long nr_pages, void *data) { > > + phys_addr_t end_paddr = (start_pfn + nr_pages) << PAGE_SHIFT; > > This could still wrap to 0 on 32-bit. I think the robust thing to do is either spray > some extra -1s and +1s around to make all the "end" values inclusive limits, or > maybe just do everything in units of pages rather than bytes (i.e. use > PFN_DOWN() on the bus_dma_region entry values). > Ok, let me try the latter one, which looks easier to me. > > + phys_addr_t start_paddr = start_pfn << PAGE_SHIFT; > > + struct device *dev = (struct device *)data; > > + struct bus_dma_region *region = NULL; > > + const struct bus_dma_region *m; > > + > > + while (start_paddr < end_paddr) { > > + // find region containing start_paddr > > Nit: inconsistent comment style (although it's not a particularly valuable > comment anyway, IMO the loop itself is clear enough). > Sure, let me remove it. -- Cheers, Justin (Jia He)
diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index f0ccca16a0ac..d9d1c67c8579 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -144,6 +144,7 @@ bool dma_pci_p2pdma_supported(struct device *dev); int dma_set_mask(struct device *dev, u64 mask); int dma_set_coherent_mask(struct device *dev, u64 mask); u64 dma_get_required_mask(struct device *dev); +bool all_ram_in_dma_range_map(struct device *dev); size_t dma_max_mapping_size(struct device *dev); size_t dma_opt_mapping_size(struct device *dev); bool dma_need_sync(struct device *dev, dma_addr_t dma_addr); @@ -475,8 +476,11 @@ static inline int dma_coerce_mask_and_coherent(struct device *dev, u64 mask) */ static inline 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); } static inline unsigned int dma_get_max_seg_size(struct device *dev) diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index e323ca48f7f2..ab407deb81b8 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -14,6 +14,7 @@ #include <linux/of_device.h> #include <linux/slab.h> #include <linux/vmalloc.h> +#include <linux/dma-direct.h> #include "debug.h" #include "direct.h" @@ -819,6 +820,50 @@ size_t dma_opt_mapping_size(struct device *dev) } EXPORT_SYMBOL_GPL(dma_opt_mapping_size); +/* + * To check whether all ram resource ranges are mapped in dma range map + * Returns 0 when continuous check is needed + * Returns 1 if there is some ram range can't be mapped to dma_range_map + */ +static int check_ram_in_range_map(unsigned long start_pfn, + unsigned long nr_pages, void *data) +{ + phys_addr_t end_paddr = (start_pfn + nr_pages) << PAGE_SHIFT; + phys_addr_t start_paddr = start_pfn << PAGE_SHIFT; + struct device *dev = (struct device *)data; + struct bus_dma_region *region = NULL; + const struct bus_dma_region *m; + + while (start_paddr < end_paddr) { + // find region containing start_paddr + for (m = dev->dma_range_map; m->size; m++) { + if (start_paddr >= m->cpu_start + && start_paddr - m->cpu_start < m->size) { + region = (struct bus_dma_region *)m; + break; + } + } + if (!region) + return 1; + + start_paddr = region->cpu_start + region->size; + /* handle overflow of phys_addr_t */ + if (start_paddr == 0) + break; + } + + return 0; +} + +bool all_ram_in_dma_range_map(struct device *dev) +{ + if (!dev->dma_range_map) + return 1; + + return !walk_system_ram_range(0, ULONG_MAX, dev, check_ram_in_range_map); +} +EXPORT_SYMBOL_GPL(all_ram_in_dma_range_map); + bool dma_need_sync(struct device *dev, dma_addr_t dma_addr) { const struct dma_map_ops *ops = get_dma_ops(dev);