close_clears_pmcc_test.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright 2014, Michael Ellerman, IBM Corp.
  3. * Licensed under GPLv2.
  4. */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <setjmp.h>
  8. #include <signal.h>
  9. #include "ebb.h"
  10. /*
  11. * Test that closing the EBB event clears MMCR0_PMCC, preventing further access
  12. * by userspace to the PMU hardware.
  13. */
  14. int close_clears_pmcc(void)
  15. {
  16. struct event event;
  17. event_init_named(&event, 0x1001e, "cycles");
  18. event_leader_ebb_init(&event);
  19. FAIL_IF(event_open(&event));
  20. ebb_enable_pmc_counting(1);
  21. setup_ebb_handler(standard_ebb_callee);
  22. ebb_global_enable();
  23. FAIL_IF(ebb_event_enable(&event));
  24. mtspr(SPRN_PMC1, pmc_sample_period(sample_period));
  25. while (ebb_state.stats.ebb_count < 1)
  26. FAIL_IF(core_busy_loop());
  27. ebb_global_disable();
  28. event_close(&event);
  29. FAIL_IF(ebb_state.stats.ebb_count == 0);
  30. /* The real test is here, do we take a SIGILL when writing PMU regs now
  31. * that we have closed the event. We expect that we will. */
  32. FAIL_IF(catch_sigill(write_pmc1));
  33. /* We should still be able to read EBB regs though */
  34. mfspr(SPRN_EBBHR);
  35. mfspr(SPRN_EBBRR);
  36. mfspr(SPRN_BESCR);
  37. return 0;
  38. }
  39. int main(void)
  40. {
  41. return test_harness(close_clears_pmcc, "close_clears_pmcc");
  42. }