Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp3177707ybf; Tue, 3 Mar 2020 00:49:19 -0800 (PST) X-Google-Smtp-Source: ADFU+vuNImEmIGZKPE8yuTvKQg3MUbS075YpAl39Bk0yHUIQBP0qmHNM25E6vdg14sNJsLLNvBtq X-Received: by 2002:a9d:70c5:: with SMTP id w5mr2676746otj.58.1583225359306; Tue, 03 Mar 2020 00:49:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583225359; cv=none; d=google.com; s=arc-20160816; b=GjqVlBXAPlYN7r8QB7kdCtPx/NfndddGY2I1Ds4eU7f9oqesmF6Zmx4C/oBcbL0jve sSy7ERBFXywzX6GOHZyPjd3mJSxCOn+IQM1dutvW2AgE6RlGqQ8KPfCFrG3eF6JiJRKN y1Kxs0fVbXemKpRd5q/iwvMHZmj62mj7LpjX1KBOe/DMdXa1k1MCum9ly/2641LeWrPo g/gqxig1vdjidRvRiFdK21ip548VuqkSTCSmj7QFHCNTw0+905SVu7R0QbXb1Egx/Mys Ij48Pilpuk77yB3WC25mHHHo+QyWZVba46A3kUzGotn9rWp2XM9X3vYbxpuQBeOm4Oxf YK9Q== 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:dkim-signature; bh=q+Dx+bhdegB+eWVNZExdRg6MuYP3hf9RoraGKKuypFY=; b=ocIpZyXnBMkLBi04ULI4Yn6EVDivL0xQQeAfvW1X2Rt/zmpJIXhbGF3FAIXcy3bseI cXm29/XdwFApxyjy6up9J7djdzF6fyJEXqHAcOLEhbYGmXq2ZuWGu+glUnuGZT/aCI2C 5Np4iIG32nz8aA/34ZZqqQzSz+hWGGdXk1xH9L6412x7eYQHf8BU0/1A05m2eBDE9KC5 qsB+86Ar81oSGhyMZl+AVCBlkFA0KSEga9b/uQhF3blqqccuW/aKDtWHwje8zLuDX8kh kuU9kAmOQDzpIitBjKQ8+t1LyiHp+qwcQq8C4xUo9jcNMqgjemzUcAXocTbbMAfuoWNF 5VVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AtGoi4z2; 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=pass (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 z13si4454516otm.104.2020.03.03.00.49.07; Tue, 03 Mar 2020 00:49:19 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=AtGoi4z2; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727774AbgCCIsK (ORCPT + 99 others); Tue, 3 Mar 2020 03:48:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:23962 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725840AbgCCIsJ (ORCPT ); Tue, 3 Mar 2020 03:48:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583225287; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q+Dx+bhdegB+eWVNZExdRg6MuYP3hf9RoraGKKuypFY=; b=AtGoi4z2Xg+aBOhGpwQD+rirT3DUw3qglc+OanMxsXnf7LQwYsoqlq/yg+lAWWu1M2uvke AU/dCsMvrqDnVuFxHjI9v3jyDDf6jZLchAML2dZr2SCC6SflTJAGCgF3dJwaewl6imvwa2 8VPXrOzVP+9QiCtq4sUC6+tOVyhOW5I= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-106-A-BqoCXSNxqPgsD3v2wr5Q-1; Tue, 03 Mar 2020 03:48:06 -0500 X-MC-Unique: A-BqoCXSNxqPgsD3v2wr5Q-1 Received: by mail-wr1-f71.google.com with SMTP id w8so126828wrn.7 for ; Tue, 03 Mar 2020 00:48:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=q+Dx+bhdegB+eWVNZExdRg6MuYP3hf9RoraGKKuypFY=; b=EKfL7241BuJTBH9H8YQ7/Mlj7ShGOOkLpZfBr6JT0eKdz0IarElDyyxgbM4DRprK/t DUiGjXSL/pTAwOVXxL93JlqHAWHA+G8D15VCMsesQZrQ18YyidGHYihT7SpiRbVeh2Tx Q7TywvpHAfL8sm3Kpi46pzUet/RRswmnBqmHmqaSTR7/qCCjcuea9cp+SdnqTxzrYQn1 Xy4tzPj85mZIafKUfl5Y0iqqwYLphw1J0dTjrlL+R0Z65vWnSQ+Z0LLmnZ3n1ag8ScNN XFcjRx+wu3xDSz/MvECQ2rIsdC9LadlVkw9zduTT5Lnv2St3yo8XK2z7xhRYbBxaqjot aexQ== X-Gm-Message-State: ANhLgQ1D77fHPyvx9nlFYnQtS8azkcm7+zCALzeL4uN67fs8FDkAA4+u FsRBY934GGefQlBrZq4dCJ7p9Y6eomtlbb2veZn2sfZEDZbJqOVidkfwBx42pPlR02TnkTqxBZ4 LQuO/VedIn+xNPnQVQtCcvtZ5 X-Received: by 2002:a5d:518b:: with SMTP id k11mr4535743wrv.114.1583225283702; Tue, 03 Mar 2020 00:48:03 -0800 (PST) X-Received: by 2002:a5d:518b:: with SMTP id k11mr4535701wrv.114.1583225283410; Tue, 03 Mar 2020 00:48:03 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:4c52:2f3b:d346:82de? ([2001:b07:6468:f312:4c52:2f3b:d346:82de]) by smtp.gmail.com with ESMTPSA id i204sm2895140wma.44.2020.03.03.00.48.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 03 Mar 2020 00:48:02 -0800 (PST) Subject: Re: [PATCH 3/6] KVM: x86: Add dedicated emulator helper for grabbing CPUID.maxphyaddr To: Sean Christopherson Cc: Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Jan Kiszka , Xiaoyao Li References: <20200302195736.24777-1-sean.j.christopherson@intel.com> <20200302195736.24777-4-sean.j.christopherson@intel.com> From: Paolo Bonzini Message-ID: Date: Tue, 3 Mar 2020 09:48:03 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200302195736.24777-4-sean.j.christopherson@intel.com> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/03/20 20:57, Sean Christopherson wrote: > Add a helper to retrieve cpuid_maxphyaddr() instead of manually > calculating the value in the emulator via raw CPUID output. In addition > to consolidating logic, this also paves the way toward simplifying > kvm_cpuid(), whose somewhat confusing return value exists purely to > support the emulator's maxphyaddr calculation. > > No functional change intended. I don't think this is a particularly useful change. Yes, it's not intuitive but is it more than a matter of documentation (and possibly moving the check_cr_write snippet into a separate function)? Paolo > Signed-off-by: Sean Christopherson > --- > arch/x86/include/asm/kvm_emulate.h | 1 + > arch/x86/kvm/emulate.c | 10 +--------- > arch/x86/kvm/x86.c | 6 ++++++ > 3 files changed, 8 insertions(+), 9 deletions(-) > > diff --git a/arch/x86/include/asm/kvm_emulate.h b/arch/x86/include/asm/kvm_emulate.h > index bf5f5e476f65..ded06515d30f 100644 > --- a/arch/x86/include/asm/kvm_emulate.h > +++ b/arch/x86/include/asm/kvm_emulate.h > @@ -222,6 +222,7 @@ struct x86_emulate_ops { > > bool (*get_cpuid)(struct x86_emulate_ctxt *ctxt, u32 *eax, u32 *ebx, > u32 *ecx, u32 *edx, bool check_limit); > + int (*get_cpuid_maxphyaddr)(struct x86_emulate_ctxt *ctxt); > bool (*guest_has_long_mode)(struct x86_emulate_ctxt *ctxt); > bool (*guest_has_movbe)(struct x86_emulate_ctxt *ctxt); > bool (*guest_has_fxsr)(struct x86_emulate_ctxt *ctxt); > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index dd19fb3539e0..bf02ed51e90f 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -4244,16 +4244,8 @@ static int check_cr_write(struct x86_emulate_ctxt *ctxt) > > ctxt->ops->get_msr(ctxt, MSR_EFER, &efer); > if (efer & EFER_LMA) { > - u64 maxphyaddr; > - u32 eax, ebx, ecx, edx; > + int maxphyaddr = ctxt->ops->get_cpuid_maxphyaddr(ctxt); > > - eax = 0x80000008; > - ecx = 0; > - if (ctxt->ops->get_cpuid(ctxt, &eax, &ebx, &ecx, > - &edx, false)) > - maxphyaddr = eax & 0xff; > - else > - maxphyaddr = 36; > rsvd = rsvd_bits(maxphyaddr, 63); > if (ctxt->ops->get_cr(ctxt, 4) & X86_CR4_PCIDE) > rsvd &= ~X86_CR3_PCID_NOFLUSH; > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index ddd1d296bd20..5467ee71c25b 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -6209,6 +6209,11 @@ static bool emulator_get_cpuid(struct x86_emulate_ctxt *ctxt, > return kvm_cpuid(emul_to_vcpu(ctxt), eax, ebx, ecx, edx, check_limit); > } > > +static int emulator_get_cpuid_maxphyaddr(struct x86_emulate_ctxt *ctxt) > +{ > + return cpuid_maxphyaddr(emul_to_vcpu(ctxt)); > +} > + > static bool emulator_guest_has_long_mode(struct x86_emulate_ctxt *ctxt) > { > return guest_cpuid_has(emul_to_vcpu(ctxt), X86_FEATURE_LM); > @@ -6301,6 +6306,7 @@ static const struct x86_emulate_ops emulate_ops = { > .fix_hypercall = emulator_fix_hypercall, > .intercept = emulator_intercept, > .get_cpuid = emulator_get_cpuid, > + .get_cpuid_maxphyaddr= emulator_get_cpuid_maxphyaddr, > .guest_has_long_mode = emulator_guest_has_long_mode, > .guest_has_movbe = emulator_guest_has_movbe, > .guest_has_fxsr = emulator_guest_has_fxsr, >