Received: by 2002:ab2:7855:0:b0:1f9:5764:f03e with SMTP id m21csp738093lqp; Wed, 22 May 2024 20:10:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqZ6blSIz8lWsmZ7I72Iuc2OLGrlPNpiqmM/R8oIZK5UoYYc2qYfWCVdXoJNNNL/pSuRYIc/PH/C7XZ4UyXUpro+RwX4hXjEgl9lcMhw== X-Google-Smtp-Source: AGHT+IEGvsqClZCjWtqhGhRqcTgaOzG1XGjSnfa5zcn7QHYdDWdW6+aRbWGWqG5FRPW8MJS9og41 X-Received: by 2002:a25:6f04:0:b0:dc7:4b0a:589 with SMTP id 3f1490d57ef6-df4e0e1e07cmr3754417276.55.1716433854294; Wed, 22 May 2024 20:10:54 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716433854; cv=pass; d=google.com; s=arc-20160816; b=mOb39VY/Z05xc1Kwl+66YwnDNObAaa70RtDvhQLAoNbP3oonDykGjR19O7ngqLskst pgFgwy3cU3E6cGRFhurifcZs/xOSol1VB5ghxGHtBRfOjlVQoPq6fgqJLkUCdkjMDWHr o9egewnRglX1jFXd4CL3YtHgHLd7f6i+xdZewII1r74uHMAVT9ywK4eJ6I5PT/YRBSBp LfYNvvyWOtgBsHqyuYssBRQKidsPX4acCFJioJfaj0GR74hwVdLlqS8mwDwLsjSRQHgj sYjcTq379m9B4eZu9JKTjdBAcrvZRyTgzB5D45/HsUkULJAeYtkar7MMDFWequ0PiOwY 3QvQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Y2wo3y4UNsz0GeLEteqfOqkmqse/M5ohgK2AihkbKqU=; fh=JOrDXAv7dX9lqUsWenmIinruxsV5NNS7FV+l4Q4onAY=; b=yNkvsNeKo1gNshd3jDV9uOs0vhLwyLSEohrqz1JzEnRhghXxTO/hAos912X7VKt7KN kaznQ1U9esl2fp1cTrED2VtJtELmOOQE9sR+TnZRZJ1t7ST4hptyO2p+uoO1NYaTHaAo IWk6mXeG8+j+rsZ+Lc0hI+XH8qIjPuzMqhFibrORNhr+dEGTJ5n4QDZOZwMaxRDU9wUH kSx4UJn7F3OE9eJ1uKEviSxrnnX3UhEojMisNmUuLCo+hKYWX8APO1zi2/pJTERrZatg nTcqMUbGKtxugiujfIy30bKW9MWTE1LY0dGgWne2NXPLtV0b7N76gTlKLBuuzWdSM+yh YoSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-186937-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186937-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43e15949790si104635451cf.377.2024.05.22.20.10.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 20:10:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-186937-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-186937-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-186937-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 042061C2143C for ; Thu, 23 May 2024 03:10:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BFE8613B2B6; Thu, 23 May 2024 03:10:34 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA74CA34; Thu, 23 May 2024 03:10:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716433834; cv=none; b=FoTTWCgRT9OQeqIBjXUlS29QObB6w/eiB/XOFHl/iGOZGTEUgEIRtpuvhJdhan3lupzxEBRsIDAoNuK6PrZdy8ihwF27M4D5swbMI5yViWXR2DlBIZzy0PT5GeC5zkgawEfsT2vX/BgxaFzyOxk6ZcMH88hu8aqVnCrWry4xlAA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716433834; c=relaxed/simple; bh=lBV13ulQ/56Ti/yP9kvxk+BpnJZiDj0HResYl3GulRM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P9+bb9iDXDASjGhBoNm/kCbwYxA+x33qjkO9YuX/e9ltuJZxuYc2i0qgzesIRrmt2DJ73406z00Y+6W8uasLOQZLF24hDkigD7VUdaOHGCmxKzD+WwO8SxrEcHjXQ+Zl7KECYMsnaV7OBG4w1XAPxgCeUz3el2fFJ4tG9dzMerw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [10.2.5.213]) by gateway (Coremail) with SMTP id _____8BxFeigs05mYeQCAA--.2691S3; Thu, 23 May 2024 11:10:24 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxNMWfs05mCEQGAA--.6973S6; Thu, 23 May 2024 11:10:24 +0800 (CST) From: Bibo Mao To: Tianrui Zhao , Huacai Chen Cc: WANG Xuerui , kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] LoongArch: KVM: Add VM LBT feature detection support Date: Thu, 23 May 2024 11:10:23 +0800 Message-Id: <20240523031023.709347-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240523031023.709347-1-maobibo@loongson.cn> References: <20240523031023.709347-1-maobibo@loongson.cn> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:AQAAf8DxNMWfs05mCEQGAA--.6973S6 X-CM-SenderInfo: xpdruxter6z05rqj20fqof0/ X-Coremail-Antispam: 1Uk129KBjDUn29KB7ZKAUJUUUUU529EdanIXcx71UUUUU7KY7 ZEXasCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnUUvcSsGvfC2Kfnx nUUI43ZEXa7xR_UUUUUUUUU== Before virt machine or vcpu is created, vmm need check supported features from KVM. Here ioctl command KVM_HAS_DEVICE_ATTR is added for VM, and macro KVM_LOONGARCH_VM_FEAT_CTRL is added to check supported feature. Now only KVM_LOONGARCH_VM_FEAT_LBT feature is added, in later any new feature can be added if it is used for vmm. Signed-off-by: Bibo Mao --- arch/loongarch/include/uapi/asm/kvm.h | 4 ++++ arch/loongarch/kvm/vm.c | 34 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/include/uapi/asm/kvm.h b/arch/loongarch/include/uapi/asm/kvm.h index 656aa6a723a6..8605ecc27806 100644 --- a/arch/loongarch/include/uapi/asm/kvm.h +++ b/arch/loongarch/include/uapi/asm/kvm.h @@ -91,6 +91,10 @@ struct kvm_fpu { #define KVM_IOC_CSRID(REG) LOONGARCH_REG_64(KVM_REG_LOONGARCH_CSR, REG) #define KVM_IOC_CPUCFG(REG) LOONGARCH_REG_64(KVM_REG_LOONGARCH_CPUCFG, REG) +/* Device Control API on vm fd */ +#define KVM_LOONGARCH_VM_FEAT_CTRL 0 +#define KVM_LOONGARCH_VM_FEAT_LBT 0 + /* Device Control API on vcpu fd */ #define KVM_LOONGARCH_VCPU_CPUCFG 0 #define KVM_LOONGARCH_VCPU_PVTIME_CTRL 1 diff --git a/arch/loongarch/kvm/vm.c b/arch/loongarch/kvm/vm.c index 6b2e4f66ad26..38452bc23f8c 100644 --- a/arch/loongarch/kvm/vm.c +++ b/arch/loongarch/kvm/vm.c @@ -99,7 +99,39 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) return r; } +static int kvm_vm_feature_has_attr(struct kvm *kvm, struct kvm_device_attr *attr) +{ + switch (attr->attr) { + case KVM_LOONGARCH_VM_FEAT_LBT: + return 0; + default: + return -ENXIO; + } +} + +static int kvm_vm_has_attr(struct kvm *kvm, struct kvm_device_attr *attr) +{ + switch (attr->group) { + case KVM_LOONGARCH_VM_FEAT_CTRL: + return kvm_vm_feature_has_attr(kvm, attr); + default: + return -ENXIO; + } +} + int kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg) { - return -ENOIOCTLCMD; + struct kvm *kvm = filp->private_data; + void __user *argp = (void __user *)arg; + struct kvm_device_attr attr; + + switch (ioctl) { + case KVM_HAS_DEVICE_ATTR: + if (copy_from_user(&attr, argp, sizeof(attr))) + return -EFAULT; + + return kvm_vm_has_attr(kvm, &attr); + default: + return -EINVAL; + } } -- 2.39.3