• Yosry Ahmed's avatar
    x86/mm: clarify "prev" usage in switch_mm_irqs_off() · 3cfd6625
    Yosry Ahmed authored
    In the x86 implementation of switch_mm_irqs_off(), we do not use the
    "prev" argument passed in by the caller, we use exclusively use
    "real_prev", which is cpu_tlbstate.loaded_mm.  This is not obvious at the
    first sight.
    
    Furthermore, a comment describes a condition that happens when called with
    prev == next, but this should not affect the function in any way since
    prev is unused.  Apparently, the comment is intended to clarify why we
    don't rely on prev == next to decide whether we need to update CR3, but
    again, it is not obvious.  The comment also references the fact that
    leave_mm() calls with prev == NULL and tsk == NULL, but this also
    shouldn't matter because prev is unused and tsk is only used in one
    function which has a NULL check.
    
    Clarify things by renaming (prev -> unused) and (real_prev -> prev), also
    move and rewrite the comment as an explanation for why we don't rely on
    "prev" supplied by the caller in x86 code and use our own.  Hopefully this
    makes reading the code easier.
    
    Link: https://lkml.kernel.org/r/20240126080644.1714297-2-yosryahmed@google.comSigned-off-by: default avatarYosry Ahmed <yosryahmed@google.com>
    Cc: Andy Lutomirski <luto@kernel.org>
    Cc: Borislav Petkov (AMD) <bp@alien8.de>
    Cc: Dave Hansen <dave.hansen@linux.intel.com>
    Cc: Ingo Molnar <mingo@redhat.com>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    3cfd6625
tlb.c 39.3 KB