Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp931967rwa; Sat, 20 Aug 2022 19:05:49 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+LJ8i/Zw/ux9zb2gIc1BAvmHmH0InUofs+8S4GUrbL8HBYhj1ZcqwQtvvTF6vxDt0Ts3s X-Received: by 2002:a17:903:1248:b0:172:614b:234b with SMTP id u8-20020a170903124800b00172614b234bmr14304598plh.169.1661047548743; Sat, 20 Aug 2022 19:05:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661047548; cv=none; d=google.com; s=arc-20160816; b=l1rQG5G/iF9uPKGFG2mMqZP3QEiHYK1RJxe6ja+xY/YFCcJFOqCa8bvxE3S2vjLzSW nT9eLfiLSHve88J33iUByUKWK8uaK4rEqn5py7hdk5Wx4gItNBZn8LPXyQyuaJ2jbFui 2VMycp5LPhH3jzjgmivS+5Ojd8f1OFL9e8cDuzN07JHZ8BCKmoIHQ1vKXJdnNFuAXJTC jnoe2rZhROBkA+o5ued0AaYugtgtDN0FEogAl0HAQUSaqakkuAhl13x7EAsmwNBJjZIc bleEpaPtiqEs6JAElx4Mfqv9cbWIlP0nwd3KAkaAvwX34Q9GpnY9ZzSafSQEcjacYZXG qE7g== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=VBrnM6CuTzIPpHE+rhpaLE/CGSehyrDcRVlK4nUbzIE=; b=GSmoTl4bPK7i8fg6Ymnn4yyhi6Znl0kd9Wkswv9G++31O3bD3lFfWnUYLJCBwlovGp gn/wG+93/r/bDmajW1qdPejrLzr8wgmRIIFneXYNzM3Iy8Z/547z0Th6d9zdQCdGjhaz jA09lR2BZAmEW2NY8ihNX64JOgDm6hD3kHvHM32ZsYm6aQaXlx90RbBaQYezYAQuJ07p URzKtmkDGftHLrLUn95C/MnPkmIY5v3PkrtR9aAUbn/fAdIyNujiMr/5vvOAiqVAOaFc glV9QI/K7TlpJGERhI1STpSx1tgVbfF3r7X8MXhvKAwUwks70UaGnk8HcGZu0z+JVj+n 8MhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@163.com header.s=s110527 header.b=Mb9kOg0k; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w8-20020a63b748000000b00429fc7c9640si9088348pgt.258.2022.08.20.19.05.19; Sat, 20 Aug 2022 19:05:48 -0700 (PDT) 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=@163.com header.s=s110527 header.b=Mb9kOg0k; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232315AbiHUBlJ (ORCPT + 99 others); Sat, 20 Aug 2022 21:41:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229512AbiHUBlH (ORCPT ); Sat, 20 Aug 2022 21:41:07 -0400 Received: from m12-14.163.com (m12-14.163.com [220.181.12.14]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 22AA8248EF for ; Sat, 20 Aug 2022 18:41:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=VBrnM 6CuTzIPpHE+rhpaLE/CGSehyrDcRVlK4nUbzIE=; b=Mb9kOg0kJpdQYOePnhJGp UlEbwdcMer7mb3X3KIODhbIv7XCGkeSF+eMTjYlQqteZZ3IYsh6b9QIYhQ9MrRxy 84QFZy/cFtdqgNhl4YGuRIrpWJaUVIxpyKGneRcI2/Q2fESloPXD4pkxdzrf11lW KQR+tiD+ueIgNyIOBEjVP0= Received: from whoami-VirtualBox.. (unknown [223.72.91.40]) by smtp10 (Coremail) with SMTP id DsCowAAHhNjQjAFj1eUbCw--.40452S2; Sun, 21 Aug 2022 09:39:29 +0800 (CST) From: Jinyu Tang To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alexandre.ghiti@canonical.com, guoren@kernel.org, akpm@linux-foundation.org, heiko@sntech.de, panqinglin2020@iscas.ac.cn, unnanyong@huawei.com, tongtiangen@huawei.com, anshuman.khandual@arm.com, anup@brainfault.org Cc: atishp@rivosinc.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, falcon@tinylab.org, Jinyu Tang Subject: [RFC PATCH v1] riscv: make update_mmu_cache to support asid Date: Sun, 21 Aug 2022 09:39:26 +0800 Message-Id: <20220821013926.8968-1-tjytimi@163.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: DsCowAAHhNjQjAFj1eUbCw--.40452S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxAFyxGrW8AFyxtr48ZF1UWrg_yoW5Aw4kpF srCws5K3yfGrn3Gry2vrZrur1aqw1vg3WSyFWav390qrsIgFyjgF9xK340vr1rJFyrWFWS kayayr15u3yYv3JanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zM6wunUUUUU= X-Originating-IP: [223.72.91.40] X-CM-SenderInfo: xwm13xlpl6il2tof0z/1tbiYxFkeFaEKrCgNAAAsy X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 The `update_mmu_cache` function in riscv flush tlb cache without asid information now, which will flush tlbs in other tasks' address space even if processor support asid. So add a new function `flush_tlb_local_one_page` to flush local one page whether processor supports asid or not. If asid is supported, this function will use it. Signed-off-by: Jinyu Tang --- arch/riscv/include/asm/pgtable.h | 2 +- arch/riscv/include/asm/tlbflush.h | 2 ++ arch/riscv/mm/tlbflush.c | 11 +++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 7ec936910a96..09ccefa6b6c7 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -415,7 +415,7 @@ static inline void update_mmu_cache(struct vm_area_struct *vma, * Relying on flush_tlb_fix_spurious_fault would suffice, but * the extra traps reduce performance. So, eagerly SFENCE.VMA. */ - local_flush_tlb_page(address); + flush_tlb_local_one_page(vma, address); } static inline void update_mmu_cache_pmd(struct vm_area_struct *vma, diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 801019381dea..120aeb1c6ecf 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -30,6 +30,7 @@ static inline void local_flush_tlb_page(unsigned long addr) #if defined(CONFIG_SMP) && defined(CONFIG_MMU) void flush_tlb_all(void); void flush_tlb_mm(struct mm_struct *mm); +void flush_tlb_local_one_page(struct vm_area_struct *vma, unsigned long addr); void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); @@ -42,6 +43,7 @@ void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, #define flush_tlb_all() local_flush_tlb_all() #define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) +#define flush_tlb_local_one_page(vma, addr) local_flush_tlb_page(addr) static inline void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 37ed760d007c..a2634ce55626 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -64,6 +64,17 @@ static void __sbi_tlb_flush_range(struct mm_struct *mm, unsigned long start, put_cpu(); } +void flush_tlb_local_one_page(struct vm_area_struct *vma, unsigned long addr) +{ + if (static_branch_unlikely(&use_asid_allocator)) { + unsigned long asid = atomic_long_read(&vma->vm_mm->context.id); + + local_flush_tlb_page_asid(addr, asid); + } else { + local_flush_tlb_page(addr); + } +} + void flush_tlb_mm(struct mm_struct *mm) { __sbi_tlb_flush_range(mm, 0, -1, PAGE_SIZE); -- 2.30.2