Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6801031rdb; Tue, 2 Jan 2024 14:07:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHNGHTzCBnScLRfqlUgi4lHm2dt2dkIarldnJLnnZayCxPln0vQnsY4wR7R/+DAfTXKQEyK X-Received: by 2002:a17:906:5185:b0:a28:113:8eeb with SMTP id y5-20020a170906518500b00a2801138eebmr1456659ejk.16.1704233219923; Tue, 02 Jan 2024 14:06:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704233219; cv=none; d=google.com; s=arc-20160816; b=wIHnFxI2jTivh9gVzVsftD29foOI5/EN9MXbJkWFrIIwchpCIhef4NRS/JdwJrvUTV IpiaPbk3lJ1RC2if9LYBxgHmlfKTedpbM9gj8jRSvA8zqmO15H71T8kJ+KzCbMHaxMQ9 WaH0zjsWse7wTyWCh+yDrhfPePHuWyc7UZZuhd1M/yLtE8G0iqCKhV1TSVv6wEKkFzjO SAatiElD1cwDcxLpuSSqA2wlFcsbP7MnGBix5t8+JfHwhK0JDgguFEdy49n5RtPC5hjE egpRmXu+wrj+Fr6V+F9lggLVPQUmJY3Yh9qEx6RViW7lpcBBQnEhJIdPREZZgkfwnw4V 1qZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=g2cmoIK/tf9yPohv/YvO5QQvGunkgXtONjIGDQZEX58=; fh=dlotjpk72cYcmDz0+AxIEXTz48ooVBc8lhZ+ndNwuOg=; b=yiPfXZKBlql8bVN48WB7PeGNvZGT3IzR2NkYF9s9K7PtSr02ufKnu/TOaI/W8aS6Le 8WJJElCTZVDYm3BxssztTE5GuB4u+DRS1w9uDoUWTobERWWI4K55DlfxZ7pzAK+2HOwq YUejx/3SoUggKNaqEP+XqrqN06p0VhB0cuu3G5UmM84/QpmFiIODIP3BIpEpFIZwtsdV uf8HiTVrXxVTxIA47dEuzr0huOCafDZRHYU9YJoJx4EXlnoUNmrQ9QAdrISbdYXxpqDt +pauBs9oPP2Fyaql5aREkeewrNhkHWIqmIzsKJaNANU03pfXmY9avr7voHqVV54Zl8T1 PMig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=NKqqWxPa; spf=pass (google.com: domain of linux-kernel+bounces-14919-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id yj7-20020a170907708700b00a27ec2cd8bcsi2164351ejb.680.2024.01.02.14.06.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:06:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14919-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=NKqqWxPa; spf=pass (google.com: domain of linux-kernel+bounces-14919-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14919-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id A87C11F21620 for ; Tue, 2 Jan 2024 22:06:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 542541947B; Tue, 2 Jan 2024 22:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="NKqqWxPa" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1AB461947A for ; Tue, 2 Jan 2024 22:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-28bc7155755so3952296a91.2 for ; Tue, 02 Jan 2024 14:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232906; x=1704837706; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g2cmoIK/tf9yPohv/YvO5QQvGunkgXtONjIGDQZEX58=; b=NKqqWxPaj9rcV1IWAEDEU5QgBO1QwiNOgePEN9zSk7nzNbpWa44amkz2NbAO6NLdHJ MLMvcUQ4n3FWjNLww45EzULW9lgASED1bsOKehFf9/sLOsXYlIsRRPLlMWQPAzz3pndL N3I9aLOTxJ+0sXdLCvpQlk6IuLCik+2236voMxhb8/Yz1qGbOIdAK34fcs8SFsBFW5VT xtncr81K2RPu27HOCTYsAS1XUumIxuNDtA78pj/zp/T45YydmbEu2OfyEOxCJ9S1a79i BdTjkNPY9HL72mdjFvJq4nMloRpUIfk37237cZfmt+vARzPch6FZxki2j+JN9RFiJmL8 u8+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232906; x=1704837706; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g2cmoIK/tf9yPohv/YvO5QQvGunkgXtONjIGDQZEX58=; b=g8Px5+hBA5tqkHUcGnjR9fbo46CrvGxSqphTEixYCDDbrzjj1hsJa1bgQ9y8syRDEA oEABHh3/UEyX/6+MwMmKuNEfTUxXY8ipUSMnjAL1O9lne2uke6DAP9LOx0B6ITyoGr6R 3v8WWMfjCEpCkiVtjKJaARVaS8BDZwSxaOmelm1urKlqrDYnNxgH8H0/0sLaPIgnMoaJ s4T/+agPjWY+r+ne2+whoeHY6znjjNMwQzmo+BLT9YD0ad8FbpvWsTPNKI1+G1LZlvlc kzppI4BuycbVXGDfyXe1IC9CrmeW80VaipE2QThMweFL0hTSOcUgUGMEBEIiBKL9zq1C 4wAw== X-Gm-Message-State: AOJu0YzeX87//xDNABoytTYrZxNjDKgMmTXNCFCH+rxPpa3QuEjqfGJW ueRBvoI4y/AzGxHov0W/lfjSDaeBUU/EOw== X-Received: by 2002:a17:90a:134f:b0:28c:b1bd:3c42 with SMTP id y15-20020a17090a134f00b0028cb1bd3c42mr2130687pjf.55.1704232906433; Tue, 02 Jan 2024 14:01:46 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id r59-20020a17090a43c100b0028ce507cd7dsm101724pjg.55.2024.01.02.14.01.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:46 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Samuel Holland Subject: [PATCH v4 09/12] riscv: mm: Use a fixed layout for the MM context ID Date: Tue, 2 Jan 2024 14:00:46 -0800 Message-ID: <20240102220134.3229156-10-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240102220134.3229156-1-samuel.holland@sifive.com> References: <20240102220134.3229156-1-samuel.holland@sifive.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, the size of the ASID field in the MM context ID dynamically depends on the number of hardware-supported ASID bits. This requires reading a global variable to extract either field from the context ID. Instead, allocate the maximum possible number of bits to the ASID field, so the layout of the context ID is known at compile-time. Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/include/asm/mmu.h | 4 ++-- arch/riscv/include/asm/tlbflush.h | 2 -- arch/riscv/mm/context.c | 6 ++---- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h index a550fbf770be..dc0273f7905f 100644 --- a/arch/riscv/include/asm/mmu.h +++ b/arch/riscv/include/asm/mmu.h @@ -26,8 +26,8 @@ typedef struct { #endif } mm_context_t; -#define cntx2asid(cntx) ((cntx) & asid_mask) -#define cntx2version(cntx) ((cntx) & ~asid_mask) +#define cntx2asid(cntx) ((cntx) & SATP_ASID_MASK) +#define cntx2version(cntx) ((cntx) & ~SATP_ASID_MASK) void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, pgprot_t prot); diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index d9913590f82e..5bfd37cfd8c3 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -15,8 +15,6 @@ #define FLUSH_TLB_NO_ASID ((unsigned long)-1) #ifdef CONFIG_MMU -extern unsigned long asid_mask; - static inline void local_flush_tlb_all(void) { __asm__ __volatile__ ("sfence.vma" : : : "memory"); diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c index 43d005f63253..b5170ac1b742 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -22,7 +22,6 @@ DEFINE_STATIC_KEY_FALSE(use_asid_allocator); static unsigned long asid_bits; static unsigned long num_asids; -unsigned long asid_mask; static atomic_long_t current_version; @@ -128,7 +127,7 @@ static unsigned long __new_context(struct mm_struct *mm) goto set_asid; /* We're out of ASIDs, so increment current_version */ - ver = atomic_long_add_return_relaxed(num_asids, ¤t_version); + ver = atomic_long_add_return_relaxed(BIT(SATP_ASID_BITS), ¤t_version); /* Flush everything */ __flush_context(); @@ -247,7 +246,6 @@ static int __init asids_init(void) /* Pre-compute ASID details */ if (asid_bits) { num_asids = 1 << asid_bits; - asid_mask = num_asids - 1; } /* @@ -255,7 +253,7 @@ static int __init asids_init(void) * at-least twice more than CPUs */ if (num_asids > (2 * num_possible_cpus())) { - atomic_long_set(¤t_version, num_asids); + atomic_long_set(¤t_version, BIT(SATP_ASID_BITS)); context_asid_map = bitmap_zalloc(num_asids, GFP_KERNEL); if (!context_asid_map) -- 2.42.0