From patchwork Tue Oct 29 20:45:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 839459 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 48C172076D7 for ; Tue, 29 Oct 2024 20:45:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234748; cv=none; b=pP+4tfWJe9V+OFArjXbBwRcuLWQKQ7j5CnlGLPM+JT/5EZuluB7YVnjJtaMWeMXd3RcNIHV254AqEzA8R/iNNmiidYVKE0l5m10J8hcDI3bHvesnwZ9BEjBf1LzWdGtBrgvrCFnFcHJqx4u5ovT1Cu2kMh6ndA1V6y9lcKrnjMQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234748; c=relaxed/simple; bh=ANVvHO/Zb6fJtzVUz2e7HjfsostgYB8KbWIfjKVTCSo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=OsgXDQTh5zxhRDubjodVxy1yCudY3f1LmA61xNfMvdHZFTw4fVp/jEzQ5V8hTPw/+agSGko9PP50DxpfodsptDFWW3iarbLsrV5acNCaV0P8KYWMRkocqlK2h0J5kQrekHm1FoquHoexM6VD2lp/ijsh1xW87fGo9hW5i1MFDVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=L3Gvwbv8; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="L3Gvwbv8" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e36cfed818so95893167b3.3 for ; Tue, 29 Oct 2024 13:45:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234745; x=1730839545; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IKVtq75fITyzSDoz03OSyDAa5pp0EHjXr3igFrBPeF4=; b=L3Gvwbv8sSTOIpogPw3LWLYmnHht8jwdmNw/qSjtDDksVdpGU/tGmwZxqFZ74WKK0H 12L7A9eGG53PMYiM2lFmIEEns5WeYUMQB6wIDVmnQar3aqS+C0S8Dm0EdjTkG6M9SDvi utGfDQlQFGZene1H5+Q5J+R2myh+2j3J8abM7qnHMgNB9/LTdj5VEz5mwJJRNKBmvjTr ylDK2r4w/3DsPW6lrfyATTIrbTdoO6zHYdnoxSWBxs13uW/g87Ny5+8ZsgaopN6X9fGQ BqLf86gNmUNV3ciPp4IHpjnHxSO5XFqxcBq1rkz6t+sPQ3qAubSy7Jg7vgluvLqSO2+2 oTGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234745; x=1730839545; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IKVtq75fITyzSDoz03OSyDAa5pp0EHjXr3igFrBPeF4=; b=hW3PGm80lGbVferBbmRCC5bYhdq6XALyy7c+O+dt5Aqo9V/cyL+j1ak8uvjIQJcdFM J9eBwBk1Kl3H2c/Wxh7hCm0EB/ZHA+lhy/m4gm/vugDlZeBE0DRjt91fXs9KNduK94U9 pqCOVfK967MCkqB7WIu2v52Yjk2IGMLuoAHXKY0EiAxuIPNVcTCTXcboWeoukE4QPAKg +RoCKAmK1K1Y/O9lSVZ09IjrI2IBqruQ/oxZ4C9JlIvPSM4MOpi2v4fsemAM97XSPlbR RokDWfNtgb0QSP5+FZzhgZIFspR7TDRPaSnwYmz28Q8W3Xi03f1zwvq7ZSG+wGbv2lkl WJVQ== X-Forwarded-Encrypted: i=1; AJvYcCUIr4kAQW7fil3V3KfcjDnhRD/2FVqat+Kg3ZlvZ9PwXEVpjVtXNue5nQhws1mNKIi+VpHwvaqqxsolhvh4qY0=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6K35mld5nBxydQjAMktzMcRFEnA73bplTQYAxB7Xr2oLLG4e8 14mvbFsArfNG5xj7uZ3bEy6siytC2Xf44AbCvPliS+eJP5FC4n5iSmN/je56sqJhbtMRl1acevw RCV6YHOumgax8I8DaX+SItA== X-Google-Smtp-Source: AGHT+IHZYCaL3wj1+u0hTpzTRQJ1G7IFk6vtNOjfqwf31bO7KQxkZpsTH7OU8mGhiD8LbP4+F/NssnNl88Gr6RiQGg== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:690c:c14:b0:6ea:34c0:966 with SMTP id 00721157ae682-6ea34c00d19mr990757b3.5.1730234745296; Tue, 29 Oct 2024 13:45:45 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:35 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-2-almasrymina@google.com> Subject: [PATCH net-next v1 1/7] net: page_pool: rename page_pool_alloc_netmem to *_netmems From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan page_pool_alloc_netmem (without an s) was the mirror of page_pool_alloc_pages (with an s), which was confusing. Rename to page_pool_alloc_netmems so it's the mirror of page_pool_alloc_pages. Signed-off-by: Mina Almasry --- include/net/page_pool/types.h | 2 +- net/core/page_pool.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/net/page_pool/types.h b/include/net/page_pool/types.h index c022c410abe3..8f564fe9eb9a 100644 --- a/include/net/page_pool/types.h +++ b/include/net/page_pool/types.h @@ -242,7 +242,7 @@ struct page_pool { }; struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp); -netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp); +netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp); struct page *page_pool_alloc_frag(struct page_pool *pool, unsigned int *offset, unsigned int size, gfp_t gfp); netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool, diff --git a/net/core/page_pool.c b/net/core/page_pool.c index a813d30d2135..77de79c1933b 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -574,7 +574,7 @@ static noinline netmem_ref __page_pool_alloc_pages_slow(struct page_pool *pool, /* For using page_pool replace: alloc_pages() API calls, but provide * synchronization guarantee for allocation side. */ -netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp) +netmem_ref page_pool_alloc_netmems(struct page_pool *pool, gfp_t gfp) { netmem_ref netmem; @@ -590,11 +590,11 @@ netmem_ref page_pool_alloc_netmem(struct page_pool *pool, gfp_t gfp) netmem = __page_pool_alloc_pages_slow(pool, gfp); return netmem; } -EXPORT_SYMBOL(page_pool_alloc_netmem); +EXPORT_SYMBOL(page_pool_alloc_netmems); struct page *page_pool_alloc_pages(struct page_pool *pool, gfp_t gfp) { - return netmem_to_page(page_pool_alloc_netmem(pool, gfp)); + return netmem_to_page(page_pool_alloc_netmems(pool, gfp)); } EXPORT_SYMBOL(page_pool_alloc_pages); ALLOW_ERROR_INJECTION(page_pool_alloc_pages, NULL); @@ -956,7 +956,7 @@ netmem_ref page_pool_alloc_frag_netmem(struct page_pool *pool, } if (!netmem) { - netmem = page_pool_alloc_netmem(pool, gfp); + netmem = page_pool_alloc_netmems(pool, gfp); if (unlikely(!netmem)) { pool->frag_page = 0; return 0; From patchwork Tue Oct 29 20:45:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 839458 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 05392208975 for ; Tue, 29 Oct 2024 20:45:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234751; cv=none; b=qgZ30gKinp/jdlCmN8pEHD6BAYbTpPiSghso6zMmy0ZNpFvuZvqDAWqaZHgJ6GjNQez/UBornWO4EZfTCgDVfzEzKai1QW8QDS1d3JJSflUGFIkkYxyDjU3ytPsiRo7b4MGPcpZOkisIQaR8NlPydW4VBK48iKGgaWMaE+qVc28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234751; c=relaxed/simple; bh=wj9CgD+x0GVWC/RysuEBDRx4mXq9fGHiB/kdVGdaca4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m5dxKvzZvuMhtAD+DcGcT4djiruUjPywFYerrMvrPmCSeRZBIFDoGwgcJUqBl6s8dPC8Tjip6WkZ5HnCL05kvmDxMh9QtdGd8s93m15bDzPtY/IIS2bPFHr7lL2eJEeqiJ0qu7BIeZdmMNNFg2TtCSR7D09YHm6ouZj0urgZU8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nPcxWyh4; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nPcxWyh4" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-6e370d76c15so114530337b3.2 for ; Tue, 29 Oct 2024 13:45:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234749; x=1730839549; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Ia0Z0AQiuotb1aQB7+r4THgYyxvP1pQZETcnEmFDqWc=; b=nPcxWyh4nHDSfNGljewbLP/Ur27KLsWEgOsJWAgGqK3EwwPcSUeOcF9Z6Z7v3vqShx uZEPgwTPherzGDH6Fx4fwowpnrbAM9/mrffJTAa4IrtUiJS4/4MXywBcMzLFNbyS5Qt7 +oIxoclN2QOnB9Arxel024zrWvT8LFsZkuVuFB80g4WRbP9pDlReKAvLAnNX5mjtJuO/ SvNfXga1w5eFkRoWw4F+fnxN+tnQeCriNBaQpDkbtMVRpeiYa8rUJf5l5Z9W3o09kUvT g2jClRPtnG+C4UXCqYD6Mmv7rzVWz3MZRZGCa4X5sftT/grATazTuDFP6iOa2Ox2KzjQ Zp3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234749; x=1730839549; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Ia0Z0AQiuotb1aQB7+r4THgYyxvP1pQZETcnEmFDqWc=; b=r/yhS8sQT+7SQH3Pm+sGeyjRjIPwL0yGPZCscbvDfzfIuSveODP4rP7kmdNRotEI4a /LmbEqUwRRhboRyhHAiulaxwGOmFxrOjcFOg9WqszPPkAw9EOTQcjqecb3zryA+5PGiA ZB4j6285GvEDNBbRnwi5+RYuCa91MjfM72DHNfU8JFp2fkqBP44P/X6VobLSXXSNVmDw hNVJOEdGM6C97GdVpaPRA/hKxcUu1NmTqHZ2c/5i1JPBzOiyXO0UP0qGGLz1UskPrxIZ XL6MMWEHwi8k4tsC15Ls/9fMFwjtNBtPXHbwjALqMINEknh0TOSAIc6NghDQ4mXuIBbR y+Lg== X-Forwarded-Encrypted: i=1; AJvYcCWmz7jxP7WDDGmHhHQlKxCFCrHrJphTxL0/MbNvSuKveeHHLNsHDIEnmHD2/vh7KD/QYbfImtlScRMU369I0c4=@vger.kernel.org X-Gm-Message-State: AOJu0YxTUBCJvObKqSfUDVaT0ZZ/S3WKquklOh++KD3s0ju+z/gJSVtD OeasA3U0i2z/nZO4YnlfevQHcA0VuExuE9em3r4g/upY1C3w+GJW5WKwvDvugho9YUBcOLBGsfw il5lKV1669u8jIWDRKzB9gA== X-Google-Smtp-Source: AGHT+IF6iUlUajnIuWSLwO8GHFuWPdZ7TzjtXW+wmOwLsLSi+oJyQ0Mqbj3G/hC6QRpn9nQ26QyYa9SQhh+OMtpcIA== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:f301:0:b0:e28:eaba:356a with SMTP id 3f1490d57ef6-e3087c10916mr55330276.9.1730234748927; Tue, 29 Oct 2024 13:45:48 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:37 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-4-almasrymina@google.com> Subject: [PATCH net-next v1 3/7] page_pool: Set `dma_sync` to false for devmem memory provider From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan , Samiullah Khawaja , Jason Gunthorpe From: Samiullah Khawaja Move the `dma_map` and `dma_sync` checks to `page_pool_init` to make them generic. Set dma_sync to false for devmem memory provider because the dma_sync APIs should not be used for dma_buf backed devmem memory provider. Cc: Jason Gunthorpe Signed-off-by: Samiullah Khawaja Signed-off-by: Mina Almasry --- net/core/devmem.c | 9 ++++----- net/core/page_pool.c | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/net/core/devmem.c b/net/core/devmem.c index 11b91c12ee11..826d0b00159f 100644 --- a/net/core/devmem.c +++ b/net/core/devmem.c @@ -331,11 +331,10 @@ int mp_dmabuf_devmem_init(struct page_pool *pool) if (!binding) return -EINVAL; - if (!pool->dma_map) - return -EOPNOTSUPP; - - if (pool->dma_sync) - return -EOPNOTSUPP; + /* dma-buf dma addresses should not be used with + * dma_sync_for_cpu/device. Force disable dma_sync. + */ + pool->dma_sync = false; if (pool->p.order != 0) return -E2BIG; diff --git a/net/core/page_pool.c b/net/core/page_pool.c index 77de79c1933b..528dd4d18eab 100644 --- a/net/core/page_pool.c +++ b/net/core/page_pool.c @@ -287,6 +287,9 @@ static int page_pool_init(struct page_pool *pool, } if (pool->mp_priv) { + if (!pool->dma_map || !pool->dma_sync) + return -EOPNOTSUPP; + err = mp_dmabuf_devmem_init(pool); if (err) { pr_warn("%s() mem-provider init failed %d\n", __func__, From patchwork Tue Oct 29 20:45:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 839457 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 EBEC2209F36 for ; Tue, 29 Oct 2024 20:45:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234755; cv=none; b=SEJ47d49WXjbdwmsVGRKHIkc8Ew4orWbpMMltSzypwcBRwCKYAMMSZenGzXugIRuw06dbCvIV5uoznVdMbFxqg/USSt2bN45+j73Z444cocOLGL27/k9LZx01rb6upSYJVhqLpmi0PsXOCGCHHCmXdv6QliG6QseKru0icUyy64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730234755; c=relaxed/simple; bh=oxvcO/ZaB/lL61u8pEJ51NobI8qaVVYlrPTrDOUpHPQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eGc0+QD4pldzVA+C+JCfKkPKTwEZGjzpWkBom1758R1K2wwuYAAN6nt2pWarlJ3NtxFvLJUgBTBq7VqtIRftzFU40eUxpdUW9n7NHjvn2kgxtzCadq3LmyIPy/44RMw4w4DgcvZvAdnWu5jtpT5lhNqkJ+V4EjPQ9zip3gr9b+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=pd8bUOpU; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pd8bUOpU" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6ea258fe4b6so31708987b3.1 for ; Tue, 29 Oct 2024 13:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730234753; x=1730839553; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=pKjGAeVoY4GHFtcwq5banhGcJjKwOgTAegNaQaox++w=; b=pd8bUOpUpARD3tcU0bwU12p3PxGCDqoDAszXIIqwYhYs7Bqc7QY1iLPZUnZw2yGNyo liUPo980BUweJNRqeACnmtcMMkhI6WvV9VP+qzzEKJt/gfBBmJ9AaXnXowunn2QLiyXO /d5HBm+pX0YsX7sobJsvzOB8/fl1NsB3RUMeBol5EpE8V+EGt1GhvZors7y/0L2qSAje T3XGtUKjuUwqN2rucag9C0dQDTqWV5tvLCQH8Qu3mrnLUjylW3xO/GWqT1WNtZU9dCQC czSVTbLpIVvC7GOlMHnTgn/y2AXD6Hj1CABV3sjpA/6dnJoa1R9aq+fUSZnR0DAiAEPW EwQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730234753; x=1730839553; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=pKjGAeVoY4GHFtcwq5banhGcJjKwOgTAegNaQaox++w=; b=g+OemH+ssn8hMXmWlwnJkb2sL/gP5++mLU8segE3J83gWPpp/l6Wud3ObtRwptwXPX Y/Dr/Gt+Gjo3HUa/dzaG4h/lPfdriCp9HM3dTiqHPvCEFe9jGDctYDq4mQ1WYiHpVHBh b2iut86DJGrKcpGOdC3YwdrPyOsg/xfiMctpG6QWCjXPkWwEmjkfC2ILiciGxS6j5Vl0 vnjWhLypV6UiwvP1g8vpNAkHV5uVPDShc3HO/fl7P0KhIuYudIyg23XpSpX/pcpD9F+/ XvYbicMsYp/HqzVdXDcC6NWGnGLohuH23yrsVvcC5YsB3nll5iMKCpRp6SdNV63w630w JjmA== X-Forwarded-Encrypted: i=1; AJvYcCUsUp9vebjP6XOVHEaf+whjmkLvtPSoCEmNZyFEywPJ/eJ6PeYw8je/lXuR7Iac1LVK3oBceo9ClT8ZgtIrirs=@vger.kernel.org X-Gm-Message-State: AOJu0Yw+Y+YttWzTIGpfej/TsBUopOLUcvglf/ICy7CjtCMVBph7vnKO R4vrVuU2wTcunaNosSmDacoY85/j5qYLZCcuKjVgrm7dJNi9J74aVk7SLcg5ozZbC3fTgzCOdC9 K9n0N4w4/7sKhLR9wl3Eyxg== X-Google-Smtp-Source: AGHT+IFriD3g24XyT1jM0DrGKfcuWZDYLvFnWpLS3cNOCFhL6xGL+ZOplvsxqtm8XLZC9n/DUx7QNPgLv1gz7vx1pw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:690c:2c85:b0:6e3:14c3:379a with SMTP id 00721157ae682-6e9d87a71camr2100287b3.0.1730234753049; Tue, 29 Oct 2024 13:45:53 -0700 (PDT) Date: Tue, 29 Oct 2024 20:45:39 +0000 In-Reply-To: <20241029204541.1301203-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029204541.1301203-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029204541.1301203-6-almasrymina@google.com> Subject: [PATCH net-next v1 5/7] netmem: add netmem_prefetch From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan prefect(page) is a common thing to be called from drivers. Add netmem_prefetch that can be called on generic netmem. Skips the prefetch for net_iovs. Signed-off-by: Mina Almasry --- include/net/netmem.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/net/netmem.h b/include/net/netmem.h index 8a6e20be4b9d..923c47147aa8 100644 --- a/include/net/netmem.h +++ b/include/net/netmem.h @@ -171,4 +171,11 @@ static inline unsigned long netmem_get_dma_addr(netmem_ref netmem) return __netmem_clear_lsb(netmem)->dma_addr; } +static inline void netmem_prefetch(netmem_ref netmem) +{ + if (netmem_is_net_iov(netmem)) + return; + + prefetch(netmem_to_page(netmem)); +} #endif /* _NET_NETMEM_H */ From patchwork Tue Oct 29 20:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 839456 Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (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 EE657207A0F for ; Tue, 29 Oct 2024 20:55:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730235333; cv=none; b=ctBXq4OU4i9QvkG1IlLGGiVg0MKJFmsbcas8fNVbsHURosbTxNHNt4V/Z8FpwaHzx9Ru+7bpg0GidiKUPWJB0CxIFTmCmtATR4gkwhujvM/EpreGAl+YSU9WEfkPo1bfqqGurR43bx+zA/9K3LR4qiippysStB6ToKSqTzbqPII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730235333; c=relaxed/simple; bh=mQ6IINwbv+WqN8eNzea0/anvNw/9DICQ4rWqPuw7YWQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fmvz6alG97GxMmnnk6uUFjDcPddV2U/haGfDxNYuKI4ImwPhEUOIGMXA85/SPOu50dSVamnC4vO4LZQJ8MjciIPSe6DJqnea34LlLdBsmXEgqBqFE69G7q9ocDqbPvlPze3yY39ZZMTWH3OD8M0jP6v/V2NGvad4+va/Ycwk1p4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=n0gZIR53; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="n0gZIR53" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-e292dbfd834so9612518276.3 for ; Tue, 29 Oct 2024 13:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730235330; x=1730840130; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=bKpRCsSetJLLXlDYxzCijv6xVtSe3eCBCnbKb8kuBnA=; b=n0gZIR53ZEh5948T2NT5Vtz5gI9lNdqRir/X+O1P5EcN01YFb3GiY7XgkHwoKewjbe WcSu7P8lYVj/VRxsTfqRXQFURPG7Idvp2DpC09XNloM93JG79HvaJks+qGzWLANH4Es4 uO8G2lEdJ1Kpt9IIJ0f3WlR1s1YZcDNW3wnnguGIi72ukVDe5bXlICtMdyw585bmhUuw +GrMyjHnvZzQBIfSNyo3ZE1E0XvkAlywhO8bptDKAQ4WwthvNVTDwB6qJGvuYbnnWTOJ 8tveQFDLx3e4GEtsPMHZlKpfs8goTs60YMqXxr2jLT1O2wA2tZTs9LE6j6b75NqBEjE8 zgPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730235330; x=1730840130; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=bKpRCsSetJLLXlDYxzCijv6xVtSe3eCBCnbKb8kuBnA=; b=XS8yWIqK8IHF//hkOeDEo875DC7I4QUeqbBi+dQsyqhSNuXBBcjRFWrSpM7gN80Sf+ tW0jicsHydzOKMuSqG7rtpmSj5zgGG5dnwJk4caYRqq6wV4aEqTus10yDKRhsC81CIoF rX4MURiqbDs+mdKtM7LFF7G5h0n3qatL3e8S8FjZIU1UgqAuZMxLHHvBz+582Q/KIDOx lUQfu4LTPc/4RbHYfbixaih91EbNqeo6DCiF5DwALX1ILOkCvyBk5cjwIdRa4wD/nUJE zjjrElCk5u68uTrEcOtkavwYFu1fuVO56gmFDsYOgAjtdhUfDM32fAy27IUff5vhi1N9 ilpw== X-Forwarded-Encrypted: i=1; AJvYcCVPg9Rn9VEnCwDzytxMizlqmPr3gLh7xsVM53aGBNAwv9H8e82apcjd6HXkv8kECjMRdv8cM8pTZnhHqhVM0dg=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4Hlt4t5ahgSCNdW+G4eENZLDEQ8TDgv8wGTGEoTZZCbUSsgR+ lRPKt96D1z0BLmf4lQW8jPxjXZfDIbmFInH5PMNoSjwhWHZBJ7SAynYkx5vj6zRDQea8ed9iWsb OhLgiMDSwQi39M/sQvnbuHg== X-Google-Smtp-Source: AGHT+IEE7dLJq88/f4VVbxU0VfsyGl1ZHgwa5wCblziyZGTjJhsrP38TX70qH8bVr1KXcQFHnEzpeHyoZA5aeIAonQ== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a25:c78a:0:b0:e17:8e4f:981a with SMTP id 3f1490d57ef6-e3087c2d8b1mr69573276.11.1730235329787; Tue, 29 Oct 2024 13:55:29 -0700 (PDT) Date: Tue, 29 Oct 2024 20:55:21 +0000 In-Reply-To: <20241029205524.1306364-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241029205524.1306364-1-almasrymina@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241029205524.1306364-2-almasrymina@google.com> Subject: [PATCH net-next v1 6/7] net: fix SO_DEVMEM_DONTNEED looping too long From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Cc: Mina Almasry , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Jesper Dangaard Brouer , Ilias Apalodimas , Shuah Khan , Yi Lai Check we're going to free a reasonable number of frags in token_count before starting the loop, to prevent looping too long. Also minor code cleanups: - Flip checks to reduce indentation. - Use sizeof(*tokens) everywhere for consistentcy. Cc: Yi Lai Signed-off-by: Mina Almasry --- net/core/sock.c | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) -- 2.47.0.163.g1226f6d8fa-goog diff --git a/net/core/sock.c b/net/core/sock.c index 7f398bd07fb7..8603b8d87f2e 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1047,11 +1047,12 @@ static int sock_reserve_memory(struct sock *sk, int bytes) #ifdef CONFIG_PAGE_POOL -/* This is the number of tokens that the user can SO_DEVMEM_DONTNEED in +/* This is the number of frags that the user can SO_DEVMEM_DONTNEED in * 1 syscall. The limit exists to limit the amount of memory the kernel - * allocates to copy these tokens. + * allocates to copy these tokens, and to prevent looping over the frags for + * too long. */ -#define MAX_DONTNEED_TOKENS 128 +#define MAX_DONTNEED_FRAGS 1024 static noinline_for_stack int sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen) @@ -1059,43 +1060,52 @@ sock_devmem_dontneed(struct sock *sk, sockptr_t optval, unsigned int optlen) unsigned int num_tokens, i, j, k, netmem_num = 0; struct dmabuf_token *tokens; netmem_ref netmems[16]; + u64 num_frags = 0; int ret = 0; if (!sk_is_tcp(sk)) return -EBADF; - if (optlen % sizeof(struct dmabuf_token) || - optlen > sizeof(*tokens) * MAX_DONTNEED_TOKENS) + if (optlen % sizeof(*tokens) || + optlen > sizeof(*tokens) * MAX_DONTNEED_FRAGS) return -EINVAL; - tokens = kvmalloc_array(optlen, sizeof(*tokens), GFP_KERNEL); + num_tokens = optlen / sizeof(*tokens); + tokens = kvmalloc_array(num_tokens, sizeof(*tokens), GFP_KERNEL); if (!tokens) return -ENOMEM; - num_tokens = optlen / sizeof(struct dmabuf_token); if (copy_from_sockptr(tokens, optval, optlen)) { kvfree(tokens); return -EFAULT; } + for (i = 0; i < num_tokens; i++) { + num_frags += tokens[i].token_count; + if (num_frags > MAX_DONTNEED_FRAGS) { + kvfree(tokens); + return -E2BIG; + } + } + xa_lock_bh(&sk->sk_user_frags); for (i = 0; i < num_tokens; i++) { for (j = 0; j < tokens[i].token_count; j++) { netmem_ref netmem = (__force netmem_ref)__xa_erase( &sk->sk_user_frags, tokens[i].token_start + j); - if (netmem && - !WARN_ON_ONCE(!netmem_is_net_iov(netmem))) { - netmems[netmem_num++] = netmem; - if (netmem_num == ARRAY_SIZE(netmems)) { - xa_unlock_bh(&sk->sk_user_frags); - for (k = 0; k < netmem_num; k++) - WARN_ON_ONCE(!napi_pp_put_page(netmems[k])); - netmem_num = 0; - xa_lock_bh(&sk->sk_user_frags); - } - ret++; + if (!netmem || WARN_ON_ONCE(!netmem_is_net_iov(netmem))) + continue; + + netmems[netmem_num++] = netmem; + if (netmem_num == ARRAY_SIZE(netmems)) { + xa_unlock_bh(&sk->sk_user_frags); + for (k = 0; k < netmem_num; k++) + WARN_ON_ONCE(!napi_pp_put_page(netmems[k])); + netmem_num = 0; + xa_lock_bh(&sk->sk_user_frags); } + ret++; } }