Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1354001pxf; Fri, 12 Mar 2021 07:45:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwK9OQLtuhhviQCGlMTKWFejU4xZ3li3hOPoHTfjeuOL4nFjVpo0q5UjpiO0Mmi1CeZecJ8 X-Received: by 2002:a17:906:b884:: with SMTP id hb4mr9084007ejb.536.1615563933125; Fri, 12 Mar 2021 07:45:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615563933; cv=none; d=google.com; s=arc-20160816; b=Um0PBk4ddUx3qC1msWRz/MoZsF/kqCzuTGiPGJ+d27NysJrr7yCH3MrRd4y/JSsBaF 2CUwhh/+s5ZOhEt5HNkuBRpiytbXXqshnW/HSQ1F1l5/+3ZqXtUGbOvg1lvwtsduPuOK b9hvmd1VGBJjDlW/9fgGh90rsH6rX6grRtyGZJpbFDXLekyDGMBkGG52du7oFtU4Sk93 OZv9glyvKYEVxGPmnvLtrfPRh3KTovLN/y3jrz26J7ims9l2BpHOLBqUcpi5KnS6ymlR ++6kCUka/1uvpIq9LoH6asmrcmHvVXkLaZQ7/Jl8TFBwKsW1E0Zxve3O4aN06xgZpKhc NEYg== 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=QsanQIxQSHsn1vC65N0QJG8+iLH/LuKr/aTdgNdRnKA=; b=efNU6Whq5Xh8+fwnzBqnHqWDDAhxZMERVnw4jiW3lA0fvAdoDxoCpOEULA1b0Cp2gU 7BfTzVQccnq0WJr+Mt8cZTvrL9RBpvmuFKqIFT9K8C3QIrbUOayi2gAl9k7zrbzoRqgo xrhewcGitU50McQJoQXrN7JYsBmPx2In/IW7DA0STTYmcdnnkp2JvBILtlMKVOto+Q2i Epr7+crx+AectNyfA0aq1N6Zy/RTHoH/c+u0oCjIMn1mxOW6bT8bp53WO/A4yXB73rIQ qtQb8hX8GhE6dV2HSPpjhtUd1O+9XWyXNiPeL9F2qq1wCL/bTyHAgTm8oAWMnWxofKVU 18ew== 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 l16si2107541edb.221.2021.03.12.07.45.09; Fri, 12 Mar 2021 07:45:33 -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 S232296AbhCLPoF (ORCPT + 99 others); Fri, 12 Mar 2021 10:44:05 -0500 Received: from outbound-smtp14.blacknight.com ([46.22.139.231]:35185 "EHLO outbound-smtp14.blacknight.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232030AbhCLPnh (ORCPT ); Fri, 12 Mar 2021 10:43:37 -0500 Received: from mail.blacknight.com (pemlinmail06.blacknight.ie [81.17.255.152]) by outbound-smtp14.blacknight.com (Postfix) with ESMTPS id B7F631C3FFC for ; Fri, 12 Mar 2021 15:43:33 +0000 (GMT) Received: (qmail 19893 invoked from network); 12 Mar 2021 15:43:32 -0000 Received: from unknown (HELO stampy.112glenside.lan) (mgorman@techsingularity.net@[84.203.22.4]) by 81.17.254.9 with ESMTPA; 12 Mar 2021 15:43:32 -0000 From: Mel Gorman To: Andrew Morton Cc: Chuck Lever , Jesper Dangaard Brouer , Christoph Hellwig , Alexander Duyck , Matthew Wilcox , LKML , Linux-Net , Linux-MM , Linux-NFS , Mel Gorman Subject: [PATCH 6/7] net: page_pool: refactor dma_map into own function page_pool_dma_map Date: Fri, 12 Mar 2021 15:43:30 +0000 Message-Id: <20210312154331.32229-7-mgorman@techsingularity.net> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210312154331.32229-1-mgorman@techsingularity.net> References: <20210312154331.32229-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 Reviewed-by: Ilias Apalodimas --- 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..40e1b2beaa6c 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