From patchwork Mon Jul 10 20:43:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307636 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 17BDEEB64D9 for ; Mon, 10 Jul 2023 20:44:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 35E838E0026; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30DC58E001B; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1AFB88E0026; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 0B2428E001B for ; Mon, 10 Jul 2023 16:44:11 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D399316023D for ; Mon, 10 Jul 2023 20:44:10 +0000 (UTC) X-FDA: 80996879460.07.7007C23 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf14.hostedemail.com (Postfix) with ESMTP id C8D7E10001C for ; Mon, 10 Jul 2023 20:44:08 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LstrdFs9; dmarc=none; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689021849; a=rsa-sha256; cv=none; b=SCW/Hvxzq0C0McVxfxICm+6vqWfUKAgjPC4qsD53Bq9XCxtGLa9qBaIo30gyU717k1XHO2 aQH4BQZDTPY+/nOP2szG7nyjl+doMwmXVbotTdTfUt8/Ji9AwKIfBPjhAdnIiBdqkqm2Gm tzdFZCA1QgkqalrnroX7RKRVzSqcJQk= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LstrdFs9; dmarc=none; spf=none (imf14.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689021849; 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=LkNLbBSWedZKYyPfN1pGuZQo5tC7Q714M9YkIGeohI8=; b=NBcr69aWpfxcXzfmBQ4xIR6kneRZ0Uy/HgL+Hp5/lKjrWMxgIB9sPqERj5zKZtxUlH0jAR MjsOtKsHgt+5z3caVmuFJCg4O+shpSeeBpO0d+AZdnhwFIYfUZeVJm0LJAE8sUfi5NLhtt d+w4zwVckQ8TDASqy0XQaKu9NT3AWJ4= 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=LkNLbBSWedZKYyPfN1pGuZQo5tC7Q714M9YkIGeohI8=; b=LstrdFs9UlKVnGLIEf/uAPHDQu pOcMiPmZPEJbQXp8d+wByOWnPshMUaJOCjYNfNldJhUqffupXq2qr8ZW2cIEmvQSvBMZBk4WZTWwx D+h9KKwgOJoSQv5oq9816YjDOxDh8LKWQTqQLYLMInOiJTbUxKGZjexoGn7JzrNc1CLeVnITSE7n7 jz4V7oRq0/Gll+bVW0g0QVkL+PoDSNhsfLO9kWfztiTTfuVf7WndNMFG5cpOgSme0XkSl0Xiox2R5 bU0RGm7kycVY3av7mjwaL0GDR6eAER8KIgTNLG4IrpJTHfaEWOCIWBqgqOZHA39mj7MRaicZpYCdR TEEB/kQQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjT-00Eupe-BF; Mon, 10 Jul 2023 20:43:43 +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 v5 19/38] openrisc: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:20 +0100 Message-Id: <20230710204339.3554919-20-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230710204339.3554919-1-willy@infradead.org> References: <20230710204339.3554919-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: C8D7E10001C X-Stat-Signature: paqz7rxwu9w36fnoy3znscbg7zknyh96 X-HE-Tag: 1689021848-159070 X-HE-Meta: U2FsdGVkX1/8AFa4aY95Kg6Hl2+QxGzFRsid1ZD75ge+BlpdLHuu6PqvQ6Ic1LJklHjqacJBX6DBMX8w9XA9/e/V8DdQPjBBbtSzTegR17A2fp4p/b1YKrfcTu5t9ruYutsr1hD+srmz9UrxSUcEE3OxC5mIUWzho+98NXCaAoxB9JApoETGiihJoa/aiJZWzjlBVk2ekXqzs/2ReI5FC5gfKhN3GC/XO6TxSGhqJho9Ier6ye94F8wLhCUTyKlqnEscNvuXs/S2sFr+bFeiGbtZQEdZDbS8/xiKvwdHA3dkhAaaiJAvORK/zC9qLPqRrN59qe4KDRH4EGrG/hiU9iJxBJrpgFsp+2B2y7Z+Cko0zND60odIjmiDtqpRSearaIV6heNMd/Z1IJvk3p9wkBW6mqdN5tQnGwMy5VIYKweaOKngkpkcB25UtFNFAfZ3qX5RjKm2UvPgCCQLxJKCQR+GrwTHlr80L5B01GlPm6DgVqBLBvEUAXkaaTR8ICVZa+JKTxd2MXavci+m1fD3Ec80yC0JoEmkkYkML+TsC0gOYRKwJht7moODMkuhU9T2/66/8HxEv5PywL17XNIGu82N6pqRXrv1qkTRtZS+8j9CKrBJIi5qrPh4taaKXfwKr15GRehAF7HrwWrspxZ8y8aROtc5Hy4ES+2a8A0VfqVDUf8srDsgTuuWJ0QnNpKjaiz7VLEHkMyALTHtH+I31NmDrLmd9+eDZQV1oV/kQ0VNe7nIcBBez/iHz7PQEoMBkVvz9F5Yr03OVqxp6+OaRxysYLK5dDnLPkgzSdH3trL2A1zPn4Nv0JdEF4VrIqhbtIKOrZtWRXqszgN6DCJWrxjnqJ3EuTe28vvdYq2eA8DPSnm+Ex0luDaPL0pKs475Li/gXDI4gVS5F9n/m3DcXKPYO4YnjhlDWKvT61Yo9V2FwoaE61gN5182flHeMt+Vx/iGUi7w1K1rPKeNvvh MTdgijVo i/VJqoDPVn/6VfIhBbluOIeCFu2HJydiIUc0kKf/1xKwxiufHNNtnM9pVl8ml+4gWKcLYO6rcotfOND4671glh3xEyGjPuW44Ds/CJqBLeZthXjM70g0+5wASLKOj49/CyjbAphhYK7nucP2B0lGa7XV2I8H2vqYxe9RJN1vBMdzOpKhrO4wQZBgrxnmGJxFslmVge0U42awCV0BseC/FHp5ZsRBDFYhp+SDRBI6hBfZilvZBjizncoV8b/9riGZuaEKSI/5rYcBkLz0= 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)); + } }