From patchwork Sat Oct 28 23:12:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13439618 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 70C41C00A5A for ; Sat, 28 Oct 2023 23:14:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B7F536B02E2; Sat, 28 Oct 2023 19:13:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B07FC6B02E3; Sat, 28 Oct 2023 19:13:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 930C26B02E5; Sat, 28 Oct 2023 19:13:58 -0400 (EDT) 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 7B4276B02E2 for ; Sat, 28 Oct 2023 19:13:58 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 57A0B1A0463 for ; Sat, 28 Oct 2023 23:13:58 +0000 (UTC) X-FDA: 81396424956.25.1CE7CE2 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) by imf15.hostedemail.com (Postfix) with ESMTP id 8566BA0004 for ; Sat, 28 Oct 2023 23:13:56 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=W8PfBv7m; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf15.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.43 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=1698534836; 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=fE3CAdf9uNR+8NXkOESdg+YzzJbVsHppNjOV2VSgArtgGdW5tji+NWGwB4gV80FptU/rey iFFMm/BXLfdosOnkPQ0VyC//3ByZhYsxZwvf/QPzwC4rpNcHeHR8uDoNzkTrvpk6FQiRYg adQeddKb4eEWi4NN0AoLQpARlADEQ6I= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=W8PfBv7m; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf15.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.161.43 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698534836; a=rsa-sha256; cv=none; b=Bu2MAMBGYLhIgI6iW+WeiXyWDZKeoJUUj5gpTjbQ+2RwTqnK7tg+fziQD1Z1s05Adc/ZlA rkB74HGYn2fvMs/2687tcTN3pH44j+lqMAWhP5HdNUnbDwrAWWRRF8Mxy1vvt/mqLh1lJZ MAFyaD3T82PWg9uuvVUKvjpv/RTSSzs= Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-581d4f9a2c5so2072595eaf.0 for ; Sat, 28 Oct 2023 16:13:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698534835; x=1699139635; 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=W8PfBv7m3Pyj6UHezWakpWQckBv3Yy/2TvsgAt/rCurKF1uchRqsa6rxb0Nw7qCp2k /DwdC62VVnBEft7X+T6f1Fm3vCd4vSiMVZZj0MXYRSWbA/ETXht/WJI0reREqnS+mOut ridwv2k4UJ99RmbyeimquwXznuFZZu35VPSPQ/2BrWDSg4MX5kPLPt20xaaF1I8QM0WM toHWuQlCyP1G7kkVhj5N4lUPXN80DzyfQqvl1BoDbqmWSPL0/uXpWhjlDehEWxA1/1Ct 3AALTw7MfDIGrxfZIt1NLLrTyXqid4CNrJVkR6o9D7lHmntYlX/OTKiuCwAruCla6Rsw AO3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698534835; x=1699139635; 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=G9xjXIhgrjCCohtHr1dHQsMpQ4X9qmPVLmJmEQhMRFNf2XXMY/3sfCiqHt6tB7Ozb6 fDgKF8QG2Kv/oRA8r3o9IgIFK+cunjQ/JPm2/DYfBFSiVRVaS9qj/SlRNRFJyUKDty+q UacpqZWEZx1Oj/ecuGeyHJN2MPmHEIqCgszFhsBgfQyhZp4ANOq+K5UblS+UR0dahuSz oFmJoN3wARM1St8cPDZo4gl6hdI1MewYPG3/Xu079fOhfm+a+JplU+BJ3qnFptrU7HZA K6+zlxbtn+BbpAB7DADBDjUlYx/3RR6o2trsIHzyp+3DlMjKa8XuXVuzRZSp8LkIYwC/ hU8w== X-Gm-Message-State: AOJu0YzGTgkQZcwb5oHvX1K+qmLbzhmzkFsbHi+YOdpLGIlLays+claP qJgjRaimBrQKyQTOoMlE3F9lq/yuEqIcqFfWJn0= X-Google-Smtp-Source: AGHT+IEpjr2TCXm5am55hbUBmsnjcw94CHvXcnlavbn7wyDrZYS6wclRzO1RWsfOFMjAji60OjxQDg== X-Received: by 2002:a05:6358:5e08:b0:168:d6cd:7b2e with SMTP id q8-20020a0563585e0800b00168d6cd7b2emr6151237rwn.29.1698534835540; Sat, 28 Oct 2023 16:13:55 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:13:54 -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 10/11] riscv: mm: Preserve global TLB entries when switching contexts Date: Sat, 28 Oct 2023 16:12:08 -0700 Message-ID: <20231028231339.3116618-11-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 X-Rspamd-Queue-Id: 8566BA0004 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: 3cbxa5q1akq7sibst41fdypsh7e5qoss X-HE-Tag: 1698534836-275808 X-HE-Meta: U2FsdGVkX1+tXPfsmJaiP+co1GAILUqQiwgRkVAQq/ICz9ClTvGnNVSLkltNezhj7J7+yaileav7q3ZbwRftC+2CF/lQNqY/bcHcEYEPhrPxLnpBbajcsKOhdCenolPyVkDlaDQpFTNEIv7P68gV08n29P+SUR4aPpeyfsRUulYAdW7El3sLLrbFVxTSd+KGuT9D4W1IXjO6mUFfwWTsYeY8MnzUyvUk+medEwy95X5xqAm37KH1HgxXqQfzKb6Pfy77nEWpHCLKr8ro0ymuGKXWeh4MjUuyZb/kyEz8KUB4wttZgyji7q0fxRHXgQkXJJs0WvgYEXaOAYJ1S+hsZGBBK+klzYZSONbc/9wDAEAqzB7uaWpqIGQWsYDK3CgvKiZ0GpfLJJ/mKyRqSjaB50J7m3COJ67A2KZT4kaksqQEJxACoBR7l0JrudsnNZhgcwXaMre51DU9IBsOvrxwgPau0iVAHeJRssy/msVpdcwoQG8kLiUlP9VnNm32baBJdOhubimD+Tfmh4uV85dM+Va4HE8vKjiEhGrbK3FcEQFuEUfBv2ZioznbR1dYX4K5WNKwnM0WD7CMoPW7fwIleuF+8sLKZc+snEOr+qi0bzY+34QsHppG5SkYHKQC/YXdrl4g8PecVDS8fw+oNqW3dFlpWRAYRIeokHelecNJ5BTyECI06XwqOB+r0qCJTLIwlWS+r+QhjT9B6yO/ccEllG3x9/YDmHXKCpSgEBnwZCsrGOL5iPKB4C0hv2YTCk+wAiph0sFL1Y0N2qLnFSGLg8CtSqPKkDSk/T6uv/tuiGITk5iooIef7nuJpcfUfc52zLsxChtCxyDc3ifmpwfgzV5a8+/QNgc++ih5u5JjRghXya8mvGRFrL/gwxPnrBp/bmVHM1MoGn1PGVouChVYGlILlvul6Ded5enwLGxXemLZ0PM0B2BO1YxvqGYIi56f4R6KyvDF4sX6a4TB0lW cKDguPzB 7wMfS/IUuAoRGsO6moHfXqaAT8ZdvWQofeqNXa24WvLzUnNEkUFl7wKMesaRfxbtO3EgvFRW18IFy+OF1XUAvAex8wjCn3GGFOejgzmwcnv1bZJxCj/K2wigjzbWGKA2XXewwcEtaIe//UNCSqiLwUh4tSbawX21ukJ3Rc0dOOCXCp7sYFEYJQfogtt10WMnk/lusUeRjRH2EzTQ7fA2LqnDiLokT7WmF8b3xsVVzyNounvMnBXWVYxHTG39dWv+uqGcNPB8RbuJKdDKMNkM72r/3CB4kViroPqZTWubmhJIYP0/9wnTIguKYSE5G5+Eaey0cBjaK1w3sz655jjLrqKjVcmcEnO2akNLcNd4oPSRvRo3rRloj0kVHslPaK2Pjz/CJ8jnVmt00KSk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.229746, 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 --- (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,