From patchwork Fri Jan 18 17:56:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 156039 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3535949jaa; Fri, 18 Jan 2019 09:56:38 -0800 (PST) X-Google-Smtp-Source: ALg8bN7hIzG7J3vF9l4C/53aczjWKpVCv636mZLdYrbHW5xRme8zWZLCobZ6hT9MV+nZVLvWQWq9 X-Received: by 2002:a63:1321:: with SMTP id i33mr18960780pgl.380.1547834198103; Fri, 18 Jan 2019 09:56:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547834198; cv=none; d=google.com; s=arc-20160816; b=vwkHJZLEqCns8ZkaY3bjklOYtNBivVN4ifjwrcYNbDSQ+x1rc5iOMt0BJRU59B+yKR D08oyfvhhvArblTTeHOvbq1zj0nc1eC0LJtjKDE6fVwlE/WU5n2Kn175zo7ApwfNzbbd BtsVcSOAnICPPiHBDyMH0pd9+vEwFODK7mH5zSPhqnCx7XgJ10IFGNlhWCOKl6tg4tRW T1euoNxqN5CexXNcH/ejDdwNfbab+aOpHFJSHby4wGf5dv4X2ROpPAQ4qf8ME++963TI BtQiVB75cRIBAJ6ynhWn/9iA4WKKWlhFgX4yBIB3mKSx9GFmkfyLpdlF1aSllZYZh8wY G+sQ== 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; bh=VjTwtV8m+T6Kl3GHx9ZIQuZkjGM+mO2Jtm2KdhHMcXA=; b=ZHvJYbX6wJ/UmCHuH+IyEGkWZLnMYfrL4Ff4l9Nt9LqRhSjanoLZm3R/YOO+flEyVM QEgDdS+klJF1u5rESi2kVBHHD/nPXp7c/+inlJHP9ETXOmOxCjALs2jJ68EgBQyPjYsH H/tenek8eutvPd0oVfxDXioSHIk7KCnMAf78+Wjwomv03ONx68zDIEnRtoNcMOkGjS2y bjKizOtWlgqf1SMsRWwPp6Ifniz47C1PQZThB6hqK/gKjuILU0D3rpUCAcEgibo/XwW4 Ub8JUgWiRBFXeXw7pt4bcAas3eXBfst5MycnarigpLopENGyJ3n977llGpT10olGKMmB SOfg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si5084692pgy.408.2019.01.18.09.56.37; Fri, 18 Jan 2019 09:56:38 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728624AbfARR4h (ORCPT + 15 others); Fri, 18 Jan 2019 12:56:37 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:35884 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728619AbfARR4h (ORCPT ); Fri, 18 Jan 2019 12:56:37 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0455A80D; Fri, 18 Jan 2019 09:56:37 -0800 (PST) Received: from moonbear.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C5DDD3F7BE; Fri, 18 Jan 2019 09:56:35 -0800 (PST) From: Kristina Martsenko To: stable@vger.kernel.org Cc: Catalin Marinas , Christoffer Dall , Marc Zyngier , Mark Rutland , Will Deacon Subject: [PATCH 4.14 1/2] arm64/kvm: consistently handle host HCR_EL2 flags Date: Fri, 18 Jan 2019 17:56:32 +0000 Message-Id: <20190118175633.6464-1-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <7acde9fd-242b-0850-81b3-6dbd4cc75565@arm.com> References: <7acde9fd-242b-0850-81b3-6dbd4cc75565@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Rutland [ Backport of upstream commit 4eaed6aa2c628101246bcabc91b203bfac1193f8 ] In KVM we define the configuration of HCR_EL2 for a VHE HOST in HCR_HOST_VHE_FLAGS, but we don't have a similar definition for the non-VHE host flags, and open-code HCR_RW. Further, in head.S we open-code the flags for VHE and non-VHE configurations. In future, we're going to want to configure more flags for the host, so lets add a HCR_HOST_NVHE_FLAGS defintion, and consistently use both HCR_HOST_VHE_FLAGS and HCR_HOST_NVHE_FLAGS in the kvm code and head.S. We now use mov_q to generate the HCR_EL2 value, as we use when configuring other registers in head.S. Reviewed-by: Marc Zyngier Reviewed-by: Richard Henderson Signed-off-by: Mark Rutland Reviewed-by: Christoffer Dall Cc: Catalin Marinas Cc: Marc Zyngier Cc: Will Deacon Cc: kvmarm@lists.cs.columbia.edu Signed-off-by: Will Deacon [kristina: backport to 4.14.y: adjust context] Signed-off-by: Kristina Martsenko --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/kernel/head.S | 5 ++--- arch/arm64/kvm/hyp/switch.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 73cc4309fe01..9b25a1e2d583 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -82,6 +82,7 @@ HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW) #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) #define HCR_INT_OVERRIDE (HCR_FMO | HCR_IMO) +#define HCR_HOST_NVHE_FLAGS (HCR_RW) #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) /* TCR_EL2 Registers bits */ diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index 261f3f88364c..ec393275ba04 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -414,10 +414,9 @@ CPU_LE( bic x0, x0, #(1 << 25) ) // Clear the EE bit for EL2 #endif /* Hyp configuration. */ - mov x0, #HCR_RW // 64-bit EL1 + mov_q x0, HCR_HOST_NVHE_FLAGS cbz x2, set_hcr - orr x0, x0, #HCR_TGE // Enable Host Extensions - orr x0, x0, #HCR_E2H + mov_q x0, HCR_HOST_VHE_FLAGS set_hcr: msr hcr_el2, x0 isb diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c index b2f1992c6234..44845996b554 100644 --- a/arch/arm64/kvm/hyp/switch.c +++ b/arch/arm64/kvm/hyp/switch.c @@ -127,7 +127,7 @@ static void __hyp_text __deactivate_traps_nvhe(void) mdcr_el2 |= MDCR_EL2_E2PB_MASK << MDCR_EL2_E2PB_SHIFT; write_sysreg(mdcr_el2, mdcr_el2); - write_sysreg(HCR_RW, hcr_el2); + write_sysreg(HCR_HOST_NVHE_FLAGS, hcr_el2); write_sysreg(CPTR_EL2_DEFAULT, cptr_el2); } From patchwork Fri Jan 18 17:56:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kristina Martsenko X-Patchwork-Id: 156040 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp3535997jaa; Fri, 18 Jan 2019 09:56:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN6+qPOnDbw601Gwd6OWlxO6jjgMFebgGMF7alVaaoLcldHnFgfo4427yRwLvMHPaLWR8EgI X-Received: by 2002:a17:902:8f97:: with SMTP id z23mr20322769plo.283.1547834201356; Fri, 18 Jan 2019 09:56:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547834201; cv=none; d=google.com; s=arc-20160816; b=cCBWuhZaIHTCGMKRabmTKZVrrRsSF70MbJHQrWFVwopG8+lMuPTGhD98mi74dJxfaj A5XXwgonpxED51yGrM3z7CGjFZHa2Y+gljP76WuZaAaTnCKlTk+jnYMyqz7yF7fXdvvj 84LhJpGBbEO3pYEepVk4eCXhhLOxot40KEkeXZ6xH1gHCGQHc/dyUC9GXb6cIKV1hseW H6Zqz8AsV1dw91GPPkWdQlIkGFGv300UYBWDXEIxH0sbG/VxfAIeQjh6KiDbDcjbHBwt 1PxC1N+Qv5JRyFUkgdq+5Is1AXYqG8XF/5w1ucam4VgbxkZ4Tysr8z6aXsTntAIdecYL pg1g== 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; bh=LkdBlHqIVBCsOx0mptPKjX1wGy+aSUt5xo8PcYPhjJ0=; b=k3ZbmYa10tx5Bu9gLucMJgB/VTOwGGsOTFObHWow6O9X9C8hgLvdFVlDPmf3JE0QNk 6wtXKx5OhrvbYuPRbVBtDFV5evdJ/nEuBKXvQ6X+2KhHEUqk34tKSFxz5Sh3KCJDrd4e CpBG+T1dPmeQTrm+N97zpi2H3S/Xq4/tYDUPBEVGCXIXLByYUQfnKFAqvIaPlRuXNA9+ 9YHe2Hk1d77mgMH+QzD3HKIVMuD6ZafyQfxSc0O6srBOg7graOPxuIEotaqL8LvatrLf gqazTldchk71yL7J9e73tCmmbPZl5eez0MtD7MQ6hVjctkP/4+Wp5Xmh4jF+Vo/HJ4kK D6mw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 11si5084692pgy.408.2019.01.18.09.56.41; Fri, 18 Jan 2019 09:56:41 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728628AbfARR4k (ORCPT + 15 others); Fri, 18 Jan 2019 12:56:40 -0500 Received: from foss.arm.com ([217.140.101.70]:35888 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728619AbfARR4k (ORCPT ); Fri, 18 Jan 2019 12:56:40 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 37E0080D; Fri, 18 Jan 2019 09:56:40 -0800 (PST) Received: from moonbear.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0560A3F7BE; Fri, 18 Jan 2019 09:56:38 -0800 (PST) From: Kristina Martsenko To: stable@vger.kernel.org Cc: Catalin Marinas , Christoffer Dall , Marc Zyngier , Mark Rutland , Will Deacon Subject: [PATCH 4.14 2/2] arm64: Don't trap host pointer auth use to EL2 Date: Fri, 18 Jan 2019 17:56:33 +0000 Message-Id: <20190118175633.6464-2-kristina.martsenko@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190118175633.6464-1-kristina.martsenko@arm.com> References: <7acde9fd-242b-0850-81b3-6dbd4cc75565@arm.com> <20190118175633.6464-1-kristina.martsenko@arm.com> Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mark Rutland [ Backport of upstream commit b3669b1e1c09890d61109a1a8ece2c5b66804714 ] To allow EL0 (and/or EL1) to use pointer authentication functionality, we must ensure that pointer authentication instructions and accesses to pointer authentication keys are not trapped to EL2. This patch ensures that HCR_EL2 is configured appropriately when the kernel is booted at EL2. For non-VHE kernels we set HCR_EL2.{API,APK}, ensuring that EL1 can access keys and permit EL0 use of instructions. For VHE kernels host EL0 (TGE && E2H) is unaffected by these settings, and it doesn't matter how we configure HCR_EL2.{API,APK}, so we don't bother setting them. This does not enable support for KVM guests, since KVM manages HCR_EL2 itself when running VMs. Reviewed-by: Richard Henderson Signed-off-by: Mark Rutland Acked-by: Christoffer Dall Cc: Catalin Marinas Cc: Marc Zyngier Cc: Will Deacon Cc: kvmarm@lists.cs.columbia.edu Signed-off-by: Will Deacon [kristina: backport to 4.14.y: adjust context] Signed-off-by: Kristina Martsenko --- arch/arm64/include/asm/kvm_arm.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) -- 2.11.0 diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 9b25a1e2d583..1d6d980f80ac 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -23,6 +23,8 @@ #include /* Hyp Configuration Register (HCR) bits */ +#define HCR_API (UL(1) << 41) +#define HCR_APK (UL(1) << 40) #define HCR_E2H (UL(1) << 34) #define HCR_ID (UL(1) << 33) #define HCR_CD (UL(1) << 32) @@ -82,7 +84,7 @@ HCR_AMO | HCR_SWIO | HCR_TIDCP | HCR_RW) #define HCR_VIRT_EXCP_MASK (HCR_VSE | HCR_VI | HCR_VF) #define HCR_INT_OVERRIDE (HCR_FMO | HCR_IMO) -#define HCR_HOST_NVHE_FLAGS (HCR_RW) +#define HCR_HOST_NVHE_FLAGS (HCR_RW | HCR_API | HCR_APK) #define HCR_HOST_VHE_FLAGS (HCR_RW | HCR_TGE | HCR_E2H) /* TCR_EL2 Registers bits */