From patchwork Thu Mar 1 12:54:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Shi X-Patchwork-Id: 130224 Delivered-To: patch@linaro.org Received: by 10.80.172.228 with SMTP id x91csp2771073edc; Thu, 1 Mar 2018 05:04:35 -0800 (PST) X-Google-Smtp-Source: AG47ELuYK1dyQkaFtE1DKKy/W3q8KmxaZ2nzJwZmJqnV040wEqaEff2CE/obIdwvs5+BrHyRqgxc X-Received: by 10.99.96.200 with SMTP id u191mr1519271pgb.252.1519909475062; Thu, 01 Mar 2018 05:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519909475; cv=none; d=google.com; s=arc-20160816; b=xgbmzkbtUbjkngg7czylbG676TEFWw60JZLMDPA91rxxdz7azQQl/qBfvs+OGyB1KQ OR2g+x5eF9J18JRryHCgmUqQCTVRJCSSlrtAhq6qnp5M/yALTLG30JglT8sd+kGyAjid S9T2dg2MOzZ4WV49ec+rqNng2Qm3JtytD672Fa2C8KgvoiyWIRKKnoZZNQYSeYyTYY44 mp4grbU/FVi4aXmVG+jZQT9f7PmlcKZwiDylOhQAfnwPqO9/doFAxXhsBs01Kdy33VLY 0Coq3GdqotwJ9xmMi0F8tRPh16PRLfq4b0l1pDJHRCrm35cRV2UfXZr1HAJqx8O8GV8L XgIQ== 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:cc:to:from:dkim-signature:arc-authentication-results; bh=NZ2qtdpybzZDjgWGLMAPxPIrjxBvuuwvSlz1/mXg4z0=; b=eFiduEAYuiYbWgNkVejf2M3PhXyCb1Nfiqr2Oh5ZJCbB/czzpvfIbJKumLSnEA35oz 8PH2cMbfUdWYB1GpPCMivfXfVtNrx2SkYR9brhys4c+2IvTH4kMqDmr2pfuKWi+HB7TY JTrCfbejSn/ioiyQ7pL8FoDCc5nEZ0BYQSH2TH6HELX2wNqPtAWdg/NY+etPPGNB2QCS hxSnQgRPa+7nqgEEfV8DevBQtp9MW+uOvhwFjbRgUHvTvleQ7jKFYOVGJsj7HpLv483b yHjfqggxXi/LJQ+TDUG6FcgE1kOOAI2cD3wlcTzQbGRbwDpDszAk0OobPmeggyI8dn2H Fr0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=HRBfzix6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 e13si2441046pgt.569.2018.03.01.05.04.34; Thu, 01 Mar 2018 05:04:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=HRBfzix6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1031114AbeCANEa (ORCPT + 28 others); Thu, 1 Mar 2018 08:04:30 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:36970 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030654AbeCAM6x (ORCPT ); Thu, 1 Mar 2018 07:58:53 -0500 Received: by mail-pg0-f66.google.com with SMTP id y26so2276093pgv.4 for ; Thu, 01 Mar 2018 04:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NZ2qtdpybzZDjgWGLMAPxPIrjxBvuuwvSlz1/mXg4z0=; b=HRBfzix657WyZtW2j/hHUvw3T0vT+NmV9/CkteQKq78WzaWl7nAJTkr9ejDlnpVxLm lczwa0QTAidlAfX3q1YI/0SonGtjMuTeaYobaU2aGsOPGyk9vsbjggfgpY93gVotf6Nx ibKhfBQWu1vNK2rZkSz6m4XEIZXrpgSkk6Eqk= 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; bh=NZ2qtdpybzZDjgWGLMAPxPIrjxBvuuwvSlz1/mXg4z0=; b=TUdrdVIya4xFQxy8sMHrJzhBlQKQMJJWDGEb4WS4mP5KpAfxhign+k1O0dwPdwQaz3 IavB/xcF7+v88d9kLHRbSsZEucf7C5cLP3hON0a1Z0u3GDy/lIpfRacihmDmaPQOk/zb Kd0+0e8FRM2nREbdzy6eASDyJZ4gLZrpILZKSwkOTu+JsgYvZMZMuul/zEuTHMFsVgOc q+OGaZvqJ2N2z/4FCU1csozlhcs29AnRj1F241KDs7ArjoNQqqUjkb7ysffQvAhXioyM Yk82GqRX+mFEUdyHH9usu8SzyvKKQMDs89Km4YIxk2aeXeVjTOEU9LUFvYviexoVCZEZ 0y8w== X-Gm-Message-State: APf1xPDCvc9aYI4oqGyead/KQNdrJIsIMkoEo10L1dojx40dCnYLR8n3 OLbG4qTCcv9WxjEKSyswGJJmJw== X-Received: by 10.99.53.193 with SMTP id c184mr1469471pga.180.1519909133280; Thu, 01 Mar 2018 04:58:53 -0800 (PST) Received: from localhost.localdomain (176.122.172.82.16clouds.com. [176.122.172.82]) by smtp.gmail.com with ESMTPSA id x4sm2289655pfb.46.2018.03.01.04.58.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Mar 2018 04:58:52 -0800 (PST) From: Alex Shi To: Marc Zyngier , Will Deacon , Ard Biesheuvel , Catalin Marinas , stable@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Alex Shi Subject: [PATCH 25/45] arm64: KVM: Use per-CPU vector when BP hardening is enabled Date: Thu, 1 Mar 2018 20:54:02 +0800 Message-Id: <1519908862-11425-26-git-send-email-alex.shi@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> References: <1519908862-11425-1-git-send-email-alex.shi@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 --- 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)