Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp2562978rdd; Fri, 12 Jan 2024 13:38:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcU5oKHRGqmt7rjI6kNFW0f+aJG5gFNUTsDa1K5WkSWuMJEzfKzz6IEO2jnTvOqPVARKzt X-Received: by 2002:a05:622a:44b:b0:429:c66b:c2f9 with SMTP id o11-20020a05622a044b00b00429c66bc2f9mr2538570qtx.104.1705095493135; Fri, 12 Jan 2024 13:38:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705095493; cv=none; d=google.com; s=arc-20160816; b=Fn5DkajiOicw5yB0iapM+TZ7SRwKh3saGKQIIQ67/nvfZHZ9GcE/9lKPR+KNQlxWs0 eqOwCxZ7WOzVML+fZr5NplLqNlc0Wu/CuJmBI0VATMHBw3eE9iTKYtkgPmbU8A31Y8zF rLgBWcqXnY39D/xi3g64WkNyWvads/6s2hUZWRLGjcr+y3GgFRpup1VDu/lii3ENCu9a EpKOh6nfImG45p3zOjOTAO9axq3uyVBxLuQmyWhvYjOGa8Vrh9CC7o9iXkgn2THDLjuc 56UsSDvZM1G3KiBdkxuNjN9uWWBAfIn0z/pd1MSsRPDdgqJoxRE6Vi7bN27mYAYS2RwV ij9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=jG4xr+IJ1pGejJdBIle2Hs7xpC517ms091KPl27ARDY=; fh=Z45WPoZiS6KTbK+CIGQdgcP3fCfYVXVMiZR63x9PaPU=; b=EYXzqQAYDiRVTAD+UF2uertS3InMwGMJfq10aVUI1i3iJsX4K3P1UBsQnAmWTs8Ea0 VvxtmPbyln1M6F/lGQuD6BCgajv7NSxbrkWG51WFwkbGP/+7FvzZMQph7laQVdhQmvMS 8gVeaggH3dJ29JUA0U8QqL7gaqBFEV7QYovXhLAEwfyRVRs7B1qJxXLW9UeI2rgwu+XV BUL+tU9wiyA/XR2WUUoWLougnlp981rLjlALXBsLdaziVEmGDP2hClEjqiUqVa6/2b6V OfoYXuLHaufT3KlUVNXZMWiCBFWPkwlTu0TFAwrBnEPqs1YpfXsSZ8SwKHyy6Rh8xbiH GFpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YRFLi26J; spf=pass (google.com: domain of linux-kernel+bounces-25048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25048-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 b7-20020a05622a020700b004299880c545si3856035qtx.155.2024.01.12.13.38.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Jan 2024 13:38:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-25048-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=YRFLi26J; spf=pass (google.com: domain of linux-kernel+bounces-25048-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-25048-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 D08001C21C8A for ; Fri, 12 Jan 2024 21:38:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6300517734; Fri, 12 Jan 2024 21:38:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YRFLi26J" 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 55458175A8 for ; Fri, 12 Jan 2024 21:38:01 +0000 (UTC) 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-5e9de9795dfso136107947b3.0 for ; Fri, 12 Jan 2024 13:38:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705095480; x=1705700280; 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=jG4xr+IJ1pGejJdBIle2Hs7xpC517ms091KPl27ARDY=; b=YRFLi26JdwwqfoGm4D2eO41OW0+mjXerEW19jAW4CpTGFIwsBfdEjaHT4BfpMuTD5P Gu1G/Rz7WgcpIoQMWJyK1q2m9NnnJYtgFmmxzvRbZ9X2LmI4geQ/8kEkXUUd6AvMXuTa JA1rHzzHeHzlp1jI1Pc4z59K0eqvWbEVvFDTjQtPe0M+pxac5hShbuubGDyBn/7o4b70 LPiaBq0ZsBCu27gNaThnvV4wf7XhG1I/bPdMDnnrjCpf3fxF+fhMkVKD37RcT39VB4dV wHZ1fWLkhF1wr74GfpjWSkI3koRG0S+sUPYZ07Mgs4DuNLQ+stInmycopfc4ksNHliik EHjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705095480; x=1705700280; 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=jG4xr+IJ1pGejJdBIle2Hs7xpC517ms091KPl27ARDY=; b=jNbsGA80ZUwudfTh5iLTLOCpWpsRJh0d2PJsYXbTN6QvWxujLlzfhr/RV8hAkHniJG soCsbYLTqmQCntkOFPNUZK5cQAItAnVivzGeMvEwrAwaPB/5jIidBc4ihpBS9kS803VM gmZCAsp9vYzNvbMqr5po6zOjdlqVLXfBxR7sqrRF4VaOJumXBXmoopkhnUAwJHyKsoE1 Qc+2e31e7ayRwi/o2vtCiwGzvoYJpk5uQ+YsNNwNes8JENF5Z7NCtHYccbvRPntaDFlW EgcK0jE6pYsB158/dTpCMvcdDiDA7XU2EW6XTkd/WxNY7xEAkVRouArJV1UXbvJxrIc2 gMiw== X-Gm-Message-State: AOJu0YzVp2EOl9iVTx1PWgQsnKwXczE8xuBDU4W+/+YxBfc4FiIJbjFH FAKIQoMjUFBRgk1Am6/17evVVKp9bZOVrwQalg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:220b:b0:dbd:b7cb:8a61 with SMTP id dm11-20020a056902220b00b00dbdb7cb8a61mr624141ybb.2.1705095480409; Fri, 12 Jan 2024 13:38:00 -0800 (PST) Date: Fri, 12 Jan 2024 13:37:58 -0800 In-Reply-To: <5f51fda5-bc07-42ac-a723-d09d90136961@linux.intel.com> 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="us-ascii" 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 generate 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 = _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? I'm hesitant to add an assertion of any king without the ability to actually test the code.