Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3029450rwo; Mon, 24 Jul 2023 05:21:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlEh7sqisGX5vzQgQwAMbHMzJfAxonBOuMrTs7FXO6mjUSvpT8uxPotXPV6Q2PIh2JyNDNnk X-Received: by 2002:a17:903:1c7:b0:1bb:14e7:4fdc with SMTP id e7-20020a17090301c700b001bb14e74fdcmr12497592plh.61.1690201289085; Mon, 24 Jul 2023 05:21:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690201289; cv=none; d=google.com; s=arc-20160816; b=C3DaBzkQfsOUKp3GZUBQ913IeIUBKY+fG7iBVu8Bd8YD88oaiHsYtnLPO4csT4y0Yc 7zdItSS1iWs76ENQ1Ts46IrCmJBQ2AN8oYfU0ZqbeC1fA/llzq5SWWrZPdnbyWwsHULY Vw0BBAjkj5sndmi1dyug0z/A0/8q1th2r/57MQoXZP5tDBPIteKaF38I2zDqiIh9AHPA zHO+8hnhFiy9uVEJcQZ/A9u5AhWKTgQ6ErTobSKVfMBVIe0HMPThpV3GRSs37h/v+sz6 VJWaqxqMDDhysGEtkpLqCIFKlOfK/ZuGa58MtPgMoE7duoC4JSu5VI1I/GPIi/kiZ4W1 Gb4Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3UsclA8esb5yjaA+NGjJNgEmQ0LgzxquKTs0lPBUKfU=; fh=dVJW99k/j9JQXeFtpLIDAtb2mvVhjCi4JR/3W8vTvUA=; b=I0McMblKexAIngC9IRywTbxSNvgJa5GPKGWwN8ZUuEgX8jX0L8gYnEVwN/E0H0XNs+ Du2BZ1s9IyVy3OtmzN8om85B6JZ8fJmCznV7ExqmNXCoz3AxtqeQ6vwWT4m5KeDbZwTy ptsHXXs0ttpjKBGLunqWWz0nhITccMXfxVKJbgNI9ITbnIN7NsU2t4pOKZO+JCcekRm2 LmGlQ52iziPqDFeTHBugijIGRTwqRN/2z7bHjanXKKJAlE2mS5vQHBltB/l2IYkRZhTH 2FGbhqOSRWil4ouyTRZKmpTXmhSIfobO6lqtg7izoJMdWbQUNw/DZz2ltlWLgXRMZeS4 tiZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ke11-20020a170903340b00b001b9fef6bf58si8575802plb.294.2023.07.24.05.21.16; Mon, 24 Jul 2023 05:21:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230356AbjGXMQT (ORCPT + 99 others); Mon, 24 Jul 2023 08:16:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjGXMQJ (ORCPT ); Mon, 24 Jul 2023 08:16:09 -0400 Received: from frasgout11.his.huawei.com (unknown [14.137.139.23]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 614301994; Mon, 24 Jul 2023 05:15:41 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout11.his.huawei.com (SkyGuard) with ESMTP id 4R8f321FSdz9ynSq; Mon, 24 Jul 2023 20:04:14 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.222.124]) by APP2 (Coremail) with SMTP id GxC2BwA3_lTGar5ky0byBA--.27936S9; Mon, 24 Jul 2023 13:14:51 +0100 (CET) From: Petr Tesarik To: Stefano Stabellini , Russell King , Thomas Bogendoerfer , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Juergen Gross , Oleksandr Tyshchenko , Christoph Hellwig , Marek Szyprowski , Robin Murphy , Jonathan Corbet , Andy Shevchenko , Hans de Goede , Sakari Ailus , James Seo , James Clark , Kees Cook , xen-devel@lists.xenproject.org (moderated list:XEN HYPERVISOR ARM), linux-arm-kernel@lists.infradead.org (moderated list:ARM PORT), linux-kernel@vger.kernel.org (open list), linux-mips@vger.kernel.org (open list:MIPS), iommu@lists.linux.dev (open list:XEN SWIOTLB SUBSYSTEM) Cc: Roberto Sassu , petr@tesarici.cz Subject: [PATCH v5 7/9] swiotlb: determine potential physical address limit Date: Mon, 24 Jul 2023 14:12:43 +0200 Message-Id: <0d4d789bf4d7caddb88c5690a82c66f146532a3e.1690200598.git.petr.tesarik.ext@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: GxC2BwA3_lTGar5ky0byBA--.27936S9 X-Coremail-Antispam: 1UD129KBjvJXoWxXw4fJr1kZrW7Cry5Cw4xtFb_yoW5AF4DpF y8Jr4FgFsFqF12yrWxCw1IyFn5Ga18CrW29rW5urnxZr17Ww13Wrs7Kr45trySqF4IgF4S 9Fyxua4Y9FsFv37anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUml14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26r4j6F4UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_ Cr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x IIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_ Gr1lF7xvr2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8c xan2IY04v7MxkF7I0Ew4C26cxK6c8Ij28IcwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE 7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI 8E67AF67kF1VAFwI0_Wrv_Gr1UMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_JFI_ Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r 1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr1j6F4U JbIYCTnIWIevJa73UjIFyTuYvjfUnzVbDUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_L3,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Petr Tesarik The value returned by default_swiotlb_limit() should be constant, because it is used to decide whether DMA can be used. To allow allocating memory pools on the fly, use the maximum possible physical address rather than the highest address used by the default pool. For swiotlb_init_remap(), this is either an arch-specific limit used by memblock_alloc_low(), or the highest directly mapped physical address if the initialization flags include SWIOTLB_ANY. For swiotlb_init_late(), the highest address is determined by the GFP flags. Signed-off-by: Petr Tesarik --- include/linux/swiotlb.h | 2 ++ kernel/dma/swiotlb.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index ad5bdf66ed7a..d5ce51657fac 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -109,6 +109,7 @@ struct io_tlb_pool { * @force_bounce: %true if swiotlb bouncing is forced * @for_alloc: %true if the pool is used for memory allocation * @can_grow: %true if more pools can be allocated dynamically. + * @phys_limit: Maximum allowed physical address. * @total_used: The total number of slots in the pool that are currently used * across all areas. Used only for calculating used_hiwater in * debugfs. @@ -123,6 +124,7 @@ struct io_tlb_mem { bool for_alloc; #ifdef CONFIG_SWIOTLB_DYNAMIC bool can_grow; + u64 phys_limit; #endif #ifdef CONFIG_DEBUG_FS atomic_long_t total_used; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 8672810f7c56..7e8edf011bba 100644 --- a/kernel/dma/swiotlb.c +++ b/kernel/dma/swiotlb.c @@ -334,6 +334,10 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags, #ifdef CONFIG_SWIOTLB_DYNAMIC if (!remap) io_tlb_default_mem.can_grow = true; + if (flags & SWIOTLB_ANY) + io_tlb_default_mem.phys_limit = virt_to_phys(high_memory - 1); + else + io_tlb_default_mem.phys_limit = ARCH_LOW_ADDRESS_LIMIT; #endif if (!default_nareas) @@ -409,6 +413,12 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask, #ifdef CONFIG_SWIOTLB_DYNAMIC 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); + else if (IS_ENABLED(CONFIG_ZONE_DMA32) && (gfp_mask & __GFP_DMA32)) + io_tlb_default_mem.phys_limit = DMA_BIT_MASK(32); + else + io_tlb_default_mem.phys_limit = virt_to_phys(high_memory - 1); #endif if (!default_nareas) @@ -1390,7 +1400,11 @@ phys_addr_t default_swiotlb_base(void) */ phys_addr_t default_swiotlb_limit(void) { +#ifdef CONFIG_SWIOTLB_DYNAMIC + return io_tlb_default_mem.phys_limit; +#else return io_tlb_default_mem.defpool.end - 1; +#endif } #ifdef CONFIG_DEBUG_FS -- 2.25.1