From patchwork Wed Nov 22 01:07:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13463795 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 3E195C61D97 for ; Wed, 22 Nov 2023 01:08:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 189716B052E; Tue, 21 Nov 2023 20:08:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 13AAC6B052F; Tue, 21 Nov 2023 20:08:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECF3F6B0530; Tue, 21 Nov 2023 20:08:29 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id D630E6B052E for ; Tue, 21 Nov 2023 20:08:29 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id B2E9116040B for ; Wed, 22 Nov 2023 01:08:29 +0000 (UTC) X-FDA: 81483804738.20.DF107F1 Received: from mail-oi1-f174.google.com (mail-oi1-f174.google.com [209.85.167.174]) by imf07.hostedemail.com (Postfix) with ESMTP id DEAC240013 for ; Wed, 22 Nov 2023 01:08:27 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=mp0GnDnd; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf07.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.167.174 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=1700615308; 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=Wj2ICW1Fptg7hPvDVbuVBoYZZibiQ7SyAcM7RK2jyBY=; b=5fmO70WnmfWZuxw32ayQxvHmqv6fX5uFqnFmie3PKAeAvC7mRRz+B4KoldON9gQ3KwT561 hDxMISfz+xO9mJvNT2heql2O9T3yzTU43WLzOoVx9fxvbA4cRRt7UL/r24S4WHqWUfKIkp d6KiiK9WBtoh9sUDNfB5wjY4l0Xa6FE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=mp0GnDnd; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf07.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.167.174 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1700615308; a=rsa-sha256; cv=none; b=7tz12YGezNUhZQfrxnLtOQbpJkxyDne9B1yzhpaGJ2P4LKhuy+ycSFmb/tcG7lR59cBi6D tZJjN0p9jdBbbg4efREzV/nQyXbpI1O9wf8VvzWC/aTYp/r7NFJyVo0Xkx0LYFJiAY+tqF jyafKNFrhSbwSXuMfoJUAFFwmtIl4QY= Received: by mail-oi1-f174.google.com with SMTP id 5614622812f47-3b2f507c03cso3625798b6e.2 for ; Tue, 21 Nov 2023 17:08:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1700615307; x=1701220107; 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=Wj2ICW1Fptg7hPvDVbuVBoYZZibiQ7SyAcM7RK2jyBY=; b=mp0GnDndrzNR/NftyalIXOK3XrbX6bCD0G+PLEBLFr1n5RbI7Oe+V7pRKt+OiEvv5g EyGkVL2BUh24ORnUSjFcoUE8vjPIuY9IsetCLCb1jZt1Z3kLnPbNHY4dgp/SA/J6kYd3 6U1ZM4gEFqIhlXI6oQBJJDfLLMupDmHw8mMGgxo8LQ2XKj0lFjEDAfh6LEpsRLE2krk2 ByO+3ViuJHK1dPPl/SUPAvLQQs2p+iX/bfzGDlu9j8cUGYuLgBTNS85m5prOz+g4EvHY UPq+7ToHHrBpqdv+UUpyC5Bw2LprQ0zP9p0d2GwWf7lwkA9xbuEVq5Vk5oVQcqYQTZ3G PdGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700615307; x=1701220107; 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=Wj2ICW1Fptg7hPvDVbuVBoYZZibiQ7SyAcM7RK2jyBY=; b=USLs63Y+07M4pY8+Jm8921pKsKKAHU2ZdyHvb43xuFpaCGDPFHVjv+R3g7aPQum5DY /pMmJd8JJ4qHD0ASE/8LfrpU3qCA2bWqLUGvDJuWDbfIA27+bTwOKz/rLmkW9nGdvI0P LwYdbt+302bNcCY7Ta52w7kntcgWUhPa3gBjKhEBRBFO0wLnZaEDteqo64QNmWHALitr bLhLfb4NO3X22DYc+A5gazly+5gOD5Kf0aB/t0Uw752zQqpjxtPbcwxuDnvSwbPxnJd2 EY2b949TOa/igq95Pd+yJzrhOX2QAiN9e0qzMx1MCXlnUAanaK7daAtzMxNsDLbf9fuc Gb5g== X-Gm-Message-State: AOJu0YwFOFxtELmVX2+dKHNN5n4/3lHrOvga/1bCe9rsrOhi7De6WTKL CjhWva5Kl3aW4Bxu4xrC2jfcKg== X-Google-Smtp-Source: AGHT+IE4b2JAkpIlmqFLR7/QsgdBYQzfOQCASKlXtamU7cDqbXpB+e41Rju/TG/nF3J4VXpKvwiJIw== X-Received: by 2002:a05:6808:699:b0:3b7:673:8705 with SMTP id k25-20020a056808069900b003b706738705mr885196oig.18.1700615307054; Tue, 21 Nov 2023 17:08:27 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bn5-20020a056a00324500b006be047268d5sm8713961pfb.174.2023.11.21.17.08.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 17:08:26 -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 v3 8/8] riscv: mm: Always use ASID to flush MM contexts Date: Tue, 21 Nov 2023 17:07:19 -0800 Message-ID: <20231122010815.3545294-9-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231122010815.3545294-1-samuel.holland@sifive.com> References: <20231122010815.3545294-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DEAC240013 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: y4fpagfdnff7zfimd84eyo8fzn76t8ec X-HE-Tag: 1700615307-265292 X-HE-Meta: U2FsdGVkX18bR0BgzgSeUhDvjFVevAHt4YBSf5AyLf9MOG0RdyiRxJ4GydJr74ZOsY+9bzxx94q+eZHAQZvJcPflu124XZAiCuy7JEcn0mSpXUqGc8cTfiVOgp8vsjTCoRaLwjLlPN2uuiqm5doo7zOKs3q3k6AXWYfW39RYGyeTpI16VWNuQZHThhpH0jMo5LqlUnxwEhWWJmsFWDwVP3OVjdWDrqsl4F5vsRPxUXiCwrpJ/Q202f1akODic0EYvzTakaamB9hMgCr3qDIVHy+8o8jyodREFT8imv3tk5U6LSkJSl3xSpOxADJ8fcJdxsSH/RsS/nxvOyXStD59mccv2ex9sX84JZ3i9In4/XdYw6VuPjXK2d5gFpssoIx/EE9fxtg8MuQHBGbMvUydyDDjYBiFVdDyS/CnVcC97GZ5DzNGSqY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: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Even if multiple ASIDs are not supported, using the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. So it is always more efficient to use the single-ASID code path. Signed-off-by: Samuel Holland --- (no changes since v2) Changes in v2: - Update both copies of __flush_tlb_range() arch/riscv/include/asm/mmu_context.h | 2 -- arch/riscv/mm/context.c | 3 +-- arch/riscv/mm/tlbflush.c | 5 ++--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/riscv/include/asm/mmu_context.h b/arch/riscv/include/asm/mmu_context.h index 7030837adc1a..b0659413a080 100644 --- a/arch/riscv/include/asm/mmu_context.h +++ b/arch/riscv/include/asm/mmu_context.h @@ -33,8 +33,6 @@ static inline int init_new_context(struct task_struct *tsk, return 0; } -DECLARE_STATIC_KEY_FALSE(use_asid_allocator); - #include #endif /* _ASM_RISCV_MMU_CONTEXT_H */ diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c index 3ca9b653df7d..20057085ab8a 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -18,8 +18,7 @@ #ifdef CONFIG_MMU -DEFINE_STATIC_KEY_FALSE(use_asid_allocator); - +static DEFINE_STATIC_KEY_FALSE(use_asid_allocator); static unsigned long num_asids; static atomic_long_t current_version; diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index 23409d70440f..d6619be10341 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -90,8 +90,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, /* check if the tlbflush needs to be sent to other CPUs */ broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; - if (static_branch_unlikely(&use_asid_allocator)) - asid = cntx2asid(atomic_long_read(&mm->context.id)); + asid = cntx2asid(atomic_long_read(&mm->context.id)); } else { cmask = cpu_online_mask; broadcast = true; @@ -122,7 +121,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, { unsigned long asid = FLUSH_TLB_NO_ASID; - if (mm && static_branch_unlikely(&use_asid_allocator)) + if (mm) asid = cntx2asid(atomic_long_read(&mm->context.id)); local_flush_tlb_range_asid(start, size, stride, asid);