From patchwork Mon Jun 19 08:32:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 109810 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp2854156vqr; Mon, 19 Jun 2023 01:44:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4TFq2skJrVkkiPHGBLv9JeWuWtlVvsLLTRAohKs7SS3nxA443iJiKwfYkMdayOpyddji8Z X-Received: by 2002:a05:6a00:1804:b0:666:ada0:4b01 with SMTP id y4-20020a056a00180400b00666ada04b01mr355018pfa.32.1687164246129; Mon, 19 Jun 2023 01:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687164246; cv=none; d=google.com; s=arc-20160816; b=rsj2B8TIDpmyc9cYk3dTEdW451r+s37K/CRv8EjWq1Dq+yj4FkBZf91DzGfM7s9Gpp qeXQirgjlzHdA33KJJjNV9Z5d8XdgoLnKw2lEbmSHBVxCPbdDysQ/X6dgyQHy0I40gA6 lam28hY0TeTbhCKKNNWh1TSiwA8xDzFHmS0/M/l5WQMUM4SR5+gLMpMOu0K29p3zwy3j 8W/sufK/RXgIaPQkzpgPhtr2gcPMYJlP2l1CbtZ9VMGaUmCNoigxk4yr3tjDYJwdEXyL Z4fSRkIM9E5Zcr/h1jA5mUSnzUdkoCMhFe0dlSBCq9BzMjHjEhi81LSB9ua8qw/g4b4E Ih5A== 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=fI5khc4BPlH2S+PeYqihlrKKQaHJnpJM0cMIR4gdPnk=; b=i1BzEJDabB8agylWcatMNu5pirI4dkN9GQYRY+jVbyQFA5hYf7A2WbYIpb1uOHWqry 1lAGjr4Om1erhbZQHPyO7Eyv+GjNTMO8Tm9Ng90LB0NgaE8egV7sf+HwpSnO09FPMJzN ZRJdv787WdWfHrmK4PPNRbzVsETQsWPJ/qdT55zOCdlqcV4q4mhuNnE2iQoMs4L7w796 +fx81H9uT8s7BWDaSoGQcFAQwltDnIQbRdTJeAJAz106gaEOYAQsquE1R9hRzXSQg9/o kHyku22quwQg7Lmxpju3vqpfDn4HjqbcQX5eL3vXfpen28pZRz+IkzCy/tBJe7/z/0iC ceRQ== 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 k2-20020aa79722000000b00666aaa3b271si4547063pfg.10.2023.06.19.01.43.54; Mon, 19 Jun 2023 01:44:06 -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 S231138AbjFSIee (ORCPT + 99 others); Mon, 19 Jun 2023 04:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230190AbjFSIdQ (ORCPT ); Mon, 19 Jun 2023 04:33:16 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DBAAA116; Mon, 19 Jun 2023 01:33:13 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8DxyOnEEpBk2ssGAA--.13968S3; Mon, 19 Jun 2023 16:33:08 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxC8q3EpBkAgsgAA--.15169S19; Mon, 19 Jun 2023 16:33:07 +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, tangyouling@loongson.cn Subject: [PATCH v14 17/30] LoongArch: KVM: Implement virtual machine tlb operations Date: Mon, 19 Jun 2023 16:32:42 +0800 Message-Id: <20230619083255.3841777-18-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230619083255.3841777-1-zhaotianrui@loongson.cn> References: <20230619083255.3841777-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxC8q3EpBkAgsgAA--.15169S19 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,SPF_HELO_NONE, 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?1769119936929903831?= X-GMAIL-MSGID: =?utf-8?q?1769119936929903831?= Implement LoongArch virtual machine tlb operations such as flush tlb by specific gpa parameter and flush all of the virt machines tlb. Reviewed-by: Bibo Mao 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 000000000000..3475b76492ad --- /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 + +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); +}