Re: [PATCH] KVM: nVMX: expose INS/OUTS information support

From: Paolo Bonzini
Date: Mon Sep 05 2016 - 09:36:39 EST




On 05/09/2016 11:19, Yury Norov wrote:
>> >
>> > +static inline bool cpu_has_vmx_basic_inout(void)
> inline is useless. See Documentation/CodingStyle, Chapter 15

No, it's not. See Documentation/CodingStyle, Chapter 15: "While the use
of inlines can be appropriate (for example as a means of replacing
macros, see Chapter 12), it very often is not".

>> > +{
>> > + return (((u64)vmcs_config.basic_cap << 32) & VMX_BASIC_INOUT);
> You can shift VMX_BASIC_INOUT (at compile time) and avoid the shifting of
> vmcs_config.basic_cap at runtime.

Not really since VMX_BASIC_INOUT comes from the processor manual.

It's ironic that your first remark places a lot of trust in the
compiler, while the second places none. The compiler is happy to
optimize away the left-shift/bitwise-AND pair to this:

movq %rdi, %rax
shrq $22, %rax
andl $1, %eax

where 22 is the order of VMX_BASIC_INOUT's only set bit, minus 32.

Paolo