From patchwork Tue Oct 1 07:58:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13895541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2832DE77170 for ; Thu, 5 Dec 2024 15:21:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3138F6B0108; Thu, 5 Dec 2024 10:19:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E7D7B6B00FA; Thu, 5 Dec 2024 10:19:12 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE6706B00AB; Thu, 5 Dec 2024 10:19:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 67338280036 for ; Tue, 1 Oct 2024 03:59:39 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B7EE980E86 for ; Tue, 1 Oct 2024 07:59:38 +0000 (UTC) X-FDA: 82624284036.22.F8EC7DC Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by imf09.hostedemail.com (Postfix) with ESMTP id 53F3914000F for ; Tue, 1 Oct 2024 07:59:35 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="OHx5I/+7"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of yunshenglin0825@gmail.com designates 209.85.216.65 as permitted sender) smtp.mailfrom=yunshenglin0825@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727769435; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=vktSfFznxxqxdyooYxAJtLpLR+uBOH4pDsLUZk+TldI=; b=gVsidJVLMdx3Soy0mVmMHu+i4yekyJdZgcUX8WTJaXSueUA0pLskvLyDb/hgPmKzSzgbvj O3MxsZDwo2ALTmQENK4zVXe3SODPb0RQyOKxQHV7fxxnwpnSRW7ksDJkiFnHPWSnQUoOaz ezqIj3YeHJN2zsCE9YOFAPObb9IxyRg= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727769435; a=rsa-sha256; cv=none; b=gH2XKygX2BMjufQnEkBhodb0GF6nN+WetcQMsl0ThbBdxR3f9PcS7f3NK5G5Dqz5O0F2V+ 4e5L2l3o64VqXsUdLPkpkIixpmEJqAHSJhQwoMEwdL1eGwG62/9wKL0swjebiNE52bhG1G TIKe2YIO1Ws4p4Sd8L2hZzdDte5ZB5g= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="OHx5I/+7"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf09.hostedemail.com: domain of yunshenglin0825@gmail.com designates 209.85.216.65 as permitted sender) smtp.mailfrom=yunshenglin0825@gmail.com Received: by mail-pj1-f65.google.com with SMTP id 98e67ed59e1d1-2e0b0142bbfso3267411a91.1 for ; Tue, 01 Oct 2024 00:59:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727769574; x=1728374374; darn=kvack.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=vktSfFznxxqxdyooYxAJtLpLR+uBOH4pDsLUZk+TldI=; b=OHx5I/+7Y/fWK39C5yKW+zYmIHExt4uZS9rYrepyN+XmtSZCsdWDMWY2S+4qkgIeV1 flJhF6AzBnDhF6TmGeFao5PggwisZtHTSmF1DOYE+NMLf0RwjbXNdumQLQ4BMhF2IAnl xLu55MbPKkXHnV96zPJm7sRVMAfzkXX/KB6G2pvc75Z9Vi4nKCS096N1H+YL8j+FQnwg aw+RNr1B2NQB41u4gR09AwsZHw19Cb3TuNtxMdfTW9NFbQ+nV9TpcCHDZ3SnfxX0v9J2 /vYi3kOAULT/S3t1OSc8BeH6uhphH1c/4ApfCMP89LHj28amNF7M6j/Ztdb5alpWfWlD 4azw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727769574; x=1728374374; 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=vktSfFznxxqxdyooYxAJtLpLR+uBOH4pDsLUZk+TldI=; b=UWLaaFsIqLyJv3Yfp1CM+w+KndfVf673coJUa5RcplS8OkPXKQbLGw19VFa3frM6wy x1C6LQ8XG1Jf/g8Byfb80z85TF6AA2obbIukeocZQ4oFjTXV7SbcUNfZN9v9wsZAkGdh nDeFmZRq9E602x2xvx4/X3wvRfnIDL8CSstAym9ARyGta5IhlD1ZpY/+3nxRv+y4m0R/ pZz2ZtysMMmSn8XbsO/aT7T0DWhft2RjoBvSaKI1B2mZseKcfVmVTV5eU5+zhrXEifcU TFR+TW57QUS8orGWH7WLUqhKN3SlmUH2FtCx2FbsJTUwm9OnM/gsq3h3TqcS31rgeNwa Skgw== X-Forwarded-Encrypted: i=1; AJvYcCXG35UIK0ALCrXic2YTptJleJWWCpeKHjHODOtKa5ee0K+AcmOH/j9KlfaWDCPY6jHl/Q/1niUjHw==@kvack.org X-Gm-Message-State: AOJu0Yx6vMK91GV1KG1NbOAPAvixfR8dTcceKWMt+XEWgYzd48Um7aKB CuQtSYFmPQfzBrYPobptrB4Kn0qbEIeAKzI+c5g32Wm9yRd7ZbH9 X-Google-Smtp-Source: AGHT+IH1qx+VpqO/M0ZFFo8jx2Ltv6BvYYP7WVtyTnNPIJSUx7pF6s/8RS08Pp9OK0t2pqi6/zCT9A== X-Received: by 2002:a17:90a:2f65:b0:2d8:999a:bc37 with SMTP id 98e67ed59e1d1-2e15a34cfe8mr3372002a91.19.1727769574029; Tue, 01 Oct 2024 00:59:34 -0700 (PDT) Received: from yunshenglin-MS-7549.. ([2409:8a55:301b:e120:88bd:a0fb:c6d6:c4a2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e16d6d2sm13168168a91.2.2024.10.01.00.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2024 00:59:33 -0700 (PDT) From: Yunsheng Lin X-Google-Original-From: Yunsheng Lin To: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yunsheng Lin , Alexander Duyck , Alexander Duyck , Chuck Lever , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Morton , Eric Dumazet , David Howells , Marc Dionne , Trond Myklebust , Anna Schumaker , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Shuah Khan , kvm@vger.kernel.org, virtualization@lists.linux.dev, linux-mm@kvack.org, linux-afs@lists.infradead.org, linux-nfs@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH net-next v19 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Tue, 1 Oct 2024 15:58:47 +0800 Message-Id: <20241001075858.48936-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001075858.48936-1-linyunsheng@huawei.com> References: <20241001075858.48936-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 53F3914000F X-Stat-Signature: iy1un3cckhzr873daxcjmzqy5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DuZbZVMsArahJlHx9w/vuANxV1BgJoJ/bOn7Lf1zp6SXamP23pndkyQ8edehztGUPkclKU17a/8Zmc9nkFg4CnIBcgly5t+np4OVVBjRiWjDdFm5KikL+I5TJ42Y8LLAVg9aSPucsD4ugojobH6Ow8WrkiQTR3Syf89V/sNCHqTdqyZv5xVx6ASzGQq95m9NNIzzwGeCrjQvtrb+ttQuR9FxVMxAUlAQDZzl/mHClg7iYJ++gF2dHnEjgHgHlrOcSWN3b7HW5A3M8PlBknHiZkOpjJ3c2U2ht49xAyN5mIAgiHdN3plHzvR9q7608NUYZ/Fg6ZgXlvsUocVPHMtBj8NivmYxdlcb+Ubbl5Xbdeuj9KgJIKXc2tM9jC0QL1ZMhiW5cJ+kKEsCM+e25uL1fbduBrbOvo8TJJg0k2ZdMIWINctgzBJGJ0c/OaLEyy3agEQMC8SOT4LQubgEdrHBLDvgfJt1Wstykse5Qf1/+CUuZpPH12Fr7RHLBKPRoeEooNYozJrcYZp8AFU1zRiv80GdhaTb5LOAyR9Vk4NX59hL7KdFF6FKoWZnVkREBKOoxIPf0ogABCVhPk5CQ4FimDiRXLuJkpUZfDEUhcMbHdliIqu+A== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use appropriate frag_page API instead of caller accessing 'page_frag_cache' directly. CC: Alexander Duyck Signed-off-by: Yunsheng Lin Reviewed-by: Alexander Duyck Acked-by: Chuck Lever --- drivers/vhost/net.c | 2 +- include/linux/page_frag_cache.h | 10 ++++++++++ net/core/skbuff.c | 6 +++--- net/rxrpc/conn_object.c | 4 +--- net/rxrpc/local_object.c | 4 +--- net/sunrpc/svcsock.c | 6 ++---- tools/testing/selftests/mm/page_frag/page_frag_test.c | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index f16279351db5..9ad37c012189 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1325,7 +1325,7 @@ static int vhost_net_open(struct inode *inode, struct file *f) vqs[VHOST_NET_VQ_RX]); f->private_data = n; - n->pf_cache.va = NULL; + page_frag_cache_init(&n->pf_cache); return 0; } diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h index 67ac8626ed9b..0a52f7a179c8 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -7,6 +7,16 @@ #include #include +static inline void page_frag_cache_init(struct page_frag_cache *nc) +{ + nc->va = NULL; +} + +static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *nc) +{ + return !!nc->pfmemalloc; +} + void page_frag_cache_drain(struct page_frag_cache *nc); void __page_frag_cache_drain(struct page *page, unsigned int count); void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 74149dc4ee31..ca01880c7ad0 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -753,14 +753,14 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len, if (in_hardirq() || irqs_disabled()) { nc = this_cpu_ptr(&netdev_alloc_cache); data = page_frag_alloc(nc, len, gfp_mask); - pfmemalloc = nc->pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); } else { local_bh_disable(); local_lock_nested_bh(&napi_alloc_cache.bh_lock); nc = this_cpu_ptr(&napi_alloc_cache.page); data = page_frag_alloc(nc, len, gfp_mask); - pfmemalloc = nc->pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); local_unlock_nested_bh(&napi_alloc_cache.bh_lock); local_bh_enable(); @@ -850,7 +850,7 @@ struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len) len = SKB_HEAD_ALIGN(len); data = page_frag_alloc(&nc->page, len, gfp_mask); - pfmemalloc = nc->page.pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(&nc->page); } local_unlock_nested_bh(&napi_alloc_cache.bh_lock); diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c index 1539d315afe7..694c4df7a1a3 100644 --- a/net/rxrpc/conn_object.c +++ b/net/rxrpc/conn_object.c @@ -337,9 +337,7 @@ static void rxrpc_clean_up_connection(struct work_struct *work) */ rxrpc_purge_queue(&conn->rx_queue); - if (conn->tx_data_alloc.va) - __page_frag_cache_drain(virt_to_page(conn->tx_data_alloc.va), - conn->tx_data_alloc.pagecnt_bias); + page_frag_cache_drain(&conn->tx_data_alloc); call_rcu(&conn->rcu, rxrpc_rcu_free_connection); } diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c index 504453c688d7..a8cffe47cf01 100644 --- a/net/rxrpc/local_object.c +++ b/net/rxrpc/local_object.c @@ -452,9 +452,7 @@ void rxrpc_destroy_local(struct rxrpc_local *local) #endif rxrpc_purge_queue(&local->rx_queue); rxrpc_purge_client_connections(local); - if (local->tx_alloc.va) - __page_frag_cache_drain(virt_to_page(local->tx_alloc.va), - local->tx_alloc.pagecnt_bias); + page_frag_cache_drain(&local->tx_alloc); } /* diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 825ec5357691..b785425c3315 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1608,7 +1608,6 @@ static void svc_tcp_sock_detach(struct svc_xprt *xprt) static void svc_sock_free(struct svc_xprt *xprt) { struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); - struct page_frag_cache *pfc = &svsk->sk_frag_cache; struct socket *sock = svsk->sk_sock; trace_svcsock_free(svsk, sock); @@ -1618,8 +1617,7 @@ static void svc_sock_free(struct svc_xprt *xprt) sockfd_put(sock); else sock_release(sock); - if (pfc->va) - __page_frag_cache_drain(virt_to_head_page(pfc->va), - pfc->pagecnt_bias); + + page_frag_cache_drain(&svsk->sk_frag_cache); kfree(svsk); } diff --git a/tools/testing/selftests/mm/page_frag/page_frag_test.c b/tools/testing/selftests/mm/page_frag/page_frag_test.c index fdf204550c9a..36543a129e40 100644 --- a/tools/testing/selftests/mm/page_frag/page_frag_test.c +++ b/tools/testing/selftests/mm/page_frag/page_frag_test.c @@ -117,7 +117,7 @@ static int __init page_frag_test_init(void) u64 duration; int ret; - test_nc.va = NULL; + page_frag_cache_init(&test_nc); atomic_set(&nthreads, 2); init_completion(&wait);