Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp9176722rwp; Thu, 20 Jul 2023 00:15:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlHd09WSJ47FTSAdbAxku/XU9kLz0lc6f0/1sACTtu+X/T2w2hE/Stg5IfyNlKEeyJOg9I2V X-Received: by 2002:a05:6a00:1906:b0:668:846b:9b5d with SMTP id y6-20020a056a00190600b00668846b9b5dmr8275365pfi.5.1689837303633; Thu, 20 Jul 2023 00:15:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689837303; cv=none; d=google.com; s=arc-20160816; b=RpYfdIFB+pFtdd/FpFF2NxTqgCcQBBuvDeTrl9NKWwytEuVnkfNIzA/xA6FBWYWDcT UmnSVzFc7baB/V0IdvNO8dW7yuhAtw3QUteb6vxg4lrimhOAGSETTOucHPaVpLdMnkvJ icX3KaDtqrhjJb0Smub8NFp+SYS04qn3unGUwdqoEoTC3PWcjrPa/7ynFViOmqeroUGl uze9yThHVjsxl052h7hk+rpFgsMhexaiIiwJ50VfU2Xe+PdPo+OnRr507a2WpOUvQ7P6 aCkPeiM7X1RqJBdokjZ7ADg2SvVSWXZPAL/pJxWgRgIYLf48lxF4bP/YXMASphvNZtKl TrMA== 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=S0tTA+GUcRZw/ZKKPu6n/9hKnRhRaFhrj5gOsciE21ou9bN1DoqzuYomXnTKngQBbY PeYzsazsFlKR9sKP2uuN4N2i3J/9qv2K2XzcAmV6RrmEHVbhyPVVhk7eoGNMBKE33mzf lFKw+ko1KskoiWEkN5hx4Twry+S34HiLEzxkh/aoobfdUgge77TUEyR8Na57mTm/cIwL NZlYbuAGVhwx3rTIC5N1OPr/4iDNANmNDfWAcHfaYgMc4GZ7CObCzJD/NDq7qIiWDZfC cCZ/G1qTlQ3/gow4fTTrRMaAdty/ttA5WRvNFfwSIlGWYqQVgSOldkoq5j/DBdFrTrlI zVlg== 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 bt27-20020a056a00439b00b0066882062113si407099pfb.9.2023.07.20.00.14.50; Thu, 20 Jul 2023 00:15:03 -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 S230183AbjGTG22 (ORCPT + 99 others); Thu, 20 Jul 2023 02:28:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230115AbjGTG2V (ORCPT ); Thu, 20 Jul 2023 02:28:21 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3FBBF2113; Wed, 19 Jul 2023 23:28:19 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8BxIvAA1LhkIo0HAA--.18416S3; Thu, 20 Jul 2023 14:28:16 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxvM7907hkHU81AA--.16059S6; Thu, 20 Jul 2023 14:28:16 +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 v17 04/30] LoongArch: KVM: Implement VM related functions Date: Thu, 20 Jul 2023 14:27:47 +0800 Message-Id: <20230720062813.4126751-5-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230720062813.4126751-1-zhaotianrui@loongson.cn> References: <20230720062813.4126751-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxvM7907hkHU81AA--.16059S6 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,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