From patchwork Thu Jul 13 15:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 119988 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1911161vqm; Thu, 13 Jul 2023 08:43:06 -0700 (PDT) X-Google-Smtp-Source: APBJJlF9Lbp/nJS+vTTSCVjqdZZ6TUeVVi04wthEbbC37ROm+v0TauY1vwvzsIR2zlbOhV/MMlyy X-Received: by 2002:a2e:83c9:0:b0:2b6:dbc5:5ca4 with SMTP id s9-20020a2e83c9000000b002b6dbc55ca4mr1703027ljh.16.1689262985897; Thu, 13 Jul 2023 08:43:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689262985; cv=none; d=google.com; s=arc-20160816; b=r4RE6ZlnxIs1N1ySbyp+I19c7QjjTuYfrfLVNAgu7kurBbASyPHPqXyMe/jQH4uSOM RPTmJLqK3ZjVtqXHTnZsJnDW3kzJYsRgHX2MeyEViG2bg16WJMUJgWUk6lHsUX06bzH1 Mu9Izts4VTp8vZ2El8R4xoJSnKitY2W+b79Xo/YRvO34EyPmIQUPRCeWoEAonNLySblR 9QynRKNXYZfjTFghKPeG+/+jseAL6PgdXQczqpv+bxQK7CJiAfm56Sa9TOih3Vm8sLLK AiqfbzqkfaFVWMJ+rIFHBB9N2Xax6o2rGPiKlg0pytBZMR9EroEGP7BVuQryyWCBlaGY JmTg== 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=XLaZuWL4ioP2bb3eegltgIxrjMj8i1YX9y5mzQfpEcc=; fh=uKf5PwTVKZKxSaZteLEQnx7Wj7sy6DZnn4JrVRVZWTg=; b=t4FMrbbLraNdngBwMQiYD1/A1g/fnaNCZPg238jmkpkg5ZmOXkAy9pm95wxQhKIUea +a+48EV6aFVy6Jfu6Kv+lq7Mg4mRDPziTWQq7axT6oU4Nu5YRiOJ7mUoI+yYvtbBX36p lSWkQ8pkxZhHOPaLeDcD6pHON/72NDVY/ee/sNhLUKAKNulA6pPqnkBXgslOfEp4Y/bm tZt+/YgH2eT275sq+QCQtPln2AUSW4IjNL0l3zlaSXlbc7SpRg0UK35S6ttUnqvoyILQ eERxSECjkPFC+FptoQwHsoUVAQGD0fmGQZkiicNFJ/gXTmlfFbjwtOzlkA3J62JDT0ml zPbA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g25-20020a1709064e5900b00988939ad0bdsi7706287ejw.321.2023.07.13.08.42.40; Thu, 13 Jul 2023 08:43:05 -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 S234699AbjGMP0h (ORCPT + 99 others); Thu, 13 Jul 2023 11:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231705AbjGMP0a (ORCPT ); Thu, 13 Jul 2023 11:26:30 -0400 Received: from frasgout13.his.huawei.com (unknown [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60AB22D49; Thu, 13 Jul 2023 08:26:13 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4R1ypK5Xjpz9xGnG; Thu, 13 Jul 2023 23:15:05 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.218.161]) by APP1 (Coremail) with SMTP id LxC2BwA3k94BF7BkxG6BBA--.7207S8; Thu, 13 Jul 2023 16:25:29 +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 , Petr Tesarik , Jonathan Corbet , Andy Shevchenko , Hans de Goede , 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 , Kefeng Wang , petr@tesarici.cz Subject: [PATCH v4 6/8] swiotlb: determine potential physical address limit Date: Thu, 13 Jul 2023 17:23:17 +0200 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CM-TRANSID: LxC2BwA3k94BF7BkxG6BBA--.7207S8 X-Coremail-Antispam: 1UD129KBjvJXoWxXw4fJr4fZFy7GF1UZrWDurg_yoW5Cry3pF y8A3WrKFsFqFnrCryxC3W7AFnaga18Cr47urW3ur15Zry3Ww1fKwsrKr45tr1FqF409F4I vFyFvayYvFsIvw7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQl14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rV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Y_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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771320624624449654 X-GMAIL-MSGID: 1771320624624449654 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 | 12 +++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h index b642e7739604..ff8f5150f4de 100644 --- a/include/linux/swiotlb.h +++ b/include/linux/swiotlb.h @@ -105,6 +105,7 @@ struct io_tlb_pool { * struct io_tlb_mem - Software IO TLB allocator * @pool: IO TLB memory pool descriptor. * @nslabs: Total number of IO TLB slabs in all pools. + * @phys_limit: Maximum allowed physical address. * @debugfs: The dentry to debugfs. * @force_bounce: %true if swiotlb bouncing is forced * @for_alloc: %true if the pool is used for memory allocation @@ -118,6 +119,7 @@ struct io_tlb_pool { struct io_tlb_mem { struct io_tlb_pool *pool; unsigned long nslabs; + u64 phys_limit; struct dentry *debugfs; bool force_bounce; bool for_alloc; diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c index 6ec5a81acc2a..d6a05727efc5 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, io_tlb_default_mem.force_bounce = swiotlb_force_bounce || (flags & SWIOTLB_FORCE); io_tlb_default_mem.can_grow = !remap; + 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; if (!default_nareas) swiotlb_adjust_nareas(num_possible_cpus()); @@ -402,6 +406,12 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask, io_tlb_default_mem.force_bounce = swiotlb_force_bounce; io_tlb_default_mem.can_grow = !remap; + 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); if (!default_nareas) swiotlb_adjust_nareas(num_possible_cpus()); @@ -1338,7 +1348,7 @@ phys_addr_t default_swiotlb_start(void) */ phys_addr_t default_swiotlb_limit(void) { - return io_tlb_default_pool.end - 1; + return io_tlb_default_mem.phys_limit; } #ifdef CONFIG_DEBUG_FS