From patchwork Thu Oct 19 14:01:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Ghiti X-Patchwork-Id: 15624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2010:b0:403:3b70:6f57 with SMTP id fe16csp403495vqb; Thu, 19 Oct 2023 07:02:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGWdU5ijKefloQf85923SabodFf5L1/t3AQsFOFnC6wqlhNAuo5L1lGbX5iQV+f3bmayxxF X-Received: by 2002:a05:6a21:71c7:b0:16b:79b3:222b with SMTP id ay7-20020a056a2171c700b0016b79b3222bmr2049787pzc.34.1697724137522; Thu, 19 Oct 2023 07:02:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697724137; cv=none; d=google.com; s=arc-20160816; b=y75MvnsFHRdiMivXT0EycJj6kDe+8HQ20hrNFldGwQSctY2W5IkfRdhl3wDN95CK3s 5z7eiul0BjwcqKyHSAyar0Jg7xSg8aZExyGNsG/4fo4yFAp1Wv3sFUrx/LMsJ/1iESHI J4oGMWOxzc2jqXNkHl/KXT8ORIdG3I4UlXl+hBupQ52PnDeFlBfggI+HCJ8M0L2kIt01 PUh09Kw2mPqzeKnobKLKYRtsOLskO36SaiVTEJCIdnB2y+7MoWgpU5QqOZ2qC0xErBk6 oEB9QJpczYzOUh9K1IHe4lfiFIgP9uPLck6LJ9BY3I280cH6ZycTVrbt0y/lLPSgg9Fa UT7w== 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 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id az1-20020a056a02004100b00577f65baa3esi4545001pgb.775.2023.10.19.07.02.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 07:02:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 2E927831D2DF; Thu, 19 Oct 2023 07:02:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235386AbjJSOCJ (ORCPT + 25 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 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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 19 Oct 2023 07:02:15 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780192785473750833 X-GMAIL-MSGID: 1780192785473750833 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(-)