Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * Copyright 2014, Michael Ellerman, IBM Corp.
0004  */
0005 
0006 #include <stdio.h>
0007 #include <stdlib.h>
0008 #include <setjmp.h>
0009 #include <signal.h>
0010 
0011 #include "ebb.h"
0012 
0013 
0014 /*
0015  * Test that closing the EBB event clears MMCR0_PMCC, preventing further access
0016  * by userspace to the PMU hardware.
0017  */
0018 
0019 int close_clears_pmcc(void)
0020 {
0021     struct event event;
0022 
0023     SKIP_IF(!ebb_is_supported());
0024 
0025     event_init_named(&event, 0x1001e, "cycles");
0026     event_leader_ebb_init(&event);
0027 
0028     FAIL_IF(event_open(&event));
0029 
0030     ebb_enable_pmc_counting(1);
0031     setup_ebb_handler(standard_ebb_callee);
0032     ebb_global_enable();
0033     FAIL_IF(ebb_event_enable(&event));
0034 
0035     mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
0036 
0037     while (ebb_state.stats.ebb_count < 1)
0038         FAIL_IF(core_busy_loop());
0039 
0040     ebb_global_disable();
0041     event_close(&event);
0042 
0043     FAIL_IF(ebb_state.stats.ebb_count == 0);
0044 
0045     /* The real test is here, do we take a SIGILL when writing PMU regs now
0046      * that we have closed the event. We expect that we will. */
0047 
0048     FAIL_IF(catch_sigill(write_pmc1));
0049 
0050     /* We should still be able to read EBB regs though */
0051     mfspr(SPRN_EBBHR);
0052     mfspr(SPRN_EBBRR);
0053     mfspr(SPRN_BESCR);
0054 
0055     return 0;
0056 }
0057 
0058 int main(void)
0059 {
0060     return test_harness(close_clears_pmcc, "close_clears_pmcc");
0061 }