From patchwork Mon Jul 10 20:43:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13307603 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 596D2EB64DA for ; Mon, 10 Jul 2023 20:43:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 952758E0008; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8DA7B8E0007; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72CC88E0008; Mon, 10 Jul 2023 16:43:47 -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 4E6298E0001 for ; Mon, 10 Jul 2023 16:43:47 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F05CB16024D for ; Mon, 10 Jul 2023 20:43:46 +0000 (UTC) X-FDA: 80996878452.24.260E292 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf04.hostedemail.com (Postfix) with ESMTP id 3B32C40009 for ; Mon, 10 Jul 2023 20:43:44 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dGHT51LM; dmarc=none; spf=none (imf04.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=1689021825; 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=5gt+3Xe9De1Yff1oJDu3SmVusJ4BF3xtLN8hDiFU6E0=; b=0mMuzwhJ7eVJPbKjan3gitgZ8hvAwfkEGn+XJ6RVbi7dNvrq00Mrxm8jDW6fRCaLlTgnS+ 1d7PrPGffV01Y/723XIouQgntzUZzdPJDzhCBKy3u4Fn0/lI35KayOaPnSTJb3Kypx4pOE zpm0DMvZ5GmhhFvzR+BJvlYvJuErXeY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=dGHT51LM; dmarc=none; spf=none (imf04.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=1689021825; a=rsa-sha256; cv=none; b=FQLcQQHZM2bcHmRGX0EfM1YdYHnacJm+SLbvHTWgpXT0kiOQlDgXalmpbZnJJfKPoKpf5P E7Wclsc9A0+jiXQCC6lXEvxqPZ1AqlpC9mY/CcaUfkMzu8Rcd5Pzq5cI5+Uny9oqa/PuVl e7YPQQw4hL8y8i/rOkQhLgca1D8ktaU= 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=5gt+3Xe9De1Yff1oJDu3SmVusJ4BF3xtLN8hDiFU6E0=; b=dGHT51LMU6SlQXei6rkZXyExJi p1aFtkyf4pEDSYgYiZ/k2gJQpuEtvPQuWOrzfE7rqxmCY0lOiBf3KNuaByGkvb2JKVrxNOYDk8HKJ x2pM848J4epxGkcJGcefxsEHJvwSCEM8aHiumMhIWD4J9OGQsVh1o0gsIDgaK84JaxtSxWw0T+CiQ NnV5uJ372hxvssehPX0qG4WVDx0cELUoDYmiZtlfScLXJ1WqS0llR5Pe7y5/k9vifGRLPvc4zSYwB M6HPvdZ3lv6t+Uhrhjy1GY7lCRbQfjPaADhpVyNLhzYU2zL/7VO3wz1rFSy0dNv1bMtGw9xIMEZ2k GaMyVtIg==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qIxjS-00Eup5-Kh; Mon, 10 Jul 2023 20:43:42 +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 , linux-ia64@vger.kernel.org Subject: [PATCH v5 13/38] ia64: Implement the new page table range API Date: Mon, 10 Jul 2023 21:43:14 +0100 Message-Id: <20230710204339.3554919-14-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-Rspamd-Queue-Id: 3B32C40009 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 56yoi5e573g19gitjaskqgtumnnbufha X-HE-Tag: 1689021824-443703 X-HE-Meta: U2FsdGVkX1+w3GPtNTgOGNPYjFpX0NL+fWHvfunsc15zc8Ifp4kdmhZs58cJrA9AQ27pfp8uNYlkv/6af62N93Am7aFrUKjDlSuCo6gVtpp8OT0qtRS5YdK+6TRZpybz2w9b2cBsczAcbh4Fj6sGIZT3QhO/vtp1ZWrF4LrkwyNpPdHNMFbSMRz4cWlMjLZcpeP6p72xFGHO7HkV5yU4xG6OlTZw/+oI+c4wSAlmih36kBKxxSao/u36zPfMmc0rzmZwbGn35MZkM6SsIOAn4Ap6Cb61l3bp41tOPDfY5/q1vn8K+buf1G7uzzAKQFLBGWXyLy0UvA8MvbX0lYQJgu+oq/NQ6PlD2mTrs2vuiqmTKZdUAWzV9NgG6GOFTlkJzQhn7025fnOU5t4FKe1gXJobEgdoVr9T80bMZDQ/pUQJvGHp0HaYFQBGHjheiuRTmMNKFxEO6P7DWbqKMPPP9XOWNDYIL6sZEsAEGgL8os+pTg7dR86hE81BGwsyexcFcfcC9EB8zXp9meEniLb2cwHhVhpshjov5esoMHluugPkuv32NrxhYSg+31BLa3xO/ul56k5tK+ufRgI8xqQzNsvwRUie6A5MiQ0GNFmUQetEqvmr9yi24A/XqewAag5hUyrKiyIFt9oHhYjBy0BcivqcZz5TJivn6ExfOFNp46d9S7XvHVHUubXG6JUg5U5wI/pQqY08SejlN5lScNrUkik6yWRR8D61ZqBPGmpc4ZjUhL2xwBjpQacG0dK1zs17esfnrYeGM53wMLqy2IZZ58sf3SlX4V3lUAFWVr6uFExkjGVOAfrZPkSSvC7DrFm9yfCr07px9H7x2pcmkZYjN07dWBfsle6Fhixdkwup/Wxeq2X6Bmlt7W3T71md/jrS1gcCUWnWeodcPguGu5hSi4E1B2XYdXWDeVDoFbiVlfXk1LA6Pkd6ScW/mAmtxCfHs8jxkSuxJ3XH7D8T6PK XJBrg6P7 eN2ouK8zTM9TJnZVDXwOGxIhT6HsBxABSTwDwzAVrSLuQJf8cWmQHnkmSLOL6a3JQGLPDYo+7VYf/1/TEdlrHkIcmea/Y76Wbb/vmPXCtrFQatprhfRLS/W2kcvKIyWY/eTs+GyC0pRA5Y8llGsllF7uI5U3Jyagx4jDBuu9DjW3pm4pubjNFPLnjxYBG+7CNFLOJOVNCbHAzFmo32XGmhkW1u23ElsfdJnfpriqWMWNseMoHzQvAaFgmIw== 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_clean) flag from being per-page to per-folio, which makes arch_dma_mark_clean() and mark_clean() a little more exciting. Signed-off-by: Matthew Wilcox (Oracle) Acked-by: Mike Rapoport (IBM) Cc: linux-ia64@vger.kernel.org --- arch/ia64/hp/common/sba_iommu.c | 26 +++++++++++++++----------- arch/ia64/include/asm/cacheflush.h | 14 ++++++++++---- arch/ia64/include/asm/pgtable.h | 4 ++-- arch/ia64/mm/init.c | 28 +++++++++++++++++++--------- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/arch/ia64/hp/common/sba_iommu.c b/arch/ia64/hp/common/sba_iommu.c index 8ad6946521d8..48d475f10003 100644 --- a/arch/ia64/hp/common/sba_iommu.c +++ b/arch/ia64/hp/common/sba_iommu.c @@ -798,22 +798,26 @@ sba_io_pdir_entry(u64 *pdir_ptr, unsigned long vba) #endif #ifdef ENABLE_MARK_CLEAN -/** +/* * Since DMA is i-cache coherent, any (complete) pages that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ -static void -mark_clean (void *addr, size_t size) +static void mark_clean(void *addr, size_t size) { - unsigned long pg_addr, end; - - pg_addr = PAGE_ALIGN((unsigned long) addr); - end = (unsigned long) addr + size; - while (pg_addr + PAGE_SIZE <= end) { - struct page *page = virt_to_page((void *)pg_addr); - set_bit(PG_arch_1, &page->flags); - pg_addr += PAGE_SIZE; + struct folio *folio = virt_to_folio(addr); + ssize_t left = size; + size_t offset = offset_in_folio(folio, addr); + + if (offset) { + left -= folio_size(folio) - offset; + folio = folio_next(folio); + } + + while (left >= folio_size(folio)) { + set_bit(PG_arch_1, &folio->flags); + left -= folio_size(folio); + folio = folio_next(folio); } } #endif diff --git a/arch/ia64/include/asm/cacheflush.h b/arch/ia64/include/asm/cacheflush.h index 708c0fa5d975..eac493fa9e0d 100644 --- a/arch/ia64/include/asm/cacheflush.h +++ b/arch/ia64/include/asm/cacheflush.h @@ -13,10 +13,16 @@ #include #define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE 1 -#define flush_dcache_page(page) \ -do { \ - clear_bit(PG_arch_1, &(page)->flags); \ -} while (0) +static inline void flush_dcache_folio(struct folio *folio) +{ + clear_bit(PG_arch_1, &folio->flags); +} +#define flush_dcache_folio flush_dcache_folio + +static inline void flush_dcache_page(struct page *page) +{ + flush_dcache_folio(page_folio(page)); +} extern void flush_icache_range(unsigned long start, unsigned long end); #define flush_icache_range flush_icache_range diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h index 21c97e31a28a..4e5dd800ce1f 100644 --- a/arch/ia64/include/asm/pgtable.h +++ b/arch/ia64/include/asm/pgtable.h @@ -206,6 +206,7 @@ ia64_phys_addr_valid (unsigned long addr) #define RGN_MAP_SHIFT (PGDIR_SHIFT + PTRS_PER_PGD_SHIFT - 3) #define RGN_MAP_LIMIT ((1UL << RGN_MAP_SHIFT) - PAGE_SIZE) /* per region addr limit */ +#define PFN_PTE_SHIFT PAGE_SHIFT /* * Conversion functions: convert page frame number (pfn) and a protection value to a page * table entry (pte). @@ -303,8 +304,6 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) *ptep = pteval; } -#define set_pte_at(mm,addr,ptep,pteval) set_pte(ptep,pteval) - /* * Make page protection values cacheable, uncacheable, or write- * combining. Note that "protection" is really a misnomer here as the @@ -396,6 +395,7 @@ pte_same (pte_t a, pte_t b) return pte_val(a) == pte_val(b); } +#define update_mmu_cache_range(vmf, vma, address, ptep, nr) do { } while (0) #define update_mmu_cache(vma, address, ptep) do { } while (0) extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c index 7f5353e28516..b95debabdc2a 100644 --- a/arch/ia64/mm/init.c +++ b/arch/ia64/mm/init.c @@ -50,30 +50,40 @@ void __ia64_sync_icache_dcache (pte_t pte) { unsigned long addr; - struct page *page; + struct folio *folio; - page = pte_page(pte); - addr = (unsigned long) page_address(page); + folio = page_folio(pte_page(pte)); + addr = (unsigned long)folio_address(folio); - if (test_bit(PG_arch_1, &page->flags)) + if (test_bit(PG_arch_1, &folio->flags)) return; /* i-cache is already coherent with d-cache */ - flush_icache_range(addr, addr + page_size(page)); - set_bit(PG_arch_1, &page->flags); /* mark page as clean */ + flush_icache_range(addr, addr + folio_size(folio)); + set_bit(PG_arch_1, &folio->flags); /* mark page as clean */ } /* - * Since DMA is i-cache coherent, any (complete) pages that were written via + * Since DMA is i-cache coherent, any (complete) folios that were written via * DMA can be marked as "clean" so that lazy_mmu_prot_update() doesn't have to * flush them when they get mapped into an executable vm-area. */ void arch_dma_mark_clean(phys_addr_t paddr, size_t size) { unsigned long pfn = PHYS_PFN(paddr); + struct folio *folio = page_folio(pfn_to_page(pfn)); + ssize_t left = size; + size_t offset = offset_in_folio(folio, paddr); - do { + if (offset) { + left -= folio_size(folio) - offset; + folio = folio_next(folio); + } + + while (left >= (ssize_t)folio_size(folio)) { set_bit(PG_arch_1, &pfn_to_page(pfn)->flags); - } while (++pfn <= PHYS_PFN(paddr + size - 1)); + left -= folio_size(folio); + folio = folio_next(folio); + } } inline void