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: 13577717 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 F0A11C54E49 for ; Thu, 29 Feb 2024 23:22:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E66A940008; Thu, 29 Feb 2024 18:22:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96EB1940007; Thu, 29 Feb 2024 18:22:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E848940008; Thu, 29 Feb 2024 18:22:28 -0500 (EST) 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 6597C940007 for ; Thu, 29 Feb 2024 18:22:28 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 49339A150F for ; Thu, 29 Feb 2024 23:22:28 +0000 (UTC) X-FDA: 81846417576.09.DCE2790 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) by imf19.hostedemail.com (Postfix) with ESMTP id A05331A000B for ; Thu, 29 Feb 2024 23:22:26 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b="eHG5bwA/"; spf=pass (imf19.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709248946; 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=xKA9g+j/ocbn1C/5HG9gh/SWijsALu7iPj3AmeT0yjNIieO3Eyabt6FxjMLfknqvZmGjAj 4iLYuLyBTtZoVmAyX7d/bdwE99MmVfvSjlBj9eM99xYqmGW9TUilUhPAy+AFWMbOBllRgl LsbLDFtV9DYqVELVkDi2lIX/5CxaEZE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709248946; a=rsa-sha256; cv=none; b=hE5BHxrBtTOhaiRIpd0Gl/D+vvR01FnZhIXKLHM8bsf4Plo1xKFseT5NPhFWa53+EfkIrr UuMouVAN3l9mPZiQ2T3qCQUap1VqRlpwNwKgEvFLtPDINmbMyRy4cgUXen+6I5ae0Svufm uCjzmpaGXJVlI5YcSkG/1RHr8wPa1rQ= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b="eHG5bwA/"; spf=pass (imf19.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.167.176 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3c19b79535aso860192b6e.0 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=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=eHG5bwA//EH8wWzWFmsKFQa7ELWJTngh7Qftet0lVFrGghHhW1kOLWmkUJz0XVI50E H8xpg4Hk6avyfCdqQZyMLPLHonhOsy+PIEusgMUK/cARUdDzt82WySsBKK6vOdzmIBDU nrdW/kv/d3AH5Dk8pds2zHY50VOdY9lhEQ60FFestma0eTM0ihEQtPrYGRWbuqo3B4ds 8bJBb1GE/Mxzq43FswtpY4l8SPnoKBj81aA6CAJF58yBgFVIZrkB4+OMoainyLrpD1Mv 0ghShYhSQ1SvLWpMHEpvYYNAqMZ1ecJJ6QEnFFo6v3/whT3UAe6Ga8KnNofgrOIEVR8K DMWw== 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=exh7V26OIfkm5ZkxSyNzipPD15kTETvOrvG2g1s/tfjd+lV2YPBHoJzj51DN2IVgcM GtmD8VuxjEwws8e7r2xdF95/5HVlaF3c/hFNhZSfpg9sMg3Pv+W6ju5O1xSK5UGhwCHF lk0g+gJiz0P/DtDPDyAj+wQKrEAZyBitBrLXmC3x7VSusKBDCNfeRhzDFQQe3xjUD1ts BGtMdO/N30mVzYY9lfuPgOzVKaG0CiodDQ7W18duNcVFAOxvfMHteGs40bY2YAL/Nhtj IP/+p+YtU1qsfxCriE3TtW1Wi9H/d/vJykLZIso3n7aZffVKZUqLvwO4z9xo9z2rY5dq zEcA== X-Forwarded-Encrypted: i=1; AJvYcCXnDcTIjI3Qu1vELa/1EC2wcMJn01Fwm8zdPmx93perhuW8VCBfcxgMvWh3gxrXCgOCovJA4N6H+vELXfQDFXn3tIo= X-Gm-Message-State: AOJu0Yx9HVOdaLkt+hZ9XVfUq2dj/3HPPSMr7ZUW5boNiv6dTjB0FndJ 74ly4vlAsoW6mnN/PhkakOTonJAz0Qar74owWbPptYhFbgYO5s4Tep/KMsrEguJB46zSUZvs8jv A X-Google-Smtp-Source: AGHT+IHmmt9lzZLUCIFAbm5GqyPJaePE9QFXJ4x/3NAo+fPZmowQvwtei5P759brqGkqtPXCOnb8SQ== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: A05331A000B X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: x5561prkgzppysaq7rwk9p6eu71z7brh X-HE-Tag: 1709248946-281202 X-HE-Meta: U2FsdGVkX19RaDRzoXhYqswiEsxaFN9oKVj0MbiVA6vn1Yd0xgrgWxc4S7VRKZVROnVU9fWSJmMfI+j05hUAI+TCWHrIvBfga+CYCknzc8r1/E4Nfvp0deVdc2poCUmIHdGukzFZ7abXynmlT8jpaZCtwkUMXhVm7nalGaRVrf+V1zYdyMjm7XQo1YT8WrfSssfnvR/hwqs8pi7GS8pUk7gOZHztztoXesqwjguGG7Dwl6MtEpNvqBgWNRlt5q64jHK3HF7a0OAssn/TNOdD9pPKn2KhSjtDD5Y8B52EuKBoIUAuG/BRmx8F0idh4gVpSVh7CdBS9CjACivSpFZnD0/nWJh4hWPkdjmKVbTpndwNzT7fEEuvtEjRZ6U0HLOu7mkiXAVPjSGZ7X/gc4kM3g/02oYqtYkdl2XGwiQkrBgAcnOMYQmQu94bpW0zoZpjQekIdNWj604OUI9D98q6VdFMpXeAdudmfdT07K+ggIG/isubzqs4yl+rEEJ9Rg/LCRhiqpeTuYIAzUrKwYbTiN6tSRovWtWcYQqJ95GQnH+x3ZOoG1sEyRKcJI1O5JorSxDTyvyW14uAjT7vBBuaOmBtKsSBvREtT+tS6v5QvryaoY4L+fY1iP9QYwE3ACsZa1fIFy9RlEmiutUXfscAN3sosKrWSf3rSMY0Qwkd8Gn2IA95iMx3jBz4ihOKfDcy1cG5HA8jK2ohGraW2aZj6cQp0rgN2auXqlvgXVLAHn3N7bx5dNU6rJxZdYuwmy5P8ix1sdF1CQDJdwC83JaWLaXEYLiBwZiy/6hqAOKF6xyPvEYbLL1vPGpeLxRjJ8zGzxizHuZjMHFofAb/NG5HIDwkedxpZ+riIxomC3E5qqXqHOOFBls7+k3nW282kC2n8I9fKFGoDUnXeUIi6SIALdPH8B7a8TXukokM7LnBXlYhau8kXG+PEyU/7/qPZWoHUse3pNiMwc9AaqTviLg EyWOSXsX 858OEcHWOb/sdK+a4I5ViYlVMJJdorNZMa1MnoyFDXCBHZxKlw0Aj6KWNz5CRHNq7ndjBdDZGSSrsFS9qY1oasDKRS7MlzYvf6aNDYfBfbhumSqQ= 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,