Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp3451806pxy; Mon, 26 Apr 2021 01:59:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzqiU6QDyPsY8dI9e8UG64wsJDleh+PL6uJMEXCqK9WDpoZQQdZ8cDbACrzL4748mhUUZK7 X-Received: by 2002:a17:90a:6385:: with SMTP id f5mr21436930pjj.212.1619427553436; Mon, 26 Apr 2021 01:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619427553; cv=none; d=google.com; s=arc-20160816; b=BPQGntNNb0HKYStRzGMGwGbyY1JAGXFfiS3roCD13hUDfJryFBr5cfU9dlpKvIFNqB Mx25irZdrc1AApR/M9iyvuzNhxXL3AArlIcfdxsbcFDmFTR7+JBjxcC4k5YAAfE3x7F6 Y2eJ1jOyfwoatqQgo9slICjxFSrLTm8L9Rjzqg5MlREX+dG7odvWhBlVLtBknSPx6Vo7 r5vJO+2zoOtfSPKYIrQn0VDJO/e30I9ja806IKmO7qwlxs3oZ2+3bTxIJOA4+EfzaDaN l6iwlPq+6RseKs2q6rVNzy1m5le117XE1d/sHiBqF2k/pQ/4U0xu9tZ4OVv71K2Ggv9H 4O+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=xrtgnm/L0WtusbYF9SuDZ+pYt9hjB7RMvd0KmtVIh7o=; b=i31lAzKhFUERj7R4/70j8a/NjAbywIy/LLIdaeg8Qhd+whSOrbpP+TsVrrqFnCo52Z UyrTrevRfSWU2CjfB/B8J4xW1cMaC/s/zSr0gB391OB6HVvh6HIITn8I+lx3/P3JLmZQ 6kEiw49iofn9uXHy4ms5kLYvyH1b4DXkpA4hbjqcXU59wYh8sMFAfBpzjWjRPRWIQt7C yMVQnPF8sL2zLRBYZ2YjKKfC3Ts9qSLO1HmJLot/Ft8UoM6xzyBm39qCFNnZDZUnh78N wqPBLnLXGWC3r50g4vW0nvgsloCkCTf5+ycUZYzP4JCGXzVvHJCVI32ELhg0vGUAvjn3 Buuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OtR+TGKC; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d19si16551952pgv.38.2021.04.26.01.59.00; Mon, 26 Apr 2021 01:59:13 -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=@redhat.com header.s=mimecast20190719 header.b=OtR+TGKC; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232241AbhDZI6X (ORCPT + 99 others); Mon, 26 Apr 2021 04:58:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20108 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232116AbhDZI6S (ORCPT ); Mon, 26 Apr 2021 04:58:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619427450; 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: in-reply-to:in-reply-to:references:references; bh=xrtgnm/L0WtusbYF9SuDZ+pYt9hjB7RMvd0KmtVIh7o=; b=OtR+TGKCg4S/PVJ8lQwYlY2Sqd4gYCMUQxm7WJ+ReO3P5NMQGDfSjM7r/rP0JM9BpWW6Yp hsKn0jxcqVpd0wbBm1x7Aur2UfUQS2b+gmTg8TfDDXo/ucMCYDtrkYGkKImEwLMRMeFyUZ MS9kpfEG3Mug2vZzvNIn03UGEintzi8= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-603-cEPmFHbAMjq8giTK5dyVpA-1; Mon, 26 Apr 2021 04:57:28 -0400 X-MC-Unique: cEPmFHbAMjq8giTK5dyVpA-1 Received: by mail-ej1-f69.google.com with SMTP id p25-20020a1709061419b0290378364a6464so9917789ejc.15 for ; Mon, 26 Apr 2021 01:57:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=xrtgnm/L0WtusbYF9SuDZ+pYt9hjB7RMvd0KmtVIh7o=; b=gCrC7lmVHOkjdGMwXA1xL5L/qpx2qOF39YqbWzcefJB66O4y9s9DAIWMT/VuYEuFNZ xZcroWxeuNQdcvJ2fwDU4ubZ8/Y823Brmck6U37c2pFboH/wV2Jb+L110kTr1todm+8O TLAfLAnrKqLoDbceGd4Wb2aBiutHcVynczDvpmBcT9HO6lPQOkYWJ1TiX73CIJaqb6Rr xCnaivFqBAbqdCZPkeAJp8fYArSiAO1q5tRLj+J9//GeeLXa6l8UhCkiXLbCOrKC+3nA dx/BFoQa4DolH4XHX7oGhduvA5Lu5fiATXDG1AAfQ3HWUoJhAZyS3JWjCRCzLeyXM/QJ gbUw== X-Gm-Message-State: AOAM533JfhWR/bdQyL8lhx1n7yz/qOkPy/DFc+TZK24h9XgNsFtzixF6 dN8SgqScXJi2DuTa59+527Q6r3IQTcy4B+lqCrFuotG8YYMo53F5/F5huQzskTX3k6kudd1ruv6 kxemB9kZZ9YPHvBq1UVAzV7AE X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr11080385edr.111.1619427447086; Mon, 26 Apr 2021 01:57:27 -0700 (PDT) X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr11080371edr.111.1619427446916; Mon, 26 Apr 2021 01:57:26 -0700 (PDT) Received: from vitty.brq.redhat.com (g-server-2.ign.cz. [91.219.240.2]) by smtp.gmail.com with ESMTPSA id o8sm10956335ejm.18.2021.04.26.01.57.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Apr 2021 01:57:26 -0700 (PDT) From: Vitaly Kuznetsov To: Sean Christopherson , Paolo Bonzini Cc: Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Reiji Watanabe Subject: Re: [PATCH v3 2/4] KVM: SVM: Clear MSR_TSC_AUX[63:32] on write In-Reply-To: <20210423223404.3860547-3-seanjc@google.com> References: <20210423223404.3860547-1-seanjc@google.com> <20210423223404.3860547-3-seanjc@google.com> Date: Mon, 26 Apr 2021 10:57:26 +0200 Message-ID: <87k0opfmo9.fsf@vitty.brq.redhat.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sean Christopherson writes: > Force clear bits 63:32 of MSR_TSC_AUX on write to emulate current AMD > CPUs, which completely ignore the upper 32 bits, including dropping them > on write. Emulating AMD hardware will also allow migrating a vCPU from > AMD hardware to Intel hardware without requiring userspace to manually > clear the upper bits, which are reserved on Intel hardware. > > Presumably, MSR_TSC_AUX[63:32] are intended to be reserved on AMD, but > sadly the APM doesn't say _anything_ about those bits in the context of > MSR access. The RDTSCP entry simply states that RCX contains bits 31:0 > of the MSR, zero extended. And even worse is that the RDPID description > implies that it can consume all 64 bits of the MSR: > > RDPID reads the value of TSC_AUX MSR used by the RDTSCP instruction > into the specified destination register. Normal operand size prefixes > do not apply and the update is either 32 bit or 64 bit based on the > current mode. > > Emulate current hardware behavior to give KVM the best odds of playing > nice with whatever the behavior of future AMD CPUs happens to be. > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/svm/svm.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index 9ed9c7bd7cfd..71d704f8d569 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -2904,8 +2904,17 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr) > * direct_access_msrs. Doing that would require a rdmsr in > * svm_vcpu_put. > */ > - svm->tsc_aux = data; > wrmsrl(MSR_TSC_AUX, svm->tsc_aux); Hm, shouldn't this be wrmsrl(MSR_TSC_AUX, data) or wrmsrl(MSR_TSC_AUX, (u32)data) then? As svm->tsc_aux wasn't updated yet. > + > + /* > + * 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. Emulate AMD CPU behavior > + * to avoid explosions if the vCPU is migrated from an AMD host > + * to an Intel host. > + */ > + svm->tsc_aux = (u32)data; Actually, shouldn't we just move wrmsrl() here? Assuming we're not sure how (and if) upper 32 bits are going to be used, it would probably make sense to not write them to the actual MSR... > break; > case MSR_IA32_DEBUGCTLMSR: > if (!boot_cpu_has(X86_FEATURE_LBRV)) { -- Vitaly