From patchwork Mon Feb 20 15:06:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Tesarik X-Patchwork-Id: 59542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1376452wrn; Mon, 20 Feb 2023 07:48:00 -0800 (PST) X-Google-Smtp-Source: AK7set/z21k71/7TIEQ7Clh3/7eM+60+6yNs7CB3lcl2jKnGloTwlWtMYez3DvBQvCdYrd4RlJL1 X-Received: by 2002:a17:906:2611:b0:87b:d62c:d87 with SMTP id h17-20020a170906261100b0087bd62c0d87mr8911146ejc.1.1676908080135; Mon, 20 Feb 2023 07:48:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676908080; cv=none; d=google.com; s=arc-20160816; b=0qADud/YUxJl/0iRMX1xKQ9yecyhbB0D/LQ7FuAqPCH1coZ8CO+8eyVQ9/u52B85DQ 2vZv8IDnO30ZZgRU+Rc7XGUpks+YH5z0766moy7TjCDr7BIdqNGmlKvJV18FAJHc/6Hz 0Ys2zSV/YLmR/r3yQBzQ9KQ/l/E+U+ezyFzQAPzjEqzhlSuWr2GCGBGfmP0h4ASt+UZT XYHut3OxAP3uBaaKpCCUWIKYJn6iBi1HTqVDeTexRs9eB1or6yJqZ0q7SlZY+8HquKBB ExqANuB5ZIDbFrIgfqSBkJO8eBaqT6efSvKRqkU9DWpuORV/iqx7893BCI7yotzgLvWe g18Q== 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=BpL41GsTf0jnJKB3DYFQ0qvb2UJTTZZItaxEOtHSljg=; b=vK54galuNl5eraniMNgIAyl7EmztNpKLTCHpnSSTjBzKvZ0A/Tf0wlzLKy5iU49USl 4K0yJrnAKBiLTFa4GEAC0Dtvwk1u8iqL0xgCbh1QNobExYjl7DWQeK3Gw4DZRe3iK6UE BKYQZtCzry3leART4nvlWF8xg9uLJ/+1ozLatFEA7O0VMHJP1f2Fn3CuttMrSU1aC7Lk mXDEXBOEPExa35G0XA1ze+plaJOF6kBAInN0bYsKRi1MbvpfH9dJoOmdq8Yg1dEWP+Gn aQz8QLZ1dPQlbOS7eEyMlbTp19Px8TqNlm6TnnORtltK26jvcg8KOjElghDC4irJriH3 gACg== 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 up29-20020a170907cc9d00b008b17ac5c728si13506225ejc.434.2023.02.20.07.47.32; Mon, 20 Feb 2023 07:48:00 -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 S231902AbjBTP1r (ORCPT + 99 others); Mon, 20 Feb 2023 10:27:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231191AbjBTP1p (ORCPT ); Mon, 20 Feb 2023 10:27:45 -0500 X-Greylist: delayed 720 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 20 Feb 2023 07:27:21 PST Received: from frasgout12.his.huawei.com (frasgout12.his.huawei.com [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDC93C3B for ; Mon, 20 Feb 2023 07:27:21 -0800 (PST) Received: from mail02.huawei.com (unknown [172.18.147.227]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4PL5Bn1W4vz9xGY9 for ; Mon, 20 Feb 2023 22:58:09 +0800 (CST) Received: from huaweicloud.com (unknown [10.81.223.230]) by APP1 (Coremail) with SMTP id LxC2BwCXHwuAjPNjH5A6AQ--.54716S2; Mon, 20 Feb 2023 16:06:47 +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 Subject: [PATCH] dma-direct: cleanup parameters to dma_direct_optimal_gfp_mask Date: Mon, 20 Feb 2023 16:06:22 +0100 Message-Id: <20230220150622.454-1-petrtesarik@huaweicloud.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CM-TRANSID: LxC2BwCXHwuAjPNjH5A6AQ--.54716S2 X-Coremail-Antispam: 1UD129KBjvJXoW7Zr48CFyDtr4rAr4kCw48Zwb_yoW8KF1kpr 4xGFy3GrWFvF1fZa9rZa1kCryYy3sYka1fJFyxtwn3ArZ8Wr9aqF9rKw15tw1fJF9Y9r1f XFs5Ja45Ars8ZaUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUv014x267AKxVW8JVW5JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWUuVWrJwAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26r1j6r1xM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r1j 6r4UM28EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJV WxJr1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E 2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJV W8JwACjcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lc7CjxVAKzI0EY4vE 52x082I5MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrV AFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCI c40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267 AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Wr1j6rW3Jr1lIxAIcVC2z280aVAFwI0_ Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUj dHUDUUUUU== 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?1758365566606672383?= 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;