Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1626859pxb; Thu, 4 Mar 2021 16:50:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzv+k/8CZx2wbMU6cX+jY0lZ9LL94RtCWkMlcihW9OWDQ+/TRLoYbts2EqhcILRLav3fL78 X-Received: by 2002:a05:6e02:12a8:: with SMTP id f8mr6254765ilr.174.1614905452388; Thu, 04 Mar 2021 16:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614905452; cv=none; d=google.com; s=arc-20160816; b=jGTfyR5rKzbG3RJUJW8xEFJeXcuf57zsa6uib/Ivf2ge/cFXCS2s2+9DXAPthoWlYP 7KOaaVta66RTldkYQBJsRCnH43Mbq+tRmQ76+QS2uhs9Yld2iRCIKuqsuuaQsptmPgwz 2X0hHRgbRXK6lF6KjGwQd9XKzQpEsW7AzgocFI3bHPxgi69gLGHYBwyJiGtyetkzfWc1 lni5VV6TBThQGR5aHx5fybEASDISPiYMlsLiRvNgy5iH43vRnRQfQnLIbmW2B0LzJUOX LAae+QQ7lsUL3Avz15vKekMEX7fMkJuObsIcXdw8OIppO72TN6rx46bQAmT7pc+7BgrY S9Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tfjZcU3b9XBszi13RocA+Z9H6iZikjohZpktcKNP5fc=; b=wIJ51EOJZjbKo2a71LuYpOz/X+AWXtUc80Io+xu168LSWq/xr8O27r14bxhnRtZYlC Rgle6cuFBIiUyY7GFP+OFBb5Qg2tKxmde2K7QVKrk5LAbEMe3migXm+GaWuwGQfCShOj trM1gGBUXuy+6kPwKzYZAQ5y15Rg8PmzVjrQEuknMo3lF6Y8s9o/NKbS7LAz7KOI8FG9 h2cbzkGmiIu6U8sSG2U47GLSA8myzfaObjaHHKZRDqBaGAS3ZB6R7F7ex8+b2o38INwp yIu+h28Qbark3nBwigEs9FDjRYRTUuF51c6bOZ+B8lH8JxzO6VnUE0YBTWoYt1poAFWz ViVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y1vfUPKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j29si622789ila.91.2021.03.04.16.50.39; Thu, 04 Mar 2021 16:50:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Y1vfUPKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237731AbhCDQcx (ORCPT + 99 others); Thu, 4 Mar 2021 11:32:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237690AbhCDQcW (ORCPT ); Thu, 4 Mar 2021 11:32:22 -0500 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D582C061756 for ; Thu, 4 Mar 2021 08:31:42 -0800 (PST) Received: by mail-pf1-x436.google.com with SMTP id t29so19298732pfg.11 for ; Thu, 04 Mar 2021 08:31:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=tfjZcU3b9XBszi13RocA+Z9H6iZikjohZpktcKNP5fc=; b=Y1vfUPKT1GHGCBY0dM8C+w9CbN7Ip3h+88hNE/NlXWIcyElau962o/KQMx8jYFFaOo s2ff2PW6zQeC0DAxTi73sAU727e23c9eIkfhmmGUV9eojoG9/dZdXs04VEz8v7+hOGMg EQfobU3ygD/63hSoTHfW+EPeV4h01iMofeqHyFYoNcZqRMUtlEOR5PEsYyH7ZCoXTuQj TiLwrg9psTBYOCSIAjKkR104Oj1wKyNecLlipeJeMoQ6WFNWUsiW5h1xiBKCDBL7doHs uuWgnizHmyXUNb1BBTLmLZXdkFl1G6o6FFXNBaiCUxTCqrgj301lyqEgjmQ4ToGwhBtE RamA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=tfjZcU3b9XBszi13RocA+Z9H6iZikjohZpktcKNP5fc=; b=cV1v0RmCbFIw4XnGmhSzReKSWzAqkybnGUMQRZ1Vd4MpgcEftrNLsNaZ3Lpde9p5Cp vcUuojUyIMPD5loiCkYw33B0C6rKtuyfm/UFikib/aI/Iryyou+H/LWOMZcf7bld0Y7u qqGP6LDJ7n2nRkxYwvUv+2Udc5t1AeJeNui7Zl1lQjdF0HXYhu6VXkriDvVzsrLwtPC3 q+N3xTzXppGELckGHLri19bcw3YuJnTmxRrBM+w3DkOeFke+Nxg6+mXwljaQ8xYdAEHY mbVuuTj4kh0mFygzZRhzFXNO66F+LQcHbCigV3QC5+dOzyNcHBIkSUfe5YbFMSg4Yl+R Y1+w== X-Gm-Message-State: AOAM533h/d01uA/leXXQLkoVCeG+HizKgCV6GBI4nImLVsXWCCVBfDcD lWkX36tsFukGWZAAD3+q8dYTtg== X-Received: by 2002:aa7:93a6:0:b029:1ed:8b81:6a2e with SMTP id x6-20020aa793a60000b02901ed8b816a2emr4560406pff.29.1614875501447; Thu, 04 Mar 2021 08:31:41 -0800 (PST) Received: from google.com ([2620:15c:f:10:9857:be95:97a2:e91c]) by smtp.gmail.com with ESMTPSA id h7sm3156541pfo.45.2021.03.04.08.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Mar 2021 08:31:40 -0800 (PST) Date: Thu, 4 Mar 2021 08:31:33 -0800 From: Sean Christopherson To: Like Xu Cc: Paolo Bonzini , Peter Zijlstra , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , Dave Hansen , wei.w.wang@intel.com, Borislav Petkov , kvm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 9/9] KVM: x86: Add XSAVE Support for Architectural LBRs Message-ID: References: <20210303135756.1546253-1-like.xu@linux.intel.com> <20210303135756.1546253-10-like.xu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 04, 2021, Like Xu wrote: > On 2021/3/4 2:03, Sean Christopherson wrote: > > if (vmx_umip_emulated()) > > kvm_cpu_cap_set(X86_FEATURE_UMIP); > > > > /* CPUID 0xD.1 */ > > - supported_xss = 0; > > if (!cpu_has_vmx_xsaves()) > > kvm_cpu_cap_clear(X86_FEATURE_XSAVES); > > if (!cpu_has_vmx_xsaves()) > supported_xss = 0; Argh, I forgot XSAVES has a VMCS control. That's why kvm_arch_hardware_setup() clears supported_xss if !XSAVES. I guess just leave that existing code, but maybe add a comment. Paolo, any thoughts on how to keep supported_xss aligned with support_xcr0, without spreading the logic around too much? > kvm_cpu_cap_clear(X86_FEATURE_XSAVES); > > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 7b0adebec1ef..5f9eb1f5b840 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -205,6 +205,8 @@ static struct kvm_user_return_msrs __percpu *user_return_msrs; > > | XFEATURE_MASK_BNDCSR | XFEATURE_MASK_AVX512 \ > > | XFEATURE_MASK_PKRU) > > > > +#define KVM_SUPPORTED_XSS XFEATURE_MASK_LBR > > + > > u64 __read_mostly host_efer; > > EXPORT_SYMBOL_GPL(host_efer); > > > > @@ -8037,6 +8039,11 @@ int kvm_arch_init(void *opaque) > > supported_xcr0 = host_xcr0 & KVM_SUPPORTED_XCR0; > > } > > > > + if (boot_cpu_has(X86_FEATURE_XSAVES)) > > { > > > + rdmsrl(MSR_IA32_XSS, host_xss); > > + supported_xss = host_xss & KVM_SUPPORTED_XSS; > > + } > > + > > if (pi_inject_timer == -1) > > pi_inject_timer = housekeeping_enabled(HK_FLAG_TIMER); > > #ifdef CONFIG_X86_64 > > @@ -10412,9 +10419,6 @@ int kvm_arch_hardware_setup(void *opaque) > > > > rdmsrl_safe(MSR_EFER, &host_efer); > > > > - if (boot_cpu_has(X86_FEATURE_XSAVES)) > > - rdmsrl(MSR_IA32_XSS, host_xss); > > - > > r = ops->hardware_setup(); > > if (r != 0) > > return r; > > @@ -10422,9 +10426,6 @@ int kvm_arch_hardware_setup(void *opaque) > > memcpy(&kvm_x86_ops, ops->runtime_ops, sizeof(kvm_x86_ops)); > > kvm_ops_static_call_update(); > > > > - if (!kvm_cpu_cap_has(X86_FEATURE_XSAVES)) > > - supported_xss = 0; > > - > > #define __kvm_cpu_cap_has(UNUSED_, f) kvm_cpu_cap_has(f) > > cr4_reserved_bits = __cr4_reserved_bits(__kvm_cpu_cap_has, UNUSED_); > > #undef __kvm_cpu_cap_has > > >