From patchwork Wed Dec 27 15:04:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 183494 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1493762dyb; Wed, 27 Dec 2023 07:19:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IHdMhsclf0qXmCDZhIcB1OKhLz/Hue/wNb2RRli7KHwOxEvAjgZ2FO9jSS4Vv3cIgs8u8Za X-Received: by 2002:a17:903:230d:b0:1d3:155b:8181 with SMTP id d13-20020a170903230d00b001d3155b8181mr11972703plh.1.1703690378045; Wed, 27 Dec 2023 07:19:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703690378; cv=none; d=google.com; s=arc-20160816; b=mkmowdOmPB7HE0MMUb38ryLpHr7ttt1DOnGpdvsAoS+kLYTgi8ZapgY64kOd3eh8yk 8qFbOL99o1y0Ew2R7vnNbI1xutioZFYcwNCNdjRRctrr1cDglOFuEFCt6rixYATChd2t vTNQTEa+v+B4Dz09djo3m2MKQopRGsEmxLrKzTqLQq8QIUhN/bSSvNlWCGapZ8jx4BVB 1XgU6L5JrpRJgBbdK9OHyVa8kiwyehnH+7kUoXZ+jRBYiST6PqiX+aRokhJ6qemDMQ2h ttJzpfKTpUszmxrMMftVjxn3gBijzMqFHglKqwVf2C5fGQA5nkvGFEu3HVJLdbVryeah 0ZjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GzIgESaYmJMXfkzKpVfVmI14OpFWOuNDrszgjEjlO94=; fh=4ESZ1c62iMGhYlhC2pjn9wB4qPFQ2ZNstb13IlN3w/8=; b=PtlOHjey4OZj38hQTGCiHAo0RoadzbJSpUXK5evpYtuM5wU9Uk4tCJMvSy9doQ1cP7 UdeQ/EoTfDw8OjFvuEsFZBkuJu8x/g1zJu1T9+sMhcVioXqrYJX0oYMAkB2bfAoAAxXZ ox9+0APd0+OSMVJUKIgFwGLIN6DUlYfAIyEt7zApvWquDUFLwDQslJtgCyW7PLeqkJiW n5JAZCLmuFSHV9ZyEKG+M84dUIIWDEbT24JxyvtuSJPk3CjqL1Gepzc+dhIGjaLfVUD6 PTOMimpo1jBzw+0TTgGm+cgz5ohpo9f4mjoUBk6yT9H3aQMm+Vdj55ilhgc1Y3RFWbAE CiSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=NDqdcjcT; spf=pass (google.com: domain of linux-kernel+bounces-12079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id t5-20020a1709028c8500b001d47bbe7dedsi1610318plo.616.2023.12.27.07.19.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 07:19:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=NDqdcjcT; spf=pass (google.com: domain of linux-kernel+bounces-12079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 9E4BEB2253D for ; Wed, 27 Dec 2023 15:13:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CB77346B9F; Wed, 27 Dec 2023 15:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="NDqdcjcT" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.tkos.co.il (hours.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3EC5E4595B; Wed, 27 Dec 2023 15:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il Received: from tarshish.tkos.co.il (unknown [10.0.8.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 43D39440F19; Wed, 27 Dec 2023 17:02:43 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1703689363; bh=NDjhIXrijySlyAenotxkN/N6ucKkMmhIuT0+ciVsprY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NDqdcjcTK2m+7XK61ZGidZ5CHtBbiSX38xo6izGJCY26bma2wq7IBWT4vz000eUw1 GBbwyf7OQe+WaevbOBXI+5vavzS5FexuGsu1cTgMYyNCTp1yxO8Kx5jqkppNWa6Z8j G/94uSrvb6kFeiuJzbR3wWgZFMCTFEAZXRRD5jqHa1q3iQwABRitbkrY3IBwFqBRM9 ZlogSwyK6XNcbZ5B6kSPEuHxCz0+ItVYTRfoquADxy8KvWxqqP11b4ScQU54jhnxXU S5X08TEbiHVEdcVcv7WEld7Zmelmi5aa6tL4Gh5BrEponHpbVWgdEmUQ1qNIAqcQTZ dZT3UDYjbT/8A== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Frank Rowand , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried Subject: [PATCH RFC 1/4] of: get dma area lower limit Date: Wed, 27 Dec 2023 17:04:25 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786448841767247450 X-GMAIL-MSGID: 1786448841767247450 of_dma_get_max_cpu_address() returns the highest CPU address that devices can use for DMA. The implicit assumption is that all CPU addresses below that limit are suitable for DMA. However the 'dma-ranges' property this code uses also encodes a lower limit for DMA that is potentially non zero. Rename to of_dma_get_cpu_limits(), and extend to retrieve also the lower limit for the same 'dma-ranges' property describing the high limit. Update callers of of_dma_get_max_cpu_address(). No functional change intended. Signed-off-by: Baruch Siach --- arch/arm64/mm/init.c | 4 +++- drivers/of/address.c | 38 +++++++++++++++++++++++++++----------- drivers/of/unittest.c | 8 ++++---- include/linux/of.h | 11 ++++++++--- 4 files changed, 42 insertions(+), 19 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index 74c1db8ce271..d6c723ae6fb0 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -136,11 +136,13 @@ static void __init zone_sizes_init(void) unsigned long max_zone_pfns[MAX_NR_ZONES] = {0}; unsigned int __maybe_unused acpi_zone_dma_bits; unsigned int __maybe_unused dt_zone_dma_bits; + phys_addr_t __maybe_unused max_cpu_address; phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32); #ifdef CONFIG_ZONE_DMA acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address()); - dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL)); + of_dma_get_cpu_limits(NULL, &max_cpu_address, NULL); + dt_zone_dma_bits = fls64(max_cpu_address); zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); arm64_dma_phys_limit = max_zone_phys(zone_dma_bits); max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); diff --git a/drivers/of/address.c b/drivers/of/address.c index b59956310f66..51fa52bbe911 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -965,21 +965,25 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) #endif /* CONFIG_HAS_DMA */ /** - * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA + * of_dma_get_cpu_limits - Gets highest CPU address suitable for DMA * @np: The node to start searching from or NULL to start from the root + * @max: Pointer to high address limit or NULL if not needed + * @min: Pointer to low address limit or NULL if not needed * * Gets the highest CPU physical address that is addressable by all DMA masters - * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no - * DMA constrained device is found, it returns PHYS_ADDR_MAX. + * in the sub-tree pointed by np, or the whole tree if @np in NULL. If no + * DMA constrained device is found, @*max is PHYS_ADDR_MAX, and @*low is 0. */ -phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np) +void __init of_dma_get_cpu_limits(struct device_node *np, + phys_addr_t *max, phys_addr_t *min) { phys_addr_t max_cpu_addr = PHYS_ADDR_MAX; struct of_range_parser parser; - phys_addr_t subtree_max_addr; + phys_addr_t min_cpu_addr = 0; struct device_node *child; struct of_range range; const __be32 *ranges; + u64 cpu_start = 0; u64 cpu_end = 0; int len; @@ -989,21 +993,33 @@ phys_addr_t __init of_dma_get_max_cpu_address(struct device_node *np) ranges = of_get_property(np, "dma-ranges", &len); if (ranges && len) { of_dma_range_parser_init(&parser, np); - for_each_of_range(&parser, &range) - if (range.cpu_addr + range.size > cpu_end) + for_each_of_range(&parser, &range) { + if (range.cpu_addr + range.size > cpu_end) { cpu_end = range.cpu_addr + range.size - 1; + cpu_start = range.cpu_addr; + } + } - if (max_cpu_addr > cpu_end) + if (max_cpu_addr > cpu_end) { max_cpu_addr = cpu_end; + min_cpu_addr = cpu_start; + } } for_each_available_child_of_node(np, child) { - subtree_max_addr = of_dma_get_max_cpu_address(child); - if (max_cpu_addr > subtree_max_addr) + phys_addr_t subtree_max_addr, subtree_min_addr; + + of_dma_get_cpu_limits(child, &subtree_max_addr, &subtree_min_addr); + if (max_cpu_addr > subtree_max_addr) { max_cpu_addr = subtree_max_addr; + min_cpu_addr = subtree_min_addr; + } } - return max_cpu_addr; + if (max) + *max = max_cpu_addr; + if (min) + *min = min_cpu_addr; } /** diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index e9e90e96600e..21d273a05ba6 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -908,7 +908,7 @@ static void __init of_unittest_changeset(void) #endif } -static void __init of_unittest_dma_get_max_cpu_address(void) +static void __init of_unittest_dma_get_cpu_limits(void) { struct device_node *np; phys_addr_t cpu_addr; @@ -922,9 +922,9 @@ static void __init of_unittest_dma_get_max_cpu_address(void) return; } - cpu_addr = of_dma_get_max_cpu_address(np); + of_dma_get_cpu_limits(np, &cpu_addr, NULL); unittest(cpu_addr == 0x4fffffff, - "of_dma_get_max_cpu_address: wrong CPU addr %pad (expecting %x)\n", + "of_dma_get_cpu_limits: wrong CPU addr %pad (expecting %x)\n", &cpu_addr, 0x4fffffff); } @@ -4104,7 +4104,7 @@ static int __init of_unittest(void) of_unittest_changeset(); of_unittest_parse_interrupts(); of_unittest_parse_interrupts_extended(); - of_unittest_dma_get_max_cpu_address(); + of_unittest_dma_get_cpu_limits(); of_unittest_parse_dma_ranges(); of_unittest_pci_dma_ranges(); of_unittest_bus_ranges(); diff --git a/include/linux/of.h b/include/linux/of.h index 6a9ddf20e79a..629b402d81bf 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -445,7 +445,8 @@ int of_map_id(struct device_node *np, u32 id, const char *map_name, const char *map_mask_name, struct device_node **target, u32 *id_out); -phys_addr_t of_dma_get_max_cpu_address(struct device_node *np); +void of_dma_get_cpu_limits(struct device_node *np, phys_addr_t *max, + phys_addr_t *min); struct kimage; void *of_kexec_alloc_and_setup_fdt(const struct kimage *image, @@ -865,9 +866,13 @@ static inline int of_map_id(struct device_node *np, u32 id, return -EINVAL; } -static inline phys_addr_t of_dma_get_max_cpu_address(struct device_node *np) +static inline void of_dma_get_cpu_limits(struct device_node *np, + phys_addr_t *max, phys_addr_t *min) { - return PHYS_ADDR_MAX; + if (max) + *max = PHYS_ADDR_MAX; + if (min) + *min = 0; } static inline const void *of_device_get_match_data(const struct device *dev) From patchwork Wed Dec 27 15:04:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 183489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1489516dyb; Wed, 27 Dec 2023 07:13:10 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwbPFT6VOD6c4oW8AsXmFLDIdrG1cn+JAsc2gSP+tWHzA1EqtRUVMUhzPBHYSyG8kkuL99 X-Received: by 2002:a05:6808:4490:b0:3bb:c750:b99e with SMTP id eq16-20020a056808449000b003bbc750b99emr1203935oib.76.1703689990567; Wed, 27 Dec 2023 07:13:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703689990; cv=none; d=google.com; s=arc-20160816; b=plkeAil3W9a7xaJ76VtV4ssGzB3hqT0iLpuDCfsjWVvYr0LrBQHQRpMPSIG6qetmMF O6vq55uVMwvqUqXKk7+d/VMijHFjk+2x1aAaDyw4TAx1trw8EQOTH3SmZyUSA11usi+n jGKwv2DR6BWClHzTWUnY0xyoCh3B0VZtYJ1IC/bTqPA/A/RuAmKKLubpmr8hilweMnOj DOObTw3LANbw1x2rkFxEv4GrSdXH84vvoO5aCwIFcVhRWS9/iKRbgzkGndSH639vghy1 gF/f5n6BCjC9ykLYD891i3nSLTbg3ArFSt7RpjgLJo0j1VVFoUFe3Zy+WNRI0YwBk7Js 9hpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=GWsenZ5c4q8EEYc1AND5IbedgsVdySqhxGYR7OEzvMs=; fh=4ESZ1c62iMGhYlhC2pjn9wB4qPFQ2ZNstb13IlN3w/8=; b=Ntzj2kplyC1Zjbo1Y+UA1RLXo46N/gaGp3y8A+WVYmlWebHx2SHaZ122hNASol+MQb Ve7j+IsfZuFz11xX/SfhQNFsyKT2c42ES4/oScn5BVlbSj5Nm4OrFcykFsdQu/ISZOn7 EvNwpYChOi90JJtZ68gj1HqXBe3elmczuCLbqZHOwq24jvwpsp8UhwJtLLIJOuzqnTkv FCF0Skvvdfi3fgD4eg2OCgY4nLlTvjDt1i4YUGX02pqq67Q5zW+MGKBi+hx+6Qi7g2hd LO/BUNa88VGS8OrJTlDsQ3PR8XoFn40OCx47zYvBnoZ1fXappjwQbHNDUIuKUhhfMTcK EU5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=mo8kuyQN; spf=pass (google.com: domain of linux-kernel+bounces-12075-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12075-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id m2-20020a0561023e8200b004671dcc7601si499218vsv.220.2023.12.27.07.13.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 07:13:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12075-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=mo8kuyQN; spf=pass (google.com: domain of linux-kernel+bounces-12075-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12075-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 535381C21828 for ; Wed, 27 Dec 2023 15:13:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C034E4652F; Wed, 27 Dec 2023 15:12:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="mo8kuyQN" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.tkos.co.il (mail.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1F4145945; Wed, 27 Dec 2023 15:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il Received: from tarshish.tkos.co.il (unknown [10.0.8.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 9B3B4440F44; Wed, 27 Dec 2023 17:02:43 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1703689363; bh=vHknldfNxE6H031gNGXJeZaZPVKmHSiQjt/n9eWWmvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mo8kuyQN+AxfYfCNDNSuV7Xg9+Hh8qX3c8Ccb7hNdP1yl4uRh6Ays7AwF/oL0Wlnb sFFQUfKuwK9waKPQYMFGGyU5MOuL49rj8n0iThLx3uWD7bWmfiY7fkOgTyd2ry9q4H I2X6UQrFkZRkBtIO0Av1+6Bnpt1FuX136J2T/zU9e6NiwGPO9N+Ar02+IiMjckBYDP lNDV/T3N3w7UXhPiHIP8UeaCfy7R6mNBgTQhndtuoWeld/Ku/vr+H2kcfwXKmge28Y IUgg/NrAtre8xqij2GLQkalGCiD7vum2qsElzd84bvK8CE1IF3l1wdjA6CCLRhG7We RyPND9l8Ga1bw== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Frank Rowand , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried Subject: [PATCH RFC 2/4] of: unittest: add test for of_dma_get_cpu_limits() 'min' param Date: Wed, 27 Dec 2023 17:04:26 +0200 Message-ID: <9704923d06839d92f4ef6fb28523b0f47e154df4.1703683642.git.baruch@tkos.co.il> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786448435233479043 X-GMAIL-MSGID: 1786448435233479043 Verify that of_dma_get_cpu_limits() sets this new parameter to the expected result. Signed-off-by: Baruch Siach --- drivers/of/unittest.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 21d273a05ba6..d3b2c6ca56cd 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -911,7 +911,7 @@ static void __init of_unittest_changeset(void) static void __init of_unittest_dma_get_cpu_limits(void) { struct device_node *np; - phys_addr_t cpu_addr; + phys_addr_t cpu_addr_max, cpu_addr_min; if (!IS_ENABLED(CONFIG_OF_ADDRESS)) return; @@ -922,10 +922,13 @@ static void __init of_unittest_dma_get_cpu_limits(void) return; } - of_dma_get_cpu_limits(np, &cpu_addr, NULL); - unittest(cpu_addr == 0x4fffffff, - "of_dma_get_cpu_limits: wrong CPU addr %pad (expecting %x)\n", - &cpu_addr, 0x4fffffff); + of_dma_get_cpu_limits(np, &cpu_addr_max, &cpu_addr_min); + unittest(cpu_addr_max == 0x4fffffff, + "of_dma_get_cpu_limits: wrong CPU max addr %pad (expecting %x)\n", + &cpu_addr_max, 0x4fffffff); + unittest(cpu_addr_min == 0x40000000, + "of_dma_get_cpu_limits: wrong CPU min addr %pad (expecting %x)\n", + &cpu_addr_min, 0x40000000); } static void __init of_unittest_dma_ranges_one(const char *path, From patchwork Wed Dec 27 15:04:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 183491 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1489739dyb; Wed, 27 Dec 2023 07:13:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IE3HRY/J7+YwlwgLwp50Yul+GujP6DMMDvOfmk4vgzPTKkeq5bZcwWstdt9Gns6RMWL0DTN X-Received: by 2002:a05:6a00:1d89:b0:6d9:b0ec:259a with SMTP id z9-20020a056a001d8900b006d9b0ec259amr1712691pfw.65.1703690007714; Wed, 27 Dec 2023 07:13:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703690007; cv=none; d=google.com; s=arc-20160816; b=wYjHoyp4amGVMP/tJibVf9+o8kQ3DTVhw1w9oth/glVUhJyBZaA64nEgB0GxaP9jEo sAYsV9R3XNTEiBIepMkOOo3qx9TPNxEYpwSSHf5e4YYJ4lnrCDDm7ujmsPOnk5e3olrG z4Rlapn/5/qLsaBcO/XMrgJfFMpzcPm5Z3UzixxLYC8rLdkC2QQ7eugtxpVKF1dOi0a0 A9DoSgTJSo4V6lInxnhjvxyxeL+10KahMTbYsfPIq0DAk9A5VdXSV62pqC8RWKZ/cNln kr8yzwObrWBUXeNHNu236/HluBxfgE9qLfC6knUmVpSZ1nwVO8GIsyhiud8C+R0hNWwm pwgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=UpeQjVcIvIDTirwrvD24BariIFRBko8olSTXSbStkLI=; fh=4ESZ1c62iMGhYlhC2pjn9wB4qPFQ2ZNstb13IlN3w/8=; b=EyNS4/M1OJZdUyqQU4v1p6o52FQWahcattPwW8jx3qpfSyF/66NfCeY/WycMT8QBge qxtxQYzTiGUzx/cBzmQ2poijs+6rN+dZodVYIUbYj0UnDsQhvdmNrYoUpR1WnpY1ZVOW PuB6VNR2S6h2snYQ93w7TwLsXXMr503JD42maWJg/noc8XZASfsLEnJqExQmhyNrCKL7 vh4JAqZoRx/LXbe7d2alFozbl3dZMgfrWpsmVLbcqclk/txT8U2vjv6f5vzmUfU1Kty+ 50uYPfosbruHHyp7vbw1XphJwFJdyaYfY+ZiyoMKoO/u/Ml6n6IMLJ+TQrewpEhRZ6UV 9H2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=YoaHfAea; spf=pass (google.com: domain of linux-kernel+bounces-12078-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12078-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a25-20020a656419000000b005ce0b70d2b0si6493618pgv.102.2023.12.27.07.13.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 07:13:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12078-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=YoaHfAea; spf=pass (google.com: domain of linux-kernel+bounces-12078-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12078-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 355A3283881 for ; Wed, 27 Dec 2023 15:13:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F38546B80; Wed, 27 Dec 2023 15:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="YoaHfAea" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.tkos.co.il (mail.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A8C345957; Wed, 27 Dec 2023 15:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il Received: from tarshish.tkos.co.il (unknown [10.0.8.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 14300440F4B; Wed, 27 Dec 2023 17:02:44 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1703689364; bh=st9CHgymVQhW3AqOhh2Rin5cH7JUg2qvgO/LnRxoumc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YoaHfAeaNk4IPaAWZfUwbo1ubF56b+leDPEd4c4QmVuIHJy/OFHORP1tdrd0ZBHih GEeHhUgDHV1h40Dm0kVpFDVWGczdYLfWSqAG1frkc4xywnvHxHbuv1SeJJ1tlepZBs tKuxvMy56I8tNUFNZT88w+a/5nPWUwhaJZEgjiYkF4VbUxsNB2VHAlhGp63I8f+btv SFUEnGnn4fgpmh7m10km6y4VqfClzcNVQpB+7O9paBCoYgKksirVPXIh+fcV0xikaj z5Qcpw1ROUGDFlH8BBsmv/kKhaz7blHANDbenLCXGPyyEFuEI/nQStojzw5fwt4pw+ ONZwK5p79Fhbw== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Frank Rowand , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried Subject: [PATCH RFC 3/4] dma-direct: add offset to zone_dma_bits Date: Wed, 27 Dec 2023 17:04:27 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786448453585610934 X-GMAIL-MSGID: 1786448453585610934 Current code using zone_dma_bits assume that all addresses range in the bits mask are suitable for DMA. For some existing platforms this assumption is not correct. DMA range might have non zero lower limit. Add 'zone_dma_off' for platform code to set base address for DMA zone. Rename the dma_direct_supported() local 'min_mask' variable to better describe its use as limit. Suggested-by: Catalin Marinas Signed-off-by: Baruch Siach --- include/linux/dma-direct.h | 1 + kernel/dma/direct.c | 10 ++++++---- kernel/dma/pool.c | 2 +- kernel/dma/swiotlb.c | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/linux/dma-direct.h b/include/linux/dma-direct.h index 18aade195884..77c52019c1ff 100644 --- a/include/linux/dma-direct.h +++ b/include/linux/dma-direct.h @@ -13,6 +13,7 @@ #include extern unsigned int zone_dma_bits; +extern phys_addr_t zone_dma_off; /* * Record the mapping of CPU physical to DMA addresses for a given region. diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 73c95815789a..7a54fa71a174 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -21,6 +21,7 @@ * override the variable below for dma-direct to work properly. */ unsigned int zone_dma_bits __ro_after_init = 24; +phys_addr_t zone_dma_off __ro_after_init; static inline dma_addr_t phys_to_dma_direct(struct device *dev, phys_addr_t phys) @@ -59,7 +60,7 @@ static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 *phys_limit) * zones. */ *phys_limit = dma_to_phys(dev, dma_limit); - if (*phys_limit <= DMA_BIT_MASK(zone_dma_bits)) + if (*phys_limit <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits)) return GFP_DMA; if (*phys_limit <= DMA_BIT_MASK(32)) return GFP_DMA32; @@ -566,7 +567,7 @@ int dma_direct_mmap(struct device *dev, struct vm_area_struct *vma, int dma_direct_supported(struct device *dev, u64 mask) { - u64 min_mask = (max_pfn - 1) << PAGE_SHIFT; + u64 min_limit = (max_pfn - 1) << PAGE_SHIFT; /* * Because 32-bit DMA masks are so common we expect every architecture @@ -583,8 +584,9 @@ int dma_direct_supported(struct device *dev, u64 mask) * part of the check. */ if (IS_ENABLED(CONFIG_ZONE_DMA)) - min_mask = min_t(u64, min_mask, DMA_BIT_MASK(zone_dma_bits)); - return mask >= phys_to_dma_unencrypted(dev, min_mask); + min_limit = min_t(u64, min_limit, + zone_dma_off + DMA_BIT_MASK(zone_dma_bits)); + return mask >= phys_to_dma_unencrypted(dev, min_limit); } /* diff --git a/kernel/dma/pool.c b/kernel/dma/pool.c index b481c48a31a6..0103e932444d 100644 --- a/kernel/dma/pool.c +++ b/kernel/dma/pool.c @@ -70,7 +70,7 @@ static bool cma_in_zone(gfp_t gfp) /* CMA can't cross zone boundaries, see cma_activate_area() */ end = cma_get_base(cma) + size - 1; if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp & GFP_DMA)) - return end <= DMA_BIT_MASK(zone_dma_bits); + return end <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits); if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp & GFP_DMA32)) return end <= DMA_BIT_MASK(32); return true; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 33d942615be5..bd3071894d2b 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -446,7 +446,8 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask, if (!remap) io_tlb_default_mem.can_grow = true; if (IS_ENABLED(CONFIG_ZONE_DMA) && (gfp_mask & __GFP_DMA)) - io_tlb_default_mem.phys_limit = DMA_BIT_MASK(zone_dma_bits); + io_tlb_default_mem.phys_limit = + zone_dma_off + DMA_BIT_MASK(zone_dma_bits); else if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp_mask & __GFP_DMA32)) io_tlb_default_mem.phys_limit = DMA_BIT_MASK(32); else @@ -625,7 +626,7 @@ static struct page *swiotlb_alloc_tlb(struct device *dev, size_t bytes, } gfp &= ~GFP_ZONEMASK; - if (phys_limit <= DMA_BIT_MASK(zone_dma_bits)) + if (phys_limit <= zone_dma_off + DMA_BIT_MASK(zone_dma_bits)) gfp |= __GFP_DMA; else if (phys_limit <= DMA_BIT_MASK(32)) gfp |= __GFP_DMA32; From patchwork Wed Dec 27 15:04:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baruch Siach X-Patchwork-Id: 183490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp1489710dyb; Wed, 27 Dec 2023 07:13:24 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkcH2mXtsPpWNWdGstdBMon4Xeko+uXD7aMjHNj+9CC1IAC9NxVw1anF3hfie4wD2TkOhY X-Received: by 2002:a50:d598:0:b0:553:6de7:3157 with SMTP id v24-20020a50d598000000b005536de73157mr5157523edi.76.1703690004459; Wed, 27 Dec 2023 07:13:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703690004; cv=none; d=google.com; s=arc-20160816; b=DZNDxdzdiqxFNfXE/N17RdeX7Y5yk4Rx9UbGBClBfBh56Nr9TSu3gvU81QWtbG1Seh +yeLMEq5FAuOKpE0+WkoMd1ZkDbQC0PeWy17SWtfkyAFPDkfViE/1CqPMKLvaihBV2XV TjJEMeFXvUUZD/77zTW/4+3jAOzC1ggSIavSJnq89WZUzhPbYSeECCP+3j7AdLy3oP6h vUNHdyuEsyyRy82Sp+IlPeLZ+6pesncE9Cyox1MvWcQoCG9ZKsGNCoqoCUeJlQS70xnR tpoKJGRYXPumJsK4Rh9rklgOBP0D1hQZkCPazTrJWtG6dht7OsMNo7RnJBUqgqCGGEoV pisA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ra/yp9q/x7wzeSniZm4BQ1sWCUP/vjslHIYTwNRFw5g=; fh=4ESZ1c62iMGhYlhC2pjn9wB4qPFQ2ZNstb13IlN3w/8=; b=xv4ZFzKDC/3V/ED1rtWwOS/gW1oo/YUSnxFd26Kj/qZRB4weJ5lCBFnFDmkFx2F14O gX5reCa5AJruI+5IAP0jeKOIi6u+Ubkrj4D4Opb31JSmFW6mrbGr7fYzsT36efQM/+di 2OOlhXJQ4dfWkHj+/uUqs96z39rrITVH0PI/ljo6CA2Q3SelzUdXiRY6sUh2VBRGFyEb 71kbg3oR3Y+bsrAurLvAYTVpFURy/FZ4UM5hkKN3QwT/ncfQWPNjzxMog29gxAeYtAmc UKMwLcXekZ+U1cZZLbw8V2ken3DH2Fw47hXUiuos/GYodXqqZj+Nl87u7OCWsI6nSmMy EYYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=NxNyJc+I; spf=pass (google.com: domain of linux-kernel+bounces-12077-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12077-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id d25-20020a50cd59000000b0055366eab7e6si6100630edj.461.2023.12.27.07.13.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Dec 2023 07:13:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12077-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@tkos.co.il header.s=default header.b=NxNyJc+I; spf=pass (google.com: domain of linux-kernel+bounces-12077-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12077-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tkos.co.il Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7A51C1F22113 for ; Wed, 27 Dec 2023 15:13:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6357446557; Wed, 27 Dec 2023 15:12:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=tkos.co.il header.i=@tkos.co.il header.b="NxNyJc+I" X-Original-To: linux-kernel@vger.kernel.org Received: from mail.tkos.co.il (mail.tkos.co.il [84.110.109.230]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EFB5A4594F; Wed, 27 Dec 2023 15:12:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tkos.co.il Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tkos.co.il Received: from tarshish.tkos.co.il (unknown [10.0.8.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.tkos.co.il (Postfix) with ESMTPS id 83D11440F4F; Wed, 27 Dec 2023 17:02:44 +0200 (IST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tkos.co.il; s=default; t=1703689364; bh=z/R1KgqdKS7NyxMFjGVmdIDGKoIBS1QfbhFNrs3Fnbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NxNyJc+IY8RZrFmWwyP1yFuErwO6dUxa893heT/GsEdHBoJSid19eX8xWM4HFb1vh Tb1WRVA0fGMIvU7ofAVvI8euZs3sZyT3MJao8Svo6d0Ey4smRJZkOUB3lc3Usiy9Ec 9h/aOPBmjcxWrfCbFHxxe2SzF8IIuwFbEoAxy7qX0HeeH6bArOLQNjEFdSS15LEhjG 6JvO61GhQB8nCCrYzuYHnsOE0XzMmzmQ+cOjLbto2inSFTfw9F53XOhBM1LMGmx7oa UioelDo5PlbEIUGcplg4IFzjWB/YoP6iaQIjYrI/ay6trFf02fqvkv5k4f56mKm4hW PiOD+SINQYQ6A== From: Baruch Siach To: Christoph Hellwig , Marek Szyprowski , Rob Herring , Frank Rowand , Catalin Marinas , Will Deacon Cc: Baruch Siach , Robin Murphy , iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, =?utf-8?b?UGV0ciBUZXNhxZnDrWs=?= , Ramon Fried Subject: [PATCH RFC 4/4] arm64: mm: take DMA zone offset into account Date: Wed, 27 Dec 2023 17:04:28 +0200 Message-ID: X-Mailer: git-send-email 2.43.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786448449703569478 X-GMAIL-MSGID: 1786448449703569478 Commit 791ab8b2e3db ("arm64: Ignore any DMA offsets in the max_zone_phys() calculation") made DMA/DMA32 zones span the entire RAM when RAM starts above 32-bits. This breaks hardware with DMA area that start above 32-bits. But the commit log says that "we haven't noticed any such hardware". It turns out that such hardware does exist. One such platform has RAM starting at 32GB with an internal bus that has the following DMA limits: #address-cells = <2>; #size-cells = <2>; dma-ranges = <0x00 0xc0000000 0x08 0x00000000 0x00 0x40000000>; Devices under this bus can see 1GB of DMA range between 3GB-4GB in each device address space. This range is mapped to CPU memory at 32GB-33GB. With current code DMA allocations for devices under this bus are not limited to DMA area, leading to run-time allocation failure. Modify 'zone_dma_bits' calculation (via dt_zone_dma_bits) to only cover the actual DMA area starting at 'zone_dma_off'. Use the newly introduced 'min' parameter of of_dma_get_cpu_limits() to set 'zone_dma_off'. DMA32 zone is useless in this configuration, so make its limit the same as the DMA zone when the lower DMA limit is higher than 32-bits. The result is DMA zone that properly reflects the hardware constraints as follows: [ 0.000000] Zone ranges: [ 0.000000] DMA [mem 0x0000000800000000-0x000000083fffffff] [ 0.000000] DMA32 empty [ 0.000000] Normal [mem 0x0000000840000000-0x0000000bffffffff] Suggested-by: Catalin Marinas Signed-off-by: Baruch Siach --- arch/arm64/mm/init.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c index d6c723ae6fb0..4a8fd8394ce6 100644 --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -118,10 +118,11 @@ static void __init arch_reserve_crashkernel(void) * limit. If DRAM starts above 32-bit, expand the zone to the maximum * available memory, otherwise cap it at 32-bit. */ -static phys_addr_t __init max_zone_phys(unsigned int zone_bits) +static phys_addr_t __init max_zone_phys(unsigned int zone_bits, + phys_addr_t zone_off) { phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits); - phys_addr_t phys_start = memblock_start_of_DRAM(); + phys_addr_t phys_start = memblock_start_of_DRAM() - zone_off; if (phys_start > U32_MAX) zone_mask = PHYS_ADDR_MAX; @@ -137,14 +138,19 @@ static void __init zone_sizes_init(void) unsigned int __maybe_unused acpi_zone_dma_bits; unsigned int __maybe_unused dt_zone_dma_bits; phys_addr_t __maybe_unused max_cpu_address; - phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32); + phys_addr_t __maybe_unused min_cpu_address; + phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32, 0); #ifdef CONFIG_ZONE_DMA acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address()); - of_dma_get_cpu_limits(NULL, &max_cpu_address, NULL); - dt_zone_dma_bits = fls64(max_cpu_address); + of_dma_get_cpu_limits(NULL, &max_cpu_address, &min_cpu_address); + dt_zone_dma_bits = fls64(max_cpu_address - min_cpu_address); zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits); - arm64_dma_phys_limit = max_zone_phys(zone_dma_bits); + zone_dma_off = min_cpu_address; + arm64_dma_phys_limit = max_zone_phys(zone_dma_bits, zone_dma_off) + + zone_dma_off; + if (zone_dma_off > U32_MAX) + dma32_phys_limit = arm64_dma_phys_limit; max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit); #endif #ifdef CONFIG_ZONE_DMA32