Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1815315rwd; Fri, 9 Jun 2023 02:32:51 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kovT03MTItLgmzkXQQ63elXg3SdlgV0FIg//7TK/qsyq8OoISoVfvJh9eXkEPwv6aGLJw X-Received: by 2002:a17:902:d2c9:b0:1b1:b111:dfe8 with SMTP id n9-20020a170902d2c900b001b1b111dfe8mr665301plc.66.1686303170848; Fri, 09 Jun 2023 02:32:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686303170; cv=none; d=google.com; s=arc-20160816; b=CS6dtAVCIXZJCV5F38oq75tRrXhNVMWrK56KU/qcl7W8HOe6av7ttNJ6FWDOfHg+i5 0C8XtrM4XVYNfg1ji/Rv2Zvil4WkVX3lvDpZmMphBoXNRukk/t27ni4avFFWcqZNZ8fo igBdnPvVR3FA/VNt5J+kiMxVk8y9YQb4NAv++mVI95SVGcJZnGlQFjTdx92xXwKJYuxE xc5uVaoO+Mz9oByj86QjqO9mmqmWfg+yfQKDNZao/1xkMuZcMznFI5Q4Xvhw4hjSFJVP QO56VR86Sev/It6AAEnnEnpXF0mPo6Tap7LzsVFaEKC9T1yL3C+yMajXEEhY7Or0QOF0 a4dg== 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=OlN8uB2Qr9aAee3hKYY/1RONpbdheF2xuX59Z1RYZUk=; b=WNu+Hdr6z4R5QzWX22XAjcTf0xzqi0BupPR2jrokk8aA0YChKNN4+9s3LQBaNHWWsh yAdvhZoXh6HTGZjO54DYb8LHkrOBQumV+CCia4ItfxJvuzY43ysPZZyt4wsfIU7fshtB MU1SLqpJmyNWl2ILxdDaYq87wvufMmf9UJSfObVHnPZJpjm/g32eiHjePmkUHn6miumy CyW8KCA60r+wvRHR3NAzRR9TAit0LJtPxPru6NPjcqH2V60bWxF6SEv/oBGE72XrNuM3 +pmk8Ril7evCkO4RPJ7nAotas5OSi+Y/3XGksQyDwuro04CgpjCiCVjGNQVYomzr6nk6 BeGw== 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 m7-20020a170902db0700b001a95babe3c0si2594647plx.371.2023.06.09.02.32.38; Fri, 09 Jun 2023 02:32:50 -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 S241465AbjFIJWQ (ORCPT + 99 others); Fri, 9 Jun 2023 05:22:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240531AbjFIJVo (ORCPT ); Fri, 9 Jun 2023 05:21:44 -0400 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B8FFE65BD; Fri, 9 Jun 2023 02:16:24 -0700 (PDT) Received: from loongson.cn (unknown [10.2.5.185]) by gateway (Coremail) with SMTP id _____8Bx7eoU7IJkAv0AAA--.3064S3; Fri, 09 Jun 2023 17:08:36 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxFOQQ7IJkzHQKAA--.31790S6; Fri, 09 Jun 2023 17:08:35 +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 v13 04/30] LoongArch: KVM: Implement VM related functions Date: Fri, 9 Jun 2023 17:08:06 +0800 Message-Id: <20230609090832.2131037-5-zhaotianrui@loongson.cn> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230609090832.2131037-1-zhaotianrui@loongson.cn> References: <20230609090832.2131037-1-zhaotianrui@loongson.cn> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8DxFOQQ7IJkzHQKAA--.31790S6 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..84554988b4fd --- /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.gpa_mm.pgd = kvm_pgd_alloc(); + if (!kvm->arch.gpa_mm.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