Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1983128rdh; Sat, 28 Oct 2023 16:14:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGMSJYzz+8oLjFFDdnjxGopNM7zFJ37LVyVCGMsOf6bE+/eiQ5px27UvZQCD/2IGTbPt54z X-Received: by 2002:a05:6870:1097:b0:1dd:4271:3a88 with SMTP id 23-20020a056870109700b001dd42713a88mr6393465oaq.58.1698534887997; Sat, 28 Oct 2023 16:14:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698534887; cv=none; d=google.com; s=arc-20160816; b=GwRVmfvq9/x8WHde5AtJySeg++5lgLtqjhYGvI+zb9gUYLKK/Inc8/QDXEh077WtuO 7l1BmeYt8o1V/8byrbKkJhoR2/tWD1XckLdCdICM3KiEmOHM2jNMtlJq/yPPRmLP8Tgq Xmvlq2rKcx5+YXlz7P24BBaE674b1QrIRrmvgkvCPwVQglyl//R3eqTvqdtfJhcq3reV kGKY4muhifQXQ0I/kkqhXK2s4pBWx871C2mS/D733tf7Qa0dO0/IkO/4RYEY8hjyfxHN DE82GpQ7POnnGWYitnJ+jb5l3N5tNSEfQ/T4vBnbz0hjYu3QQkB8higM90N/Nb0zqT8R sqwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; fh=9K4IlIICZaNW+K3e6o3g6KPBoLBMkIMAK+rlB58927I=; b=XipQRoyfLbv4hYVfkRFMdzsWqHdI486xZLVpoEPNEbpX/KYLlzOPWGvd/mydzO9sUI OLQuW36tUZkYqLwEKgCd26nbq0rBh4rbTXUZK9kiAmgQbdiajTuQrevUR90Y+TJLKabc 9XvPHmr5tq16F1fIZs77rSLMM49mYP3twUl+LkDtlbVAu2UpBz+yaaYniJt2oRRtf74c tOsBjmv0jlSvZCelVlXYa5Hbrl0OMa9A0IJSUjsHStndqeELd2LxEJOIE/eRb2jn0i4f 7BMRMp0N8KxqUi3h6L9YF7zqLahnrJoTg2zDHNiUkxPhGipHCO9m/MWOhboUDaRWQQU0 qkCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iHcRbx+m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id l128-20020a633e86000000b005b18ac47c0fsi2952785pga.532.2023.10.28.16.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:14:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=iHcRbx+m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 13F1E808E8ED; Sat, 28 Oct 2023 16:14:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230088AbjJ1XOI (ORCPT + 99 others); Sat, 28 Oct 2023 19:14:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42480 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230003AbjJ1XN6 (ORCPT ); Sat, 28 Oct 2023 19:13:58 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 692EEED for ; Sat, 28 Oct 2023 16:13:53 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6c4cbab83aaso2241624a34.1 for ; Sat, 28 Oct 2023 16:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698534832; x=1699139632; 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=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; b=iHcRbx+mh/is2zOiLO1C8565EhG3yX4UN8thHJRx9oleH6+7wXkj7cW0KEpxZregGH BJWAGCmSvyFf+2K/Q2VbBh8Gy3o6ln4PljiE+FPSM4p2mSDjc+iP1EvFd56h09x7KeHV MLcjs/pStT9tR6EJmp6mWJvFWx4e1qr5ji9/SilbgdvDHhvfgr9VczOjTgm5eCP4t72K oYzpZpS/IRCZyIVQvjvHcv35icPLcYm2V7EaztsrKz9S9afogzMO9tgVfLrNc4Ftjlmo IuhahHPfFAIytTAjOFx/uugbSsuP4fn68zFHM0PI2RXFBPdqpfW6PsTlsLxYq0oh0gWw wJTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698534832; x=1699139632; 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=nfPkHia9ku1mIe8MIuwK1ts/4i7vxeqzbyNHZF4YvJg=; b=e3zCOaSbtB9oQHhEi+pBGz5XQu/qtfKGVLrJYWN+geDetcrxKL9WNH+PEfxLWm8S8D 92pPr0eY0z+DwbKazIMCz9Is5UoxRGKzd1Ti42kGgyBomnR41vASjXrquMZO1REszbn5 sYYb5yqd4NjCwwcdYDC0dLfBMhqjEr66jHyuB7UWc3Qfs42nYPjov07RTli2rdmGIRV0 2WuOILfVyD6jNyqGxmwT6G0sYNhkFgOg7T2ySB/QSnlI+OPlKn8nh8Jk/FfdOvgnZ2y/ 649COM+l/WVjkPsfEkt9Dl7AwAR0BK3w42ijSiSysEl9wGefa0iLGaI4SbHHz0yKXH68 g82A== X-Gm-Message-State: AOJu0YznLrojlpQb1sXr3WeuXi/3t3uYBdO1pP+1EDVcDovS0kso/kpx 5Eufn1gTaDimjBgaU6ccNOLPDUpx4GZhrxsEtbc= X-Received: by 2002:a05:6830:1e30:b0:6bd:c7c3:aac2 with SMTP id t16-20020a0568301e3000b006bdc7c3aac2mr6567117otr.18.1698534832734; Sat, 28 Oct 2023 16:13:52 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id u17-20020a17090341d100b001b8622c1ad2sm3679345ple.130.2023.10.28.16.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:13:52 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , Alexandre Ghiti , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Samuel Holland Subject: [PATCH v2 08/11] riscv: mm: Use a fixed layout for the MM context ID Date: Sat, 28 Oct 2023 16:12:06 -0700 Message-ID: <20231028231339.3116618-9-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231028231339.3116618-1-samuel.holland@sifive.com> References: <20231028231339.3116618-1-samuel.holland@sifive.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Sat, 28 Oct 2023 16:14:42 -0700 (PDT) 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 --- (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 e529a643be17..62d780037169 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) -- 2.42.0