Re: [PATCH] KVM: x86/mmu: fix comparison of u8 with -1

From: Nick Desaulniers
Date: Tue Nov 26 2019 - 12:24:29 EST


On Tue, Nov 26, 2019 at 8:21 AM Colin King <colin.king@xxxxxxxxxxxxx> wrote:
>
> From: Colin Ian King <colin.king@xxxxxxxxxxxxx>
>
> The comparison of the u8 value __entry->u with -1 is always
> going to be false because a __entry-u can never be negative.
> Fix this by casting it to a s8 integer.
>
> Addresses clang warning:
> arch/x86/kvm/./mmutrace.h:360:16: warning: result of comparison
> of constant -1 with expression of type 'u8' (aka 'unsigned char')
> is always false [-Wtautological-constant-out-of-range-compare]

(__entry->u is defined as a u8)

>
> Fixes: 335e192a3fa4 ("KVM: x86: add tracepoints around __direct_map and FNAME(fetch)")
> Signed-off-by: Colin Ian King <colin.king@xxxxxxxxxxxxx>
> ---
> arch/x86/kvm/mmutrace.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/mmutrace.h b/arch/x86/kvm/mmutrace.h
> index 7ca8831c7d1a..3466cd528a67 100644
> --- a/arch/x86/kvm/mmutrace.h
> +++ b/arch/x86/kvm/mmutrace.h
> @@ -357,7 +357,7 @@ TRACE_EVENT(
> __entry->r ? "r" : "-",
> __entry->spte & PT_WRITABLE_MASK ? "w" : "-",
> __entry->x ? "x" : "-",
> - __entry->u == -1 ? "" : (__entry->u ? "u" : "-"),
> + (s8)__entry->u == -1 ? "" : (__entry->u ? "u" : "-"),

Or could compare against 0xFF instead of -1. Either way, thanks for the patch.
Reviewed-by: Nick Desaulniers <ndesaulniers@xxxxxxxxxx>

> __entry->level, __entry->sptep
> )
> );


--
Thanks,
~Nick Desaulniers