Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp371439rdb; Thu, 19 Oct 2023 07:02:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHtrN7l7BfJWH7TOea2EExkXK/CE6ognIDW4MzVhkb8qNOXsck9G+6igFODlt1u9WrC0P7w X-Received: by 2002:a17:903:32d0:b0:1c6:943:baca with SMTP id i16-20020a17090332d000b001c60943bacamr2302506plr.28.1697724151702; Thu, 19 Oct 2023 07:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697724151; cv=none; d=google.com; s=arc-20160816; b=0IvHasWD+wFknVMK50mr1VnOpgx7z7/nNth3dHAYXZUYbkAU2xbRQRYvwBjD/Mf02m SU7xS2ePVnyzlmokl7QENmy60ZyvTqfIUBWHiNuw4RY4teaGEA1lcs7mwDUEyeKeni95 oV5+sj3wDzqNfkQCSYDFnO+8OhuzDzCtct/Ne/mjSRKUodVM6AvanaPPxQK8WOscQ6le cbeJltgyM92dJig5eBZA+7qCewF//pTLS280oDatqZILuODmAmw3WLn1EMy+S//HtlXA c2mc3jKAhvC9QAf6yu10tJR1p1AWZmGIrvdv+R52+uh2LBgLXvi6U3J+UC3e+XqNfAn0 Q5kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=dYapP8IUUxaJFtFuPCmZusI+AtIHAeMa/0OE5NMEm0Y=; fh=WST3+wf7QGnYAda/rKC0Dxh+vkTvdze2M8sQdehbzOU=; b=RH2zYGOVoa+UYPKkZzGqRCZMXTSf5C2iwVBbIRi6QmzbAVMU3sgV940kriZhOLVNX2 jZvXANYQ9N7eIDQo37hkHp742abZ27sdCYjrA0r98ETqgF+20s/CCCNEqWscPCgiFLqK IpzKq1jkXHWTDOyauYSavEdQ1VldlhjSHLjKmMv8WFL9mv5gmwsNDaAo5SVTZmO7DcpI 3KBCCNN3iHK3PZVx6hetocSLFXesfbaX88IGcmiBVNQHAZMu75JekKWmr0cXjWXp4PLu s00LeApq1BvQUYeEx3ZXU4AxogG9UoODF58d6IgUHV4vWK/XZjngXTABhXpo7U+3f1sl jpOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hpIRfi1v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id k9-20020a170902c40900b001b81fe65fa3si2292644plk.569.2023.10.19.07.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=hpIRfi1v; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 3BAB9829F9B5; Thu, 19 Oct 2023 07:02:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345856AbjJSOCJ (ORCPT + 99 others); Thu, 19 Oct 2023 10:02:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235321AbjJSOCI (ORCPT ); Thu, 19 Oct 2023 10:02:08 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96C98130 for ; Thu, 19 Oct 2023 07:02:03 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-32da7ac5c4fso4113588f8f.1 for ; Thu, 19 Oct 2023 07:02:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1697724122; x=1698328922; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dYapP8IUUxaJFtFuPCmZusI+AtIHAeMa/0OE5NMEm0Y=; b=hpIRfi1vLAjLTlBYReNuIW6B6fkPZugPJCqCj9Y4qWrwQJE7dTeu6xpIfEdzsjmzMS AwEhEjV2fl2q6KCC9Ho+L/3ChJ83ExkkiDjJVSa0MoZHBuygDI1kJEocyfeQi0bkZ94w JBhfSZMwkmvarrng9Bj7ynFLddEE50YTYS/rs+Qv8ajTRs3c1sBPy1ubzFCFsWBe37mT hNx/fQsUWY8puxIX6xdkl8QZbzwNkC2atHXTukGvlVg5w6SFykIBWBcby3BKJyY/c7wE GwS08n3JDNZPXXzYQrWziVJIXWKOCdwBvEajiw4t7wkqDiz/0RmCLDK/F4kKs+UTS+xC 1AyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697724122; x=1698328922; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dYapP8IUUxaJFtFuPCmZusI+AtIHAeMa/0OE5NMEm0Y=; b=aJfcI/KdbewGFtcRlLuZZGCfnyRC6P0uuPUeQfQlNfnBdvxDZ6z2RMamTcSTs7NGK5 BRJn2j1r8f9bqrh3IgJfZTFnUHk4NA6KGuwQPFQ0HPpd16CPBrbJDSDGXH5tU81hCx8N YVff8Sxq2i3xhq8Fowb7mRWKfItziKoYRRnUvItCjdeX2MxPPJ/is1kZffEETKHW2YXu wNi73G4Ir27NI4L3rwxLTuR5YjE+hhKlYzkqWQ4URM5/zMES68uOg+pOESIh26H9qcTW vHi+rmALgAo4WxVo3iE1dJGJxWnqSQk82F6NDpvaRP8JnpIldTX7Oz8s/pCck14yPw7l xfCg== X-Gm-Message-State: AOJu0YyhJ1jrz8AE9LoH3GPDHCVKpBkP8DgU2kgj4CEXfHB3Fp0tSils VXQqmExtpt88aNs69Y/WBjM17w== X-Received: by 2002:a5d:4561:0:b0:32d:a827:d0fb with SMTP id a1-20020a5d4561000000b0032da827d0fbmr1817267wrc.27.1697724121113; Thu, 19 Oct 2023 07:02:01 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id b16-20020a056000055000b00326f5d0ce0asm4598711wrf.21.2023.10.19.07.01.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:02:00 -0700 (PDT) From: Alexandre Ghiti To: Will Deacon , "Aneesh Kumar K . V" , Andrew Morton , Nick Piggin , Peter Zijlstra , Mayuresh Chitale , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Lad Prabhakar Cc: Alexandre Ghiti Subject: [PATCH v5 0/4] riscv: tlb flush improvements Date: Thu, 19 Oct 2023 16:01:47 +0200 Message-Id: <20231019140151.21629-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Thu, 19 Oct 2023 07:02:27 -0700 (PDT) This series optimizes the tlb flushes on riscv which used to simply flush the whole tlb whatever the size of the range to flush or the size of the stride. Patch 3 introduces a threshold that is microarchitecture specific and will very likely be modified by vendors, not sure though which mechanism we'll use to do that (dt? alternatives? vendor initialization code?). Next steps would be to implement: - svinval extension as Mayuresh did here [1] - BATCHED_UNMAP_TLB_FLUSH (I'll wait for arm64 patchset to land) - MMU_GATHER_RCU_TABLE_FREE - MMU_GATHER_MERGE_VMAS Any other idea welcome. [1] https://lore.kernel.org/linux-riscv/20230623123849.1425805-1-mchitale@ventanamicro.com/ Changes in v5: - Fix commit message s/flush_tlb/tlb_flush thanks to Samuel - Simplify NAPOT mapping stride size handling, as suggested by Samuel - Add TB from Prabhakar - Add RB from Samuel - Remove TB/RB from patch 2 as it changed enough Changes in v4: - Correctly handle the stride size for a NAPOT hugepage, thanks to Aaron Durbin! - Fix flush_tlb_kernel_range() which passed a wrong argument to __flush_tlb_range() - Factorize code to handle asid/no asid flushes - Fix kernel flush bug where I used to pass 0 instead of x0, big thanks to Samuel for finding that! Changes in v3: - Add RB from Andrew, thanks! - Unwrap a few lines, as suggested by Andrew - Introduce defines for -1 constants used in tlbflush.c, as suggested by Andrew and Conor - Use huge_page_size() directly instead of using the shift, as suggested by Andrew - Remove misleading comments as suggested by Conor Changes in v2: - Make static tlb_flush_all_threshold, we'll figure out later how to override this value on a vendor basis, as suggested by Conor and Palmer - Fix nommu build, as reported by Conor Alexandre Ghiti (4): riscv: Improve tlb_flush() riscv: Improve flush_tlb_range() for hugetlb pages riscv: Make __flush_tlb_range() loop over pte instead of flushing the whole tlb riscv: Improve flush_tlb_kernel_range() arch/riscv/include/asm/sbi.h | 3 - arch/riscv/include/asm/tlb.h | 8 +- arch/riscv/include/asm/tlbflush.h | 15 ++- arch/riscv/kernel/sbi.c | 32 ++---- arch/riscv/mm/tlbflush.c | 184 +++++++++++++++++++----------- 5 files changed, 147 insertions(+), 95 deletions(-) -- 2.39.2