x86/vmx: Shrink TASK_SWITCH's hvm_task_switch_reason reasons[]
diff mbox series

Message ID 20200107122501.15511-1-andrew.cooper3@citrix.com
State New
Headers show
Series
  • x86/vmx: Shrink TASK_SWITCH's hvm_task_switch_reason reasons[]
Related show

Commit Message

Andrew Cooper Jan. 7, 2020, 12:25 p.m. UTC
No need to use 4-byte integers to store two bits of information.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wl@xen.org>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Jun Nakajima <jun.nakajima@intel.com>
CC: Kevin Tian <kevin.tian@intel.com>
---
 xen/arch/x86/hvm/vmx/vmx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jan Beulich Jan. 7, 2020, 1:20 p.m. UTC | #1
On 07.01.2020 13:25, Andrew Cooper wrote:
> No need to use 4-byte integers to store two bits of information.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

In principle
Reviewed-by: Jan Beulich <jbeulich@suse.com>
But ...

> --- a/xen/arch/x86/hvm/vmx/vmx.c
> +++ b/xen/arch/x86/hvm/vmx/vmx.c
> @@ -3978,7 +3978,7 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs)
>          vmx_update_cpu_exec_control(v);
>          break;
>      case EXIT_REASON_TASK_SWITCH: {
> -        static const enum hvm_task_switch_reason reasons[] = {
> +        static const int8_t reasons[] = {
>              TSW_call_or_int, TSW_iret, TSW_jmp, TSW_call_or_int
>          };

... given our general preference of unsigned types when values
can't become negative, why not uint8_t?

As an aside, elsewhere I saw people starting to convert code
because apparently gcc 10 will warn about enum type mismatches.
I didn't investigate yet whether that's just for enum -> enum
conversions, or also for enum <- / -> integer ones. Of course
it wouldn't be the end of the world if we had to revert the
change above; did you consider the alternative of making the
enum a __packed one (which would avoid potential issues like
the one named)?

Jan
Tian, Kevin Jan. 19, 2020, 4:09 a.m. UTC | #2
> From: Andrew Cooper <andrew.cooper3@citrix.com>
> Sent: Tuesday, January 7, 2020 8:25 PM
> 
> No need to use 4-byte integers to store two bits of information.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>

Patch
diff mbox series

diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c
index f83f102638..b79bca71ad 100644
--- a/xen/arch/x86/hvm/vmx/vmx.c
+++ b/xen/arch/x86/hvm/vmx/vmx.c
@@ -3978,7 +3978,7 @@  void vmx_vmexit_handler(struct cpu_user_regs *regs)
         vmx_update_cpu_exec_control(v);
         break;
     case EXIT_REASON_TASK_SWITCH: {
-        static const enum hvm_task_switch_reason reasons[] = {
+        static const int8_t reasons[] = {
             TSW_call_or_int, TSW_iret, TSW_jmp, TSW_call_or_int
         };
         unsigned int inst_len, source;