Re: xen_exit_mmap() questions

From: Ingo Molnar
Date: Thu Apr 27 2017 - 02:27:54 EST



* Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx> wrote:

> > xen_mc_issue() does:
> >
> > if ((paravirt_get_lazy_mode() & mode) == 0)
> > xen_mc_flush();
> >
> > I assume the load_cr3() is intended to deal with the case where we're
> > in lazy mode, but we'll still be in lazy mode, right? Or does it
> > serve some other purpose?
>
> Of course. I can't read (I ignored the "== 0" part).

Ha, ob'sidenote: the preferred form to write this is:

if (!(paravirt_get_lazy_mode() & mode))
xen_mc_flush();

... exactly due to the readability problem you ran into: a 'pre' negation is much
easier to read, plus '==' tends to trigger 'equal to' attributes in the brain,
which is the opposite of negation. So it's very easy to mis-read such syntactic
constructs even if they are technically correct.

I think '== 0' should be forbidden in all cases where the purpose is a logic
operation and should be used strictly only in cases where we do explicit integer
arithmetics.

(Bools and '== false' are suboptimal for similar reasons.)

... but I digress!

Ingo