From patchwork Wed Mar 27 04:49:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13605554 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 B63EDC54E67 for ; Wed, 27 Mar 2024 04:51:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC4936B00A2; Wed, 27 Mar 2024 00:51:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B4D0B6B00A3; Wed, 27 Mar 2024 00:51:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 902E56B00A4; Wed, 27 Mar 2024 00:51:00 -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 7D2C56B00A2 for ; Wed, 27 Mar 2024 00:51:00 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 3ADB5A03B9 for ; Wed, 27 Mar 2024 04:51:00 +0000 (UTC) X-FDA: 81941594280.16.08EC3B5 Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by imf08.hostedemail.com (Postfix) with ESMTP id 5783E160004 for ; Wed, 27 Mar 2024 04:50:58 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Mhwl5sPi; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf08.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.54 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=1711515058; 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=A+Ju3+5NsQ7zqLi78mVdBh82QtKzTZZzrfFOA+rFDFs=; b=b1TH14cie+n3bC799DliJVlnqSVvrz8KednnRbZEoC1A7hWIpyWuMGGGfqMG/AQrwOB3/p NtjXWSYdAMS2o+LKnYizQRC3/1NccJ0EymvX+O33bDqXYRI1j4cMFD8PLgj6Z6Hgisp1iA M87QLQX7z0zi/YFxKkVR17WCtg5alug= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=Mhwl5sPi; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf08.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.54 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711515058; a=rsa-sha256; cv=none; b=Rp4HgDCo6pnX7bVf5QkP46ckxiHyipti71u6IDHsEedjlSMvmFa5TbtUHhC/kPwAOlBRhg QOwd2ek6fG0NnMgJKC9iqXGSDpME2xDkmABnJjYafhUKtBS4mddJXJgz6sPPt6sg5pyPNI a3jY6XWHHmYHCrSrTtJJe0tPkWhnca0= Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-5a4859178f1so3414916eaf.0 for ; Tue, 26 Mar 2024 21:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711515057; x=1712119857; 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=A+Ju3+5NsQ7zqLi78mVdBh82QtKzTZZzrfFOA+rFDFs=; b=Mhwl5sPiFAlAaqcwHLsIWL8i5cFJe0STLg+RHwUa7OOKTRaQNdfS4ZEGZ057G8Q9R8 GRpMWWfuH6zi+JdZPQQPAweZVCuGsQ6DFCK6+PfqL6u+3D3QnYlH6JLwU5IUmXgvl2Ri FchmTWAiAVW7KuCzMs5+Ea89gEJ0EFCDLSgvryt1HrMY+JHOgRfML2xyhQ7yn0qCYZoF weqk/2yaAdTSvgX/bPyEjrMz8rpk+R2ThSrVbyfdh3ioa0VFuPBIYbtZO+/X08YY+AaL xf0MxIqDFokbp7HMP60jXwHxMOkwyyTZ9syR26+6+zaFdzm7zQmrHg7zj1s+cigo8v+w JZZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711515057; x=1712119857; 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=A+Ju3+5NsQ7zqLi78mVdBh82QtKzTZZzrfFOA+rFDFs=; b=Q/HEJWbSYOmlG5BMOTO4rLgnLXzDmVzukydXjAWvkW/pNMaYu89fQKttpQFX0vKCUI /a2PBeE4eYQGSp1E2FQTNzrAbNBtwuzzAPC/8GlyiSVkKJYrzAQUbePoLjBfxGIlQgGD azZqBpIyNL3TJV0RLXX7N4fbu1QRAPTRkFhchfCdqzF/SC+/C92AI1YanqPttdROFBtk btXaTgZhvLtXJg5iseaXcR4QertdIIH63AuuznFq99Kc0Mk9i+FG8kw8Rg4GvcEYvDqL nRAzKIvMUtKGpdYLqjMqmZWjhN8Td8fWOkbcNsKW0np1waa4Eg3DyhlBCkGpkaQ8/l6L CQPw== X-Forwarded-Encrypted: i=1; AJvYcCX7rBIUvwqF2HyfMrHCx+yISDnyo/PVxHKUhsqSpJyRZBjzGkC7LzR4krKrxRleS+oPAJ5hV/w2/+WR76mKnMutngk= X-Gm-Message-State: AOJu0YxfxlOUkg3N++yJ38ZI+YinEvsWSJJbmtNmkk9/3/2brfH2VNfc gWLNwkUJKQ8XtUCyDVYU09HGaNw1quGF8MXzKWtkZD0BbJQYcpwOzJleEv4Bqto= X-Google-Smtp-Source: AGHT+IE4clbeICIX6LaCSNcjSNKRNzkyOLoTskHKcKR+t8ek8fOhgjRruwacqNmtd1HR0FedGGJk+g== X-Received: by 2002:a05:6358:6397:b0:17e:c8d9:328 with SMTP id k23-20020a056358639700b0017ec8d90328mr5244771rwh.11.1711515057489; Tue, 26 Mar 2024 21:50:57 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e31-20020a63501f000000b005e4666261besm8351500pgb.50.2024.03.26.21.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 21:50:56 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Jisheng Zhang , Yunhui Cui , Samuel Holland Subject: [PATCH v6 10/13] riscv: mm: Use a fixed layout for the MM context ID Date: Tue, 26 Mar 2024 21:49:51 -0700 Message-ID: <20240327045035.368512-11-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327045035.368512-1-samuel.holland@sifive.com> References: <20240327045035.368512-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5783E160004 X-Stat-Signature: oo1gj9igrjada4afpartrt6npkqjxbcp X-Rspam-User: X-HE-Tag: 1711515058-682732 X-HE-Meta: U2FsdGVkX1/J3SHfa2OB0ZIS6F6f92Msxpa7uXcZykN7c3gayViHgRDKpmtKCmyZVyLXVLV9XVf+Dyc472xvYDaflxaR9Avy9aX4zSC6e99DcpgBYPgqfSV0DejPGkVBKAxv5gkrYmtZwHwRhgoqhLSg1sjed7htfUSefscRAUuzcNGxJ9s2ENMVcL6T15Mkecqb1amzGDGEXskJ8nsZcPhFwePo8T4otGs8H4vEdU0QLQBsy8vugB8EbhWduLXjMXu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S8I5ygzLMMEONt9ueLOORgq0DWbvDCIYJZcoxYlQwqtKdih+ZsekDYXYlKsoqo0c2PsdAIJkQfHx7oSw2OFzh60CXtefn13+rxeIbWKZcK8og9k= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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. Reviewed-by: Alexandre Ghiti 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 8e329721375b..72e559934952 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 b562b3c44487..5315af06cd4d 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)