From patchwork Mon Feb 27 17:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13154056 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 99C98C7EE23 for ; Mon, 27 Feb 2023 17:58:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 92C106B00A9; Mon, 27 Feb 2023 12:58:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DC3D6B00AA; Mon, 27 Feb 2023 12:58:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7305D6B00AB; Mon, 27 Feb 2023 12:58:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 576DB6B00A9 for ; Mon, 27 Feb 2023 12:58:01 -0500 (EST) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 37B681604E1 for ; Mon, 27 Feb 2023 17:58:01 +0000 (UTC) X-FDA: 80513830362.01.7070EDF Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf08.hostedemail.com (Postfix) with ESMTP id 7B124160015 for ; Mon, 27 Feb 2023 17:57:59 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jhpNHFRR; spf=none (imf08.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=1677520679; 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=Nqz7AKc3hPtY/ZHqOcsiEiY49KCNRExEKCVBLCnS/x4=; b=QPx7VOxkStWCrfWfJDP2EhZewKm9mQekQk0l1iIrRoedz/w8VbI/Lyk/EayqhKQIYlf3bc 6zU4F4fi08qCWmWGjsf7cCPufgW+YunlgTT9S953xodlPoPIwUt19ocJ7pmrlbp2xGgiFl 9tKCPptSXFtxpvWITNb+u2S3eNdXIHU= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=jhpNHFRR; spf=none (imf08.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=1677520679; a=rsa-sha256; cv=none; b=yTtV8JLAMjx/5SVRkS6RF8DUfYIjP5Z0kN6GyCUF7S8w1bg9VN3wKZkYz8ij3F2KR/2TxA NUyT9S8+pTizJB56Hxzx5bS2CZoWX7ObeYHhJfRv9gnlliNDMi/SlLU6NRnzE3c4Wa+rVL pki7z8L5eOOMqC5xGiVmmDp8n7AVAs4= 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=Nqz7AKc3hPtY/ZHqOcsiEiY49KCNRExEKCVBLCnS/x4=; b=jhpNHFRRyHy/TpBPFwxYsEg8wh cAfbO9iPyvMMMxJLy9gFVnY64izGm0jMDIyMcKZ2uw2PGuZ2q4Vhzg0zHntzp8duThNZeQAS1EzIj szvUcBMcnPMwi4bKX0LG5dbY91B1UvdO92qBeIFHka3WECGGXsJTlDEI0kcCLKxrJnGnUOahjHtum I0/W48if3Ic2/DQkq4kUN9GQAW0dcN2bsoqvQZUwsWeDY0a33VLnDzWnTu4piJ6pqrf9OxglH7ep7 ERTtDf75judvHo0eNzidtpBMDJ4qO42dkIzfOmIgLUPlai6YSxZnNPHkfegT7ihWcgpZtN+ehHm11 Epy/Hc+g==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWhkv-000IXh-3a; Mon, 27 Feb 2023 17:57:45 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-openrisc@vger.kernel.org Subject: [PATCH v2 16/30] openrisc: Implement the new page table range API Date: Mon, 27 Feb 2023 17:57:27 +0000 Message-Id: <20230227175741.71216-17-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230227175741.71216-1-willy@infradead.org> References: <20230227175741.71216-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mt4skxzqb9xqkt7afuwf1gt6mxkaj8hw X-Rspamd-Queue-Id: 7B124160015 X-HE-Tag: 1677520679-17577 X-HE-Meta: U2FsdGVkX18qAKZy2pHd8rvR4zuIwb+3iwX0gTt3LXM1Oc++bc17b/4ldsaI8bmK5xoBv7IBANAPlRWnDbEiQWnUZwv/Tuv2yM0XiqXip4TLyKno5gty168TXHxBASItliY4EMzOoDsyBscnWhgK56rk6ovRbR2rnziOnHlJlH0wJ02Rg5zvHRAAaUSnXZV9jg1a5k0kyfYwJpR0WvZm0HvDXGYOW3xG2PZvko+IbCaBQLtxHLSmUVLFdnNyFi1orkja31g5IsMUoqYCeQDaj7OzR3jWvomVwPL/eA1ouQ8tmoTzubx58wKMQrl4TKjXCxyvGYoRueLbDQlrbwRk+/HF6UTIheMLGQwht+cuLBJwe8SsiUDFIyLfex6bEPpR4QpsBMvkIM6zBK0DB1nxTeU3eoSDpRf/i2cUnaCT/Q2vPKHtPCmrYd/8PGZsjqIAJrTAlJrt02pODCqK+3L0W4sE15I9S3vLu8ucuh9cemu1DaK1JQZBaf0nwuJSsr8Pv8Eali1EDXAC2mjhdsnkQ+qybKf38Xw/3ikx/ondQfEEUgUHYPerUnJYLExcu9B1b9c/ZluGGA38UDhlaW0TPh7ft8GiMkH9Lrg4XI7czQESpFkyj/hbsMSy5km29stI8bgHK185rnsf/wRZ6JmD1pu2pxPYTpFD8d43qlZ6Bzqg37SWYzx1mfmBpJEVoGaj/0WcVEItzkqyt54gBaXfHU31Kv9vjLIKhIW7JcmP3Bf5a36ToawGmgCcAMpXznp4FfJYkamxn7cx8tCE2eT1NuEZvWsgRLupQq2C8+pN1Ko52RRRfSydXLQNQlnU+ngWMUjxMyle+HoBgoK4eBfgEFacU7OMYZoxoE4eQ0ynpQnIxUmRgmqZqPb2FFm7oscvgiExxxOCZ9uIz20wj9NfpHviy/jbsnb7l3lckfTaWskKco1HE5SK6TOv8W/e9tR355YR3aioSqP95W/rEXA E0Ct4Nwd LpcZtB5KjR8oobEWHx8Xi0NEZcXnB4o2iOaup03ymTrLjcXKoKvkGtKQeoyeCg46Dmo8iAS01OmQoMLauCvWjB8KGY0u3vwYd0eZP5jOQyPVWbWlKz6d5/2Wb9Dztvqku2OYjQ2Km9uyXpjcBBLYg1TX04nuJF0AurLrqDovpnwsT19L2jphyBFnYlSsNLgC9HwgJlGK5Q6GEumGemhJbt8IMdHdsiMvaLqIYQmEzI7AHOtvZvNiYQw/5agfmraz4gW4y/AzzpjhaPZ0UUBxGlk8EFw== 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() 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: 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 | 27 +++++++++++++++++++++----- arch/openrisc/mm/cache.c | 12 ++++++++---- 3 files changed, 37 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..1a7077150d7b 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -46,7 +46,21 @@ 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) + +static inline void set_ptes(struct mm_struct *mm, unsigned long addr, + pte_t *ptep, pte_t pte, unsigned int nr) +{ + for (;;) { + set_pte(ptep, pte); + if (--nr == 0) + break; + ptep++; + pte_val(pte) += PAGE_SIZE; + } +} + +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) + /* * (pmds are folded into pgds so this doesn't get actually called, * but the define is needed for a generic inline function.) @@ -379,13 +393,16 @@ 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_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(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)); + } }