From patchwork Wed Mar 27 04:49:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13605552 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 5BCC2C47DD9 for ; Wed, 27 Mar 2024 04:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DE7426B0085; Wed, 27 Mar 2024 00:50:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D48F16B009F; Wed, 27 Mar 2024 00:50:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC2E76B00A0; Wed, 27 Mar 2024 00:50:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id A78236B0085 for ; Wed, 27 Mar 2024 00:50:56 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 7AABC1403D6 for ; Wed, 27 Mar 2024 04:50:56 +0000 (UTC) X-FDA: 81941594112.03.EBBC88D Received: from mail-ot1-f50.google.com (mail-ot1-f50.google.com [209.85.210.50]) by imf30.hostedemail.com (Postfix) with ESMTP id A558D8000C for ; Wed, 27 Mar 2024 04:50:54 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=crFgZsC+; spf=pass (imf30.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.50 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=1711515054; 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=4DMxbhiunBS0lKLURYVBJG3nyObzwUO8ZrXza9ckh2c=; b=eI7ViTvFtsAnpscsjwBxnjX+I7duxpV+d9C0iTIIUjvjHTvaDRKUPc9VdgFyIUKJkd9zrA k4k4Geo8qCGzktT3OmYnuZswDYRzfIJJ9zaMDEbGT9co2d/M/FyDf7sVBkVyEjtBHVOSr8 6z64OhavXC70hbBkdyvUMV6NWJuHa6c= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=crFgZsC+; spf=pass (imf30.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.50 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=1711515054; a=rsa-sha256; cv=none; b=zMOTGla02jC2a97wXLf/41WA6/IZJR0lJpPWflwwZLEezQotyMBKk/M7nH98cPAS9VqCCV WWfCB5nikzw+qVK92w1rHJ4Io1ZFNKJc5ScAS+l9POKXc5YahuCWUhXuSAYda9GargWIPZ Ijj0HrZiSY2gcAfx/C+LdrsXNBjikO8= Received: by mail-ot1-f50.google.com with SMTP id 46e09a7af769-6e6a9e2e2b6so3481379a34.1 for ; Tue, 26 Mar 2024 21:50:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711515054; x=1712119854; 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=4DMxbhiunBS0lKLURYVBJG3nyObzwUO8ZrXza9ckh2c=; b=crFgZsC+PAacXnM5PlRp0C3h3LW/mzW66S2XEFUpmVzKP5sCmt7VOr0zSNJ5L0Bd0J N824yiZSMUlxzVHyf817bFV/n6/zKXKLtGMHao8wSh9z8M2SXudp7PiBEf5aCBVqds1d No4Ku0+XSgq5ur8A1WoIw24XQTxE7G+tYWX8qi2m73zcM8llpf+M72w26qQl4oo5pTl4 2ZekdgRANexpCM5kSQ1kagrv+CaA7/+3HpBrW+o586n/bgeQNdtuxKOY/3bmYCUarBJg 32msRh4Zmk6Mt33eYeziOpWZzjLxdRjgsHdo7ou9QvfJNgIxGJn5FnIGyuur2yOBxGQ9 d8NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711515054; x=1712119854; 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=4DMxbhiunBS0lKLURYVBJG3nyObzwUO8ZrXza9ckh2c=; b=CkE1VoxQXV9KBls5g0daugzxY8TvI798XJua2FIOrbc/N7j08XlZuvMIk05H8WzJu6 erF6tcEYs8ug4lcqIWmCsAy11k+aKzQu6VIPYHdwGGy/Xppfp6t4RGzPdN6mUN6LBAZ6 fTuoIAS9xHFxE6FOOqSVifbOHSeHm9LNCpTVr6yMNjPyeF9UU8G7DtCeJdvfUSenaRR1 8Cnb4p3nFrGsXg95cE757IuIpZoURU2sN0Kc/KChCPlKc4erRr8cCet0srhtgzhxTQ0A wdWEP8+Ph3H+VhETBVIvRpOC9ybdYTw+feuvr8bWeMy5uFsrUnv4TlVVHoFvdhsKhqy0 z50w== X-Forwarded-Encrypted: i=1; AJvYcCWE/qIrSC5qD0K/v9YE9fsV5mj5G00EiCecnRT2UvWkLk5HFcCj2bVt7dHflaYZebiqwpRynlP7MLNSd2JXhZ/tlSg= X-Gm-Message-State: AOJu0Yww0tpZJMscPW/4frWdRcT+SVpKjW0AAir99o2UvHA/gZdBg01B nm3JYz8kRboztOlDRCp7n4B9U2wzVNVAofdVSIWwEEAL6aUWFwlWyPuX+jVCKko= X-Google-Smtp-Source: AGHT+IEKVJUxYPHGmGQ7jZ/KC0+y46rPbmkW2DQ4LqVeHQ3jmUBdRhZe5PVjdoDThc5iPwQM0jPRUg== X-Received: by 2002:a9d:61d8:0:b0:6e6:9af5:752b with SMTP id h24-20020a9d61d8000000b006e69af5752bmr1730488otk.0.1711515053696; Tue, 26 Mar 2024 21:50:53 -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.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 21:50:52 -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 08/13] riscv: Avoid TLB flush loops when affected by SiFive CIP-1200 Date: Tue, 26 Mar 2024 21:49:49 -0700 Message-ID: <20240327045035.368512-9-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: A558D8000C X-Rspam-User: X-Stat-Signature: 6zrjtrtwrg1tjmn3cyi8a8qetpauzugu X-Rspamd-Server: rspam01 X-HE-Tag: 1711515054-214761 X-HE-Meta: U2FsdGVkX1/VsqhpdzCMLAW0avzfmXXpBNZWm9p2TDNtxmdiBwbeHbDhaRec2bT9Y6xXjvANLV38z8JPZUBJ1hsFRjfOa1Bkwls9i+xMbzdE9eyNIc3qU9tQCSoVWirtcRfPfKjO6/cFk8+WpaMdvqQVvut75ZinxJMGusIgWVuqcJm0WegPUlT9FmYqQmjHSqbka8soXY1J1wGwhVv5ZaBB73DRQwfN36Zle9hEcnCdJ0cOKCDBl6H1tffGkjuAph1+h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R7Pj1JxMkxQdZ0PP8iY12s5jvkhJvSPKjc/813g3Hn3bjUgtRr35nJ/4rKY= X-Bogosity: Ham, tests=bogofilter, spamicity=0.001892, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Implementations affected by SiFive errata CIP-1200 have a bug which forces the kernel to always use the global variant of the sfence.vma instruction. When affected by this errata, do not attempt to flush a range of addresses; each iteration of the loop would actually flush the whole TLB instead. Instead, minimize the overall number of sfence.vma instructions. Signed-off-by: Samuel Holland Reviewed-by: Yunhui Cui --- Changes in v6: - Clarify the commit message for patch 8 based on ML discussion Changes in v4: - Only set tlb_flush_all_threshold when CONFIG_MMU=y. Changes in v3: - New patch for v3 arch/riscv/errata/sifive/errata.c | 5 +++++ arch/riscv/include/asm/tlbflush.h | 2 ++ arch/riscv/mm/tlbflush.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/riscv/errata/sifive/errata.c b/arch/riscv/errata/sifive/errata.c index 3d9a32d791f7..716cfedad3a2 100644 --- a/arch/riscv/errata/sifive/errata.c +++ b/arch/riscv/errata/sifive/errata.c @@ -42,6 +42,11 @@ static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long imp return false; if ((impid & 0xffffff) > 0x200630 || impid == 0x1200626) return false; + +#ifdef CONFIG_MMU + tlb_flush_all_threshold = 0; +#endif + return true; } diff --git a/arch/riscv/include/asm/tlbflush.h b/arch/riscv/include/asm/tlbflush.h index 463b615d7728..8e329721375b 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -66,6 +66,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); + +extern unsigned long tlb_flush_all_threshold; #else /* CONFIG_MMU */ #define local_flush_tlb_all() do { } while (0) #endif /* CONFIG_MMU */ diff --git a/arch/riscv/mm/tlbflush.c b/arch/riscv/mm/tlbflush.c index ad7bdcfcc219..18af7b5053af 100644 --- a/arch/riscv/mm/tlbflush.c +++ b/arch/riscv/mm/tlbflush.c @@ -11,7 +11,7 @@ * Flush entire TLB if number of entries to be flushed is greater * than the threshold below. */ -static unsigned long tlb_flush_all_threshold __read_mostly = 64; +unsigned long tlb_flush_all_threshold __read_mostly = 64; static void local_flush_tlb_range_threshold_asid(unsigned long start, unsigned long size,