Re: [PATCH v3 1/6] x86/alternatives: Teach text_poke_bp() to emulate instructions

From: Borislav Petkov
Date: Tue Oct 08 2019 - 11:24:18 EST

On Tue, Oct 08, 2019 at 11:04:12AM -0400, Steven Rostedt wrote:
> The difference between do_sync and i is that i gets incremented at
> every iteration, where do_sync gets incremented only when the first
> conditional is false. But I still see do_sync as a loop variable.

I'd prefer it this way:

do_sync = 0;

for (i = 0; i < nr_entries; i++) {
if (tp[i].text[0] == INT3_INSN_OPCODE)

text_poke(tp[i].addr, tp[i].text, sizeof(int3));

if (do_sync)
on_each_cpu(do_sync_core, NULL, 1);

Clear and simple. We clear it, the loop runs and we check it after the
loop ends. Clear and simple pattern which you see everywhere in code.
All well known and uneventful.

Now if the do_sync clearing is in the for () brackets, you have to stop
and look for it and wonder, why is that thing there, is there anything
special about it?

And with the amount of code going through us every day, I'd prefer well
known and uneventful in any day of the week.