Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/powerpc/pmu: Add selftest for checking invalid bits in event code

Some of the bits in the event code is reserved for specific platforms.
Event code bits 52-59 are reserved in power9, whereas in power10, these
are used for programming Monitor Mode Control Register 3 (MMCR3). Bit 9
in event code is reserved in power9, whereas it is used for programming
"radix_scope_qual" bit 18 in Monitor Mode Control Register 1 (MMCR1).

Testcase to ensure that using reserved bits in event code should cause
event_open to fail.

Signed-off-by: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20220610134113.62991-24-atrajeev@linux.vnet.ibm.com

authored by

Athira Rajeev and committed by
Michael Ellerman
5196a279 122b6b9e

+68 -1
+1 -1
tools/testing/selftests/powerpc/pmu/event_code_tests/Makefile
··· 3 3 4 4 TEST_GEN_PROGS := group_constraint_pmc56_test group_pmc56_exclude_constraints_test group_constraint_pmc_count_test \ 5 5 group_constraint_repeat_test group_constraint_radix_scope_qual_test reserved_bits_mmcra_sample_elig_mode_test \ 6 - group_constraint_mmcra_sample_test 6 + group_constraint_mmcra_sample_test invalid_event_code_test 7 7 8 8 top_srcdir = ../../../../../.. 9 9 include ../../../lib.mk
+67
tools/testing/selftests/powerpc/pmu/event_code_tests/invalid_event_code_test.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * Copyright 2022, Athira Rajeev, IBM Corp. 4 + */ 5 + 6 + #include <stdio.h> 7 + #include <sys/prctl.h> 8 + #include <limits.h> 9 + #include "../event.h" 10 + #include "../sampling_tests/misc.h" 11 + 12 + /* The data cache was reloaded from local core's L3 due to a demand load */ 13 + #define EventCode_1 0x1340000001c040 14 + /* PM_DATA_RADIX_PROCESS_L2_PTE_FROM_L2 */ 15 + #define EventCode_2 0x14242 16 + /* Event code with IFM, EBB, BHRB bits set in event code */ 17 + #define EventCode_3 0xf00000000000001e 18 + 19 + /* 20 + * Some of the bits in the event code is 21 + * reserved for specific platforms. 22 + * Event code bits 52-59 are reserved in power9, 23 + * whereas in power10, these are used for programming 24 + * Monitor Mode Control Register 3 (MMCR3). 25 + * Bit 9 in event code is reserved in power9, 26 + * whereas it is used for programming "radix_scope_qual" 27 + * bit 18 in Monitor Mode Control Register 1 (MMCR1). 28 + * 29 + * Testcase to ensure that using reserved bits in 30 + * event code should cause event_open to fail. 31 + */ 32 + 33 + static int invalid_event_code(void) 34 + { 35 + struct event event; 36 + 37 + /* Check for platform support for the test */ 38 + SKIP_IF(platform_check_for_tests()); 39 + 40 + /* 41 + * Events using MMCR3 bits and radix scope qual bits 42 + * should fail in power9 and should succeed in power10. 43 + * Init the events and check for pass/fail in event open. 44 + */ 45 + if (have_hwcap2(PPC_FEATURE2_ARCH_3_1)) { 46 + event_init(&event, EventCode_1); 47 + FAIL_IF(event_open(&event)); 48 + event_close(&event); 49 + 50 + event_init(&event, EventCode_2); 51 + FAIL_IF(event_open(&event)); 52 + event_close(&event); 53 + } else { 54 + event_init(&event, EventCode_1); 55 + FAIL_IF(!event_open(&event)); 56 + 57 + event_init(&event, EventCode_2); 58 + FAIL_IF(!event_open(&event)); 59 + } 60 + 61 + return 0; 62 + } 63 + 64 + int main(void) 65 + { 66 + return test_harness(invalid_event_code, "invalid_event_code"); 67 + }