* [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control
@ 2022-05-20 14:37 Uros Bizjak
2022-05-21 10:45 ` kernel test robot
2022-06-15 12:13 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: Uros Bizjak @ 2022-05-20 14:37 UTC (permalink / raw)
To: kvm, linux-kernel
Cc: Uros Bizjak, Paolo Bonzini, Sean Christopherson,
Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel
Use try_cmpxchg64 instead of cmpxchg64 (*ptr, old, new) != old
in pi_try_set_control. cmpxchg returns success in ZF flag, so this
change saves a compare after cmpxchg (and related move instruction
in front of cmpxchg):
b9: 88 44 24 60 mov %al,0x60(%rsp)
bd: 48 89 c8 mov %rcx,%rax
c0: c6 44 24 62 f2 movb $0xf2,0x62(%rsp)
c5: 48 8b 74 24 60 mov 0x60(%rsp),%rsi
ca: f0 49 0f b1 34 24 lock cmpxchg %rsi,(%r12)
d0: 48 39 c1 cmp %rax,%rcx
d3: 75 cf jne a4 <vmx_vcpu_pi_load+0xa4>
patched:
c1: 88 54 24 60 mov %dl,0x60(%rsp)
c5: c6 44 24 62 f2 movb $0xf2,0x62(%rsp)
ca: 48 8b 54 24 60 mov 0x60(%rsp),%rdx
cf: f0 48 0f b1 13 lock cmpxchg %rdx,(%rbx)
d4: 75 d5 jne ab <vmx_vcpu_pi_load+0xab>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Wanpeng Li <wanpengli@tencent.com>
Cc: Jim Mattson <jmattson@google.com>
Cc: Joerg Roedel <joro@8bytes.org>
---
v2:
- use address of local variable &old
The patch is agains tip tree.
---
arch/x86/kvm/vmx/posted_intr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c
index 3834bb30ce54..259315ea5e44 100644
--- a/arch/x86/kvm/vmx/posted_intr.c
+++ b/arch/x86/kvm/vmx/posted_intr.c
@@ -42,7 +42,7 @@ static int pi_try_set_control(struct pi_desc *pi_desc, u64 old, u64 new)
* update must be retried with a fresh snapshot an ON change causes
* the cmpxchg to fail.
*/
- if (cmpxchg64(&pi_desc->control, old, new) != old)
+ if (!try_cmpxchg64(&pi_desc->control, &old, new))
return -EBUSY;
return 0;
--
2.35.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control
2022-05-20 14:37 [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control Uros Bizjak
@ 2022-05-21 10:45 ` kernel test robot
2022-06-15 12:13 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: kernel test robot @ 2022-05-21 10:45 UTC (permalink / raw)
To: Uros Bizjak, kvm, linux-kernel
Cc: kbuild-all, Uros Bizjak, Paolo Bonzini, Sean Christopherson,
Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel
Hi Uros,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kvm/master]
[also build test ERROR on mst-vhost/linux-next linux/master linus/master v5.18-rc7]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Uros-Bizjak/KVM-VMX-Use-try_cmpxchg64-in-pi_try_set_control/20220520-223925
base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git master
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20220521/202205211837.X2KKIXbP-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-1) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/84128ccce45cc3ece9b9f8d4df8afa81651547c9
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Uros-Bizjak/KVM-VMX-Use-try_cmpxchg64-in-pi_try_set_control/20220520-223925
git checkout 84128ccce45cc3ece9b9f8d4df8afa81651547c9
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash
If you fix the issue, kindly add following tag where applicable
Reported-by: kernel test robot <lkp@intel.com>
All errors (new ones prefixed by >>):
arch/x86/kvm/vmx/posted_intr.c: In function 'pi_try_set_control':
>> arch/x86/kvm/vmx/posted_intr.c:45:14: error: implicit declaration of function 'try_cmpxchg64'; did you mean 'try_cmpxchg'? [-Werror=implicit-function-declaration]
45 | if (!try_cmpxchg64(&pi_desc->control, &old, new))
| ^~~~~~~~~~~~~
| try_cmpxchg
cc1: some warnings being treated as errors
vim +45 arch/x86/kvm/vmx/posted_intr.c
36
37 static int pi_try_set_control(struct pi_desc *pi_desc, u64 old, u64 new)
38 {
39 /*
40 * PID.ON can be set at any time by a different vCPU or by hardware,
41 * e.g. a device. PID.control must be written atomically, and the
42 * update must be retried with a fresh snapshot an ON change causes
43 * the cmpxchg to fail.
44 */
> 45 if (!try_cmpxchg64(&pi_desc->control, &old, new))
46 return -EBUSY;
47
48 return 0;
49 }
50
--
0-DAY CI Kernel Test Service
https://01.org/lkp
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control
2022-05-20 14:37 [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control Uros Bizjak
2022-05-21 10:45 ` kernel test robot
@ 2022-06-15 12:13 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2022-06-15 12:13 UTC (permalink / raw)
To: Uros Bizjak
Cc: kvm, linux-kernel, Sean Christopherson, Vitaly Kuznetsov,
Wanpeng Li, Jim Mattson, Joerg Roedel
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-06-15 12:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-20 14:37 [PATCH v2] KVM: VMX: Use try_cmpxchg64 in pi_try_set_control Uros Bizjak
2022-05-21 10:45 ` kernel test robot
2022-06-15 12:13 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).