From mboxrd@z Thu Jan 1 00:00:00 1970 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 0C46CC47073 for ; Thu, 4 Jan 2024 12:55:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 808E26B0341; Thu, 4 Jan 2024 07:55:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B9156B0342; Thu, 4 Jan 2024 07:55:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6804F6B0343; Thu, 4 Jan 2024 07:55:54 -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 5484D6B0341 for ; Thu, 4 Jan 2024 07:55:54 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 22930A1E7C for ; Thu, 4 Jan 2024 12:55:54 +0000 (UTC) X-FDA: 81641625828.09.7918551 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf19.hostedemail.com (Postfix) with ESMTP id 679D31A0003 for ; Thu, 4 Jan 2024 12:55:52 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QXI6V434; dmarc=none; spf=pass (imf19.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1704372952; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=cjQDiWQhmYwu06q+jnykGxK4oKv3uADualUi+Y7oThw=; b=pAaFFBsxBSUBc3pCvQqXo3b3AvEPq71VLEj1z6soZRgx428PnwFw+QMCWkqJfq7H4QXODJ XgwEuEAWDizXIq+6JN9H1GeJl1MWfCMpsZfm+u6O0TCdva4p7qp48qwobPCc90zC9wnUN+ wneKrVNTzQC55N1L2sDx3/y5L5FjIAo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=QXI6V434; dmarc=none; spf=pass (imf19.hostedemail.com: domain of alexghiti@rivosinc.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=alexghiti@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704372952; a=rsa-sha256; cv=none; b=zKGPwgHDlkrC9sCtHDt0qLy3lSrNT72iIqZ5E9A+ozhDR0a3Ha9ZkxtKSpvLaQUV60AB2j 6ClXD7LdQNzvQRaAdO65dfzI0UGV66bjkmyRXwP48gU3l+Q+2nSkqz0kEec74mKP+/l9XV xFQ6cGEU/u0ulmDdreupmvjpMHsE05M= Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2cd1919f0acso6661911fa.0 for ; Thu, 04 Jan 2024 04:55:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1704372950; x=1704977750; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cjQDiWQhmYwu06q+jnykGxK4oKv3uADualUi+Y7oThw=; b=QXI6V434nICNh4ZEm6u8PLTpDHAA2XM4vEQS0c1PtJz5qRIX0Sf+yhiJMp7vfIRKfj KzeOLgKqOI0aClH1jNB6n67O6MAD8PJQl58oLjZqn3hmhmyu5QqEi/bFBXoAYPNOuUAV Q8RxGlm8esN6i1insaUhs+5bazKbAZu+mGxn2C2tKoVHLnt2S7YXIMbDNpgvwO3dASA5 aqHWqzYvPBbsy2JQ3Xg7TJ+BqtN1H2mzYECZpV4SDN7tQlwKDTwiC6CwxNz5PrU1xEtD kUWfNJg6VNyRaHXpu+RE4bOVrhxOelkPwm6xtoSrzUo7aCtdFLPEUggyroPXS4UOc4AV aGVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704372950; x=1704977750; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cjQDiWQhmYwu06q+jnykGxK4oKv3uADualUi+Y7oThw=; b=uDuPrmszGwhOrlM8nEzRqA5HW9axA/sWUk+52eAZsGc1iprloAGbJHevpVncAKL9GO AJOeW7Ye3Eezi2C1DfJiGixW6PyV3hBmOmrm0nqhWHQDBa6Fy00V+tMVe5iQyL1hezVj s1DQKaWA76699AFBjOU5FxPYb2NPH+UKviihgUghZz/iNWQrpnbe3YLd4w31cWJVTJe9 ohj+q38GxzvdTu4txZsPqSj3ZMn3VvAqXba1XRn/faprFNYe532rCn8w3zePLiJXHIHV Of03E3biLWs/kc0/AQteCiC31tSx6dt87dU9ji1l/6RHnzorKQS5pwKjnF8GMoZdTAeI mUJg== X-Gm-Message-State: AOJu0YwlJ79jLUBzSOsjV4jlrs/XOeGoDnFbxfaVDfwSP0WMBKcBuP4C qXIYxEBhzuPOFegEKcfgKM8hpQFiD8RfX6oMWHOPp4ulD/5NPSipLyHEFXkOmDA= X-Google-Smtp-Source: AGHT+IHNx4kxzc88ls5DeUmZEq3LCdQ7T5LlcjxcR56/jWxl2zztQ6IRlN2xiwuKaa1gM1Qx2n2k1SQVWMFXB48tpgc= X-Received: by 2002:a05:6512:3b07:b0:50e:378b:5187 with SMTP id f7-20020a0565123b0700b0050e378b5187mr480099lfv.41.1704372950594; Thu, 04 Jan 2024 04:55:50 -0800 (PST) MIME-Version: 1.0 References: <20240102220134.3229156-1-samuel.holland@sifive.com> <20240102220134.3229156-12-samuel.holland@sifive.com> In-Reply-To: <20240102220134.3229156-12-samuel.holland@sifive.com> From: Alexandre Ghiti Date: Thu, 4 Jan 2024 13:55:40 +0100 Message-ID: Subject: Re: [PATCH v4 11/12] riscv: mm: Preserve global TLB entries when switching contexts To: Samuel Holland Cc: Palmer Dabbelt , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 679D31A0003 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6cooen6z6fr4g9giptqwc1enry9kojnw X-HE-Tag: 1704372952-723745 X-HE-Meta: U2FsdGVkX19xL9GcY4uJ+zS/anSePeSPGGhKsvc9TmPlX+gRar81EGwjJxmEuYgFMjWs/8vbUc2U/DQNqoqxSWz48RjBsjs5gvB4dh/yEp6GV4D+B9gd6ZvgjvulMdAOVz4RpCW/tYj0aDs6lS1Hm0wMAzb1y0w3/LcRW2ZcxfdpeQsIcJp5oeyRCPZW27cZQjsAfln5NoelAVQqTbPIhB/nzSoBnA2YcIk9vVmr50Nnv8TXfk1/Y3lW7cYsHqp2es3yXhn8mu60ZFsrUi6j6vvcfARrGLro1SgB9GbKSkmaVoJqMLKJM6IgMM/eK9696c/PXK1gUkwRt/Gb0H0/Hqg1KcZZjKgY4y3rJmycGoEUTp/NFv58Aqqc2o2gBgqpme0fntl3IEdk7AGbEzujVQnsJln5pjyYALOFilVNT3+QWjHdWnmIBqrELPeqerYG8IEOsBQzgmOAmCQ15eXoWgtb+cv66v1ftR+JFPB3ZW8k9cqRDIbV28lbU5D/taYQFWE4lqh3rFmjUofK6s5ZN5IAqyw2dKpURK49SoJCQaO36FB3+CtQuk1WVNROsp5X9r5lgTl1JTrhM83HRTn2ml/9vB1bOoOnWUWWh1nRQ0TpuB9HY8jx4rLcFMzpW6ZOB//AE3zwSfNAt5aGAxszWfYH1YLRfE7thmJONQ314JxRUp1PLkbg+WjtDjjIDFyHMtQyhOA5ngfL+T7XgKvD0MzVhzsOJfrj37vJg36zpKH+Upq1ONWGQzxhWkxpb6UZxolXcMOXEkqfflgNmzGRw9YHVURF5/AHpge2d8+GESukIE5Xp6zHj5zEGAdD8xkhUisilY9+ONtJLKqxZMmxfoEYPPVkaKXY/TG7wQdk4Yyj6LgEI6I/v91kGWP+99wxkV3msCG9tpfTlGta/fXlMLG0MsM1B1Gu/sduEF1E1QoVSlKKBp4Dm7YbPWN3mnrTM5rR/p4yKC979Ry3xo2 u2dxBsfH cozzbDClhLAyi+x5ZFGntoscW4aY05mGEcSQu X-Bogosity: Ham, tests=bogofilter, spamicity=0.000020, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Jan 2, 2024 at 11:01=E2=80=AFPM Samuel Holland wrote: > > 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=3Dx0. 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, > -- > 2.42.0 > You can add: Reviewed-by: Alexandre Ghiti Thanks, Alex