Received: by 10.223.185.116 with SMTP id b49csp554171wrg; Fri, 16 Feb 2018 03:29:04 -0800 (PST) X-Google-Smtp-Source: AH8x227dFfGVSWdbZilvBXcmZZ+BYosGbLLvvYVd+vhRvVWbG+GwG5rCAlQiUBlW4xUK+8lYjbZn X-Received: by 2002:a17:902:a504:: with SMTP id s4-v6mr5758913plq.43.1518780543980; Fri, 16 Feb 2018 03:29:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518780543; cv=none; d=google.com; s=arc-20160816; b=zylQ9gXjOu8XUn4LbsQiED8ob0Hybyk39eWLF0i81GlbkWDUfcVCI+l8obfjNHls2v ciRpzmu6dF1un8VhiflLynmztPAvOwrWKxGesoLfoJCiSmVAzZ6YNfTwR0cJ/R147LUC 5MWne3Mfh4G3csjQUj/WGgTOAEUsKpVYNE5RY6H3LwfIIwiy3pV+2n3NxKTOUdXqdQPw YEgu2rLC6W+7qu7YOVyTDH4nrhkBiIYfXcROiPRbabR/alO3d6V+I4Qx6YeqrZZPOR01 EiYIVbG1cMeuK2FQFOU6hUCetJQS8n4+fgehLnEDtVE54m5JpKDwXYsEio2NpRco5K3r sliw== 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=9nuz1JmyWV8dvj8h+xlcU3R7/CzD/tSD91m211Mv+AU=; b=ozoGncQCyUlqNX0CdmxpPHKUjHHnLQgTapBG3bGWAzm5txd553ZThRT1UMCDiCmBIF o16TfolvEBOwlIuafK/3ZuhvMl7bHwe1KUnaY0421A62z9uCSX2BSVZQoUQQEGx070cz QRuNAJSgoJtvjP9ajUXX+gqzhqBrIFP8aoVuWjWCmkPVQWSONpZIgXsN3qcGbO+0vinh hmzdbB0LguXLtSzs5tQG3vDa2jDszSWENR6MCRIYQ28HnaPbHkv10EDTw4w+LEmotG8d XhabUOMk2IRw7XEhH1cpOHQEYo0hQuwYzFnehzkEwE0/vzPyeaWDm8mDZtEzT/aBWR8q Oxtw== 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 s13si6035778pgp.145.2018.02.16.03.28.49; Fri, 16 Feb 2018 03:29:03 -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 S1165724AbeBORui (ORCPT + 99 others); Thu, 15 Feb 2018 12:50:38 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:55226 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1164273AbeBOPas (ORCPT ); Thu, 15 Feb 2018 10:30:48 -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 E3156110D; Thu, 15 Feb 2018 15:30:47 +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 029/195] [Variant 3/Meltdown] arm64: mm: Allocate ASIDs in pairs Date: Thu, 15 Feb 2018 16:15:20 +0100 Message-Id: <20180215151707.202473299@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 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: Ard Biesheuvel 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) @@ -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; } @@ -156,16 +165,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) @@ -182,7 +191,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)