Received: by 2002:a05:6358:700f:b0:131:369:b2a3 with SMTP id 15csp1671376rwo; Wed, 2 Aug 2023 19:30:11 -0700 (PDT) X-Google-Smtp-Source: APBJJlEykxHYX8oe7dE1NbHFcvtIhN00VvK5UgZy5nNiSwd9+5yC8u3jYdnoqY61YDSjA6aKNjyc X-Received: by 2002:a17:906:530c:b0:99b:f4b2:6f13 with SMTP id h12-20020a170906530c00b0099bf4b26f13mr6451552ejo.1.1691029810904; Wed, 02 Aug 2023 19:30:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691029810; cv=none; d=google.com; s=arc-20160816; b=Exg8z3sr7QB88YUzeQj7HFHnyAJ/s7FGOq+i4pFmEp4YRAJmlxXY3RK+l5DatnqPPv jhEdiBJzn4nKw/18tWH3D/VRLx1xLQJeS9P1hhEQ7dmzw7JbJVJIukMP1YOhQfqPF/yg h2Rt5Cg3aENuUEX4euZSAWRFE61lBJh+Oqaw4c5BRWXHb/Tw8rjwL13lRXDd5ia3/uiG RH2xP1WoH+9nVBQRgZzcieAEMGUiJnZkallf3Ln3FF+bj5jN0MYiwmhUezauN0Jc09io 91gGJU9vQpUqiihKI77rcnYVsMa8HTVlDhPgyqF7vGF7lPXWbSksz9UT+bgSSRKrHGi/ Llgw== 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=GBEYPGMMykejTvuEzS6IpauUTE7Uu25F0Ayi+XP+suE=; fh=vBXozhnPXwSB3DJhjnKWz3f6luaN/KxHDpM6/QeZg4o=; b=Tks5utkuN3NRwE9a30MAwFTd12XanC3S6ixiSTdjNDnMxPa+oJJf2rNYzFMMOX6mFU CI8sVM8fhkoUbFCTHaZjlFfo+Te7ooVQYPV75BhnpAXOFjq2ROpmxyuPxkPbo+Y08d1R vUqBiTCxxJ3UISLLz+Z/g2ZrXEoHpP39qZALqMu42Qgf9zPlmTh1TODTn4REWEjCC3fM olDAISazoxaNPEEztrThtxcFguc5TsDcio83zIm+IpIrFwwAoFqwox/WqkKYMXcFUEPY 2nCUUKps0UQI9StXHtOHVA6Ps9VkEoJPd8iurHArWD0j5B9tVgqYtkpT2bqePrmuoRQa /B4g== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a170906524d00b009935121ecd7si7419811ejm.639.2023.08.02.19.29.44; Wed, 02 Aug 2023 19:30:10 -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 S232377AbjHCCWB (ORCPT + 99 others); Wed, 2 Aug 2023 22:22:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232145AbjHCCVu (ORCPT ); Wed, 2 Aug 2023 22:21:50 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D2335E73; Wed, 2 Aug 2023 19:21:48 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Cx5_E6D8tkr2gPAA--.36000S3; Thu, 03 Aug 2023 10:21:46 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cx_c4yD8tk8oNGAA--.51268S6; Thu, 03 Aug 2023 10:21:45 +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 v18 04/30] LoongArch: KVM: Implement VM related functions Date: Thu, 3 Aug 2023 10:21:12 +0800 Message-Id: <20230803022138.2736430-5-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230803022138.2736430-1-zhaotianrui@loongson.cn> References: <20230803022138.2736430-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8Cx_c4yD8tk8oNGAA--.51268S6 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 Implement LoongArch VM operations: Init and destroy vm interface, allocating memory page to save the vm pgd when init vm. Implement vm check extension, such as getting vcpu number info, memory slots info, and fpu info. And implement vm status description. Reviewed-by: Bibo Mao Signed-off-by: Tianrui Zhao --- arch/loongarch/kvm/vm.c | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 arch/loongarch/kvm/vm.c diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c new file mode 100644 index 000000000000..bde78f063305 --- /dev/null +++ b/arch/loongarch/kvm/vm.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2020-2023 Loongson Technology Corporation Limited + */ + +#include + +const struct _kvm_stats_desc kvm_vm_stats_desc[] = { + KVM_GENERIC_VM_STATS(), +}; + +const struct kvm_stats_header kvm_vm_stats_header = { + .name_size = KVM_STATS_NAME_SIZE, + .num_desc = ARRAY_SIZE(kvm_vm_stats_desc), + .id_offset = sizeof(struct kvm_stats_header), + .desc_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE, + .data_offset = sizeof(struct kvm_stats_header) + KVM_STATS_NAME_SIZE + + sizeof(kvm_vm_stats_desc), +}; + +int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) +{ + /* Allocate page table to map GPA -> RPA */ + kvm->arch.pgd = kvm_pgd_alloc(); + if (!kvm->arch.pgd) + return -ENOMEM; + + kvm_init_vmcs(kvm); + kvm->arch.gpa_size = BIT(cpu_vabits - 1); + return 0; +} + +void kvm_arch_destroy_vm(struct kvm *kvm) +{ + kvm_destroy_vcpus(kvm); + _kvm_destroy_mm(kvm); +} + +int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) +{ + int r; + + switch (ext) { + case KVM_CAP_ONE_REG: + case KVM_CAP_ENABLE_CAP: + case KVM_CAP_READONLY_MEM: + case KVM_CAP_SYNC_MMU: + case KVM_CAP_IMMEDIATE_EXIT: + case KVM_CAP_IOEVENTFD: + case KVM_CAP_MP_STATE: + r = 1; + break; + case KVM_CAP_NR_VCPUS: + r = num_online_cpus(); + break; + case KVM_CAP_MAX_VCPUS: + r = KVM_MAX_VCPUS; + break; + case KVM_CAP_MAX_VCPU_ID: + r = KVM_MAX_VCPU_IDS; + break; + case KVM_CAP_NR_MEMSLOTS: + r = KVM_USER_MEM_SLOTS; + break; + default: + r = 0; + break; + } + + return r; +} + +int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) +{ + return -ENOIOCTLCMD; +} -- 2.39.1