Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp600533ybf; Wed, 26 Feb 2020 19:21:21 -0800 (PST) X-Google-Smtp-Source: APXvYqxks4WZk8pSSJ7NMjrzc0ivT0G1pVdjfznczTTQ78sVtJo6t2UpiVw0zvf1tsFeX1WNgvpH X-Received: by 2002:aca:5dc3:: with SMTP id r186mr1735882oib.137.1582773680891; Wed, 26 Feb 2020 19:21:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582773680; cv=none; d=google.com; s=arc-20160816; b=LpLGf9S4kcmpZMSmc3W2Mhg5KVxQ+ePkFjiMQNNUByq0ye3BPSdY7SqFhVq5lARFLI FTilw86JT9jmdtGe3CFgUC5iM+0opsa5wZXyeOeCeLGlmCnrKgms3+yndkXiWc9cgsly o+BqlAoq4Bbci9oxeEFVkPeUVuRXyC7bCA7P1uMora/qeaSpo9ez0wKmaVBnFSuWOaWw bWIOMhyKk9Nnx4zXwbz8my6Nx3ynKdp4OFmN3JFDpXaeFafbc/P10IEYMyJhVXQmVNHm 2pUNpK7YhGGih7SnkZvn4DJs8o/H9GyuPGpwswXw+xz65MSGWIUrgnCX7fbDltKpas9p 3vhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=r12vN//5nCyTJY2DcEQUvRK3S3KPl6sE/9M5rXaJILU=; b=0+GVt6PJO0XLj3EU9M50R2xxBz+nELXJXf2FNsZwlDxZ3yrnRFAZEkhUNJQux1LkAc 8XoqscXje+j2nnV/Vy/LIDK6Cni+FtTYhlTZh1S2nVHkwgT3uwYsDcuMIaZ+SnF8qF5S GDZuRR4/IRhWqL55LDbdaHWzUcv7Da8zdk3UHPeYy2d5yuEK8lEe1LtNOZHYyp8SA21a S/TZ1FUFeUAUq/UQunQ/g8Qr1xL5ygSwjreiRVB6G+GquFsYHWXmZnMagKx1fB1iRp82 Bpg6kI+9b0hGaoCDSkLNLUcWM0LgKnH8M2x+rQluVnaOWIH6qfI61tu1bJF3SFGVsFud IYFg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si734548otp.273.2020.02.26.19.21.09; Wed, 26 Feb 2020 19:21:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728306AbgB0DUN (ORCPT + 99 others); Wed, 26 Feb 2020 22:20:13 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:10701 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728220AbgB0DUN (ORCPT ); Wed, 26 Feb 2020 22:20:13 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 90D6C3EA773AAD8D60D2; Thu, 27 Feb 2020 11:20:08 +0800 (CST) Received: from huawei.com (10.175.105.18) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Thu, 27 Feb 2020 11:19:59 +0800 From: linmiaohe To: , , , , , , , , , , CC: , , , Subject: [PATCH v2] KVM: X86: deprecate obsolete KVM_GET_CPUID2 ioctl Date: Thu, 27 Feb 2020 11:21:28 +0800 Message-ID: <1582773688-4956-1-git-send-email-linmiaohe@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.105.18] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin When kvm_vcpu_ioctl_get_cpuid2() fails, we set cpuid->nent to the value of vcpu->arch.cpuid_nent. But this is in vain as cpuid->nent is not copied to userspace by copy_to_user() from call site. Also cpuid->nent is not updated to indicate how many entries were retrieved on success case. So this ioctl is straight up broken. And in fact, it's not used anywhere. So it should be deprecated. Suggested-by: Paolo Bonzini Signed-off-by: Miaohe Lin --- arch/x86/kvm/cpuid.c | 20 -------------------- arch/x86/kvm/cpuid.h | 3 --- arch/x86/kvm/x86.c | 16 ++-------------- include/uapi/linux/kvm.h | 1 + tools/include/uapi/linux/kvm.h | 1 + 5 files changed, 4 insertions(+), 37 deletions(-) diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c index b1c469446b07..5e041a1282b8 100644 --- a/arch/x86/kvm/cpuid.c +++ b/arch/x86/kvm/cpuid.c @@ -261,26 +261,6 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, return r; } -int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, - struct kvm_cpuid2 *cpuid, - struct kvm_cpuid_entry2 __user *entries) -{ - int r; - - r = -E2BIG; - if (cpuid->nent < vcpu->arch.cpuid_nent) - goto out; - r = -EFAULT; - if (copy_to_user(entries, &vcpu->arch.cpuid_entries, - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2))) - goto out; - return 0; - -out: - cpuid->nent = vcpu->arch.cpuid_nent; - return r; -} - static __always_inline void cpuid_mask(u32 *word, int wordnum) { reverse_cpuid_check(wordnum); diff --git a/arch/x86/kvm/cpuid.h b/arch/x86/kvm/cpuid.h index 7366c618aa04..76555de38e1b 100644 --- a/arch/x86/kvm/cpuid.h +++ b/arch/x86/kvm/cpuid.h @@ -19,9 +19,6 @@ int kvm_vcpu_ioctl_set_cpuid(struct kvm_vcpu *vcpu, int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu, struct kvm_cpuid2 *cpuid, struct kvm_cpuid_entry2 __user *entries); -int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu, - struct kvm_cpuid2 *cpuid, - struct kvm_cpuid_entry2 __user *entries); bool kvm_cpuid(struct kvm_vcpu *vcpu, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx, bool check_limit); diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ddd1d296bd20..a6d99abedb2c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4295,21 +4295,9 @@ long kvm_arch_vcpu_ioctl(struct file *filp, cpuid_arg->entries); break; } + /* KVM_GET_CPUID2 is deprecated, should not be used. */ case KVM_GET_CPUID2: { - struct kvm_cpuid2 __user *cpuid_arg = argp; - struct kvm_cpuid2 cpuid; - - r = -EFAULT; - if (copy_from_user(&cpuid, cpuid_arg, sizeof(cpuid))) - goto out; - r = kvm_vcpu_ioctl_get_cpuid2(vcpu, &cpuid, - cpuid_arg->entries); - if (r) - goto out; - r = -EFAULT; - if (copy_to_user(cpuid_arg, &cpuid, sizeof(cpuid))) - goto out; - r = 0; + r = -EINVAL; break; } case KVM_GET_MSRS: { diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 4b95f9a31a2f..61524780603d 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1380,6 +1380,7 @@ struct kvm_s390_ucas_mapping { #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state) #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state) #define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2) +/* KVM_GET_CPUID2 is deprecated, should not be used. */ #define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2) /* Available with KVM_CAP_VAPIC */ #define KVM_TPR_ACCESS_REPORTING _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl) diff --git a/tools/include/uapi/linux/kvm.h b/tools/include/uapi/linux/kvm.h index f0a16b4adbbd..2ef719af4c57 100644 --- a/tools/include/uapi/linux/kvm.h +++ b/tools/include/uapi/linux/kvm.h @@ -1379,6 +1379,7 @@ struct kvm_s390_ucas_mapping { #define KVM_GET_LAPIC _IOR(KVMIO, 0x8e, struct kvm_lapic_state) #define KVM_SET_LAPIC _IOW(KVMIO, 0x8f, struct kvm_lapic_state) #define KVM_SET_CPUID2 _IOW(KVMIO, 0x90, struct kvm_cpuid2) +/* KVM_GET_CPUID2 is deprecated, should not be used. */ #define KVM_GET_CPUID2 _IOWR(KVMIO, 0x91, struct kvm_cpuid2) /* Available with KVM_CAP_VAPIC */ #define KVM_TPR_ACCESS_REPORTING _IOWR(KVMIO, 0x92, struct kvm_tpr_access_ctl) -- 2.19.1