From patchwork Mon Feb 26 08:19:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 10241789 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 D68F460208 for ; Mon, 26 Feb 2018 09:43:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C61C729EB9 for ; Mon, 26 Feb 2018 09:43:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BA92529EBF; Mon, 26 Feb 2018 09:43: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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 44FD129EB9 for ; Mon, 26 Feb 2018 09:43:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P/TFm8o5QvFA6NNbjrh4QszUqaLc8WKthS5Y91LgrdA=; b=JmLIAPpQXkeluI 2VheVMc0iax20yHpyBjE6rY3PCXlkLAh+8PLXlV4/tfNNmbSVu79HzBijU6aTNHLeinKpPj4iI/Kc TzKmb2I14slZOZNMnDrgxdP6WgQho6SaXIqpmowN7OamhngVNmOThKlfOCMIQ5Z2/n751pLOMDTnD hIDUMqbHbpb800rjMuN/Ll1ta9Dg7RWSd/7ZamXS3qs53N+8nDCKayCTQkx1XmN8agn/7cZuaXcns bBTQURlvU2whO6K6DPLacJhtjHKCQhC7q+bQoC0KfVD1GlNqbQ8W19UfnpSaX/SzyT7Y6z8528rnV X/DepYG/UxlT0Ry1Ie1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eqFJZ-0000Iy-8E; Mon, 26 Feb 2018 09:43:21 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqFI9-0007sG-BL for linux-arm-kernel@bombadil.infradead.org; Mon, 26 Feb 2018 09:41:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:To:From:Sender:Reply-To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=XF3NgDLv8+ueVB8Xvd1HYusPmZ7vqfE4Nzmt2Dh5Rd0=; b=BwkaRAKiOxta2rI1LKVpioPyW 9Ad7ASy3vYAf6GKsgwDSH4xwDJRyyUWDwa7LXF98B05CBhMo7n9IE2YUjFX877NcgA+eb2qFVUjRv 1iZmlO66DVzK6/IQUFvCa80c45x/yg9Oo2erj9oRypZUJPF9h9A72PRg1mm81Sz4sse4Zu3hO/v8t zhl2F2XEvbF24E8lAHhO2hhHNQI1VM+wZNn79/XTx9Y/MyWTgUh2Xo2qjMoWCUsceau+BPDfbnNRc YJvLWc6X0EC0co7+RNOtMo5DnLu3whgmEZU6E544KrLpdZXVMlw1KHuaj0DyP3gpo/mYav1dwNN7R lonG5z++w==; Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eqE58-0003WL-04 for linux-arm-kernel@lists.infradead.org; Mon, 26 Feb 2018 08:24:22 +0000 Received: by mail-pf0-x244.google.com with SMTP id d26so6221148pfn.5 for ; Mon, 26 Feb 2018 00:24:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=XF3NgDLv8+ueVB8Xvd1HYusPmZ7vqfE4Nzmt2Dh5Rd0=; b=inZdjk12xBzZXv9CV/YXKVmXhYgE7NuNrm930dN6daBFfls25rUUL0kpK+d0vBIDJN NfQr7ifN8BE0zYldx8EMDwliUCC/0MxZoLqxFPCMDnDNNmqj8+/mG/BJyFpDccggRbda Gqpt1e3rZog4/d+e8AomfQFXrrRW/RQv3E15U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=XF3NgDLv8+ueVB8Xvd1HYusPmZ7vqfE4Nzmt2Dh5Rd0=; b=jiNVw2vcRbFXgCD6RY5sCrm+mhLrHg4lIhy5nHi6Xwg3Pp7O7EL503mgCeiWyAM7Jp LMPnAFTWpUNjuLB59ivHgb0hYadWS9x8vlr7+NYHlmT4c9ykgtknEmtOHeLxOjP/jWWp V4rHaaAhKGpEyJNxK3uofozdebMW7857liwLjSkglNE2JMPG4PANKUmSFtAtsHlBWhAx VApRpr2u1q7lOewf4PYxWbHhnRyeHL7OYYt7OfRZT/JwVWXLW4ZwHS0TQTJlN1jwWsPa 8JkfmTGA2xyPECU1PIFweJXtY6mU9BFq63pb0sEL2ITnjUKsaokLD3Y7GLGyt3TprcW5 Ww/Q== X-Gm-Message-State: APf1xPBsC5L7+5g/e/6kuSaUevFTf2S6CG8L/FMJwWCvK8FrgTaiGzOr lbUyR4Vu2gq3Ui2bcSdtUiv3TQ== X-Google-Smtp-Source: AH8x226ujlZKMrSO9CIJVQeCckn19naB35cBUeyASsjWwdut53x8vdAz+ZqwtXq4+xejOsvYw42qwg== X-Received: by 10.98.152.205 with SMTP id d74mr9871501pfk.115.1519633449585; Mon, 26 Feb 2018 00:24:09 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id o86sm1422706pfi.87.2018.02.26.00.24.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Feb 2018 00:24:09 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, Christoffer Dall , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Russell King , linux-arm-kernel@lists.infradead.org (moderated list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvmarm@lists.cs.columbia.edu (open list:KERNEL VIRTUAL MACHINE (KVM) FOR ARM), kvm@vger.kernel.org (open list:KERNEL VIRTUAL MACHINE (KVM)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH 25/52] arm64: KVM: Use per-CPU vector when BP hardening is enabled Date: Mon, 26 Feb 2018 16:19:59 +0800 Message-Id: <1519633227-29832-26-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> References: <1519633227-29832-1-git-send-email-alex.shi@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180226_032422_071752_50936793 X-CRM114-Status: GOOD ( 17.35 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc Zyngier commit 6840bdd73d07 upstream Now that we have per-CPU vectors, let's plug then in the KVM/arm64 code. Signed-off-by: Marc Zyngier Signed-off-by: Will Deacon Signed-off-by: Alex Shi Conflicts: mv changes from virt/kvm/arm/arm.c to arch/arm/kvm/arm.c --- arch/arm/include/asm/kvm_mmu.h | 10 ++++++++++ arch/arm/kvm/arm.c | 8 +++++++- arch/arm64/include/asm/kvm_mmu.h | 38 ++++++++++++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/switch.c | 2 +- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index a58bbaa..d10e362 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -223,6 +223,16 @@ static inline unsigned int kvm_get_vmid_bits(void) return 8; } +static inline void *kvm_get_hyp_vector(void) +{ + return kvm_ksym_ref(__kvm_hyp_vector); +} + +static inline int kvm_map_vectors(void) +{ + return 0; +} + #endif /* !__ASSEMBLY__ */ #endif /* __ARM_KVM_MMU_H__ */ diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index c38bfbe..4e4ae07 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -1088,7 +1088,7 @@ static void cpu_init_hyp_mode(void *dummy) pgd_ptr = kvm_mmu_get_httbr(); stack_page = __this_cpu_read(kvm_arm_hyp_stack_page); hyp_stack_ptr = stack_page + PAGE_SIZE; - vector_ptr = (unsigned long)kvm_ksym_ref(__kvm_hyp_vector); + vector_ptr = (unsigned long)kvm_get_hyp_vector(); __cpu_init_hyp_mode(pgd_ptr, hyp_stack_ptr, vector_ptr); __cpu_init_stage2(); @@ -1345,6 +1345,12 @@ static int init_hyp_mode(void) goto out_err; } + err = kvm_map_vectors(); + if (err) { + kvm_err("Cannot map vectors\n"); + goto out_err; + } + /* * Map the Hyp stack pages */ diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 6d22017..80bf337 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -313,5 +313,43 @@ static inline unsigned int kvm_get_vmid_bits(void) return (cpuid_feature_extract_unsigned_field(reg, ID_AA64MMFR1_VMIDBITS_SHIFT) == 2) ? 16 : 8; } +#ifdef CONFIG_HARDEN_BRANCH_PREDICTOR +#include + +static inline void *kvm_get_hyp_vector(void) +{ + struct bp_hardening_data *data = arm64_get_bp_hardening_data(); + void *vect = kvm_ksym_ref(__kvm_hyp_vector); + + if (data->fn) { + vect = __bp_harden_hyp_vecs_start + + data->hyp_vectors_slot * SZ_2K; + + if (!cpus_have_cap(ARM64_HAS_VIRT_HOST_EXTN)) + vect = lm_alias(vect); + } + + return vect; +} + +static inline int kvm_map_vectors(void) +{ + return create_hyp_mappings(kvm_ksym_ref(__bp_harden_hyp_vecs_start), + kvm_ksym_ref(__bp_harden_hyp_vecs_end), + PAGE_HYP_EXEC); +} + +#else +static inline void *kvm_get_hyp_vector(void) +{ + return kvm_ksym_ref(__kvm_hyp_vector); +} + +static inline int kvm_map_vectors(void) +{ + return 0; +} +#endif + #endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */ diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index 0c848c1..cf6d962 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -50,7 +50,7 @@ static void __hyp_text __activate_traps_vhe(void) val &= ~CPACR_EL1_FPEN; write_sysreg(val, cpacr_el1); - write_sysreg(__kvm_hyp_vector, vbar_el1); + write_sysreg(kvm_get_hyp_vector(), vbar_el1); } static void __hyp_text __activate_traps_nvhe(void)