From patchwork Thu Feb 29 23:21: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: 208555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp741354dyb; Thu, 29 Feb 2024 15:25:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWm9zq0J+LHQTMFQuXESO4eVyklhXYNB04PuRK8OLtt1XrYCaiB9Gypmcx8gRTr0LGJYhydCF7V3Aef6YJxBpWRwsJC/w== X-Google-Smtp-Source: AGHT+IGU/CM7dCi1fu3+1nJC4kFbvRCnVZ8Z5WRojbm+Rv9a+kuRArRLNpcTDlCeLcSnlES5MhW6 X-Received: by 2002:a17:906:11ce:b0:a44:1fcf:9b9c with SMTP id o14-20020a17090611ce00b00a441fcf9b9cmr67667eja.51.1709249141950; Thu, 29 Feb 2024 15:25:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709249141; cv=pass; d=google.com; s=arc-20160816; b=Z+pPtK6phN/BUwu9q3erlue6+RYR0vyluCMo6kQ2z+GlnTYYMmCDAIx/92Mu9xtrhB nO493GZV2XITjuHiKevcbkzHVlpikdi7YAKzJ+huGTVwDK0s6HHH0yCAflV40FyflUWb iK1RRdXwTjsN4Sdox620HgeNzMwmT9stA7MEr7rb78n57d0VLhV+DyYLg7M0Oejm533v JWmzsbWEr1/iSSb+f4l9OwFmO1L0UI0vV+aXOIop5dvjrIyficPJMiCm+FTg6PAOQdnK cVrMn7R6JztDTcLF2kVEDkxZlMz5YtaRK392OC/eL7BLUxOZvoyk5xuPWYD1mD4CU/ha 5CgQ== ARC-Message-Signature: i=2; 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=hwpkv2OuO7YHUplKH98oFVfOa+CFbclxXNu0ysmduyU=; fh=kVMl8kfpA36Ro/3P2bM4CdBKxR/FbbKq3UwoDY1wFDQ=; b=DnW8ChsuBrUUtU7+JhJh5YuqpQCMFx7clzhFJWJbYxcqD/ar5zyxfb6uUy9+UTd9VB 2zdj4F6b3C199yuvncfivqjZ6ziznyFyihvwKejdlbTHddHZ5VucPzZOjmrGnwtAjBcu u9Jjp7TXwsv5wFGVq1fsw+xuUf2F7VdrQLOVVlli5Pik50Q3ofXtJ6xDVQ1C3aLGuvR6 lGpjxK5DOQ1eBXH0UNuYAh1OUiXZbB/t/dQ0U4G57+eQ4pBtWFQUVJU9fsEjlgeQwuBU l82ErcqpY+WKC+OhnpDe7wKaz/ovWBDMeGxEvGZ5Ni3bC4BA/W2tPU1iFCWOoVhvBmn6 Vkew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XSvn8kij; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-87684-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87684-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id gf9-20020a170906e20900b00a3f848dbca0si929478ejb.594.2024.02.29.15.25.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:25:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87684-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=XSvn8kij; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-87684-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87684-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 909EC1F23145 for ; Thu, 29 Feb 2024 23:25:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C761814BD78; Thu, 29 Feb 2024 23:22:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="XSvn8kij" Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 94168145668 for ; Thu, 29 Feb 2024 23:22:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709248948; cv=none; b=GpIUqyhwn9sJmdsEICsn57css4NLH71GWWKZ3+7Uns4HDkDzvCNRrwY+uJcDOrwyH4frePlmaZpyEXRoIkwTNEjkdW8ltOmUJWqaJve3Pu63XuGSUqse2ZvBRqAvRN6TrLl5HMDDBZL1A1p2UXo+izpaWW5WUvzwkzvD9QnvYok= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709248948; c=relaxed/simple; bh=MRE4XT0P9lLUUCp1Ujsa6SQk4prpBDb9nMVRKvQ6tEU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E4GAX3Xv+UI+98BgTuHZlqCVwwEnsm2gYONN4Xv2SfQbR+SejtyfS/lsvxpcBK9uJMORDX3H7Gm0NgIQXrL8ebwxxSa7AyLVn9ZDBS3nhroaLkcaYaTzApXJWD3/SDW6yYq2VcVBlklXI4xstQAWmtd7V2QvI45QRu/c8CFDTBg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=XSvn8kij; arc=none smtp.client-ip=209.85.167.170 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-oi1-f170.google.com with SMTP id 5614622812f47-3bb9b28acb4so1094686b6e.2 for ; Thu, 29 Feb 2024 15:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709248946; x=1709853746; 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=hwpkv2OuO7YHUplKH98oFVfOa+CFbclxXNu0ysmduyU=; b=XSvn8kijH43lMHYjQhBT0h1zp2LObu8ygYFKiDSr3mS/HXqIzckAiAmvpc+COu0a2e 3jOeUVSnSk+Onb1pHstwBjfqUS5KGf8RXtO6tAtJm6eaCHkXou/JQiWDojnRBlolaYHM kBUDXsvMVoJVYzEmE1oL5rZfj/ljFQ26OMJ1meUy3YBJ8i3hlPYk/OSLOkUHA5KGTZrU jbxkqEEbCl5g12LXsmxXoSIRe3rVDZFQSFjX0o0s0dTO28YG2KbXa7laBLDx5j4GGwn9 lK4IDJko3KLj3es+Gy7PODJy5cb4nvbV9LZxJ5ACeZHpQCJ4Y1SwtE00qMWrJT4JaNoG LPfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709248946; x=1709853746; 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=DRvGW7+TLapQHMFqVqMOK1dSanEk6P6tYCcCvhqciRup2ORjyzFt/inCea4qikuUOX Rey35XDu1R5AsX152gsfy+P4lzW9bIAcWdbPnDrwzenKqQrl4zzHfEAmOiex8DSHVkCt YWVxa130ohLvXktkz0oy2uLlPQBel5WebQxkQKlwAlerAV7opgjFbidGZVH6beG8M1U+ 4slINWcQScDEGlfBhfjOJivfDaNHfEXkT7LKE56feHiCoiNVwg3HvPDGstlMX3oykRbD XmZGSSIFT014P7r0nnsk429vS23OSuFgyOHH2m1SNQ9YM7j3xkTGxu0voYl0Ha080pjK tUVQ== X-Gm-Message-State: AOJu0YyPLL4gG6leb9aGuFLI4a76KCLB3ZvrLpUanB0cPLhOB2Ecssx+ C4tOi1U9Oty7EbrjYNZEudr5KI21ZTtRIdV7H0drvTpYqKtrWCApNp1qRW9yBNk= X-Received: by 2002:a05:6808:17a7:b0:3c1:af49:222b with SMTP id bg39-20020a05680817a700b003c1af49222bmr47209oib.37.1709248945851; Thu, 29 Feb 2024 15:22:25 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id c6-20020aa78806000000b006e55aa75d6csm1779719pfo.122.2024.02.29.15.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:22:25 -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 , Jisheng Zhang , Yunhui Cui , Samuel Holland Subject: [PATCH v5 12/13] riscv: mm: Preserve global TLB entries when switching contexts Date: Thu, 29 Feb 2024 15:21:53 -0800 Message-ID: <20240229232211.161961-13-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240229232211.161961-1-samuel.holland@sifive.com> References: <20240229232211.161961-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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792277628443863540 X-GMAIL-MSGID: 1792277628443863540 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,