Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp896177rwb; Wed, 7 Dec 2022 06:21:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7OXey/Kog5QFkqgYjR/c5LJncp7TCKG5N44UUfGgZTSBqwCNNptY0M0jECXEtnhAP2eqbj X-Received: by 2002:a05:6402:13cf:b0:46d:83ea:44e6 with SMTP id a15-20020a05640213cf00b0046d83ea44e6mr722158edx.179.1670422915774; Wed, 07 Dec 2022 06:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670422915; cv=none; d=google.com; s=arc-20160816; b=bGXyUQANmVcgmfh3y8+IiOdtB4wwoIGEqQk61nZABILZyeWmAyj4EGiCL1s9xfjDbJ mf4uBonlbauVcufpFDBLnXeNcGK22HjEIcV09fsbebxDMTuzDJi+gUo67EimZsuLP2ZB dbh9zySSaslRlmOOG2YL0ljXU1dPcpjB3oO2M+e+RBa9Es+sxgivTBXd/q4Co2HrDCnC RG1Z68QIXqIdKIpYVS/8JmjA5YPL2dFHu+K2WEsTGDrdt+/kQOrpXvcLeiKsAsW+F4oV jqG74PDv69g6sV+9POd7uIIDu/oZh8g91DiDKw2LCCNyaYCw57xJ8VNXTkY0HxG8ZOiL g+PA== 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; bh=3NarVeOiEU2MKb/Jh/ahPMpA3SxVvUpVj5eADvkHXss=; b=ApjTRGwnnrAbfh3KGNKB5ZB4zCoLMu9pKvCZoGUQ9WGHPpffnaGPTtKLsqV31Owu48 yIN9YPmLzbLAf+ROpPYnWya51Fqo4jr2KqnH93khTdJKnIuG+Y8w3yJ2udoDoGMmWxug 2RqqlGCsYi0wgs2hlpc/MuHcy27hBuCw43qXPjFgENUz0s7cmwjekXvS1XkRBUaXPe5n RU7yqDXOqSnENmU9RIca2RoSWH55UyOwUGfip0lZxgJrYKiTkhHlT9aTincxTnslgyWS QjSnDupzgL21GCFr8GuBSCEFve4z3d/ay2SrNVBl857rvs59xWqtasJIGQgF7yl2num9 pLDg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hb17-20020a170907161100b007c0fa2e0f95si7106556ejc.167.2022.12.07.06.21.34; Wed, 07 Dec 2022 06:21:55 -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; 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 S229961AbiLGOKZ (ORCPT + 75 others); Wed, 7 Dec 2022 09:10:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229867AbiLGOKX (ORCPT ); Wed, 7 Dec 2022 09:10:23 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA0C3F0D for ; Wed, 7 Dec 2022 06:10:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6ED49B81E05 for ; Wed, 7 Dec 2022 14:10:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1FCEC433C1; Wed, 7 Dec 2022 14:10:16 +0000 (UTC) From: Huacai Chen To: Huacai Chen Cc: loongarch@lists.linux.dev, Xuefeng Li , Guo Ren , Xuerui Wang , Jiaxun Yang , linux-kernel@vger.kernel.org, Huacai Chen , Rui Wang Subject: [PATCH] LoongArch: mm: Fix huge page entry update for virtual machine Date: Wed, 7 Dec 2022 22:10:43 +0800 Message-Id: <20221207141043.1600863-1-chenhuacai@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS 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 In virtual machine (guest mode), the tlbwr instruction can not write the last entry of MTLB, so we need to make it non-present by invtlb and then write it by tlbfill. This also simplify the whole logic. Signed-off-by: Rui Wang Signed-off-by: Huacai Chen --- arch/loongarch/mm/tlbex.S | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/arch/loongarch/mm/tlbex.S b/arch/loongarch/mm/tlbex.S index d8ee8fbc8c67..58781c6e4191 100644 --- a/arch/loongarch/mm/tlbex.S +++ b/arch/loongarch/mm/tlbex.S @@ -10,6 +10,8 @@ #include #include +#define INVTLB_ADDR_GFALSE_AND_ASID 5 + #define PTRS_PER_PGD_BITS (PAGE_SHIFT - 3) #define PTRS_PER_PUD_BITS (PAGE_SHIFT - 3) #define PTRS_PER_PMD_BITS (PAGE_SHIFT - 3) @@ -136,13 +138,10 @@ tlb_huge_update_load: ori t0, ra, _PAGE_VALID st.d t0, t1, 0 #endif - tlbsrch - addu16i.d t1, zero, -(CSR_TLBIDX_EHINV >> 16) - addi.d ra, t1, 0 - csrxchg ra, t1, LOONGARCH_CSR_TLBIDX - tlbwr - - csrxchg zero, t1, LOONGARCH_CSR_TLBIDX + csrrd ra, LOONGARCH_CSR_ASID + csrrd t1, LOONGARCH_CSR_BADV + andi ra, ra, CSR_ASID_ASID + invtlb INVTLB_ADDR_GFALSE_AND_ASID, ra, t1 /* * A huge PTE describes an area the size of the @@ -287,13 +286,11 @@ tlb_huge_update_store: ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED) st.d t0, t1, 0 #endif - tlbsrch - addu16i.d t1, zero, -(CSR_TLBIDX_EHINV >> 16) - addi.d ra, t1, 0 - csrxchg ra, t1, LOONGARCH_CSR_TLBIDX - tlbwr + csrrd ra, LOONGARCH_CSR_ASID + csrrd t1, LOONGARCH_CSR_BADV + andi ra, ra, CSR_ASID_ASID + invtlb INVTLB_ADDR_GFALSE_AND_ASID, ra, t1 - csrxchg zero, t1, LOONGARCH_CSR_TLBIDX /* * A huge PTE describes an area the size of the * configured huge page size. This is twice the @@ -436,6 +433,11 @@ tlb_huge_update_modify: ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED) st.d t0, t1, 0 #endif + csrrd ra, LOONGARCH_CSR_ASID + csrrd t1, LOONGARCH_CSR_BADV + andi ra, ra, CSR_ASID_ASID + invtlb INVTLB_ADDR_GFALSE_AND_ASID, ra, t1 + /* * A huge PTE describes an area the size of the * configured huge page size. This is twice the @@ -466,7 +468,7 @@ tlb_huge_update_modify: addu16i.d t1, zero, (PS_HUGE_SIZE << (CSR_TLBIDX_PS_SHIFT - 16)) csrxchg t1, t0, LOONGARCH_CSR_TLBIDX - tlbwr + tlbfill /* Reset default page size */ addu16i.d t0, zero, (CSR_TLBIDX_PS >> 16) -- 2.31.1