From patchwork Wed Mar 27 04:49: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: 13605550 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 06D65C54E67 for ; Wed, 27 Mar 2024 04:50:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6BDFE6B009C; Wed, 27 Mar 2024 00:50:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 66D7C6B009D; Wed, 27 Mar 2024 00:50:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4BFCB6B009E; Wed, 27 Mar 2024 00:50:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 383F46B009C for ; Wed, 27 Mar 2024 00:50:54 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CE2FD16060C for ; Wed, 27 Mar 2024 04:50:53 +0000 (UTC) X-FDA: 81941593986.02.C3551C0 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf30.hostedemail.com (Postfix) with ESMTP id 25B7E80005 for ; Wed, 27 Mar 2024 04:50:51 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=ZB122B02; spf=pass (imf30.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 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=1711515052; 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=7nL2m+hLarkGQvecSEd0KAq0QtYwqUItfZBnVAx3yeI=; b=iiloRkcMwZmohdgqeOltTEACr5lxgXEFqInB9kP5HoAIQ30Hnb5TwWYKEgwOjWrUDBpkco Kue8nLoVW3ekxj5vMj81ppDq83gjRj9y5O7MSmkCH9UO3BPmHwKMHOyJ775uAHqQX7h3of pXvrOmuhP3moqUy2LsQ2bIUyZCrHwqM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=ZB122B02; spf=pass (imf30.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711515052; a=rsa-sha256; cv=none; b=7FisQIn6ydnGtPeXszQOUJeFd+hXBHvA7SlwkEg5WbekoFL/7Me+w74jUv2Zez4h4X/Mer t1qms5a74guBx347TF8lHF8RFUPVk7L3dUizm2bDUSLgQbNTZ2P56k/q/XxfjfOF3ENJu4 QjMjXU55FCFdMkCHhGNIv9tztbjB0WQ= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-6e73e8bdea2so5252903b3a.0 for ; Tue, 26 Mar 2024 21:50:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711515051; x=1712119851; 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=7nL2m+hLarkGQvecSEd0KAq0QtYwqUItfZBnVAx3yeI=; b=ZB122B029vx2sBz/7sPoTpodARK0beMX8+hdhsPb/r2mSX9V2lGcAuv3Ia7ZZ4yveU 9eXEllJ12jlmgjQt7yVL8lfp+gEQBAOVEaNt+2hbJ38EaRI4s89XsIIwMv+82KwGTpGs mC1aedY7EZLvPZEXho2sAwpEOa3gbge8+CHwDoXJKKzp4KPajw78QSofJuLn3XaTL4X1 w9RZpvrx3IDRzCDS7RJYjqo7edVfGJHklN9t7+k/rlNeqtkDuqMujQvWQrNBrxUCo4Fc Dgg3uwQZuRQdHlaYaL8kKVlVScxX18yRjQvZBoTzPDB3woRjDNeG9cJQH0aRm0GVjcLp /V4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711515051; x=1712119851; 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=7nL2m+hLarkGQvecSEd0KAq0QtYwqUItfZBnVAx3yeI=; b=FyXat8ZuSibtIfu9I7QEbNCQW7imFVHQtTmWf66hZvmxNZJpnoyi3FeOMCkRXSvgxR xxtwyTt5SEHlCSzByA742AdQrU9PO2NcrUrSGFbUCsDabxo3beYh3PLIsy36q7y0sLOx aTOHlOVH43lmEh64QLrFjS9gCZr+aMjZBUhSv4Ez6pqEOq4yxPTjYq7qKraeLwGOijwp a+wVwX7af4zfOthDuHCHyJP5I1mAo3Zy2HnwD/EmLzQOPgJy4qbdyiP3L/QpHFeD4M0L uXw9ElbIPR1v/CMMarNLWVniCN0r8dJ91dVeURO6moSI340wZpaoa8ZktSlfdV1bKeFI MV1A== X-Forwarded-Encrypted: i=1; AJvYcCU4ShjZacedMthgM7h0pi338Fy4KfwG+CbCzeZboqfy6rZ100xttb86+bexG86k+2lytlBrpnQlfrvNgvDzlV/dpYA= X-Gm-Message-State: AOJu0Yw3Nwp2jn3BuNO3KqBbPELJ/4epfWp0Gr9bWpAn2uWzVrr8dqeG 9D47O9SKIepiTi7zDQ97yXqQ42ac9W+T7gGdpvsbpyYivsNW5ZeRQVSopZOBpuE= X-Google-Smtp-Source: AGHT+IGyz4xXUqNq5aXCdK4lWIBgBxDZJLK6nH/Xm7w+Te1ce++GEK9gbqC/aCbf24OJ2Eh82pVCjA== X-Received: by 2002:a05:6a00:13a2:b0:6ea:8e89:7eca with SMTP id t34-20020a056a0013a200b006ea8e897ecamr1940335pfg.32.1711515050263; Tue, 26 Mar 2024 21:50:50 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id e31-20020a63501f000000b005e4666261besm8351500pgb.50.2024.03.26.21.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 21:50:49 -0700 (PDT) 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 v6 06/13] riscv: mm: Combine the SMP and UP TLB flush code Date: Tue, 26 Mar 2024 21:49:47 -0700 Message-ID: <20240327045035.368512-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327045035.368512-1-samuel.holland@sifive.com> References: <20240327045035.368512-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 25B7E80005 X-Rspam-User: X-Stat-Signature: 39ebw6ferybewehc73dydu6pw1h7y4sh X-Rspamd-Server: rspam01 X-HE-Tag: 1711515051-519388 X-HE-Meta: U2FsdGVkX1+JuI8VT4///PjqzFp8gzykZa0g81HX4aOCyi69X1kLmu2hYmY6yZ/o1Vr/cF+r1nmx2xazAYFqt4fGBeMjg0pGiyHcliRv1BsH7YMV/O58JQZ7jFgnu2vkUnBPbFzpWnH1R4dGNjwE54pVamrkImx1NHQUik2pMgWya0h9VzSuLyhwT77mfD9X+GkVo1CIMSpsCnymOdyOyuX0t2AAblw7F6PdPmJFlyDG4TVz2GEDMud0QpS/dU5yyaE7RRx4ZxvjPdQTK6Z9ETz1trnK9ONqJR7DgdOkDk8dtJLX57mSSD183jPd+F8/Eunbj6SYCeXRvLaq4b1qvkllnjWUAuBJneD/8V1Ynqx2vz0qoSq1VbrTQWDXzu6iaDKVGL+2M6DK73DyrcPy7kQiCt47tk5EKFYk5+jDj9xn/Tupel3ccil70E146FHqPPo4xGpC22VRcNEcXecIviXlOa64rgrcZHkwrXXPAbJYNnZosUUGno/8FjESyYswCMawC31zc10B/27nfVOcdcMuUfRLVQlLC54El4rx5fOby1/XKDlUABsgyl5zgIs8MDSVT2RgllqNLANUJlvxlwQxMkF/uA1gV6TyaEdQdtfWm/h52svHDA/ZfpWPDH1kHBlwG/0syF+u6N8axnxR7PdltMQ77mTZmnqmvRdAp0t22cMeuQ4S5aoB5S0w5RTZgSF8xnj0VrOh2FCQDTiFq2zSXIljl92E0FFeN4M8znjmL3mea/m8BYA4yF9mjI24Sh9woCQ5oAn3kwhgMwCUtIYp3CZ2gaiW3HMZSUGRqCvTUytWjDEM/X2Aw6tpMTAEQKH3bCl1hEkufe4G3dk83cyfK1uOwiY0OtIxbTNpqVKNtN8zCyk7AigDL++PBtEI/fU2hQMIYZqm+ZW1J19x8anrEt2QYIs8bRZx9NE14ZGZPO/Alry+xA/rJaFX/z4GmOEgjik3cUxdnSWYW4b Wxln6PSV uPLP4ZIiPC+Vu9H7WmRYv7XhLpx7K+hbT2QmvdqmfwqposViXMGySCvKEGIu8HYy2LBeQM/V3xYiz8tYQSeSUuX8WY8Hn+ESneEO0ivqywJ19yGSBTrUkH0XfKQ== 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 Reviewed-by: Yunhui Cui --- (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 | 31 +++---------------------------- arch/riscv/mm/Makefile | 5 +---- 3 files changed, 5 insertions(+), 33 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index be09c8836d56..442532819a44 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 4112cc8d1d69..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,28 +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() -#define local_flush_tlb_kernel_range(start, end) 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