From patchwork Tue Oct 29 23:05:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Wei X-Patchwork-Id: 13855622 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C386720C002 for ; Tue, 29 Oct 2024 23:06:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730243168; cv=none; b=MIlg03YSiIEc7zoAp3QUOAZ1Uz93j9mH1Mmy0L6Qoezn7YvjA5Fvp3FVx6310Urg6MCwvhClxjQqwpnRlfMGVqwb/H1gim4VoZLqpvllBajn9p4ceK/kJFG93lFb2f8n54nymxtWa5SsL+vwTSJpj7D5EPKeWnBRf8ND3zAtygs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730243168; c=relaxed/simple; bh=89Bp0oZ2BOmf5uCIKFKyoWYm/7ULInna3cvf7XCxcog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=crsYjPYeAmm7VvSuY1cYYsfUB+FuT0oJLZF7H0ZM/5xShRtTS2Cy2mAxX6v0KoCeVQkVyAhTaD/oAv4QYfraQA1fRF5fcGI/rVnm9jmoRSC7m7c9lvMn0akG/ChsBgLasuhTfRVuKUO6oe+ooLW+55WhutT2+OtsQ4kqOePBgcM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk; spf=none smtp.mailfrom=davidwei.uk; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b=zxg9JZv+; arc=none smtp.client-ip=209.85.214.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=davidwei.uk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=davidwei-uk.20230601.gappssmtp.com header.i=@davidwei-uk.20230601.gappssmtp.com header.b="zxg9JZv+" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-20c6f492d2dso67878905ad.0 for ; Tue, 29 Oct 2024 16:06:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=davidwei-uk.20230601.gappssmtp.com; s=20230601; t=1730243166; x=1730847966; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZQ+z4LZe+3hLij7urnws1Z9lmMZkjsHwRtyYTTLmPFQ=; b=zxg9JZv+6dZ+5cXq5Kn+6F5+zpR4uW15J5bIZPBT2LYKuMUQ/JHc1DszI5LDSaoKxz G41QqmFluirgfENzZL2qtmID4zidiX1tt5uRbg++cDw6u4ub0r3VCrxyXPvduTEwU97A UVqJA5sXtQyFuVfDVU+Ty4NFzUeZSP0DKGT8zEPQsUJujC9jIpoRPhz3+lGJS2kQ8Nmv 1CTU+W7DCPmxiyXb45a7WPAoO6YQGquFGhTHv1F2javZVwej6owzhv4ubfrkIJwempX9 xOOoWsZnFcG/h488NTcpBrUOYADI7QNLrHpYDr354QsWvM5EJScz8DgBJT9Y9Xv6IswL HOYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730243166; x=1730847966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZQ+z4LZe+3hLij7urnws1Z9lmMZkjsHwRtyYTTLmPFQ=; b=H9iV0Qm5r1mO4kiRcNMO+uCZ3CwgY5AGekHeqV3lUNE1yHpfYluo/44eyx77kIZU3E iY5Td/cnWsMrClPfkJVws+1OKC2IhFveC/ePkkeYhufQlyhRoLlc0h8e2EFuA+Xp1g0H Ux9TP1PwZSXgRPAVrajDCcQ7upxK+6gotUBifnYWuz/tnAJkARXIATO8BpqwPG3ntAmj oUZQzoDOFvz7XWklo07+7nNgz748Nulaj1iJ2NB+3iy4a1lTm7+FqS07VwLJBldvi3Pn ZHSAcGTG9CyTPAc2bbgGsBFd/IAqTWVDNVp1/J8OdX93OMEmQFXieF6fyHtn4b6xhHvi O8pA== X-Forwarded-Encrypted: i=1; AJvYcCWKW/Gw15IGLZNciQL2BW28JXfLLnP1Gb+pOxwKJf2Pj2eXr1PXXhJCtFs3zpEgfurH3TKmk1o=@vger.kernel.org X-Gm-Message-State: AOJu0Yzl7KA2/RNq55bfKBDAy/iJcWJA0PKV36NaWXxtPKLX33n6M2wq llD3k4kCbsfMm/XgS4Q9JMsEP0BxCKxmEaHukYvDAbBxUaaKhkvGQGbNbQURWc8= X-Google-Smtp-Source: AGHT+IHjuANZAW3TvhtdD6oXCsd9MFh33Q9JELmAs4hrgwPZUyadFVAGtfNtElEXcxMaxIFjJEuTCw== X-Received: by 2002:a17:903:2284:b0:20c:8907:902 with SMTP id d9443c01a7336-210c6c92159mr141610155ad.49.1730243166167; Tue, 29 Oct 2024 16:06:06 -0700 (PDT) Received: from localhost (fwdproxy-prn-019.fbsv.net. [2a03:2880:ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-210f0bee05asm14002455ad.250.2024.10.29.16.06.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:06:05 -0700 (PDT) From: David Wei To: io-uring@vger.kernel.org, netdev@vger.kernel.org Cc: Jens Axboe , Pavel Begunkov , Jakub Kicinski , Paolo Abeni , "David S. Miller" , Eric Dumazet , Jesper Dangaard Brouer , David Ahern , Mina Almasry , Stanislav Fomichev , Joe Damato , Pedro Tammela Subject: [PATCH v7 06/15] net: page pool: add helper creating area from pages Date: Tue, 29 Oct 2024 16:05:09 -0700 Message-ID: <20241029230521.2385749-7-dw@davidwei.uk> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241029230521.2385749-1-dw@davidwei.uk> References: <20241029230521.2385749-1-dw@davidwei.uk> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pavel Begunkov Add a helper that takes an array of pages and initialises passed in memory provider's area with them, where each net_iov takes one page. It's also responsible for setting up dma mappings. We keep it in page_pool.c not to leak netmem details to outside providers like io_uring, which don't have access to netmem_priv.h and other private helpers. Signed-off-by: Pavel Begunkov Signed-off-by: David Wei --- include/net/page_pool/memory_provider.h | 10 ++++ net/core/page_pool.c | 63 ++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 include/net/page_pool/memory_provider.h diff --git a/include/net/page_pool/memory_provider.h b/include/net/page_pool/memory_provider.h new file mode 100644 index 000000000000..83d7eec0058d --- /dev/null +++ b/include/net/page_pool/memory_provider.h @@ -0,0 +1,10 @@ +#ifndef _NET_PAGE_POOL_MEMORY_PROVIDER_H +#define _NET_PAGE_POOL_MEMORY_PROVIDER_H + +int page_pool_mp_init_paged_area(struct page_pool *pool, + struct net_iov_area *area, + struct page **pages); +void page_pool_mp_release_area(struct page_pool *pool, + struct net_iov_area *area); + +#endif diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 9a675e16e6a4..8bd4a3c80726 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -459,7 +460,8 @@ page_pool_dma_sync_for_device(const struct page_pool *pool, __page_pool_dma_sync_for_device(pool, netmem, dma_sync_size); } -static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem) +static bool page_pool_dma_map_page(struct page_pool *pool, netmem_ref netmem, + struct page *page) { dma_addr_t dma; @@ -468,7 +470,7 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem) * 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, netmem_to_page(netmem), 0, + dma = dma_map_page_attrs(pool->p.dev, page, 0, (PAGE_SIZE << pool->p.order), pool->p.dma_dir, DMA_ATTR_SKIP_CPU_SYNC | DMA_ATTR_WEAK_ORDERING); @@ -490,6 +492,11 @@ static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem) return false; } +static bool page_pool_dma_map(struct page_pool *pool, netmem_ref netmem) +{ + return page_pool_dma_map_page(pool, netmem, netmem_to_page(netmem)); +} + static struct page *__page_pool_alloc_page_order(struct page_pool *pool, gfp_t gfp) { @@ -1154,3 +1161,55 @@ void page_pool_update_nid(struct page_pool *pool, int new_nid) } } EXPORT_SYMBOL(page_pool_update_nid); + +static void page_pool_release_page_dma(struct page_pool *pool, + netmem_ref netmem) +{ + __page_pool_release_page_dma(pool, netmem); +} + +int page_pool_mp_init_paged_area(struct page_pool *pool, + struct net_iov_area *area, + struct page **pages) +{ + struct net_iov *niov; + netmem_ref netmem; + int i, ret = 0; + + if (!pool->dma_map) + return -EOPNOTSUPP; + + for (i = 0; i < area->num_niovs; i++) { + niov = &area->niovs[i]; + netmem = net_iov_to_netmem(niov); + + page_pool_set_pp_info(pool, netmem); + if (!page_pool_dma_map_page(pool, netmem, pages[i])) { + ret = -EINVAL; + goto err_unmap_dma; + } + } + return 0; + +err_unmap_dma: + while (i--) { + netmem = net_iov_to_netmem(&area->niovs[i]); + page_pool_release_page_dma(pool, netmem); + } + return ret; +} + +void page_pool_mp_release_area(struct page_pool *pool, + struct net_iov_area *area) +{ + int i; + + if (!pool->dma_map) + return; + + for (i = 0; i < area->num_niovs; i++) { + struct net_iov *niov = &area->niovs[i]; + + page_pool_release_page_dma(pool, net_iov_to_netmem(niov)); + } +}