mbox series

[0/3] x86/KVM/VMX: Introduce and use try_cmpxchg64()

Message ID 20201215182805.53913-1-ubizjak@gmail.com (mailing list archive)
Headers show
Series x86/KVM/VMX: Introduce and use try_cmpxchg64() | expand

Message

Uros Bizjak Dec. 15, 2020, 6:28 p.m. UTC
This patch series introduces try_cmpxchg64() atomic locking function.

try_cmpxchg64() provides the same interface for 64 bit and 32 bit targets,
emits CMPXCHGQ for 64 bit targets and CMPXCHG8B for 32 bit targets,
and provides appropriate fallbacks when CMPXCHG8B is unavailable.

try_cmpxchg64() reuses flags from CMPXCHGQ/CMPXCHG8B instructions and
avoids unneeded CMP for 64 bit targets or XOR/XOR/OR sequence for
32 bit targets.

Cc: Will Deacon <will@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: "H. Peter Anvin" <hpa@zytor.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>

Uros Bizjak (3):
  asm-generic/atomic: Add try_cmpxchg64() instrumentation
  locking/atomic/x86: Introduce arch_try_cmpxchg64()
  KVM/VMX: Use try_cmpxchg64() in posted_intr.c

 arch/x86/include/asm/cmpxchg_32.h         | 62 +++++++++++++++++++----
 arch/x86/include/asm/cmpxchg_64.h         |  6 +++
 arch/x86/kvm/vmx/posted_intr.c            |  9 ++--
 include/asm-generic/atomic-instrumented.h | 46 ++++++++++++++++-
 scripts/atomic/gen-atomic-instrumented.sh |  2 +-
 5 files changed, 108 insertions(+), 17 deletions(-)

Comments

Sean Christopherson Jan. 15, 2021, 6:09 p.m. UTC | #1
On Tue, Dec 15, 2020, Uros Bizjak wrote:
> This patch series introduces try_cmpxchg64() atomic locking function.
> 
> try_cmpxchg64() provides the same interface for 64 bit and 32 bit targets,
> emits CMPXCHGQ for 64 bit targets and CMPXCHG8B for 32 bit targets,
> and provides appropriate fallbacks when CMPXCHG8B is unavailable.
> 
> try_cmpxchg64() reuses flags from CMPXCHGQ/CMPXCHG8B instructions and
> avoids unneeded CMP for 64 bit targets or XOR/XOR/OR sequence for
> 32 bit targets.
> 
> Cc: Will Deacon <will@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.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>
> 
> Uros Bizjak (3):
>   asm-generic/atomic: Add try_cmpxchg64() instrumentation
>   locking/atomic/x86: Introduce arch_try_cmpxchg64()
>   KVM/VMX: Use try_cmpxchg64() in posted_intr.c

For anyone else trying to apply this, it depends on v5.11-rc1 (commit
29f006fdefe6, "asm-generic/atomic: Add try_cmpxchg() fallbacks"), which hasn't
yet been merged into Paolo's tree.

>  arch/x86/include/asm/cmpxchg_32.h         | 62 +++++++++++++++++++----
>  arch/x86/include/asm/cmpxchg_64.h         |  6 +++
>  arch/x86/kvm/vmx/posted_intr.c            |  9 ++--
>  include/asm-generic/atomic-instrumented.h | 46 ++++++++++++++++-
>  scripts/atomic/gen-atomic-instrumented.sh |  2 +-
>  5 files changed, 108 insertions(+), 17 deletions(-)
> 
> -- 
> 2.26.2
>
Paolo Bonzini Jan. 18, 2021, 6:26 p.m. UTC | #2
On 15/12/20 19:28, Uros Bizjak wrote:
> This patch series introduces try_cmpxchg64() atomic locking function.
> 
> try_cmpxchg64() provides the same interface for 64 bit and 32 bit targets,
> emits CMPXCHGQ for 64 bit targets and CMPXCHG8B for 32 bit targets,
> and provides appropriate fallbacks when CMPXCHG8B is unavailable.
> 
> try_cmpxchg64() reuses flags from CMPXCHGQ/CMPXCHG8B instructions and
> avoids unneeded CMP for 64 bit targets or XOR/XOR/OR sequence for
> 32 bit targets.
> 
> Cc: Will Deacon <will@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Boqun Feng <boqun.feng@gmail.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Borislav Petkov <bp@alien8.de>
> Cc: "H. Peter Anvin" <hpa@zytor.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>
> 
> Uros Bizjak (3):
>    asm-generic/atomic: Add try_cmpxchg64() instrumentation
>    locking/atomic/x86: Introduce arch_try_cmpxchg64()
>    KVM/VMX: Use try_cmpxchg64() in posted_intr.c
> 
>   arch/x86/include/asm/cmpxchg_32.h         | 62 +++++++++++++++++++----
>   arch/x86/include/asm/cmpxchg_64.h         |  6 +++
>   arch/x86/kvm/vmx/posted_intr.c            |  9 ++--
>   include/asm-generic/atomic-instrumented.h | 46 ++++++++++++++++-
>   scripts/atomic/gen-atomic-instrumented.sh |  2 +-
>   5 files changed, 108 insertions(+), 17 deletions(-)
> 

Queued, thanks.

Paolo