On Fri, Jan 13, 2023 at 12:45:02PM +0100, Andrew Jones wrote: > On Thu, Dec 15, 2022 at 09:00:45AM -0800, Atish Patra wrote: ... > > + /* Start the counters that have been configured and requested by the guest */ > > + for_each_set_bit(i, &ctr_mask, RISCV_MAX_COUNTERS) { > > + pmc_index = i + ctr_base; > > + if (!test_bit(pmc_index, kvpmu->pmc_in_use)) > > + continue; > > + pmc = &kvpmu->pmc[pmc_index]; > > + if (flag & SBI_PMU_START_FLAG_SET_INIT_VALUE) > > + pmc->counter_val = ival; > > + if (pmc->perf_event) { > > + if (unlikely(pmc->started)) { > > + sbiret = SBI_ERR_ALREADY_STARTED; > > + continue; > > + } > > + perf_event_period(pmc->perf_event, pmu_get_sample_period(pmc)); > > + perf_event_enable(pmc->perf_event); > > + pmc->started = true; > > + } else { > > + kvm_debug("Can not start counter due to invalid confiugartion\n"); > ^ Cannot ^ configuration > > > + sbiret = SBI_ERR_INVALID_PARAM; > > + } > > + } > > Possibly a spec oversight is that we continue to try and start counters, > even when we've seen errors. The problem with implementing that is that > if we have both errors we only return the last one. I.e. one counter > was already started and another counter resulted in invalid-param, we > only return invalid-param. We also don't say anything about the number > of failures / successes. I think we should bail on the first error and > even stop counters that we started. Callers can then try again after > correcting their input without potentially getting already-started errors. > We'd need to change the spec to do that though. > Thinking about this some more, the spec doesn't prohibit implementations from bailing on the first error, so we can do that. But maybe we don't need to stop the counters we started. We can leave it to the driver to sort out what got configured/started and what didn't when it gets an error. Thanks, drew