Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp2443765rbb; Wed, 28 Feb 2024 01:49:35 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUOb4yKOAEFBSfAzR8OQPddlQjStGQbSLwLHe5hM4geWNxxzy11xVYDdK5s+ImzWTulsVdlyxVb82EsHHE+rwvn4KfyKX9SAfBbuRFdrQ== X-Google-Smtp-Source: AGHT+IEtc1DGS5y3em6PXdI0hL+39O2eLYMs1Q4FArdcsS5i/k3TjWXfnpDKPefp+W2DrPMmJu/S X-Received: by 2002:a05:6a00:4b08:b0:6e0:50cb:5f0a with SMTP id kq8-20020a056a004b0800b006e050cb5f0amr2578991pfb.12.1709113774831; Wed, 28 Feb 2024 01:49:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709113774; cv=pass; d=google.com; s=arc-20160816; b=jH+PwXdmT/+qLprAHEXHGP35UJ3ZekFvLtCaju/WNFiXnEZoZ6eE3bUEy7oI5AfkcZ tM9y3rbcBlwh6aek7cGU1Qbs+1N25zEHomTi6RqUY1EqCZAUe8JA+ZYiNQsOt/1amfRf ptkXvBP+oQSzEYEIuSHQKBpbYGv+Vod1ExFRAGtX9Bpyo7PC8R2lp0aFZ4AczAvJ4lHZ SzhlxCYwrhmdiVy3cAxZiwX5cOEHMKrneEFkSQazTZjzi8qaKm3HbLqVcK0KgaDXVl/c opB5uSsOYqBwtyFZ8Gi+LyufjyIrjT3pNWk9l/1pSTZ13jvbu24H+GybsQ8yAF+sWWmb I9aw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=fsCym9aHBeJvlUtY57kt8x1IP0isH1vXizI9Lm8sOsM=; fh=4G9IKQeGVG4b/LAdr0T+TZfSuE5OF+6DNHYIGQi2/wc=; b=UC9z5e5SGDGzc3DP4bJ82Jd/VTmYZZsNG4atxAMVoXet2kzLdi4lDN8lQlIwnHCuz5 9kvIYZxuC7KkmrxpnUXTR2gKPUBn6wUQ9JlaTZpssNIwlmCRP2hqsyWeoKK2IbFy6oB6 JZ0xlv0nIUlZmePZOz3KHYXUfL7CreSzi0bnWMFkBP9rJ6s13HqH29ywyieInHeBbnI8 4FiO/05gKxt+0OQdYcO8k0JhPNQUXUQGAZeGoCG6JCQJer6wHJZTNGa2hXUnufbN8Mex PVHidU2tC9aoBnve2zr/MsF1q3WICb6ucDBLQDIYNpxEED1em9kXNDLTL/EgMlUPqDDU 0fmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-84765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id r18-20020a63ec52000000b005d4af343858si7021685pgj.361.2024.02.28.01.49.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Feb 2024 01:49:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-84765-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id A0F89B24CA6 for ; Wed, 28 Feb 2024 09:32:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B67B936AE1; Wed, 28 Feb 2024 09:32:06 +0000 (UTC) Received: from szxga06-in.huawei.com (szxga06-in.huawei.com [45.249.212.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D74D0364A0; Wed, 28 Feb 2024 09:32:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.32 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709112726; cv=none; b=Cd+dXNOonmV6Wx5EeNQYI90U1eBn+Uji+wyOJTZU/DAyBDFS5VoT0u7PylXg0Y0JUQA6mYdvVeJmTWRddxPIiGI7/SSCYNSoCVZi7JyKlxhEphjgTjlpnYylOAwTDveKy1rURvf8K0KsQHM/v1iilXAujbF2KdqitUA/SpZnDjM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709112726; c=relaxed/simple; bh=rtYrKnDHGy1tiASLdyqYGdZiFjmIz6YBwthQ2luhzKo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BrMrr/b3fvDlIdS/LTmxxd3GKSPQAUtWJkTWYNSV5FqLH06h8mAdgX+prebcU+q93UfY+2mygUM5Xa442XrNp/ZWnQFhZzlahF7f35Va17OFu2iTA1aYFQ782vYoAhnb82xpQrIGGuY8PwAiBWwQh0kwrjkePPQ13GEbKE4lQjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.17]) by szxga06-in.huawei.com (SkyGuard) with ESMTP id 4Tl8HW1WW4zqjHD; Wed, 28 Feb 2024 17:31:19 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id 5F7F01A0172; Wed, 28 Feb 2024 17:31:56 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Wed, 28 Feb 2024 17:31:56 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Eric Dumazet , Subject: [PATCH net-next v6 1/5] mm/page_alloc: modify page_frag_alloc_align() to accept align as an argument Date: Wed, 28 Feb 2024 17:30:08 +0800 Message-ID: <20240228093013.8263-2-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240228093013.8263-1-linyunsheng@huawei.com> References: <20240228093013.8263-1-linyunsheng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500005.china.huawei.com (7.185.36.74) napi_alloc_frag_align() and netdev_alloc_frag_align() accept align as an argument, and they are thin wrappers around the __napi_alloc_frag_align() and __netdev_alloc_frag_align() APIs doing the alignment checking and align mask conversion, in order to call page_frag_alloc_align() directly. The intention here is to keep the alignment checking and the alignmask conversion in in-line wrapper to avoid those kind of operations during execution time since it can usually be handled during compile time. We are going to use page_frag_alloc_align() in vhost_net.c, it need the same kind of alignment checking and alignmask conversion, so split up page_frag_alloc_align into an inline wrapper doing the above operation, and add __page_frag_alloc_align() which is passed with the align mask the original function expected as suggested by Alexander. Signed-off-by: Yunsheng Lin CC: Alexander Duyck --- include/linux/gfp.h | 15 +++++++++++---- mm/page_alloc.c | 8 ++++---- net/core/skbuff.c | 9 ++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/include/linux/gfp.h b/include/linux/gfp.h index de292a007138..28aea17fa59b 100644 --- a/include/linux/gfp.h +++ b/include/linux/gfp.h @@ -312,14 +312,21 @@ extern void free_pages(unsigned long addr, unsigned int order); struct page_frag_cache; extern void __page_frag_cache_drain(struct page *page, unsigned int count); -extern void *page_frag_alloc_align(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask, - unsigned int align_mask); +void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, + gfp_t gfp_mask, unsigned int align_mask); + +static inline void *page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align) +{ + WARN_ON_ONCE(!is_power_of_2(align)); + return __page_frag_alloc_align(nc, fragsz, gfp_mask, -align); +} static inline void *page_frag_alloc(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask) { - return page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); + return __page_frag_alloc_align(nc, fragsz, gfp_mask, ~0u); } extern void page_frag_free(void *addr); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 150d4f23b010..c0f7e67c4250 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -4708,9 +4708,9 @@ void __page_frag_cache_drain(struct page *page, unsigned int count) } EXPORT_SYMBOL(__page_frag_cache_drain); -void *page_frag_alloc_align(struct page_frag_cache *nc, - unsigned int fragsz, gfp_t gfp_mask, - unsigned int align_mask) +void *__page_frag_alloc_align(struct page_frag_cache *nc, + unsigned int fragsz, gfp_t gfp_mask, + unsigned int align_mask) { unsigned int size = PAGE_SIZE; struct page *page; @@ -4779,7 +4779,7 @@ void *page_frag_alloc_align(struct page_frag_cache *nc, return nc->va + offset; } -EXPORT_SYMBOL(page_frag_alloc_align); +EXPORT_SYMBOL(__page_frag_alloc_align); /* * Frees a page fragment allocated out of either a compound or order 0 page. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 1f918e602bc4..43d7fc150acc 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -315,7 +315,8 @@ void *__napi_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) fragsz = SKB_DATA_ALIGN(fragsz); - return page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); + return __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, + align_mask); } EXPORT_SYMBOL(__napi_alloc_frag_align); @@ -327,13 +328,15 @@ void *__netdev_alloc_frag_align(unsigned int fragsz, unsigned int align_mask) if (in_hardirq() || irqs_disabled()) { struct page_frag_cache *nc = this_cpu_ptr(&netdev_alloc_cache); - data = page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, align_mask); + data = __page_frag_alloc_align(nc, fragsz, GFP_ATOMIC, + align_mask); } else { struct napi_alloc_cache *nc; local_bh_disable(); nc = this_cpu_ptr(&napi_alloc_cache); - data = page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, align_mask); + data = __page_frag_alloc_align(&nc->page, fragsz, GFP_ATOMIC, + align_mask); local_bh_enable(); } return data; -- 2.33.0