From nobody Sat Dec 31 02:47:56 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4NkRPm3D3vz2lCcZ; Sat, 31 Dec 2022 02:47:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4NkRPm2jFJz4Lwn; Sat, 31 Dec 2022 02:47:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672454876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pCFhpjPpBevPWDnKWCGerugJunIO8MYFddOJGz6AzCI=; b=uJjKM2eHWctsj3+3hFaCjnSORbUqkfvVYZ9RecIGgDgYN+J6iEBCt69URPgGIMM/dlzs+y onvNpZ2DlCwyMDcTA1Q9I2nVlX+JWmsIXcae9DG48sAK3Mj+v0IYGQFIQiYg3l8hWm1rY1 uJPgUp8Eyfwt8lbNMmlsKDRjf4VF7dpa0Ge/2W7ZW/CdRyYUxg17w/m7MWSn/zIfHOU7nS omVGOxWjtEXxWJye8AEbUhvCiZbm07C35XlWtvY+29gLkgx7oMIwNSFOv5y+av2ndlFzLm cvdU7QEdiHBmIrw+rKmopXfkD9c22ZlI7J2TGFFyDk7FiKOnBNO1T+Ui3qLDDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1672454876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pCFhpjPpBevPWDnKWCGerugJunIO8MYFddOJGz6AzCI=; b=kPlUmsnNTDFKCUjdMNIEdS1FYCUrU+VSPx28nyYg4sCZT16ndJdHhEzTRoADwi8otc0BaC OUpmyzT31d9GgxeBByCbwx3Jc8foOLNeBjuxt2tq0ek0x2TFSq31ikyWTxkTIiXg4lLiuG aeG37vkrGj96rcjM3/Kl8jR2J/dQ+Wld84zyg8zMO4NJuiGvl47/USsZOo5Aik2gi/YE7x DnKHbUu4R3lRaI2kvwJMaz6bg+ZWQwzK6fFhgw9BGShbCsAeMdkUCXBw4X3D2+RlK+OE7L uS4aplmQ197GOMzeAPH3elySNnhbOhfmJSiZ14MvxKFR0DTY+LZEKU27XdIvgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1672454876; a=rsa-sha256; cv=none; b=GcdYb7UGqYHeSWUg4qKVFc29hWWTfyue7ttqOXylHDVqF97tCrrRDulP7OoEjVqbf0K5hP pmbpUoqJB/XF/2/F6WF1gZWnjp1OoqMlF9xdwXTTwX7vS2h3JCI5/0gOv9GLZ09Im7SEMz vSUQWZ6vh43jYX9DEoeomd+45k+fUyg9zMhIy3lTnvWYBhBrWgSBkoyhRSjH6Hwi8DrOyj qBYwrez6ztMUUMr8IHzbV47bVPdh+2F2MJx33UCcoPhx2AS0CRt/ARSq9axDTzMHjtZVuQ HA1Uj83ebj9V/3vVzA8iHlvTXlM7XSRkq6EOJNnQ9PXPXSKKjh/SkyglYOAFnQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4NkRPm1gfJzWw7; Sat, 31 Dec 2022 02:47:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 2BV2luBL035974; Sat, 31 Dec 2022 02:47:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2BV2luJE035973; Sat, 31 Dec 2022 02:47:56 GMT (envelope-from git) Date: Sat, 31 Dec 2022 02:47:56 GMT Message-Id: <202212310247.2BV2luJE035973@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: 55038a6306a5 - main - LinuxKPI: add simplified vesion of page_frag_cache List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 55038a6306a570c9f2df89f5ad076de0f7d98152 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=55038a6306a570c9f2df89f5ad076de0f7d98152 commit 55038a6306a570c9f2df89f5ad076de0f7d98152 Author: Bjoern A. Zeeb AuthorDate: 2022-12-03 00:33:34 +0000 Commit: Bjoern A. Zeeb CommitDate: 2022-12-31 02:45:44 +0000 LinuxKPI: add simplified vesion of page_frag_cache For the moment and the currently only consumer (mt76) add a simplified version of the page_frag_cache. We will only accept fragement sizes up to 1 PAGE_SIZE (KASSERT) and we will always return a full page. Should we add more consumers or small (or large) objects would become a problem we can always add a more elaborate version. Discussed with: markj Reviewed by: markj (,hselasky commented as well) MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D37595 --- sys/compat/linuxkpi/common/include/linux/gfp.h | 29 +++++++++++++++++ sys/compat/linuxkpi/common/src/linux_page.c | 45 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/sys/compat/linuxkpi/common/include/linux/gfp.h b/sys/compat/linuxkpi/common/include/linux/gfp.h index 63b23b4b637e..a2930b44b0c4 100644 --- a/sys/compat/linuxkpi/common/include/linux/gfp.h +++ b/sys/compat/linuxkpi/common/include/linux/gfp.h @@ -81,6 +81,11 @@ CTASSERT((__GFP_DMA32 & GFP_NATIVE_MASK) == 0); CTASSERT((__GFP_BITS_MASK & GFP_NATIVE_MASK) == GFP_NATIVE_MASK); +struct page_frag_cache { + void *va; + int pagecnt_bias; +}; + /* * Resolve a page into a virtual address: * @@ -95,6 +100,9 @@ extern void *linux_page_address(struct page *); */ extern vm_page_t linux_alloc_pages(gfp_t flags, unsigned int order); extern void linux_free_pages(vm_page_t page, unsigned int order); +void *linuxkpi_page_frag_alloc(struct page_frag_cache *, size_t, gfp_t); +void linuxkpi_page_frag_free(void *); +void linuxkpi__page_frag_cache_drain(struct page *, size_t); static inline struct page * alloc_page(gfp_t flags) @@ -176,6 +184,27 @@ free_page(uintptr_t addr) linux_free_kmem(addr, 0); } +static inline void * +page_frag_alloc(struct page_frag_cache *pfc, size_t fragsz, gfp_t gfp) +{ + + return (linuxkpi_page_frag_alloc(pfc, fragsz, gfp)); +} + +static inline void +page_frag_free(void *addr) +{ + + linuxkpi_page_frag_free(addr); +} + +static inline void +__page_frag_cache_drain(struct page *page, size_t count) +{ + + linuxkpi__page_frag_cache_drain(page, count); +} + static inline bool gfpflags_allow_blocking(const gfp_t gfp_flags) { diff --git a/sys/compat/linuxkpi/common/src/linux_page.c b/sys/compat/linuxkpi/common/src/linux_page.c index 26b0ed649372..2bbe8f502cba 100644 --- a/sys/compat/linuxkpi/common/src/linux_page.c +++ b/sys/compat/linuxkpi/common/src/linux_page.c @@ -429,3 +429,48 @@ lkpi_arch_phys_wc_del(int reg) free(mrdesc, M_LKMTRR); #endif } + +/* + * This is a highly simplified version of the Linux page_frag_cache. + * We only support up-to 1 single page as fragment size and we will + * always return a full page. This may be wasteful on small objects + * but the only known consumer (mt76) is either asking for a half-page + * or a full page. If this was to become a problem we can implement + * a more elaborate version. + */ +void * +linuxkpi_page_frag_alloc(struct page_frag_cache *pfc, + size_t fragsz, gfp_t gfp) +{ + vm_page_t pages; + + if (fragsz == 0) + return (NULL); + + KASSERT(fragsz <= PAGE_SIZE, ("%s: fragsz %zu > PAGE_SIZE not yet " + "supported", __func__, fragsz)); + + pages = alloc_pages(gfp, flsl(howmany(fragsz, PAGE_SIZE) - 1)); + pfc->va = linux_page_address(pages); + + /* Passed in as "count" to __page_frag_cache_drain(). Unused by us. */ + pfc->pagecnt_bias = 0; + + return (pfc->va); +} + +void +linuxkpi_page_frag_free(void *addr) +{ + vm_page_t page; + + page = PHYS_TO_VM_PAGE(vtophys(addr)); + linux_free_pages(page, 0); +} + +void +linuxkpi__page_frag_cache_drain(struct page *page, size_t count __unused) +{ + + linux_free_pages(page, 0); +}