}
 EXPORT_SYMBOL_GPL(riscv_pmu_get_hpm_info);
 
+static unsigned long pmu_sbi_get_filter_flags(struct perf_event *event)
+{
+       unsigned long cflags = 0;
+       bool guest_events = false;
+
+       if (event->attr.config1 & RISCV_PMU_CONFIG1_GUEST_EVENTS)
+               guest_events = true;
+       if (event->attr.exclude_kernel)
+               cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_VSINH : SBI_PMU_CFG_FLAG_SET_SINH;
+       if (event->attr.exclude_user)
+               cflags |= guest_events ? SBI_PMU_CFG_FLAG_SET_VUINH : SBI_PMU_CFG_FLAG_SET_UINH;
+       if (guest_events && event->attr.exclude_hv)
+               cflags |= SBI_PMU_CFG_FLAG_SET_SINH;
+       if (event->attr.exclude_host)
+               cflags |= SBI_PMU_CFG_FLAG_SET_UINH | SBI_PMU_CFG_FLAG_SET_SINH;
+       if (event->attr.exclude_guest)
+               cflags |= SBI_PMU_CFG_FLAG_SET_VSINH | SBI_PMU_CFG_FLAG_SET_VUINH;
+
+       return cflags;
+}
+
 static int pmu_sbi_ctr_get_idx(struct perf_event *event)
 {
        struct hw_perf_event *hwc = &event->hw;
        uint64_t cbase = 0;
        unsigned long cflags = 0;
 
-       if (event->attr.exclude_kernel)
-               cflags |= SBI_PMU_CFG_FLAG_SET_SINH;
-       if (event->attr.exclude_user)
-               cflags |= SBI_PMU_CFG_FLAG_SET_UINH;
-
+       cflags = pmu_sbi_get_filter_flags(event);
        /* retrieve the available counter index */
 #if defined(CONFIG_32BIT)
        ret = sbi_ecall(SBI_EXT_PMU, SBI_EXT_PMU_COUNTER_CFG_MATCH, cbase,