From patchwork Thu Aug 17 12:59:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: zhaotianrui X-Patchwork-Id: 136030 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp1493737vqi; Fri, 18 Aug 2023 08:43:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF23KaXysggbyeerx0l33XQlumxIqdC0MLgqzgZm2m6LdeS6goM/iMfOo0VsWT3QkwhO7+a X-Received: by 2002:a17:906:31d9:b0:99b:bbe:e232 with SMTP id f25-20020a17090631d900b0099b0bbee232mr2388053ejf.68.1692373393970; Fri, 18 Aug 2023 08:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692373393; cv=none; d=google.com; s=arc-20160816; b=Jz1XhVsNoylJT8rbIwMCw5J9+WUGBCUyDG9w1Bfzyux5jzf/bp7/wDxVCzNeFwmQaO grUVqSzygaX3vTyzTL2a/djtl/PrIunFGD/3uiqzgCVC1vTY/OiZyFC4PICJGGCehhOc wk+4FbwUPQGMtNdEDeh6mWBnp+BvVoKWDnqBECOvy1PvuFvMJkXRlyAmnpTUtnr0uPAd u9S6iuFYe09Vd90TIYlSuyXJtcjMNoG6cRWB49qxv5ltfwlTWb3/4LWanWU+QvoxWA2l eyQK5OCL7CiMwaZhAudprSg2KqReIquDYBqtVKYLCG9FoABZf+ScayvMbvkDd264LPPj tpBA== 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=SsYeNTXdUDPXZ/N1KdW/9dOE9bYvOzjQsNXxsXYsEV8=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=sCiAVtBk2Mof3xliBw0eUXIsIF+knL/yrGsZacxMl2Iaiqk6qat2AwWOIk5BD8Q2+i uIXA/6JUpKPSty4vmlbrL+KhCVvPwSZEWw9kisjQJK2RfjlGztP0X+jleW5aPdzszEuD l8yrSz5K2oWP9I1Oc6zz9wq9qPSS9w0Jj+FZ3zGiv1kPP6xq7uWXyVvG3Kw9bohl7mpa sZT8ZcMvECNR18aZcuL134jlfxoHTa6odotS3dKzi2NHkn3f5EGVJoXzCp2goMi6DLex 6+o+BLergWkcBQNstVIT8MuvLQ4ZuPlH4exoDnzxQPHoPY3tG0uAxb3PuWR6xUcmET/u GQ0A== 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 c4-20020a17090603c400b0099b7a166716si1474504eja.245.2023.08.18.08.42.48; Fri, 18 Aug 2023 08:43:13 -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 S1351092AbjHQNAV (ORCPT + 99 others); Thu, 17 Aug 2023 09:00:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351106AbjHQNAI (ORCPT ); Thu, 17 Aug 2023 09:00:08 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7752F30D1; Thu, 17 Aug 2023 06:00:06 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8AxqOjOGd5kVoYZAA--.16433S3; Thu, 17 Aug 2023 20:59:58 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxniPIGd5kmchcAA--.55665S19; Thu, 17 Aug 2023 20:59:58 +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 Subject: [PATCH v19 17/30] LoongArch: KVM: Implement virtual machine tlb operations Date: Thu, 17 Aug 2023 20:59:38 +0800 Message-Id: <20230817125951.1126909-18-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230817125951.1126909-1-zhaotianrui@loongson.cn> References: <20230817125951.1126909-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 X-CM-TRANSID: AQAAf8BxniPIGd5kmchcAA--.55665S19 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774582124085127959 X-GMAIL-MSGID: 1774582124085127959 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 | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 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..0bcbd80ac631 --- /dev/null +++ b/arch/loongarch/kvm/tlb.c @@ -0,0 +1,34 @@ +// 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) +{ + 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); + 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); +}