Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3907884pxy; Mon, 26 Apr 2021 12:42:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw2fP0etb1gJqwMgs55xUAaybQ09TR5XSJP6cIhT5CBQ/8pk8IoQqrBV0wX3iAsMN4AFhsR X-Received: by 2002:a62:2a14:0:b029:263:20c5:6d8c with SMTP id q20-20020a622a140000b029026320c56d8cmr19730079pfq.23.1619466145889; Mon, 26 Apr 2021 12:42:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619466145; cv=none; d=google.com; s=arc-20160816; b=clNUI0YA5w5zPo/J7CecnsH/P6KQkQ+KIzTUcImM8xw+m3hSGOOa2PRBC1GAXTzF+k 5SbXhizPJYhziZrcpZGezHqPZuqvlCb07LsJ9tolNpoV77FSX8CSkGim9R48vGRVl4Uu FT7D5JUKT5SAYEvM0WdwNMsWuqN7roYmMMRHg/4qyDFcB979qN9gRNNw5Grgja3JCbeR iafpCeCk1xY1eL8culYX1T67Sd7GW1l1i/bfMQawyZairUnnxponoWMqQeWURA11RYA0 4Nu2/aabxNh9YftobyKe2fkBHynh8NKvkk8rzqqMPbtUrJ6q9keLVPwBJ7XG0Rp/RAiS Fcmg== 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=ab2HES6R0vCLyUYQvcY8/tnqqG94WlRNIsnH2B1gsKI=; b=QP7llpcOnLdb4B8KH3qvuznGlCTNFkl6srj1ApiYlbyvHSwOfQH1riI/HX6DP6BzwU FwEtdwZWTTUJYHj0vrxuGQgLPqyNd4b/YtnK6oM60niMXYrMWOFmOeoMILwykXBqiNSK tqkyl27N1697z/RSqDfNGr63qJAmvBI7FADM/lTtz4WlDG5nXL+xAk4ULkdYlsPinfx7 fkaSaKzbixWFW0JnDFDL2Kkslaza8vwssGb2EvCNaZ6vMLfeX6drqHwCvLRJzemZvIiz mJnjIKiVprdeDRxk+Y6ujY91GrwumB+3iSzYQuk7YgCHFtKN6BJSjYx6jDuMZobANIrt a8jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ocwCBcwt; 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 t11si424710pjg.102.2021.04.26.12.42.13; Mon, 26 Apr 2021 12:42:25 -0700 (PDT) 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=ocwCBcwt; 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 S237571AbhDZTjZ (ORCPT + 99 others); Mon, 26 Apr 2021 15:39:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235128AbhDZTjY (ORCPT ); Mon, 26 Apr 2021 15:39:24 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE629C061574 for ; Mon, 26 Apr 2021 12:38:42 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id w6so25174471pfc.8 for ; Mon, 26 Apr 2021 12:38:42 -0700 (PDT) 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=ab2HES6R0vCLyUYQvcY8/tnqqG94WlRNIsnH2B1gsKI=; b=ocwCBcwt2VCpKKeAqYQfJueYG8T5dZBsg0BzfmEJ4kC9MQSlmlps94SflUGmK2mVr/ WzULuKECHKMXaVeHed4EbwbPTktOzC/Pgk43oq9BfjiNl9DYJSHZ1DjOc/t8kknhwyos MLA6+f66wmN8WT0jaM98sT3w7onjO+15DTtIVIU9N1eRRoPOc9oSYvB9YPwvlTSSN382 w/vLzw0csN6NyA/H8UVawatOlVRmxH5k629uNs1QdMfjlzpbu89hGYSXQs+rLnsaR5Y+ hKRsz7CWwC/aEpbIK3hfzxMLEx31bnYkEZGrBGbc5BwYLNwMwWnf/JocYnjRsdjsO1Ts h9vA== 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=ab2HES6R0vCLyUYQvcY8/tnqqG94WlRNIsnH2B1gsKI=; b=F105NYKM6OHpNNkpgLbrwb8v4L7BrCfPV7uSdIzQuXGB6np5nDQEX4XWP3OEi60+uo QjQ9KJ11YC3ErH4NVWymEZNXEil0MmtEPdp4k30jAuzfRJomwNfBlXDehJz1lqluRold /aZHBX+fljrDMewlXjERdlie7yDoFdCbdtsB72LQcvTpRQiCoiSpKNbF4o01gv1EItQg /ICrOkp5f50wSHQwAZUsfFvo1ivxNm1NNjLU0vToDXD+qgkhZ6RctyuCp8g5ilFFJqJP RR8S1Vh8oQH0roOjuXY7dC5goXd1Lc5bng5Af6lA/h3Cex1h4XIO03v2zQOeWI3+DS/k dHLQ== X-Gm-Message-State: AOAM531tuxS75uApijjaVspd89LwuMbKr3s+0/CwwcVmNE7uQsE7+p7m 0x/ALh5XWeZIalhNNG+nBBv1sA== X-Received: by 2002:a62:65c7:0:b029:278:e19f:f838 with SMTP id z190-20020a6265c70000b0290278e19ff838mr2848137pfb.64.1619465922089; Mon, 26 Apr 2021 12:38:42 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id i18sm439912pfq.59.2021.04.26.12.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 12:38:41 -0700 (PDT) Date: Mon, 26 Apr 2021 19:38:37 +0000 From: Sean Christopherson To: Reiji Watanabe Cc: Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 3/4] KVM: x86: Tie Intel and AMD behavior for MSR_TSC_AUX to guest CPU model Message-ID: References: <20210423223404.3860547-1-seanjc@google.com> <20210423223404.3860547-4-seanjc@google.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 Sat, Apr 24, 2021, Reiji Watanabe wrote: > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -1610,6 +1610,29 @@ static int __kvm_set_msr(struct kvm_vcpu *vcpu, u32 index, u64 data, > > * invokes 64-bit SYSENTER. > > */ > > data = get_canonical(data, vcpu_virt_addr_bits(vcpu)); > > + break; > > + case MSR_TSC_AUX: > > + if (!kvm_cpu_cap_has(X86_FEATURE_RDTSCP)) > > + return 1; > > + > > + if (!host_initiated && > > + !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) > > + return 1; > > + > > + /* > > + * Per Intel's SDM, bits 63:32 are reserved, but AMD's APM has > > + * incomplete and conflicting architectural behavior. Current > > + * AMD CPUs completely ignore bits 63:32, i.e. they aren't > > + * reserved and always read as zeros. Enforce Intel's reserved > > + * bits check if and only if the guest CPU is Intel, and clear > > + * the bits in all other cases. This ensures cross-vendor > > + * migration will provide consistent behavior for the guest. > > + */ > > + if (guest_cpuid_is_intel(vcpu) && (data >> 32) != 0) > > + return 1; > > + > > + data = (u32)data; > > + break; > > } > > > > msr.data = data; > > @@ -1646,6 +1669,17 @@ int __kvm_get_msr(struct kvm_vcpu *vcpu, u32 index, u64 *data, > > if (!host_initiated && !kvm_msr_allowed(vcpu, index, KVM_MSR_FILTER_READ)) > > return KVM_MSR_RET_FILTERED; > > > > + switch (index) { > > + case MSR_TSC_AUX: > > + if (!kvm_cpu_cap_has(X86_FEATURE_RDTSCP)) > > + return 1; > > + > > + if (!host_initiated && > > + !guest_cpuid_has(vcpu, X86_FEATURE_RDTSCP)) > > + return 1; > > > It looks Table 2-2 of the Intel SDM Vol4 (April 2021) says > TSC_AUX is supported: > > If CPUID.80000001H:EDX[27] = 1 or CPUID.(EAX=7,ECX=0):ECX[22] = 1 > > Should we also check X86_FEATURE_RDPID before returning 1 > due to no RDTSCP support ? Yep. VMX should also clear RDPID if the ENABLE_RDTSCP control isn't supported. That bug isn't fatal because KVM emulates RDPID on #UD, but it would be a notieable performance hit for the guest. There is also a kernel bug lurking; vgetcpu_cpu_init() doesn't check X86_FEATURE_RDPID and will fail to initialize MSR_TSC_AUX if RDPID is supported but RDTSCP is not, and __getcpu() uses RDPID. I'll verify that's broken and send a patch for that one too. > There doesn't seem to be a similar description in the APM though. AMD also documents this in Appendix E: CPUID Fn0000_0007_EBX_x0 Structured Extended Feature Identifiers (ECX=0) Bits Field Name ... 22 RDPID RDPID instruction and TSC_AUX MSR support.