From patchwork Mon Feb 20 15:13:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 59545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1379877wrn; Mon, 20 Feb 2023 07:56:20 -0800 (PST) X-Google-Smtp-Source: AK7set+y3j4GBhL4yYzh0oYmteC3bqCOllioVp2U8DQ48ZL5lA9cUPjvjqWOWR+exr749L0fSwI3 X-Received: by 2002:a17:907:7f0d:b0:87b:d2b3:67ca with SMTP id qf13-20020a1709077f0d00b0087bd2b367camr11256189ejc.75.1676908580016; Mon, 20 Feb 2023 07:56:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676908580; cv=none; d=google.com; s=arc-20160816; b=jCEeSi5npD+MrNY5UpobLFPvUQ0F3jxLSjCJE6QPbxl282pknAHNafX6WfAKPD0jbS XlIUaUmkQ3RIK7x+67z6gMCAYzlr3d6Wtt/kBJGQn6GHz20KzYSjrPEavCcz0Dxr6izr MBszWhaLT49ZSr/3G+fkQOwt+RphOti73qfLcDxpsVdXHd/vje25gkjaMQredfRM+Zrt Tnkz669bqMFqvf7TedE7WQSNVR0UWFZB79OQRKVCEl2AqZJ9JrTXo6/jJoCpXiKJ9hXD nsh9gLFiPOm4/J04IjjpalRejLJ0Z22+2Ok1j90EzvTPnG3ovigg2j6eY9hYW7MJNwm8 I2Jg== 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=OQl8GFU4zcP0T3P1ORJ/qO2QwHwd8t4di5M+LYbwa3c=; b=XBsz3OZj3haVNSJLuhlWk2JLxKU0BUfxaMSnXK0fWUy+0WRIExQANBDjowCg8AXrsx PUr8HqIsE4D4efFUgF0XXGlUT46PAOqbuze1Wt8Y8F5hEs5+f6kTKVnMmoL3xNhd+2nV KzSFH0UwLukK5uJbS07ua8nyit1GDnsaBLEyzuQidllHpejzjY1SXnZgzhkh1RnLPA2W pudy1Mghvz3EQloYAyarw20WgyfdWI2jmPSqkPQFwp4WwlkJs9q0XroWOOchZ4BBktrD DnLNMZTMzzO1DnfqYzMdBLBe7B3cPPEDc3QZxXxm91TEN8Z0RPdA2gRgDnD0u6lbDc/g /n1w== 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 c11-20020a17090620cb00b008b12654bac7si19318844ejc.410.2023.02.20.07.55.56; Mon, 20 Feb 2023 07:56:20 -0800 (PST) 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 S231969AbjBTPcR (ORCPT + 99 others); Mon, 20 Feb 2023 10:32:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229690AbjBTPcP (ORCPT ); Mon, 20 Feb 2023 10:32:15 -0500 Received: from frasgout13.his.huawei.com (frasgout13.his.huawei.com [14.137.139.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0687166DA for ; Mon, 20 Feb 2023 07:32:13 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.228]) by frasgout13.his.huawei.com (SkyGuard) with ESMTP id 4PL5Mc0Ztqz9xyNj for ; Mon, 20 Feb 2023 23:05:48 +0800 (CST) Received: from huaweicloud.com (unknown [10.81.223.230]) by APP2 (Coremail) with SMTP id GxC2BwD37mU1jvNjxxw4AQ--.54334S2; Mon, 20 Feb 2023 16:14:03 +0100 (CET) From: Petr Tesarik To: Christoph Hellwig , Marek Szyprowski , Robin Murphy , iommu@lists.linux.dev (open list:DMA MAPPING HELPERS), linux-kernel@vger.kernel.org (open list) Cc: roberto.sassu@huaweicloud.com, Petr Tesarik , Petr Tesarik Subject: [PATCH] dma-direct: cleanup parameters to dma_direct_optimal_gfp_mask Date: Mon, 20 Feb 2023 16:13:47 +0100 Message-Id: <20230220151347.590-1-petrtesarik@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: GxC2BwD37mU1jvNjxxw4AQ--.54334S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Zr48CFyDtr4rAr4kCw48Zwb_yoW8KF1kpr 4xGFy3GrWFvF1fZa9rZa1kCryYyr9Yka1fJa4xtwn3ArZ8Wr9aqF9rKw15tw1fJF9Ygr1f XF4kJa45Ars8AaUanT9S1TB71UUUUUDqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9F14x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUuVWrJwAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j 6F4UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJV WxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAaw2AFwI0_ Jw0_GFylc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4 AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE 17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMI IF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v20xvaj40_Wr1j6rW3 Jr1lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcS sGvfC2KfnxnUUI43ZEXa7VUjHmh7UUUUU== X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE autolearn=ham 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758365566606672383?= X-GMAIL-MSGID: =?utf-8?q?1758366091022352870?= Since both callers of dma_direct_optimal_gfp_mask() pass dev->coherent_dma_mask as the second argument, it is better to remove that parameter altogether. Not only is reducing number of parameters good for readability, but the new function signature is also more logical: The optimal flags depend only on data contained in struct device. While touching this code, let's also rename phys_mask to phys_limit in dma_direct_alloc_from_pool(), because it is indeed a limit. Signed-off-by: Petr Tesarik --- kernel/dma/direct.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 63859a101ed8..5595d1d5cdcc 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -44,10 +44,11 @@ u64 dma_direct_get_required_mask(struct device *dev) return (1ULL << (fls64(max_dma) - 1)) * 2 - 1; } -static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 dma_mask, - u64 *phys_limit) +static gfp_t dma_direct_optimal_gfp_mask(struct device *dev, u64 *phys_limit) { - u64 dma_limit = min_not_zero(dma_mask, dev->bus_dma_limit); + u64 dma_limit = min_not_zero( + dev->coherent_dma_mask, + dev->bus_dma_limit); /* * Optimistically try the zone that the physical address mask falls @@ -126,8 +127,7 @@ static struct page *__dma_direct_alloc_pages(struct device *dev, size_t size, if (is_swiotlb_for_alloc(dev)) return dma_direct_alloc_swiotlb(dev, size); - gfp |= dma_direct_optimal_gfp_mask(dev, dev->coherent_dma_mask, - &phys_limit); + gfp |= dma_direct_optimal_gfp_mask(dev, &phys_limit); page = dma_alloc_contiguous(dev, size, gfp); if (page) { if (!dma_coherent_ok(dev, page_to_phys(page), size) || @@ -172,14 +172,13 @@ static void *dma_direct_alloc_from_pool(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t gfp) { struct page *page; - u64 phys_mask; + u64 phys_limit; void *ret; if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_DMA_COHERENT_POOL))) return NULL; - gfp |= dma_direct_optimal_gfp_mask(dev, dev->coherent_dma_mask, - &phys_mask); + gfp |= dma_direct_optimal_gfp_mask(dev, &phys_limit); page = dma_alloc_from_pool(dev, size, &ret, gfp, dma_coherent_ok); if (!page) return NULL;