From patchwork Mon Feb 27 17:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 62066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2561182wrd; Mon, 27 Feb 2023 09:59:46 -0800 (PST) X-Google-Smtp-Source: AK7set9JhMOX09DjkIRD5VwsO5ef/coUyLhTYbmJANljw13eqchaNqe9RMtZyn0PnfGVe6exZPyM X-Received: by 2002:a17:90b:1d86:b0:237:99b8:4eef with SMTP id pf6-20020a17090b1d8600b0023799b84eefmr116234pjb.9.1677520786159; Mon, 27 Feb 2023 09:59:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677520786; cv=none; d=google.com; s=arc-20160816; b=xzERQwQvWfrAdEH24EbIe10yZCpjNE4KG7YSOFxNgn89iDx7H4cOYqhuS1PHncpLj1 LPPReBxdGfkxXmK0cXjV1zQ/VKxe6CXXahpDU6gPUf7u5jUc7DlTEzV8SHtYAxajNiW0 ITiJeTrsC51HrVWjHdwzRSTX1vWvpQmds4lcpcZvjQVEiRRwqVZKuN9cYbo2n4wGymFT d/vgzB8X3o7Uz/JPxZ/Z30vRHlAUu/C8RqEk5opUs6/JcmWdZfbKePwWQb1ef/4ohQ8+ u1fgQJ6ZuA9/l/b1EFQCeWIECFT1VNpVjrGyFLUNRQQRUeaNaU9pF0OSVgTqwNqHgQnh 73rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fxYZM+dA5j6swMF6gw/nu6/QS6N0if0H8qzTGtI3Nx4=; b=UEvjI0HF6aHlksu3f2VYPKrViwjmQU3O3F00YJusz1Bus370bIzo/4vT9nGaDKgzQF Kb7PXfk91gR9Iim2ceGH7bu6ztk41tGYfb7QW+UU1WwIf6xdUQd4vP98a4gOuQBMwwEG 4oGm7aFV3C8yh5YezO1/OJjyZM+i5UwYNk6YXaVyqizUTU0GBapUCxbQWbEpfitiFDbx tII+uH2obV/qv6sEI0n/+vH4belditIon4tX1SnY2wO7am95rWKACtfhPbbXhXP+E1fK Bj0AXVRlBirROTEPL+ynzOQFwLLjPjbtYsFUvxEpMlC0Mwc/eF9AUkq5VwpRyUGaQYxq KhRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=b1Oo1BaN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j14-20020a17090a738e00b00230ca3efcf3si7613153pjg.158.2023.02.27.09.59.33; Mon, 27 Feb 2023 09:59:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=b1Oo1BaN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230174AbjB0R6H (ORCPT + 99 others); Mon, 27 Feb 2023 12:58:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230083AbjB0R5y (ORCPT ); Mon, 27 Feb 2023 12:57:54 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81FF22448C; Mon, 27 Feb 2023 09:57:47 -0800 (PST) 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=fxYZM+dA5j6swMF6gw/nu6/QS6N0if0H8qzTGtI3Nx4=; b=b1Oo1BaN8LP9ha/JnRRL5DsJ/V EoOvGgwr+jghsnF8bDZmTkXQLjBfuksYjYMyLBXvW/1odjPJlIm3s4dgF9og2c/I7g1bC+56ijwba j7Ta1l/0uPm4WPgpcHC8zMM32aZDUTBtelP6RMHAg4ibMytgguA9LwUh4YsU1mlG7BaHbEm2OcHPy Tl5mglk3oQIHBJxKysycjLijuvERqc9MndGUyA7hGduAhswYpEtS2qbzIYt27c3Q6/Eep2B23yb08 3Gfp5dOlhZxtrrGtnzcENqXnoJYdpS16nFWRBi/hBpg3UPW5TyJkSI+KkSI+Uuz3XlSPWHa9OI7uf lu5QnORw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pWhku-000IXP-G1; Mon, 27 Feb 2023 17:57:44 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org, linux-arch@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Huacai Chen , WANG Xuerui , loongarch@lists.linux.dev Subject: [PATCH v2 11/30] loongarch: Implement the new page table range API Date: Mon, 27 Feb 2023 17:57:22 +0000 Message-Id: <20230227175741.71216-12-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-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759008035837316682?= X-GMAIL-MSGID: =?utf-8?q?1759008035837316682?= Add set_ptes() and update_mmu_cache_range(). It would probably be more efficient to implement __update_tlb() by flushing the entire folio instead of calling it __update_tlb() N times, but I'll leave that for someone who understands the architecture better. Signed-off-by: Matthew Wilcox (Oracle) Cc: Huacai Chen Cc: WANG Xuerui Cc: loongarch@lists.linux.dev --- arch/loongarch/include/asm/cacheflush.h | 2 ++ arch/loongarch/include/asm/pgtable.h | 30 +++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/arch/loongarch/include/asm/cacheflush.h b/arch/loongarch/include/asm/cacheflush.h index 0681788eb474..7907eb42bfbd 100644 --- a/arch/loongarch/include/asm/cacheflush.h +++ b/arch/loongarch/include/asm/cacheflush.h @@ -47,8 +47,10 @@ void local_flush_icache_range(unsigned long start, unsigned long end); #define flush_cache_vmap(start, end) do { } while (0) #define flush_cache_vunmap(start, end) do { } while (0) #define flush_icache_page(vma, page) do { } while (0) +#define flush_icache_pages(vma, page) do { } while (0) #define flush_icache_user_page(vma, page, addr, len) do { } while (0) #define flush_dcache_page(page) do { } while (0) +#define flush_dcache_folio(folio) do { } while (0) #define flush_dcache_mmap_lock(mapping) do { } while (0) #define flush_dcache_mmap_unlock(mapping) do { } while (0) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/asm/pgtable.h index d28fb9dbec59..9154d317ffb4 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -334,12 +334,20 @@ static inline void set_pte(pte_t *ptep, pte_t pteval) } } -static inline void set_pte_at(struct mm_struct *mm, unsigned long addr, - pte_t *ptep, pte_t 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) += 1 << _PFN_SHIFT; + } } +#define set_pte_at(mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1) + static inline void pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep) { /* Preserve global status for the pair */ @@ -445,11 +453,19 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot) extern void __update_tlb(struct vm_area_struct *vma, unsigned long address, pte_t *ptep); -static inline void update_mmu_cache(struct vm_area_struct *vma, - unsigned long address, pte_t *ptep) +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, ptep); + for (;;) { + __update_tlb(vma, address, ptep); + if (--nr == 0) + break; + address += PAGE_SIZE; + ptep++; + } } +#define update_mmu_cache(vma, addr, ptep) \ + update_mmu_cache_range(vma, addr, ptep, 1) #define __HAVE_ARCH_UPDATE_MMU_TLB #define update_mmu_tlb update_mmu_cache