Received: by 10.213.65.68 with SMTP id h4csp713726imn; Fri, 6 Apr 2018 07:42:59 -0700 (PDT) X-Google-Smtp-Source: AIpwx48l71zd/UEHZttWIirbkfuPL0yhzS6b98BUhTcMJKqUvghuvmkeAuO9h8yCnUfVwbtB5kj0 X-Received: by 2002:a17:902:594c:: with SMTP id e12-v6mr795329plj.233.1523025779671; Fri, 06 Apr 2018 07:42:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523025779; cv=none; d=google.com; s=arc-20160816; b=q9dC+EsEeTMdqc9AvkAaCCc5wE070hOc3PkV5JcYkEpjD68ifasmHVr4WD8YXcfcts NwE8/nLBt3vUaekl61/qD7Wv+zVc4W3gGjqBuJJ5i1YAc99GicShtl+g5Dv+ohlahBGa 82GsafpalDz4yw4zMVS3mLx+I8OKbl+SK9TiCZWJKSySim4p9eiNDO1VFEg0auu3XXjg dg69d+wW8UdQRDRBnIdYJ90zB1TDWK/QEsEyNH5i8kOgo2/sot/Blq6TDtPQ+uFoqiXm 1Xzcn2Jd3rRo4QvenEZJLWxR+2xxIDkHmC3QuBsCcdLUJvzXQjGCAtTsVg1GKbSohCpJ GD7g== 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=PHbixr3Xji6AB2niWjfdHbA4AMOik78uQGVjDBZxeI0=; b=Wsvy5dgw/dVVmaS28/O8gRPrPC0v5pMXGDvOxr16OScP74elAH6QHefdCXOTuP1Ik9 A+WUB5IOKhY5MZkTP6tytSf1C5z33VPzce7r978QOPFsOXtLi+7Zw6PCMVk2OYPo0rgF CgdbplvvFBh16XJxZbqL0X51zWnAZCPM4rFmkCxZiB8EedhtTLf0wXjsoaA0WMiP3zpU ue5SYStiE/NI/od0O4w1uNmqe735ZoTMpytmvddn28NANkNJbJoF7TVWzQjKl+UXk70d Azuw8gjMiQGzJmrmmcFQT8V8iP0LobDSE2Q7Z47pK84PqMaLmIqKtvQCVpHo6+RAbdFM zBKQ== 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 t88si8265285pfg.342.2018.04.06.07.42.45; Fri, 06 Apr 2018 07:42:59 -0700 (PDT) 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 S1753643AbeDFOl2 (ORCPT + 99 others); Fri, 6 Apr 2018 10:41:28 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58446 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755899AbeDFNel (ORCPT ); Fri, 6 Apr 2018 09:34:41 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2DF9EDBB; Fri, 6 Apr 2018 13:34:41 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Mark Rutland , Laura Abbott , Shanker Donthineni , Will Deacon , Greg Hackmann , Alex Shi Subject: [PATCH 4.9 052/102] arm64: mm: Allocate ASIDs in pairs Date: Fri, 6 Apr 2018 15:23:33 +0200 Message-Id: <20180406084338.948783994@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084331.507038179@linuxfoundation.org> References: <20180406084331.507038179@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Will Deacon commit 0c8ea531b774 upstream. In preparation for separate kernel/user ASIDs, allocate them in pairs for each mm_struct. The bottom bit distinguishes the two: if it is set, then the ASID will map only userspace. Reviewed-by: Mark Rutland Tested-by: Laura Abbott Tested-by: Shanker Donthineni Signed-off-by: Will Deacon Signed-off-by: Alex Shi [v4.9 backport] Signed-off-by: Mark Rutland [v4.9 backport] Tested-by: Will Deacon Tested-by: Greg Hackmann Signed-off-by: Greg Kroah-Hartman --- arch/arm64/include/asm/mmu.h | 2 ++ arch/arm64/mm/context.c | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -16,6 +16,8 @@ #ifndef __ASM_MMU_H #define __ASM_MMU_H +#define USER_ASID_FLAG (UL(1) << 48) + typedef struct { atomic64_t id; void *vdso; --- a/arch/arm64/mm/context.c +++ b/arch/arm64/mm/context.c @@ -39,7 +39,16 @@ static cpumask_t tlb_flush_pending; #define ASID_MASK (~GENMASK(asid_bits - 1, 0)) #define ASID_FIRST_VERSION (1UL << asid_bits) -#define NUM_USER_ASIDS ASID_FIRST_VERSION + +#ifdef CONFIG_UNMAP_KERNEL_AT_EL0 +#define NUM_USER_ASIDS (ASID_FIRST_VERSION >> 1) +#define asid2idx(asid) (((asid) & ~ASID_MASK) >> 1) +#define idx2asid(idx) (((idx) << 1) & ~ASID_MASK) +#else +#define NUM_USER_ASIDS (ASID_FIRST_VERSION) +#define asid2idx(asid) ((asid) & ~ASID_MASK) +#define idx2asid(idx) asid2idx(idx) +#endif /* Get the ASIDBits supported by the current CPU */ static u32 get_cpu_asid_bits(void) @@ -104,7 +113,7 @@ static void flush_context(unsigned int c */ if (asid == 0) asid = per_cpu(reserved_asids, i); - __set_bit(asid & ~ASID_MASK, asid_map); + __set_bit(asid2idx(asid), asid_map); per_cpu(reserved_asids, i) = asid; } @@ -159,16 +168,16 @@ static u64 new_context(struct mm_struct * We had a valid ASID in a previous life, so try to re-use * it if possible. */ - asid &= ~ASID_MASK; - if (!__test_and_set_bit(asid, asid_map)) + if (!__test_and_set_bit(asid2idx(asid), asid_map)) return newasid; } /* * Allocate a free ASID. If we can't find one, take a note of the - * currently active ASIDs and mark the TLBs as requiring flushes. - * We always count from ASID #1, as we use ASID #0 when setting a - * reserved TTBR0 for the init_mm. + * currently active ASIDs and mark the TLBs as requiring flushes. We + * always count from ASID #2 (index 1), as we use ASID #0 when setting + * a reserved TTBR0 for the init_mm and we allocate ASIDs in even/odd + * pairs. */ asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx); if (asid != NUM_USER_ASIDS) @@ -185,7 +194,7 @@ static u64 new_context(struct mm_struct set_asid: __set_bit(asid, asid_map); cur_idx = asid; - return asid | generation; + return idx2asid(asid) | generation; } void check_and_switch_context(struct mm_struct *mm, unsigned int cpu)