Received: by 10.223.185.116 with SMTP id b49csp2166981wrg; Thu, 15 Feb 2018 07:32:06 -0800 (PST) X-Google-Smtp-Source: AH8x224cwpX5X6KHhPv7ARyP+ixoIynI0O+pUmRkBimAZBjA9RpmlQa0mNddl+YmVQp1sdi9EEY4 X-Received: by 10.99.123.12 with SMTP id w12mr2435399pgc.405.1518708726576; Thu, 15 Feb 2018 07:32:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518708726; cv=none; d=google.com; s=arc-20160816; b=BaU1LGyLWM04sqXXb21EewA+/fxuIfnL1Ncu6ilXyWIFHzkCHuxhwa6v4dwI0SLC6B /rYsT5Zm47PFCRsRMVTT5rDXrra8W4DPTuj02ceo3u/UzW4DjNv3BZyfZZQ5hVlt5YCD tqLFQ1NutchZ4zCLeF9b/Cp+MWjpOQdYo6llTQi6qsfXL5xUeI85rky9ixKsEg9/sueS cWq7ZGlbmwJzhGdrzWSylMoOFVJS5bDnv49pHPYJm3pHZ7VgfgABDRaZcED9qGZfjgVy XliitK7TncsBaJqcU3Dwssd0PEKM6HCe7fb1m3iNaSwwqFqeewyUZmItQvlFiG4/Fx71 nFpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=HQAT7k1QPjCJd0R0ycH6sxsFLrPeB1iE5p/y2hyjjBE=; b=ES+vPHXtSGJs0YQ9AoBnRPxOUhDlNPv4wGPz0CXq1gJWJpedq99f3xQ/DxLhI1+F3i t5QDhSP+NPonI59BIgoyRdyv1Sh4XhmXXUHgUnl6pE2zkFMOIplCtawQ1Zfp/nOtw3EH TsV6dNyOugqa9d4AWhymbCe8yRQXjtsf/kaNOADW6noynMypV263pbCRLaBAPyqXmCBl TgfT/Hw90nz5JI8+hEv5VO/m1QkHPy8KTIvlEz86BELoX8OtekSdOVoryyenhNDPAeG0 IVNwPzOhOvxqBxTd+ngqcSeLjT96a9q2TTDU0iOh6Mzcwxwjh+VKA/qOKecEnIawupkL 8yTA== ARC-Authentication-Results: i=1; mx.google.com; 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 d81si3471093pfd.139.2018.02.15.07.31.51; Thu, 15 Feb 2018 07:32:06 -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; 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 S1164253AbeBOPai (ORCPT + 99 others); Thu, 15 Feb 2018 10:30:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:55122 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164223AbeBOPae (ORCPT ); Thu, 15 Feb 2018 10:30:34 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0EAA41111; Thu, 15 Feb 2018 15:30:33 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Laura Abbott , Shanker Donthineni , Will Deacon , Ard Biesheuvel Subject: [PATCH 4.14 025/195] [Variant 3/Meltdown] arm64: mm: Move ASID from TTBR0 to TTBR1 Date: Thu, 15 Feb 2018 16:15:16 +0100 Message-Id: <20180215151707.003894362@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151705.738773577@linuxfoundation.org> References: <20180215151705.738773577@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon Commit 7655abb95386 upstream. In preparation for mapping kernelspace and userspace with different ASIDs, move the ASID to TTBR1 and update switch_mm to context-switch TTBR0 via an invalid mapping (the zero page). Reviewed-by: Mark Rutland Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Ard Biesheuvel Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/mmu_context.h | 7 +++++++ arch/arm64/include/asm/pgtable-hwdef.h | 1 + arch/arm64/include/asm/proc-fns.h | 6 ------ arch/arm64/mm/proc.S | 9 ++++++--- 4 files changed, 14 insertions(+), 9 deletions(-) --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -57,6 +57,13 @@ static inline void cpu_set_reserved_ttbr isb(); } +static inline void cpu_switch_mm(pgd_t *pgd, struct mm_struct *mm) +{ + BUG_ON(pgd == swapper_pg_dir); + cpu_set_reserved_ttbr0(); + cpu_do_switch_mm(virt_to_phys(pgd),mm); +} + /* * TCR.T0SZ value to use when the ID map is active. Usually equals * TCR_T0SZ(VA_BITS), unless system RAM is positioned very high in --- a/arch/arm64/include/asm/pgtable-hwdef.h +++ b/arch/arm64/include/asm/pgtable-hwdef.h @@ -272,6 +272,7 @@ #define TCR_TG1_4K (UL(2) << TCR_TG1_SHIFT) #define TCR_TG1_64K (UL(3) << TCR_TG1_SHIFT) +#define TCR_A1 (UL(1) << 22) #define TCR_ASID16 (UL(1) << 36) #define TCR_TBI0 (UL(1) << 37) #define TCR_HA (UL(1) << 39) --- a/arch/arm64/include/asm/proc-fns.h +++ b/arch/arm64/include/asm/proc-fns.h @@ -35,12 +35,6 @@ extern u64 cpu_do_resume(phys_addr_t ptr #include -#define cpu_switch_mm(pgd,mm) \ -do { \ - BUG_ON(pgd == swapper_pg_dir); \ - cpu_do_switch_mm(virt_to_phys(pgd),mm); \ -} while (0) - #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ #endif /* __ASM_PROCFNS_H */ --- a/arch/arm64/mm/proc.S +++ b/arch/arm64/mm/proc.S @@ -139,9 +139,12 @@ ENDPROC(cpu_do_resume) */ ENTRY(cpu_do_switch_mm) pre_ttbr0_update_workaround x0, x2, x3 + mrs x2, ttbr1_el1 mmid x1, x1 // get mm->context.id - bfi x0, x1, #48, #16 // set the ASID - msr ttbr0_el1, x0 // set TTBR0 + bfi x2, x1, #48, #16 // set the ASID + msr ttbr1_el1, x2 // in TTBR1 (since TCR.A1 is set) + isb + msr ttbr0_el1, x0 // now update TTBR0 isb post_ttbr0_update_workaround ret @@ -225,7 +228,7 @@ ENTRY(__cpu_setup) * both user and kernel. */ ldr x10, =TCR_TxSZ(VA_BITS) | TCR_CACHE_FLAGS | TCR_SMP_FLAGS | \ - TCR_TG_FLAGS | TCR_ASID16 | TCR_TBI0 + TCR_TG_FLAGS | TCR_ASID16 | TCR_TBI0 | TCR_A1 tcr_set_idmap_t0sz x10, x9 /*