From patchwork Tue Jan 2 22:00:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13509539 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 7C4E4C46CD2 for ; Tue, 2 Jan 2024 22:02:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80A736B02D1; Tue, 2 Jan 2024 17:01:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B9206B02D8; Tue, 2 Jan 2024 17:01:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 60C256B02D6; Tue, 2 Jan 2024 17:01:52 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4D1A66B02D1 for ; Tue, 2 Jan 2024 17:01:52 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 25F2A1A00DF for ; Tue, 2 Jan 2024 22:01:52 +0000 (UTC) X-FDA: 81635744064.12.BA23E92 Received: from mail-pj1-f53.google.com (mail-pj1-f53.google.com [209.85.216.53]) by imf15.hostedemail.com (Postfix) with ESMTP id 6A68CA0013 for ; Tue, 2 Jan 2024 22:01:50 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=DSACYx13; spf=pass (imf15.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.216.53 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=1704232910; 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=ntXY1BdgwMpYCVbC/qFvmg3dz3t/ZzKIeqKl93B+ekg=; b=Tl2UNHI7X9KV/Kd7/IwlWJjpd9FpCU5V8o9seO92qWlVGe8Hx3QQxmvjnjhKjfeS6eFDGt xVzX/oCzQqpNtFYSZpWTTM0Hgre6WRI0SBPt0IiTcPvBSHeqodWQ2Poi8iKl4FtFOTYckP w7MoQq4yDNc/8X9d8KfcRS7BGpeH4kM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704232910; a=rsa-sha256; cv=none; b=vx/Ijnr9Y/QYeystThQiDJGdJFYlVNvUegTbsIJRjAJpK/2l8pESj+Qku0djM20NXEOR83 b9gSblCPScsFLOquK8nuz2lZfJhHseAAQwaYZ+ylGmCvWgOd0eMzc63/MX1nhytxIufwfm OXBHM9hoSz4m3t0vdPyS5j7zx3ijJYA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=DSACYx13; spf=pass (imf15.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.216.53 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-pj1-f53.google.com with SMTP id 98e67ed59e1d1-28c2b8d6f2aso3491273a91.2 for ; Tue, 02 Jan 2024 14:01:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232909; x=1704837709; 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=ntXY1BdgwMpYCVbC/qFvmg3dz3t/ZzKIeqKl93B+ekg=; b=DSACYx13PPFLfxZGwB3A+3+kgMv6sksoUzr8Ot2sYCQ2xi8+II51TpxvaJmwTdECrm F3fvZQOtTd+6ONybY3Fgrehh6sZFkKr+LsqHBQrlMUXM1/5rtc1Wrqk446A9OgYo+yJU +Pba8qPnAaw1XpbC8rdyLhTWZtyVqtu+pBxDL+oM8Lktkd9VNg7K1cnN6trM6B2u2KVO Fu8NfBF5/QJ2cj6gZMVK4pgywkZNKX4nIzg1QYIEAEGGJfV7DT0gQuz+gwTjS8ky2Q4z zCtDO1fbnPi+PHz0zgUaXdt3OFm5y9uY0EcSJpNFe+xqEPI8vs+AJ5snD8/05JdeEvoB A+hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232909; x=1704837709; 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=ntXY1BdgwMpYCVbC/qFvmg3dz3t/ZzKIeqKl93B+ekg=; b=meATExgqpgoUKhjQK+sb/pn77e1TDA1SPoSOx05vVr6SGljn5zTBhzxe/6xzry78nm zv4CCYLztH9JMPuRq14D9qnV89wJJ91r6WrsFLZa887B5u5YvkWo5BvYXWWCLs7mzi60 FGx3182G3mkWViiMvKChs1smCOyIpqWVVGnqvzUn6sFejMBz3foRZ7Q/gpRZyYq3GoSL OJm9y6CV+lykLqJAJyHa0e1rVSB0HmfXNjEcQvtiaFX3O+Msd0jZYHRPAMkQJ5U/c5w7 7YP/zcO/2iT+UavcbEiLm4mOfQOHxYJ9BUpME3bCnVvhQoyAHPkuRyGjOVQglWlFqae7 qenA== X-Gm-Message-State: AOJu0YyKNgRLJaGBsp9QkYULlLBIhnSoYH7PFzK6RDpCtqLrnAAhJxJq NIMDsfqjDznkXyVrkgo8K695CXMjbGqaMPTNekQw2htNQ3M= X-Google-Smtp-Source: AGHT+IE6m2P6rWzQ+Gmcf0Ghh7A4crRVy8Bq5ePskuN3Kp4kY6ZC52OLPfUohVtqOdFfc+/yJvJ6pQ== X-Received: by 2002:a17:90a:bc46:b0:28b:31f5:9668 with SMTP id t6-20020a17090abc4600b0028b31f59668mr5241043pjv.30.1704232909372; Tue, 02 Jan 2024 14:01:49 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:49 -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 12/12] riscv: mm: Always use an ASID to flush mm contexts Date: Tue, 2 Jan 2024 14:00:49 -0800 Message-ID: <20240102220134.3229156-13-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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6A68CA0013 X-Rspam-User: X-Stat-Signature: ipyr5y96de4oaehrqj45e8wbjmnj41hu X-Rspamd-Server: rspam03 X-HE-Tag: 1704232910-477586 X-HE-Meta: U2FsdGVkX1+BfynnXJfBdd61b45WHXdYP5iiXeDQifrhu74qCkFs941xvnjaNsyBR7G23JB8d9U7oSVQ5iNFrBPmULWGUJc6EZAu5AnQqamWuj+Q4ap1yoMzLn1ybhWTrv192U3GgeloxmlaFUpyAwfYZF5eZXxiRB/0eUZdKoxC9cONlEe0qOWomDr6VPxF4RSTiH/JjvU9a6BKalz1ZAAmQHJcl6IHaGw4Rb2VReeDaGePCSQ576J/JBY3JLgKQoJx9kYIV6+fGX0fxp8fURIX+Ugq2Cg+0O4L9MnWKiWiLKW2Ru+sJMj4WRlfiv9pL9G0RQuQmHsxmu104+D3lJzRqB4Xo5T5hTlZqqsJbUN9TpytAUDKYZBSNP65MlrTZeLFZnH954Z6pjjD8DGK9NnicdhUNfXVLd9Gv9IeUoa3Y0F4Z2yXHL/MxXnrKGEBBN8eU19FB2dFjtRcDYnmOfjqnm0zsGYiEuYONyT616RROzMzH5Ufe02ziZ7Pzw8gY0mYpoLMbqv76tO3+3qOdq+ASQBX3hICqGY5ydd+a9ikHr9NKaCDkhAIQPxfwAiG4Y/9Lj8+kd5be/LgyCvXmQUuXgoM8Q95EPRmGjJFU0udSWEtdb/0gvaaLnr711dIoZqI/GwAPARm3Fdto54613B1lZS/ohqG8bsHGKuBlpVNZiJU4rlJJSQIMD/q/T3G5w5xL9+sL4CGQnUncCtwQAuB+kIROvqYFnT0F1I7DPAEMRbeXlwcnnconNZfI5Pvjr7vXuj8gkDajlGvLN/hE1dgs8QZFFnYyeVXsM3OD3eSyK91zABTdHWxw56974Jd3L9T6vMwEVPzvSl6B7lZtS3fuxMzrAKB5vvYhZa077yoPUgFzxAEPHZ/wAfBWy76sASQJQHNn63GDpR0Jpg/B5WBBvWVuWq5c5tJcoSb7EkUenyyX4NcpQZlQxRkPQFWC8df0A1cmpw/3ft2kFm QzNx6KnF E/3OhIsXIOYc3E4FLq865l0k12DJtoCT+0QX5okosJGunUsvspfCQl0RcfCy9dFDkxo6G0XNMQUgymZinEqVI0p4kwQyw3EBW7KMgPoaccubzLfg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000245, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: 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 Reviewed-by: Alexandre Ghiti --- Changes in v4: - There is now only one copy of __flush_tlb_range() 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 | 3 +-- 3 files changed, 2 insertions(+), 6 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 5ec621545c69..39d80f56d292 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -84,8 +84,7 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, if (cpumask_empty(cmask)) return; - 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; }