From patchwork Thu Feb 29 23:21:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13577711 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 8B12DC54E49 for ; Thu, 29 Feb 2024 23:22:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D1B116B009D; Thu, 29 Feb 2024 18:22:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CCA606B009F; Thu, 29 Feb 2024 18:22:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AF6CA6B00A0; Thu, 29 Feb 2024 18:22:22 -0500 (EST) 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 9C2BD6B009D for ; Thu, 29 Feb 2024 18:22:22 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 67BBEA0FFE for ; Thu, 29 Feb 2024 23:22:22 +0000 (UTC) X-FDA: 81846417324.30.9CB17EB Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf28.hostedemail.com (Postfix) with ESMTP id 8E0FEC001F for ; Thu, 29 Feb 2024 23:22:20 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=LKW2OZRk; spf=pass (imf28.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1709248940; 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=uLB9vlYe9JfwQMhDb14nNgv57tMyr8X6yVrB4e0zcQU=; b=FH8wN4mtRG6Tsl1L/A52wHLC+Eje7GFFE5h4Fr7qlgH7NIZ/Sgkb8MATfVJ9nyqso8gGNZ OwJZzGzGCNMg1YpMAN7Sd2VuQsMn5+IeDjvaTTzQWPdzu2erY4Bg3LW8iASA+HNvCFfxY5 rPJiHl5Nbi0cN+xgQoRNCP1In4KhgtE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1709248940; a=rsa-sha256; cv=none; b=03rz7K6WOB2MczT0GizJzU9nk+2csc5aRAFmrGyMZZ3aG0yWbvWlpZEJgymaxI5fRYqjHW rE1Ydbq4FxTUJPLHcnAS/VIR/AMDHerG6JQkiJOifrIgHwCs8OHMqtrn/SnMH7X9ZQVagt keM8DcX0zasFb1B/d18WcRa+7i6KyKE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=LKW2OZRk; spf=pass (imf28.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.178 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e09143c7bdso1080209b3a.3 for ; Thu, 29 Feb 2024 15:22:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1709248939; x=1709853739; 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=uLB9vlYe9JfwQMhDb14nNgv57tMyr8X6yVrB4e0zcQU=; b=LKW2OZRkis6HJlM5UJcSpn2IXN0HOz0Ml1DDsiY7HqBpzgK9fPj+LaUi+MuUKhkRPc /s1dDqU1sd6CRqntqN7nr2y5j2X69G3kkzmbsWOOIMdfrxiyONjlGS1P+4tpBbxZraQI HD1TJX3sr/iL7ZTY2cXAhjFx6VVWXcOINK7QugE3UxpJn9fRySKn7LYq/MUMIr3q0unF 1gC/uaEOVYhbXvoObxR/3EYliesWK+p+uhnnz4C/T4DsQwBTJ0hVJb7iyMbL6ty/YMxi xd3+k3Bwal9dl7DDqWWsTezqPJz4wBcAKqS+agYX4g25ogpj9WQ4GdoLWKvAkGRmLfK+ 2EUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709248939; x=1709853739; 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=uLB9vlYe9JfwQMhDb14nNgv57tMyr8X6yVrB4e0zcQU=; b=Ad4DlFfEKwMD2BGrg8TU5BC1ldo5xMAcq6g5Dr1gbiQgKvgM9nGckeN6/mdIRGe4kr Iw5MPv7K4emYUZpJRHlR+Zf0cFBKLgtU4b9FASCeKxtYDROiCO3d+18yMrw+T6ToCoyI s7EDx3nmlM3FPjP7v59yQyLD8It2RQKQ6F7GB1e6D+2ffftv1tamkcVvkoLpCSuk2uvi Mxf9ETLCre+/SBdKgI1kV211FyIerCjr/963bNJ/1NVXSdIGfmu1cjwn+7UAArYEBqzv 7aWBbvCP8sizXykdj6E+n8xyF4yrSBq/McAM3OFoUvrSpuSVlSf1Wc7wEws0hY2BH5bK yh6g== X-Forwarded-Encrypted: i=1; AJvYcCXIVq9Em6uLuI7CGpIj3UJ6eicWHHCKWW2NHGgu1fyJHabUF2qctf3IxIe2WTJtRgnrqBuXrdx2ZJw+VWfKmqRXz04= X-Gm-Message-State: AOJu0YyGg1o6mP2JkH2CHYrpac2Uenc82vpWaSQg+k/1UDDwVA2Wl2CC 5tLL0I5jkKKYV4uTADfYM9fdT0Bhih8sRhOmkXP51jCMeP8THoBJuUnDkwfygng= X-Google-Smtp-Source: AGHT+IFNMqThgNRh63sPPm1+a+RZC7oBqAsJKeQJ9ncYhwlwuRqR+WMAL4ZrZQk20TebpNdIS4mveg== X-Received: by 2002:a05:6a00:2354:b0:6e5:80a4:2ff2 with SMTP id j20-20020a056a00235400b006e580a42ff2mr152068pfj.30.1709248939492; Thu, 29 Feb 2024 15:22:19 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id c6-20020aa78806000000b006e55aa75d6csm1779719pfo.122.2024.02.29.15.22.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 15:22:19 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Jisheng Zhang , Yunhui Cui , Samuel Holland Subject: [PATCH v5 06/13] riscv: mm: Combine the SMP and UP TLB flush code Date: Thu, 29 Feb 2024 15:21:47 -0800 Message-ID: <20240229232211.161961-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240229232211.161961-1-samuel.holland@sifive.com> References: <20240229232211.161961-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 8E0FEC001F X-Rspam-User: X-Stat-Signature: 6ro5wn6j1aq8jmhn3krd6fto96uzgtoz X-Rspamd-Server: rspam03 X-HE-Tag: 1709248940-6694 X-HE-Meta: U2FsdGVkX18eEbA9bQ8yb3VOQvpC3st/2InCpjwKpxRiRBlY8WLrHrf1A2sqGifxaD5YlbKducgNAYZKK12ZA89uW70gaeehFoT+BOFzWOku0HrB0/6RBRztZEY1bS8SiysO/MgHH8qKwbebc+/x9MVCjYkPK7WJeI2PcxGdyjx3S3SBVfC4dx2fqFFSLZHyPzOqONzdvqKPFpQhdlrCT1/GagZOavLhUaSTDVOsTiZ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uSNVzZSqdra70yAzqgBKE0pR4YCbe7eAoFzTs62Kc82yTx1u5WFEq146pYZn+GTTq3bPvVjyEJzr15HcmUdBaLbpYPThr3uEiP+QeZftywldLZd9RBhaMTcyml6J5trK3XFUk2O0ED6UI= 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: In SMP configurations, all TLB flushing narrower than flush_tlb_all() goes through __flush_tlb_range(). Do the same in UP configurations. This allows UP configurations to take advantage of recent improvements to the code in tlbflush.c, such as support for huge pages and flushing multiple-page ranges. Reviewed-by: Alexandre Ghiti Signed-off-by: Samuel Holland --- (no changes since v4) Changes in v4: - Merge the two copies of __flush_tlb_range() and rely on the compiler to optimize out the broadcast path (both clang and gcc do this) - Merge the two copies of flush_tlb_all() and rely on constant folding Changes in v2: - Move the SMP/UP merge earlier in the series to avoid build issues - Make a copy of __flush_tlb_range() instead of adding ifdefs inside - local_flush_tlb_all() is the only function used on !MMU (smpboot.c) arch/riscv/Kconfig | 2 +- arch/riscv/include/asm/tlbflush.h | 30 +++--------------------------- arch/riscv/mm/Makefile | 5 +---- 3 files changed, 5 insertions(+), 32 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 0bfcfec67ed5..de9b6f2279ff 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -60,7 +60,7 @@ config RISCV select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS select ARCH_USES_CFI_TRAPS if CFI_CLANG - select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if SMP && MMU + select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH if MMU select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 928f096dca21..4f86424b1ba5 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -27,12 +27,7 @@ static inline void local_flush_tlb_page(unsigned long addr) { ALT_FLUSH_TLB_PAGE(__asm__ __volatile__ ("sfence.vma %0" : : "r" (addr) : "memory")); } -#else /* CONFIG_MMU */ -#define local_flush_tlb_all() do { } while (0) -#define local_flush_tlb_page(addr) do { } while (0) -#endif /* CONFIG_MMU */ -#if defined(CONFIG_SMP) && defined(CONFIG_MMU) void flush_tlb_all(void); void flush_tlb_mm(struct mm_struct *mm); void flush_tlb_mm_range(struct mm_struct *mm, unsigned long start, @@ -54,27 +49,8 @@ void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *batch, unsigned long uaddr); void arch_flush_tlb_batched_pending(struct mm_struct *mm); void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch); - -#else /* CONFIG_SMP && CONFIG_MMU */ - -#define flush_tlb_all() local_flush_tlb_all() -#define flush_tlb_page(vma, addr) local_flush_tlb_page(addr) - -static inline void flush_tlb_range(struct vm_area_struct *vma, - unsigned long start, unsigned long end) -{ - local_flush_tlb_all(); -} - -/* Flush a range of kernel pages */ -static inline void flush_tlb_kernel_range(unsigned long start, - unsigned long end) -{ - 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 */ +#else /* CONFIG_MMU */ +#define local_flush_tlb_all() do { } while (0) +#endif /* CONFIG_MMU */ #endif /* _ASM_RISCV_TLBFLUSH_H */ diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile index 2c869f8026a8..cbe4d775ef56 100644 --- a/arch/riscv/mm/Makefile +++ b/arch/riscv/mm/Makefile @@ -13,14 +13,11 @@ endif KCOV_INSTRUMENT_init.o := n obj-y += init.o -obj-$(CONFIG_MMU) += extable.o fault.o pageattr.o pgtable.o +obj-$(CONFIG_MMU) += extable.o fault.o pageattr.o pgtable.o tlbflush.o obj-y += cacheflush.o obj-y += context.o obj-y += pmem.o -ifeq ($(CONFIG_MMU),y) -obj-$(CONFIG_SMP) += tlbflush.o -endif obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o obj-$(CONFIG_PTDUMP_CORE) += ptdump.o obj-$(CONFIG_KASAN) += kasan_init.o