From patchwork Wed Sep 27 03:09:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 145146 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2378110vqu; Tue, 26 Sep 2023 21:32:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJuC5sos2yVBxra8k41e6OjPams1RcQgvZMVR+EzGy6QeuanIoqDQTParnCnup/o6ucLdD X-Received: by 2002:a05:6871:207:b0:1b7:4521:14b6 with SMTP id t7-20020a056871020700b001b7452114b6mr1198338oad.5.1695789167207; Tue, 26 Sep 2023 21:32:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695789167; cv=none; d=google.com; s=arc-20160816; b=VKyqaUaLKCWrh0Avp6n2u8O/LMwIBpoxNel8VOx53xBdhjjQByp1GhxXMLWufLEl2U m4LAg3C1BF51BewbhaQf/1ykUV6B0LB8FMyAzvJGDO7UQ46Kz38rJvZcXUPW5zPnzSgW fgmaluWuj5JRbWXNg4UbWT7tCTQDWCFDy1ANvXLdCuWIvwntm2THbwEToZHSGlLAUeYz Nj3u4l+Gzb9u0n/mDXyBZ1gyospEODQA/qeiAXom0fuIBU+XYrWWWzlFxUjOdEuvWFTz mt1TUC0QLSQVZvLrCaKipIKZnhPjBw8fZ1mnqn7eiZ47t282NqP9/1Uy3WSCRmtW/9jk qBfg== 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 Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w20-20020a63fb54000000b00578b4edf57esi14304580pgj.797.2023.09.26.21.32.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 21:32:47 -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 6EDAA81D6A83; Tue, 26 Sep 2023 21:22:37 -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 S229804AbjI0EWR (ORCPT + 26 others); Wed, 27 Sep 2023 00:22:17 -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 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:37 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778163821899095226 X-GMAIL-MSGID: 1778163821899095226 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); +}