Received: by 10.223.185.116 with SMTP id b49csp491683wrg; Fri, 16 Feb 2018 02:23:27 -0800 (PST) X-Google-Smtp-Source: AH8x226HOg5j43yh91PcEA/b9t/fQHdEM+1a/O1tYa31tNTWV6bjhvSD19qjdQTmYHuXYF2nArjA X-Received: by 2002:a17:902:9686:: with SMTP id n6-v6mr5361642plp.333.1518776607334; Fri, 16 Feb 2018 02:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518776607; cv=none; d=google.com; s=arc-20160816; b=HLyy/w3f34tHNRdg3ppwGw6acFnUxcc03AKvP/JgjHtpBQ8WjZA44A6Rl1UOLzRCme XLZMbTDSLQ+Rlk7bVDey6U+zOY/ODLFGftWrSiYq+/xf9kGDVn3A7Oqjjr7KZKOGkJ/V BuRuqkM8TWvMwvxn50vXJMuFyiL7QQU/aVo35N/2ELX3wJUVb/ZQADI0zmDMLQtiWL7U 1Q2f6AsdMzqkQsXMLgp7z9al8NdDEwCLTpB2tehsYxDtZAyGzUExPz06oazMaoungWQd e83cYf4ERhxdEpfi4E7CxKivg37QeIX1LqjDPRLqxnuCIkXrKmXMETKJLPZUzW5h/hA+ PVAA== 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=RIwyDXiV0cLso8daOKujI4C5zHV+1aDzto+lwaWKTYA=; b=skVWGgZwZugh0RLJkddkr5n6TWSBE7IFsbTFQ8XvsfX/yfPk+lSudn4krL7xWoqfvY D/6yuwHBgMzgftb4Ik6f759WDwyqmPVynPz0txxO4qKywIvBb5g16qMXS5Im7swAzd3o gXipudUETqcDNc4xtiTIHREQfzsnc44+NgihUSAb5VK7xq+8YrfX+ChGxaogmVqV7R1S hRYQ91yUWNeSXbNEZc4YuZWddZx1Me48NuF0USQjkeVoflNE8bhMaVeK4BNxOF3bMP9D HYGOfhuSmv5xtm7uTOEh3Te/Q3WC70E/t4Bj1BE5+FIt9fCwhE2E3ISyKtG+rliGSEZz O56A== 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 204si2733837pgb.389.2018.02.16.02.23.11; Fri, 16 Feb 2018 02:23:26 -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 S1426678AbeBOQ7W (ORCPT + 99 others); Thu, 15 Feb 2018 11:59:22 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59718 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423483AbeBOPjP (ORCPT ); Thu, 15 Feb 2018 10:39:15 -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 9145210FE; Thu, 15 Feb 2018 15:39:14 +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 Subject: [PATCH 4.15 017/202] [Variant 3/Meltdown] arm64: mm: Move ASID from TTBR0 to TTBR1 Date: Thu, 15 Feb 2018 16:15:17 +0100 Message-Id: <20180215151713.758586695@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180215151712.768794354@linuxfoundation.org> References: <20180215151712.768794354@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.15-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: 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 @@ -224,7 +227,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 /*