From patchwork Mon Jul 11 12:24:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 12913466 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B4DDBC433EF for ; Mon, 11 Jul 2022 12:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=VEaqsRYHgN76eec3YUMbcdPpDZjhzq/sjztCD4+gfMU=; b=37UStFTsRb6eUo nwyAs16MKeEsxIT9oLMAdOxS/HpyYMaijOY6TQ0oZ9yBBEF+TtF7/uYv0Jy7tNOszt9jiEseoAaNi jAI42KOCsWbGJTAdycBcpG/TIC1wAknhGJd9Spo1/y2whqkfh4EjwO2BFP4+E8IYqKNM7KXXvdCou KR9MUsW4aiRouw1jk4vNRk9srd1Wvs3C1NdRVcobzVf3WwcBHc4HfKkEX5XaeWyllzBEKab2FeQUL jnR1Of2+C9dKYHOCjRtazNlQrvIrIQFlZKHu1qdiSaGEtHd5sEHH6gOrAeVoX2IwaethtQRdt1UsZ OIvO8pZV9tmeUV26uATA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWP-001Pl0-Bw; Mon, 11 Jul 2022 12:28:17 +0000 Received: from sender4-op-o14.zoho.com ([136.143.188.14]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWG-001Pgs-V3 for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2022 12:28:11 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1657542486; cv=none; d=zohomail.com; s=zohoarc; b=B8RlRZ/5yroueJFXiAHVH1mlXjxtZ7t0XswTWYGnM/Dxh5l8JOPEIz7ljR5Aa/TxeNa5yyf1WxcCYlM3rx93ZqQl57gnx74SGa4SOtyBRP02qavN8jkdWkyyGHH72TAbBaf+pfMljGzPQgrIqVpo+NXuLD2Tjc6fOoSE9U7dCGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657542486; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=HwXOig16pXGDeKv+H+OhTU1Ct215tHrAf79CKNQ+hsA=; b=XDIgGV3ruxfy1J14mmroPkuFNkuGIoY59s1ss2+hyknDVpObonwV8hBOytDSw4tDH/TIrPGUYux2vhiXsLTDBbgXBPpMiky08KU1RsDr4jxZZbZUoOTnmYiLJ63l1OVnL+Sw5RvzEiAWo4bLog/fCCk0wHoiLKUZoEnE84uIWn0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657542486; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=HwXOig16pXGDeKv+H+OhTU1Ct215tHrAf79CKNQ+hsA=; b=WxEl023tQ+yaoo8T9DFz8cyUMyKNEWHQkkzgufuRjMofQV2193zfvzaOQBziHlnJ 9jyi/fl9b4q/ZmeX1vu20uf9/qUcplHzHVveA2FRFqvL8APO4KHwfXE5qGTfFLc5cQ6 gBmv8C1AYGxnE7VNsQWL8XbvWvE7pSmThk+EF7Ck= Received: from sh-lchen.ambarella.net (180.169.129.130 [180.169.129.130]) by mx.zohomail.com with SMTPS id 1657542484599946.4016813577733; Mon, 11 Jul 2022 05:28:04 -0700 (PDT) From: Li Chen To: Catalin Marinas , Will Deacon , Rob Herring , Frank Rowand , Andrew Morton Cc: Li Chen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 1/4] of: add struct page support to rmem Date: Mon, 11 Jul 2022 20:24:51 +0800 Message-Id: <20220711122459.13773-2-me@linux.beauty> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711122459.13773-1-me@linux.beauty> References: <20220711122459.13773-1-me@linux.beauty> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220711_052809_087417_E7EFFA4E X-CRM114-Status: GOOD ( 24.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Li Chen This commit add a new config OF_RESERVED_MEM_DIO_SUPPORT and some utilities to enables consumers to build struct pages on rmem. Signed-off-by: Li Chen Change-Id: Iaba8874775c6d3a7096ac19575bb884db13351d1 Reported-by: kernel test robot Reported-by: kernel test robot Reported-by: Dan Carpenter --- drivers/of/Kconfig | 9 ++ drivers/of/of_reserved_mem.c | 218 +++++++++++++++++++++++++++++++- include/linux/of_reserved_mem.h | 11 ++ 3 files changed, 237 insertions(+), 1 deletion(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 80b5fd44ab1c..0297c03328d8 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -73,6 +73,15 @@ config OF_IRQ config OF_RESERVED_MEM def_bool OF_EARLY_FLATTREE +config OF_RESERVED_MEM_DIO_SUPPORT + bool "add Direct I/O support to reserved_mem" + depends on ZONE_DEVICE && ARCH_KEEP_MEMBLOCK + help + By default, reserved memory don't get struct page support, which + means you cannot do Direct I/O from this region. This config takes + uses of ZONE_DEVICE and treats rmem as hotplug mem to get struct + page and DIO support. + config OF_RESOLVE bool diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c index 9da8835ba5a5..f4974da6df98 100644 --- a/drivers/of/of_reserved_mem.c +++ b/drivers/of/of_reserved_mem.c @@ -72,7 +72,6 @@ void __init fdt_reserved_mem_save_node(unsigned long node, const char *uname, rmem->size = size; reserved_mem_count++; - return; } /* @@ -447,3 +446,220 @@ struct reserved_mem *of_reserved_mem_lookup(struct device_node *np) return NULL; } EXPORT_SYMBOL_GPL(of_reserved_mem_lookup); + +/** + * get_reserved_mem_from_dev() - get reserved_mem from a device node + * @dev: device pointer + * + * This function look for reserved_mem from given device. + * + * Returns a reserved_mem pointer, or NULL on error. + */ +struct reserved_mem *get_reserved_mem_from_dev(struct device *dev) +{ + struct device_node *np = dev_of_node(dev); + struct device_node *rmem_np; + struct reserved_mem *rmem = NULL; + + rmem_np = of_parse_phandle(np, "memory-region", 0); + if (!rmem_np) { + dev_err(dev, "failed to get memory region node\n"); + return ERR_PTR(-ENODEV); + } + + rmem = of_reserved_mem_lookup(rmem_np); + if (!rmem) { + dev_err(dev, "Failed to lookup reserved memory\n"); + return ERR_PTR(EINVAL); + } + return rmem; +} +EXPORT_SYMBOL_GPL(get_reserved_mem_from_dev); + +#ifdef CONFIG_OF_RESERVED_MEM_DIO_SUPPORT + +static int reserved_mem_dio_in_region(unsigned long addr, + unsigned long size, + const struct reserved_mem *rmem) +{ + if ((rmem && (addr >= rmem->base) && + ((addr + size) <= (rmem->base + rmem->size)))) + return 0; + + return -EINVAL; +} + +static int reserved_mem_dio_get_page(struct mm_struct *mm, + unsigned long start, + struct page **page, + const struct reserved_mem *rmem) +{ + unsigned long vaddr = start & PAGE_MASK, pfn; + int ret = -EFAULT; + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + p4d_t *p4d; + + pgd = pgd_offset(mm, vaddr); + if (pgd_none(*pgd)) + return ret; + + p4d = p4d_offset(pgd, vaddr); + if (p4d_none(*p4d)) + return ret; + + pud = pud_offset(p4d, vaddr); + if (pud_none(*pud)) + return ret; + + pmd = pmd_offset(pud, vaddr); + if (pmd_none(*pmd)) + return ret; + + pte = pte_offset_map(pmd, vaddr); + if (pte_none(*pte)) + goto out; + + pfn = pte_pfn(*pte); + if (!pfn_valid(pfn)) + goto out; + + if (likely(reserved_mem_dio_in_region(pfn << PAGE_SHIFT, PAGE_SIZE, rmem) < + 0)) + goto out; + + if (page) { + *page = pfn_to_page(pfn); + get_page(*page); + } + + ret = 0; + +out: + pte_unmap(pte); + return ret; +} + +static struct page *reserved_mem_dio_find_special_page(struct vm_area_struct *vma, + unsigned long addr) +{ + struct page *page = NULL; + + reserved_mem_dio_get_page(vma->vm_mm, addr, &page, + (struct reserved_mem *)vma->vm_private_data); + return page; +} + +static const struct vm_operations_struct rmem_dio_vmops = { + .find_special_page = reserved_mem_dio_find_special_page, +}; + +/** + * reserved_mem_dio_mmap() - mmap helper function to map given rmem to userspace + * with struct pages support + * @file: file pointing to address space structure to wait for + * @vma: the vm area in which the mapping is added + * @rmem: reserved memory region from dts, which can be obtained from + * get_reserved_mem_from_dev(dev) + * + * Returns: 0 on success or a negative error-code on failure. + */ +int reserved_mem_dio_mmap(struct file *file, struct vm_area_struct *vma, struct reserved_mem *rmem) +{ + int ret = 0; + unsigned long nr_pages; + + if (!rmem) { + pr_err("%s: failed to get rmem from private data\n", __func__); + return -ENOMEM; + } + if (!rmem->pages) { + pr_err("%s: failed to get struct pages from reserved mem\n", __func__); + return -ENOMEM; + } + + if (!rmem->nr_pages) { + pr_err("%s: error: rmem nr_pages is 0\n", __func__); + return -ENOMEM; + } + + if (vma->vm_end - vma->vm_start > rmem->size) + return -EINVAL; + + vma->vm_private_data = rmem; + + /* duplicitate nr_pages in that vm_insert_pages can change nr_pages */ + nr_pages = rmem->nr_pages; + + /* + * use vm_insert_pages instead of add remap_pfn_range variant + * because vm_insert_pages will invoke rmap functions to inc _mapcount, + * while latter don't do it. When unmap, + * kernel will warn if page's _mapcount is <= -1. + */ + ret = vm_insert_pages(vma, vma->vm_start, rmem->pages, &nr_pages); + if (ret < 0) + pr_err("%s vm_insert_pages fail, error is %d\n", __func__, ret); + + vma->vm_ops = &rmem_dio_vmops; + + return ret; +} +EXPORT_SYMBOL_GPL(reserved_mem_dio_mmap); + +/** + * reserved_mem_memremap_pages() - build struct pages for reserved mem + * @dev: device pointer + * @rmem: reserved memory region from dts, which can be get by + * get_reserved_mem_from_dev(dev) + * + * Returns: 0 on success or a negative error-code on failure. + */ +void *reserved_mem_memremap_pages(struct device *dev, struct reserved_mem *rmem) +{ + struct dev_pagemap *pgmap_rmem_dio; + void *vaddr; + struct page **pages; + int i; + unsigned long offset = 0; + struct page *page; + + rmem->nr_pages = DIV_ROUND_UP(rmem->size, PAGE_SIZE); + pages = kvmalloc_array(rmem->nr_pages, sizeof(*pages), GFP_KERNEL); + if (!pages) + return ERR_PTR(-ENOMEM); + + pgmap_rmem_dio = devm_kzalloc(dev, sizeof(*pgmap_rmem_dio), GFP_KERNEL); + + pgmap_rmem_dio->range.start = rmem->base; + pgmap_rmem_dio->range.end = rmem->base + rmem->size - 1; + pgmap_rmem_dio->nr_range = 1; + pgmap_rmem_dio->type = MEMORY_DEVICE_GENERIC; + + pr_debug("%s, will do devm_memremap_pages, start from %llx, to %llx\n", + __func__, pgmap_rmem_dio->range.start, pgmap_rmem_dio->range.end); + + vaddr = devm_memremap_pages(dev, pgmap_rmem_dio); + + if (IS_ERR_OR_NULL(vaddr)) { + dev_err(dev, "%s %d: %ld", __func__, __LINE__, PTR_ERR(vaddr)); + return vaddr; + } + + rmem->pages = pages; + + for (i = 0; i < rmem->nr_pages; offset += PAGE_SIZE) { + page = virt_to_page((unsigned long)vaddr + offset); + if (!page) { + pr_err("%s: virt_to_page fail\n", __func__); + return ERR_PTR(-ENOMEM); + } + pages[i++] = page; + } + + return vaddr; +} +EXPORT_SYMBOL_GPL(reserved_mem_memremap_pages); +#endif diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h index 4de2a24cadc9..0aa1ef883060 100644 --- a/include/linux/of_reserved_mem.h +++ b/include/linux/of_reserved_mem.h @@ -16,6 +16,10 @@ struct reserved_mem { phys_addr_t base; phys_addr_t size; void *priv; +#ifdef CONFIG_OF_RESERVED_MEM_DIO_SUPPORT + struct page **pages; /* point to array of struct pages of this region */ + unsigned long nr_pages; /* number of struct page* */ +#endif }; struct reserved_mem_ops { @@ -81,4 +85,11 @@ static inline int of_reserved_mem_device_init(struct device *dev) return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0); } +struct reserved_mem *get_reserved_mem_from_dev(struct device *dev); + +#ifdef CONFIG_OF_RESERVED_MEM_DIO_SUPPORT +int reserved_mem_dio_mmap(struct file *file, struct vm_area_struct *vma, struct reserved_mem *rmem); +void *reserved_mem_memremap_pages(struct device *dev, struct reserved_mem *rmem); +#endif + #endif /* __OF_RESERVED_MEM_H */ From patchwork Mon Jul 11 12:24:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 12913467 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2F043C43334 for ; Mon, 11 Jul 2022 12:29:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=MUTa+8dTl099ohjdonvoLmVBbHQWkZ6MhURxpBYXQ0c=; b=g8D9J6PNgzH/21 43fsIYchWSRwaDzUC3049dm9E2NJFyHWsnS/Rv3kI+TUeV65ik4IWa+0jaCEcdIxvVxgUFdPTC3RB Bhi3XEw9RWKcNjgZf+L7Qj7wrV49xJi0SGv48VWYTiw63n6pIei0XaFbf5SFBYL2ym4nu/Du/qokf 0chJdlmK6FzEwcPhVLZ8JTMaBu7KcYivMCONCgJ0UmjzRWSQ+/VTOUYlxh6xkwvEuoJ41eXcv0IZi +B68q6zjvwNlb/JDOQjFAdeVxAjxKzBjUnc72CZqaF00Ae0+FpNvetQjSZqpVnVi+mphbAM6BOptY RiohXCjtPZ5N7bX3Mgqw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWe-001PtE-CS; Mon, 11 Jul 2022 12:28:32 +0000 Received: from sender4-op-o14.zoho.com ([136.143.188.14]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWT-001PnN-Lr for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2022 12:28:22 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1657542496; cv=none; d=zohomail.com; s=zohoarc; b=d9jlwf2JduepAUH0sP5MVHxLsoRxqYD2zVBYKAyqOCrDGaIgIww8ZN60Ke5MlhVsrzfUaQ2eIIxKEk12xqZvw3+xwABssGIZS/XbfnFQt4TCJGWGWYbNNkvPYn0wolsnVKnqygo1CZ2KUFr1gNUmsVBoGII4AGDGQ7h/iH/HwbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657542496; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=nNMEZ/IULIqFkQZN/oBrcmZXnBPShQJWnrZceFIU7hk=; b=gA37RdDjMuGem70uRtqv1PDGFxctWfJodDZlIWpRWTJeFO9OkNhb3Gd4PeYqTdNUSlZ3q/f2uuIwvijb1BbEQekeqU1iLVnrKg67QDYGqop69TywVMtKVzqDyIMWmzcEFlntGgG8RXJEhitDFlYg53IVFY3bNn8ap2PUJuucakc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657542496; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=nNMEZ/IULIqFkQZN/oBrcmZXnBPShQJWnrZceFIU7hk=; b=KrYo66Fvw84KWCAXvugb8MTWVK3cvnzI/YA9ujEKbC98ESaZwaOvHO0GXEbOMRiA BpF3GRKM/9dGBv3L14VlJ6NOF4KdgKbBkWVC8OvJdNV1wvSH1XcuuAicOHqR8lK8TlG PCzKIOnsOEY45R6iD7bsj0wBT8ORA5vXRpvmRxNA= Received: from sh-lchen.ambarella.net (180.169.129.130 [180.169.129.130]) by mx.zohomail.com with SMTPS id 1657542495481198.279413668139; Mon, 11 Jul 2022 05:28:15 -0700 (PDT) From: Li Chen To: Catalin Marinas , Will Deacon , Rob Herring , Frank Rowand , Andrew Morton Cc: Li Chen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 2/4] mm/sparse: skip no-map memblock check when fill_subsection_map Date: Mon, 11 Jul 2022 20:24:52 +0800 Message-Id: <20220711122459.13773-3-me@linux.beauty> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711122459.13773-1-me@linux.beauty> References: <20220711122459.13773-1-me@linux.beauty> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220711_052821_783451_7049D0FF X-CRM114-Status: GOOD ( 10.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Li Chen When mhp use sparse_add_section, don't check no-map region, so that to allow no-map reserved memory to get struct page support. Signed-off-by: Li Chen Change-Id: I0d2673cec1b66adf695251037a00c240976b226f Reported-by: kernel test robot --- mm/sparse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mm/sparse.c b/mm/sparse.c index 120bc8ea5293..a29cd1e7014f 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -690,7 +690,9 @@ static int fill_subsection_map(unsigned long pfn, unsigned long nr_pages) if (bitmap_empty(map, SUBSECTIONS_PER_SECTION)) rc = -EINVAL; - else if (bitmap_intersects(map, subsection_map, SUBSECTIONS_PER_SECTION)) + else if (memblock_is_map_memory(PFN_PHYS(pfn)) && + bitmap_intersects(map, subsection_map, + SUBSECTIONS_PER_SECTION)) rc = -EEXIST; else bitmap_or(subsection_map, map, subsection_map, From patchwork Mon Jul 11 12:24:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 12913468 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0AED6C433EF for ; Mon, 11 Jul 2022 12:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mlIHMhObmCRe0i+/bSt+smu24dpNB43d4XSclYID8r4=; b=ofRR3Qy0lx7LEk tp/gTJqA+eV0236V6T+q6yf9Le/wGIYpxNT0K7kxKAsjucenk6osPCwbHEVh5eAdNHqNqBWanC6vZ c1OvSIDukCgc5BUGID1eB+ubCE4Z/q4z9zrCTaoKjXMZnenwEHx49W63GveQyRAMwAU68ZY2TEsxC Kt2TE1PmeKB+yxc5XJRx8+QMcUB46ds7PXlNGR/yXRx0JfHTkoVgwdLlHGuOQEjXAid/fkntreS3E cPRzln3oRjXtSruRrg33kpnMT/dbNz2DWYGEH8vcm6KXqkT9EObNZ0GyfULrWJm/OmXmMO6RYoq2t 0xgMvevufsKzl5bBs0zA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsX7-001QAr-NQ; Mon, 11 Jul 2022 12:29:01 +0000 Received: from sender4-op-o14.zoho.com ([136.143.188.14]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWd-001Pt1-60 for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2022 12:28:32 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1657542507; cv=none; d=zohomail.com; s=zohoarc; b=Wj44IkAqMXaiKU22l0jln19+dFZUF2tU1v6Ac7YOgtpb7vvnuFcD34l08N0YVG5nbJN2R/+aYu0sMawgJiFRjkG5NTyizEg5zz82r2G5Fuavr9rJ7dAIm9Gk1uicehNvkJsl5Iu3r4UvzamBKsmZDQXDKHfZpaLKatzU4OGALH8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657542507; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=XcBY/Eq5IywNEBwnOGSytrIPNKZEd+GUxWkjesqgdhE=; b=BY4tqD/qFDF9rINfEZzxZKU+DaJNwKdHh1xD5Y+CVu4grzv+a9lvB9jhxgANvAy0p7xxK976w1KMBdDQhMhIIWYrqdY3GrmjDQfK4805g/qdEhPLEpuAkpWRFvkSC2ukCmVBB3pM0XMPR6G/X7TYFDG9NwL93CbGOiuxwQOVyGc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657542507; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=XcBY/Eq5IywNEBwnOGSytrIPNKZEd+GUxWkjesqgdhE=; b=ZtcV/kLTYKL80lJw5yjgoMSBb4kqp2TEbTehtIGGwreBUCqr63ySryzpBf6w5IzY AIKjzm5yLsYgY1zXvcUsf1xJM1Op5zu0c1+cIxJnWup9K6mr8+cTEzpHJXeu4g73b2Y JWLicwjaA0FO8VmTqNcRBsP917DGU9KHhd+PIbmE= Received: from sh-lchen.ambarella.net (180.169.129.130 [180.169.129.130]) by mx.zohomail.com with SMTPS id 1657542504796249.49555353239066; Mon, 11 Jul 2022 05:28:24 -0700 (PDT) From: Li Chen To: Catalin Marinas , Will Deacon , Rob Herring , Frank Rowand , Andrew Morton Cc: Li Chen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 3/4] arm64: mm: move memblock_clear_nomap after __add_pages Date: Mon, 11 Jul 2022 20:24:53 +0800 Message-Id: <20220711122459.13773-4-me@linux.beauty> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711122459.13773-1-me@linux.beauty> References: <20220711122459.13773-1-me@linux.beauty> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220711_052831_282161_A8F9C8F5 X-CRM114-Status: GOOD ( 10.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Li Chen I'm trying to add struct page support to nomap reserved memory, and have skipped nomap bitmap_intersects check in fill_subsection_map, so just move memblock_clear_nomap after __add_pages. Signed-off-by: Li Chen Change-Id: I5e26fdc3f3e55b12f1acc1adb47fb262c4877ff3 --- arch/arm64/mm/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/mm/mmu.c b/arch/arm64/mm/mmu.c index 6680689242df..2e7f503837e4 100644 --- a/arch/arm64/mm/mmu.c +++ b/arch/arm64/mm/mmu.c @@ -1537,10 +1537,10 @@ int arch_add_memory(int nid, u64 start, u64 size, size, params->pgprot, __pgd_pgtable_alloc, flags); - memblock_clear_nomap(start, size); ret = __add_pages(nid, start >> PAGE_SHIFT, size >> PAGE_SHIFT, params); + memblock_clear_nomap(start, size); if (ret) __remove_pgd_mapping(swapper_pg_dir, __phys_to_virt(start), size); From patchwork Mon Jul 11 12:24:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Chen X-Patchwork-Id: 12913469 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AA7EC43334 for ; Mon, 11 Jul 2022 12:30:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mpLKQ4z8LTLYKbC8KzWlomMoBMvVf384q5/KKGCjD+g=; b=sFleLnfOBIRpv8 Q+sPdFrEKITGVQPvyyX0FdgJBtGkSsoPydiEluPBGon+r9qCaliYSbfpBQIKEn+KQsZMTMWe9r41q YnnXQLMoFcW8KJFInyshjPLK4Id92cwULXc3eEsm1D2gVh3Pka6hrJA40xt196B8EEXXJRz6c95vn eRHquIcZU88NuPGdQ2KD62TN0sR4Oty9dwje7i2qCoMg/dR2K/tiY/1mTdbKc8HrAT7U0f0MJ3b+8 3388q6ORd3HVaLVuEfhu82UA3T2vnhXr4hekcGsxFgrFhVMTHMIyTgNMF/yXx7DJ1ko/GS24h778g jFC62ennWk0O4CbzB0mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsXO-001QNE-2I; Mon, 11 Jul 2022 12:29:18 +0000 Received: from sender4-op-o14.zoho.com ([136.143.188.14]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oAsWi-001Pwd-CG for linux-arm-kernel@lists.infradead.org; Mon, 11 Jul 2022 12:28:39 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1657542513; cv=none; d=zohomail.com; s=zohoarc; b=BWLMC3it4BtPyJWYDoPgYKmbLqEhQRxv8s3RJ9kVzUq4qSI3Se1FWX6GzIcNcUQyYwPw5MwzLU3Lt+4A2Y2KLof2kHNvZ/TaGNRptdXyiv5OSs4IFQDxHO0zHG4xT5fEMhVDp2U5LmP3sF3Ah0dgo8POju7SL3GZBzVm0DwnP8o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657542513; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/45RwWvpZQ8gxiW9JTrbUVV5LljPR1ktHOujlwlnKxQ=; b=mr/8H1PKbsemg6iuOktY9uH9bIO4L2xoejQBtu3J6xBCmTUVVqm5akq2/PUJNfCZEdPPquqMTLk9LYIt6L/G3ctrpuk+kNmRJ8OmO6t7fBxwWhOcKMvKK6/MSdeGJipFvolMPDc0J1iFF9SnR0/lfyKp6QllbiaiCSWF0C3OqD4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=linux.beauty; spf=pass smtp.mailfrom=me@linux.beauty; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1657542513; s=zmail; d=linux.beauty; i=me@linux.beauty; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-Id:Message-Id:In-Reply-To:References:MIME-Version:Content-Transfer-Encoding:Reply-To; bh=/45RwWvpZQ8gxiW9JTrbUVV5LljPR1ktHOujlwlnKxQ=; b=NN43XqsWrzBzau+jKqb4vYqFipSvenjZhL4yn+DPsre33ZTgav2bIdy0QYA6N8rU oNotCfkx7vY9ndsfCNxE+pgGJfoOkxJSqJ34oRF3MWJuTQ2HBYanF+XR0SiEGj69Yg5 N3UGyfNPfQFxA+OJGzZH4WcxXRB28kWFRk+MtFWc= Received: from sh-lchen.ambarella.net (180.169.129.130 [180.169.129.130]) by mx.zohomail.com with SMTPS id 1657542511621198.9230621815609; Mon, 11 Jul 2022 05:28:31 -0700 (PDT) From: Li Chen To: Catalin Marinas , Will Deacon , Rob Herring , Frank Rowand , Andrew Morton Cc: Li Chen , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 4/4] sample/reserved_mem: Introduce a sample of struct page and dio support to no-map rmem Date: Mon, 11 Jul 2022 20:24:54 +0800 Message-Id: <20220711122459.13773-5-me@linux.beauty> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220711122459.13773-1-me@linux.beauty> References: <20220711122459.13773-1-me@linux.beauty> MIME-Version: 1.0 X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220711_052836_538307_1339ECBD X-CRM114-Status: GOOD ( 20.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Li Chen This sample driver shows how to build struct pages support to no-map rmem. Signed-off-by: Li Chen Change-Id: Ie78494fa86fda40ceb73eab3b8ba505d0ad851a1 --- samples/Kconfig | 7 ++ samples/Makefile | 1 + samples/reserved_mem/Makefile | 2 + samples/reserved_mem/rmem_dio.c | 116 ++++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+) create mode 100755 samples/reserved_mem/Makefile create mode 100755 samples/reserved_mem/rmem_dio.c diff --git a/samples/Kconfig b/samples/Kconfig index b0503ef058d3..d83ba02ec215 100644 --- a/samples/Kconfig +++ b/samples/Kconfig @@ -6,6 +6,13 @@ menuconfig SAMPLES if SAMPLES +config RESERVED_MEM_DIO + tristate "Build example reserved mem dio support" + depends on OF_RESERVED_MEM_DIO_SUPPORT + help + Build kernel space sample module to show how to add struct + page and dio support to reserved memory. + config SAMPLE_AUXDISPLAY bool "auxdisplay sample" depends on CC_CAN_LINK diff --git a/samples/Makefile b/samples/Makefile index 087e0988ccc5..106a386869eb 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for Linux samples code +obj-$(CONFIG_RESERVED_MEM_DIO) += reserved_mem/ subdir-$(CONFIG_SAMPLE_AUXDISPLAY) += auxdisplay subdir-$(CONFIG_SAMPLE_ANDROID_BINDERFS) += binderfs obj-$(CONFIG_SAMPLE_CONFIGFS) += configfs/ diff --git a/samples/reserved_mem/Makefile b/samples/reserved_mem/Makefile new file mode 100755 index 000000000000..a4f5c8bc08dc --- /dev/null +++ b/samples/reserved_mem/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_RESERVED_MEM_DIO) += rmem_dio.o diff --git a/samples/reserved_mem/rmem_dio.c b/samples/reserved_mem/rmem_dio.c new file mode 100755 index 000000000000..ffb3395de63c --- /dev/null +++ b/samples/reserved_mem/rmem_dio.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Sample driver for reserved memory with struct page and dio support. + * + * wsps is abbr for with struct page support + * + * Copyright (C) 2022 Li Chen + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * dts example + * rmem: rmem@1 { + * compatible = "shared-dma-pool"; + * no-map; + * size = <0x0 0x20000000>; + * }; + * perf { + * compatible = "example,rmem"; + * memory-region = <&rmem>; + * }; + */ + +static struct reserved_mem *rmem; + +static int rmem_wsps_open(struct inode *inode, struct file *filp) +{ + return 0; +} + +static int rmem_wsps_release(struct inode *inode, + struct file *filp) +{ + return 0; +} + +static int rmem_wsps_mmap(struct file *file, + struct vm_area_struct *vma) +{ + return reserved_mem_dio_mmap(file, vma, rmem); +} + +static const struct file_operations rmem_wsps_remap_ops = { + .owner = THIS_MODULE, + .open = rmem_wsps_open, + .release = rmem_wsps_release, + .mmap = rmem_wsps_mmap, +}; + +static struct miscdevice rmem_wsps_miscdev = { + .minor = MISC_DYNAMIC_MINOR, + .name = "rmem_wsps", + .fops = &rmem_wsps_remap_ops, +}; + +static int rmem_wsps_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + void *vaddr; + int ret; + + ret = misc_register(&rmem_wsps_miscdev); + if (ret) { + dev_err(dev, "%s: misc_register failed, %d\n", __func__, ret); + return -ENODEV; + } + + rmem = get_reserved_mem_from_dev(dev); + if (!rmem) { + dev_err(dev, "%s: failed to find reserved\n", __func__); + return -ENODEV; + } + + vaddr = reserved_mem_memremap_pages(dev, rmem); + if (IS_ERR_OR_NULL(vaddr)) + return PTR_ERR(vaddr); + + return 0; +} + +static const struct of_device_id rmem_dio_match[] = { + { + .compatible = "example,rmem", + }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, rmem_dio_match); + +static struct platform_driver rmem_wsps_driver = { + .probe = rmem_wsps_probe, + .driver = { + .name = "rmem_wsps", + .of_match_table = rmem_dio_match, + }, +}; + +static int __init rmem_wsps_init(void) +{ + return platform_driver_register(&rmem_wsps_driver); +} + +module_init(rmem_wsps_init); +MODULE_LICENSE("GPL");