Re: [PATCH V5 1/2] perf ignore LBR and extra_regs

From: Peter Zijlstra
Date: Mon Jul 14 2014 - 07:08:28 EST


On Thu, Jul 10, 2014 at 03:59:43AM -0700, kan.liang@xxxxxxxxx wrote:
> +/*
> + * Under certain circumstances, access certain MSR may cause #GP.
> + * The function tests if the input MSR can be safely accessed.
> + */
> +static inline bool check_msr(unsigned long msr)
> +{
> + u64 val_old, val_new, val_tmp;
> +
> + /*
> + * Read the current value, change it and read it back to see if it
> + * matches, this is needed to detect certain hardware emulators
> + * (qemu/kvm) that don't trap on the MSR access and always return 0s.
> + */
> + if (rdmsrl_safe(msr, &val_old))
> + goto msr_fail;
> + /*
> + * Only chagne it slightly,
> + * since the higher bits of some MSRs cannot be updated by wrmsrl.
> + * E.g. MSR_LBR_TOS
> + */
> + val_tmp = val_old ^ 0x3UL;
> + if (wrmsrl_safe(msr, val_tmp) ||
> + rdmsrl_safe(msr, &val_new))
> + goto msr_fail;
> +
> + if (val_new != val_tmp)
> + goto msr_fail;
> +
> + /* Here it's sure that the MSR can be safely accessed.
> + * Restore the old value and return.
> + */
> + wrmsrl(msr, val_old);
> +
> + return true;
> +
> +msr_fail:
> + return false;
> +}

I don't think we need the msr_fail thing, there's no state to clean up,
you can return false at all places you now have goto.

Attachment: pgpj45Vp4tmNv.pgp
Description: PGP signature