From patchwork Sat Oct 28 23:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13439616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81BF1C001DD for ; Sat, 28 Oct 2023 23:14:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B56466B02DB; Sat, 28 Oct 2023 19:13:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AEAD96B02DD; Sat, 28 Oct 2023 19:13:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E3FE6B02DF; Sat, 28 Oct 2023 19:13:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 74F1A6B02DB for ; Sat, 28 Oct 2023 19:13:55 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4541D14087C for ; Sat, 28 Oct 2023 23:13:55 +0000 (UTC) X-FDA: 81396424830.19.5607E4B Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by imf17.hostedemail.com (Postfix) with ESMTP id 8067440006 for ; Sat, 28 Oct 2023 23:13:53 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Okj1T4kA; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf17.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.47 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698534833; a=rsa-sha256; cv=none; b=e4eU6ubtYY3EzUb2aMOl5BiDpPN0LUA5iyL7HdRqI5IADixOzXtZ7+VVZhjPk3yG6zMmOQ 6XCw1MUxXM8GXJbIhsufaX83vzqhbHy+soy3sCwOVvCqdYf3renCKSaNEXt3kPwbdlJT+K ViEUa+eeZyy0X6RxVE2cPmPhMMi+SXA= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Okj1T4kA; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf17.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.47 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698534833; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; b=XjCXSDDppPKFe7NgEQV+yy/2GKyP3el1Aq6J+zfLp1QE5MkwlwSJ3Z8Gk4CFqz7avAPJuY FlS1ezihJ7jC/ePLYL6Qeb7S2ADlP2h4EWHYG7sz+fo3+L4T42ddpYTpTJtx3tTfAnC1OH zIUnqbYH5vReHM0IfBEf/ZO9l4sCRvU= Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6ce2b6b3cb6so2234147a34.3 for ; Sat, 28 Oct 2023 16:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698534832; x=1699139632; darn=kvack.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=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; b=Okj1T4kA1CGFUTzclvAQ7z/hWpYx29wqpK4FaWWbT+lpSmmfQ3+uSwFI9jTiTYqplU DPqGXTSCJfImCsE+mJVwpC1DMuSujYK/GLD5RNRnclBkQhbHYnjfmgwfGjTORV+khDff azsavRAdHFDzofrkl91T5kzlgZF/1k3UPyPb/Lcsnh16claLSRFMVx6UhmznkTScxW2W fsQvYvvIiq3AJKcvyiUN+I6VFhXtoe682AQmC28V8fx1xbxqcBwpt2w9G7jfJlQmuK5O PYqDPfu8DoBYfGM0ZtofHm7rTkHiONilSNq4S4FDBAY7aK6zR8GzgxDeTo41A7X4xnyj 7tMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698534832; x=1699139632; 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=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; b=LSn08tU3rzyHw4jnLauYjLL34gJs+XcpE0qOwd4VkQzsEiKQIMe0vqjQARhVUmrvsE WvYAMJty/4HAOxaWNOqYYBrUY2cHbGiSxNpAy97f4Fhr2WBUznhvauGOO5DatQAhml97 gW16o/cuIvFy/URFr5T3ySdZBsPiqI0EvwmXEQ9D/DkZDMJ3hHlprR4B9jTU2hw28Vrd ftQvclH6WcCwolZK79bQn1vOj2PJYgJAPb5ff/AdEeWebKQpMN6/BJqVHQTPanoc1hpp 3PMvINHemKrjC/s5up8I/xHqMIgoG1R5FUEGsx9cUzRY0+K8ayTIUr1p8bdtmqKtSTUt OusA== X-Gm-Message-State: AOJu0YyxhgvYVNAyuX44TAwbb8alceRXYp7pUz6722cEGKPmhC5KuczF wiAyOhf4FJoIut+tKyGkelsm4Q== X-Google-Smtp-Source: AGHT+IERITWcnpZawWSuuFpc/cjj/Gs86LMrNqv2CdnNpOWafKnnt4wsBVVnxZL60abLMgaX5a0ZCA== X-Received: by 2002:a05:6830:1e30:b0:6bd:c7c3:aac2 with SMTP id t16-20020a0568301e3000b006bdc7c3aac2mr6567117otr.18.1698534832734; Sat, 28 Oct 2023 16:13:52 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id u17-20020a17090341d100b001b8622c1ad2sm3679345ple.130.2023.10.28.16.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:13:52 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , Alexandre Ghiti , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Samuel Holland Subject: [PATCH v2 08/11] riscv: mm: Use a fixed layout for the MM context ID Date: Sat, 28 Oct 2023 16:12:06 -0700 Message-ID: <20231028231339.3116618-9-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231028231339.3116618-1-samuel.holland@sifive.com> References: <20231028231339.3116618-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8067440006 X-Stat-Signature: brtjq4qwc4n85azahhnpeogxqxketpsk X-HE-Tag: 1698534833-597490 X-HE-Meta: U2FsdGVkX18FzFstjFiWm13uFK8UIUjQfkuW9a9C9m6rzjWlmLyO5TsqjjWJrpLj6NmhaoRVrtTBMyo0g/v1rYzBUiPUBJ+y6J7xUtC9LpBjJCSZozwuC+7UvfE6fvW60JkSKKKxwxqynSetU/Af33k3cRHwAEnm+KLmrxEZTp2S4tCaWO5SJ6P8JZxYLEUMpEmxj88d4mX2bZjiGP3L7nR8xmrDqQKOeroxu4DZvRNFpTF7leLN+DRCEb1URxep5hH3EoJg+bWu7WmYgozwFrgrP4+2CIxNqLKr8ZGQpfFoh5R693tiatRTLpwdDTpsQPaTl1GWBq/ETiG0FNlCaij5DLpNsPQ5gF+qGUGRCxaygcEFU87IE2DgVNZdZzqC7rt+M8ZNTpe6lmwM8m9DLS9h7BTgZbUjITxk9ovj9i72xWnQF2Wg09ityhOiatZYC9ThDsZ7AVwNjLaBTsf+qyWHV9U4kZR+QY5IJsCtRBd0jsLWeTmtGFVP8iJmAAK6K4rJagLlHBsRZInlrARPvDYJFKnKcZnmbaYC7vgTKkW1x1OV7l6CyKIANvzYyBS+cWK8sKUwjsh4FuCFhZdTSCySTPQvN3yPB95jxUDFoSOINECvtAeGDSuQkFjcQcZILsA48wzp1HrBsmIwsrVphvUuHT1jpWAlvD7Xroi7HBHwP3mi4kG5vfjNdo8HHxQd4UosjWL8nHxY2eJZ2jHu5P5VPLo08e+hn9K/BO13MzL2obaO5JJtW4Dmwe/BWbBWl18B+see7eyediWItz22bM1ASE+HaEvGSIEM4g+3DiFnzA38jBGX4zXWOWpDzOSSvM7HIA9mDm/EopzpOFBRMBV6loiWkL31zm35PVlbVV7k+Gm+BT1G9aYoBZjEC/acrwojqz49J1kURcA+Ivyn4RGIKUfqngwI60vgiXs3gR2h8e79QmTdTJcra6dodXqAO/s8oWaJkjiGcYhSs0j lJpEo5VP x9Ze5ETpO+Tyx+NrG+toJBbFZv4Iw0uPwYdsCZQ1rd5GnWx2ReGFnV7iqaQ1BEj7DKXgAMy5HDjrk5sWcxPS5S5uPyRK2oNYOIqv+JCKSWYzT1vlYlOBKZ8df0pQHkiU23F42217naJZnkDqHB0Vp9TDGRAASQsYx5c56TZ+uDQ5w4HzU7CgNJRQxMxXOkFzccuSacybY6SKuUGz9kRqwGMTZtZbl5yYErsZt7Ejb2h7LrC7rDEWUoKydrN+5171hwioZ32gveqBAkHROPnFvT3UFxLPJbpcs0UirWlNaqaGsLtwZ6Req7VHAsdJ/uWq3bN4bZd8o5JzyA1I5YhQ7I8nbbIf9pfTIkO8fGU2hhdq0RmrpM9FXnwbuKw+diS87TzpQk9inxzTmmbQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000150, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 e529a643be17..62d780037169 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)