Received: by 2002:a05:7412:f589:b0:e2:908c:2ebd with SMTP id eh9csp961880rdb; Wed, 1 Nov 2023 07:42:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFNZu9Ny5UM0wcwSFgrScNoltMCbB1w+Ec9BOu+eJXNvbxIuthExFqSXw0XAiiMi44UB/I2 X-Received: by 2002:a05:6358:9d85:b0:168:e3a9:14f5 with SMTP id d5-20020a0563589d8500b00168e3a914f5mr14154953rwo.12.1698849727453; Wed, 01 Nov 2023 07:42:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698849727; cv=none; d=google.com; s=arc-20160816; b=Lkxt8OJ29IMmaxRx8GO6jqiJsMRbia3ERbeTH5y98OrM01MBMNmXUKxmDFd/40wLc4 XgLqhsI7ijAugTxhBba9Px4UQyleU9qreetBBTkrOvBd+iYjw2rayFuELUem/AdIMuIa yrGrGKgOunOM/KHHde68NTSx/Xc5MjbxJ2pdsdwCKBQZqsm0HcvC5PmRF/UTHMz4mFfL m4IRyyEmHldGl0K42+kTdLB5sodXHK2Y0jQWm/gJYF/U4d36JLYiB408TeiBqfeaRBqB 5Ei/szMdN0OFkN8B7T1mqv37VbWJJfQJKoraeiFwOjbs38WYbKRnN+Upz3FE99rvlUI4 hk8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=vY+whK5XqbSYsbcvwYkxlvLDj7c4sWYoMlLiCl+8FOk=; fh=9H2JdZ4RfWqrKjgeBNKplQMSTrXHkLX7N6ZGqyjTrX8=; b=uiYPZ8Z3OSdgJntD0LzWdiaIhJTBU/6Qvkeqa1eVkSvTXpzSF7OxbmO1EMh3VsTlZQ CBUD7Qb09Y1TILeEhgBL7FMmeW/bkQx6TD2EpH1vmfKwy3QcGY7Y5jGE9qeMKspYkHcr OottsCNHF2txgFhsvriucp75xVJRMdHj3OztJmO4SHul/ZQ5fqzcA53lS30fxcl0VxXX EvRDPirru3c4BO4kiSShy9FiuQozZAYzadA4GRO5R+69FafhHNlPJNanu0mR3wlAtTgr lAn718xHClMR9z2FDMk2vnOQ+4Obp7oVp6eCj5xEQoTIvoVb+60NOgAFdamBVTRqQ/Y+ iR6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LfDKBilu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l72-20020a63914b000000b005898cf1c6a0si13400pge.324.2023.11.01.07.42.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:42:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=LfDKBilu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9C23480FDDFC; Wed, 1 Nov 2023 07:42:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344598AbjKAOmF (ORCPT + 99 others); Wed, 1 Nov 2023 10:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344438AbjKAOmD (ORCPT ); Wed, 1 Nov 2023 10:42:03 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6518FD for ; Wed, 1 Nov 2023 07:41:57 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-da0737dcb26so7162855276.3 for ; Wed, 01 Nov 2023 07:41:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698849717; x=1699454517; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=vY+whK5XqbSYsbcvwYkxlvLDj7c4sWYoMlLiCl+8FOk=; b=LfDKBilu4NrSerjztc1lrZy8phroJv/F2apm3wn0KDjMa59lUkyl1NpYYdI9OvIEOL TClkgg2MVEVcDljIhz4wlqODduPTbjuizVIPoH3QQPtd/lSMvjumg8lvM4/Pxa29M+Ae zko2FcItwkGq8s9JuKbDRnHa6QAxZ0EVzEE2APspZVCuRY94vFxXYZNmWqzpjryecr0f ZnxW6RN7/QIrxuVswW+PWOU1FgonTqVmvrHspdovd7/FYt0t4F8sa3TEtceGlSdrlauA x/u8N7Y9K6fR1O/J7ML45OBqHD9dMqd11ZzYo05RWVtONBMCCTQ5H8OGYbJpdDm/DYLW TgHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698849717; x=1699454517; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vY+whK5XqbSYsbcvwYkxlvLDj7c4sWYoMlLiCl+8FOk=; b=LXHyvb0o0T2su+9de8u0zF22SkmhluxdlRVHTNwqwuAp5AmHXTod0fMPnqAw4sXpXZ SePnsN0XMFzTem16bwUi6Oj0wrIhtWsTdg3P/ijZc7AXr1WghGmPngGoQgfuWfxjArEw QIw/x0iEMX5ehpSQtOyYMl12bbDvA1Si+aFxUh2gujJD0KOi5xgqU3Wtg5QDyLIIa/0T DFCyMlpQfvKACJ9XAOySAyaycw94da1xd4uHYE4UiMRtumrOPi8ElzKK+INbRgRiGQtQ iE2jmKDaaKDMP7DClmSqkRr2LGAEqftXX9EJePod6VwRjXDLQpbbxPdHkEHGPIMkGwoB 8KwA== X-Gm-Message-State: AOJu0YydlxywFP/S2P/aTdw5Ja4cqo5LdRB0nG6WE9PEx3JEL7J0ETuS I4v5yTF5RiLkYtVJl/KeC58O1QaBDcM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:549:b0:da3:b96c:6c48 with SMTP id z9-20020a056902054900b00da3b96c6c48mr39857ybs.9.1698849717105; Wed, 01 Nov 2023 07:41:57 -0700 (PDT) Date: Wed, 1 Nov 2023 07:41:55 -0700 In-Reply-To: <96c30a78fa95071e87045b7293c2cf796d4182a0.camel@redhat.com> Mime-Version: 1.0 References: <20230914063325.85503-1-weijiang.yang@intel.com> <20230914063325.85503-10-weijiang.yang@intel.com> <96c30a78fa95071e87045b7293c2cf796d4182a0.camel@redhat.com> Message-ID: Subject: Re: [PATCH v6 09/25] KVM: x86: Rework cpuid_get_supported_xcr0() to operate on vCPU data From: Sean Christopherson To: Maxim Levitsky Cc: Yang Weijiang , pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, dave.hansen@intel.com, peterz@infradead.org, chao.gao@intel.com, rick.p.edgecombe@intel.com, john.allen@amd.com Content-Type: text/plain; charset="us-ascii" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 01 Nov 2023 07:42:05 -0700 (PDT) On Tue, Oct 31, 2023, Maxim Levitsky wrote: > On Thu, 2023-09-14 at 02:33 -0400, Yang Weijiang wrote: > > From: Sean Christopherson > > > > Rework and rename cpuid_get_supported_xcr0() to explicitly operate on vCPU > > state, i.e. on a vCPU's CPUID state. Prior to commit 275a87244ec8 ("KVM: > > x86: Don't adjust guest's CPUID.0x12.1 (allowed SGX enclave XFRM)"), KVM > > incorrectly fudged guest CPUID at runtime, > Can you explain how commit 275a87244ec8 relates to this patch? > > > which in turn necessitated massaging the incoming CPUID state for > > KVM_SET_CPUID{2} so as not to run afoul of kvm_cpuid_check_equal(). > > Can you link the commit that added this 'massaging' and explain on how this > relates to this patch? It's commit 275a87244ec8, which is right above. I think the missing part is an explicit call out that the massaging used cpuid_get_supported_xcr0() with the incoming "struct kvm_cpuid_entry2", i.e. without a "struct kvm_vcpu". > Can you explain what is the problem that this patch is trying to solve? Is this better? -- Rework and rename cpuid_get_supported_xcr0() to explicitly operate on vCPU state, i.e. on a vCPU's CPUID state, now that the only usage of the helper is to retrieve a vCPU's already-set CPUID. Prior to commit 275a87244ec8 ("KVM: x86: Don't adjust guest's CPUID.0x12.1 (allowed SGX enclave XFRM)"), KVM incorrectly fudged guest CPUID at runtime, which in turn necessitated massaging the incoming CPUID state for KVM_SET_CPUID{2} so as not to run afoul of kvm_cpuid_check_equal(). I.e. KVM also invoked cpuid_get_supported_xcr0() with the incoming CPUID state, and thus without an explicit vCPU object. -- > Is it really allowed in x86 spec to have different supported mask of XCR0 bits > on different CPUs (assuming all CPUs of the same type)? Yes, nothing in the SDM explicitly states that all cores in have identical feature sets. And "assuming all CPUs of the same type" isn't really a valid constraint because it's very doable to put different SKUs into a multi-socket system. Intel even (somewhat inadvertantly) kinda sorta shipped such CPUs, as Alder Lake P-cores support AVX512 but E-cores do not, and IIRC early (pre-production?) BIOS didn't disable AVX512 on the P-Cores, i.e. software could observe cores with and without AVX512. That quickly got fixed because it confused software, but until Intel squashed AVX512 entirely with a microcode update, disabling E-Cores in BIOS would effectively enable AVX512 on the remaining P-Cores. And it's not XCR0-related, but PMUs on Alder Lake (and all Intel hybrid CPUs) are truly heterogenous. It's a mess for virtualization, but concrete proof that there are no architectural guarantees regarding homogeneity of feature sets. > If true, does KVM supports it? Yes. Whether or not that's a good thing is definitely debatle, bug KVM's ABI for a very long time has allowed userspace to expose whatever it wants via KVM_SET_CPUID. Getting (guest) software to play nice is an entirely different matter, but exposing heterogenous vCPUs isn't an architectural violation.