Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1394811 > unrolled thread

Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where?

Started byBrooks Moses <bmoses@google.com>
First post2016-05-05 02:50 +0200
Last post2016-05-09 17:50 +0200
Articles 8 — 4 participants

Back to article view | Back to linux.kernel


Contents

  Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Brooks Moses <bmoses@google.com> - 2016-05-05 02:50 +0200
    Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Borislav Petkov <bp@suse.de> - 2016-05-05 10:30 +0200
      Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Brooks Moses <bmoses@google.com> - 2016-05-05 21:20 +0200
      Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Paolo Bonzini <pbonzini@redhat.com> - 2016-05-09 16:10 +0200
        Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Radim Krčmář <rkrcmar@redhat.com> - 2016-05-09 16:50 +0200
          Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Paolo Bonzini <pbonzini@redhat.com> - 2016-05-09 17:20 +0200
            Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Radim Krčmář <rkrcmar@redhat.com> - 2016-05-09 17:30 +0200
              Re: Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where? Borislav Petkov <bp@suse.de> - 2016-05-09 17:50 +0200

#1394811 — Is BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where?

FromBrooks Moses <bmoses@google.com>
Date2016-05-05 02:50 +0200
SubjectIs BIT() in arch/x86/include/uapi/asm/kvm.h defined? Where?
Message-ID<rvfEm-6ak-7@gated-at.bofh.it>
Hello!

Ian and I have run into what looks like a bug in
arch/x86/include/uapi/asm/kvm.h, but it also looks so obvious that we
surely must be doing something wrong.  So I request enlightenment.

We discovered this problem on the 4.5.2 release, but the relevant code
appears unchanged from 2013 until current trunk.

When I run "make ARCH=x86 headers_install", and then write a simple C
file that #includes "asm/kvm.h" from the resulting tree, I get a
compiler error: the BIT() macro used on line 219 of that file is
undefined:
https://github.com/torvalds/linux/blob/master/arch/x86/include/uapi/asm/kvm.h#L219

I attempted to find where it was supposed to be defined, and the only
match for "define BIT(" in the whole tree is in
include/linux/bitops.h:
https://github.com/torvalds/linux/blob/master/include/linux/bitops.h#L6

However, that's not in a "uapi" directory, and it's not listed in
include/uapi/linux/Kbuild, so "make headers_install" doesn't install
it.  Further, kvm.h doesn't reference it with a #include, so even if
it were installed, it wouldn't be included.

It seems that we must be missing something obvious.  But what?

Thanks,
- Brooks


P.S. The change that appears to have added this reference is this
one, signed-off-on by Borislav and Paolo, which is why I've added you
to the cc line.
https://github.com/torvalds/linux/commit/9c15bb1d0a8411f9bb3395d21d5309bde7da0c1c

[toc] | [next] | [standalone]


#1394935

FromBorislav Petkov <bp@suse.de>
Date2016-05-05 10:30 +0200
Message-ID<rvmPB-4Dm-115@gated-at.bofh.it>
In reply to#1394811
On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
> When I run "make ARCH=x86 headers_install", and then write a simple C
> file that #includes "asm/kvm.h" from the resulting tree, I get a
> compiler error: the BIT() macro used on line 219 of that file is
> undefined:

The below patch should help...

@Paulo: btw, any chance we can fix that "signifcant" typo :-) in
KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
stone?

---
From: Borislav Petkov <bp@suse.de>
Date: Thu, 5 May 2016 10:18:23 +0200
Subject: [PATCH] x86/kvm: Do not use BIT() in user-exported header

Apparently, we're not exporting BIT() to userspace.

Reported-by: Brooks Moses <bmoses@google.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/include/uapi/asm/kvm.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
index cd54147cb365..739c0c594022 100644
--- a/arch/x86/include/uapi/asm/kvm.h
+++ b/arch/x86/include/uapi/asm/kvm.h
@@ -216,9 +216,9 @@ struct kvm_cpuid_entry2 {
 	__u32 padding[3];
 };
 
-#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		BIT(0)
-#define KVM_CPUID_FLAG_STATEFUL_FUNC		BIT(1)
-#define KVM_CPUID_FLAG_STATE_READ_NEXT		BIT(2)
+#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		(1 << 0)
+#define KVM_CPUID_FLAG_STATEFUL_FUNC		(1 << 1)
+#define KVM_CPUID_FLAG_STATE_READ_NEXT		(1 << 2)
 
 /* for KVM_SET_CPUID2 */
 struct kvm_cpuid2 {
-- 
2.7.3

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [next] | [standalone]


#1395310

FromBrooks Moses <bmoses@google.com>
Date2016-05-05 21:20 +0200
Message-ID<rvwYx-61n-11@gated-at.bofh.it>
In reply to#1394935
On Thu, May 5, 2016 at 1:24 AM, Borislav Petkov <bp@suse.de> wrote:
> On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
>> When I run "make ARCH=x86 headers_install", and then write a simple C
>> file that #includes "asm/kvm.h" from the resulting tree, I get a
>> compiler error: the BIT() macro used on line 219 of that file is
>> undefined:
>
> The below patch should help...

Thanks for the quick reply!  Yes, this should fix things for us -- and
answers my implicit question of whether it was better to fix this by
avoiding the macro or whether bitops.h was expected to be exported.

> @Paulo: btw, any chance we can fix that "signifcant" typo :-) in
> KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
> stone?

It's user-visible, but since it's been defined to something that
doesn't work in user-space, it seems unlikely to me that it has any
actual users....

- Brooks

[toc] | [prev] | [next] | [standalone]


#1397077

FromPaolo Bonzini <pbonzini@redhat.com>
Date2016-05-09 16:10 +0200
Message-ID<rwU2K-7bS-1@gated-at.bofh.it>
In reply to#1394935

On 05/05/2016 10:24, Borislav Petkov wrote:
> On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
>> When I run "make ARCH=x86 headers_install", and then write a simple C
>> file that #includes "asm/kvm.h" from the resulting tree, I get a
>> compiler error: the BIT() macro used on line 219 of that file is
>> undefined:
> 
> The below patch should help...
> 
> @Paulo: btw, any chance we can fix that "signifcant" typo :-) in
> KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
> stone?

Unfortuntely it is cast in stone.  The patch below is good though.
Radim, please commit it
(http://article.gmane.org/gmane.linux.kernel/2215443/raw) or pass the
tree back to me so that I can. :)

Thanks,

Paolo

> ---
> From: Borislav Petkov <bp@suse.de>
> Date: Thu, 5 May 2016 10:18:23 +0200
> Subject: [PATCH] x86/kvm: Do not use BIT() in user-exported header
> 
> Apparently, we're not exporting BIT() to userspace.
> 
> Reported-by: Brooks Moses <bmoses@google.com>
> Signed-off-by: Borislav Petkov <bp@suse.de>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/include/uapi/asm/kvm.h | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h
> index cd54147cb365..739c0c594022 100644
> --- a/arch/x86/include/uapi/asm/kvm.h
> +++ b/arch/x86/include/uapi/asm/kvm.h
> @@ -216,9 +216,9 @@ struct kvm_cpuid_entry2 {
>  	__u32 padding[3];
>  };
>  
> -#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		BIT(0)
> -#define KVM_CPUID_FLAG_STATEFUL_FUNC		BIT(1)
> -#define KVM_CPUID_FLAG_STATE_READ_NEXT		BIT(2)
> +#define KVM_CPUID_FLAG_SIGNIFCANT_INDEX		(1 << 0)
> +#define KVM_CPUID_FLAG_STATEFUL_FUNC		(1 << 1)
> +#define KVM_CPUID_FLAG_STATE_READ_NEXT		(1 << 2)


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

>  /* for KVM_SET_CPUID2 */
>  struct kvm_cpuid2 {
> 

[toc] | [prev] | [next] | [standalone]


#1397110

FromRadim Krčmář <rkrcmar@redhat.com>
Date2016-05-09 16:50 +0200
Message-ID<rwUFr-7AA-7@gated-at.bofh.it>
In reply to#1397077
2016-05-09 16:00+0200, Paolo Bonzini:
> On 05/05/2016 10:24, Borislav Petkov wrote:
>> On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
>>> When I run "make ARCH=x86 headers_install", and then write a simple C
>>> file that #includes "asm/kvm.h" from the resulting tree, I get a
>>> compiler error: the BIT() macro used on line 219 of that file is
>>> undefined:
>> 
>> The below patch should help...
>> 
>> @Paulo: btw, any chance we can fix that "signifcant" typo :-) in
>> KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
>> stone?
> 
> Unfortuntely it is cast in stone.  The patch below is good though.

We can "fix" it by introducing a second name for the entry.  Do you
think it's worth?

> Radim, please commit it
> (http://article.gmane.org/gmane.linux.kernel/2215443/raw) or pass the
> tree back to me so that I can. :)

I've committed the patch.  The tree is yours now -- there probably is a
lot I missed ...

[toc] | [prev] | [next] | [standalone]


#1397137

FromPaolo Bonzini <pbonzini@redhat.com>
Date2016-05-09 17:20 +0200
Message-ID<rwV8u-8cW-21@gated-at.bofh.it>
In reply to#1397110

On 09/05/2016 16:47, Radim Krčmář wrote:
> 2016-05-09 16:00+0200, Paolo Bonzini:
>> On 05/05/2016 10:24, Borislav Petkov wrote:
>>> On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
>>>> When I run "make ARCH=x86 headers_install", and then write a simple C
>>>> file that #includes "asm/kvm.h" from the resulting tree, I get a
>>>> compiler error: the BIT() macro used on line 219 of that file is
>>>> undefined:
>>>
>>> The below patch should help...
>>>
>>> @Paulo: btw, any chance we can fix that "signifcant" typo :-) in
>>> KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
>>> stone?
>>
>> Unfortuntely it is cast in stone.  The patch below is good though.
> 
> We can "fix" it by introducing a second name for the entry.  Do you
> think it's worth?

I don't think so, but perhaps there are precedents for doing that?

>> Radim, please commit it
>> (http://article.gmane.org/gmane.linux.kernel/2215443/raw) or pass the
>> tree back to me so that I can. :)
> 
> I've committed the patch.  The tree is yours now -- there probably is a
> lot I missed ...

No problem, I "only" have 1300 messages to go in my inbox but I'll take
a closer look at those that you didn't reply to.

Thanks,

Paolo

[toc] | [prev] | [next] | [standalone]


#1397144

FromRadim Krčmář <rkrcmar@redhat.com>
Date2016-05-09 17:30 +0200
Message-ID<rwVia-8if-15@gated-at.bofh.it>
In reply to#1397137
2016-05-09 17:15+0200, Paolo Bonzini:
> On 09/05/2016 16:47, Radim Krčmář wrote:
>> 2016-05-09 16:00+0200, Paolo Bonzini:
>>> On 05/05/2016 10:24, Borislav Petkov wrote:
>>>> On Wed, May 04, 2016 at 05:49:27PM -0700, Brooks Moses wrote:
>>>>> When I run "make ARCH=x86 headers_install", and then write a simple C
>>>>> file that #includes "asm/kvm.h" from the resulting tree, I get a
>>>>> compiler error: the BIT() macro used on line 219 of that file is
>>>>> undefined:
>>>>
>>>> The below patch should help...
>>>>
>>>> @Paulo: btw, any chance we can fix that "signifcant" typo :-) in
>>>> KVM_CPUID_FLAG_SIGNIFCANT_INDEX or is it user-visible and cast in
>>>> stone?
>>>
>>> Unfortuntely it is cast in stone.  The patch below is good though.
>> 
>> We can "fix" it by introducing a second name for the entry.  Do you
>> think it's worth?
> 
> I don't think so, but perhaps there are precedents for doing that?

I can't think of any, and it seems pointless to me ...

[toc] | [prev] | [next] | [standalone]


#1397150

FromBorislav Petkov <bp@suse.de>
Date2016-05-09 17:50 +0200
Message-ID<rwVBv-8t-1@gated-at.bofh.it>
In reply to#1397144
On Mon, May 09, 2016 at 05:25:02PM +0200, Radim Krčmář wrote:
> I can't think of any, and it seems pointless to me ...

Yeah, f'get it - there are more examples for this like "umount" instead
of "unmount", etc... :-P

What's done is done.

-- 
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web