Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1875025rdb; Wed, 31 Jan 2024 11:43:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IEliRshqWpx7Mx4c7tq8Bm9+lQTWOmVcgg4CPJPUm9R/selEZWyBvjWTRtjGn6vfOtx7UB6 X-Received: by 2002:a05:6214:19cd:b0:68c:5b0b:601 with SMTP id j13-20020a05621419cd00b0068c5b0b0601mr2579792qvc.59.1706730200095; Wed, 31 Jan 2024 11:43:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706730200; cv=pass; d=google.com; s=arc-20160816; b=eHpzW+CKtIQkFY7riKtIJFDVb7bhhz0ipKaA3pJvWhOMUJ3WIPkGUbi7F2COTgGOKN /z6tA6S0vsU1+mcWbjcnA0IHLvYD4hM0A0OokEGmYIMoKXNuoAuydlyCibVqtXq76HDT 8UOqHG0ajEwF3O/uqRdG99RHWi3hCJaGqUMTlYTWlIoxeqKQ3Y8FpqIIVPqMlUm7dJxk ZGyWx0DtwzK6CCcHfW+HS0VSyrbTPbcTpiBXaoa3M0Y5rBvx87HVhiy6gDptbZmVy0Br Tu3Dbem8QSolkyXaAEayg2Yev4yp1BaNR5nVBAOXTyb9dS9HCanq0P5ty5AJjqIub7pI ItlQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=cr3/DP7XTiupTVnBc4u5yU3Y9Y+FH/h9EKQ8I83CyCY=; fh=u23w9VztcRHhPUapYNwHArI52B8f1ziAg2gElBkaMoE=; b=rGTS+WkD5sFPm+EqbFeltlbXSfLt0cuEROSykeOS0z+nNddpgQL/0XDazJXdb7HFpZ jLi2361N8FaNDg8X1bsnNyvsvSpe4OMOARp2BZ9enAcMrp3Uf+EFP8T7XGoDnJYFg2Jh X0BTzfNClbYo6q7fNfubzVryLhwVnjZYh84dP6NWDZ11fhVG3Z1QQdf5ydKVJZSgNyMt WoA8Oa9AYZYB1EfWyeqw04JysDJC/nPsIRokSO8RXFLASQw0j4/HrpBspJh+nJ6Kat+6 m8UTOx6Sj1zEBI3N1M8713XlyUgBnoEYtQwb/BHdHqAHXsqnxLCXn6+3UdQA71gqDW3O M24Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wnstmyq6; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=1; AJvYcCV4tanyQZlsl9NlRYPuu2o+NnCDy0opvZhhcq14761C9dmtJ/MyDTAwSBkhK1vp9qVRHisYEw6jLiERO02X60+JVc2coHmIV/7UAyx58Q== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kl16-20020a056214519000b0068c469b28f0si8744787qvb.479.2024.01.31.11.43.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:43:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-47028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=wnstmyq6; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-47028-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-47028-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id C6E6C1C24D29 for ; Wed, 31 Jan 2024 19:43:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D97173EA98; Wed, 31 Jan 2024 19:43:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="wnstmyq6" Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 87D0E3E49D for ; Wed, 31 Jan 2024 19:43:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706730187; cv=none; b=pHYic26STS+NIJg0KbZV0r10nV25kM16CLK7GXYSOLwjNbttx34HhVwq3w3p0cWHzetuO6RyPo5t0GGOcCdRo2u5cyH8SiCEZ16dHhWoUrP5TnlNE8mI/bDsBA28dEnOLoa+N/sbhRIhCzruzHIBdCN5Wvu+en/GZ8S1dbXW4o4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706730187; c=relaxed/simple; bh=i4zKc6NhXiMSl9AuIN6/Dd9lQJhIilwgHlR+1G0X1UE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pvWaJcTmkR1SRTGXmchokXBdHU+N7/Ki8oO770+V1oOwzuVv4CldscdkGQ/iCw9lNRBQlGWiJ5kjlnlPjiRHQGKekMEQdptpLTKbQMpVB1kI0PeXCCL9lsx5OiTMztuexaTk/HuXH1LaB4OnYXYaE1UawbZ20m+kCiKcFpjliMc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=wnstmyq6; arc=none smtp.client-ip=209.85.215.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5bdbe2de25fso176793a12.3 for ; Wed, 31 Jan 2024 11:43:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706730185; x=1707334985; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cr3/DP7XTiupTVnBc4u5yU3Y9Y+FH/h9EKQ8I83CyCY=; b=wnstmyq6/yomqAUwPSvsMekgX0N7AtuzgzhJINNIYohbb3+/7XO+LHSeDSbrXcKVu3 JdkyNbuqECFaqv+Z7SHiEdp20OwFy472hJUV3be43veAreiPW3kbvHgCkLFNyDnLAw10 LqhaSkxiAgsQPdBkI/ce41sYsAYsaobupY6NJBLlMrpLABPhvthD1dQTlAurVcrduZAR 4NnqRlY28q4R493yWYkAFqN/Fwm1kGtfwtOhhsxcNtILVALp5bLt+Mvf2cYHZejCrp+2 OTE1PXiriZVxmAgs7Alh3u5kodkIRuZsFh1dMC7Ge0CgOm/FdCSG1aBtXDSzDYKWpprP JO1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706730185; x=1707334985; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=cr3/DP7XTiupTVnBc4u5yU3Y9Y+FH/h9EKQ8I83CyCY=; b=e2n2inCvelpe3wDAokn2f1VzGayw6lTjsUbnYWLFuLXdUcubcJYhKSjqsAAXfgu1KE GaNqNIFDGib7pV6O7pl6TICBEvtT/PdW90oEZpAmEDErivJc9qYmX3PpRPfEWx0pj3ZM JaiDPk+Q9kAfifzHkvSEjYYhAVrMaMdqFrp0rF4i7mzpdlPOZfMhRYkja48zTv77ARbi R6y42qW82p885lULCSm/giPOr4kv74DuOl5cK27FSjvbJ1hkKs6ntGgIxaiLUlhfgj9+ PukfxLV3FRP7ERhLFliNFR2ydU8Y8f0klOKCPBxnfb9GkGeygC1oaaR3jW9s0Mkt19SE UIjA== X-Gm-Message-State: AOJu0Yxx4UiFn3bAPi5ZXLFaebGTnDwt7TNacd6qaqBzKDGTdaHBKStS BM8T9v9EafMkGFzsFCTLUIioX0nKoqABjo/6SgbY/okoL8qx8UxpFI5zbnFGQw== X-Received: by 2002:a05:6a20:ba7:b0:19c:a980:58d6 with SMTP id i39-20020a056a200ba700b0019ca98058d6mr2532369pzh.2.1706730184553; Wed, 31 Jan 2024 11:43:04 -0800 (PST) X-Forwarded-Encrypted: i=0; AJvYcCW+Pmwekr6pGKH43l8LTrTPx/TDT45wLMdyer8MiHn77z1PbTGEAX/+GPDXwv4AgP1vTdvy17rkOYYaZn6Ea7m559tkEgbSRrADfrrclpVj+PoiJclfnEWeatlWnBp6Lfigo/4OEXNez77qvOL+x4NhYyJqheGkBKZGLHJAyyXokB3u6mOHtpe/oq8yIjgf+VHosCqSZ8Jo05W7AA== Received: from google.com (60.89.247.35.bc.googleusercontent.com. [35.247.89.60]) by smtp.gmail.com with ESMTPSA id nc8-20020a17090b37c800b0028c8a2a9c73sm1926517pjb.25.2024.01.31.11.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jan 2024 11:43:04 -0800 (PST) Date: Wed, 31 Jan 2024 19:43:00 +0000 From: Mingwei Zhang To: Paolo Bonzini Cc: Sean Christopherson , Aaron Lewis , "H. Peter Anvin" , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] KVM: x86/pmu: Reset perf_capabilities in vcpu to 0 if PDCM is disabled Message-ID: References: <20240124003858.3954822-1-mizhang@google.com> <20240124003858.3954822-2-mizhang@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Jan 29, 2024, Paolo Bonzini wrote: > On 1/24/24 23:51, Sean Christopherson wrote: > > > If we follow the suggestion by removing the initial value at vCPU > > > creation time, then I think it breaks the existing VMM code, since that > > > requires VMM to explicitly set the MSR, which I am not sure we do today. > > Yeah, I'm hoping we can squeak by without breaking existing setups. > > > > I'm 99% certain QEMU is ok, as QEMU has explicitly set MSR_IA32_PERF_CAPABILITIES > > since support for PDCM/PERF_CAPABILITIES was added by commit ea39f9b643 > > ("target/i386: define a new MSR based feature word - FEAT_PERF_CAPABILITIES"). > > > > Frankly, if our VMM doesn't do the same, then it's wildly busted. Relying on > > KVM to define the vCPU is irresponsible, to put it nicely. > > Yes, I tend to agree. Discussed with Sean offline. Yes, I also agree that this should be handled at VMM level. MSR_IA32_PERF_CAPABILITIES should be regarded as part of the CPUID, or sort of. The diff is that its own "KVM_GET_SUPPORTED_CPUID" (ie., the default value) should come from KVM_GET_MSRS of the device ioctl. Providing the default value for MSR_IA32_PERF_CAPABILITIES is really making things messed. KVM has to always guard access to the cached guest value with the checking of X86_FEATURE_PDCM. I believe guest_cpuid_has(vcpu, X86_FEATURE_PDCM) will take runtime cost. > > What QEMU does goes from the squeaky clean to the very debatable depending > on the parameters you give it. > > With "-cpu Haswell" and similar, it will provide values for all CPUID and > MSR bits that match as much as possible values from an actual CPU model. It > will complain if there are some values that do not match[1]. > > With "-cpu host", it will copy values from KVM_GET_SUPPORTED_CPUID and from > the feature MSRs, but only for features that it knows about. > > With "-cpu host,migratable=no", it will copy values from > KVM_GET_SUPPORTED_CPUID and from the feature MSRs, but only for *feature > words* (CPUID registers, or MSRs) that it knows about. This is where it > becomes debatable, because a CPUID bit could be added without QEMU knowing > the corresponding MSR. In this case, the user probably expects the MSR to > have a nonzero. On one hand I agree that it would be irresponsible, on the > other hand that's the point of "-cpu host,migratable=no". > > If you want to proceed with the change, I don't have any problem with > considering it a QEMU bug that it doesn't copy over to the guest any unknown > leaves or MSRs. > reply from another thread: CrosVM issue is not related to this one. It might have something to do with KVM_GET_MSR_INDEX_LIST. I will come up details later. > Paolo > > [1] Unfortunately it's not fatal because there are way way too many models, > and also because until recently TCG lacked AVX---and therefore could only > emulate completely some very old CPU models. But with "-cpu > Haswell,enforce" then everything's clean. >