[v3,10/12] KVM: x86/mmu: Use BUILD_BUG_ON_INVALID() for KVM_MMU_WARN_ON() stub

Message ID 20230729004722.1056172-11-seanjc@google.com
State New
Headers
Series KVM: x86/mmu: Clean up MMU_DEBUG and BUG/WARN usage |

Commit Message

Sean Christopherson July 29, 2023, 12:47 a.m. UTC
  Use BUILD_BUG_ON_INVALID() instead of an empty do-while loop to stub out
KVM_MMU_WARN_ON() when CONFIG_KVM_PROVE_MMU=n, that way _some_ build
issues with the usage of KVM_MMU_WARN_ON() will be dected even if the
kernel is using the stubs, e.g. basic syntax errors will be detected.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/mmu/mmu_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Philippe Mathieu-Daudé Aug. 1, 2023, 2:04 p.m. UTC | #1
Hi Sean,

On 29/7/23 02:47, Sean Christopherson wrote:
> Use BUILD_BUG_ON_INVALID() instead of an empty do-while loop to stub out
> KVM_MMU_WARN_ON() when CONFIG_KVM_PROVE_MMU=n, that way _some_ build
> issues with the usage of KVM_MMU_WARN_ON() will be dected even if the
> kernel is using the stubs, e.g. basic syntax errors will be detected.
> 
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/mmu/mmu_internal.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> index 40e74db6a7d5..f1ef670058e5 100644
> --- a/arch/x86/kvm/mmu/mmu_internal.h
> +++ b/arch/x86/kvm/mmu/mmu_internal.h
> @@ -9,7 +9,7 @@
>   #ifdef CONFIG_KVM_PROVE_MMU
>   #define KVM_MMU_WARN_ON(x) WARN_ON_ONCE(x)
>   #else
> -#define KVM_MMU_WARN_ON(x) do { } while (0)
> +#define KVM_MMU_WARN_ON(x) BUILD_BUG_ON_INVALID(x)

No need to include <linux/build_bug.h> ? Anyhow,

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>

>   #endif
>
  
Sean Christopherson Aug. 1, 2023, 11:41 p.m. UTC | #2
On Tue, Aug 01, 2023, Philippe Mathieu-Daudé wrote:
> Hi Sean,
> 
> On 29/7/23 02:47, Sean Christopherson wrote:
> > Use BUILD_BUG_ON_INVALID() instead of an empty do-while loop to stub out
> > KVM_MMU_WARN_ON() when CONFIG_KVM_PROVE_MMU=n, that way _some_ build
> > issues with the usage of KVM_MMU_WARN_ON() will be dected even if the
> > kernel is using the stubs, e.g. basic syntax errors will be detected.
> > 
> > Signed-off-by: Sean Christopherson <seanjc@google.com>
> > ---
> >   arch/x86/kvm/mmu/mmu_internal.h | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
> > index 40e74db6a7d5..f1ef670058e5 100644
> > --- a/arch/x86/kvm/mmu/mmu_internal.h
> > +++ b/arch/x86/kvm/mmu/mmu_internal.h
> > @@ -9,7 +9,7 @@
> >   #ifdef CONFIG_KVM_PROVE_MMU
> >   #define KVM_MMU_WARN_ON(x) WARN_ON_ONCE(x)
> >   #else
> > -#define KVM_MMU_WARN_ON(x) do { } while (0)
> > +#define KVM_MMU_WARN_ON(x) BUILD_BUG_ON_INVALID(x)
> 
> No need to include <linux/build_bug.h> ?

It's indirectly included via

  linux/kvm_host.h => linux/bug.h => linux/build_bug.h

Depending on the day, I might argue for explicitly including all dependencies, but
in this case build_bug.h is a "core" header, and IMO there's no value added by
including it directly.
  
Philippe Mathieu-Daudé Aug. 2, 2023, 6:49 a.m. UTC | #3
On 2/8/23 01:41, Sean Christopherson wrote:
> On Tue, Aug 01, 2023, Philippe Mathieu-Daudé wrote:
>> Hi Sean,
>>
>> On 29/7/23 02:47, Sean Christopherson wrote:
>>> Use BUILD_BUG_ON_INVALID() instead of an empty do-while loop to stub out
>>> KVM_MMU_WARN_ON() when CONFIG_KVM_PROVE_MMU=n, that way _some_ build
>>> issues with the usage of KVM_MMU_WARN_ON() will be dected even if the
>>> kernel is using the stubs, e.g. basic syntax errors will be detected.
>>>
>>> Signed-off-by: Sean Christopherson <seanjc@google.com>
>>> ---
>>>    arch/x86/kvm/mmu/mmu_internal.h | 2 +-
>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
>>> index 40e74db6a7d5..f1ef670058e5 100644
>>> --- a/arch/x86/kvm/mmu/mmu_internal.h
>>> +++ b/arch/x86/kvm/mmu/mmu_internal.h
>>> @@ -9,7 +9,7 @@
>>>    #ifdef CONFIG_KVM_PROVE_MMU
>>>    #define KVM_MMU_WARN_ON(x) WARN_ON_ONCE(x)
>>>    #else
>>> -#define KVM_MMU_WARN_ON(x) do { } while (0)
>>> +#define KVM_MMU_WARN_ON(x) BUILD_BUG_ON_INVALID(x)
>>
>> No need to include <linux/build_bug.h> ?
> 
> It's indirectly included via
> 
>    linux/kvm_host.h => linux/bug.h => linux/build_bug.h
> 
> Depending on the day, I might argue for explicitly including all dependencies, but
> in this case build_bug.h is a "core" header, and IMO there's no value added by
> including it directly.

OK, fine then, thanks!
  

Patch

diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h
index 40e74db6a7d5..f1ef670058e5 100644
--- a/arch/x86/kvm/mmu/mmu_internal.h
+++ b/arch/x86/kvm/mmu/mmu_internal.h
@@ -9,7 +9,7 @@ 
 #ifdef CONFIG_KVM_PROVE_MMU
 #define KVM_MMU_WARN_ON(x) WARN_ON_ONCE(x)
 #else
-#define KVM_MMU_WARN_ON(x) do { } while (0)
+#define KVM_MMU_WARN_ON(x) BUILD_BUG_ON_INVALID(x)
 #endif
 
 /* Page table builder macros common to shadow (host) PTEs and guest PTEs. */