From patchwork Sat Oct 28 23:12:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13439612 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 6971AC4167B for ; Sat, 28 Oct 2023 23:13:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11B286B02CF; Sat, 28 Oct 2023 19:13:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 055FB6B02D3; Sat, 28 Oct 2023 19:13:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D76D56B02D7; Sat, 28 Oct 2023 19:13:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id C23C36B02CF for ; Sat, 28 Oct 2023 19:13:50 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 75F9A1A0463 for ; Sat, 28 Oct 2023 23:13:50 +0000 (UTC) X-FDA: 81396424620.18.4D7B078 Received: from mail-oa1-f45.google.com (mail-oa1-f45.google.com [209.85.160.45]) by imf21.hostedemail.com (Postfix) with ESMTP id 8608F1C000D for ; Sat, 28 Oct 2023 23:13:48 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=D0sCXu6U; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf21.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1698534828; 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=56YUmquglDtdI2AgsFp8Dfqen0eRNcOUaE781b7rud8=; b=HbUF9GZ+CrdEieOMHrVgtdyXbI1B6X2Q/WYc0nYVUgZ280VfdAEKzM6wqphuLoKFK3xKtT 8Q1RsrIr1HlRM9RHggX6L8ETCw0hKfY3CavcPUx5/GRmpNjCyn6TK1WnBWWXziW339LpHS Q76ad1A1PRv70IuExOvaClA7vZW+RBU= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=D0sCXu6U; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf21.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.160.45 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1698534828; a=rsa-sha256; cv=none; b=Aq+XNvpEIFIAgqqbrZFSAqsc5kxYBetUgooB61kwj08CHvps0dvyVjYZCF40UGRC6GhKh2 sPBrA9VSAzHnnHJXRGIpEBNMOMAmWsN/gHWvHkqv2Nn8A3BYcCMKluXOmu4818RWhobFK2 R1OxFdxWvlqjJ91m/aBZj0g6pUCh14Q= Received: by mail-oa1-f45.google.com with SMTP id 586e51a60fabf-1ea4a3d0a44so2219252fac.1 for ; Sat, 28 Oct 2023 16:13:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1698534827; x=1699139627; 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=56YUmquglDtdI2AgsFp8Dfqen0eRNcOUaE781b7rud8=; b=D0sCXu6UF0A7uqDY7XpqxCd1QBmW75goOAVDMnvOe5uGZcsZqD1fsm2X523YhVz3D3 4UD1tQGiwlvQ3R6dsnILwviCghwbHu53VMYQmi+eGxK3tBiCetQcjr/g75IKz+Zp6D+R 92//36ja4xc5qyT+tcfB4k4YIJqG02bNHGDkaocy4/NvGT4+056T5lQSopN8DacIU46e iSrdP4v6+cHxBieO4nPnPZVLEyaDQNC6bz6hqK9dq0RM7eT4va49Lr7O0Ma5cM/3sG2l kh1v8ye54eN0YQ4CIFx/VX5Up3KTnBogSgPCN0pYOfze9X61NwsFK8B5ZkxHFVjW2Qm6 R9lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698534827; x=1699139627; 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=56YUmquglDtdI2AgsFp8Dfqen0eRNcOUaE781b7rud8=; b=kfzauEjDBKFei0cEERQoYjHciEvUQCmgZJEfqcHXZPnMmAdZ94cUCA2X2c+eX0mKPH TjyGNpVqPZI/5hjynBTFkny3QlqtEBEy8OAOu2Wsas3S7KtiWCi5huK1z5A2yt6DIUc7 nGOBIyv9ZV1aaR/JSlIc1n0QGEesz581kpRNsIkp7TYCaFm6WFZ9BzNgZXFetwH0+tbz coXllNg6VSNYRHqyaxsroFkbYEyAFhoeJvPAvKoaayLUIOYhaIMzewmNKbCadH6WE/cX NvmFXQFb/+t/U54ysHU89aHsWEQcxeN5DuiaWMU9oAw9XEUdeJvnPqDfy/6/cLBcPojo eAow== X-Gm-Message-State: AOJu0YyTBpN9VDlCl+O/4CaI8V5AsxvMmFg0M4O0DBZTrNmLVE3nOemO mjzKW38eZ+OsJnezDs00dHzbMw== X-Google-Smtp-Source: AGHT+IGq5Mcxzf3tN07mJTIgv1Wxotaz2Uaine2ZZiRfV+MdLhpoDUKwMV8rRW6x4wnAP4zHnD4SGA== X-Received: by 2002:a05:6358:903:b0:168:dc03:5b90 with SMTP id r3-20020a056358090300b00168dc035b90mr9086199rwi.23.1698534827455; Sat, 28 Oct 2023 16:13:47 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id u17-20020a17090341d100b001b8622c1ad2sm3679345ple.130.2023.10.28.16.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 16:13:46 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , Alexandre Ghiti , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Andrew Jones , Lad Prabhakar , Samuel Holland Subject: [PATCH v2 04/11] riscv: Improve flush_tlb_kernel_range() Date: Sat, 28 Oct 2023 16:12:02 -0700 Message-ID: <20231028231339.3116618-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231028231339.3116618-1-samuel.holland@sifive.com> References: <20231028231339.3116618-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: pxz3173yp5xbfrgyecihf8ary6x7dfzs X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8608F1C000D X-HE-Tag: 1698534828-22245 X-HE-Meta: U2FsdGVkX1+SB/IG6IWcbeYzS90ajEr30rgyCj3/8yL9DISI2tZxS0zOsQ8bkyj1SA62NwH67SlhDp/0y9sAqzj/YGAEPbM8ER0YcI6NgKdokqWcP5N14+U8iFuLP4tg3G6KnR6jLhGdTvKGu24zkBICEVczUC057rVmOktDnPazhnWmcbSyGFU5KuilWJwsJX85ERrAupsmikGNMZUEL7a3sbTRUi+JDwdJYDFcuwL2xkkGAPX+MmpjhXs2bGtAw5JUE/G2HkibDzplMzwU2NcGLvrvJkkKyjaD6meAZuH12PpYjoA3yIEfpQ4MA0t+8PkzHNb2Tp4bTdNkpXu6LHngmVkBjKfcAyVG5Ryb4tYufJAFoTWA/XJSgCzUz+s9hj9KbHN52KcRiUsJ53D9upISA8y2yxH7ndCVJ3Sq5VHl5k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9ywoskh0slDeU3NbSCw0tcImExGi9uMGQaXfk/EDNMmqL8egG2PWC/8sgjk/uM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Alexandre Ghiti This function used to simply flush the whole tlb of all harts, be more subtile and try to only flush the range. The problem is that we can only use PAGE_SIZE as stride since we don't know the size of the underlying mapping and then this function will be improved only if the size of the region to flush is < threshold * PAGE_SIZE. Signed-off-by: Alexandre Ghiti Reviewed-by: Andrew Jones Tested-by: Lad Prabhakar # On RZ/Five SMARC [Samuel: Use cpu_online_mask and merge if statements] Signed-off-by: Samuel Holland --- Changes in v2: - Rebase on Alexandre's "riscv: tlb flush improvements" series v5 arch/riscv/include/asm/tlbflush.h | 11 +++++----- arch/riscv/mm/tlbflush.c | 34 ++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 170a49c531c6..8f3418c5f172 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -40,6 +40,7 @@ void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, void flush_tlb_page(struct vm_area_struct *vma, unsigned long addr); void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); +void flush_tlb_kernel_range(unsigned long start, unsigned long end); #ifdef CONFIG_TRANSPARENT_HUGEPAGE #define __HAVE_ARCH_FLUSH_PMD_TLB_RANGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, @@ -56,15 +57,15 @@ static inline void flush_tlb_range(struct vm_area_struct *vma, local_flush_tlb_all(); } -#define flush_tlb_mm(mm) flush_tlb_all() -#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() -#endif /* !CONFIG_SMP || !CONFIG_MMU */ - /* Flush a range of kernel pages */ static inline void flush_tlb_kernel_range(unsigned long start, unsigned long end) { - flush_tlb_all(); + local_flush_tlb_all(); } +#define flush_tlb_mm(mm) flush_tlb_all() +#define flush_tlb_mm_range(mm, start, end, page_size) flush_tlb_all() +#endif /* !CONFIG_SMP || !CONFIG_MMU */ + #endif /* _ASM_RISCV_TLBFLUSH_H */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index e46fefc70927..e6659d7368b3 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -97,20 +97,27 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, unsigned long size, unsigned long stride) { struct flush_tlb_range_data ftd; - struct cpumask *cmask = mm_cpumask(mm); + const struct cpumask *cmask; unsigned long asid = FLUSH_TLB_NO_ASID; - unsigned int cpuid; bool broadcast; - if (cpumask_empty(cmask)) - return; + if (mm) { + unsigned int cpuid; + + cmask = mm_cpumask(mm); + if (cpumask_empty(cmask)) + return; - cpuid = get_cpu(); - /* check if the tlbflush needs to be sent to other CPUs */ - broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; + cpuid = get_cpu(); + /* check if the tlbflush needs to be sent to other CPUs */ + broadcast = cpumask_any_but(cmask, cpuid) < nr_cpu_ids; - if (static_branch_unlikely(&use_asid_allocator)) - asid = atomic_long_read(&mm->context.id) & asid_mask; + if (static_branch_unlikely(&use_asid_allocator)) + asid = atomic_long_read(&mm->context.id) & asid_mask; + } else { + cmask = cpu_online_mask; + broadcast = true; + } if (broadcast) { if (riscv_use_ipi_for_rfence()) { @@ -128,7 +135,8 @@ static void __flush_tlb_range(struct mm_struct *mm, unsigned long start, local_flush_tlb_range_asid(start, size, stride, asid); } - put_cpu(); + if (mm) + put_cpu(); } void flush_tlb_mm(struct mm_struct *mm) @@ -179,6 +187,12 @@ void flush_tlb_range(struct vm_area_struct *vma, unsigned long start, __flush_tlb_range(vma->vm_mm, start, end - start, stride_size); } + +void flush_tlb_kernel_range(unsigned long start, unsigned long end) +{ + __flush_tlb_range(NULL, start, end - start, PAGE_SIZE); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)