KVM: Switch 'requests' to be 64-bit (explicitly)
PATCH 1/1 KVM: Switch 'requests' to be 64-bit (explicitly)
Switch 'requests' to be explicitly 64-bit and update BUILD_BUG_ON check to use the size of "requests" instead of the hard-coded '32'.
That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
include/linux/kvm_host.h +5 -5
@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \ (unsigned)(((nr) + KVM_REQUEST_ARCH_BASE) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)
@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;unsigned long guest_debug;int pre_pcpu;
@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_request_pending (struct kvm_vcpu *vcpu)
@@ -1132,12 +1132,12 @@ static inline bool kvm_request_pending(struct kvm_vcpu *vcpu)static inline bool kvm_test_request (int req,struct kvm_vcpu *vcpu) { -return test_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +return test_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline void kvm_clear_request (int req,struct kvm_vcpu *vcpu) { -clear_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +clear_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_check_request (int req,struct kvm_vcpu *vcpu)
Signature · 1 line
2.7.4
Quoted 20 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kvm_host.h +0
-0
include/linux/kvm_host.h static inline bool is_error_page(struct page *page) · line 132
Quoted 5 lines
include/linux/kvm_host.h +1
-1@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \
While looking at a completely unrelated code I realize that there is FIELD_SIZEOF that is doing exactly what I did. Will use it in v2.
Quoted 26 lines
include/linux/kvm_host.h +2
-3(unsigned )(((nr) +KVM_REQUEST_ARCH_BASE ) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;unsigned long guest_debug;int pre_pcpu;@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_request_pending (struct kvm_vcpu *vcpu)@@ -1132,12 +1132,12 @@ static inline bool kvm_request_pending(struct kvm_vcpu *vcpu)static inline bool kvm_test_request (int req,struct kvm_vcpu *vcpu) { -return test_bit (req &KVM_REQUEST_MASK , &vcpu->requests);
include/linux/kvm_host.h static inline bool kvm_request_pending(struct kvm_vcpu *vcpu) · line 1143
Quoted 10 lines
include/linux/kvm_host.h +2
-1+return test_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline void kvm_clear_request (int req,struct kvm_vcpu *vcpu) { -clear_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +clear_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_check_request (int req,struct kvm_vcpu *vcpu)
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Jim Mattson
Reviewed-byQuoted 4 lines · KarimAllah
Quoted 3 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.
Quoted 8 lines
Quoted 8 lines
That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>
I like it!
Paolo Bonzini
maintainerQuoted 11 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>
I'm afraid architectures like ARM 32 need this to be conditional (using Kconfig).
Thanks,
Paolo
Quoted 51 lines
--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kvm_host.h +5
-5@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \ (unsigned)(((nr) + KVM_REQUEST_ARCH_BASE) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;unsigned long guest_debug;int pre_pcpu;@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_request_pending (struct kvm_vcpu *vcpu)@@ -1132,12 +1132,12 @@ static inline bool kvm_request_pending(struct kvm_vcpu *vcpu)static inline bool kvm_test_request (int req,struct kvm_vcpu *vcpu) { -return test_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +return test_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline void kvm_clear_request (int req,struct kvm_vcpu *vcpu) { -clear_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +clear_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_check_request (int req,struct kvm_vcpu *vcpu)
Quoted 8 lines · Paolo Bonzini
Quoted 7 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Quoted 8 lines
Quoted 5 lines
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>I'm afraid architectures like ARM 32 need this to be conditional (using
Kconfig).
Why would using a 64-bit 'requests' be a problem for ARM32? Are you concerned about performance here or is there some symantic problem?
Quoted 49 lines
Thanks,
Paolo
Quoted 44 lines
--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kvm_host.h +4
-4@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \ (unsigned)(((nr) + KVM_REQUEST_ARCH_BASE) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;unsigned long guest_debug;int pre_pcpu;@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_request_pending (struct kvm_vcpu *vcpu)@@ -1132,12 +1132,12 @@ static inline bool kvm_request_pending(struct kvm_vcpu *vcpu)static inline bool kvm_test_request (int req,struct kvm_vcpu *vcpu) { -return test_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +return test_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }
Quoted 10 lines
include/linux/kvm_host.h static inline bool kvm_request_pending(struct kvm_vcpu *vcpu) · line 1143
Quoted 8 lines
include/linux/kvm_host.h +1
-1static inline void kvm_clear_request (int req,struct kvm_vcpu *vcpu) { -clear_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +clear_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests); }static inline bool kvm_check_request (int req,struct kvm_vcpu *vcpu)
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Paolo Bonzini
maintainerQuoted 15 lines · KarimAllah
Quoted 14 lines · Paolo Bonzini
Quoted 12 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>
Quoted 5 lines
Quoted 2 lines
I'm afraid architectures like ARM 32 need this to be conditional (using
Kconfig).Why would using a 64-bit 'requests' be a problem for ARM32? Are you concerned about performance here or is there some symantic problem?
They don't support atomics on double-word data.
Paolo
Quoted 19 lines · Paolo Bonzini
Quoted 18 lines · KarimAllah
Quoted 16 lines · Paolo Bonzini
Quoted 13 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I'm afraid architectures like ARM 32 need this to be conditional (using
Kconfig).Why would using a 64-bit 'requests' be a problem for ARM32? Are you concerned about performance here or is there some symantic problem?
They don't support atomics on double-word data.
But they support atomics on single words. Of which there are two. We don't need atomic updates of the whole 64-bit quantity (a là cmpxchg). Do we strictly need this to be atomic accross the 64-bit?
Looking at the use cases for "requests":
kvm_clear_requestkvm_test_requestkvm_request_pendingkvm_check_request
... and all of them would still work if the atomicity is only at the word level, right?
Quoted 3 lines
Paolo
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
Paolo Bonzini
maintainerQuoted 7 lines · KarimAllah
Quoted 1 line
They don't support atomics on double-word data.
But they support atomics on single words. Of which there are two. We don't need atomic updates of the whole 64-bit quantity (a là cmpxchg). Do we strictly need this to be atomic accross the 64-bit?
Looking at the use cases for "requests":
Quoted 8 lines
kvm_clear_requestkvm_test_requestkvm_request_pendingkvm_check_request... and all of them would still work if the atomicity is only at the word level, right?
Good point! Then yes, requests can be made 64 bit wide.
Paolo
Quoted 29 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kvm_host.h +1
-1@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \ (unsigned)(((nr) + KVM_REQUEST_ARCH_BASE) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)
include/linux/kvm_host.h struct kvm_vcpu { · line 226
Quoted 5 lines
include/linux/kvm_host.h +1
-1@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;
The usual thing to do for bitmaps is something like:
#define KVM_REQUEST_NR (KVM_REQUEST_ARCH_BASE + KVM_REQUEST_ARCH_NR)
unsigned long requests[BITS_TO_LONGS(NR_KVM_REQUESTS)];
include/linux/kvm_host.h static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) · line 1125
Quoted 9 lines
include/linux/kvm_host.h +1
-1unsigned long guest_debug;int pre_pcpu;@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests);
... which wouldn't require a void cast to make the bit API functions happy (as these expect a pointer to the first unsigned long in the bitmap).
Thanks,
Mark.
Quoted 46 lines · Mark Rutland
Quoted 30 lines · KarimAllah Ahmed
Switch 'requests' to be explicitly 64-bit and update
BUILD_BUG_ONcheck to use the size of "requests" instead of the hard-coded '32'.That gives us a bit more room again for arch-specific requests as we already ran out of space for x86 due to the hard-coded check.
Cc Paolo Bonzini <[email protected]>Cc Radim Krčmář <[email protected]>Signed-off-by KarimAllah Ahmed <[email protected]>--- include/linux/kvm_host.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)include/linux/kvm_host.h +1
-1@@ -129,7 +129,7 @@ static inline bool is_error_page(struct page *page)#define KVM_REQUEST_ARCH_BASE 8#define KVM_ARCH_REQ_FLAGS (nr, flags) ({ \ - BUILD_BUG_ON((unsigned)(nr) >= 32 - KVM_REQUEST_ARCH_BASE); \ + BUILD_BUG_ON((unsigned)(nr) >= (sizeof(((struct kvm_vcpu *)0)->requests) * 8) - KVM_REQUEST_ARCH_BASE); \ (unsigned)(((nr) + KVM_REQUEST_ARCH_BASE) | (flags)); \ })#define KVM_ARCH_REQ (nr) KVM_ARCH_REQ_FLAGS(nr, 0)include/linux/kvm_host.h struct kvm_vcpu { · line 226
Quoted 5 lines
include/linux/kvm_host.h +1
-1@@ -223,7 +223,7 @@ struct kvm_vcpu {int vcpu_id;int srcu_idx;int mode; -unsigned long requests; +u64 requests;The usual thing to do for bitmaps is something like:
#define
KVM_REQUEST_NR(KVM_REQUEST_ARCH_BASE+KVM_REQUEST_ARCH_NR)unsigned long requests[BITS_TO_LONGS(NR_KVM_REQUESTS)];Quoted 3 lines
include/linux/kvm_host.h +0
-0unsigned long guest_debug;
Quoted 11 lines
include/linux/kvm_host.h static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu) · line 1125
Quoted 7 lines
include/linux/kvm_host.h +1
-1int pre_pcpu;@@ -1122,7 +1122,7 @@ static inline void kvm_make_request(int req, struct kvm_vcpu *vcpu)* caller. Paired with the smp_mb__after_atomic in kvm_check_request. */ smp_wmb (); -set_bit (req &KVM_REQUEST_MASK , &vcpu->requests); +set_bit (req &KVM_REQUEST_MASK , (void *)&vcpu->requests);... which wouldn't require a void cast to make the bit API functions happy (as these expect a pointer to the first unsigned long in the bitmap).
Ah, right! Good point.
Paolo,
Would you prefer to switch "requests" to a bitmap and update kvm_request_pending to handle this?
Quoted 4 lines
Thanks,
Mark.
Amazon Development Center Germany GmbH
Berlin - Dresden - Aachen
main office: Krausenstr. 38, 10117 Berlin
Geschaeftsfuehrer: Dr. Ralf Herbrich, Christian Schlaeger
Ust-ID: DE289237879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B