From patchwork Tue Mar 21 03:56:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 72657 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp1575789wrt; Mon, 20 Mar 2023 21:07:16 -0700 (PDT) X-Google-Smtp-Source: AK7set/7EbiJdP0DGufn+jRV2l/dx1PdA/MXxq6UiIiaVtSxGIh0cOyM4fOtxYnVhfcEBF9Dk20c X-Received: by 2002:a17:90a:c244:b0:23a:6be8:9446 with SMTP id d4-20020a17090ac24400b0023a6be89446mr900391pjx.48.1679371636561; Mon, 20 Mar 2023 21:07:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679371636; cv=none; d=google.com; s=arc-20160816; b=u1IVqLU2LqNCIruE8DjcLFwx+LR9zw0V17UmCj+6hA8NagL4oDT89kazRjjAwYczQH zMXGkypeWQvbxFU9SHSUimqSylVwv8cIbFxbNuJh5ZhQ0KI/ayJ6Tbk7LsqaBCrx9opm ZR7s9/0l4QKoZPXzrhYjoYvvaWBMpquXxiYcWShwnVfWOvjucHxsZSd4/14k79H+Zlvm Qn1E4qwAmFL9iPq35VYP33gLDtndxRduAJgCtnax/3/bZUiMIWI23zZy6ZQAgzy5cD3z GjnsJpyGlOYKESlHPLmGsUbiOCQOBMr/tNu0mR+jOH03vawwbXVnAMsI9XtRnRG+ksa3 GHJw== 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=zMRI6a2SXLpjkV2h3gZK1i9HMVDf4wHBM98N9yGOQL4=; b=R5p+IlKuDirKa3DPA51VAHCsNSi+ahb/4Fm+Mz4tCSe4RqdWI60YpKDvlG6VESwUgQ BshhhFJZr1j+C5r2V32H3AZlVNxbu6DO51yFpKYHJFwLJCoqWM6oo+BUR4ypp+D9q+UM iKtlSwbGwLv23OPxP/x3NmTjsOAFVHQRF/Qub0HIklBCXnTh6Dzuz1o/1Hxh7/QivHZ/ hukNAIchAYQU1HhQoakozLbBiz1MiLmgbtXqxGjOfk9Z9TZtVDnxgP/uuEmIxlnNaSpu XPJR4iKucNAv3EDjZAcwea56Y0Gl3Vr3AtBNWVKRF7XixXCpJetzfKBBtCJpkIOicnxT +8xg== 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 d36-20020a17090a6f2700b0023d422d08c6si12539362pjk.27.2023.03.20.21.07.00; Mon, 20 Mar 2023 21:07:16 -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 S230129AbjCUD6M (ORCPT + 99 others); Mon, 20 Mar 2023 23:58:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjCUD5G (ORCPT ); Mon, 20 Mar 2023 23:57:06 -0400 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CB3602DE60; Mon, 20 Mar 2023 20:57:03 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxJPwOKxlklDYPAA--.22514S3; Tue, 21 Mar 2023 11:57:02 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxD78EKxlkQB4IAA--.33942S19; Tue, 21 Mar 2023 11:57:02 +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 Subject: [PATCH v4 17/29] LoongArch: KVM: Implement virtual machine tlb operations Date: Tue, 21 Mar 2023 11:56:39 +0800 Message-Id: <20230321035651.598505-18-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230321035651.598505-1-zhaotianrui@loongson.cn> References: <20230321035651.598505-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8DxD78EKxlkQB4IAA--.33942S19 X-CM-SenderInfo: p2kd03xldq233l6o00pqjv00gofq/ X-Coremail-Antispam: 1Uk129KBjvJXoW7XF1kXF1ktFWUXr1ftF13Arb_yoW8JF4rpF yfurs5Kw4fX3ZrW39xXwn7Wr13Xr4vkF17ZFW3ua4rZrZrtr1vyFnakryDJFWUtayrCr48 W34ftF4jgFWUJwUanT9S1TB71UUUUjJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU bxxFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3wA2ocxC64kIII0Yj41l84x0c7CEw4 AK67xGY2AK021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF 7I0E14v26r4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aV CY1x0267AKxVW8Jr0_Cr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487 Mc804VCY07AIYIkI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VCjz48v1s IEY20_WwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_ JF0_Jw1l42xK82IYc2Ij64vIr41l42xK82IY6x8ErcxFaVAv8VWrMxC20s026xCaFVCjc4 AY6r1j6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCj r7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6x IIjxv20xvE14v26w1j6s0DMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8Jr0_Cr1UMIIF0xvE 42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVW8Jr0_Cr1UMIIF0xvEx4A2js IEc7CjxVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvj4RKpBTUUUUU X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760948793092851397?= X-GMAIL-MSGID: =?utf-8?q?1760948793092851397?= 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 000000000..66e116cf2 --- /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); +}