Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1403818lqd; Thu, 25 Apr 2024 14:47:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXjSQXhH3QVmejM+59UtCHunRH/5LVq/G8uf42H95vsH9XcudzGaKRuAbpseWFE3ipOJC52PnM2RAa96xAcWoOFK2KSTFzVKnhAhUrZJg== X-Google-Smtp-Source: AGHT+IFKL4CCnevUK9k2rj+JdZ0Dttot4ZlmhEGX01rhoGww44RmB0B5ayaX+GXR7XrIftAPiTgR X-Received: by 2002:a50:d4ce:0:b0:56e:24a5:587a with SMTP id e14-20020a50d4ce000000b0056e24a5587amr609696edj.11.1714081657725; Thu, 25 Apr 2024 14:47:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714081657; cv=pass; d=google.com; s=arc-20160816; b=EF/NFD3I8ApuQJV28lEHVkb4pY3NYDaCk+z41gCJgEfLDOQqF4nf7OcdludbnDCxBt zz4AhuEkAxAZFO213+UqzybGeQUrdDyHoXp/910LliLW/OcQzAoa6jQPQbkWNZuocVGh Zg5em9o917gukGxf5IkKB0idk8/u1aJ/DRf29sQbVGGX95kEYAS2EXsxkGLBo41eayLi Z8Xktm7OFMcWew32ifwjFeqAtiMgnK8BpxLpEJJuCnYKGNRlrJ4B+vSlv2hfj/C3H9Gh KTqXFsBEOZNnCgBcidBqL1xFh9txqcdj40kGEcaHXaWVsaWUM8G0fzQacHJ9Y0AveV03 SB1g== 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=s9g005zQ0uoPXb33P7XvBANrUcDvwGxhLLo5EvZW0qw=; fh=i/22XUaHK2X5kG40RCrVbwSb3b61f2YrqI+apwxuHtc=; b=eWehpDU3OUaWMVeLgVhjpbK96fj50prm8D/ROfbrbjRudIHzs5tEGi4zP3Kp7xkFUx JmHE42JwbCyKvFYMzujz4ADKmzOVuYmoKj6UQoPVKbHkAkXr5kEjlrr7yySz5eU+sr6/ gJ3YQbQbBloUk5c62eSemE68+keS40VFLUMD5SG8tWLImatnhsWvmg72epTa6e3PRLwM LRvfBMSklTm4+ychT1y9OtUHtHIflAkn8ntV+0+frGVY+0XzwZ8Gnd1WonKqsBEbUAeH dgbtrbBNkrc/wLonQsXqKAmd3tWxu6jIVs1G7CcWMWN5aSGJ2xkyeOEEvBgB8XnxWtN+ XC9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=kSkLWvbg; 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-159241-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159241-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 y9-20020a50eb09000000b0057240420fdcsi1051259edp.518.2024.04.25.14.47.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 14:47:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159241-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=kSkLWvbg; 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-159241-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159241-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 754D81F214C0 for ; Thu, 25 Apr 2024 21:47:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D2EE156992; Thu, 25 Apr 2024 21:46:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="kSkLWvbg" Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (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 0496615664D for ; Thu, 25 Apr 2024 21:46:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714081566; cv=none; b=C3mvqYmBjiHwP3ZUvqarRyjT16XDYGW8inRFFbE5ve0eoEw9sJG1zOO2WYqgYeF14H/7Gk36P8jI5730Wu8hyx2Qznc4T77yAweaNIoi1902UGjwraPrYvCi7JKgdhIjYaVX21lK/zu6slKC3mnjcteDoVKXzdj4lzv3lUvs7Ds= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714081566; c=relaxed/simple; bh=ddLKxs1S7s/ADJE035dpDCdlheH8Ec/EUB9hgxSWCqA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ClGWuoP0eCoTYWg5+IY90tkHAZKUCjja2AaXFUpId704kPjiSHHwENQ8wfYDrD6vIKr6iUYMDxOuSz9lSDbkKIXkygYWJa+/tptzs1naPNkh7ZgAMAESY/dos0a6UvcL68jRB7MwQ4xjCjvekUm00mkTNzWl0Does/bRnPsy44U= 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=kSkLWvbg; arc=none smtp.client-ip=209.85.215.202 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-pg1-f202.google.com with SMTP id 41be03b00d2f7-5d8dd488e09so1688331a12.2 for ; Thu, 25 Apr 2024 14:46:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714081564; x=1714686364; 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=s9g005zQ0uoPXb33P7XvBANrUcDvwGxhLLo5EvZW0qw=; b=kSkLWvbg9oxhLeu4v+HlAcmDuMvp/TTyiIxrPO+Km5RX/EntkNjXgZDBRuDfgwewoT ddYYDw0g/r1E0G1QsMEMXC7bkcQ2JNGli1QfsoCaghQhA+ZEh4YdQXiesFhgp0Fd5gGZ f7IopQ4+W8w0TB4+vzeoNVwMeRUmp1YQfvTcHOLogHR3kp5exTbIwZvjwPFRY/ZgMPe6 mEU2au01Tjk2oSiqO4CHiWWQgmuSFZ3ThrhcMZBSTfjlrFVZV/Wksjb0NbkUBuYFAIUu HRvmQ1XECZBXWxtxxfX4usJjxSNUSmsXjoHGtnCfBtQP9xljJY21sEgKGZm8ALbWJf9e D3Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714081564; x=1714686364; 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=s9g005zQ0uoPXb33P7XvBANrUcDvwGxhLLo5EvZW0qw=; b=SpclIlBj+dLI9Fk+Eg0ocEgo4FPiIozbCDp0/wHw7euQeTohBWjPH7aWS7YyQrwhdA LyXay136qd9KZPcb/RSMjLE+lUkSblG24Rpu/cXvWzoxJwiB6NiCa8yc9onCXllGxCAL G9h8gHGJJuDk3Cx9lYP/7T7QAudkI8VmOm4p9c2Yg1Q0bh9XI/rvZ12ZaXsGex7HZ3r8 //aSxPyq5YwoSOh/Pmk1cQxMzPRVeYYKuBRIA0Uehw0Nokn7lu9xI8lEyChVdhDG3ZvQ NfwFJEOP0NBWtdWPTAv3j8bi20tBQu1EBcZmIj8poX8sAIyK16H+bxXiCxMSy/MlUI+g 9TYg== X-Forwarded-Encrypted: i=1; AJvYcCUw8vhSq7XDC2Rgcnvwj4LjupHZT1aEhJEakF6B/2aRdUsoGDGiwymUIBUob9AopPav2LS5Ep0I/V498cyAXdrJHtZ6I+dRmxV+O/1w X-Gm-Message-State: AOJu0Yykc96hy6g25fayi8pGGgC2ten7yfwt3d/PO0+oBETklDdQTF36 qeyFBqXGgb9AI+B6+tdsI90iId20N5WiI0xfQ+/qqDSTmUUQvAQighdyo7hsas61ZVIUUBSmhjE rrw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a63:2005:0:b0:5f7:fca4:6d2f with SMTP id g5-20020a632005000000b005f7fca46d2fmr25355pgg.7.1714081564026; Thu, 25 Apr 2024 14:46:04 -0700 (PDT) Date: Thu, 25 Apr 2024 14:46:02 -0700 In-Reply-To: <42acf1fc-1603-4ac5-8a09-edae2d85963d@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <7834a811-4764-42aa-8198-55c4556d947b@linux.intel.com> <6af2da05-cb47-46f7-b129-08463bc9469b@linux.intel.com> <42acf1fc-1603-4ac5-8a09-edae2d85963d@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 23/41] KVM: x86/pmu: Implement the save/restore of PMU state for Intel CPU From: Sean Christopherson To: Kan Liang Cc: Mingwei Zhang , Dapeng Mi , maobibo , Xiong Zhang , pbonzini@redhat.com, peterz@infradead.org, kan.liang@intel.com, zhenyuw@linux.intel.com, jmattson@google.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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Thu, Apr 25, 2024, Kan Liang wrote: > On 2024-04-25 4:16 p.m., Mingwei Zhang wrote: > > On Thu, Apr 25, 2024 at 9:13=E2=80=AFAM Liang, Kan wrote: > >> It should not happen. For the current implementation, perf rejects all > >> the !exclude_guest system-wide event creation if a guest with the vPMU > >> is running. > >> However, it's possible to create an exclude_guest system-wide event at > >> any time. KVM cannot use the information from the VM-entry to decide i= f > >> there will be active perf events in the VM-exit. > >=20 > > Hmm, why not? If there is any exclude_guest system-wide event, > > perf_guest_enter() can return something to tell KVM "hey, some active > > host events are swapped out. they are originally in counter #2 and > > #3". If so, at the time when perf_guest_enter() returns, KVM will ack > > that and keep it in its pmu data structure. >=20 > I think it's possible that someone creates !exclude_guest event after I assume you mean an exclude_guest=3D1 event? Because perf should be in a = state where it rejects exclude_guest=3D0 events. > the perf_guest_enter(). The stale information is saved in the KVM. Perf > will schedule the event in the next perf_guest_exit(). KVM will not know = it. Ya, the creation of an event on a CPU that currently has guest PMU state lo= aded is what I had in mind when I suggested a callback in my sketch: : D. Add a perf callback that is invoked from IRQ context when perf wants= to : configure a new PMU-based events, *before* actually programming the = MSRs, : and have KVM's callback put the guest PMU state It's a similar idea to TIF_NEED_FPU_LOAD, just that instead of a common chu= nk of kernel code swapping out the guest state (kernel_fpu_begin()), it's a callb= ack into KVM.