Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1327226rdb; Tue, 30 Jan 2024 15:28:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFFj/UMOiuOSssRy3mY6i1bridtDGtCW6JauikAdActb1LWq9q6LIRSEo0NkTUJXbPFw1vO X-Received: by 2002:ae9:c103:0:b0:785:35d3:405f with SMTP id z3-20020ae9c103000000b0078535d3405fmr1611092qki.48.1706657300512; Tue, 30 Jan 2024 15:28:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706657300; cv=pass; d=google.com; s=arc-20160816; b=czAxvt33eYXewqY8cUDCxRXLlrg/KVthw0Mhtjchz0ap2BHSfb88slT1cCalR5iH7U iwjnqUxqNdcT55y3rl4yC0xoYOsO6bMbNsMmDagBtF33RqkS17bq1MYd9vIDYIn20l0z PtjMkQbZuYCspMs33W+hHB1PElEAN2bf8xyj2OA1xtJntJZk2hJ4ye7gK7rJ4EMXY4Ez whYZJ4mY8eJEUouWjHnEVbeytSUvzlUJI4unUUQJrJ923VkxprbYjYFLkHw9gU/CLNdA 9M27mUoL+a9yPOPMMJH/0KGJFRhawHmwsPKZv5jPMKuL3E3IpR8t9RtUugK99NVMZPyW sASg== 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=4LUZBTwgQWOqcUDdzUzVaclv3cSncxEYBiXIU8rhjPo=; fh=Z45WPoZiS6KTbK+CIGQdgcP3fCfYVXVMiZR63x9PaPU=; b=C5khXBOoCsxz+g1s3oRY1cuYKgnJUa43hDWEwxoh9zVNJNO4cUGTArFtApF4tg1Xg5 WDOUjv70zD6u+d2fSJP8hG0aNpGOXejdxKmEr8nL2SwrXR5SjYnRcpNWB9D5Wgp4vVyf KZ91gwo6+ue50tD8c0dUaMWTr3jL8WZaoq3+imwJEkGic6H97+8EDnvYCos69k8x5ZoI lfBDLsqDh3sGmj49VKaOC4VZOfAkLuyUj+yo33I72mbUdjK638vL7wLb+DR2g3htkKnC Qhp5X2XFEAO+Y2s3hNqkV1egRA2ZNs9p50BYUDNCuMWIBTWplMxpVUjyijIuuv7Lmaib 2Iug== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AX2A6ypD; 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-45478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45478-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id ou31-20020a05620a621f00b007831f4bd3d2si10657937qkn.393.2024.01.30.15.28.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 15:28:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=AX2A6ypD; 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-45478-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45478-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 3924A1C218C4 for ; Tue, 30 Jan 2024 23:28:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 454EF79DBE; Tue, 30 Jan 2024 23:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AX2A6ypD" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 A8CA579943 for ; Tue, 30 Jan 2024 23:27:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706657273; cv=none; b=u7+G1rRnt5zuf2E/gsS0OynnHesvbR0rhwB2qRu7DdUQvjJKuNf1swULZp/eAaW6URHIIx1DUZYLi5E740yvVE8cJi2oy/3m8VifzoeYDi4I4YI1o5x5J4CA3FnVoBef7hApKXCy+Fr1iqf/+NpfbECWobxr1uv1WoaV58hB7fc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706657273; c=relaxed/simple; bh=KfTemhN3MAvuoqt6yf5Kxs1pawxGT8UvKf0mXE649a4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=AFAm739HokbCPpwV8cFX+2tYVt78mAeqljz6nzWycoQk79y327unUNyBi4o26rMHIZaxKPc9CE1y17LRFRlijc+wt4Ov2CNZdndY5Yf3Bb2uj/lAL/J6/oEsoO1YCAtChqFvotnWI7/svEcr3M5zsbbdFvh3OP5jmn40tWpg3Ho= 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=AX2A6ypD; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-603f93acd7cso13043447b3.0 for ; Tue, 30 Jan 2024 15:27:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706657270; x=1707262070; 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=4LUZBTwgQWOqcUDdzUzVaclv3cSncxEYBiXIU8rhjPo=; b=AX2A6ypDaChfkgaj23qrbsy+YKRTa+OHCweeTH8CB7Zb1fNKwkOXSufQ316+JU3+kJ 4yvtd+gcam1mo7tVJNJ9tC1y0gGB9lY1JwOSMf+5fgLTbQ2A6jGXAkKeVuisKefq59xM MJ/kjG/Z7y8I6/I6Vjdwz6sILPcYQ9NI8n37k6y5dIV0T7+uIWxSsq+qTjov3X6Tzm09 cOn5HsqxQ2CK/YexloGxySgma737AzyVxk9qNmfKTixRs4+koaTegJGntBBDDoyeKoCP 6c1wN0wuabD8yO+MOzwec8bzKgmV5l3mutFvWMgi6TWTYLXYFOAs+2Udiu+BtCKH6GqD nRag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706657270; x=1707262070; 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=4LUZBTwgQWOqcUDdzUzVaclv3cSncxEYBiXIU8rhjPo=; b=SeCdp99XFUEGzZEFJ7ut4ksxI+tEmvX/t/TTdvPRf+2FNYgpFCThF56RuP+CrLoZQF xM1xeewyWfrqwoRjQ/mGslEfUUNlMSApptlAPaEg5V/UR10oN1T2B+5aGD7dmX+MUJ5Z pZR+y9iAGKyc+PlQUkK/ODwXDQGeXP3221H3GQ7fX4sllKQcyBdxdPi+5uJIIU0YSsaS V4LVC8wdCrX/Iy4y12NuwGr7MEG7iy48cBOvikyW6gK3XM1I53c7c467fFvjZDcmGZ68 rMa2hDtlTSq30P5Wp+1rBenPkc1tJbMGhDNWzRapM37y4tBSIIJnZwUWVvh6WTGgpvZZ qXRw== X-Gm-Message-State: AOJu0YxCQwgf0Bey19hwGVHU9m8aChWR+y/JlE/wduw+S6FjK0l7a7U0 Fegr9xulWZyg7u0cVn8ScN7oe/WhvoOXltdtNpnKEsqbjgXhZnmTWK5X/8IBU3ElqFjsFHQ/bRL EkQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:1b10:b0:dc6:9e4a:f950 with SMTP id eh16-20020a0569021b1000b00dc69e4af950mr14836ybb.3.1706657270711; Tue, 30 Jan 2024 15:27:50 -0800 (PST) Date: Tue, 30 Jan 2024 15:27:49 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240109230250.424295-1-seanjc@google.com> <20240109230250.424295-17-seanjc@google.com> <5f51fda5-bc07-42ac-a723-d09d90136961@linux.intel.com> Message-ID: Subject: Re: [PATCH v10 16/29] KVM: selftests: Test Intel PMU architectural events on gp counters From: Sean Christopherson To: Dapeng Mi Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Jim Mattson , Jinrong Liang , Aaron Lewis , Like Xu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, Jan 15, 2024, Dapeng Mi wrote: >=20 > On 1/13/2024 5:37 AM, Sean Christopherson wrote: > > On Fri, Jan 12, 2024, Dapeng Mi wrote: > > > On 1/10/2024 7:02 AM, Sean Christopherson wrote: > > > > +/* > > > > + * If an architectural event is supported and guaranteed to genera= te at least > > > > + * one "hit, assert that its count is non-zero. If an event isn't= supported or > > > > + * the test can't guarantee the associated action will occur, then= all bets are > > > > + * off regarding the count, i.e. no checks can be done. > > > > + * > > > > + * Sanity check that in all cases, the event doesn't count when it= 's disabled, > > > > + * and that KVM correctly emulates the write of an arbitrary value= . > > > > + */ > > > > +static void guest_assert_event_count(uint8_t idx, > > > > + struct kvm_x86_pmu_feature event, > > > > + uint32_t pmc, uint32_t pmc_msr) > > > > +{ > > > > + uint64_t count; > > > > + > > > > + count =3D _rdpmc(pmc); > > > > + if (!this_pmu_has(event)) > > > > + goto sanity_checks; > > > > + > > > > + switch (idx) { > > > > + case INTEL_ARCH_INSTRUCTIONS_RETIRED_INDEX: > > > > + GUEST_ASSERT_EQ(count, NUM_INSNS_RETIRED); > > > > + break; > > > > + case INTEL_ARCH_BRANCHES_RETIRED_INDEX: > > > > + GUEST_ASSERT_EQ(count, NUM_BRANCHES); > > > > + break; > > > > + case INTEL_ARCH_CPU_CYCLES_INDEX: > > > > + case INTEL_ARCH_REFERENCE_CYCLES_INDEX: > > > Since we already support slots event in below guest_test_arch_event()= , we > > > can add check for INTEL_ARCH_TOPDOWN_SLOTS_INDEX here. > > Can that actually be tested at this point, since KVM doesn't support > > X86_PMU_FEATURE_TOPDOWN_SLOTS, i.e. this_pmu_has() above should always = fail, no? >=20 > I suppose X86_PMU_FEATURE_TOPDOWN_SLOTS has been supported in KVM.=C2=A0 = The > following output comes from a guest with latest kvm-x86 code on the Sapph= ire > Rapids platform. >=20 > sudo cpuid -l 0xa > CPU 0: > =C2=A0=C2=A0 Architecture Performance Monitoring Features (0xa): > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 version ID=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =3D 0x2 (2) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 number of counters per logical processor = =3D 0x8 (8) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 bit width of counter=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 =3D 0x30 (48) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 length of EBX bit vector=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0 =3D 0x8 (8) > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 core cycle event=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D available > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 instruction retired event=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =3D available > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 reference cycles event=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 =3D available > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 last-level cache ref event=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D a= vailable > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 last-level cache miss event=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D availab= le > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 branch inst retired event=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =3D available > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 branch mispred retired event=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 =3D available > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 top-down slots event=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 =3D available >=20 > Current KVM doesn't support fixed counter 3 and pseudo slots event yet, b= ut > the architectural slots event is supported and can be programed on a GP > counter. Current test code can cover this case, so I think we'd better ad= d > the check for the slots count. Can you submit a patch on top, with a changelog that includes justification= that that explains exactly what assertions can be made on the top-down slots eve= nt given the "workload" being measured? I'm definitely not opposed to adding = coverage for top-down slots, but at this point, I don't want to respin this series, = nor do I want to make that change when applying on the fly.