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: 129578 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp3357367lja; Mon, 26 Feb 2018 00:24:16 -0800 (PST) X-Google-Smtp-Source: AH8x226D0nmJEFb95bhLnSIRDVpq8DKRIdEZ44Lzc0eJWci0fbWdvlKXgRvaCEb86+q0rwRZZLXe X-Received: by 2002:a17:902:3103:: with SMTP id w3-v6mr9423133plb.99.1519633455876; Mon, 26 Feb 2018 00:24:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519633455; cv=none; d=google.com; s=arc-20160816; b=wgHMC3z0/mfcrD8K4eHgI7eu95oalUj3GO6ebBzVyMiID0J0NMHUL7Ylkh7Rfhswex i0H/kFPxyZ/Z5T6YIuGn1unq74W9Y5nffpVAtdvCBdUtu5RZxNZp+oq78nUwfjGKqoGL t9n+X/yZoWg3zAjZE3zjyvfhZHAnA1h2vf/ATz06quZLZIdlrvP/ZdZmUQDab6SoINSN km7EM3rx5dWwco8jkJFde2OR2OIybT69FT3nKHGHJA0zDTc250G4NevnLR7wxZSd78aC fAyls230hUy+dv/YwGI0k+LFK9srBpuJLtVi0S9AlhS+DHz1M66hKjqhXGdijA0E2aI9 m5GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:arc-authentication-results; bh=XF3NgDLv8+ueVB8Xvd1HYusPmZ7vqfE4Nzmt2Dh5Rd0=; b=UwlyFMwIvSqPw/zrtAixrKDH/Bz662t/RbrD21du2CPLozsJBOG6OG5oJQu+Jduv0+ kKQUWc1NBThhlD6rjFFoftc1yuXhz51zUPANclSdAfwvYJAi172Tpbn25oPWMCaNUdX5 mTrI4S8v/lwjkreYIir6PY9NuMIAaUS6tXFEBtpcB5dDHZN3AjLguQLqq9qSSap+0o0a LzVdCKfgp8t1bpW/c8y7Ilwp6qRtZFS/Az1VV+OeqHI5DWlJi9ddglf2qHK7rBeQ5EKh ozyhoK42zxtDCShA4LDJ1rb7gBJ9aBW+hQF31neUL3nteaP7WA3lGShAkQWlGku/0ZOj u55Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=inZdjk12; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b11si5249076pgr.612.2018.02.26.00.24.15; Mon, 26 Feb 2018 00:24:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=inZdjk12; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751891AbeBZIYN (ORCPT + 10 others); Mon, 26 Feb 2018 03:24:13 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:46862 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751883AbeBZIYK (ORCPT ); Mon, 26 Feb 2018 03:24:10 -0500 Received: by mail-pf0-f196.google.com with SMTP id z10so1882200pfh.13 for ; Mon, 26 Feb 2018 00:24:10 -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=TOfT9lDuOyUKp/xzVAnoaafL/sGXx3+Pvo5gXvj56AMjIJVEzkUnETP3WxhUbjIv5f zcWxCelAEi8VPGc5RJCe3xDavavptHRuzX4JGEmx2lfHDOW0N7A5KoqnVKj78ETYbtPT +DNpKgn1ZZTN9NcOvqxbhvEeKH8G1xnf5xNXpwoOUb392rdakmjow0PgPF6XRgEwcIjN Ggsh9Qsafd3oioR3SPjYe0n73ijBYOsz5wBCzKBTo+9b66molrEG83OFiK02Um0ory8Q H5XaBLmtxz5PnfopFna7aE5hmt4siV33VW67S6fVGKcV0PIWseCndVVIf29X4qjqZJ4d S/7w== X-Gm-Message-State: APf1xPCUAAaRAzffxxxGV/FE8yKa7c9gE6hZrvDrNg8NyciIxkNqyu27 7oa6GXiPjFUyCIbFGAiVgLnaxg== 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?b?UmFkaW0gS3LEjW3DocWZ?= , 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> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org 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(-) -- 2.7.4 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)