Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp1461532rdb; Tue, 30 Jan 2024 21:50:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+RLnF6xw2jEph4+xCpafqeJoXcwhz/LiY2a0JyEj5oPYFk57JeX36Iyew4YpYmOaOZH5d X-Received: by 2002:a67:b307:0:b0:46c:a642:c6c3 with SMTP id a7-20020a67b307000000b0046ca642c6c3mr583394vsm.43.1706680212781; Tue, 30 Jan 2024 21:50:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706680212; cv=pass; d=google.com; s=arc-20160816; b=z3IuOpvqzChtKZtGgElSPVjFYZ/5Nc/6PQGaNxt/kIRXAMaBPd050Bo8DR0I/Za1vm Yo8/Njmj/rL9n7laWGhDEX8aExMoxeFm8qOA4m8MsSPIdS8XgOlPKdqnQ+paFQnQgmZ9 EC/a6+hogAdPog3RPqpP6JOxNaT7l/OhckoT6oujAZMs/YCXN0mu2aHaQxK9yrS1bkaB ATXhHzHHOlfQQ16pJ61APPWFaS28yp65pu0pKbyrmLQCjz1h0A/y4QcsUIJGSU1k+w3v qi5Hh8BzosERYEwDQpsCkTKrj7UrgYzBG+h9ShcmscgXZdhtj3Xwo4In8D6526qz+CQR zC1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=h2pv8OLz4U4zq7WW7bFM7qDoA3kjn7jR1x5CFBz2P6E=; fh=gbIosxO2SrgmpUXLF2Xaj3zebETc1zZcbZoyFDtTdWs=; b=zoEnlSTAWHwKwLrS7NIhBC4ezkmgK7eGOXHBDV+nQ5SP1AAq3kstc1hP/c6PIp7xNH TnttBiOqu6vSNZe4gqZqHHxkY28dtuMS+TRHH1eclConosNnnoFCYwDZmhhA9Bd5TG9u 7VUt1DWnMLB1/fsoR/TmWpsZmJFfVtCr10EPBS5BuycrXHLBIeSrqr1HpXcARIv65bxR KklPJixj9SAHqJlB3wB0QkWSWNXtOoSszvt4ciENDK1SB3dKkA2hW8eTrncTvoCIp51t tZsBNNe0YA+mQqoKL/DsOyMkFYdYTYRZPULM/M7zo3K1dpZCI4U2BxuVoXXEzScN3jpX B/pA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=FrYV8GpX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45625-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45625-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com X-Forwarded-Encrypted: i=1; AJvYcCUEEdWjPwsoTcz+ZjIWuxah9KKdWCsA++s+KAa+bNaCAA549trq2YkTkVxrkC0HG5o15HqTqQvjSGKFY76QeJWk7fYDlRaQlojq8z54RQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id q4-20020ad45744000000b0068c469e8e89si7892647qvx.262.2024.01.30.21.50.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 21:50:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45625-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=@intel.com header.s=Intel header.b=FrYV8GpX; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-45625-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45625-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 814AB1C254C0 for ; Wed, 31 Jan 2024 02:11:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D08C5667; Wed, 31 Jan 2024 02:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="FrYV8GpX" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AA019523B; Wed, 31 Jan 2024 02:11:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667088; cv=none; b=mcl3N5b0aftedAeki6QsjJ53F2tIIAj0h6Jlh2s6jMX9mVwufs9lR3w5GKp6hYYsF7xmjR9Mh1N/gBhduiczby+mE6AHjT4hMhb3yqn85+N3dba9vt7141EQgUTu/VaNjuu6IfNTGKGjTUc2Pof7dVrd6XWKH2FvZg75bn2HovU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706667088; c=relaxed/simple; bh=1eECbBTXJn2dJ3RKcITy2+8k4nSv/+0yUURQeFCZNHw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=suLeJsvHt9lfidM6BU8B5nyydsHO9HEvV0aCmrcNkMdTj0v6zR85A72cLVh22VW0VFd2c1iwXhqWvUGTfwAFNVAuUTMRwxysGYx8xIJ+7EWN5Dz7VJ8AIcXLUUZIlokCA2j+a1tcGdWKIYo1vNwtxmkpdFUqHnH9+gGReu+QI+E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=FrYV8GpX; arc=none smtp.client-ip=198.175.65.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706667087; x=1738203087; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=1eECbBTXJn2dJ3RKcITy2+8k4nSv/+0yUURQeFCZNHw=; b=FrYV8GpXf6eoW0guiCm70JnbkiUW9jB5QFCBhQMvVbx5jPaf01pFtw4I bjA/mCZ5XsYMN/Ud+dufkOh5GmNlaGDI/pdw0sXkF4AFDBCKHv7rnU/vF h1GHFLoat5kS/NpRNq+55O/4tqvQQ6MIG+QP2nW4xIoWRrqrcGHwuaUnn hOkk8VbVtLLwWWqiHANW8ol/iSWdArKvQdqYiWomOP1006F2fBAFmm0ow pUV12H2B2I8BL2RiJRJscFgskngnLaZokKuFf4J5aBujY56tkUtckzLVU afZNBfiAd88e3NNyyvrbyEJhfVmJKarO+h0NAdN7LQL4dge00TuD/VK94 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10969"; a="3317037" X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="3317037" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:11:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,231,1701158400"; d="scan'208";a="30333826" Received: from dapengmi-mobl1.ccr.corp.intel.com (HELO [10.93.12.33]) ([10.93.12.33]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2024 18:11:23 -0800 Message-ID: Date: Wed, 31 Jan 2024 10:11:20 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v10 16/29] KVM: selftests: Test Intel PMU architectural events on gp counters To: Sean Christopherson Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Kan Liang , Jim Mattson , Jinrong Liang , Aaron Lewis , Like Xu References: <20240109230250.424295-1-seanjc@google.com> <20240109230250.424295-17-seanjc@google.com> <5f51fda5-bc07-42ac-a723-d09d90136961@linux.intel.com> Content-Language: en-US From: "Mi, Dapeng" In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 1/31/2024 7:27 AM, Sean Christopherson wrote: > On Mon, Jan 15, 2024, Dapeng Mi wrote: >> 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 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 suppose X86_PMU_FEATURE_TOPDOWN_SLOTS has been supported in KVM.  The >> following output comes from a guest with latest kvm-x86 code on the Sapphire >> Rapids platform. >> >> sudo cpuid -l 0xa >> CPU 0: >>    Architecture Performance Monitoring Features (0xa): >>       version ID                               = 0x2 (2) >>       number of counters per logical processor = 0x8 (8) >>       bit width of counter                     = 0x30 (48) >>       length of EBX bit vector                 = 0x8 (8) >>       core cycle event                         = available >>       instruction retired event                = available >>       reference cycles event                   = available >>       last-level cache ref event               = available >>       last-level cache miss event              = available >>       branch inst retired event                = available >>       branch mispred retired event             = available >>       top-down slots event                     = available >> >> Current KVM doesn't support fixed counter 3 and pseudo slots event yet, but >> 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 add >> 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 event > 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. Yeah, I'm glad to submit a patch for this. :) BTW, I have a patch series to do the bug fixes and improvements for kvm-unit-tests/pmu test. (some improvement ideas come from this patchset.) https://lore.kernel.org/kvm/20240103031409.2504051-1-dapeng1.mi@linux.intel.com/ Could you please kindly review them? Thanks. >