From patchwork Wed Aug 2 15:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13338341 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 7E2A1C07E8C for ; Wed, 2 Aug 2023 15:14:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D17A0280190; Wed, 2 Aug 2023 11:14:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 858E8280196; Wed, 2 Aug 2023 11:14:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C679280190; Wed, 2 Aug 2023 11:14:15 -0400 (EDT) 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 CD4D0280195 for ; Wed, 2 Aug 2023 11:14:14 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 84446120F9F for ; Wed, 2 Aug 2023 15:14:14 +0000 (UTC) X-FDA: 81079510428.23.9FF3D97 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id 6ED7B40013 for ; Wed, 2 Aug 2023 15:14:11 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=noGvCnhS; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690989252; 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=VNpFvvJuxNncni/NZj8MqUaBRQkp6jW1k1zH+muyRMk=; b=3XzEEwvG/dr4e5rYwQfMa0dAby1n8wGhhuBIg3j3wFDX9jVHyOtuPH7o7EVV7RpFcWXJ5x HyJJ/e0Kv6hTyUEaAmhZ1Rtct2rDEUk8ZMTFJj4PtU+zEUWUl3yb9wyuGus3XMaBFlRybO ufe0OPgJQiR0b6lEA7K+2/6aq5XqFbc= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=noGvCnhS; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690989252; a=rsa-sha256; cv=none; b=Y3QEfFK2Kdbt8HkFIluDFm43lHbM2D6qMcol+sHuGTCxJrtHGREROPOGm0JDeQBgUeNOXs 2O+Wm/GZcpWP8lbrlNvXMALPnBU8PCAHLAtYG4vdRL24/RFViR1KX+dsvOzNmkVaxlqJ8G gDq0WwG1d3Tu/uQM4Ia3vio9zTyn13Q= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=VNpFvvJuxNncni/NZj8MqUaBRQkp6jW1k1zH+muyRMk=; b=noGvCnhS9S4mgWHMRm9TXvx40M TCeYeWtmyAT9uWLfWJpesadFa0pXWjz2gE4OdZD8eTAypBDZqw2iKRpqTjIDZ2avPr0EULQzAyrMz 7bZoL+hXe9Vo93OQj3Ibqe49WWSrxBLT5EMQDTDTSDEZRYIiQHaqnznlVh8bUNDuv205uuSvqY2fS 6kfggKqXVAhQNd4ztc+q6VCyzpJgwellAvJFm0b2AGFrhU66ESrhJ8d9BEnP05Mkg1Nf9Nhlb+5gp z/gnJSLlCGOQQpRSDrZmSty7pBGapaY4WiqyyO6OoAnkGkzw4qFMNjbfufjGXEz6qLpe/zdpo8SDS e17P3+Wg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qRDY9-00Ffj7-05; Wed, 02 Aug 2023 15:14:09 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Guo Ren , Mike Rapoport , linux-csky@vger.kernel.org Subject: [PATCH v6 11/38] csky: Implement the new page table range API Date: Wed, 2 Aug 2023 16:13:39 +0100 Message-Id: <20230802151406.3735276-12-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230802151406.3735276-1-willy@infradead.org> References: <20230802151406.3735276-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6ED7B40013 X-Rspam-User: X-Stat-Signature: b999budqewdixw9ynckhwh9cg77qsbc6 X-Rspamd-Server: rspam01 X-HE-Tag: 1690989251-894519 X-HE-Meta: U2FsdGVkX18eTsrdPCgg2U+0wAu9+SkrWNs9/EwaacPdGGen/O5PhM7fXp7PzP9cJ+fgFhwE+xzlFBICvfWZIf48AoJFhy5Cj1GENxOOGqCOSmqhjNCZQjZ5ICykuDrdXwQ8TBC7HiNgTnL/DB53d/lmcxz9P5R/AXP4jp9fT2Ng0Z/7gHU1Jy5ExpxFtfJeZLejinBQhK0LIYODNdVBhQTUS1+VECGSK/XBcW6IOHIYrHL7U5gusvPo4pO503mSNZwdp/oLHa71qWniH9Xf0zNj8lwClKo8QY23jcQRdnx6kvXDKZcDSAWm5qriB1neR/UDNIwG8Wg443SwMb9YI4bENW9Qj462MgdjwRhElBLFa5hBIegQL5/R3pZHAnnqYmNNVRMNcn0dLLhk4vIkMrD7E4Wqle/hZzSLVg1g2sIrxD9W/fEHH3QR8mNPp2oKRjf419LR4u2e8lq3pjoN0ZKe7OqUE9ZnKZaxErjmCmkzA6BdMUIvcfk4fTSNW6p9cEIm6MQGFCxLK1aLZdFZd2HDP/x5w2S3akweAmhQsY3N5fls6TTabxqQE2jFTunDPkcppSo1PTV6wwKcMWTOPSF8omYWr1c5nPgv5Mftu8/y7s5EL/aPP3sSgQswcX7MVLODTb8j5GPSPwyBrZ0qKfJo4fbBGsfZPQ4oMyfkXsN8jnLpPYrMoAj7vs9rQ3yI84XS0rxuGU35Z2LW6xmx3+GuVJmO9p37leU79UTSFxZKwlAN6umORGZMWBsYp3zoo3008DAXwnxGOVZklMnx9HJanSW1OYpu84Y/tOtxWk1iMMCjgPvmJq8ecQGOX6f3X4PARgEZv0bWRoEqYgMwaW1xAZQFg53xlOOf34PXlksHZXFu406NsJRIn5R/7cIaXTeQSagl/Po58UOpD6KzDj28Ov+5LdEeQKRliinCMCK6qGdyc0M9A7d6zT2SwkL6F+ff9354LyJqY41BzTr rXYFBoEO v3DVOxP4KdC0u+Iks1gpDB66jKOgvxWrcznMJkztymb8daGWzYtN56nq5mVs6BqzSht+DAErFPTIQ0G3PXjf9I5LuYpymHWQlZQJ2JVG2dxPxNGM3mr1bWB8Ss8o3QjJzlu9DNu6LFUgr9dk/hhP9/5iAL+cvlzKwSJmuwu/cRAQFOt59gpmJwtJtOBKfNo6MARswgs+HJDiziDRNw7eRx9MSSfuYgA1w47YLXKi5uWNfjl3AkpXc9G+X7Q== 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: Add PFN_PTE_SHIFT, update_mmu_cache_range() and flush_dcache_folio(). Change the PG_dcache_clean flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Guo Ren Acked-by: Mike Rapoport (IBM) Cc: linux-csky@vger.kernel.org --- arch/csky/abiv1/cacheflush.c | 32 +++++++++++++++++----------- arch/csky/abiv1/inc/abi/cacheflush.h | 2 ++ arch/csky/abiv2/cacheflush.c | 32 ++++++++++++++-------------- arch/csky/abiv2/inc/abi/cacheflush.h | 10 +++++++-- arch/csky/include/asm/pgtable.h | 8 ++++--- 5 files changed, 50 insertions(+), 34 deletions(-) diff --git a/arch/csky/abiv1/cacheflush.c b/arch/csky/abiv1/cacheflush.c index 94fbc03cbe70..171e8fb32285 100644 --- a/arch/csky/abiv1/cacheflush.c +++ b/arch/csky/abiv1/cacheflush.c @@ -15,45 +15,51 @@ #define PG_dcache_clean PG_arch_1 -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(folio_pfn(folio))) return; - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); - if (mapping && !page_mapcount(page)) - clear_bit(PG_dcache_clean, &page->flags); + if (mapping && !folio_mapped(folio)) + clear_bit(PG_dcache_clean, &folio->flags); else { dcache_wbinv_all(); if (mapping) icache_inv_all(); - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } +EXPORT_SYMBOL(flush_dcache_folio); + +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} EXPORT_SYMBOL(flush_dcache_page); -void update_mmu_cache(struct vm_area_struct *vma, unsigned long addr, - pte_t *ptep) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long addr, pte_t *ptep, unsigned int nr) { unsigned long pfn = pte_pfn(*ptep); - struct page *page; + struct folio *folio; flush_tlb_page(vma, addr); if (!pfn_valid(pfn)) return; - page = pfn_to_page(pfn); - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) + folio = page_folio(pfn_to_page(pfn)); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) dcache_wbinv_all(); - if (page_mapping_file(page)) { + if (folio_flush_mapping(folio)) { if (vma->vm_flags & VM_EXEC) icache_inv_all(); } diff --git a/arch/csky/abiv1/inc/abi/cacheflush.h b/arch/csky/abiv1/inc/abi/cacheflush.h index ed62e2066ba7..0d6cb65624c4 100644 --- a/arch/csky/abiv1/inc/abi/cacheflush.h +++ b/arch/csky/abiv1/inc/abi/cacheflush.h @@ -9,6 +9,8 @@ #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 extern void flush_dcache_page(struct page *); +void flush_dcache_folio(struct folio *); +#define flush_dcache_folio flush_dcache_folio #define flush_cache_mm(mm) dcache_wbinv_all() #define flush_cache_page(vma, page, pfn) cache_wbinv_all() diff --git a/arch/csky/abiv2/cacheflush.c b/arch/csky/abiv2/cacheflush.c index 9923cd24db58..d05a551af5d5 100644 --- a/arch/csky/abiv2/cacheflush.c +++ b/arch/csky/abiv2/cacheflush.c @@ -7,32 +7,32 @@ #include #include -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, - pte_t *pte) +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *pte, unsigned int nr) { - unsigned long addr; - struct page *page; + unsigned long pfn = pte_pfn(*pte); + struct folio *folio; + unsigned int i; flush_tlb_page(vma, address); - if (!pfn_valid(pte_pfn(*pte))) + if (!pfn_valid(pfn)) return; - page = pfn_to_page(pte_pfn(*pte)); - if (page == ZERO_PAGE(0)) - return; + folio = page_folio(pfn_to_page(pfn)); - if (test_and_set_bit(PG_dcache_clean, &page->flags)) + if (test_and_set_bit(PG_dcache_clean, &folio->flags)) return; - addr = (unsigned long) kmap_atomic(page); - - dcache_wb_range(addr, addr + PAGE_SIZE); + for (i = 0; i < folio_nr_pages(folio); i++) { + unsigned long addr = (unsigned long) kmap_local_folio(folio, + i * PAGE_SIZE); - if (vma->vm_flags & VM_EXEC) - icache_inv_range(addr, addr + PAGE_SIZE); - - kunmap_atomic((void *) addr); + dcache_wb_range(addr, addr + PAGE_SIZE); + if (vma->vm_flags & VM_EXEC) + icache_inv_range(addr, addr + PAGE_SIZE); + kunmap_local((void *) addr); + } } void flush_icache_deferred(struct mm_struct *mm) diff --git a/arch/csky/abiv2/inc/abi/cacheflush.h b/arch/csky/abiv2/inc/abi/cacheflush.h index a565e00c3f70..9c728933a776 100644 --- a/arch/csky/abiv2/inc/abi/cacheflush.h +++ b/arch/csky/abiv2/inc/abi/cacheflush.h @@ -18,11 +18,17 @@ #define PG_dcache_clean PG_arch_1 +static inline void flush_dcache_folio(struct folio *folio) +{ + if (test_bit(PG_dcache_clean, &folio->flags)) + clear_bit(PG_dcache_clean, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 static inline void flush_dcache_page(struct page *page) { - if (test_bit(PG_dcache_clean, &page->flags)) - clear_bit(PG_dcache_clean, &page->flags); + flush_dcache_folio(page_folio(page)); } #define flush_dcache_mmap_lock(mapping) do { } while (0) diff --git a/arch/csky/include/asm/pgtable.h b/arch/csky/include/asm/pgtable.h index d4042495febc..42405037c871 100644 --- a/arch/csky/include/asm/pgtable.h +++ b/arch/csky/include/asm/pgtable.h @@ -28,6 +28,7 @@ #define pgd_ERROR(e) \ pr_err("%s:%d: bad pgd %08lx.\n", __FILE__, __LINE__, pgd_val(e)) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pmd_pfn(pmd) (pmd_phys(pmd) >> PAGE_SHIFT) #define pmd_page(pmd) (pfn_to_page(pmd_phys(pmd) >> PAGE_SHIFT)) #define pte_clear(mm, addr, ptep) set_pte((ptep), \ @@ -90,7 +91,6 @@ static inline void set_pte(pte_t *p, pte_t pte) /* prevent out of order excution */ smp_mb(); } -#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval) static inline pte_t *pmd_page_vaddr(pmd_t pmd) { @@ -263,8 +263,10 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; extern void paging_init(void); -void update_mmu_cache(struct vm_area_struct *vma, unsigned long address, - pte_t *pte); +void update_mmu_cache_range(struct vm_fault *vmf, struct vm_area_struct *vma, + unsigned long address, pte_t *pte, unsigned int nr); +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) #define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \ remap_pfn_range(vma, vaddr, pfn, size, prot)