From patchwork Mon May 21 04:09:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guo X-Patchwork-Id: 917363 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40q5rh1lVhz9s0y for ; Mon, 21 May 2018 14:48:36 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nuJzKo53"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40q5rh06YSzF0dY for ; Mon, 21 May 2018 14:48:36 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nuJzKo53"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400e:c05::242; helo=mail-pg0-x242.google.com; envelope-from=wei.guo.simon@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nuJzKo53"; dkim-atps=neutral Received: from mail-pg0-x242.google.com (mail-pg0-x242.google.com [IPv6:2607:f8b0:400e:c05::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40q5n05FQxzF0WR for ; Mon, 21 May 2018 14:45:24 +1000 (AEST) Received: by mail-pg0-x242.google.com with SMTP id 63-v6so3655801pgg.3 for ; Sun, 20 May 2018 21:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=sp0WzzUj+5P+V/vjmJOJ7w7o4pRLUWHmOn9IICJ8JWk=; b=nuJzKo53zEcWWHC5OsLxdyynxbY08inRtAEl+juEtfVM2Ku3epuyFM8Z0kNcsQ0u+x IqwyxRsgQd9KWyIkrEPURjFTig9M9xaoEUI2p8jkiCaHIPFFPDOIzAXu3AYIZMRG0v3a 7ezRRAXYLFXgxMgp4Bro9/ytOHUlV/MXDMlNueBYdvXCxFgz6GnGV0noEZcFiWkHrkkY 9TVQi63x1DdkyUvYMggLjqMa4AaEsxN02xfGjcDqt8al6gZ3Oz1PvP0J026VncXAIJyM h2QSQnuDcGiFmwbiTrsL1rjuiAEXiHAyk7guPbXnpEshnCQP0WDDv4w+cDee67ylDmMP rvTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=sp0WzzUj+5P+V/vjmJOJ7w7o4pRLUWHmOn9IICJ8JWk=; b=bQ7G8fiT/6TH2btZzaNAN09TnVirvw4HWfzaIxTAI7XM6Qo5o2+D9NtKEFdHLzOla0 f36Cjgy0VS4kGk97wZUMXrFB1OsAqou8CUTIiOAdyHS7HiEf5Rf/gJrmO5yhYR7JeH2g i3SAnCAVIdGfG3hITjOXt64B269weEGZEcRg1EI2Y+7dFxg0hufghjxjwHPjmZh/ei3C Y2PgH1Rjs1AnDfUju/1mhr0SqvU1bgxTspstReUP0Erz7CmXK+w9VDCB+iEmC/xZAaA9 KCHvU1hzyX9B6l0OBFRS9huZXzn0AUnGbvs9kIRrXEq8FSv04LlPgDZt5PtvzpORqO7n ie5g== X-Gm-Message-State: ALKqPwd9p5/2eWlMlmbnWD637aj2AdJRU6E61MNcrNDYF7uAoh7spiC7 ZTwcvPon136Vev08KK96kYy13A== X-Google-Smtp-Source: AB8JxZpEZV/9lTq50Ehoc5U+f/YkWdHec8qvgs063TDk202Y5yoodJ/TRPrwRoDrFxfNKDDGDtNfIw== X-Received: by 2002:a65:6354:: with SMTP id p20-v6mr14744519pgv.437.1526877922080; Sun, 20 May 2018 21:45:22 -0700 (PDT) Received: from simonLocalRHEL7.cn.ibm.com ([112.73.0.89]) by smtp.gmail.com with ESMTPSA id t14-v6sm24575514pfa.31.2018.05.20.21.45.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 May 2018 21:45:21 -0700 (PDT) From: wei.guo.simon@gmail.com To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH v3 00/29] KVM: PPC: Book3S PR: Transaction memory support on PR KVM Date: Mon, 21 May 2018 12:09:17 +0800 Message-Id: <1526875786-10372-1-git-send-email-wei.guo.simon@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Simon Guo , kvm-ppc@vger.kernel.org, kvm@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Simon Guo In current days, many OS distributions have utilized transaction memory functionality. In PowerPC, HV KVM supports TM. But PR KVM does not. The drive for the transaction memory support of PR KVM is the openstack Continuous Integration testing - They runs a HV(hypervisor) KVM(as level 1) and then run PR KVM(as level 2) on top of that. This patch set add transaction memory support on PR KVM. v2 -> v3 changes: 1) rebase onto Paul's kvm-ppc-next branch, which includes rework KVM_CHECK_EXTENSION ioctl (patch #25) a little bit. 2) allow mtspr TFHAR in TM suspend state 3) remove patch: "KVM: PPC: add KVM_SET_ONE_REG/KVM_GET_ONE_REG to async ioctl" 4) some minor rework per comments v1 -> v2 changes: 1. Correct a bug in trechkpt emulation: the tm sprs need to be flushed to vcpu before trechkpt. 2. add PR kvm ioctl functionalities for TM. 3. removed save_msr_tm and use kvmppc_get_msr() to determine whether a transaction state need to be restored. 4. Remove "KVM: PPC: Book3S PR: set MSR HV bit accordingly for PPC970 and others." patch. It will prevent PR KVM to start as L1 hypervisor. Since if we set HV bit to 0 when rfid to guest (who is supposed to run at HV=1 && PR=1), the guest will not be able to access its original memory. The original code always set HV bits for shadow_msr, it is benign since: HV bits can only be altered by sc instruction; it can only be set to 0 by rfid/hrfid instruction. We return to guest with rfid. So: * if KVM are running as L1 hypervisor, guest physical MSR expects HV=1. * if KVM are running as L2 hypervisor, rfid cannot update HV =1 so the HV is still 0. 5. add XER register implementation to kvmppc_copyto_vcpu_tm/kvmppc_copyfrom_vcpu_tm() 6. remove unnecessary stack frame in _kvmppc_save/restore_tm(). 7. move MSR bits sync into kvmppc_copy_from_svcpu() so that we always see inconsistent shadow_msr/kvmppc_get_msr() even when preemption. 8. doing failure recording in treclaim emulation when TEXASR_FS is 0. Test cases performed: linux/tools/testing/selftests/powerpc/tm/tm-syscall linux/tools/testing/selftests/powerpc/tm/tm-fork linux/tools/testing/selftests/powerpc/tm/tm-vmx-unavail linux/tools/testing/selftests/powerpc/tm/tm-tmspr linux/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv linux/tools/testing/selftests/powerpc/math/vsx_preempt linux/tools/testing/selftests/powerpc/math/fpu_signal linux/tools/testing/selftests/powerpc/math/vmx_preempt linux/tools/testing/selftests/powerpc/math/fpu_syscall linux/tools/testing/selftests/powerpc/math/vmx_syscall linux/tools/testing/selftests/powerpc/math/fpu_preempt linux/tools/testing/selftests/powerpc/math/vmx_signal linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-gpr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-gpr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spd-vsx linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-spr linux/tools/testing/selftests/powerpc/ptrace/ptrace-tm-vsx https://github.com/justdoitqd/publicFiles/blob/master/test_tbegin_pr.c https://github.com/justdoitqd/publicFiles/blob/master/test_tabort.c https://github.com/justdoitqd/publicFiles/blob/master/test_kvm_htm_cap.c https://github.com/justdoitqd/publicFiles/blob/master/test-tm-mig.c Simon Guo (29): powerpc: export symbol msr_check_and_set(). powerpc: add TEXASR related macros powerpc: export tm_enable()/tm_disable/tm_abort() APIs KVM: PPC: Book3S PR: Move kvmppc_save_tm/kvmppc_restore_tm to separate file KVM: PPC: Book3S PR: add new parameter (guest MSR) for kvmppc_save_tm()/kvmppc_restore_tm() KVM: PPC: Book3S PR: turn on FP/VSX/VMX MSR bits in kvmppc_save_tm() KVM: PPC: Book3S PR: add C function wrapper for _kvmppc_save/restore_tm() KVM: PPC: Book3S PR: In PR KVM suspends Transactional state when inject an interrupt. KVM: PPC: Book3S PR: PR KVM pass through MSR TM/TS bits to shadow_msr. KVM: PPC: Book3S PR: Sync TM bits to shadow msr for problem state guest KVM: PPC: Book3S PR: implement RFID TM behavior to suppress change from S0 to N0 KVM: PPC: Book3S PR: prevent TS bits change in kvmppc_interrupt_pr() KVM: PPC: Book3S PR: adds new kvmppc_copyto_vcpu_tm/kvmppc_copyfrom_vcpu_tm API for PR KVM. KVM: PPC: Book3S PR: add kvmppc_save/restore_tm_sprs() APIs KVM: PPC: Book3S PR: add transaction memory save/restore skeleton for PR KVM KVM: PPC: Book3S PR: add math support for PR KVM HTM KVM: PPC: Book3S PR: make mtspr/mfspr emulation behavior based on active TM SPRs KVM: PPC: Book3S PR: always fail transaction in guest privilege state KVM: PPC: Book3S PR: enable NV reg restore for reading TM SPR at guest privilege state KVM: PPC: Book3S PR: adds emulation for treclaim. KVM: PPC: Book3S PR: add emulation for trechkpt in PR KVM. KVM: PPC: Book3S PR: add emulation for tabort. for privilege guest KVM: PPC: Book3S PR: add guard code to prevent returning to guest with PR=0 and Transactional state KVM: PPC: Book3S PR: Support TAR handling for PR KVM HTM. KVM: PPC: Book3S PR: enable HTM for PR KVM for KVM_CHECK_EXTENSION ioctl KVM: PPC: move vcpu_load/vcpu_put down to each ioctl case in kvm_arch_vcpu_ioctl KVM: PPC: remove load/put vcpu for KVM_GET/SET_ONE_REG ioctl KVM: PPC: remove load/put vcpu for KVM_GET_REGS/KVM_SET_REGS KVM: PPC: Book3S PR: enable kvmppc_get/set_one_reg_pr() for HTM registers arch/powerpc/include/asm/asm-prototypes.h | 9 + arch/powerpc/include/asm/kvm_book3s.h | 16 + arch/powerpc/include/asm/kvm_host.h | 1 - arch/powerpc/include/asm/reg.h | 32 +- arch/powerpc/include/asm/tm.h | 2 - arch/powerpc/include/uapi/asm/tm.h | 2 +- arch/powerpc/kernel/process.c | 1 + arch/powerpc/kernel/tm.S | 12 + arch/powerpc/kvm/Makefile | 3 + arch/powerpc/kvm/book3s.c | 6 - arch/powerpc/kvm/book3s.h | 6 + arch/powerpc/kvm/book3s_64_mmu.c | 11 +- arch/powerpc/kvm/book3s_emulate.c | 369 +++++++++++++++++++++- arch/powerpc/kvm/book3s_hv_rmhandlers.S | 343 +------------------- arch/powerpc/kvm/book3s_pr.c | 339 ++++++++++++++++++-- arch/powerpc/kvm/book3s_segment.S | 13 + arch/powerpc/kvm/powerpc.c | 12 +- arch/powerpc/kvm/tm.S | 467 ++++++++++++++++++++++++++++ arch/powerpc/mm/hash_utils_64.c | 1 + arch/powerpc/platforms/powernv/copy-paste.h | 3 +- 20 files changed, 1260 insertions(+), 388 deletions(-) create mode 100644 arch/powerpc/kvm/tm.S