[2/5] KVM: x86: Shrink struct kvm_queued_exception

Message ID 20230213163351.30704-3-minipli@grsecurity.net
State New
Headers
Series [1/5] KVM: x86: Shrink struct kvm_pmu |

Commit Message

Mathias Krause Feb. 13, 2023, 4:33 p.m. UTC
  Reshuffle the boolean members of struct kvm_queued_exception and make
them individual bits, allowing denser packing.

This allows us to shrink the object size from 24 to 16 bytes for 64 bit
builds.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
 arch/x86/include/asm/kvm_host.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
  

Comments

Tom Lendacky Feb. 18, 2023, 2:55 p.m. UTC | #1
On 2/13/23 10:33, Mathias Krause wrote:
> Reshuffle the boolean members of struct kvm_queued_exception and make
> them individual bits, allowing denser packing.
> 
> This allows us to shrink the object size from 24 to 16 bytes for 64 bit
> builds.
> 
> Signed-off-by: Mathias Krause <minipli@grsecurity.net>
> ---
>   arch/x86/include/asm/kvm_host.h | 8 ++++----
>   1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 43329c60a6b5..040eee3e9583 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -701,13 +701,13 @@ struct kvm_vcpu_xen {
>   };
>   
>   struct kvm_queued_exception {
> -	bool pending;
> -	bool injected;
> -	bool has_error_code;
> +	u8 pending : 1;
> +	u8 injected : 1;
> +	u8 has_error_code : 1;
> +	u8 has_payload : 1;

I find doing something like this is clearer and easier to read:

	u8 pending		: 1,
	   injected		: 1,
	   has_error_code	: 1,
	   has_payload		: 1,
	   __reserved		: 4;

(you don't have to have the __reserved, though). Just throwing it out there.

Thanks,
Tom

>   	u8 vector;
>   	u32 error_code;
>   	unsigned long payload;
> -	bool has_payload;
>   };
>   
>   struct kvm_vcpu_arch {
  

Patch

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 43329c60a6b5..040eee3e9583 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -701,13 +701,13 @@  struct kvm_vcpu_xen {
 };
 
 struct kvm_queued_exception {
-	bool pending;
-	bool injected;
-	bool has_error_code;
+	u8 pending : 1;
+	u8 injected : 1;
+	u8 has_error_code : 1;
+	u8 has_payload : 1;
 	u8 vector;
 	u32 error_code;
 	unsigned long payload;
-	bool has_payload;
 };
 
 struct kvm_vcpu_arch {