Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1679352pxb; Mon, 22 Feb 2021 08:13:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxnFlIKP6HoCRc4xA4/fRbV/PIQcrNc5r9CHn625aoSvml7NroNkvYUYluunzMfyJrpKrhI X-Received: by 2002:aa7:c314:: with SMTP id l20mr11488399edq.148.1614010420154; Mon, 22 Feb 2021 08:13:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614010420; cv=none; d=google.com; s=arc-20160816; b=paGe03klCFGDZI/ZYsLoHYqlrpq5SnLwYFKnulMqgaiTjYD/JJR6AE6gSNSNH37BkS UvbwjJezKYoT5SeKWNIYKYwuBPLiro0BSMIALLaT3YJcww+aBTGFKlvXB71S8aonB/AY rmzUOAAiWzRzSlikQNjmvammR51R0SBO0+EeDdwZt3P9wjSlBm5bSFkWH1ySs0k8nivm ktjAVqtkZZfyNnhre1oIHsg1ScztOF3sByUfgjvqEXsLKv4JjDk+p7dxoFp8IL6KDrbu yNpelvvxJfK5AOkqeUaWCPdEbix8lV4FR9iPuehBNz7MgtzC3nuoZOu0Konz/pt9BJ0I dbaQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=mp7wIhLHWdhboT6kIoeZS80417khoNPc/CItzMbajCM=; b=X1IW3bxM+apowuvWlf6KHsJg2HQAdD5m3VykzhV1B7sGcabi0NanlqA2/2yeQsJji4 iqTqbXFvblcB2iGF+1nCRXnZHtvEQHn6CX7TGThlbe1Bjav6984eoI4VLQVZPAOQZ1WO dZq1XhG7dWxTrVWoSktKN1RFv5G8JUt6dm3he+s2xcZRinUl3/TCdZbRywgL4LOhjdFw Eoa9vyBqHDKUDCuvhE/Pa856yFf4bZZ/bziEHlicu8PinegysTBNyivJ9l21FCtvENEZ 1gB4A2915IVY6r9EgGTw6Fs3JSBHS8CddoMoAB33KbpMJ/LQNWH6GBn5h5PmAeRZfu66 MomA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GghBN+pJ; 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 r21si13501442ejo.142.2021.02.22.08.13.17; Mon, 22 Feb 2021 08:13:40 -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=GghBN+pJ; 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 S231660AbhBVQKF (ORCPT + 99 others); Mon, 22 Feb 2021 11:10:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231671AbhBVQHz (ORCPT ); Mon, 22 Feb 2021 11:07:55 -0500 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6DCCC06178A for ; Mon, 22 Feb 2021 08:07:03 -0800 (PST) Received: by mail-pg1-x534.google.com with SMTP id e6so840081pgk.5 for ; Mon, 22 Feb 2021 08:07:03 -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:content-transfer-encoding:in-reply-to; bh=mp7wIhLHWdhboT6kIoeZS80417khoNPc/CItzMbajCM=; b=GghBN+pJW634uiH0KTvYQM25/DQNpQPu4VEF3pllmDO/S+sXWWXvfEcPZD7QzQs9p2 wK0aVSoTe3R/o1UKotnmlXWXlWMFWQpMfOHkxdrSr3K+i2TOjz5/oNfo+VXAplIz9O7Y m7DPjmLtPN09xoGaMg1HPRJwS84c0QxxavAABptUXuOocx4cfM30gvi+OS7sH5SHNMKu VTiebkIQROzGNQguER8Oo5Y+llKPvpVwvIOihvewwLxecWoFR5rilxSvmx8UoGi/SDlO 4nY5QInyKBTSATXZax+wF/Xiaq55FURXrt0wCErG40INjLE41UPsXY+wgpvigM00HtLY 81Pg== 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:content-transfer-encoding :in-reply-to; bh=mp7wIhLHWdhboT6kIoeZS80417khoNPc/CItzMbajCM=; b=mrCorBSXqT3TPP25ku0++DKE/E42gaGsAv3rRaFGdexOxAmjtCUI9vNDmvZrAqs+0b 0pf1pQdkDjE8O9Rde9KKfOg6qP5q05YMwk5i4B5QHBjIQ6dq51ltQbqR6C92yYYyTdUS GK+3nbOVBqpEu9vRianDtYhCoa+mNWXIKt/6vYwSsrRAKL68bpq+aYd8kH7yAX+YsAPl vwAQZxwipOsog/Sat2aWodeE/1/rBC4hMBRGRNaB+QdrwEw4Oym2OgRIaAbb0FqlCpgr +XMmubaU+OD50AZrA5VbZ6gkgMdfbCALrUDrIt45LADC/IhjK0tcFipQNNT/mnO7KXQN yJ8w== X-Gm-Message-State: AOAM530rRPZvzX2b9iMpc0MWRn3wjFy2bHfH1njDYsRVH03k16BGrVqO z/BvMNmiyg4qIwlal2E0W14ivQ== X-Received: by 2002:a63:cf05:: with SMTP id j5mr4302479pgg.384.1614010023095; Mon, 22 Feb 2021 08:07:03 -0800 (PST) Received: from google.com ([2620:15c:f:10:655e:415b:3b95:bd58]) by smtp.gmail.com with ESMTPSA id k128sm20069508pfd.137.2021.02.22.08.07.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Feb 2021 08:07:02 -0800 (PST) Date: Mon, 22 Feb 2021 08:06:55 -0800 From: Sean Christopherson To: "Liu, Jing2" Cc: Dave Hansen , pbonzini@redhat.com, Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] kvm: x86: Revise guest_fpu xcomp_bv field Message-ID: References: <20210208161659.63020-1-jing2.liu@linux.intel.com> <4e4b37d1-e2f8-6757-003c-d19ae8184088@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 22, 2021, Liu, Jing2 wrote: > > On 2/9/2021 1:24 AM, Sean Christopherson wrote: > > On Mon, Feb 08, 2021, Dave Hansen wrote: > > > On 2/8/21 8:16 AM, Jing Liu wrote: > > > > -#define XSTATE_COMPACTION_ENABLED (1ULL << 63) > > > > - > > > > static void fill_xsave(u8 *dest, struct kvm_vcpu *vcpu) > > > > { > > > > struct xregs_state *xsave = &vcpu->arch.guest_fpu->state.xsave; > > > > @@ -4494,7 +4492,8 @@ static void load_xsave(struct kvm_vcpu *vcpu, u8 *src) > > > > /* Set XSTATE_BV and possibly XCOMP_BV. */ > > > > xsave->header.xfeatures = xstate_bv; > > > > if (boot_cpu_has(X86_FEATURE_XSAVES)) > > > > - xsave->header.xcomp_bv = host_xcr0 | XSTATE_COMPACTION_ENABLED; > > > > + xsave->header.xcomp_bv = XCOMP_BV_COMPACTED_FORMAT | > > > > + xfeatures_mask_all; > > This is wrong, xfeatures_mask_all also tracks supervisor states. > When looking at SDM Vol2 XSAVES instruction Operation part, it says as > follows, > > RFBM ← (XCR0 OR IA32_XSS) AND EDX:EAX; > COMPMASK ← RFBM OR 80000000_00000000H; > ... > > XCOMP_BV field in XSAVE header ← COMPMASK; > > > So it seems xcomp_bv also tracks supervisor states? Yes, sorry, I got distracted by Dave's question and didn't read the changelog closely. Now that I have, I find "Since fpstate_init() has initialized xcomp_bv, let's just use that." confusing. I think what you intend to say is that we can use the same _logic_ as fpstate_init_xstate() for calculating xcomp_bv. That said, it would be helpful for the changelog to explain why it's correct to use xfeatures_mask_all, e.g. just a short comment stating that the variable holds all XCR0 and XSS bits enabled by the host kernel. Justifying a change with "because other code does it" is sketchy, becuse there's no guarantee that what something else does is also correct for KVM, or that the existing code itself is even correct.