Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3368643pxb; Mon, 1 Mar 2021 08:19:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwn0QZptOrpEwe8IXgVMTh1sc7E74kV0fcFmAjsPSbW0nqG97AcPViOgrkdL8VobzLlY5bg X-Received: by 2002:a17:906:58c9:: with SMTP id e9mr5208600ejs.26.1614615547256; Mon, 01 Mar 2021 08:19:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614615547; cv=none; d=google.com; s=arc-20160816; b=ImbD06DbFdrqfiWTIw4XsOKlWrklZ+Pb3/2PBnMgTaPcmFLd/PKDJIz3q/lJ4pZLgh GzRWGJHI/PK0xrKBv93Wg8CWkb411vnisu8+RztP2KEZ9ZYw2Pq6wLD30akodxoJDmFl OmH72EDVNOG9Y4gBsG5HFsuoTNSsKJZwGrWlFsXsf5dFwPDuWvAOZYbqgx8o+W3Mws53 siK0W+zxKltKtTyAi4tsUHEDzq/Kvquj0AAb1ur25Oqag+Mjqw7QsZGZ0+IfGBL8IsGC j3PCseCzE6z3feB7SsN7vhafWfUjXYrelM6yP/4uViZlGiSHummMF5Qe2Keo/E2gs/vI GrRQ== 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=hDNTnhLLNxnXakrEcImCjvfwFJeVGpyXRStYzdEcUM0=; b=iZRTUW1umXNHpLohP8Ok+CEKk5v3+JE9YvrxQVH4azYIgLgSkVbwntwXUkieCnPF41 QWGcaSdzKGdhxJHj2P2dLJx/powbIoSNddU/MPuK5yFpqDxTqRUykmmYv7b280WsnW25 l7DHcApdxJuPcM0VnJo0yniuBIufKPJ+3gvd2wgIQ65B5wuY2Xuu6Ddzz/mIaG+hpUpw Re/9Kg00LtxALaYYP5eT4O+kHDoF31uzksarq8qlsy6S/jsqIErYqlXm4ZQW3pGCpWTq rzu0L/SGSykXKAXRoT5vWhCS4vcYflqbVRsfpY2+Y5E0EGMM+lVhtxXz+wW9Qh5QhEas Ma3w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e17si13414640edj.155.2021.03.01.08.18.43; Mon, 01 Mar 2021 08:19:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237670AbhCAQP3 (ORCPT + 99 others); Mon, 1 Mar 2021 11:15:29 -0500 Received: from outbound-smtp57.blacknight.com ([46.22.136.241]:43957 "EHLO outbound-smtp57.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237680AbhCAQNd (ORCPT ); Mon, 1 Mar 2021 11:13:33 -0500 Received: from mail.blacknight.com (pemlinmail02.blacknight.ie [81.17.254.11]) by outbound-smtp57.blacknight.com (Postfix) with ESMTPS id 05B05FA938 for ; Mon, 1 Mar 2021 16:12:02 +0000 (GMT) Received: (qmail 30545 invoked from network); 1 Mar 2021 16:12:01 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPA; 1 Mar 2021 16:12:01 -0000 From: Mel Gorman To: Andrew Morton Cc: Chuck Lever , Jesper Dangaard Brouer , LKML , Linux-Net , Linux-MM , Linux-NFS , Mel Gorman Subject: [PATCH 4/5] net: page_pool: refactor dma_map into own function page_pool_dma_map Date: Mon, 1 Mar 2021 16:11:59 +0000 Message-Id: <20210301161200.18852-5-mgorman@techsingularity.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210301161200.18852-1-mgorman@techsingularity.net> References: <20210301161200.18852-1-mgorman@techsingularity.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org From: Jesper Dangaard Brouer In preparation for next patch, move the dma mapping into its own function, as this will make it easier to follow the changes. V2: make page_pool_dma_map return boolean (Ilias) Signed-off-by: Jesper Dangaard Brouer Signed-off-by: Mel Gorman --- net/core/page_pool.c | 45 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/net/core/page_pool.c b/net/core/page_pool.c index ad8b0707af04..a26f2ceb6a87 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -180,14 +180,37 @@ static void page_pool_dma_sync_for_device(struct page_pool *pool, pool->p.dma_dir); } +static bool page_pool_dma_map(struct page_pool *pool, struct page *page) +{ + dma_addr_t dma; + + /* Setup DMA mapping: use 'struct page' area for storing DMA-addr + * since dma_addr_t can be either 32 or 64 bits and does not always fit + * into page private data (i.e 32bit cpu with 64bit DMA caps) + * This mapping is kept for lifetime of page, until leaving pool. + */ + dma = dma_map_page_attrs(pool->p.dev, page, 0, + (PAGE_SIZE << pool->p.order), + pool->p.dma_dir, DMA_ATTR_SKIP_CPU_SYNC); + if (dma_mapping_error(pool->p.dev, dma)) + return false; + + page->dma_addr = dma; + + if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) + page_pool_dma_sync_for_device(pool, page, pool->p.max_len); + + return true; +} + /* slow path */ noinline static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, gfp_t _gfp) { + unsigned int pp_flags = pool->p.flags; struct page *page; gfp_t gfp = _gfp; - dma_addr_t dma; /* We could always set __GFP_COMP, and avoid this branch, as * prep_new_page() can handle order-0 with __GFP_COMP. @@ -211,30 +234,14 @@ static struct page *__page_pool_alloc_pages_slow(struct page_pool *pool, if (!page) return NULL; - if (!(pool->p.flags & PP_FLAG_DMA_MAP)) - goto skip_dma_map; - - /* Setup DMA mapping: use 'struct page' area for storing DMA-addr - * since dma_addr_t can be either 32 or 64 bits and does not always fit - * into page private data (i.e 32bit cpu with 64bit DMA caps) - * This mapping is kept for lifetime of page, until leaving pool. - */ - dma = dma_map_page_attrs(pool->p.dev, page, 0, - (PAGE_SIZE << pool->p.order), - pool->p.dma_dir, DMA_ATTR_SKIP_CPU_SYNC); - if (dma_mapping_error(pool->p.dev, dma)) { + if (pp_flags & PP_FLAG_DMA_MAP && + unlikely(!page_pool_dma_map(pool, page))) { put_page(page); return NULL; } - page->dma_addr = dma; - if (pool->p.flags & PP_FLAG_DMA_SYNC_DEV) - page_pool_dma_sync_for_device(pool, page, pool->p.max_len); - -skip_dma_map: /* Track how many pages are held 'in-flight' */ pool->pages_state_hold_cnt++; - trace_page_pool_state_hold(pool, page, pool->pages_state_hold_cnt); /* When page just alloc'ed is should/must have refcnt 1. */ -- 2.26.2