Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1899358lqb; Mon, 27 May 2024 00:47:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/mdWdDz7qnWIWgQAAElkT94RXHHoMD2MUm6BqYbJOhbQjoIfONL1DSKpBCScoZVZZeYMoPxtShPdcu1zdjLeIoadr1zQnCgrl+PYYrA== X-Google-Smtp-Source: AGHT+IHtxeoXNNEI6WJ0TJOlR1mTwueFYDQiJwrG7byxcktL9MdOQ58+Uq7Hhfc4/Xg+lHpswGlS X-Received: by 2002:a5d:408d:0:b0:355:4cb:5048 with SMTP id ffacd0b85a97d-3552fe02949mr7250202f8f.43.1716796070136; Mon, 27 May 2024 00:47:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716796070; cv=pass; d=google.com; s=arc-20160816; b=m+2EoZJA6XDDdGxGyVrgc8SdHochPrKESegCK/n/iYQngYR76uFWpUU3pRpZTDq616 Fje8YMWfGB0m+g3r0K3oIZOVlVDbPf2DkwVAXLSCxxeEf8CdaQlmZ94VU8Tw/+eWdrTA Xv7Fv3fzZxYAMjbVcwa6uQZtqLSvpSE7Sh/WrWyvWDMhl257E10VTHuz+rjudNWW4hv6 fUu1ys483Lijfq/u5FyFLxMBqfEz6Rhgu2r+t/36h2ZxujpOFTivNVpRJkV5j3ZmNBeC cChVkCmK9U0U/DCNTv9gd1DpSqVrZSHP32/mHeHzKjQeuFBcdG5ufkO8L54XYLo3G43X bBdQ== 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=YnbxTu82yE7XkhHlUuzwZPr2moljGEiL++0KAJU/reo=; fh=JOrDXAv7dX9lqUsWenmIinruxsV5NNS7FV+l4Q4onAY=; b=JUwlA0o8iedPi+Umkb+DejKNfFwasQcvb3RZmajJIQqPnIE2eLr0qfAH572DzSMDoY 8LMGoGlim1qjAWwXoUYAy9Mz5Y0AxW1CQG0ybf52s5dTthYUGQ/roqSVpAs2xsCEBA2O xFQ+3Py4OYeRgaS5w1FxZFjSKNKn6v8EkbYsCS8pO4Q2Jqz9nmgyEFsHSKUC4IV325yo iLTffXpHHZnljBcXyCt8XzHU2dvRwMmJuwkc+veXy9VOLjfYafHlLhvnNuxekS0cRVNx wNSzF8XLhzq2/sx+dAG2Xj7aiS6OPmxcNNvyNfXcTBt81/PcYVkBc+0VOfKa5UFJUJ6J itiA==; 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-190162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190162-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a626cdd0b43si355278766b.947.2024.05.27.00.47.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 May 2024 00:47:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-190162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=loongson.cn); spf=pass (google.com: domain of linux-kernel+bounces-190162-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-190162-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B93961F21464 for ; Mon, 27 May 2024 07:47:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 963574EB37; Mon, 27 May 2024 07:46:56 +0000 (UTC) Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C31732836A; Mon, 27 May 2024 07:46:53 +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=1716796016; cv=none; b=OVPv1AlCm/Wrc9fIZQ1Wta4UkdiDrDLVVWof+m76mkSQlUwm5ohDXawo6FfMFhTRa4uMfYkibK5xT+x9213RFEK05KECysYqKgIBCr9iisTrVrqsaEb9c91sKKZSElxWqS6iKsblhRIbwJu9HUzmq4/EfjWSSbGWBkVXL1CfazI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716796016; c=relaxed/simple; bh=4YyU3rtnfFX9YrhUnBGT37Ld3wJFK1+xQcIB/PpJnZ0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=YQwQ5pM3+caCB5ohAOYswd7jIAXoAJf9JBTigJBYly8CkDiODaF48W/epjUAYmia9evPUqBnSZdSQBYoqtp4fSUJSfpB9HXF1G+IDGqHJ6DS/tmLBnJ2VdklGvStYBvaQqHX9WfUnUGYLR3o0AANsSq4TNBmgLaC5HERgaFm+Y8= 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 _____8AxW+pmOlRmvB4AAA--.382S3; Mon, 27 May 2024 15:46:46 +0800 (CST) Received: from localhost.localdomain (unknown [10.2.5.213]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxTcdlOlRmHuIKAA--.28594S6; Mon, 27 May 2024 15:46:46 +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 v3 4/4] LoongArch: KVM: Add VM LBT feature detection support Date: Mon, 27 May 2024 15:46:44 +0800 Message-Id: <20240527074644.836699-5-maobibo@loongson.cn> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240527074644.836699-1-maobibo@loongson.cn> References: <20240527074644.836699-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:AQAAf8AxTcdlOlRmHuIKAA--.28594S6 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. Three sub-features relative with LBT are added, in later any new feature can be added if it is used for vmm. The sub-features is KVM_LOONGARCH_VM_FEAT_X86BT KVM_LOONGARCH_VM_FEAT_ARMBT KVM_LOONGARCH_VM_FEAT_MIPSBT Signed-off-by: Bibo Mao --- arch/loongarch/include/uapi/asm/kvm.h | 6 ++++ arch/loongarch/kvm/vm.c | 44 ++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/include/uapi/asm/kvm.h b/arch/loongarch/include/uapi/asm/kvm.h index 656aa6a723a6..ed12e509815c 100644 --- a/arch/loongarch/include/uapi/asm/kvm.h +++ b/arch/loongarch/include/uapi/asm/kvm.h @@ -91,6 +91,12 @@ 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_X86BT 0 +#define KVM_LOONGARCH_VM_FEAT_ARMBT 1 +#define KVM_LOONGARCH_VM_FEAT_MIPSBT 2 + /* 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..09e05108c68b 100644 --- a/arch/loongarch/kvm/vm.c +++ b/arch/loongarch/kvm/vm.c @@ -99,7 +99,49 @@ 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_X86BT: + if (cpu_has_lbt_x86) + return 0; + return -ENXIO; + case KVM_LOONGARCH_VM_FEAT_ARMBT: + if (cpu_has_lbt_arm) + return 0; + return -ENXIO; + case KVM_LOONGARCH_VM_FEAT_MIPSBT: + if (cpu_has_lbt_mips) + return 0; + return -ENXIO; + 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