From patchwork Wed Mar 27 04:49:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13605556 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 56721CD1287 for ; Wed, 27 Mar 2024 04:51:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 953E16B0087; Wed, 27 Mar 2024 00:51:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B6256B00A4; Wed, 27 Mar 2024 00:51:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70D1D6B00A5; Wed, 27 Mar 2024 00:51:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5E2F86B0087 for ; Wed, 27 Mar 2024 00:51:04 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2BB9AC0522 for ; Wed, 27 Mar 2024 04:51:04 +0000 (UTC) X-FDA: 81941594448.02.5DF5926 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf17.hostedemail.com (Postfix) with ESMTP id 4F7C440004 for ; Wed, 27 Mar 2024 04:51:02 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=J0lHBFYk; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf17.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711515062; a=rsa-sha256; cv=none; b=q80kLBBKpGaZREUSQAqGbpXKoo7p1k7zlkpKqpeaUOACN7pSYmLjDIJfh/vaqeFU+kO9/g sIP8iwGBrrnRGarn/JEy9/QY36MFsPxOcIBmNJi47wb5vnRBpJNiCM3jMckOaJ+nkcxQnp kb8cghIE3GYNe3ilsUooEQnoy410aWs= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=J0lHBFYk; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf17.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 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=1711515062; 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=hwpkv2OuO7YHUplKH98oFVfOa+CFbclxXNu0ysmduyU=; b=y4+yMeNMv+SKatmOY+cSW7uYezHcT6XehLlzoOMZSfSwXUEmtOdH7o+WcTw3ZaWy7qUm30 9ZjrHxjvE5sYNiLSIKzd6YbHdfc2ecjxpKtMAyQ+tXMRnYy3GItopavQMge7uqFVSarNWi gozK4xKlveubNq97+5c0LEWod5zFE2c= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e6ee9e3cffso363816b3a.1 for ; Tue, 26 Mar 2024 21:51:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711515061; x=1712119861; 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=hwpkv2OuO7YHUplKH98oFVfOa+CFbclxXNu0ysmduyU=; b=J0lHBFYkL1lhlgA7B593N45jwgsw2M6jhvq62k2Nfnyal8ywVjNRB1lIf685Ev2wa+ X3QR3+h0ytTeNHSvBQUX1ITyVu5R94P+0wkueDM4wdhT0iGUVG+Q2lXfALqB9aGM53Fd LSzzuoDnPiR0y29/6cjhxed5BplnsLq4+Kx8V/ifWbRGJ0VDcCFFin6/I3AlUN+nsfbk NM9FIyYh9KepKm3cxMuCfL++uMhJ298ocFlVzFZMUlu8k7n85GpH46OUQMJ3ckfyCtbC XzFop5lTdD/ByZqqIKEt8VlX1f5D80jXYSqkFAPyZNSe4FiCm0YIyEkpFMTjVHzm3/Pm hpgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711515061; x=1712119861; 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=hwpkv2OuO7YHUplKH98oFVfOa+CFbclxXNu0ysmduyU=; b=pW9ttMaJoWg1SNBXF6nGnLqyp1vbkWM7JOeUIVR7jiZRNRpnfmhAnEaJSMBiDiVp5h jP1t962briidBd3hmBIp95om3G87ukBSOL1/s8JGFETH/YwrVcZkWFgZ3j7Q/QpxaBRX odbwN1Zt4bT2OIEsPhJWA6X55h8vWrafwIbhdB/C6bAmRrYDY4Ojist9t9TMT8aXRU45 TnhiLOShNYzT3lXv9c91ZKI6yjJeOCWaj/l1bUdCFH002G1pHFopTVxADuxQDfjfDP6k NN+mYNik6vnhdeL6aciaH5iqH13ugkBcp1DogS0pm4HGYdux1bExdttdjC55/jBwsYFw 9i7A== X-Forwarded-Encrypted: i=1; AJvYcCUN/izBS49+J6AUIuZ7nt58bdCAtYzH/KCUoc8ZN7OVj1jJjN/sdvh1BwMYL05/NAxivGK96meVXHJdAMCjlLgayAg= X-Gm-Message-State: AOJu0YzL5ipSg5Vk/2ETsor5RPazaKliizoSGWXZVlE/CCxV8BmKpNmL 5eFqM/Q8c666safeDlQ5UvQb7ubaKDRGUTOsKOarGWlUuL2I4l/ysrJrDab2KkM= X-Google-Smtp-Source: AGHT+IFIatp35KNpgDUDmJycAxTP3nvYaAVXQURqJcQtx3/AD7qiy3AeB8dChiHf0CcNcubYBhb1CQ== X-Received: by 2002:a05:6a20:7345:b0:1a1:67c0:c751 with SMTP id v5-20020a056a20734500b001a167c0c751mr5157753pzc.17.1711515061281; Tue, 26 Mar 2024 21:51:01 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e31-20020a63501f000000b005e4666261besm8351500pgb.50.2024.03.26.21.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 21:51:00 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Jisheng Zhang , Yunhui Cui , Samuel Holland Subject: [PATCH v6 12/13] riscv: mm: Preserve global TLB entries when switching contexts Date: Tue, 26 Mar 2024 21:49:53 -0700 Message-ID: <20240327045035.368512-13-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327045035.368512-1-samuel.holland@sifive.com> References: <20240327045035.368512-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4F7C440004 X-Stat-Signature: mmn4pb9ww7muaiek3z1ahocc63s8uixh X-HE-Tag: 1711515062-191856 X-HE-Meta: U2FsdGVkX19DCgPlfj4yapVSHMKrOdxN2E+yolOl0GhWwp8ZLzMSP15fJ/bfso+asblKwAHqgay4Jm81+kXAABhrXRDXedfKpssY4Y10drjEBxXOIEKiJsYzCtrXaQkPrNmFOru9j5J5UF7wmfbKO3c9xf7fvEybkG3Xw82YuDF5OcJ1zyD0lnVTclbS+Y5kwdPQQTNiZgU9t8nTFm7nSTASDgDSrwJ9OpGpo5mmH/1sQscyRinjvwAViZy2za0AdQYXBr9vXFUJdH19VhK9MJyyg5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RJAWNfUARS+K1sHCv1ypQZ91r8MeFEoHu+KWzg4+lhS/wyL3siC/2/xM4znz4vymXttWDWEx7qC//HhJLekSFqGWSQzKP82b+FLRTPA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, 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. Reviewed-by: Alexandre Ghiti 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 0bf6d0070a14..60cb0b82240e 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,