From patchwork Thu Nov 23 04:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 10072321 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5ED18601D5 for ; Thu, 23 Nov 2017 04:40:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FE172966C for ; Thu, 23 Nov 2017 04:40:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 44FDC29DB9; Thu, 23 Nov 2017 04:40:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D5382966C for ; Thu, 23 Nov 2017 04:40:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752660AbdKWEk3 (ORCPT ); Wed, 22 Nov 2017 23:40:29 -0500 Received: from gate.crashing.org ([63.228.1.57]:55517 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752584AbdKWEk2 (ORCPT ); Wed, 22 Nov 2017 23:40:28 -0500 Received: from pasglop.ozlabs.ibm.com (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id vAN4aMBK027724; Wed, 22 Nov 2017 22:36:45 -0600 From: Benjamin Herrenschmidt To: Paul Mackerras Cc: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, Benjamin Herrenschmidt Subject: [PATCH v2 10/11] powerpc/kvm: Store the MMU mode in the PACA on KVM exit Date: Thu, 23 Nov 2017 15:36:18 +1100 Message-Id: <20171123043619.15301-10-benh@kernel.crashing.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171123043619.15301-1-benh@kernel.crashing.org> References: <20171123043619.15301-1-benh@kernel.crashing.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This stores the MMU mode (real vs. virt) in the PACA on exceptions that do a KVM test. At the moment, we do this unconditionally in those exceptions due to how the macro system is put together. In the future we could find a way to only do it when actually exiting a guest. This will avoid a pile of mfmsr in the KVM exit path Signed-off-by: Benjamin Herrenschmidt --- arch/powerpc/include/asm/exception-64s.h | 38 ++++++++++++++++++++++--------- arch/powerpc/include/asm/kvm_book3s_asm.h | 1 + arch/powerpc/kernel/asm-offsets.c | 1 + arch/powerpc/kernel/exceptions-64s.S | 15 +++++++----- 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/arch/powerpc/include/asm/exception-64s.h b/arch/powerpc/include/asm/exception-64s.h index 9a318973af05..0921328aea78 100644 --- a/arch/powerpc/include/asm/exception-64s.h +++ b/arch/powerpc/include/asm/exception-64s.h @@ -238,7 +238,9 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) EXCEPTION_PROLOG_1(area, extra, vec); \ EXCEPTION_PROLOG_PSERIES_1(label, h); -#define __KVMTEST(h, n) \ +#define __KVMTEST(h, n, v) \ + li r10,v; \ + stb r10,HSTATE_EXIT_VIRT(r13); \ lbz r10,HSTATE_IN_GUEST(r13); \ cmpwi r10,0; \ bne do_kvm_##h##n @@ -348,12 +350,12 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) b kvmppc_skip_##h##interrupt #ifdef CONFIG_KVM_BOOK3S_64_HANDLER -#define KVMTEST(h, n) __KVMTEST(h, n) +#define KVMTEST(h, n, v) __KVMTEST(h, n, v) #define KVM_HANDLER(area, h, n) __KVM_HANDLER(area, h, n) #define KVM_HANDLER_SKIP(area, h, n) __KVM_HANDLER_SKIP(area, h, n) #else -#define KVMTEST(h, n) +#define KVMTEST(h, n, v) #define KVM_HANDLER(area, h, n) #define KVM_HANDLER_SKIP(area, h, n) #endif @@ -477,10 +479,10 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) #define STD_RELON_EXCEPTION_HV(loc, vec, label) \ SET_SCRATCH0(r13); /* save r13 */ \ EXCEPTION_RELON_PROLOG_PSERIES(PACA_EXGEN, label, \ - EXC_HV, KVMTEST_HV, vec); + EXC_HV, KVMTEST_RELON_HV, vec); #define STD_RELON_EXCEPTION_HV_OOL(vec, label) \ - EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_HV, vec); \ + EXCEPTION_PROLOG_1(PACA_EXGEN, KVMTEST_RELON_HV, vec); \ EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) /* This associate vector numbers with bits in paca->irq_happened */ @@ -501,18 +503,32 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) #define _SOFTEN_TEST(h, vec) __SOFTEN_TEST(h, vec) #define SOFTEN_TEST_PR(vec) \ - KVMTEST(EXC_STD, vec); \ + KVMTEST(EXC_STD, vec, 0); \ _SOFTEN_TEST(EXC_STD, vec) #define SOFTEN_TEST_HV(vec) \ - KVMTEST(EXC_HV, vec); \ + KVMTEST(EXC_HV, vec, 0); \ + _SOFTEN_TEST(EXC_HV, vec) + +#define SOFTEN_TEST_RELON_PR(vec) \ + KVMTEST(EXC_STD, vec, 1); \ + _SOFTEN_TEST(EXC_STD, vec) + +#define SOFTEN_TEST_RELON_HV(vec) \ + KVMTEST(EXC_HV, vec, 1); \ _SOFTEN_TEST(EXC_HV, vec) #define KVMTEST_PR(vec) \ - KVMTEST(EXC_STD, vec) + KVMTEST(EXC_STD, vec, 0) #define KVMTEST_HV(vec) \ - KVMTEST(EXC_HV, vec) + KVMTEST(EXC_HV, vec, 0) + +#define KVMTEST_RELON_PR(vec) \ + KVMTEST(EXC_STD, vec, 1) + +#define KVMTEST_RELON_HV(vec) \ + KVMTEST(EXC_HV, vec, 1) #define SOFTEN_NOTEST_PR(vec) _SOFTEN_TEST(EXC_STD, vec) #define SOFTEN_NOTEST_HV(vec) _SOFTEN_TEST(EXC_HV, vec) @@ -557,10 +573,10 @@ END_FTR_SECTION_NESTED(ftr,ftr,943) #define MASKABLE_RELON_EXCEPTION_HV(loc, vec, label) \ _MASKABLE_RELON_EXCEPTION_PSERIES(vec, label, \ - EXC_HV, SOFTEN_TEST_HV) + EXC_HV, SOFTEN_TEST_RELON_HV) #define MASKABLE_RELON_EXCEPTION_HV_OOL(vec, label) \ - EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_HV, vec); \ + EXCEPTION_PROLOG_1(PACA_EXGEN, SOFTEN_TEST_RELON_HV, vec); \ EXCEPTION_RELON_PROLOG_PSERIES_1(label, EXC_HV) /* diff --git a/arch/powerpc/include/asm/kvm_book3s_asm.h b/arch/powerpc/include/asm/kvm_book3s_asm.h index 83596f32f50b..7775a278e56e 100644 --- a/arch/powerpc/include/asm/kvm_book3s_asm.h +++ b/arch/powerpc/include/asm/kvm_book3s_asm.h @@ -118,6 +118,7 @@ struct kvmppc_host_state { void __iomem *xive_tima_phys; void __iomem *xive_tima_virt; u32 saved_xirr; + u8 exit_virt; /* MMU mode on exception exit */ u64 dabr; u64 host_mmcr[7]; /* MMCR 0,1,A, SIAR, SDAR, MMCR2, SIER */ u32 host_pmc[8]; diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index eff521c67ec3..87e3cd09659c 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -641,6 +641,7 @@ int main(void) HSTATE_FIELD(HSTATE_XIVE_TIMA_PHYS, xive_tima_phys); HSTATE_FIELD(HSTATE_XIVE_TIMA_VIRT, xive_tima_virt); HSTATE_FIELD(HSTATE_SAVED_XIRR, saved_xirr); + HSTATE_FIELD(HSTATE_EXIT_VIRT, exit_virt); HSTATE_FIELD(HSTATE_HOST_IPI, host_ipi); HSTATE_FIELD(HSTATE_PTID, ptid); HSTATE_FIELD(HSTATE_MMCR0, host_mmcr[0]); diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S index 1c80bd292e48..8a0cd4fdf015 100644 --- a/arch/powerpc/kernel/exceptions-64s.S +++ b/arch/powerpc/kernel/exceptions-64s.S @@ -700,9 +700,9 @@ EXC_VIRT_BEGIN(hardware_interrupt, 0x4500, 0x100) .globl hardware_interrupt_relon_hv; hardware_interrupt_relon_hv: BEGIN_FTR_SECTION - _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_HV) + _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_HV, SOFTEN_TEST_RELON_HV) FTR_SECTION_ELSE - _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_PR) + _MASKABLE_RELON_EXCEPTION_PSERIES(0x500, hardware_interrupt_common, EXC_STD, SOFTEN_TEST_RELON_PR) ALT_FTR_SECTION_END_IFSET(CPU_FTR_HVMODE) EXC_VIRT_END(hardware_interrupt, 0x4500, 0x100) @@ -870,21 +870,24 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception) * Userspace syscalls have already saved the PPR, hcalls must save * it before setting HMT_MEDIUM. */ -#define SYSCALL_KVMTEST \ +#define __SYSCALL_KVMTEST(test) \ mtctr r13; \ GET_PACA(r13); \ std r10,PACA_EXGEN+EX_R10(r13); \ - KVMTEST_PR(0xc00); /* uses r10, branch to do_kvm_0xc00_system_call */ \ + test; /* uses r10, branch to do_kvm_0xc00_system_call */ \ HMT_MEDIUM; \ mfctr r9; +#define SYSCALL_KVMTEST __SYSCALL_KVMTEST(KVMTEST_PR(0xc00)) +#define SYSCALL_KVMTEST_RELON __SYSCALL_KVMTEST(KVMTEST_RELON_PR(0xc00)) #else #define SYSCALL_KVMTEST \ HMT_MEDIUM; \ mr r9,r13; \ GET_PACA(r13); +#define SYSCALL_KVMTEST_RELON SYSCALL_KVMTEST #endif - + #define LOAD_SYSCALL_HANDLER(reg) \ __LOAD_HANDLER(reg, system_call_common) @@ -948,7 +951,7 @@ EXC_REAL_BEGIN(system_call, 0xc00, 0x100) EXC_REAL_END(system_call, 0xc00, 0x100) EXC_VIRT_BEGIN(system_call, 0x4c00, 0x100) - SYSCALL_KVMTEST /* loads PACA into r13, and saves r13 to r9 */ + SYSCALL_KVMTEST_RELON /* loads PACA into r13, and saves r13 to r9 */ SYSCALL_FASTENDIAN_TEST SYSCALL_VIRT SYSCALL_FASTENDIAN