From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2F17C433DF for ; Thu, 20 Aug 2020 10:41:02 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D85720639 for ; Thu, 20 Aug 2020 10:41:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="wraM9tpT"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="UGKHI5Om" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D85720639 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=udq/HJ1hjlX97R3IMRRd9B5H4kLoQY9XicA4B/fb3xc=; b=wraM9tpTsIl+lFl7fMxIrX6Mf qjqlXwSwZcmWbzi7/0Q3/aUcgUKbpyqCVguOE5YVfSinug6AhqjEfHs6eP/UpDJMEoDb3HEQAF63i 2YbzaqgYYp4YUoUzaTVjzmtx5WwSgsDW3TjqFCihse/YRMZ7c7qW0fK9pVjMFGXM9oymmGTrFlx96 EgashN3/rfey3XrwHdbRJCATx4i9uNWm9xPXbdSekX8M3C6CNMt4aRdyRtDZXGPV8CIqrEmsHg4Ex x7psIpSx7ALZFC2HRr3ZIiIzSNqANw7OywZYOwvu2A6eoRjwCyOlfq/dUygw/Fx5GbwAxXLBf4AwI 4a8mxXX8Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8hyQ-0003v1-De; Thu, 20 Aug 2020 10:39:10 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k8hvU-0002CY-0H for linux-arm-kernel@lists.infradead.org; Thu, 20 Aug 2020 10:36:09 +0000 Received: by mail-wm1-x34a.google.com with SMTP id g72so811699wme.4 for ; Thu, 20 Aug 2020 03:36:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=YnIDkojxZWvGrLdfzL+x20jLDIFUW/oDu0/bNDDOHqc=; b=UGKHI5OmI2cUPFTctM+KI91jNDPnK6yq6zAihfswg9a1jHU4W+tLBBL0gE3mVPMb8N oO2tHKOtxCqvJD1Vmi75sPsdDINO9+v4qNUeidnCjdweLYiTaud/DOTs19qNJE5Yixrm HMoh2l3Hd4E0RADAGN/4LVVpadYG3NuLMyynA50ToRXqmGYlA2L8Dvko30jtACBP6qHz bM9RRkepPzlXCvkfggwXh10srG29+0Mce90livaULrWj5QWD9oI2sYQ+bADKpz9LjPVc mU8gdXl3XerbsEbC3eNBR72F29Y1PTVSXezBo2jlMfuHm+WUSnJeDCS9bftZpzirUU26 ejwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=YnIDkojxZWvGrLdfzL+x20jLDIFUW/oDu0/bNDDOHqc=; b=ig5Vpf63U3eSQWHg3/B78uVcGC3wzmI+DsFWlIxfP8PWLR6siYWSmF3WKFPDTCi2RD E4sjOlSj0+vM+QaRKMnLzouIvD/tPRp9NgVzCmcLbgllRfV4tj0rO5Wha7BMHKGM9IcY Mvi7jI6Eo4iEKaVoi87QF+fWEhuk/93jJMGWO474ewZo/7CgoK3StNFmO7MCnTEEf8gj lgtZUEa7gN7eb2tGzcupiuSoGk+3GpfRke+rKRQ798xGWnCmK/Hx7WwgYcvnJuYCLNqe 2sOV7fGm+VHs9eeDzCn9FScvDHFqt1TkE01baoeFEm3K2TnezkTWMIUxVEOqiHTAMDTR PeDg== X-Gm-Message-State: AOAM533zeWjsq7lTSOA9JT1GZHTIZR75HNjA3sbALjgr1gdVgcGgzuXY 4xJ0y7CPFIRAPhtD0VnxUWt13Z32RBE= X-Google-Smtp-Source: ABdhPJwT89xJnZRWjqWD0qIGZ2McuPGMJdHO9+XfTBNdOsErjCDjeyowWHssxGWNT5eWz/3MNzgKYBCgVMg= X-Received: from ascull.lon.corp.google.com ([2a00:79e0:d:109:4a0f:cfff:fe4a:6363]) (user=ascull job=sendgmr) by 2002:adf:e7cd:: with SMTP id e13mr2531035wrn.227.1597919763968; Thu, 20 Aug 2020 03:36:03 -0700 (PDT) Date: Thu, 20 Aug 2020 11:34:46 +0100 In-Reply-To: <20200820103446.959000-1-ascull@google.com> Message-Id: <20200820103446.959000-21-ascull@google.com> Mime-Version: 1.0 References: <20200820103446.959000-1-ascull@google.com> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog Subject: [PATCH v2 20/20] KVM: arm64: nVHE: Handle stub HVCs in the host loop From: Andrew Scull To: kvmarm@lists.cs.columbia.edu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200820_063608_111233_E1F4831B X-CRM114-Status: GOOD ( 19.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, kernel-team@android.com, suzuki.poulose@arm.com, maz@kernel.org, Sudeep Holla , james.morse@arm.com, Andrew Scull , catalin.marinas@arm.com, will@kernel.org, julien.thierry.kdev@gmail.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Since the host is called from the hyp run loop, we can use that context to identify calls from the host rather than checking VTTBR_EL2, which will be used for the host's stage 2 in future. Moving this to C also allows for more flexibiliy e.g. in applying policies, such as forbidding HVC_RESET_VECTORS, based on the current state of the hypervisor and removes the special casing for nVHE in the exception handler. Control over arch workaround 2 is made available to the host, the same as any other vcpu. Signed-off-by: Andrew Scull --- arch/arm64/kvm/hyp/hyp-entry.S | 1 - arch/arm64/kvm/hyp/nvhe/host.S | 26 +-------------- arch/arm64/kvm/hyp/nvhe/hyp-init.S | 13 ++++++-- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 51 +++++++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index b7a1ea221f6e..db54f84003ec 100644 --- a/arch/arm64/kvm/hyp/hyp-entry.S +++ b/arch/arm64/kvm/hyp/hyp-entry.S @@ -24,7 +24,6 @@ el1_sync: // Guest trapped into EL2 ccmp x0, #ESR_ELx_EC_HVC32, #4, ne b.ne el1_trap -el1_hvc_guest: /* * Fastest possible path for ARM_SMCCC_ARCH_WORKAROUND_1. * The workaround has already been applied on the host, diff --git a/arch/arm64/kvm/hyp/nvhe/host.S b/arch/arm64/kvm/hyp/nvhe/host.S index 40620c1c87b8..68d425b7bd62 100644 --- a/arch/arm64/kvm/hyp/nvhe/host.S +++ b/arch/arm64/kvm/hyp/nvhe/host.S @@ -95,31 +95,7 @@ SYM_FUNC_END(__hyp_do_panic) .macro valid_host_el1_sync_vect .align 7 - stp x0, x1, [sp, #-16]! - mrs x0, esr_el2 - lsr x0, x0, #ESR_ELx_EC_SHIFT - cmp x0, #ESR_ELx_EC_HVC64 - ldp x0, x1, [sp], #16 - b.ne __host_exit - - /* Check for a stub HVC call */ - cmp x0, #HVC_STUB_HCALL_NR - b.hs __host_exit - - /* - * Compute the idmap address of __kvm_handle_stub_hvc and - * jump there. Since we use kimage_voffset, do not use the - * HYP VA for __kvm_handle_stub_hvc, but the kernel VA instead - * (by loading it from the constant pool). - * - * Preserve x0-x4, which may contain stub parameters. - */ - ldr x5, =__kvm_handle_stub_hvc - ldr_l x6, kimage_voffset - - /* x5 = __pa(x5) */ - sub x5, x5, x6 - br x5 + b __host_exit .endm .macro invalid_host_el2_vect diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-init.S b/arch/arm64/kvm/hyp/nvhe/hyp-init.S index 47224dc62c51..40b5aa95c194 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-init.S +++ b/arch/arm64/kvm/hyp/nvhe/hyp-init.S @@ -16,6 +16,9 @@ #include #include +#include +#include + .text .pushsection .hyp.idmap.text, "ax" @@ -138,6 +141,7 @@ SYM_CODE_START(__kvm_handle_stub_hvc) cmp x0, #HVC_SOFT_RESTART b.ne 1f +SYM_INNER_LABEL(__kvm_handle_stub_hvc_soft_restart, SYM_L_GLOBAL) /* This is where we're about to jump, staying at EL2 */ msr elr_el2, x1 mov x0, #(PSR_F_BIT | PSR_I_BIT | PSR_A_BIT | PSR_D_BIT | PSR_MODE_EL2h) @@ -150,8 +154,13 @@ SYM_CODE_START(__kvm_handle_stub_hvc) b reset 1: cmp x0, #HVC_RESET_VECTORS - b.ne 1f + b.ne 3f + b 2f + +SYM_INNER_LABEL(__kvm_handle_stub_hvc_reset_vectors, SYM_L_GLOBAL) + restore_callee_saved_regs x5 +2: /* * Set the HVC_RESET_VECTORS return code before entering the common * path so that we do not clobber x0-x2 in case we are coming via @@ -172,7 +181,7 @@ reset: msr vbar_el2, x5 eret -1: /* Bad stub call */ +3: /* Bad stub call */ mov_q x0, HVC_STUB_ERR eret diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 78d7afcefbb8..302333ea96eb 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -14,6 +14,52 @@ #include +typedef __noreturn unsigned long (*stub_hvc_handler_t) + (unsigned long, unsigned long, unsigned long, unsigned long, + unsigned long, struct kvm_cpu_context *); + +extern char __kvm_handle_stub_hvc_soft_restart[]; +extern char __kvm_handle_stub_hvc_reset_vectors[]; + +static void handle_stub_hvc(unsigned long func_id, + struct kvm_cpu_context *host_ctxt) +{ + char *stub_hvc_handler_kern_va; + stub_hvc_handler_t stub_hvc_handler; + + /* + * The handlers of the supported stub HVCs disable the MMU so they must + * be called in the idmap. We compute the idmap address by subtracting + * kimage_voffset from the kernel VA handler. + */ + switch (func_id) { + case HVC_SOFT_RESTART: + asm volatile("ldr %0, =%1" + : "=r" (stub_hvc_handler_kern_va) + : "S" (__kvm_handle_stub_hvc_soft_restart)); + break; + case HVC_RESET_VECTORS: + asm volatile("ldr %0, =%1" + : "=r" (stub_hvc_handler_kern_va) + : "S" (__kvm_handle_stub_hvc_reset_vectors)); + break; + default: + host_ctxt->regs.regs[0] = HVC_STUB_ERR; + return; + } + + stub_hvc_handler = (stub_hvc_handler_t) + (stub_hvc_handler_kern_va - kimage_voffset); + + /* Preserve x0-x4, which may contain stub parameters. */ + stub_hvc_handler(func_id, + host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], + host_ctxt->regs.regs[3], + host_ctxt->regs.regs[4], + host_ctxt); +} + static void handle_host_hcall(unsigned long func_id, struct kvm_cpu_context *host_ctxt) { @@ -118,5 +164,8 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) { hyp_panic(); func_id = host_ctxt->regs.regs[0]; - handle_host_hcall(func_id, host_ctxt); + if (func_id < HVC_STUB_HCALL_NR) + handle_stub_hvc(func_id, host_ctxt); + else + handle_host_hcall(func_id, host_ctxt); } -- 2.28.0.220.ged08abb693-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel