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=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham 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 A6900C2D0A3 for ; Mon, 9 Nov 2020 11:33:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5771A206A4 for ; Mon, 9 Nov 2020 11:33:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="OQc11lBo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729704AbgKILdK (ORCPT ); Mon, 9 Nov 2020 06:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729589AbgKILdE (ORCPT ); Mon, 9 Nov 2020 06:33:04 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3CA4C0613CF for ; Mon, 9 Nov 2020 03:33:03 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id a65so7614346wme.1 for ; Mon, 09 Nov 2020 03:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=OQc11lBoTR5fJLdx+W2P8jL214ocEiZbxcjChcEvDu+j2dkB9NsUrsMdFWRHDmee3D sYikdoR0rn5I+XINzOWJlUa5jGseeRnNVR8gfCsKBm4VUfReK9aFmu18nleZIGhQSzcq D68YQ0GXpLN6ipsxq+zdaVPhgTboJ4+FUJeb/M67GrzOMDLPVZcxDPi0fFbPdWeXmFrl hCTReFIEwsH5+p+JPg27Ma8hKvS3cDoYmhYKAFBpXZ9yuycea852h2+1pF7f6la98cXt wq5a4CtNC/F6NmihcNri6n2Nfcia3CNPUHmhxlM6YWwOI7QNr+5owVOn0ujXVRZi7D2n 1QqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=lIxnZZPZHyjarnM2vvWHCgcVLkuUHgCmRy9Jb2XMXbqtoqZRYTfo4DRVbrbwGb2H4a WGp0lrRvOzM/3xByfpfpOWLlMGjApPmuVPX6wwUSEyBVRHY7pymIDPI1z6b/sflN0w7g +OWbVK6zis7CVkAznFjj4E2TwgBsxY7IkT8Bd0P6M0Oeui9/IvrRpG4HEcLFhL3zlvgc 1Bh2juggfnzitab0hG9KwLO1ySu/O/B9E8eYWV8Td/j3V0vs3dOKWucaoq542TtYb2VL ALwlxJtRXZHp5QGOSz+8arJk4NgNLO5Gh+vAFMroutJH84TaznC/mzQOB1JQPPfEn7kd ockg== X-Gm-Message-State: AOAM531DByQfGrLaA6bZz2a6vFxydgz5y+T/T7mFadM6Ww7uPaZclAmh C6W9X/kTT/Cio+Luo6Pc2iFto+nJlmlxWaY4 X-Google-Smtp-Source: ABdhPJzvaLtgbVxyZ2GDPcw/eFFKQNxLYoWLsP6DD3k4mKvCQB7oh0IBN8nQ6nLo0FuIJVxGVngrTA== X-Received: by 2002:a7b:c20d:: with SMTP id x13mr13474111wmi.167.1604921582538; Mon, 09 Nov 2020 03:33:02 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id t11sm12458783wmf.35.2020.11.09.03.33.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:01 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Catalin Marinas , Will Deacon , Dennis Zhou , Tejun Heo , Christoph Lameter , Mark Rutland , Lorenzo Pieralisi , Quentin Perret , Andrew Scull , Andrew Walbran , kernel-team@android.com, David Brazdil Subject: [PATCH v1 11/24] kvm: arm64: Add SMC handler in nVHE EL2 Date: Mon, 9 Nov 2020 11:32:20 +0000 Message-Id: <20201109113233.9012-12-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add handler of host SMCs in KVM nVHE trap handler. Forward all SMCs to EL3 and propagate the result back to EL1. This is done in preparation for validating host SMCs in KVM nVHE protected mode. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 19332c20fcde..8661bc7deaa9 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -106,6 +106,38 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) host_ctxt->regs.regs[1] = ret; } +static void skip_host_instruction(void) +{ + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); +} + +static void forward_host_smc(struct kvm_cpu_context *host_ctxt) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3], + host_ctxt->regs.regs[4], host_ctxt->regs.regs[5], + host_ctxt->regs.regs[6], host_ctxt->regs.regs[7], + &res); + host_ctxt->regs.regs[0] = res.a0; + host_ctxt->regs.regs[1] = res.a1; + host_ctxt->regs.regs[2] = res.a2; + host_ctxt->regs.regs[3] = res.a3; +} + +static void handle_host_smc(struct kvm_cpu_context *host_ctxt) +{ + /* + * Unlike HVC, the return address of an SMC is the instruction's PC. + * Move the return address past the instruction. + */ + skip_host_instruction(); + + /* Forward SMC not handled in EL2 to EL3. */ + forward_host_smc(host_ctxt); +} + void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr = read_sysreg_el2(SYS_ESR); @@ -114,6 +146,9 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); break; + case ESR_ELx_EC_SMC64: + handle_host_smc(host_ctxt); + break; default: hyp_panic(); } -- 2.29.2.222.g5d2a92d10f8-goog 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 83F3AC4741F for ; Mon, 9 Nov 2020 11:33:08 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id E8A9E20731 for ; Mon, 9 Nov 2020 11:33:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="OQc11lBo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E8A9E20731 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvmarm-bounces@lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 867E14B772; Mon, 9 Nov 2020 06:33:07 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FPnee3L-8SY3; Mon, 9 Nov 2020 06:33:06 -0500 (EST) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 7CF3F4B627; Mon, 9 Nov 2020 06:33:06 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id BDA4A4B72B for ; Mon, 9 Nov 2020 06:33:04 -0500 (EST) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id QFaf06vXESsN for ; Mon, 9 Nov 2020 06:33:03 -0500 (EST) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id C258F4B7E3 for ; Mon, 9 Nov 2020 06:33:03 -0500 (EST) Received: by mail-wm1-f67.google.com with SMTP id p19so5264212wmg.0 for ; Mon, 09 Nov 2020 03:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=OQc11lBoTR5fJLdx+W2P8jL214ocEiZbxcjChcEvDu+j2dkB9NsUrsMdFWRHDmee3D sYikdoR0rn5I+XINzOWJlUa5jGseeRnNVR8gfCsKBm4VUfReK9aFmu18nleZIGhQSzcq D68YQ0GXpLN6ipsxq+zdaVPhgTboJ4+FUJeb/M67GrzOMDLPVZcxDPi0fFbPdWeXmFrl hCTReFIEwsH5+p+JPg27Ma8hKvS3cDoYmhYKAFBpXZ9yuycea852h2+1pF7f6la98cXt wq5a4CtNC/F6NmihcNri6n2Nfcia3CNPUHmhxlM6YWwOI7QNr+5owVOn0ujXVRZi7D2n 1QqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=Zm3mPNze/p+SDHsoO6l2DapidigngdTAuUZtAv2K6Is4NFpEdkR63xK6sM5x/50qU2 aeEODBkvrRLXAMNPBIIyVXOTVZ++YkjjNJw7cHh9wMTzrevWxhmsChB5PanErkmrxIjp zNNrlEpP3xU3tNWDzZ6MXqpaHhNrmesmOm5AI9Jy5+pZzel3B11lssynfbfm4M4z1XCi TdfZI7eMilAxgL6wAHm60lsOsGHVa1ILy3FR/AMkHp+/UwLSh+DdHitgCo5Md7JeX25M FDZ/OwsRbl2dMayRKxA2dWYNptToFjaaSzxdjI4YHSyppehGXPigplSp6x9IoBGDfLlQ k5Ug== X-Gm-Message-State: AOAM532lxLgXtSKsaQXnRVLA1HdLPn3wG2QVKIM0RFs1hMth7OLXg5kd oXumGf0dsn2Cbp4jD2O1nuTecI9awL076bYy X-Google-Smtp-Source: ABdhPJzvaLtgbVxyZ2GDPcw/eFFKQNxLYoWLsP6DD3k4mKvCQB7oh0IBN8nQ6nLo0FuIJVxGVngrTA== X-Received: by 2002:a7b:c20d:: with SMTP id x13mr13474111wmi.167.1604921582538; Mon, 09 Nov 2020 03:33:02 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id t11sm12458783wmf.35.2020.11.09.03.33.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:01 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 11/24] kvm: arm64: Add SMC handler in nVHE EL2 Date: Mon, 9 Nov 2020 11:32:20 +0000 Message-Id: <20201109113233.9012-12-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 Cc: kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , Marc Zyngier , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , Will Deacon X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Add handler of host SMCs in KVM nVHE trap handler. Forward all SMCs to EL3 and propagate the result back to EL1. This is done in preparation for validating host SMCs in KVM nVHE protected mode. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 19332c20fcde..8661bc7deaa9 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -106,6 +106,38 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) host_ctxt->regs.regs[1] = ret; } +static void skip_host_instruction(void) +{ + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); +} + +static void forward_host_smc(struct kvm_cpu_context *host_ctxt) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3], + host_ctxt->regs.regs[4], host_ctxt->regs.regs[5], + host_ctxt->regs.regs[6], host_ctxt->regs.regs[7], + &res); + host_ctxt->regs.regs[0] = res.a0; + host_ctxt->regs.regs[1] = res.a1; + host_ctxt->regs.regs[2] = res.a2; + host_ctxt->regs.regs[3] = res.a3; +} + +static void handle_host_smc(struct kvm_cpu_context *host_ctxt) +{ + /* + * Unlike HVC, the return address of an SMC is the instruction's PC. + * Move the return address past the instruction. + */ + skip_host_instruction(); + + /* Forward SMC not handled in EL2 to EL3. */ + forward_host_smc(host_ctxt); +} + void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr = read_sysreg_el2(SYS_ESR); @@ -114,6 +146,9 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); break; + case ESR_ELx_EC_SMC64: + handle_host_smc(host_ctxt); + break; default: hyp_panic(); } -- 2.29.2.222.g5d2a92d10f8-goog _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm 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.8 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 D881AC388F7 for ; Mon, 9 Nov 2020 11:35:54 +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 72FAF22201 for ; Mon, 9 Nov 2020 11:35:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZB/rPaYo"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="OQc11lBo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 72FAF22201 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:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lEIgw3jbTtQyvhFEjFLzqDhZ2/Hipu8JtJ7TsAAV7fk=; b=ZB/rPaYo3U+258jTj49SM3GOL 8f4XGk9ZPHsYHB6nr/nQzkBqKuPZNnW4VCqvaaNMQXTDo5SXddjbj/gKiJdsyZWMyZDiUmWfXZASn LwvqGb4Rl+xXVUwecb0US6vnXbxurrTbIrP2sLmVOByWcF9RlVxWFlzOj4x+ELlPKJ0NYMT8XWZQV mdnl6CudVtsSQC7roIRhw25AII6OP9ZLJaiIwYnSiSEfMKUCnuCcD5+yJxG/9do/u9pRdVJfjWk8N oWC/fgBRzxOm32t1PVRWD8yAXMxKbPEVCu4cq9PLXNVrtPmIDav3KdFmkaSMb/KB1ad6gZ0x37xat +O4shiaVA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5SC-0005JM-8L; Mon, 09 Nov 2020 11:35:20 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kc5Pz-0004Ru-LN for linux-arm-kernel@lists.infradead.org; Mon, 09 Nov 2020 11:33:14 +0000 Received: by mail-wm1-x344.google.com with SMTP id w24so5119079wmi.0 for ; Mon, 09 Nov 2020 03:33:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=OQc11lBoTR5fJLdx+W2P8jL214ocEiZbxcjChcEvDu+j2dkB9NsUrsMdFWRHDmee3D sYikdoR0rn5I+XINzOWJlUa5jGseeRnNVR8gfCsKBm4VUfReK9aFmu18nleZIGhQSzcq D68YQ0GXpLN6ipsxq+zdaVPhgTboJ4+FUJeb/M67GrzOMDLPVZcxDPi0fFbPdWeXmFrl hCTReFIEwsH5+p+JPg27Ma8hKvS3cDoYmhYKAFBpXZ9yuycea852h2+1pF7f6la98cXt wq5a4CtNC/F6NmihcNri6n2Nfcia3CNPUHmhxlM6YWwOI7QNr+5owVOn0ujXVRZi7D2n 1QqA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=LKrqV3xLA/ibeJM+AQCXY9IBi6Twfnl4kI7peR0SVVU=; b=ZbYdU7/85srHk4cjqkWIiXJiEsbwXV5rZSD6UzWEriUyuuU6O7cOl02ja+ih4MUx9x 7fU9elxjGIm4bgI/cq3//TWThLoLmzX6Eouxm+d7snBcBGPwMfg18OCxrVVf1rYTptAW 3oV+yUHEbvc0nTO1hnBX09qhK5PxsW1fi2FsEDcbkmhjeSlQvdx4xCpjcoB1xVvV+hoG JbWidSrvwGZKxZksStuOBRDfMrurSqc8iA/glNJTzJ1ksB9I2nisJ3uH4VuQklFnCTWT +CRf12dScu0B7GCleRcaqZHTqYUFmw/d3dQIKJ5HIP40Flt1ued+tmpkpx6uRQ9pS5dV nQEQ== X-Gm-Message-State: AOAM530K4RtRN+n8jCdAo/iXryTDYlZeo/zvBFu78w1GMLv1VoADnKFH 3RM2Q/kehsilTS9TX4ZCXNwUeA== X-Google-Smtp-Source: ABdhPJzvaLtgbVxyZ2GDPcw/eFFKQNxLYoWLsP6DD3k4mKvCQB7oh0IBN8nQ6nLo0FuIJVxGVngrTA== X-Received: by 2002:a7b:c20d:: with SMTP id x13mr13474111wmi.167.1604921582538; Mon, 09 Nov 2020 03:33:02 -0800 (PST) Received: from localhost ([2a01:4b00:8523:2d03:209d:10b7:c480:3e1f]) by smtp.gmail.com with ESMTPSA id t11sm12458783wmf.35.2020.11.09.03.33.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 09 Nov 2020 03:33:01 -0800 (PST) From: David Brazdil To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v1 11/24] kvm: arm64: Add SMC handler in nVHE EL2 Date: Mon, 9 Nov 2020 11:32:20 +0000 Message-Id: <20201109113233.9012-12-dbrazdil@google.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201109113233.9012-1-dbrazdil@google.com> References: <20201109113233.9012-1-dbrazdil@google.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201109_063304_498496_7B33013F X-CRM114-Status: GOOD ( 15.48 ) 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: Mark Rutland , kernel-team@android.com, Lorenzo Pieralisi , Andrew Walbran , Suzuki K Poulose , Marc Zyngier , Quentin Perret , linux-kernel@vger.kernel.org, James Morse , linux-arm-kernel@lists.infradead.org, Catalin Marinas , Tejun Heo , Dennis Zhou , Christoph Lameter , David Brazdil , Will Deacon , Julien Thierry , Andrew Scull 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 Add handler of host SMCs in KVM nVHE trap handler. Forward all SMCs to EL3 and propagate the result back to EL1. This is done in preparation for validating host SMCs in KVM nVHE protected mode. Signed-off-by: David Brazdil --- arch/arm64/kvm/hyp/nvhe/hyp-main.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c index 19332c20fcde..8661bc7deaa9 100644 --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c @@ -106,6 +106,38 @@ static void handle_host_hcall(struct kvm_cpu_context *host_ctxt) host_ctxt->regs.regs[1] = ret; } +static void skip_host_instruction(void) +{ + write_sysreg_el2(read_sysreg_el2(SYS_ELR) + 4, SYS_ELR); +} + +static void forward_host_smc(struct kvm_cpu_context *host_ctxt) +{ + struct arm_smccc_res res; + + arm_smccc_1_1_smc(host_ctxt->regs.regs[0], host_ctxt->regs.regs[1], + host_ctxt->regs.regs[2], host_ctxt->regs.regs[3], + host_ctxt->regs.regs[4], host_ctxt->regs.regs[5], + host_ctxt->regs.regs[6], host_ctxt->regs.regs[7], + &res); + host_ctxt->regs.regs[0] = res.a0; + host_ctxt->regs.regs[1] = res.a1; + host_ctxt->regs.regs[2] = res.a2; + host_ctxt->regs.regs[3] = res.a3; +} + +static void handle_host_smc(struct kvm_cpu_context *host_ctxt) +{ + /* + * Unlike HVC, the return address of an SMC is the instruction's PC. + * Move the return address past the instruction. + */ + skip_host_instruction(); + + /* Forward SMC not handled in EL2 to EL3. */ + forward_host_smc(host_ctxt); +} + void handle_trap(struct kvm_cpu_context *host_ctxt) { u64 esr = read_sysreg_el2(SYS_ESR); @@ -114,6 +146,9 @@ void handle_trap(struct kvm_cpu_context *host_ctxt) case ESR_ELx_EC_HVC64: handle_host_hcall(host_ctxt); break; + case ESR_ELx_EC_SMC64: + handle_host_smc(host_ctxt); + break; default: hyp_panic(); } -- 2.29.2.222.g5d2a92d10f8-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel