Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2325248rdh; Tue, 26 Sep 2023 21:54:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGZEgpp1c05Yvbw0VWK+tIj6ycArO5t9tf8fL4dPmm5N7LpyYozULol6AeHg71Fw8z2szcX X-Received: by 2002:a17:902:ecd2:b0:1c4:29dd:2519 with SMTP id a18-20020a170902ecd200b001c429dd2519mr712670plh.67.1695790444829; Tue, 26 Sep 2023 21:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695790444; cv=none; d=google.com; s=arc-20160816; b=hoffCVpGpH7nvtAVB+7N741R+BJH95UDNIX960THu5IeurbUcTJFA7PToJL7hdfrda WMmNuo3Y39BXF7Wf242JnAHwWGPb70pgevxQ1bQQtVMaQ6fdkI7ABJQlY3BRFsg/gv1p qbhMdayA92iiZnMpDzWCRaaImh7XCGnxkVPrr227DnDHNckNa257ShRl8Fc0GLNI5sMs WaDByLi3wxnihaTlg0GVcscaJqjmo+33JsNhpbuqFEKYcSl0dMt+D3BO+jUT6ifjEnGI 2P4fCYm1vGoogjAeR8JjjOWwsF7+wv6/jf89qkReT9essIZbIak2FYQv7MTy/6/3eaOU 8//A== 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; bh=eUTk6RLjzLIPQB4UY3rp79qJA8VdZXP3B7of8N+NJKw=; fh=DndB7O6DTG6Sgonrk2zkDJR5MPyE/Qek5uYuwsra5zw=; b=lLTGY2WLT0y5WbyJNwcT+TCn0uPCl3fbrT7OjyLmJJawFIHpR3fghNkF6ZdzgoAM16 h5b1+6/qHL9CEAHpM3y0kyr8cCsjz0kM7TR+vW0auC/HDkioHQ1XMSCMSahCdaydqvSb q9g5RB/W5E3a02oS4uuwE6PyaR8UDU30UHCdOi13bhYAfjoCc55sw9sh5BcRMyRMBL9T ikjzWet6kmhRDqVFpS/LoANqRidtxI0NJIbiOmKQUrWoGo6MgKmdyR+sLDefVgnJ4Va3 tok1D7kZVbhPJUxTQs4o5Zl0kGDwQpKqWfK/TCYmw2CCCoduDz08lSGNFlV6+eQcU2ln OXhw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id z7-20020a1709027e8700b001c60c5726absi7987409pla.39.2023.09.26.21.54.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:54:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C359B80DEA6E; Tue, 26 Sep 2023 21:22:26 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229670AbjI0EWQ (ORCPT + 99 others); Wed, 27 Sep 2023 00:22:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjI0EVB (ORCPT ); Wed, 27 Sep 2023 00:21:01 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 812761B3; Tue, 26 Sep 2023 20:10:12 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Bx5fAPnRNlVhctAA--.21309S3; Wed, 27 Sep 2023 11:10:07 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxjd4InRNlhZETAA--.42466S15; Wed, 27 Sep 2023 11:10:06 +0800 (CST) From: Tianrui Zhao To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn, Huacai Chen Subject: [PATCH v22 13/25] LoongArch: KVM: Implement virtual machine tlb operations Date: Wed, 27 Sep 2023 11:09:47 +0800 Message-Id: <20230927030959.3629941-14-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230927030959.3629941-1-zhaotianrui@loongson.cn> References: <20230927030959.3629941-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cxjd4InRNlhZETAA--.42466S15 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 21:22:26 -0700 (PDT) Implement LoongArch virtual machine tlb operations such as flush tlb by specific gpa parameter and flush all of the virtual machine's tlbs. Reviewed-by: Bibo Mao Tested-by: Huacai Chen Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/tlb.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 arch/loongarch/kvm/tlb.c diff --git a/arch/loongarch/kvm/tlb.c b/arch/loongarch/kvm/tlb.c new file mode 100644 index 0000000000..02535df6b5 --- /dev/null +++ b/arch/loongarch/kvm/tlb.c @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited + */ + +#include +#include +#include + +/* + * kvm_flush_tlb_all() - Flush all root TLB entries for guests. + * + * Invalidate all entries including GVA-->GPA and GPA-->HPA mappings. + */ +void kvm_flush_tlb_all(void) +{ + unsigned long flags; + + local_irq_save(flags); + invtlb_all(INVTLB_ALLGID, 0, 0); + local_irq_restore(flags); +} + +void kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa) +{ + unsigned long flags; + + local_irq_save(flags); + gpa &= (PAGE_MASK << 1); + invtlb(INVTLB_GID_ADDR, read_csr_gstat() & CSR_GSTAT_GID, gpa); + local_irq_restore(flags); +} -- 2.39.3