Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2740927rdh; Mon, 30 Oct 2023 06:31:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEkQ349kJVxMs1lxxen62MaGXi8rSvb/sPgpT8+m1pyArpXQPhH+XuRRe25JpUzn4WXhPdI X-Received: by 2002:a05:6a00:1307:b0:6bd:8c4a:ab8f with SMTP id j7-20020a056a00130700b006bd8c4aab8fmr8661342pfu.2.1698672707686; Mon, 30 Oct 2023 06:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698672707; cv=none; d=google.com; s=arc-20160816; b=C6L1vJu1xqeeZpbtenq/SAsIjJPvpCiJ7LkFtshjiwVebQlR97rP8LJ5h6eYlJe5pD E0j//CKmLFMqvO/rc+zzxtqHz615c9t3yC7nMsFMBEpBaxlJwA/l8j9QTP7zIPMDHde9 Z27RUHwkmgWdY0qMnYGJGjN4W+kmZLr+q9crVUpMg1FhjQkbraWcHWpDlxMf7MJKNmYd Q1Z7v018W6hWFXw55yCUtMp6429msYZoX3I+SvBKN7SuYXImCDxAZgYVQ7GdJDz4KeIN CZEq992W+4MWq5Ho9rSmIFbEHqiX2M9XkBhaOxFbbqfPxbomopUkrqBqhWD2gPSZT8gN UAKg== 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=cFAyygTf1wEzmKUuixPjgxrlB1EH/ZEG0d5M9D9G9l4=; fh=WST3+wf7QGnYAda/rKC0Dxh+vkTvdze2M8sQdehbzOU=; b=Do46usxzO9nmGTj7bQ0kDlVATPXpBpKCHIoh09G5X4LWD9Xal9xcAmczo4wi+XgJ3T 7Ndk9IbiPgJACKr/AzL9Ts129hsl+Q+Wevw8rN/mQMRICSYGisQMiifGFJNR5Nb3l4YL TeCRabtKXqMY9+m37Dp1v1G2lDpf/UBh+3qdeH5k5hfJctMl5ZGS1r0SUJCkJtFe0qek 2ZRepVqF0XxR3N2dCyBurTY6UJ52Xm4yUqVe4eR6fD560xHoT7N1vw1V3AaY2G6Tf0I2 ZL5hUcg4TEPQU2dXWJUkvdn0FkyQQPt3DACRQTsXjisc3yiHg60vOE+DZVH+kva4FK8i mOFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=bj6OJfEv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id a73-20020a63904c000000b005b91496019esi4962627pge.400.2023.10.30.06.31.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:31:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=bj6OJfEv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id AC0C7804C18B; Mon, 30 Oct 2023 06:31:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233464AbjJ3NbM (ORCPT + 99 others); Mon, 30 Oct 2023 09:31:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233472AbjJ3NbJ (ORCPT ); Mon, 30 Oct 2023 09:31:09 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D40A8D3 for ; Mon, 30 Oct 2023 06:31:03 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2c50cd16f3bso61703771fa.2 for ; Mon, 30 Oct 2023 06:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1698672662; x=1699277462; 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=cFAyygTf1wEzmKUuixPjgxrlB1EH/ZEG0d5M9D9G9l4=; b=bj6OJfEvoOiVZSPCRL+ZtsLck7sx0k4WqXSjA2LAlOmPleXECuhooyWN6SKRsZML6H fetwby11m4f9rNDijQP2rYLmceuWxtkaZBXGAlDfR91MjjYHU/1nCQ3Zr6Su1Vqu7606 zibNunm9X9cvuFVUEr9lmsc7S0UIoDEYApLO+r5yxV5OqpdOZn1j5USs+Pi1OrBWQphb ycXm2ZAAZmyk0gu0JAtaKV0781MzrsDqqGmfWpO1LczmQPVzl0VmJclCIsBpmeCthXeq yy6iel+Yn9Uf/twQcq0deYWdeHmC5DwfNV2/J+YQc44hpFLnnTJDbrB+0GdQ0Gwqot1R NBhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698672662; x=1699277462; 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=cFAyygTf1wEzmKUuixPjgxrlB1EH/ZEG0d5M9D9G9l4=; b=Y7xMKuHqoLzSZLsY5tdqE6GyJOOHQEOu6BdicIzPGfrc1VNugFknEQNsH0276NjAV9 x+aG3jybSkiTQlIiIlCqy2JTlKDFt/fZBowELcGFTlFCRE6cLh7MDJrw/gS5CGmgADaU RVa96pK2yCDolZPFtWN6QgqEaAKkX5Z1t7VaICGhht1C9GnRjDWVPxrhBowBEOq1a9gD TwRn+5lbtCYMC+u3q1RMMfbo61ASCsjYxyFkXF1mAQ7OnrFK2HfBmIV5Wk1MTc3esc8S 7Nw9cSXiIaSLnzHe9KGOdN9HPzRD3QYIl9ltRd2E7jzH7o7mbvAytmLwAtC3zafsjV2k Kf5Q== X-Gm-Message-State: AOJu0Yyp1Gi4skfm7r0eUp193/1/1lDSgUxxY6cABX3abH0O1bjQwtb6 RSJdNSYPt0PBANNFVg/Fhr9Yyw== X-Received: by 2002:a2e:a48d:0:b0:2c5:2357:c659 with SMTP id h13-20020a2ea48d000000b002c52357c659mr7665145lji.38.1698672661824; Mon, 30 Oct 2023 06:31: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 iv8-20020a05600c548800b003fefaf299b6sm9383887wmb.38.2023.10.30.06.31.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 06:31:01 -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 v6 0/4] riscv: tlb flush improvements Date: Mon, 30 Oct 2023 14:30:24 +0100 Message-Id: <20231030133027.19542-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 howler.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 (howler.vger.email [0.0.0.0]); Mon, 30 Oct 2023 06:31:44 -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 v6: - Remove ifdef SVNAPOT, as suggested by Samuel - Fix usage of u16 which could overflow, as noted by Samuel - Use cpu_online_mask, as suggested by Samuel - Move static_branch_unlikely(&use_asid_allocator) test, as suggested by Samuel - Add TB/RB from Prabhakar and Samuel, thanks guys! 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 | 181 +++++++++++++++++++----------- 5 files changed, 144 insertions(+), 95 deletions(-) -- 2.39.2