From patchwork Fri Oct 18 10:53:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13841625 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 EBF5DD2FFEC for ; Fri, 18 Oct 2024 11:00:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7EBED6B0089; Fri, 18 Oct 2024 07:00:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 79B2E6B008A; Fri, 18 Oct 2024 07:00:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 59EE26B008C; Fri, 18 Oct 2024 07:00:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3CB176B0089 for ; Fri, 18 Oct 2024 07:00:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0831E121A38 for ; Fri, 18 Oct 2024 11:00:15 +0000 (UTC) X-FDA: 82686429000.11.B64D592 Received: from szxga07-in.huawei.com (szxga07-in.huawei.com [45.249.212.35]) by imf14.hostedemail.com (Postfix) with ESMTP id B393F100029 for ; Fri, 18 Oct 2024 11:00:10 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729249078; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3cLH1ffUbO2p6/7QpbTwciO6JuoslQhl1JD6NmimWEA=; b=1zGvyFNhoVuWtquE0D56kB/XaywI2ROr2/p7HfcFjeEAUHTHEAeEwfLm3ogqYFyojPfHXe ngSzWLCBbVXGqIsP/EQahZSzkP++4yMN1GYZWJJ5ythwBJGSxZLRxBnqMKnGF9rt9ho7UM H3IcsXN2SsjE1rQiP3FLj2zhaq+yX7I= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729249078; a=rsa-sha256; cv=none; b=Ir3KU9k+BrJpUaesaQ68qxYWoShkffe7DjFMzuyXEEok2DkYogzP9+nn6H/7sWCkXsnpNU Q1xlVbkQ6Nc7iC8gfmbHFNefBSvAyMy3jBRVL7NxMrgWDHvBTGw/gKHs0ocLkEE/yC3byI mIEfUY0wNjYC9XMOTzb0bmz8YddWvCc= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.35 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4XVMC82SPnz1SCwM; Fri, 18 Oct 2024 18:59:00 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id B37551402E2; Fri, 18 Oct 2024 19:00:17 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Fri, 18 Oct 2024 19:00:17 +0800 From: Yunsheng Lin To: , , CC: , , 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 , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Shuah Khan , , , , , , Subject: [PATCH net-next v22 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Fri, 18 Oct 2024 18:53:41 +0800 Message-ID: <20241018105351.1960345-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241018105351.1960345-1-linyunsheng@huawei.com> References: <20241018105351.1960345-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspamd-Queue-Id: B393F100029 X-Stat-Signature: 76bz3q8eto5gnri1ohaq1e9yjz333wcn X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729249210-381384 X-HE-Meta: U2FsdGVkX181Vhfg6xUP6eFlymysC3iiJFE088f9VCeq/4R/m6hBPC6OyZbuuizN3+HlYiiRZ387BAoN+bchIGWU/jUvVWuvPaJxoFUCrTDa2b2E7Plk5Hfcs25xnqJ9kZdzuc9ip5uJFfZDe2byuuoSEeu2g6k/pEy52fRPaCQWvA4tkcsXmWnnplnpEFpmW4YdAoNoVA4F5oEGlWkrt/360gr/f3IZi2TBAb9W4SZ0C30V5HhlKV4RC4vgL159IqeIsUQUP9K3QQu1T2GSfdTIpS0UXM1l1MbG2NhMYz4oyzOz5dzYv4kQaEHHKqUQxzpvP19weKsY3AVisj8qYCswRSWlQVn9RsMClNQylV5FEwIZEFkei1g2Q9DvPWXZcJRhHMYBm8LdqwgbGsXkbT89ge2zODtytTh0I6YgtiYXA0VCl/IS70A1OWllPCGQdn1nZfPBtMFKOzTiAuF6Ae9DQ/qHU/MY538Aia+wyvqNozpo7A4+NSX/VjHWnL3ViRGHbzUAN+4h1pVFl7Sr5aHNAVrDXMTh2avbh1kvFgr0KZ4VAZfWJbRyEtFT4miqHok4KwXRarR3WZc8m4Yi6SbU54zUciMAQXZlQeqbV/1pa8LrlhFVlT4U6binE0ZsGHKKDro/itIJuADrcPiVIE83UqwoRK2ISeHoZGIcqU55bhoVejIZZi7qqTLCKBUx1iw7ICKmFoPPVFdsZD8Z/ctabDvaRcrUhi0so2yk0MF74zMwT4EDn6oRHdilURfBHCJC/eXutKr/EKUZWksIlbMAuWnLpVXwiin7DP5oKahjMQwQpmmniBy54OA046LdNk+2D97hLAc/FLRfqmZNMJfFfPtv+ongSU3+FreL6k1olgovt5QV20c0zrZpeg0ARltKNGs6SdnTpJjow4lbHtnpsEPVM/0mHOLGYj8KkDAGBStcgE1pB3o8hshoYkVWpd21iaThRb/6puLy3aZ pm6GiOeL M5aF6aFEioiE1CR3dbb7tqkD18vQhjiciqYb7i0avbUw10Q00O/71JOmU8xc1RN59nJFPdf1T0E6W1tMfMRKNeJNk0OyY3IEj8tBRzHtWoz1v1ED8POdct+kXuBH12vB6S/RMzRNc+JQkWu7sBp1SOXQZvNWu/WiFBEjNMMziOLl0OW4GwIw9ki2J33BlbInn8qDwei382wYhyuFUssBR0zpB0amlscYBN+TnwWP0pKWaRmOJ1ZS3hgLrskeeF/KXidK1pWckjI42VORcFBmvU+2BVXezIjfvRPdszrkfm1hknrgnoTg4D0sRe/rZBfehvsm6o2CcWZLDBmM= 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 00afeb90c23a..6841e61a6bd0 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 f9623ace2201..2792d2304605 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 13c44133e009..e806c1866e36 100644 --- a/tools/testing/selftests/mm/page_frag/page_frag_test.c +++ b/tools/testing/selftests/mm/page_frag/page_frag_test.c @@ -126,7 +126,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);