From patchwork Tue Jan 2 22:00:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13509538 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 64F6BC4707B for ; Tue, 2 Jan 2024 22:02:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 880AF6B02C9; Tue, 2 Jan 2024 17:01:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7945C6B02C5; Tue, 2 Jan 2024 17:01:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 635D76B02C7; Tue, 2 Jan 2024 17:01:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 4B5616B02C4 for ; Tue, 2 Jan 2024 17:01:51 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 2E266A1722 for ; Tue, 2 Jan 2024 22:01:51 +0000 (UTC) X-FDA: 81635744022.30.1E4FE82 Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf01.hostedemail.com (Postfix) with ESMTP id 5599940022 for ; Tue, 2 Jan 2024 22:01:49 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=ZqgLgv4V; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf01.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.216.54 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=1704232909; 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=MROdnZxFJAn7brM6ye/jIKPJcvVCbRqlgsjUSxtP0PY=; b=jXUJhn0ZmZFhI8Q37uUURytdt4qiwwSEplebsrwyOMDm3bXxxABKC/adXEG6EtiEifPftL rStoAVml7EWyGa4UPBUQw1vtvIbtAXd+mM8TrYgmYSN/IqxPTPIc2IpgUM1OzK2egla8EK VWBmxiDUKQyfIiQ4c1STn3pPYVgE6+o= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=ZqgLgv4V; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf01.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.216.54 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704232909; a=rsa-sha256; cv=none; b=WPRbcoWlYQPECI9Gck31h/g3E0UOV0tOqTHtRnxYeiTc/CatKFuRTU43bc7ozX8vI0Werb EmrZ8wLyYj5wd4kAvV3CxGEwyUuF5CAy6aM3hmyxaBHPfdjN/Xfmv11bfdu4VfoFWf7FLS o9+7kRuj6B7H9fVmWLWSGVznqWaCVHo= Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-28c0565df34so3429746a91.0 for ; Tue, 02 Jan 2024 14:01:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232908; x=1704837708; 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=MROdnZxFJAn7brM6ye/jIKPJcvVCbRqlgsjUSxtP0PY=; b=ZqgLgv4V2JFcgV8TWlh09ZTu04M2Gg9eRYenerjcs+ukkA0UF5OkxokoKFb2v9vLg5 44fzqQ9Smbomj9La0fTiRp35AhGILCNuiqLNQLoTUInO5u5BY0WgGIZ2/6AYr4cw3LrB esl3b1cs7oqExwZU3UpzS2TK5HCugO8qPZW0srxH8Ru65n2rpcj2Qq1GkYgXC+b0l4Nt qfaAITxkhegSrxPCCkQFhdIIcXkj1xeILLy42Ue85saihlUOXfQWPPZ2HgPA+9z8HO2p 50BwXOiuCi8/ap87ogBSBePJu1HZR5ONS2X2ThFFovO/ID2jPDIBCrO7ziqDE+s2LUJv zWng== 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=CpfTc+gDZmMw3wo6DgFsXOpuplATN4BB5cDbCFDLkDXA3AnuwIPOTgx/LERujguwJL J1fsXtJQ5IApt6X4BIczA3ng0WnTy+JsTMcYQTYsCz0zl2IRUirBlX1BOQfWuUj0WCwY NMvDG3esDMZdPsae/HOXyVPA1rBlSlHng1gOxhq5faaaynDA/yWU/rUH9qRsHnOoRbKV A4FZe6grni6HxeC6rJQ6TFVTGPwl49FsnEGBtW5z2ZQJ1ZR+qZNfM4agJ/AeL1kY0Z97 nWz42RbnttBHgCyx4cPMxqi0S1C99Qt1JJ4aog1x6ErgEduaJeXg+zvJ14QbfKPwB6Fn pY3Q== X-Gm-Message-State: AOJu0YxdoI9SCmF299B2W8Pxa/DLoxOpnCtRo9/iLKP8aPGB4PKDbQgT ae25lgtSfEcRAx3fb6egJxbP6eZJlDdAKiUBnCbiR8xZoYI= X-Google-Smtp-Source: AGHT+IFQ4MdRufOELZ2z13xg7yZ/1JoYbB5tE+2va7NZu/tN1uOevH1SKPh+nsWqBiMa4TjGPndiZg== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5599940022 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: g6upw8eudas6ft95ziaqxonmdy93ojmj X-HE-Tag: 1704232909-226413 X-HE-Meta: U2FsdGVkX18Lm90bzzV0MXPysp1vFQaWuv8J7a8EDsjGY/yXxQZ8eGvRUsmG3Hpz4KLqsHdFbLGqwrRQ3aueWTzxEnOxuAtj4ghl7ZxvXnb4udQupFMgJr5qepbiPqQaXniKJJMy1pFGcjOBc2Z4D7CpdbzWEsqC5CAqfMT7WLdI0AvaW+umWF7O4pHb774QAjiUspNhPx0BjKPL/lsnucA8F+DDoF0f+VUvE9agn8Zwz6IfMbZrTPfLYFVi3zH+yue5Xzd6iKZlF0/6aNKDh2iYoX2tv5AYaPkJLCZfGUTOuahlvOywat6dGXV5+y8iWr94uyzwbUHeRbcK7npBEo73HxFyJqd+2WX6Z79zvfN/t9ekeCf4Sp2iCbeQ5KW4edGKHbMl4d3cAxMZ0U6z0kBoDcohUgbyZyWDKLOh68uWxkRFp6PXqGrmiU75htaHLho31xMUuv6Y60Mu6FhKVyJl0XsgacWaeD7Ph7J5L2OboAOvllMvgTx/VaEUIbN0j2Mvd4JyxqaLBSGeDiB1OMOg/jroThkzyMntyCP0sa2xDEQTfJMMmHvDW15JcpLdfRHzSy4mbIjDrNhUOM6f6fkw0dXXMKM536UvS7/uYXOUSNdV78XmfXZHkXEVuf1EgJekSWjJIwOJ7DTyRsglW1BkRkzhtwJObvhe1u8OliNWr3VlEAgXJCw61vcLu3wS2lE6qq7bxSY0OxV/YXT0FUMp/INHM3qSiqBRc2UfhLgmgKfaEkZmovxuFvsi8+jZODFnV2cHmR3MIxo8grSvNI9xVAlWT2tUXrkQ2nW7uF1F/IRhV+rFF/o65qkpUXCnb85SMNcV+kMBB1Z6O+Kf265WkmhcO9nOPKZO7+VrfWAbS2u1Xg8GQgUpP02bQjm4ITyXlsDc2rYgw2YVv40ptoQ/9Bk2TVOg52q6GYwWJjsnU1J55d0w9keaEomUxw3f7aRlwTmNHAL+NaU8T8R mQOvDXSE 6IELSmtlhNfx0fXu1XGpzW0S72nLezO7MLlCfRP13DH/yuYY8BrLACqD4neNRS0HVglDxYKRU6N14BR6vBtUq+TFocMJg1L9IzI0+lS3KAmP7A+ySfJq20V8h/weaSJ3e6OUvgVPrbNRRndpLElKqGF1es9g/+k2bORoj380ES11U8HRt/a6gTOW7RrKd18TtPyrtrj5X53qMWlRwJGI1Jf80NRJK4Ey50ttLaOKfwRRwgpvXXWFt0usmxdG/xQoB45PDhI1mxVuZiu4ltN+dmlXZMeIi/Wx2BX44JEXHZrlB/Ot8ZUnnTfVXYhWdQwQO5v1YhO3rP4crteJJtwE6OOPMl7mBVQOKiHD268Z+AOsjdJGUwH8iPRGFvbEPVudxn6peaYgI5hpz66w= X-Bogosity: Ham, tests=bogofilter, spamicity=0.004345, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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 Reviewed-by: Alexandre Ghiti --- (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,