From patchwork Tue Jul 3 09:00:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 1149561 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 3A36DDFF72 for ; Tue, 3 Jul 2012 09:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753616Ab2GCJAz (ORCPT ); Tue, 3 Jul 2012 05:00:55 -0400 Received: from mail-qa0-f53.google.com ([209.85.216.53]:40219 "EHLO mail-qa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753538Ab2GCJAy (ORCPT ); Tue, 3 Jul 2012 05:00:54 -0400 Received: by qaas11 with SMTP id s11so2426973qaa.19 for ; Tue, 03 Jul 2012 02:00:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:to:from:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding :x-gm-message-state; bh=1DHi+gr9uZPH1n4Nb3S69KDM6D45dHv3jHqC8fhYiHM=; b=N5tYj+nqEFuqL/1pHpvMVuCMJwzURO62MWDvj+CRLbd9OJdwxB7hvnhsEFAtBhqOPQ eg3Buio+d765JUy/kXHc0yP9lNrTyqGx8eT8nJOywp/HSybDzBwKOKs1dy+AewOBy7/c 7FnkocK/1yOUAoQfmm+qdORkTKu3nm3xnDeHx3Ex71lJbGvhUDE+aZnEVuAP7xekNlfg 0DZ4o7RkJkNq0j1nl2niYlOB8V2TnbbLumvuooR20855G8FQMncZUtHCbtCdi7p5tEy6 7vny8Ezb/88aU/sr3X8Dc2hCu7Bz+JUrTt6oHDi2HomtcX96RH0a+HAe6aNKKFLGaetj Xicw== Received: by 10.229.134.205 with SMTP id k13mr8087427qct.153.1341306053158; Tue, 03 Jul 2012 02:00:53 -0700 (PDT) Received: from [127.0.1.1] (fireball.cs.columbia.edu. [128.59.13.10]) by mx.google.com with ESMTPS id gb7sm37042742qab.12.2012.07.03.02.00.52 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 03 Jul 2012 02:00:52 -0700 (PDT) Subject: [PATCH v9 09/16] ARM: KVM: Module unloading support To: android-virt@lists.cs.columbia.edu, kvm@vger.kernel.org From: Christoffer Dall Cc: tech@virtualopensystems.com Date: Tue, 03 Jul 2012 05:00:51 -0400 Message-ID: <20120703090051.27746.66039.stgit@ubuntu> In-Reply-To: <20120703085841.27746.82730.stgit@ubuntu> References: <20120703085841.27746.82730.stgit@ubuntu> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Gm-Message-State: ALoCoQl4gF3t+PibR3myi1n5JJbeRmiZvp+yjaomB+JAGAsnz3Ev/T9Zwdlop9H1mfzWFroFFo/v Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Current initialization code relies on the MMU-bit and TE-bit of the HSCTLR register to be cleared, so to support re-inserting the KVM module we must clear these bits when unloading the module. This is going to change when we support booting the kernel in Hyp mode and get rid of the SMC call, in that we will have to issue an HVC call with a parameter instead. Signed-off-by: Christoffer Dall --- arch/arm/include/asm/kvm_asm.h | 3 +++ arch/arm/kvm/arm.c | 42 ++++++++++++++++++++++++++++++++++++++++ arch/arm/kvm/exports.c | 3 +++ arch/arm/kvm/init.S | 28 +++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/arm/include/asm/kvm_asm.h b/arch/arm/include/asm/kvm_asm.h index 77831b1..58d51e3 100644 --- a/arch/arm/include/asm/kvm_asm.h +++ b/arch/arm/include/asm/kvm_asm.h @@ -39,6 +39,9 @@ struct kvm_vcpu; extern char __kvm_hyp_init[]; extern char __kvm_hyp_init_end[]; +extern char __kvm_hyp_exit[]; +extern char __kvm_hyp_exit_end[]; + extern char __kvm_hyp_vector[]; extern char __kvm_hyp_code_start[]; diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index dccac7c..63593ee 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -423,10 +423,52 @@ out_err: return err; } +static void cpu_exit_hyp_mode(void *vector) +{ + cpu_set_vector(vector); + + /* + * Disable Hyp-MMU for each cpu + */ + asm volatile ("hvc #0"); +} + +static int exit_hyp_mode(void) +{ + phys_addr_t exit_phys_addr; + int cpu; + + /* + * TODO: flush Hyp TLB in case idmap code overlaps. + * Note that we should do this in the monitor code when switching the + * HVBAR, but this is going away and should be rather done in the Hyp + * mode change of HVBAR. + */ + hyp_idmap_setup(); + exit_phys_addr = virt_to_phys(__kvm_hyp_exit); + BUG_ON(exit_phys_addr & 0x1f); + + /* + * Execute the exit code on each CPU. + * + * Note: The stack is not mapped yet, so don't do anything else than + * initializing the hypervisor mode on each CPU using a local stack + * space for temporary storage. + */ + for_each_online_cpu(cpu) { + smp_call_function_single(cpu, cpu_exit_hyp_mode, + (void *)(long)exit_phys_addr, 1); + } + + return 0; +} + void kvm_arch_exit(void) { int cpu; + exit_hyp_mode(); + free_hyp_pmds(); for_each_possible_cpu(cpu) free_page(per_cpu(kvm_arm_hyp_stack_page, cpu)); diff --git a/arch/arm/kvm/exports.c b/arch/arm/kvm/exports.c index c432c92..8ebdf07 100644 --- a/arch/arm/kvm/exports.c +++ b/arch/arm/kvm/exports.c @@ -22,6 +22,9 @@ EXPORT_SYMBOL_GPL(__kvm_hyp_init); EXPORT_SYMBOL_GPL(__kvm_hyp_init_end); +EXPORT_SYMBOL_GPL(__kvm_hyp_exit); +EXPORT_SYMBOL_GPL(__kvm_hyp_exit_end); + EXPORT_SYMBOL_GPL(__kvm_hyp_vector); EXPORT_SYMBOL_GPL(__kvm_hyp_code_start); diff --git a/arch/arm/kvm/init.S b/arch/arm/kvm/init.S index 7a046fa..4db26cb 100644 --- a/arch/arm/kvm/init.S +++ b/arch/arm/kvm/init.S @@ -118,4 +118,32 @@ __do_hyp_init: .globl __kvm_hyp_init_end __kvm_hyp_init_end: + .align 12 +__kvm_hyp_exit: + .globl __kvm_hyp_exit + + @ Hyp-mode exception vector + nop + nop + nop + nop + nop + b __do_hyp_exit + nop + nop + +__do_hyp_exit: + @ Clear the MMU and TE bits in the HSCR + mrc p15, 4, sp, c1, c0, 0 @ HSCR + bic sp, sp, #((1 << 30) | (1 << 0)) + + isb + mcr p15, 4, sp, c1, c0, 0 @ HSCR + mcr p15, 4, r0, c8, c7, 0 @ Flush Hyp TLB, r0 ignored + isb + eret + + .globl __kvm_hyp_exit_end +__kvm_hyp_exit_end: + .popsection