Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6801003rdb; Tue, 2 Jan 2024 14:06:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IGB8WXX9vMkQZWhPC22iimQ8eEGU7YEh9TpNwCkT8WsuO4ZSDedW3UKmsx3xFWn3G7gAVIa X-Received: by 2002:a05:6512:1302:b0:50e:8107:1def with SMTP id x2-20020a056512130200b0050e81071defmr6318274lfu.122.1704233215939; Tue, 02 Jan 2024 14:06:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704233215; cv=none; d=google.com; s=arc-20160816; b=H4ViTaO6JFYbAsrIYVerm+0ABTJkHgOJqgLH9XWzyLBL4NMpNWR9Af/07Dc/7b7ht6 jcvbxMj75EP61Db2Og6gy2Qn4fDTlwqvOImKRa4h+LdH+SGyPFxWP8FVGRbn6JdONnr9 vhSsXTsNpWVxgddER2mxVgy8lYrqxYkEi7bbq8roBxpXx7yLmFgRDRAb4TFzjoXtMsSZ oR77EkVTBna5lakywIygMuzcTtLQppnOgOcdZ2KcLjzHlNCCF7NE0A/Llke1O99p4cc7 bJjoDRGZldh2Pzt8sG/lozR6aULIjAg4ygEsRLoqgDKUUALnhRsW57KIJB/NrJ/q1Iny j3PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=d7sRColwM16ZDpkHsKhbx/H1UjX1V2ZP/gk6hKZVk/k=; fh=dlotjpk72cYcmDz0+AxIEXTz48ooVBc8lhZ+ndNwuOg=; b=v0VYKV1cOYzZDJtjzQg2pq1mMnKpOxeQPHN2z3hxggqPBCkyeGDBnmkn6ODGsIPGbk xT3G/y1K58ThFFkRfNJuPKCeiAbTUETqR+vqIsc9yKb4pvWWnlFmywed4qdKVf/baB4g ztH3ynsnxNWMxmwHcHvuhBOxLnp+oZQFGeXQuKqOXx+ytpa4bXGYjW5o/ver2gT13gPT oLk2fh+whR7n0IndWNHNPZRfnCcpF4wYJDvE/twXIJJ9+Og/8rDrhmhMg+rLSNOoNV1S to/CblGMy/ObBcbHX0aFYoRqDcQweZ9z5WfD3y7acGwQaqzb5tOnrdZF+NOCot3CKdh9 Mi1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="bfZ/XZFv"; spf=pass (google.com: domain of linux-kernel+bounces-14918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v20-20020a50a454000000b0054cd1a2460asi11815005edb.672.2024.01.02.14.06.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:06:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="bfZ/XZFv"; spf=pass (google.com: domain of linux-kernel+bounces-14918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AB17A1F234AF for ; Tue, 2 Jan 2024 22:06:55 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1239318E1C; Tue, 2 Jan 2024 22:01:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="bfZ/XZFv" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E9E8619471 for ; Tue, 2 Jan 2024 22:01:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-5ce2170b716so4730641a12.1 for ; Tue, 02 Jan 2024 14:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232905; x=1704837705; darn=vger.kernel.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=d7sRColwM16ZDpkHsKhbx/H1UjX1V2ZP/gk6hKZVk/k=; b=bfZ/XZFvnuIlbRaPhiMl3TU27P/xztx2cS1Kj3kl7/uEFDQZZurqnQ7s5bw2wKOnts EnnRARcDRCwsp1t0lPh/w3kOVUQ4wm3Hx6w2VbuBDZLSO1tJqkqgm65OVRk3jsXb4J5K 3bp3foZ24OKfppgCAsSRyyj0zx1SMWtrD/sdH7EgHQdwKNgI+AKhKQDeL0lBLjBnALX8 05mhfIeLGkoP519SliEsfudgx3id0R2pYdMK8dumUCCU9u33jNZGrvKewxWtDJ6vx4Mt 9KI+Cy0mY9j6YvYVbRnNgty3tyzrf75iSVY6xQwb+4cbzVDAlWs9nh5890ZpAKZSIvSB Fx9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232905; x=1704837705; 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=d7sRColwM16ZDpkHsKhbx/H1UjX1V2ZP/gk6hKZVk/k=; b=GYHt4aHlJpW+vD6HieHAqP160JSB2b8xLci43pfadxe4Exd/2lxcVaIaoFei2kxqAO earJhVHLT8SVGYWzpytPjOPlAdk50o0QLI/EE91sV93SGHhUZKlUQ+3CVZ0WtPgPjnPI kTqw8t2SRxMLoJ4SFe3ichrk1qipcvOsOgUksQelpRH8xYTEEu3s2ebv0zvnr6c3zY9I mHJFpNuH6l7qQi1XHMeUTXNJ6qXi2PcdzbYuc2m51ViA/b3kYS8aOrAe8b15cvl4FSr2 ZXOrz1LbVZ5H3dp0f4swlEwCvJ7cmNYMDWPmoBjtksDNvJtdql80zISiUrK60IUmFSWT t4OA== X-Gm-Message-State: AOJu0YwHMJpX88ccFdCAwTO9ta2UntQQsaIisRTbZFwMcwc8EOw4NlTp LcLMyK+VQetkz2ZH5ShSo4flF+QvkfrT7ft940nhVjaDtoU= X-Received: by 2002:a05:6a20:a107:b0:197:2fc0:7e25 with SMTP id q7-20020a056a20a10700b001972fc07e25mr2866566pzk.3.1704232905452; Tue, 02 Jan 2024 14:01:45 -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.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:45 -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 08/12] riscv: mm: Introduce cntx2asid/cntx2version helper macros Date: Tue, 2 Jan 2024 14:00:45 -0800 Message-ID: <20240102220134.3229156-9-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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 217fd4de6134..43d005f63253 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 76b24d4ed4ab..5ec621545c69 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -85,7 +85,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, return; if (static_branch_unlikely(&use_asid_allocator)) - asid = atomic_long_read(&mm->context.id) & asid_mask; + asid = cntx2asid(atomic_long_read(&mm->context.id)); } else { cmask = cpu_online_mask; } -- 2.42.0