From patchwork Tue Feb 28 21:37:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13155231 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 CE1E1C7EE32 for ; Tue, 28 Feb 2023 21:37:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67F9D6B0080; Tue, 28 Feb 2023 16:37:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 55A556B007D; Tue, 28 Feb 2023 16:37:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3260B6B0073; Tue, 28 Feb 2023 16:37:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id DA9C96B007D for ; Tue, 28 Feb 2023 16:37:44 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 8257FC0C6B for ; Tue, 28 Feb 2023 21:37:44 +0000 (UTC) X-FDA: 80518012848.28.09E1AB9 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf16.hostedemail.com (Postfix) with ESMTP id 8F818180021 for ; Tue, 28 Feb 2023 21:37:42 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=iCk2NHUn; spf=none (imf16.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=1677620262; 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=E51MTWtc4kvJF42CxWT2/h/jjoo3XaciyQ6YJuFHeTk=; b=pRbFi+83j4T5NlLyRI4j/ZOhXSPogXB5JgJXSnmMCDtSynT2Y+2OLJVQgIv6MELlWa4OXw XrcSb2j8Wt0GoITESm2KPcMA58PvdMn0F06ZyBRAZ7uUbdtHBstIsRjBhBcERqqTg3pDwF zmUjbbeH3tlmJp17eV54ih2mbyk0bto= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=iCk2NHUn; spf=none (imf16.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=1677620263; a=rsa-sha256; cv=none; b=hQbe1tC1dOli4PfDzeGUFg7lWb89cyc93glV24HDpbsRcS/7Q7wJF3KtL9aXZFfGBcKv7u zclO5y8bgi77Ctxumni0elw+LqeWSZ176w+GSiaA23lGH1dGhdLFwE1Axgr6NeRhV53WbE wlA6OdjXu1cxEn7Sh0so9pflDgE/mzA= 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=E51MTWtc4kvJF42CxWT2/h/jjoo3XaciyQ6YJuFHeTk=; b=iCk2NHUn77YUnj8VUtpTSTBZhH Q+w0GQqlfXZtxx1tG5dX9wrAN716AEv1qO1lhHaksuKQ2gDTBGbxLmjxh62/lBBBXQtn9d4qUbWg5 NkRL7wrzl5j6R3kWw+oBufEmIYr22w/5Q+KKN8y60jpxgbSFuSNNLfdpdsJF7s9tegSSzI4UORnak fhhuyGUt0d2zOT0wUKY2eUdpx+IXa/eFOY7iQF1aEmB8vAyULmZFwZkbsliWKYWUgMc3+1sT8AUVb bLhDPoZtuF8OvsC4dcr86rSV4aaYqAq6vF+Tn6MItEVVzeAqwYvbvTCpqWMr4K1y4eUUCpXypNmLZ AVvCuoCg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pX7fJ-0018pQ-0n; Tue, 28 Feb 2023 21:37:41 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Dinh Nguyen Subject: [PATCH v3 16/34] nios2: Implement the new page table range API Date: Tue, 28 Feb 2023 21:37:19 +0000 Message-Id: <20230228213738.272178-17-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230228213738.272178-1-willy@infradead.org> References: <20230228213738.272178-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8F818180021 X-Stat-Signature: 1kuagsffi1hqtxaf51j4qx1ydynhyp67 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677620262-135383 X-HE-Meta: U2FsdGVkX1/yptH1rfgcXw6HgX118QfhIWt4iOa9Rfx6uxQJlq3dxPiiwXH3Me6xxyrXAWPyN6qDG/VJI/q4qhmNomaJwsbXGOabC+0i/8Yyc60Eo5ZfAqZqPSdxXrViuO1RpqsbWZrcGl36XhSwUZ44XDldBL4h2BFKoc0h/46jneW8jfD4Yo31TEK3+0zFwlUkqcAYZfx7SlGrO+MjvfME5UH9hK3hMgghrUoJMP2SrgbU2BR4Mgn+8yfXD7zYQod9FyVwomuYIgAJdW7RRnMfFgoKmNn3PxEnOjEjmNfF/WqmU+Lh9rI4knfPYoyFgTORbmw6yEfOMV2/VpraGFZX21AS/UpPAJ03hXqS4HoLk/NReQs2rmicSgNoy+fZcPJE/WDp1eMP3hiU3JGW0eHe6oblMzoMEE4THyXitvNj1tLKNSXZ1duEQm+pbHqoCFXuoiWCBPz90b/SmSLAUyKsDRXYNQm+zf8/YYOI37jNAkNvxxjoeQ8kobbM/w0oaoT9IxFGqUYXfHcuQL5TAPZptVGQc2Ll1ZTpfvZzIQQHKfo8EFT2KUnQKFOh5DXcVWo8dJVCafQJ5b7fzK9q8XIFJScISbc9hiHOTIMISHy1qCw2VA9mRZKMl8KMq5w2AiUQKB41RAOr8lpIJbyjJP1PJUUOvTsDWOFTKw9JeFVfj/Ozn/iyRu17RbdMbI0ObHP41K3bE0FHtrr8IkzQk59H6vd0DyDjec6S7UwnQ91GDyXvRyZTs5LfeVKkmid+Ddhofwn9zN1LKd1R3gpxMQONy1P0nfeJmh5wDe1rWIT67oSoC67jGTybhNB83VyRGJ6zcIwquGd0IxWwG2uu4uGPOEi65TXPC1rr726Qwcxr8UHUB4tvI0x+e5ZxbkFSIMaOMrtAj4ZieyjZJri9VcTNYli/tCQ3DjY5GKriF1VdQX2MEiCHV7ERNsFWGqTITTZD9S98yRDrHCVm0ZY OI8kttZv aJWyBcgcWDx3whaxWl0GJEULQG+OMCw6T/x1cU9EAnxOW+ATWjXP7mjJJ5MiGMDIFIf3/xitDP7mg9D4GYOvU+gklYW73ke2N1lATWslWkK0D8pz8oqhfLnUVdOpEHIQgZyyBhxykvxPqNVFGn2lA5cWqIjt9Brk27n8ObfkdNwzCffFvZDxt0S+I836HkV1nUj5LZxWnqgHDLi5hECAu9J6jF6bn7FNzYCLqka64qRqLCpbd0txX+VOtvYzEsKMNYlR0 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 set_ptes(), update_mmu_cache_range(), flush_icache_pages() and flush_dcache_folio(). Change the PG_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Cc: Dinh Nguyen --- arch/nios2/include/asm/cacheflush.h | 6 ++- arch/nios2/include/asm/pgtable.h | 27 +++++++++---- arch/nios2/mm/cacheflush.c | 61 ++++++++++++++++------------- 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/arch/nios2/include/asm/cacheflush.h b/arch/nios2/include/asm/cacheflush.h index d0b71dd71287..8624ca83cffe 100644 --- a/arch/nios2/include/asm/cacheflush.h +++ b/arch/nios2/include/asm/cacheflush.h @@ -29,9 +29,13 @@ extern void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, unsigned long pfn); #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 void flush_dcache_page(struct page *page); +void flush_dcache_folio(struct folio *folio); +#define flush_dcache_folio flush_dcache_folio extern void flush_icache_range(unsigned long start, unsigned long end); -extern void flush_icache_page(struct vm_area_struct *vma, struct page *page); +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr); +#define flush_icache_page(vma, page) flush_icache_pages(vma, page, 1); #define flush_cache_vmap(start, end) flush_dcache_range(start, end) #define flush_cache_vunmap(start, end) flush_dcache_range(start, end) diff --git a/arch/nios2/include/asm/pgtable.h b/arch/nios2/include/asm/pgtable.h index 0f5c2564e9f5..8a77821a17a5 100644 --- a/arch/nios2/include/asm/pgtable.h +++ b/arch/nios2/include/asm/pgtable.h @@ -178,15 +178,23 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t pteval) +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) { - unsigned long paddr = (unsigned long)page_to_virt(pte_page(pteval)); - - flush_dcache_range(paddr, paddr + PAGE_SIZE); - set_pte(ptep, pteval); + unsigned long paddr = (unsigned long)page_to_virt(pte_page(pte)); + + flush_dcache_range(paddr, paddr + nr * PAGE_SIZE); + for (;;) { + set_pte(ptep, pte); + if (--nr == 0) + break; + ptep++; + pte_val(pte) += 1; + } } +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) + static inline int pmd_none(pmd_t pmd) { return (pmd_val(pmd) == @@ -273,7 +281,10 @@ static inline pte_t pte_swp_clear_exclusive(pte_t pte) extern void __init paging_init(void); extern void __init mmu_init(void); -extern void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *pte); +void update_mmu_cache_range(struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr); + +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) #endif /* _ASM_NIOS2_PGTABLE_H */ diff --git a/arch/nios2/mm/cacheflush.c b/arch/nios2/mm/cacheflush.c index 6aa9257c3ede..471485a84b2c 100644 --- a/arch/nios2/mm/cacheflush.c +++ b/arch/nios2/mm/cacheflush.c @@ -138,10 +138,11 @@ void flush_cache_range(struct vm_area_struct *vma, unsigned long start, __flush_icache(start, end); } -void flush_icache_page(struct vm_area_struct *vma, struct page *page) +void flush_icache_pages(struct vm_area_struct *vma, struct page *page, + unsigned int nr) { unsigned long start = (unsigned long) page_address(page); - unsigned long end = start + PAGE_SIZE; + unsigned long end = start + nr * PAGE_SIZE; __flush_dcache(start, end); __flush_icache(start, end); @@ -158,19 +159,19 @@ void flush_cache_page(struct vm_area_struct *vma, unsigned long vmaddr, __flush_icache(start, end); } -void __flush_dcache_page(struct address_space *mapping, struct page *page) +void __flush_dcache_folio(struct address_space *mapping, struct folio *folio) { /* * Writeback any data associated with the kernel mapping of this * page. This ensures that data in the physical page is mutually * coherent with the kernels mapping. */ - unsigned long start = (unsigned long)page_address(page); + unsigned long start = (unsigned long)folio_address(folio); - __flush_dcache(start, start + PAGE_SIZE); + __flush_dcache(start, start + folio_size(folio)); } -void flush_dcache_page(struct page *page) +void flush_dcache_folio(struct folio *folio) { struct address_space *mapping; @@ -178,32 +179,38 @@ void flush_dcache_page(struct page *page) * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(folio_pfn(folio))) return; - mapping = page_mapping_file(page); + mapping = folio_flush_mapping(folio); /* Flush this page if there are aliases. */ if (mapping && !mapping_mapped(mapping)) { - clear_bit(PG_dcache_clean, &page->flags); + clear_bit(PG_dcache_clean, &folio->flags); } else { - __flush_dcache_page(mapping, page); + __flush_dcache_folio(mapping, folio); if (mapping) { - unsigned long start = (unsigned long)page_address(page); - flush_aliases(mapping, page); - flush_icache_range(start, start + PAGE_SIZE); + unsigned long start = (unsigned long)folio_address(folio); + flush_aliases(mapping, folio); + flush_icache_range(start, start + folio_size(folio)); } - set_bit(PG_dcache_clean, &page->flags); + set_bit(PG_dcache_clean, &folio->flags); } } -EXPORT_SYMBOL(flush_dcache_page); +EXPORT_SYMBOL(flush_dcache_folio); + +void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} +EXPORT_SYMBOL(flush_dcache_folio); -void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +void update_mmu_cache_range(struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { pte_t pte = *ptep; unsigned long pfn = pte_pfn(pte); - struct page *page; + struct folio *folio; struct address_space *mapping; reload_tlb_page(vma, address, pte); @@ -215,19 +222,19 @@ void update_mmu_cache(struct vm_area_struct *vma, * The zero page is never written to, so never has any dirty * cache lines, and therefore never needs to be flushed. */ - page = pfn_to_page(pfn); - if (page == ZERO_PAGE(0)) + if (is_zero_pfn(pfn)) return; - mapping = page_mapping_file(page); - if (!test_and_set_bit(PG_dcache_clean, &page->flags)) - __flush_dcache_page(mapping, page); + folio = page_folio(pfn_to_page(pfn)); + mapping = folio_flush_mapping(folio); + if (!test_and_set_bit(PG_dcache_clean, &folio->flags)) + __flush_dcache_folio(mapping, folio); - if(mapping) - { - flush_aliases(mapping, page); + if (mapping) { + flush_aliases(mapping, folio); if (vma->vm_flags & VM_EXEC) - flush_icache_page(vma, page); + flush_icache_pages(vma, &folio->page, + folio_nr_pages(folio)); } }