From patchwork Tue Jan 2 22:00:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13509536 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 0E301C47079 for ; Tue, 2 Jan 2024 22:02:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C7ABF6B02BD; Tue, 2 Jan 2024 17:01:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id BD9A06B02BF; Tue, 2 Jan 2024 17:01:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A04A86B02C0; Tue, 2 Jan 2024 17:01:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 8CE4D6B02BD for ; Tue, 2 Jan 2024 17:01:49 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5B6311607CE for ; Tue, 2 Jan 2024 22:01:49 +0000 (UTC) X-FDA: 81635743938.23.59C7327 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf22.hostedemail.com (Postfix) with ESMTP id 7AAD6C000E for ; Tue, 2 Jan 2024 22:01:47 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=gDo1Z9hx; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf22.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.215.176 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=1704232907; 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=g2cmoIK/tf9yPohv/YvO5QQvGunkgXtONjIGDQZEX58=; b=hUrxeNtK6Foc51Xdd2TCBe6x5WfYmmQp8/Xh1EnpHRcjgpeANXCKaOgChwYEsAG7UPLqcj l/EmKSdJJ26U3n9ng/a4gSdWn4uPQueNSNx8XU15QEzF9pUvd2HnF5D3VIkye0gsoEsi6d DfWI6zcVwlY1DuwShsfTKlIcRjbPqi0= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=gDo1Z9hx; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf22.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704232907; a=rsa-sha256; cv=none; b=xd87iGhy44glTwpsw5cHgxnUlSmafraM/VFUJKDJrPQDLf58wzQThZnjVWWDxFZGnzN2L2 lT4MN3IT/PfAfzb7+rD/A+hDrgaTdPo2wEkpa+8KaR1j9SrrhFqfEYWnhbWbAZb/QnTB4+ Ma5o+8/5U/l9B5TJ5WdgJi3blsV3K3o= Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5cda3e35b26so2566053a12.1 for ; Tue, 02 Jan 2024 14:01:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232906; x=1704837706; 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=g2cmoIK/tf9yPohv/YvO5QQvGunkgXtONjIGDQZEX58=; b=gDo1Z9hxmPZQ52z6J8OsH5X3YBtzIhblefHQHZM8S8wUxrSmZMIPv34oh0u6KGS8DP lFNyrAgyP2Uo1mGdjI7A06i87d5qocasTuZfdPeJxs7zhYgU0e0004be5dRcaz5w5Xl8 5xxYQi9EnStSZkOYi9E7rpT9LYEA9Tt+zEZIn7UGRxb8P6Dco56bZyuQ93uI8WmtuOm+ LcsDuxXL0t4zQLuBvwBdAOqqoDGEuMnuhkXBqzztsVSim7rTU+W1jtp1HfMZFEMVu5ft ebopNR8b7vW5CpOulj98p/HLHusp0FCYrTBFAA7w7V3gXBMqmomIknvltDxJq29X59R5 CD5g== 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=u7dVWo5Sbmb4/XpFcc0Rcg0X2FieC/NVqNeKWIlHp/67jhPOB9odWvul1qdJsReTO5 tuiX/VT/aEZ1bEQ8rG9dhgB/wDPFe1TRXUakElYJzC4O13Ucxad3RiqcP74w6gkKiSAS 3UWqjJGR09ee7DY4ZRxKS6C0HawVFOUekCtQ2nDiGWOKZmfn2nXvp1euLiuIp7O4W0eC ulIoBVyLnupFxVs/LJDhfY9TmZKGJpBUZYe4fg2IXZepNqnKGb0DCwVf31rZjKCGoy56 b+Z9GK4AbDnSX83dOw3I5pH3K1YpBnsaaq51PTwgf6B6VNzkJqbViDtRl7uhDiahM2s9 n1gA== X-Gm-Message-State: AOJu0YxYyfNIG98annoEkJieIxcAllcldZokwUzR3VIkdlYYQ+d6TQ2B sA/XL6OrcgLgDqHdSBFShjq3xXR6fu8Sfw== X-Google-Smtp-Source: AGHT+IG8w/0THQ/uqOPivBsiw22hWysSlz1giatwLj9QOMmwVtysp2KaHolkndd/R0ziY6DtdT9KEQ== 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> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 7AAD6C000E X-Stat-Signature: ud9iptpm3a1548t6pd9z37twwe1tm8wp X-Rspam-User: X-HE-Tag: 1704232907-206414 X-HE-Meta: U2FsdGVkX18tjH2uXQk6FXEjmzHd1qLs9pf6nXuWJoXixeXC3JG5+G9cAdx5HFmB2163f7fU+Q+8uYeIHxqFVkK1+G/Z7OrskXnao1IMz/nSpk0X2mESCphBQhzFBZjwwhAIsaGLHmV1PmZmn2QcPdys/Q9ZT7U3HAzGYeFGsU7jPPld5xfOJKEFq1N4yUk/2Cm5c2EVOpFrcs9tHXRo+9kzU/PqVkixqwuChjC26sfY4kAXB/WtYcifjtbbyv70hGsaB+0LGfszVa0nFwnUySyHQAufkTh+9y7Y8gX7PaMpY96n+z2OQw3tQb54jWzYmjL1cOBYLM/e/CjOoQ0qQy+mdbRwUyHTkvdIsQCjnnU+DmphYSqFXVlkiR2jIT67Ji7i+LXt3jP+2e/r59IIPbRapyfqLPsYjoiPJ0CS0sCzcBHFdM6aBzmzcu+b5qTwmzvxqkFDYi3iLDyHpGOkmzNQkzfdWbVf3mk9PiYWeOaBB9DW919yrG//O9c894d1hUlOnsfIW4TRixHb2BORb1X9mg2GzNw3Bz6DDQG1WMQrolIIxo8RQwf5EeYC1JtrbpCh2O/e0hB5hYzTeHmmaD0ma3CsEtyLqJV7AJaj/f/TqqU2AO8ngtWIU5/04BYuCg+hes+kZ13APZ+aSUYOg36Kvg0vBVk4SHkhEiRKpbUonqkYuhAHSzrWoVoPdEdAvepLnnw4cpAurc/PunEXf0KrJUuXjxdcnntpXZn1V3V4ro98HoGNX+HYD5d3A0TcHOaQU0cNyKkYz/WUdXYU9Bw386C6eDw9hwybJKCjCYHpF/aMB3toXTJYlZtJ5avHRuTNcnOW9pMO6UQGPBrB7LmQ5mbAVCO7xlvh1GqJPJOXk5CDdrl0rJE6xnzux7Bp/QBeB+0kmfh3RSHKvTtUUD9pnTT/kE771vZIZ3qHG4xvkmAJ8JSPPigDDVAFR1qosOmXdoaFeorKDZpoc90 OWNLzlGy HmrZd8tXNicfESg08RnVQaJgEee92+BjcMsnNzyIx9oCbvMgYpeo+gg3NMwTWEAdzGcEQ3ajNsN+p/WcnXt4zwz3W7hkACaCM2sCmETcET+YqCxNoQ40NKpzhnnsKxr5F9OSQgyAm+U2a22eQZRNG185mJeUNM0YD0CL1IPStmIcQDAcydo0Lw7AntNiKK8XEdWgzJa2PUkhki/XzbY024FbEkYGDc6WS+PBflGrgpLUwtyJNnUrfbqCQ9BTjZEuPAAuUpFkR6wk79Pm9HkhrlbWEub1TzKsot9MXjj3pmSfAz+6aLOH19JZlYj6vSKiUeq+4NPKiDeMNzh1BJOnOLdIVCEqJ4YOEez25flo9uT0T10ZDhWANKGo3MXExEc93vwgqwTqRckFacSs= 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. Signed-off-by: Samuel Holland Reviewed-by: Alexandre Ghiti --- (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)