From patchwork Wed Aug 2 15:13:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13338369 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 42B9DC001DF for ; Wed, 2 Aug 2023 15:15:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB2D12801B0; Wed, 2 Aug 2023 11:14:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8A442801AA; Wed, 2 Aug 2023 11:14:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A507F2801B0; Wed, 2 Aug 2023 11:14:35 -0400 (EDT) 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 8AAFE2801AA for ; Wed, 2 Aug 2023 11:14:35 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 654941405E2 for ; Wed, 2 Aug 2023 15:14:35 +0000 (UTC) X-FDA: 81079511310.06.60CAC05 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf21.hostedemail.com (Postfix) with ESMTP id 70A5E1C0026 for ; Wed, 2 Aug 2023 15:14:32 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dy7B6L2U; spf=none (imf21.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=1690989272; 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=hgxbRqC0royFvXDvAgcwEvAWh4810YGjFn56dm1qu5Q=; b=2hXR0b3sFCu/YCghOHtkbzHySGB+ExlliRQFehYrcX94fCHI35X8Ez8nkWKoLsIi1Cz7CH Zp5Xl8lf6MneBU+//lau+f0Cp/aJ+MlRIGbg7CLfgCrNZh+GwsiBYWYGaRKjT2md+j/Cua Vn7z88OJJ3CZDApE4Y1CbTYJlwE7T20= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690989272; a=rsa-sha256; cv=none; b=XQT9PVVxNvSlZi5vMaC+glwPk5LvCwKPy4JhvHb5QBCseGjEQSZfJ3OJnH4cOPJcbJEdMr kDAVQQgCUFMCithh2O89Khgf0J0Qy+lLhgr9kd4Lc4slkDr2uhQvNmW3vSnuwhMB2yCFzg Rh6TKxKpDOrmWLuekOIVyArMp75Nuo8= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dy7B6L2U; spf=none (imf21.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none 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=hgxbRqC0royFvXDvAgcwEvAWh4810YGjFn56dm1qu5Q=; b=dy7B6L2Uktly3yVdII9xfIHzld pOOK5mwHaUrrszwyAz7o54cfZ/ywCxjEXJWjiQ8wtsWMw4SlJUnsZ0NSm0R528zAw2gHXjdVAq1RT x2nkWMde+2js61sxAsvzwZX9rTDXw1xrFGs64JAWLUgZOyVQrPMVtZ0z04s3oMU8034nMixXXmANy 0gP+1Yw9l8QqA6iaQvG4txUwMOYvPALHyiaFMehFkTsCa8lwfDCpZF1x6AAjiE9rUbfYvI5ernLvk Bsap6LZ87zpsd5pdkMdOc0y5B6aUqo9ZZHtAFwk+phV5LRybQnr2+9vvYbX5Yuu2s/CuEk9uIh4mH PIWQ0sgA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qRDYA-00Ffk7-0Z; Wed, 02 Aug 2023 15:14:10 +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, Mike Rapoport , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-openrisc@vger.kernel.org Subject: [PATCH v6 19/38] openrisc: Implement the new page table range API Date: Wed, 2 Aug 2023 16:13:47 +0100 Message-Id: <20230802151406.3735276-20-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: 70A5E1C0026 X-Rspam-User: X-Stat-Signature: sqk7tsudrppn3qf1e4739rxnuxs1jmgc X-Rspamd-Server: rspam03 X-HE-Tag: 1690989272-271697 X-HE-Meta: U2FsdGVkX185qEzpCDUseo0RCR/ZT/MziFZ5C794rv9jLgOO9PJu6ZdYzMoNcln6uzArOBSIZNgkLKJgcelU0Gkdnkl7Phuc9yms5GLSnq3M8sBC2YcHQqPitbmi/SRUwQRb5e0iDHiVamDBY8Zx4X6LzEu/pQWVkawL5FtytgVEvXmGFXadM1cECtf46hcnnghhWa2bbTIfDbAZDdobms+1Dk72JiPCg4+pAC77OcJHNod0npl45RQ9Pabta1l7gOe5OEQ6PrXduXeyd6s1BOHWlldAtCaFpsdd8dOKNZYvTWMgBZF/ujaNWpd9futFfJKKpuAI8c6+V8rsKw6Nq3lL7QaUUoe5JqaqQUbqGmpUdSQAyRmgSswrJ6SUQtJsnzHkCdYU3ZdWx0m3sSdpLYDm4EX7xGr6dB2wy/G22deeuTljAwdgQSmGIkcRj0m3bi1cnqluJcacqn9mhufD/r5n599XaVemEyQZg00/qFb2oNlHtdyi5jIN2RG/YjdBuYPs5P76/27Ixp+GXq+ezCUNAFhakMWEhhYSAX/WCQBYuIBerb9z6mcHjvSPFy0scppPrRHBTiK9OIFIM5pH4VRlj6porFU7+suhHK8csmiv08ZYWt3yxBzp0u58YntwwN31bdMqAxPTlFOfH84LrpxIchGBetcpsMkaRGhpoUOQcmUJVGbygKDrpdAi0E+PjPFKdf6EiuxPZ90oVt5j0+0otkvrLTJ4Va/mq7PpFRyOW3HFkuAd49lIFQ0IiKZLvhC1p83GDJeieJtKfW7adpM/bNz0OQTzIVZe2BkK3dHjVNn3TE1tNR/QsXcJSiqorGe8l6eWC8NayJTjtqn6ItMgq/8aq1LpKcT8Be7Q6PJCyhTF26vG/5jVmbSmIfR14h4ksLkitGDZ1KYrd2psR9BlSbRUIhwyToU0smcEHq3om7mB9fcZU7R34ky3YRk+kzdXyZYcAZq4nLBZ9D4 K54qy79T SthvLHFUO0XaUqR5ZAsYbvQn67Xm2fDM44QLmWNNKm8fxPEI8hqYtDIy4b+OJFq+UZ04GGOIy+Y+FVlek6wZL8xbrKdlRMLM4dqfxsQG5z4EoCpE0NasUW86+119YywprtoQbVbkOSTKJwlUjjgHhoh3o7gy6NWnR4QybBUo4dGObvItyyZJ+uRCZ4kAXg+S3DMtp/FpnkgR4IPuacLhlE1WyGEK4WUlkMldBm/fjE4jgLLnM/mITD6bH5uQY1up9vMpncsfJkm1PSqI= 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_arch_1 (aka PG_dcache_dirty) flag from being per-page to per-folio. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: Jonas Bonn Cc: Stefan Kristiansson Cc: Stafford Horne Cc: linux-openrisc@vger.kernel.org --- arch/openrisc/include/asm/cacheflush.h | 8 +++++++- arch/openrisc/include/asm/pgtable.h | 15 ++++++++++----- arch/openrisc/mm/cache.c | 12 ++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/arch/openrisc/include/asm/cacheflush.h b/arch/openrisc/include/asm/cacheflush.h index eeac40d4a854..984c331ff5f4 100644 --- a/arch/openrisc/include/asm/cacheflush.h +++ b/arch/openrisc/include/asm/cacheflush.h @@ -56,10 +56,16 @@ static inline void sync_icache_dcache(struct page *page) */ #define PG_dc_clean PG_arch_1 +static inline void flush_dcache_folio(struct folio *folio) +{ + clear_bit(PG_dc_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) { - clear_bit(PG_dc_clean, &page->flags); + flush_dcache_folio(page_folio(page)); } #define flush_icache_user_page(vma, page, addr, len) \ diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/asm/pgtable.h index 3eb9b9555d0d..7bdf1bb0d177 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -46,7 +46,7 @@ extern void paging_init(void); * hook is made available. */ #define set_pte(pteptr, pteval) ((*(pteptr)) = (pteval)) -#define set_pte_at(mm, addr, ptep, pteval) set_pte(ptep, pteval) + /* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.) @@ -357,6 +357,7 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) #define __pmd_offset(address) \ (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) +#define PFN_PTE_SHIFT PAGE_SHIFT #define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT) #define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(prot)) @@ -379,13 +380,17 @@ static inline void update_tlb(struct vm_area_struct *vma, extern void update_cache(struct vm_area_struct *vma, unsigned long address, pte_t *pte); -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *pte) +static inline void update_mmu_cache_range(struct vm_fault *vmf, + struct vm_area_struct *vma, unsigned long address, + pte_t *ptep, unsigned int nr) { - update_tlb(vma, address, pte); - update_cache(vma, address, pte); + update_tlb(vma, address, ptep); + update_cache(vma, address, ptep); } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(NULL, vma, addr, ptep, 1) + /* __PHX__ FIXME, SWAP, this probably doesn't work */ /* diff --git a/arch/openrisc/mm/cache.c b/arch/openrisc/mm/cache.c index 534a52ec5e66..eb43b73f3855 100644 --- a/arch/openrisc/mm/cache.c +++ b/arch/openrisc/mm/cache.c @@ -43,15 +43,19 @@ void update_cache(struct vm_area_struct *vma, unsigned long address, pte_t *pte) { unsigned long pfn = pte_val(*pte) >> PAGE_SHIFT; - struct page *page = pfn_to_page(pfn); - int dirty = !test_and_set_bit(PG_dc_clean, &page->flags); + struct folio *folio = page_folio(pfn_to_page(pfn)); + int dirty = !test_and_set_bit(PG_dc_clean, &folio->flags); /* * Since icaches do not snoop for updated data on OpenRISC, we * must write back and invalidate any dirty pages manually. We * can skip data pages, since they will not end up in icaches. */ - if ((vma->vm_flags & VM_EXEC) && dirty) - sync_icache_dcache(page); + if ((vma->vm_flags & VM_EXEC) && dirty) { + unsigned int nr = folio_nr_pages(folio); + + while (nr--) + sync_icache_dcache(folio_page(folio, nr)); + } }