Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp108056lqn; Thu, 11 Apr 2024 15:55:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXP07r7CmfA2c6McIbc9xnjFdvpJVjGdmH5tCYXhAzZvbuUVYrK83McvGJEdkzRJTx/261HkstsXszh4JQhyVMsVP5NyLrRXVK34XahSw== X-Google-Smtp-Source: AGHT+IEukDCGbj12BHxjo0HToFa3yNzqiZoxTWSS9IoFLY0gdyaKdNRqiXQ/kzKqAbF/1kqNKCDG X-Received: by 2002:a2e:3209:0:b0:2d6:8e88:5a8b with SMTP id y9-20020a2e3209000000b002d68e885a8bmr700004ljy.32.1712876146299; Thu, 11 Apr 2024 15:55:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712876146; cv=pass; d=google.com; s=arc-20160816; b=rBhGqdLnYPHloRzZRqEb/8Pow1tuLpTBVVL/h987rKfH5ETezkqTuHW2hWo79Kj64E dTivWbubhM5o9c2s30zaLsM/miwCEXlGrs/FA3efZ3WJAhNMLERawMYD5AQaOSBA6n28 YxTn8CUCs+2b8jgNxRp0O2i/VkogKCjUi0Sm5b/C28G46Qc+nPj6ZrL6zBq+q7f77XDr tCDmw5M8tY5SFcNPAopvPCAfwCh9RzQ2mon91/3DcdazTiMZoeJMyq6/nxRRdAyjnUKo Hy50AtchR6lY71kh/NUawuAIfJFBysxKZvz+B7h2G5PtHMJ/+UkAlHIFgul6PDxRWBHc RujQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :in-reply-to:date:dkim-signature; bh=x13dHL4gzEYkC5yKNBRYRVXjtZD/neiLlxBKsx/gpJ8=; fh=wmc52xHr9qotr6pFfikKOtkUF/LCGFCYhau+l2z0jPU=; b=XybQs+U1KgCKJNqrLS7ob2MA4FrA/2WmcBI8U2IRIL+IxCBCpF62axPqou0lTHA/m7 zQCkGt9f1l++SF+wn68yGP3zsrXyYeHSmTBjtuFIRlhnzSqKai/uwNe/6XLiw31olLxb 94fgDXX1tnlkFS/pLtj5JOjd9qehHHT+uyk9yAkk51AjXImu5rwm6YKYDkO5j5YfS/Op aAia1M97j1MAP5Tu2EY+mtBsTcA3Xbv3YLr+k4PafeXNH4KO9yvcpCqyxLDM7Xw4DoVi azxi1xGkriVaxMR6vL/QvzZLaRMFvKILN4MCY1sJ+M+YTDqIFfkxoE6pNzX48IqgVlPY GxzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Q1/m0iWf"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141687-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ox8-20020a170907100800b00a51a4052df1si1128303ejb.569.2024.04.11.15.55.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 15:55:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Q1/m0iWf"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141687-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141687-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 09B5D1F2442B for ; Thu, 11 Apr 2024 22:55:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D212148CDD; Thu, 11 Apr 2024 22:54:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Q1/m0iWf" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 9F65946542 for ; Thu, 11 Apr 2024 22:54:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876083; cv=none; b=Ye5plK1U88wJaOAIETGuKdhGnxuVrzF7Ee6UuU++qghEDpLbc1k883ai6v4GnVZ8HAAhu3rSe7nuaOlZuc5R/t11aHc5NxJvP0ajcOJP12ckDjr2dvT3fIxvsqGCR2UIMJr8WCbkW5Np0k8ToEntjV3X+YPCHmdYPqRclxlsmTw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712876083; c=relaxed/simple; bh=FFF4qSI6uoBBrGIK3b9FdhqLuckQUcIQtIymnNKbd68=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MxglS3o7zrJpNrmVw87NSTX5JVY3wINBBP8BqEpJES/d4XUj2aoxIPJ0zsAY+xmDGdDfzUZfqbx6yItI1S8ErKZgX5K4xYnxfx1qCER3bz8hyjAPi4rCd6OuqsY8WzFkFsAZ6q6uJeAyCg7YINne6KvRDSXVt6K+PpQMgv7idv4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Q1/m0iWf; arc=none smtp.client-ip=209.85.219.201 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=flex--seanjc.bounces.google.com Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6ceade361so624941276.0 for ; Thu, 11 Apr 2024 15:54:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712876080; x=1713480880; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=x13dHL4gzEYkC5yKNBRYRVXjtZD/neiLlxBKsx/gpJ8=; b=Q1/m0iWf6n48oMA85o7SsuG2KOZVNmp1zhDFJG8KkaBUxRf7ZsKWmjON4/Vlsmqth3 Y1y1Sgt6LCxttV9P3/hQA+R/n+UbAT3RuuOwYkNKgm1Oc7IxDmy6sHm4RHf0uisV2jeB zjCFo+ZL/uWAZnrKdtWOuRbrZxljF/Vaslm5KurmYlAvbowgu4OnTAe4rtoIM1/L2t+p ++UYVUtYq4BJWYVcTMrEf5ilrpapvTBEPE0pFstiGA9Tzlj+KPNTbaFLZdIVY50/3CnT vhrTyjp9WVxsxK3M7jOlTRGs1mSg8V9Vy8/WjqaLLbi7ydxyZOHoOdOQM4K6mpJ1QytK xQaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712876080; x=1713480880; h=content-transfer-encoding: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=x13dHL4gzEYkC5yKNBRYRVXjtZD/neiLlxBKsx/gpJ8=; b=myaeYJGmfTH/EWmmFv2/VZtkqZ320XLIcIfCPadk10nXu6sVBMN8LC7tNT9Gfwcfaq osAg/SMeDqKXNRrywbuzPtjRWFv2hKBKZwswonUdpB4Rigtyt90LKD0Cw12s+D/FJ/pI faN8uAovBMryrAnZMPPt03avgOjZXef23MWcVcGiR5M4/1mpocLZjlGzCrsp/4GYWqi1 WH7JXPSBViwAIQv4aGo2w3S1MRZmZNwBfQ6NM0X2nLn1vE4MZPNqfc9B2ISmTus/WV4R mqut9ElU3VVNqTpK3tfj6VOIRoIxcUIuxQRZ1isST+sBATnPuQIqha4E2Y5CgqntVAEn wbHQ== X-Forwarded-Encrypted: i=1; AJvYcCU3rXs7D0CZgxWYMJwu8l2li37wPySvq8sG2weuVmAg3ymOcSMc3J8jjtD/AhGMrFxnMVhKFJPTBUTybf6iIMtPnyTHpTFMmu4Q5LJA X-Gm-Message-State: AOJu0YzUCXtokvFo0bGAQFxIdjkQwlauo45QlEvHJO0Wp+69f4tMqCOy XBpnVfTivyBEVSc/ORY/AUASM+8KfoYVutIepR0RfsjtaUhEgvFiHGcgS3t4KVqsw+CpD6Myl8t YGg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:1386:0:b0:dcb:abcc:62be with SMTP id 128-20020a251386000000b00dcbabcc62bemr238926ybt.6.1712876080655; Thu, 11 Apr 2024 15:54:40 -0700 (PDT) Date: Thu, 11 Apr 2024 15:54:39 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> <20240126085444.324918-29-xiong.y.zhang@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 28/41] KVM: x86/pmu: Switch IA32_PERF_GLOBAL_CTRL at VM boundary From: Sean Christopherson To: Jim Mattson Cc: Xiong Zhang , pbonzini@redhat.com, peterz@infradead.org, mizhang@google.com, kan.liang@intel.com, zhenyuw@linux.intel.com, dapeng1.mi@linux.intel.com, kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, zhiyuan.lv@intel.com, eranian@google.com, irogers@google.com, samantha.alt@intel.com, like.xu.linux@gmail.com, chao.gao@intel.com, Xiong Zhang Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 11, 2024, Jim Mattson wrote: > On Thu, Apr 11, 2024 at 2:54=E2=80=AFPM Sean Christopherson wrote: > > > > On Fri, Jan 26, 2024, Xiong Zhang wrote: > > > +static void save_perf_global_ctrl_in_passthrough_pmu(struct vcpu_vmx= *vmx) > > > +{ > > > + struct kvm_pmu *pmu =3D vcpu_to_pmu(&vmx->vcpu); > > > + int i; > > > + > > > + if (vm_exit_controls_get(vmx) & VM_EXIT_SAVE_IA32_PERF_GLOBAL_C= TRL) { > > > + pmu->global_ctrl =3D vmcs_read64(GUEST_IA32_PERF_GLOBAL= _CTRL); > > > + } else { > > > + i =3D vmx_find_loadstore_msr_slot(&vmx->msr_autostore.g= uest, > > > + MSR_CORE_PERF_GLOBAL_CT= RL); > > > + if (i < 0) > > > + return; > > > + pmu->global_ctrl =3D vmx->msr_autostore.guest.val[i].va= lue; > > > > As before, NAK to using the MSR load/store lists unless there's a *real= ly* good > > reason I'm missing. >=20 > The VM-exit control, "save IA32_PERF_GLOBAL_CTL," first appears in > Sapphire Rapids. I think that's a compelling reason. Well that's annoying. When was PMU v4 introduced? E.g. if it came in ICX,= I'd be sorely tempted to make VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL a hard require= ment. And has someone confirmed that the CPU saves into the MSR store list before processing VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL? Assuming we don't make VM_EXIT_SAVE_IA32_PERF_GLOBAL_CTRL a hard requiremen= t, this code should be cleaned up and simplified. It should be impossible to = get to this point with a passthrough PMU and no slot for saving guest GLOBAL_CT= RL. E.g. this could simply be: if (cpu_has_save_perf_global_ctrl()) pmu->global_ctrl =3D vmcs_read64(GUEST_IA32_PERF_GLOBAL_CTRL); else pmu->global_ctrl =3D *pmu->__global_ctrl; where vmx_set_perf_global_ctrl() sets __global_ctrl to: pmu->__global_ctrl =3D &vmx->msr_autostore.guest.val[i].value; KVM could store 'i', i.e. the slot, but in the end it's 4 bytes per vCPU (a= ssuming 64-bit kernel, and an int to store the slot). Oh, by the by, vmx_set_perf_global_ctrl() is buggy, as it neglects to *remo= ve* PERF_GLOBAL_CTRL from the lists if userspace sets CPUID multiple times.