diff mbox series

[5/4] KVM: PPC: Tie KVM_CAP_PPC_HTM to the user-visible TM feature

Message ID 1507809534-10721-1-git-send-email-mpe@ellerman.id.au (mailing list archive)
State Accepted
Commit 2a3d6553cbd791da4fb624c2500b4580b3f9d72f
Headers show
Series [1/4] powerpc/tm: Add commandline option to disable hardware transactional memory | expand

Commit Message

Michael Ellerman Oct. 12, 2017, 11:58 a.m. UTC
Currently we use CPU_FTR_TM to decide if the CPU/kernel can support
TM (Transactional Memory), and if it's true we advertise that to
Qemu (or similar) via KVM_CAP_PPC_HTM.

PPC_FEATURE2_HTM is the user-visible feature bit, which indicates that
the CPU and kernel can support TM. Currently CPU_FTR_TM and
PPC_FEATURE2_HTM always have the same value, either true or false, so
using the former for KVM_CAP_PPC_HTM is correct.

However some Power9 CPUs can operate in a mode where TM is enabled but
TM suspended state is disabled. In this mode CPU_FTR_TM is true, but
PPC_FEATURE2_HTM is false. Instead a different PPC_FEATURE2 bit is
set, to indicate that this different mode of TM is available.

It is not safe to let guests use TM as-is, when the CPU is in this
mode. So to prevent that from happening, use PPC_FEATURE2_HTM to
determine the value of KVM_CAP_PPC_HTM.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kvm/powerpc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Michael Ellerman Oct. 24, 2017, 8:08 a.m. UTC | #1
On Thu, 2017-10-12 at 11:58:54 UTC, Michael Ellerman wrote:
> Currently we use CPU_FTR_TM to decide if the CPU/kernel can support
> TM (Transactional Memory), and if it's true we advertise that to
> Qemu (or similar) via KVM_CAP_PPC_HTM.
> 
> PPC_FEATURE2_HTM is the user-visible feature bit, which indicates that
> the CPU and kernel can support TM. Currently CPU_FTR_TM and
> PPC_FEATURE2_HTM always have the same value, either true or false, so
> using the former for KVM_CAP_PPC_HTM is correct.
> 
> However some Power9 CPUs can operate in a mode where TM is enabled but
> TM suspended state is disabled. In this mode CPU_FTR_TM is true, but
> PPC_FEATURE2_HTM is false. Instead a different PPC_FEATURE2 bit is
> set, to indicate that this different mode of TM is available.
> 
> It is not safe to let guests use TM as-is, when the CPU is in this
> mode. So to prevent that from happening, use PPC_FEATURE2_HTM to
> determine the value of KVM_CAP_PPC_HTM.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/2a3d6553cbd791da4fb624c2500b45

cheers
diff mbox series

Patch

diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
index 3480faaf1ef8..a3746b98ec11 100644
--- a/arch/powerpc/kvm/powerpc.c
+++ b/arch/powerpc/kvm/powerpc.c
@@ -644,8 +644,8 @@  int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
 		break;
 #endif
 	case KVM_CAP_PPC_HTM:
-		r = cpu_has_feature(CPU_FTR_TM_COMP) &&
-		    is_kvmppc_hv_enabled(kvm);
+		r = is_kvmppc_hv_enabled(kvm) &&
+		    (cur_cpu_spec->cpu_user_features2 & PPC_FEATURE2_HTM_COMP);
 		break;
 	default:
 		r = 0;