Received: by 10.223.185.116 with SMTP id b49csp491652wrg; Fri, 16 Feb 2018 02:23:25 -0800 (PST) X-Google-Smtp-Source: AH8x224X2t13vRleFHcOp1pMrGM9gFrYFhkeuNDczVywK+bkOu4e1IFYYMrEU/Z0QjBBMzI80Osm X-Received: by 2002:a17:902:4906:: with SMTP id u6-v6mr5255134pld.92.1518776605310; Fri, 16 Feb 2018 02:23:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518776605; cv=none; d=google.com; s=arc-20160816; b=Wyyiy0lQFYV1bATFiZT4SofIkC+89DWEyBWBBEXMcmtIZ2bNx4P5ZpFxpOCb6AnP2p eG4/wHRhV+shTiKMxaqGADDMzRhVj+GYsrJNZgp6bcUxI0o1EvqMiAHnR8Hl50ZFGu2w JM332DOeZ+qFwq1/wrY+Ec+2rCRDo9a9reReRxFoPlCisWpT2atjIG0rtDEEdVTcI6oa LoxdVrxm9OV5jOodbPlUVbgUvz7gKDfrDhylZYlJ9O7Ri0uUfEDQjM3UQRIBVTzwLeDN vTc4KZ9CT/SLntWGZ7mVD4qa/K3daD3bZBiD1b8lS9Mtm3EELiWVqDZJvnph19Uyrrnu DTNA== 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=L1/uF7OCkwsNUSmSkVTPjUieZ3VBzdboCYHvkI9r20s=; b=O7ZwM1F/Uf1XfvrLDhLZvcOd3LjjhSSzEaXF2ych6FfglGwKmD7IrKQoCQ4q3/yxM9 7TacxWTPoJlGf0xWTrVhc8z5TS2k0/9MUjz84v6FLfXalhYUe4VF6ZQmEmztdhvQz5rO BCdBBl0sKc+CmhZ6qWCIc5uquxhtY3qiRcNHNXDVmaUOKMAwMYD1vUOjon8ONJFLyE91 3QSi1RyzwMRvp/ke6f43RWR5bZZbdyrX0TYSbMQePAVPoqVoEMVdP4vv6qpUOIUgqPfh +aq+VztnLMz6tqJ65Ewtz+dlQlUF8DjDzn56GwyBmFRzIhKal0X6FghmSfce9lZ93yoQ qZhg== 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 m14si1008661pgr.249.2018.02.16.02.22.57; Fri, 16 Feb 2018 02:23:25 -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 S1426764AbeBOQ6o (ORCPT + 99 others); Thu, 15 Feb 2018 11:58:44 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:59760 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423514AbeBOPj0 (ORCPT ); Thu, 15 Feb 2018 10:39:26 -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 99FEB10F0; Thu, 15 Feb 2018 15:39:25 +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 021/202] [Variant 3/Meltdown] arm64: mm: Allocate ASIDs in pairs Date: Thu, 15 Feb 2018 16:15:21 +0100 Message-Id: <20180215151713.996965074@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 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: Greg Kroah-Hartman --- arch/arm64/include/asm/mmu.h | 1 + arch/arm64/mm/context.c | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) --- a/arch/arm64/include/asm/mmu.h +++ b/arch/arm64/include/asm/mmu.h @@ -17,6 +17,7 @@ #define __ASM_MMU_H #define MMCF_AARCH32 0x1 /* mm context flag for AArch32 executables */ +#define USER_ASID_FLAG (UL(1) << 48) typedef struct { atomic64_t id; --- 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) @@ -98,7 +107,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; } @@ -153,16 +162,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) @@ -179,7 +188,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)