From patchwork Thu Apr 27 07:10:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 88120 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp86126vqo; Thu, 27 Apr 2023 00:13:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7BuvwHrloFmaGUh1aHZmuxK5Dj8oNeOmYCWLBJQBvolDIpf0PYniWLT+qAIxSOWKBYM64k X-Received: by 2002:a05:6a00:2195:b0:627:ea7a:ff46 with SMTP id h21-20020a056a00219500b00627ea7aff46mr1193578pfi.16.1682579635103; Thu, 27 Apr 2023 00:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682579635; cv=none; d=google.com; s=arc-20160816; b=a2S/w6kyZF0pe0anTrxImfNxQT4kvososwDn0MBRyfxxmb7BRrtBlnrdthO7wRvhfE l29lwnZGz807imJwcYHVvR/hXj6u2R5zlzBSTKAHGcNUGBDlwcrHOJ5NqwBKZDr/88nZ XH1cUW7E35cdA4Mi6dykWfHUtKucNqzqU6oNfaGN6Hp7oI3XliHPPtXiVy6SNx3xwGZf GpnzB26YmW2fPzcFCqMaM5SPRYCDGELOea9HLp2d5GVGjPWWNZAtfoqa3pAaqtx5yOhi 7G3qWkl0D8sAzpv3hkOLQ2ZNdksDNZYGXmeEKa75rwQFay6jWfxHpNHIs8yibtQCL+9J ROGw== 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=pPUAVqzxrVaPAu0Mn4fRGc3mFLafEc/2/eskiGpI1FI=; b=ZYYGLVxlRWD7KFPVUf3oeQ/U3bT+BODiN07Cwm7ct06vUfBc0P+ZXBiAhuzmswCkhA 8ZS2ElyxdMrE2C/bUrIL4j3H59RwJvGpCGcYaLhlucjuUwG66vJe+rNvjsxFuXi5KvIS cosoPJ1GAJRMm5QzCWyGHaSOj9c0YF4WNwSukQbMtH2netbHLaSSiFXXkIMhU5LHMSfA uQWP7D0Q8BJFwDDLQqK8JoOivxRwXAYHfXorTwcM7YCkkmwIMfZYCv0ThOwiubFKQ2/U ODqZ0aOsgCUHdJ3O7OXCv2CedtACbXbqYMBcJKkw08tMelecAUPsuQfTht6SvSUO00BV YIew== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w185-20020a627bc2000000b006325314dc81si18836416pfc.290.2023.04.27.00.13.40; Thu, 27 Apr 2023 00:13:55 -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; 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 S243281AbjD0HMr (ORCPT + 99 others); Thu, 27 Apr 2023 03:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243105AbjD0HLU (ORCPT ); Thu, 27 Apr 2023 03:11:20 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C2ECD4487; Thu, 27 Apr 2023 00:11:18 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxDesVIEpkQXQBAA--.2453S3; Thu, 27 Apr 2023 15:11:17 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxtrENIEpksEA+AA--.18906S19; Thu, 27 Apr 2023 15:11:16 +0800 (CST) From: Tianrui Zhao To: Paolo Bonzini Cc: Huacai Chen , WANG Xuerui , Greg Kroah-Hartman , loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Jens Axboe , Mark Brown , Alex Deucher , Oliver Upton , maobibo@loongson.cn, Xi Ruoyao , zhaotianrui@loongson.cn Subject: [PATCH v8 17/30] LoongArch: KVM: Implement virtual machine tlb operations Date: Thu, 27 Apr 2023 15:10:56 +0800 Message-Id: <20230427071109.3367258-18-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230427071109.3367258-1-zhaotianrui@loongson.cn> References: <20230427071109.3367258-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxtrENIEpksEA+AA--.18906S19 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7WrW7Xw4fGF4xGw1xtw43KFg_yoW8JF4kpF yfurs5Gw4fX3ZxW39xXwn7Wr13Xr4vkF17ZFW3ua4rZrZrtr1vyFnakrykJFWUtayrCr48 W34ftF4jgFWUJw7anT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bx8Fc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aV CY1x0267AKxVWxJr0_GcWln4kS14v26r126r1DM2AIxVAIcxkEcVAq07x20xvEncxIr21l 57IF6xkI12xvs2x26I8E6xACxx1l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6x8ErcxFaV Av8VWrMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCY1x0262kKe7AKxVWU AVWUtwCF04k20xvY0x0EwIxGrwCF04k20xvE74AGY7Cv6cx26rWl4I8I3I0E4IkC6x0Yz7 v_Jr0_Gr1l4IxYO2xFxVAFwI0_JF0_Jw1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_tr0E3s1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4UJVWxJr1lIxAIcVCF 04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4UJVWxJr1lIxAIcVC2z280aV CY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0zR9iSdUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764312623037178051?= X-GMAIL-MSGID: =?utf-8?q?1764312623037178051?= Implement LoongArch virtual machine tlb operations such as flush tlb by specific gpa parameter and flush all of the virt machines tlb. Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/tlb.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 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 000000000000..66e116cf2486 --- /dev/null +++ b/arch/loongarch/kvm/tlb.c @@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited + */ + +#include +#include + +int kvm_flush_tlb_gpa(struct kvm_vcpu *vcpu, unsigned long gpa) +{ + preempt_disable(); + gpa &= (PAGE_MASK << 1); + invtlb(INVTLB_GID_ADDR, read_csr_gstat() & CSR_GSTAT_GID, gpa); + preempt_enable(); + return 0; +} + +/** + * 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); +}