From patchwork Wed Mar 27 04:49: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: 13605553 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 0501EC54E67 for ; Wed, 27 Mar 2024 04:51:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BC8366B00A1; Wed, 27 Mar 2024 00:50:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B5B9E6B00A2; Wed, 27 Mar 2024 00:50:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9EEA46B00A3; Wed, 27 Mar 2024 00:50:58 -0400 (EDT) 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 8B7036B00A1 for ; Wed, 27 Mar 2024 00:50:58 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 6172316060C for ; Wed, 27 Mar 2024 04:50:58 +0000 (UTC) X-FDA: 81941594196.13.28303E5 Received: from mail-oo1-f45.google.com (mail-oo1-f45.google.com [209.85.161.45]) by imf21.hostedemail.com (Postfix) with ESMTP id AF7891C0005 for ; Wed, 27 Mar 2024 04:50:56 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=jr7zVYI5; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf21.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.45 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=1711515056; 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=2OOp6ZEyIwMU5OnG6xTEWcirae/pY2nPqfU9WqSousc=; b=5g0vo07QAkWxdj0NSZSWYFWowRPG5p4tYiQH15f76kNw5qdWA6lWQ1aT18ElqUn8AO7k7s WQ/GskhyUi+nO/szxi1woo1U8y8JXMt42frphmPuzFHtmx57x/hcsY6KGBK1DdkvA7Ddt9 EgmXy5FLcDhwopJWtGTOZetH4p7tHhY= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=jr7zVYI5; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf21.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.45 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711515056; a=rsa-sha256; cv=none; b=QZEkW1Nt4MzCUbqPLC0MekQB08MV2TEJYwMnIvdl6qcJK/88NMzL9E+lUqWYv+JuQD/fus in50yHH9uSJ4Hvapto4//4l4bonh1TNxt8j4e8n9qTxoXTFXdY6Cxf5gMknOM6MOXaUIMR zu3lMPsLCzIia2d4gDBhcB5ztJ31c30= Received: by mail-oo1-f45.google.com with SMTP id 006d021491bc7-5a5362ceb7bso1591026eaf.1 for ; Tue, 26 Mar 2024 21:50:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711515056; x=1712119856; 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=2OOp6ZEyIwMU5OnG6xTEWcirae/pY2nPqfU9WqSousc=; b=jr7zVYI5HWjs9uj/Fa3gE0Ldk1d5KOiB1ApFwyZ0snzq3GAJn6Z75DMiGuy9zio4FY k5JYU1mFRD6afLn2bhArFRHw5E9gp3R8ZbnN2DdLKwxvaeapJ1XT1FvXYcYd0F7jvbZm 5IBwJyT9PzB/pxGzevjdDOzkECzfCWi8SeQ6q3phkL7NiLFov4AJWt2tT6JelBlcILhT tsmXVtqyCKAOFsFJnUKcazNeM0CsF/fn71Ap1BsksUeEwB3wwckgZWcSqmBSW8czF+Wo GzR74obTxJCG9NzNPk/5hVRiG9kojjJ170F3eg4y4vMF4WfBV78A9/khBzstQsDJY5PX lfVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711515056; x=1712119856; 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=2OOp6ZEyIwMU5OnG6xTEWcirae/pY2nPqfU9WqSousc=; b=jVuHjk0tXFxbWW7F0f5ADZ7boqdfeQjHeiNa5lKSkYuRCTh11StGvbe0a3fRdnusJL SR0/rfu3Rjf4k/NINaihXbQdOkhT5Jv8DtPs1uGKhWaJ7sHyEeTZU8efuFHSKKp+nQay +JMKMDa1+l54PC0VnhWmQkvAm6hRqn1NEnWNTh4vawIGQKsKxaTI2c+qtZY+MAx2wuuL V2lZH4lrj9NcDCHcL550yAasdfOA3xcm3l2Kd+rrm7NOlOhT8/wyvYWfmtmCJGWxfVSh wLlqqeZrXlaxbmwrA1ebGM8tRq5jQqqRkr/MRwaL0GdYZJB5pci2RFrg13rJuvYz+zM6 k6fQ== X-Forwarded-Encrypted: i=1; AJvYcCX3x7YNcs0WkdglkH9TtPT/snfGwrjFhA0JbmfTWpCyxXJC4NOcajH65jsu3afZKPqWgA5sXWuXFgouZfuVvfxWgyA= X-Gm-Message-State: AOJu0YyxiApoceTUBdVmJV/4BNm1NPimWl4sFTOy+0ryUmCgnMVJ10gK Z6/XEXxnnRUj0ZsPyPxRdYlbL3yZoIhglC8Mty09l/NCA5K8tgjsneSnZQIxv/E= X-Google-Smtp-Source: AGHT+IH2eQoyDSJi6zqBjW5QAslrBjHf9N1FFSb9F+mmhA++Fk/xLCVtnw/qNQbwZOYB8ND1BkvynQ== X-Received: by 2002:a05:6358:7584:b0:17c:1e6c:14c0 with SMTP id x4-20020a056358758400b0017c1e6c14c0mr311341rwf.16.1711515055737; Tue, 26 Mar 2024 21:50:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 21:50:54 -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 09/13] riscv: mm: Introduce cntx2asid/cntx2version helper macros Date: Tue, 26 Mar 2024 21:49:50 -0700 Message-ID: <20240327045035.368512-10-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: AF7891C0005 X-Stat-Signature: uzeaprabyicz61eqor4emq3gb3tokcgz X-Rspam-User: X-HE-Tag: 1711515056-543734 X-HE-Meta: U2FsdGVkX1+wjtdyzthjAtbzNtmHNDI6ZbPK55EHuBPU5LF+/nYN/dTmO1IRwKw+CTxkkRcA0FInKm80a6a51xB1F7Kv8VcMHeyjdtYZK9uwVNytJPqux4NqUxVLMsMdL7C28YbTLx7vvEQx9NapeGX2Df7T0bEC0epu2tMcgTT4ZUOFVmVbpNAaU4Y4EwKmfHCoFVvWvlWGhAdcvOcfo7FYmj9Hu6gXTvbthLboB1sQoOYXLto8wY/j/wQ7KgYwdMR7Y//tW9nexcg6P9042FJVIhBy4opQmMyWIzqLlzFbBU9MUcwHZF8k4YeJSzCOv7gs7JKjeCi02o5i6/xMvgXNDCrpeX1oEMTrv0l4HMMQQf/0HdZdeUSIt4tfLOgKxFeUh7rDN+H2b8bGOnJvJjXh1QlMD+7zttMLpc7nIDFdgdxx88tvqG30jrGi8+M54WuCofHaeZpU5WK0VV3SyZ6AbQHNMUpmUEbl9dGhoMkXtXPg/GYVlFYtnb5d2l7tQ6Wc8WItDjDTlan29t5eZz+ICwagpI7WXc+4nVaR1KY70ntvUsK07T0xxB3DxhQZJdYUAt6el+POI/ebZMGfS+go2jCCOJplrPZXlVkeguGR97G03Mz7JZMIPk3NJjnC1y+4usfbvb4cRPWmT3kadr9Y1ctgp2aTd0IbiWch8gNgUeKSw5XoX4bR2+JLZG1uZvBRfwXDyecc7dhrI+v5YC8QCr2QxDoVA+bzR+E36Q6a44ibQ0xQSLITfMEyO31HstAok/7284PRiC/afuf/E6kzbFB/r/rzo2MEOe++njeKto7UN4cuBBA5MHzU4D+6XP6vPlEysfqGy6pCi+f1KvMaf/mU6MowiUbx3MNr9FuK14wdHYw77qbG8jHr7ydum1TXmmCo8vyAIGX187xBv5ye2wn1c7fPd4MR41KMqUoQNosQ3mzPMtVukUIRdnJTMLDUMCubSlz+wU31AC3 ap5gExl4 3fwTDUvm87naQV6KxezfJo1B9f5h5deMSVKOVoFDd7YC/MDDza9Gt4UEqvYISSNfC8JVB4r9yjHPYW1lkHPWJtr5+7YYm1X4Y5W0j+HQ6xoG41Q4= 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 18af7b5053af..35266dd9a9a2 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -110,7 +110,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)