Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6804702rdb; Tue, 2 Jan 2024 14:15:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaq0RhnkvPRafnCcJaXaRf1cHgyVnvG5hO8PoBkhtBLJqm2cIjFSpjSaxwO7XawrW+nNPp X-Received: by 2002:a05:6358:91c:b0:175:4c7a:9dc4 with SMTP id r28-20020a056358091c00b001754c7a9dc4mr1678934rwi.50.1704233752787; Tue, 02 Jan 2024 14:15:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704233752; cv=none; d=google.com; s=arc-20160816; b=qZ3z8ALsbSExfqNNIkdCpA3okJqt8VEy4s8CdQoUs4lnlBFi+4noM2kEXy/tqOZRlG qlsdKXPd0GhWQ7vZfMvqG9W0X0BND1smTcny/61QuutWEV85RVFR/JfVeLN/fYSPj/Xy JlkD89tQG64H7nfN/UuSinOouoS8FaH1ayJjtJ/Q6RW8jLhq8tRuV8Vof7/suTwr70OD J6hl+gCAyppEZcmgoH2l3d8WF8yPNacxMdR2Xl9hJyHV9lWTImuFIMgGLfsLEm5qjU8v 0pJ9FrmsQh2B9lDOoO5Hfu+NeUKO6DM1/mjTIjWfmvehxE6JBWL6nTKs+TALEpUPG/1y qiaw== 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=MROdnZxFJAn7brM6ye/jIKPJcvVCbRqlgsjUSxtP0PY=; fh=dlotjpk72cYcmDz0+AxIEXTz48ooVBc8lhZ+ndNwuOg=; b=H+s6l04qYh/a4w1hea8IkdLxYk4K6Rnl6qCSJeSJcnLX1+Vk0iySCjpcQxCjuuMmOU VJIxSTJ5mw1/eVV6+oFZTvsvTwpZILSZmyvZ9Z4gtLDwNIoW1Rlij0ShEU3udneqkarR KMtw1gcu32pjMQemEX3DHJHxkcl7PD+UEC0XN4xG27owbYDLk06KdMIzRWRqNLlDuk6A 20C8CGQeOtulQaEoXvyuqySWnWOmOSoLuiv6VoGtoYUfX2DxFSASmVWEykBLMQJMT9mt M+UNXCsx9D/sFtDJBzFxEzOxuweXcIx9UcDxoXW4idBFIxqnhBVVgmWPjHzYjPo4qcXT EviA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=NX5xwfDX; spf=pass (google.com: domain of linux-kernel+bounces-14921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14921-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id c4-20020aa78c04000000b006d9b61a9bedsi14949726pfd.120.2024.01.02.14.15.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:15:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=NX5xwfDX; spf=pass (google.com: domain of linux-kernel+bounces-14921-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14921-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 763F0B2415A for ; Tue, 2 Jan 2024 22:07:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E22D81A27A; Tue, 2 Jan 2024 22:01:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="NX5xwfDX" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (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 D7DCF18B0D for ; Tue, 2 Jan 2024 22:01:48 +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-pj1-f52.google.com with SMTP id 98e67ed59e1d1-28ca63fd071so1666557a91.3 for ; Tue, 02 Jan 2024 14:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232908; x=1704837708; 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=MROdnZxFJAn7brM6ye/jIKPJcvVCbRqlgsjUSxtP0PY=; b=NX5xwfDXegsIZdZeD3oMwQwMHll3o+dryBRf6MwNR6F6IX4VNOGzcoupwUi0hInOhr h6sF53qbIWdDZj6Qgu4O+pdeZ+C9CECw8Y7lwEU4TONlqJ9Q8wa8OzdNURP/c/bf2QQc ro0tzJ7vCnxgAUvDgSgLW9K4RFISSOKH43jgvpkaFvYEEtN4TMa+QSZhoNyyTWW+sgc8 YNS5kZFkfxv2lcIiMzufz2EQ8x+nGWpgKxnoG87ULrnUExvhQiFHPka+bgs7NfgAkuLe bQe19ylYJbvD8Xl448n8aB/05Vt5ui5sGcmfLmpAonKKDwtmm37SxcSLb0u68c9NTOFx rVWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232908; x=1704837708; 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=MROdnZxFJAn7brM6ye/jIKPJcvVCbRqlgsjUSxtP0PY=; b=UFqMNXlOfX78Q7InhSbI15FSi2sm+mJwX/taC0GkxQbM/6aP6Luk1Qahjrx3lf/gjN iMZtGkeiFeyrb3rHzlzsbkYkXCBnhlAM+L+/i8GMr2/SDhM7WofFLxSilR/+ppoKo5EA wGDCJO76jeWKxdE/eRmi8RLrvb/j8zgYiltkFIHCg/DAEc5ZY5Mkjwm/nEkr5nNFztUR PdzJbSSVkuQP+FRwXP5rl2rLhizl2qxr2j6kJBslYmh2LRqnhT8tvhLliBEbIem75xfE ZvUe37x2Ic5j9F2DtxdqjW3MROZ+ORGrujKeAmmRa3iP6CWMiflPQEpDePC2Iv/vUn0g iNGA== X-Gm-Message-State: AOJu0YxOUlChG7ngwFnuj78SiRsgv46pNcq0Z+H4pVIa8552e+AVby6V tE9EAKHBb7LD00JnNaxcApNF3hvAC3N93g== X-Received: by 2002:a17:90a:5c82:b0:28c:2e1f:8bf2 with SMTP id r2-20020a17090a5c8200b0028c2e1f8bf2mr4930306pji.84.1704232908323; Tue, 02 Jan 2024 14:01:48 -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.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:48 -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 11/12] riscv: mm: Preserve global TLB entries when switching contexts Date: Tue, 2 Jan 2024 14:00:48 -0800 Message-ID: <20240102220134.3229156-12-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 If the CPU does not support multiple ASIDs, all MM contexts use ASID 0. In this case, it is still beneficial to flush the TLB by ASID, as the single-ASID variant of the sfence.vma instruction preserves TLB entries for global (kernel) pages. This optimization is recommended by the RISC-V privileged specification: If the implementation does not provide ASIDs, or software chooses to always use ASID 0, then after every satp write, software should execute SFENCE.VMA with rs1=x0. In the common case that no global translations have been modified, rs2 should be set to a register other than x0 but which contains the value zero, so that global translations are not flushed. It is not possible to apply this optimization when using the ASID allocator, because that code must flush the TLB for all ASIDs at once when incrementing the version number. Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/mm/context.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c index 43a8bc2d5af4..3ca9b653df7d 100644 --- a/arch/riscv/mm/context.c +++ b/arch/riscv/mm/context.c @@ -200,7 +200,7 @@ static void set_mm_noasid(struct mm_struct *mm) { /* Switch the page table and blindly nuke entire local TLB */ csr_write(CSR_SATP, virt_to_pfn(mm->pgd) | satp_mode); - local_flush_tlb_all(); + local_flush_tlb_all_asid(0); } static inline void set_mm(struct mm_struct *prev, -- 2.42.0