Received: by 10.223.185.116 with SMTP id b49csp2877330wrg; Mon, 5 Mar 2018 10:05:44 -0800 (PST) X-Google-Smtp-Source: AG47ELvADmcCCjVUJ26ElOYAXScaBqCWbp1DYl2StX9zFbmvqPTHO0uvM6oRGcIFncWeMHFO6tEo X-Received: by 10.98.70.89 with SMTP id t86mr16277806pfa.215.1520273144201; Mon, 05 Mar 2018 10:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520273144; cv=none; d=google.com; s=arc-20160816; b=Ah+XaigiwAU7tLV5f/46G2DWzdLTEn5fkR3yppFsBfmMs1NnZmf4G2F6hpqS+8THl2 LFXzYMOWlRw+LWcgBL93idqfBKJvvxqbHM6bjyfJxsVO6UFKjjgXxObpud8vlTcJEsoy V2v13wptpjlSzLTDrttYQaSOKHhGS/rO8Dnpv3QrdN0jS7sVfnQqD0Qyleak9pig0gHY FYu6ijYa2nH2D+5FKbd1wwS6CZqcYULZ89oDUqR1vHXpnRd1fux4yUO6sDG+gth8ZiSE R8s5SpsXOw9V6xJmNtZXHfh4m1uxAyFXTVkbGMCDJ5CRaCQ5n6KuANMT3aILWK5LS/vC 9wug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:reply-to:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=MVst1c4D4y4IvboU5XWtdLWmVFDTZ+0MpozLUVIDyw8=; b=Nnz4j8Kn62tNaRKfNqKeJVs6K6AiqsKsFVbXjqhd6aAzd51ykjFkDY9zlv8eVWRWW0 ZzdMkkVEPZ4D4p1Tn/yuoC4AKfPOFrbIvbD2lZgxlnM9vH/Wum8S/7lSUcyFpDdxda5d Xo6N4haLWvnmFisygif39ByIfQ37vm0OnfhGRNQ46ypJiiU/ArolXpT8sB3+4AjfpWu3 tRj4afnCvLx0rT4tZx15AU7w95KseB+0iVzAAxremqsy6Ad7L5tsgYzMn7ukAE2yTmdf yg6Z5yXdNgiJCrRiVT8ptwFJLI4Zf2xhBEJUCVSQZr94uZxoR12jMUlDNZj8gqe0JTly KhvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=hzTE5Zg8; dkim=pass header.i=@codeaurora.org header.s=default header.b=VHuC5Jyu; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q2si8614420pgc.727.2018.03.05.10.05.29; Mon, 05 Mar 2018 10:05:44 -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=@codeaurora.org header.s=default header.b=hzTE5Zg8; dkim=pass header.i=@codeaurora.org header.s=default header.b=VHuC5Jyu; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752854AbeCESDm (ORCPT + 99 others); Mon, 5 Mar 2018 13:03:42 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:49154 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751935AbeCESDl (ORCPT ); Mon, 5 Mar 2018 13:03:41 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id A9BBD6043F; Mon, 5 Mar 2018 18:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520273020; bh=6oGE4oGWbdRVAQluMIjQfvpbq+70n7fSy0Dy4OJ7ajs=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=hzTE5Zg8Cr8Li4BMBiMM4O8jckl7iQLhpa6H0k6B5qmiriPivdGmBU04/EH6QWyi4 hIY/AJEcthSG+FJUeaV1UOGwEswWm9llrFaerOlPQJqxTPghHrHrwIeIteERyvFni7 mi+YMfZ/OdxiAXMzdjwR0+Hk0wibF6jhgv7OOBtk= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.0.2.15] (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: shankerd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id C5C0D601EA; Mon, 5 Mar 2018 18:03:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1520273015; bh=6oGE4oGWbdRVAQluMIjQfvpbq+70n7fSy0Dy4OJ7ajs=; h=Reply-To:Subject:To:Cc:References:From:Date:In-Reply-To:From; b=VHuC5JyuMfHhiEOKdzgp/uE050pva3fFRCYCDuUhsDj0VSBhk4I5F2Qq/Uwv2tQRy ID6xPYEsWbY84JJbNLZbREkfFtLgbu4SBGE8XsPddE4a+c39LQE4FVQZ+DVJkdqNgP n97TIx9HSxAMyKCMDIzin4GKjAz8bY2I0nMTlgTU= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org C5C0D601EA Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=shankerd@codeaurora.org Reply-To: shankerd@codeaurora.org Subject: Re: [PATCH] arm64: KVM: Use SMCCC_ARCH_WORKAROUND_1 for Falkor BP hardening To: Will Deacon Cc: Thomas Speier , Vikram Sethi , Sean Campbell , Marc Zyngier , Catalin Marinas , linux-kernel , linux-arm-kernel , kvmarm , Christoffer Dall References: <1520027418-10646-1-git-send-email-shankerd@codeaurora.org> <20180305155614.GG6618@arm.com> <05c25982-4939-593f-ad30-bf496e879885@codeaurora.org> <20180305171529.GA12869@arm.com> From: Shanker Donthineni Message-ID: <770bb422-7a53-06b9-a136-4e38a0a4bed2@codeaurora.org> Date: Mon, 5 Mar 2018 12:03:33 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: <20180305171529.GA12869@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Will, On 03/05/2018 11:15 AM, Will Deacon wrote: > On Mon, Mar 05, 2018 at 10:57:58AM -0600, Shanker Donthineni wrote: >> Hi Will, >> >> On 03/05/2018 09:56 AM, Will Deacon wrote: >>> Hi Shanker, >>> >>> On Fri, Mar 02, 2018 at 03:50:18PM -0600, Shanker Donthineni wrote: >>>> The function SMCCC_ARCH_WORKAROUND_1 was introduced as part of SMC >>>> V1.1 Calling Convention to mitigate CVE-2017-5715. This patch uses >>>> the standard call SMCCC_ARCH_WORKAROUND_1 for Falkor chips instead >>>> of Silicon provider service ID 0xC2001700. >>>> >>>> Signed-off-by: Shanker Donthineni >>>> --- >>>> arch/arm64/include/asm/cpucaps.h | 2 +- >>>> arch/arm64/include/asm/kvm_asm.h | 2 -- >>>> arch/arm64/kernel/bpi.S | 8 ------ >>>> arch/arm64/kernel/cpu_errata.c | 55 ++++++++++++++-------------------------- >>>> arch/arm64/kvm/hyp/entry.S | 12 --------- >>>> arch/arm64/kvm/hyp/switch.c | 10 -------- >>>> 6 files changed, 20 insertions(+), 69 deletions(-) >>> >>> I'm happy to take this via arm64 if I get an ack from Marc/Christoffer. >>> >>>> diff --git a/arch/arm64/include/asm/cpucaps.h b/arch/arm64/include/asm/cpucaps.h >>>> index bb26382..6ecc249 100644 >>>> --- a/arch/arm64/include/asm/cpucaps.h >>>> +++ b/arch/arm64/include/asm/cpucaps.h >>>> @@ -43,7 +43,7 @@ >>>> #define ARM64_SVE 22 >>>> #define ARM64_UNMAP_KERNEL_AT_EL0 23 >>>> #define ARM64_HARDEN_BRANCH_PREDICTOR 24 >>>> -#define ARM64_HARDEN_BP_POST_GUEST_EXIT 25 >>>> +/* #define ARM64_UNALLOCATED_ENTRY 25 */ >>>> #define ARM64_HAS_RAS_EXTN 26 >>>> >>>> #define ARM64_NCAPS 27 >>> >>> These aren't ABI, so I think you can just drop >>> ARM64_HARDEN_BP_POST_GUEST_EXIT and repack the others accordingly. >>> >> Sure, I'll remove it completely in v2 patch. >> >>>> diff --git a/arch/arm64/include/asm/kvm_asm.h b/arch/arm64/include/asm/kvm_asm.h >>>> index 24961b7..ab4d0a9 100644 >>>> --- a/arch/arm64/include/asm/kvm_asm.h >>>> +++ b/arch/arm64/include/asm/kvm_asm.h >>>> @@ -68,8 +68,6 @@ >>>> >>>> extern u32 __init_stage2_translation(void); >>>> >>>> -extern void __qcom_hyp_sanitize_btac_predictors(void); >>>> - >>>> #endif >>>> >>>> #endif /* __ARM_KVM_ASM_H__ */ >>>> diff --git a/arch/arm64/kernel/bpi.S b/arch/arm64/kernel/bpi.S >>>> index e5de335..dc4eb15 100644 >>>> --- a/arch/arm64/kernel/bpi.S >>>> +++ b/arch/arm64/kernel/bpi.S >>>> @@ -55,14 +55,6 @@ ENTRY(__bp_harden_hyp_vecs_start) >>>> .endr >>>> ENTRY(__bp_harden_hyp_vecs_end) >>>> >>>> -ENTRY(__qcom_hyp_sanitize_link_stack_start) >>>> - stp x29, x30, [sp, #-16]! >>>> - .rept 16 >>>> - bl . + 4 >>>> - .endr >>>> - ldp x29, x30, [sp], #16 >>>> -ENTRY(__qcom_hyp_sanitize_link_stack_end) >>>> - >>>> .macro smccc_workaround_1 inst >>>> sub sp, sp, #(8 * 4) >>>> stp x2, x3, [sp, #(8 * 0)] >>>> diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c >>>> index 52f15cd..d779ffd4 100644 >>>> --- a/arch/arm64/kernel/cpu_errata.c >>>> +++ b/arch/arm64/kernel/cpu_errata.c >>>> @@ -67,8 +67,6 @@ static int cpu_enable_trap_ctr_access(void *__unused) >>>> DEFINE_PER_CPU_READ_MOSTLY(struct bp_hardening_data, bp_hardening_data); >>>> >>>> #ifdef CONFIG_KVM >>>> -extern char __qcom_hyp_sanitize_link_stack_start[]; >>>> -extern char __qcom_hyp_sanitize_link_stack_end[]; >>>> extern char __smccc_workaround_1_smc_start[]; >>>> extern char __smccc_workaround_1_smc_end[]; >>>> extern char __smccc_workaround_1_hvc_start[]; >>>> @@ -115,8 +113,6 @@ static void __install_bp_hardening_cb(bp_hardening_cb_t fn, >>>> spin_unlock(&bp_lock); >>>> } >>>> #else >>>> -#define __qcom_hyp_sanitize_link_stack_start NULL >>>> -#define __qcom_hyp_sanitize_link_stack_end NULL >>>> #define __smccc_workaround_1_smc_start NULL >>>> #define __smccc_workaround_1_smc_end NULL >>>> #define __smccc_workaround_1_hvc_start NULL >>>> @@ -161,12 +157,25 @@ static void call_hvc_arch_workaround_1(void) >>>> arm_smccc_1_1_hvc(ARM_SMCCC_ARCH_WORKAROUND_1, NULL); >>>> } >>>> >>>> +static void qcom_link_stack_sanitization(void) >>>> +{ >>>> + u64 tmp; >>>> + >>>> + asm volatile("mov %0, x30 \n" >>>> + ".rept 16 \n" >>>> + "bl . + 4 \n" >>>> + ".endr \n" >>>> + "mov x30, %0 \n" >>>> + : "=&r" (tmp)); >>>> +} >>>> + >>>> static int enable_smccc_arch_workaround_1(void *data) >>>> { >>>> const struct arm64_cpu_capabilities *entry = data; >>>> bp_hardening_cb_t cb; >>>> void *smccc_start, *smccc_end; >>>> struct arm_smccc_res res; >>>> + u32 midr = read_cpuid_id(); >>>> >>>> if (!entry->matches(entry, SCOPE_LOCAL_CPU)) >>>> return 0; >>>> @@ -199,33 +208,15 @@ static int enable_smccc_arch_workaround_1(void *data) >>>> return 0; >>>> } >>>> >>>> + if (((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR) || >>>> + ((midr & MIDR_CPU_MODEL_MASK) == MIDR_QCOM_FALKOR_V1)) >>>> + cb = qcom_link_stack_sanitization; >>> >>> Is this just a performance thing? Do you actually see an advantage over >>> always making the firmware call? We've seen minimal impact in our testing. >>> >> >> Yes, we've couple of advantages using the standard SMCCC_ARCH_WOKAROUND_1 framework. >> - Improves the code readability. >> - Avoid the unnecessary MIDR checks on each vCPU exit. >> - Validates ID_AA64PFR0_CVS2 feature for Falkor chips. >> - Avoids the 2nd link stack sanitization workaround in firmware. > > What I mean is, can we drop qcom_link_stack_sanitization altogether and > use the SMCCC interface for everything? > No, We would like to keep it qcom_link_stack_sanitization for host kernel since it takes a few CPU cycles instead of heavyweight SMCCC call. I posted v2 patch https://patchwork.kernel.org/patch/10259357/ to address cpucaps.h cleanup review comments. > Will > -- Shanker Donthineni Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc. Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.