From patchwork Thu Feb 29 23:21:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13577714 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 48996C54798 for ; Thu, 29 Feb 2024 23:22:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C093E6B00A1; Thu, 29 Feb 2024 18:22:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B932D6B00A3; Thu, 29 Feb 2024 18:22:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E5136B00A4; Thu, 29 Feb 2024 18:22:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 89CA36B00A1 for ; Thu, 29 Feb 2024 18:22:25 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 67D54A0146 for ; Thu, 29 Feb 2024 23:22:25 +0000 (UTC) X-FDA: 81846417450.30.41616D0 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by imf28.hostedemail.com (Postfix) with ESMTP id BABD6C000C for ; Thu, 29 Feb 2024 23:22:23 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=DN+10HOT; spf=pass (imf28.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709248943; 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=lukLV3IzObY+fmX3TTuFURPx1t0s+LwQl+LTSkieoBQ=; b=DH0RV7s8Aa46XmDVdX4AlUwpHlA/r4V/nOwAk1iGx4PWBoZa8DAHaJl7SptzZRf9Y1E9e4 1rbAt23d7GJWzjWS5ZsmB/tI+R1n7QlgiNooUHGRs+4jJY1UIJVlZwLCG2AkZTBz6l9dmV gzeNQ9IyVHH42gbL15rO0jgb0UcQfnY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709248943; a=rsa-sha256; cv=none; b=aMpzudyXErpQ/tIkWFgmZ8whzwkwOjx7P+eHjRA3CH4XTgnR9rsrznQvzsaL+i+Hmt6foR +Vfq1qCN+m3BwixS+stYIBDHot3wx8fDvNR5PRgc3Ho10BZMlGi9XcLDAVzVAfcr6z3kMW ZIdt37rl55lJKJ0o2zwxiIMKUKHmsmM= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=DN+10HOT; spf=pass (imf28.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.174 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-6e55731af5cso1202649b3a.0 for ; Thu, 29 Feb 2024 15:22:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709248943; x=1709853743; 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=lukLV3IzObY+fmX3TTuFURPx1t0s+LwQl+LTSkieoBQ=; b=DN+10HOTwGu2OuNbgU2ZpCm8FHUWGSrVSnBRLT359b7ust2Z4I/YpjvzDPd0Rul/Cl bZ3MY1+mVm88bC/X9sH3YgiXOl8xLh0+JP7N05UVDcAI7ReI/G6cOnTvH6rPZR+M0UHA 16/S/Nf0AW7FIqcjK6qBOFURZ3Z4CoiGpASsU6OJVGRdr5HsYt2a4GLEbbRLhD3NtEre VcLP4GlcFe0vKpeiYaKbwRRUSNLHQok48AYkO9jw0qtVhjLxA3x7klBzx5wSwQaKy0Eu Dfyg+CVoiFeseVdq3wU9qizEXdjPQqX39XEKN+NrImk8ekLaX48s3xB4B4i9qDf7WesL +RrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709248943; x=1709853743; 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=lukLV3IzObY+fmX3TTuFURPx1t0s+LwQl+LTSkieoBQ=; b=fEDspJBC4t8rnsviCGO+bjDK9/WgiAQZFF2Sy03xx/OBMtS1ri9uDl+6iqRM5ahsd8 xEuZxeuQIoWNpjRkOJZPOokIE1V9xkj7KR+wYPoGoHmOGaJ4vggI1pqIF6AzO0plOXda VrroPxkHzXbi8mr9a+TAnhPXPjjegZ0BzQdoDCAbh768mKviANzOoEXaODz93q5eReIb fZUGAFrGA/1AZiDnBcIeaje0E0Qh7m7ziEuaAI/N3tCiAfzPt2Bf8T+WJ3+XAGBDHad/ aHovtwD1IeJb9xTy0Q2n05zJ4jGTn/N0eCExSR2EK9Qe9BMeXgyZrwgzCVAiCBNqa2g0 nAjg== X-Forwarded-Encrypted: i=1; AJvYcCVwH7/AQxvstraD8eU3UUwgA0bYSLoBN3aRuUgSB2Xxlju4BtwwFYiEe4z2rim7B64sSBTvnihVymv0M9SL1coRoIA= X-Gm-Message-State: AOJu0Yw7hQxC7cWcf5VcG0n5jAr94hsf/WfZfMacMbcwB9ibKjU4uEoc iYlHMXc2iRfPt+GZu1o9pUhPdNONHxv9UBKIoiQcev8BOwGQnYzd4A47ywH9WLg= X-Google-Smtp-Source: AGHT+IFn2rYTQCqOuHVpuGhcF7BC7asS4ROedWcgIAd4N2h6ux4X4gjzLV3woCw85UyqGNmjtKX//g== X-Received: by 2002:a05:6a00:1955:b0:6e5:5116:2cb5 with SMTP id s21-20020a056a00195500b006e551162cb5mr172054pfk.15.1709248942678; Thu, 29 Feb 2024 15:22:22 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id c6-20020aa78806000000b006e55aa75d6csm1779719pfo.122.2024.02.29.15.22.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:22:22 -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 , Jisheng Zhang , Yunhui Cui , Samuel Holland Subject: [PATCH v5 09/13] riscv: mm: Introduce cntx2asid/cntx2version helper macros Date: Thu, 29 Feb 2024 15:21:50 -0800 Message-ID: <20240229232211.161961-10-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240229232211.161961-1-samuel.holland@sifive.com> References: <20240229232211.161961-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: BABD6C000C X-Rspam-User: X-Stat-Signature: 6p6n8ycyd5w8187mptykmzukcq885m5r X-Rspamd-Server: rspam03 X-HE-Tag: 1709248943-813832 X-HE-Meta: U2FsdGVkX1+sBS0xpF7j+HfM/QovCD2FOSDInTko2o+Uon2uGUwxHbGLD0p79vsJ/nqwGW54OtS1mpq8qjJsHs8bAC7kSOR7VlMYJTwcIAk+ypulL0X7ovyfQXhbMjUr7AtQXc+OlvVFDz7qPET4OTsBaX4ksbV48wtWWru8jqCz34dNQFB+iVJd3cVYVxkXhpt1Tis9E30jrTbrwpwi3wh/pos1PjmUt54+tXBTHetlTCyHz5Rj2ejnCHICSYmqMjw39cLeSpul6Ib0v/L7MbnXPtcZST4dnO0zopg3AgrLSx2xdB9nL0LoNfshMdfHO60jXc6lAozE2j2C4Q6ORrBVeO2OGJdtDpdsgrpTLBVHnBSSlgvHTXC3+GehM57sh/AImbRDMYnTlKETvPaBr2/vfs6zcL1Zy/g3KSl8sba0ptBIZZmJ2Rc37bShpjH/AHvozpKqVRehJ8c2oqTqBYrNmoVl9eevagQFNPybWa52amx2LTmIS+KgUGciuBNC8k/vboMbOa0uMcem2jZuHzUi213oJwioxMDQAOlmO8B15ZwtKIe8bcO3FONvov7hTsxU6FwpS+fpNgqQLBj1K1pgV7r9w8UpcG3rhb85z2vcO+2Pb/JMH1QxH90Mvin440jkt8ydHemzIvR3LyIEYBjs71kSxv2wiLwUJc9mm5EF5GiVSg6xXTEqHFrHq1vgIRmqChJxwjPcBeObpMQkrXLrQKfsIG6uM8R27OvmL9JUH7Tb4SpLW4bcAloCGWs0R4D1pe6JdS8WQ/scw6MXjwY/quC+g5A650ajQDopc0T97NSNtvsI0skW0htTeejbYskOdAwXGpLQugS+W3HTnRwhHGSS6vJ/5HMUvyDG/s+yC1kYL8x5sOkTOUUmjR2H9NrNqPqX+awDKkgfUhnRjCrx/iNk2xc/MBtGWdIBJ2w0+Ev1dJyFyLBSxvNfSQsR6Z5WOIUcygCkKNHRHcx 9BJVqzBU mpjc8M4bRpgGIAqZ4HGdFcTvr6OKPAo4hanIKrEaKSAeYJOzxMSbXZ5WU7qUuQR69MZjzV5Zb9M+if3QRCCnHNzj5Cv2hewDqgFHadFXLFyJd4Klk0HwaPsY9jA== 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: When using the ASID allocator, the MM context ID contains two values: the ASID in the lower bits, and the allocator version number in the remaining bits. Use macros to make this separation more obvious. Reviewed-by: Alexandre Ghiti Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/include/asm/mmu.h | 3 +++ arch/riscv/mm/context.c | 12 ++++++------ arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/mmu.h b/arch/riscv/include/asm/mmu.h index 355504b37f8e..a550fbf770be 100644 --- a/arch/riscv/include/asm/mmu.h +++ b/arch/riscv/include/asm/mmu.h @@ -26,6 +26,9 @@ typedef struct { #endif } mm_context_t; +#define cntx2asid(cntx) ((cntx) & asid_mask) +#define cntx2version(cntx) ((cntx) & ~asid_mask) + void __init create_pgd_mapping(pgd_t *pgdp, uintptr_t va, phys_addr_t pa, phys_addr_t sz, pgprot_t prot); #endif /* __ASSEMBLY__ */ diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c index ba8eb3944687..b562b3c44487 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -81,7 +81,7 @@ static void __flush_context(void) if (cntx == 0) cntx = per_cpu(reserved_context, i); - __set_bit(cntx & asid_mask, context_asid_map); + __set_bit(cntx2asid(cntx), context_asid_map); per_cpu(reserved_context, i) = cntx; } @@ -102,7 +102,7 @@ static unsigned long __new_context(struct mm_struct *mm) lockdep_assert_held(&context_lock); if (cntx != 0) { - unsigned long newcntx = ver | (cntx & asid_mask); + unsigned long newcntx = ver | cntx2asid(cntx); /* * If our current CONTEXT was active during a rollover, we @@ -115,7 +115,7 @@ static unsigned long __new_context(struct mm_struct *mm) * We had a valid CONTEXT in a previous life, so try to * re-use it if possible. */ - if (!__test_and_set_bit(cntx & asid_mask, context_asid_map)) + if (!__test_and_set_bit(cntx2asid(cntx), context_asid_map)) return newcntx; } @@ -168,7 +168,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu) */ old_active_cntx = atomic_long_read(&per_cpu(active_context, cpu)); if (old_active_cntx && - ((cntx & ~asid_mask) == atomic_long_read(¤t_version)) && + (cntx2version(cntx) == atomic_long_read(¤t_version)) && atomic_long_cmpxchg_relaxed(&per_cpu(active_context, cpu), old_active_cntx, cntx)) goto switch_mm_fast; @@ -177,7 +177,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu) /* Check that our ASID belongs to the current_version. */ cntx = atomic_long_read(&mm->context.id); - if ((cntx & ~asid_mask) != atomic_long_read(¤t_version)) { + if (cntx2version(cntx) != atomic_long_read(¤t_version)) { cntx = __new_context(mm); atomic_long_set(&mm->context.id, cntx); } @@ -191,7 +191,7 @@ static void set_mm_asid(struct mm_struct *mm, unsigned int cpu) switch_mm_fast: csr_write(CSR_SATP, virt_to_pfn(mm->pgd) | - ((cntx & asid_mask) << SATP_ASID_SHIFT) | + (cntx2asid(cntx) << SATP_ASID_SHIFT) | satp_mode); if (need_flush_tlb) diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 22870f213188..e194e14e5b2b 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -109,7 +109,7 @@ static void __flush_tlb_range(struct cpumask *cmask, unsigned long asid, static inline unsigned long get_mm_asid(struct mm_struct *mm) { return static_branch_unlikely(&use_asid_allocator) ? - atomic_long_read(&mm->context.id) & asid_mask : FLUSH_TLB_NO_ASID; + cntx2asid(atomic_long_read(&mm->context.id)) : FLUSH_TLB_NO_ASID; } void flush_tlb_mm(struct mm_struct *mm)