From patchwork Tue Jan 2 22:00:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13509534 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 E9FFEC46CD2 for ; Tue, 2 Jan 2024 22:01:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C309E6B02BB; Tue, 2 Jan 2024 17:01:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B8BCB6B02BC; Tue, 2 Jan 2024 17:01:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9B4CA6B02BD; Tue, 2 Jan 2024 17:01:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 7D69F6B02BB for ; Tue, 2 Jan 2024 17:01:47 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 4C77F1A00DF for ; Tue, 2 Jan 2024 22:01:47 +0000 (UTC) X-FDA: 81635743854.22.26F2642 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf24.hostedemail.com (Postfix) with ESMTP id 5AFD2180006 for ; Tue, 2 Jan 2024 22:01:45 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b="UnJSlp/4"; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf24.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.215.181 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=1704232905; 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=1tIOva8KFaIwh3i+98q+ysPtJyT8vpZl2kFy86xHGzc=; b=jrS1IZ34yYC2eahijuJVR/3QucMnoO2SvYMjaGFvK8J3c2S7jiVpoUVJu6jsXfKUDWqZ9K 6oLHMUu+WR8IAi31Km3+t5DKHaMEKaDaOQaa4Ark7fXLQHiKLNuVt6FIMiv4cmIhvz003H W9MFzGLta8EH4KdmRLaOoUafHMwykCA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b="UnJSlp/4"; dmarc=pass (policy=reject) header.from=sifive.com; spf=pass (imf24.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704232905; a=rsa-sha256; cv=none; b=MNl6Q/fvd8FtCHOpuE12rdUBcM3lDrbTAtaCpzd3qtS45YcaKYt+BSwGXKw3ZWQODfQoJ5 UoN3l92P5Ke51qVng84XG9vtq4uUGGnasV5ZQuD2yLIaSCYCS8lCn8+SxxKmLD4F3LO1Z3 mcqtTTAct5PynS3cRG2AunBB0lp1nM0= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5c66b093b86so6909333a12.0 for ; Tue, 02 Jan 2024 14:01:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1704232904; x=1704837704; 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=1tIOva8KFaIwh3i+98q+ysPtJyT8vpZl2kFy86xHGzc=; b=UnJSlp/42Xj/xJNzGoufoPWn+6OgJBoQgRfIAdlUZcl10VAAkjD1FFi2/KOQ8Zv8m9 wA9JmCvNV4Nu/O7G/0v+ZR6QkjMK0FNXq3xK7ELqZxAtR9rTzZqIry7QKAmvoxIZohfj DHY7vvDtDFDZwfdaP/GEtFn9yz025lu9w0Uni54xAxEjWgno2KRzFHcufuKNjIjcxZI0 Bh5S6tWF34LFyxsnjIpFy0fwB8OUeVLwIgXL9W57x6Aqif/NtYCR6OkCWVnwhoLYpWER 8/0X9ouG/p8zcQoMO5+/IpUBqLLo8zeyP/rCClakkHFWepcTqfbwZKAJs4P2oETe3Cur Zdag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704232904; x=1704837704; 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=1tIOva8KFaIwh3i+98q+ysPtJyT8vpZl2kFy86xHGzc=; b=M8BkLdiDrr1saAbn5kaYR4NO+fLrIUTB2z+XLkNMj0sXdCwdGiazxKH9pVtxAuus5C r166giapdVTRAao5nSPgnrLpskIaG5X4S2ifH+JdDkxe8wGKfZ1ldxI5xYysojZRLHB5 4+EDKiawJhXdySrk85U4Gt7yA7KeopzNKmSpBMFKsVv7+cH2ytBpf8Xf/24mmWpWiLw8 5jde3saZkPRertDPi3cPNsMapZ/IcgVxoSvMz5thksbOKs0qJLuDeZgnxI0ybT0GmuxX D/PyqctY5RV3kw4OWdzjpjWso4Nd4kVz5VC1B5b3bie0BvKpAKjR46aI0eEDuNxRtzaa qIYA== X-Gm-Message-State: AOJu0YyDzrLXLInP7ph09yjusqX6uP2lurpGUBwnMk05RP1iTKQ8d2h7 bWcLHVAqbpjaBj6ln8JVNvfy6BSy7GHk1w== X-Google-Smtp-Source: AGHT+IERqoXqHCzKpOJ5RqmrnOEOyFJpME6yqKz2yoKuSVbxPLF5GZg8UdvpqpiYsRMOZbO3DMheoA== X-Received: by 2002:a17:90a:d90b:b0:28c:300d:d858 with SMTP id c11-20020a17090ad90b00b0028c300dd858mr127429pjv.20.1704232904383; Tue, 02 Jan 2024 14:01:44 -0800 (PST) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id r59-20020a17090a43c100b0028ce507cd7dsm101724pjg.55.2024.01.02.14.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:01:44 -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 , Samuel Holland Subject: [PATCH v4 07/12] riscv: Avoid TLB flush loops when affected by SiFive CIP-1200 Date: Tue, 2 Jan 2024 14:00:44 -0800 Message-ID: <20240102220134.3229156-8-samuel.holland@sifive.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240102220134.3229156-1-samuel.holland@sifive.com> References: <20240102220134.3229156-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5AFD2180006 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: tssbgf6fbix63hkk84e66auzakkca79d X-HE-Tag: 1704232905-217807 X-HE-Meta: U2FsdGVkX19SWqmfSUfTfbMuB2625DTQ3/02PjwFJuwNXbi8YyyxwunOxoPMuzV4yPnQBozgS7bQmO4c/cWwkAWSaYgMBnIUyGXoaF9L8NCTARg/hubQnYv9axbqyjDgiRArkOPjjD33QgVajFR75XTiuz6w4SP3E5Q1gYOQbHaZXlMpVwLd5eneBaaY+Ls2Rzl5bkSC1gZhT+XAHTzgUrP+BJHASg+p2/2orEemg5GTC9fSJY/pNlIA3nmsOKsqH7cx/igoU2mS4gmhFQTYXVvUvh4rYolVQ4eO47pIPoUZHT2GzTYatk6zGowRpVNd5HBxfcSxVXV5SFXHJ7Oz7VCauqMNCR8ohBTkZEb91TegwfddJ2xumMWzgBpgIfjwd7fj4S1q7cKeGGfV2Uyq27Dj/49fMTPeX8wdtmhxtoyFzfrXbRynlTg4cOCP5v9uXfcnr+mHlD7V3vLvxFspYrPf7dSzPCVOMc1gQkBYPbjd4ktcPOMv7XhaME0SjR6CXOLFrNWlejdpxtfeZcJXq55Rbrkdv/DC+GXp386Q4+p5CiqqoeIsAAe+eCD2UVe5OptMPSZHTdBjr1hdylIRgL8fA4K3kit8InF92OB5Ib9h2INabRZmM2kBp7A8xaRWbmio/BB044iHuQTJVLndhM6GUcvtP478apkaqK+mUv1fm9BC6jLsbVvBoutCYwBEtgw5jO++3uHQnGRgrJ7AA9esA/EL8jzp0zWeL0dwYcbuOkpi2efzD1l8MCcTiRUaTGxgjnpiQzolp8xRT3LzTqzoL7VbBI3MzAIA8EX/iMIEPLJeoHPEV1ONQENHIH53oTxX83IR3pewwCUfOSTZubie5wfSOEjcM25v7HJ/AK3fzOS+dpuIG+cHQE9JxidsQgrrn6jh46xvHV6TWSlL7qpnN7/YbJXTtPDPKbyHkoiOiUulkHxteghGjwnzMORI5m3gzgKorOblUX8P5vc 9z7awnvz CUImVpt8p+j6pTyWPB8Z6zbhrWu35qq6iTIHKsNd2PS/8iyFyFQXjKsIVVh89BEKqrLXvGOUfpkzQCtQ5GWuul+8HFQXOT2bMHMUBbQCxiAffiypkRXYCcQc+m+S5HhB07CWyqbptQk/Bk26bP97HJz7BwCUsVsdJwu52KIRmR/WFLUUm1VeWzR15BsIQme/Dexe+KE5Lvds1nHJP9G3vw+RK6pAz5a3jox4sn5x4j3JVzzXSWI9/q6X+guCxakbGq3rBErPtTyXPKgjYNIq8uZz3BuC1MWx1G4Hg6YBrNBRGeie6Qyxfh6902zqfeJMrb2dcFLLdJ8iLUDEgFxvz9sMoRJUPtzBxM6kMJVk7B9BG+VQh5xb9FYYURryG9GqLfzWsXgO3OIIXZW0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000267, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Since implementations affected by SiFive errata CIP-1200 always use the global variant of the sfence.vma instruction, they only need to execute the instruction once. The range-based loop only hurts performance. Signed-off-by: Samuel Holland --- 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 002c4c2620f3..d9913590f82e 100644 --- a/arch/riscv/include/asm/tlbflush.h +++ b/arch/riscv/include/asm/tlbflush.h @@ -58,6 +58,8 @@ void flush_tlb_kernel_range(unsigned long start, unsigned long end); void flush_pmd_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end); #endif + +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 292d7cf3c4f6..76b24d4ed4ab 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,