[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v4 5/7] xen/riscv: introduce and initialize SBI RFENCE extension
On 14.08.2024 17:41, oleksii.kurochko@xxxxxxxxx wrote: > On Tue, 2024-08-13 at 11:34 +0200, Jan Beulich wrote: >> On 09.08.2024 18:19, Oleksii Kurochko wrote: >>> +static unsigned long sbi_major_version(void) >>> +{ >>> + return (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) & >>> + SBI_SPEC_VERSION_MAJOR_MASK; >>> +} >> >> Can you use MASK_EXTR() here, allowing to even drop the separate >> SBI_SPEC_VERSION_MAJOR_SHIFT? > I am not sure that: > (sbi_spec_version >> SBI_SPEC_VERSION_MAJOR_SHIFT) & > SBI_SPEC_VERSION_MAJOR_MASK == MASK_EXTR(sbi_spec_version, > SBI_SPEC_VERSION_MAJOR_MASK) How come you're not sure? That's precisely what MASK_EXTR() is for. >>> +static long sbi_ext_base_func(long fid) >>> +{ >>> + struct sbiret ret; >>> + >>> + ret = sbi_ecall(SBI_EXT_BASE, fid, 0, 0, 0, 0, 0, 0); >>> + if ( !ret.error ) >>> + return ret.value; >>> + else >>> + return ret.error; >> >> With the folding of two distinct values, how is the caller going to >> tell failure from success? > By checking if the return value is < 0. > According to the SBI spec [ > https://github.com/riscv-non-isa/riscv-sbi-doc/blob/master/src/binary-encoding.adoc?plain=1#L32 > ] ret.error can be or 0 ( which means success ) or something < 0 if it > was a failure. Right. And what if ret.error was 0, but ret.value was negative? >>> +int sbi_remote_sfence_vma(cpumask_t *cpu_mask, >>> + unsigned long start_addr, >>> + unsigned long size) >>> +{ >>> + return __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, >>> + cpu_mask, start_addr, size, 0, 0); >> >> No check (not even an assertion) here for __sbi_rfence still being >> NULL? > I thought that it would be enough to have BUG_ON() in sbi_init() but > then probably would be better to update the message inside BUG_ON(): > int __init sbi_init(void) > { > .... > > if ( !sbi_has_rfence() ) > { > BUG_ON("At the moment flush_xen_tlb_range_va() uses SBI rfence > to " > "flush TLB for all CPUS!"); I never really liked this kind of BUG_ON(). I leave it uncommented in code which clearly is only temporary. Plus imo such BUG_ON()s want to be next to where the risk is, i.e. in this case ahead of the possible NULL deref. Then again, without PV guests and without anything mapped at VA 0, you'll crash cleanly anyway. So perhaps my request to add a check went too far. Jan
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |