Received: by 10.223.185.116 with SMTP id b49csp1041279wrg; Wed, 21 Feb 2018 11:03:32 -0800 (PST) X-Google-Smtp-Source: AH8x227Ebb0bpeZ/269WNFpe4kbkj0wlFZGm9y1uLfRPzEeY5yUQwreO47TK1TJSXXoNBtx2nfjw X-Received: by 2002:a17:902:bb89:: with SMTP id m9-v6mr4012883pls.423.1519239812684; Wed, 21 Feb 2018 11:03:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519239812; cv=none; d=google.com; s=arc-20160816; b=H77qnqrnh7JdMFwbCGTucdTefAYxbQX4Dibch36u7+U8HpScgBScogNoAWEXg6T609 MaGUCR+X9U5BWIEswQ5Nwd2s4oC9PWb6kCLJcq09Lo59MeJtgCxbcrJBMizCKOk+ZM2U VDNmlFgFJ0hGivD6C/iYRdptu4a/vVsOkYuF7WoK/8TQXiag3twrTnBBj1WQbo1Rd4+8 94xWjOSyrJSMQtCJa5b0vw3U1pgjKT8baVAZJ3snl/6LfEm1fc0CurphDo4eN/PQlIgh Xcl8yGp9Ns0GFL7xkJMFwYdwWew535yFchahNt1iQDRwRuxwR+D4Y3EkGPHl1KgfSYlr Rifw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:arc-authentication-results; bh=A0FfYRDnrMwsP2elyNHaavVuqGQA9rcJSVLqV/64BvU=; b=sZ8s/KSwx9gzRoYtOI8LFyEgfnuP0hXEe7WHXD34OO6W9qhgco7p/0qJLnug1mycl1 d32whZykfZJkRLW+q7mXkMDhT7hvOjH6TgPfQ3dErFnOn+yjEOiAJ3P260Z+7dLxamyY WBmZdVsj+ulGdE0pS2xOfNbKl0AP5zKh9Wjh0d6acsmdS6zS+DxH+8XKTBe02FrwIclM HmudcJ18+F8fec7nVZ/W6/FfRe/w7iPdlh5ET+A4YrUF/jwMWlR24tK5UA/Xk4KSpgTc ZAw++r84gXvfpVfo1n8Cz1wik1mgyVfiaGq+Q1KEqcNKJ7e/GbJqRZLJ2BMoIaIFIj0k yDuw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l26si1789512pfj.401.2018.02.21.11.03.17; Wed, 21 Feb 2018 11:03:32 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933127AbeBUQgc (ORCPT + 99 others); Wed, 21 Feb 2018 11:36:32 -0500 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:50386 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932674AbeBUQga (ORCPT ); Wed, 21 Feb 2018 11:36:30 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 578AA407806F; Wed, 21 Feb 2018 16:36:30 +0000 (UTC) Received: from [10.36.118.60] (unknown [10.36.118.60]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C846E10073BD; Wed, 21 Feb 2018 16:36:28 +0000 (UTC) Subject: Re: [PATCH v2 1/2] KVM: x86: Add a framework for supporting MSR-based features To: Tom Lendacky , x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Joerg Roedel , Borislav Petkov , Thomas Gleixner , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <20180215231156.31016.79657.stgit@tlendack-t1.amdoffice.net> <20180215231206.31016.78914.stgit@tlendack-t1.amdoffice.net> <00583b68-d599-b709-133a-3741c258df13@redhat.com> <7f6a78ae-abab-2a03-aebd-e43e6fe168b4@amd.com> <94f6ed44-07ab-ff0f-2a6d-b3d8ff4ff4b1@redhat.com> From: Paolo Bonzini Message-ID: Date: Wed, 21 Feb 2018 17:36:27 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Feb 2018 16:36:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Wed, 21 Feb 2018 16:36:30 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 21/02/2018 15:52, Tom Lendacky wrote: > On 2/21/2018 8:47 AM, Tom Lendacky wrote: >> On 2/21/2018 8:32 AM, Paolo Bonzini wrote: >>> On 21/02/2018 15:15, Tom Lendacky wrote: >>>> On 2/21/2018 5:41 AM, Paolo Bonzini wrote: >>>>> On 16/02/2018 00:12, Tom Lendacky wrote: >>>>>> +static u32 msr_based_features[] = { >>>>>> +}; >>>>>> + >>>>>> +static unsigned int num_msr_based_features = ARRAY_SIZE(msr_based_features); >>>>>> + >>>>>> bool kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer) >>>>>> { >>>>>> if (efer & efer_reserved_bits) >>>>>> @@ -2785,6 +2794,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) >>>>>> case KVM_CAP_SET_BOOT_CPU_ID: >>>>>> case KVM_CAP_SPLIT_IRQCHIP: >>>>>> case KVM_CAP_IMMEDIATE_EXIT: >>>>>> + case KVM_CAP_GET_MSR_FEATURES: >>>>>> r = 1; >>>>>> break; >>>>>> case KVM_CAP_ADJUST_CLOCK: >>>>>> @@ -4410,6 +4420,47 @@ long kvm_arch_vm_ioctl(struct file *filp, >>>>>> r = kvm_x86_ops->mem_enc_unreg_region(kvm, ®ion); >>>>>> break; >>>>>> } >>>>>> + case KVM_GET_MSR_INDEX_LIST: { >>>>>> + struct kvm_msr_list __user *user_msr_list = argp; >>>>>> + struct kvm_msr_list msr_list; >>>>>> + unsigned int n; >>>>>> + >>>>>> + r = -EFAULT; >>>>>> + if (copy_from_user(&msr_list, user_msr_list, sizeof(msr_list))) >>>>>> + goto out; >>>>>> + n = msr_list.nmsrs; >>>>>> + msr_list.nmsrs = num_msr_based_features; >>>>>> + if (copy_to_user(user_msr_list, &msr_list, sizeof(msr_list))) >>>>>> + goto out; >>>>>> + r = -E2BIG; >>>>>> + if (n < msr_list.nmsrs) >>>>>> + goto out; >>>>>> + r = -EFAULT; >>>>>> + if (copy_to_user(user_msr_list->indices, &msr_based_features, >>>>>> + num_msr_based_features * sizeof(u32))) >>>>>> + goto out; >>>>>> + r = 0; >>>>>> + break; >>>>> >>>>> I think it's better to have some logic in kvm_init_msr_list, to filter >>>>> the MSR list based on whatever MSRs the backend provides. >>>> >>>> Ok, that's what I had originally and then you said to just return the full >>>> list and let KVM_GET_MSR return a 0 or 1 if it was supported. I can switch >>>> it back. >>> >>> Hmm, I cannot find this remark (I would have been very confused, so I >>> tried to look for it). I commented on removing kvm_valid_msr_feature, >>> but not kvm_init_msr_list. >> >> I think this is the reply that sent me off on that track: >> https://marc.info/?l=linux-kernel&m=151862648123153&w=2 Yeah, it was referring to AMD hosts that don't have the MSR. Sorry for the confusion. >> I'll make it consistent with the other MSR-related items and initialize >> the list in kvm_init_msr_list(). I'll change the signature of the >> msr_feature() kvm_x86_ops callback to take an index and optionally return >> a data value so it can be used to check for support when building the >> list and return a value when needed. > > Hmm, actually I'll just leave the signature alone and pass in a local > kvm_msr_entry struct variable for the call when initializing the list. Sounds good! Paolo