From patchwork Thu Nov 30 16:39:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Will Deacon X-Patchwork-Id: 120235 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp20692qgn; Thu, 30 Nov 2017 08:46:34 -0800 (PST) X-Google-Smtp-Source: AGs4zMbo4ja6coeVihd/Y0pH7OREs4e/4cx1MWRYYK+06orm1tEvSCadzmfpVbmEVUWUTm7VH1xB X-Received: by 10.159.214.146 with SMTP id n18mr3351443plp.310.1512060394058; Thu, 30 Nov 2017 08:46:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512060394; cv=none; d=google.com; s=arc-20160816; b=dzR6mNA4RhR29iw0H66Lc/QFdSE+3YlXkvd40ms34RDZxXz2qgXbfUnTn/vaCUIz9Q XhI36S34yYT8T0pjqcOEf9jCXZK6J985BcxCVtH8pFLq55cHeESWCKmasd26fTs48Fi/ HygySHFeDPTXpYY92HfWpbDeQUWD7czZ1o6aZDMH4IdWUK0M5zyS6MOb0o6YYz6Xb7Ki H/00kM8/siJPtU8OS48jQ5vhza3uP18o+Lp2nxiryDn2UoB1WHOrhU2o+7eMnChwtl6V VQeGuLup9Lgx8nYye5YjXIBdenilBwf2eN/F+K/VzGYidljOBmiAY7OoSppQu01+90n3 u6Nw== 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:arc-authentication-results; bh=EW5Xa6a6OclLFhj0heQvM6HaWM/n9wJa92XP/x+rHEI=; b=MqE5A6po0RI2s5oMJPtRDygcfqjEHHArrDUvhJYHE6ijw8K5/VdjStSK/00IjovOpY 0JUdQiNGNw+PLRtwBHYle1r2A822EPc5Ma8iFG3Z2fvX4Mv8UREOjacGXEzD/MYLzezn 3TEAciAJ/Uze9P1+qXskPPrE2q/2CHwOPth3nZoQZt+JgrCt0TLzWxzRm/SsY16RT3t6 MUfzYd1xwVF00OkBwOWTvQ+gwSP8nnCwdOPmByok6L8pTtL9wnBQ+b2dAJfO+sWs7ayH cxbf69V0FbkxkCAzhu76CfO10LP7F3L4AzkG56voymEDBClWYAgWmFUbXhJlBivDKI4K kukg== 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 w5si3213637pgm.49.2017.11.30.08.46.33; Thu, 30 Nov 2017 08:46:34 -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 S1753732AbdK3QqR (ORCPT + 28 others); Thu, 30 Nov 2017 11:46:17 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:57404 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753042AbdK3Qjp (ORCPT ); Thu, 30 Nov 2017 11:39:45 -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 93ABC15BE; Thu, 30 Nov 2017 08:39:44 -0800 (PST) Received: from edgewater-inn.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6507B3F774; Thu, 30 Nov 2017 08:39:44 -0800 (PST) Received: by edgewater-inn.cambridge.arm.com (Postfix, from userid 1000) id A6D3B1AE3BDF; Thu, 30 Nov 2017 16:39:47 +0000 (GMT) From: Will Deacon To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, catalin.marinas@arm.com, mark.rutland@arm.com, ard.biesheuvel@linaro.org, sboyd@codeaurora.org, dave.hansen@linux.intel.com, keescook@chromium.org, msalter@redhat.com, labbott@redhat.com, tglx@linutronix.de, Will Deacon Subject: [PATCH v2 03/18] arm64: mm: Move ASID from TTBR0 to TTBR1 Date: Thu, 30 Nov 2017 16:39:31 +0000 Message-Id: <1512059986-21325-4-git-send-email-will.deacon@arm.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1512059986-21325-1-git-send-email-will.deacon@arm.com> References: <1512059986-21325-1-git-send-email-will.deacon@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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). Signed-off-by: Will Deacon --- 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(-) -- 2.1.4 diff --git a/arch/arm64/include/asm/mmu_context.h b/arch/arm64/include/asm/mmu_context.h index 3257895a9b5e..56723bcbfaaa 100644 --- a/arch/arm64/include/asm/mmu_context.h +++ b/arch/arm64/include/asm/mmu_context.h @@ -37,6 +37,13 @@ #include #include +#define cpu_switch_mm(pgd,mm) \ +do { \ + BUG_ON(pgd == swapper_pg_dir); \ + cpu_set_reserved_ttbr0(); \ + cpu_do_switch_mm(virt_to_phys(pgd),mm); \ +} while (0) + static inline void contextidr_thread_switch(struct task_struct *next) { if (!IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR)) diff --git a/arch/arm64/include/asm/pgtable-hwdef.h b/arch/arm64/include/asm/pgtable-hwdef.h index eb0c2bd90de9..8df4cb6ac6f7 100644 --- 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) diff --git a/arch/arm64/include/asm/proc-fns.h b/arch/arm64/include/asm/proc-fns.h index 14ad6e4e87d1..16cef2e8449e 100644 --- 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, u64 idmap_ttbr); #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 */ diff --git a/arch/arm64/mm/proc.S b/arch/arm64/mm/proc.S index 95233dfc4c39..a8a64898a2aa 100644 --- 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 /*