From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32BB13314D9 for ; Sat, 23 May 2026 05:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779514617; cv=none; b=Fd6UMtIa1ApJPJL+w+cRAqrPoU+eaYlxLRNHf20/HWShdy5jg4/lL8Ep2xq5lqwsyxeZJAQyKj9dyn2Ip8iRjvuSOwzfqsPUKyy4XaBUoRqZenkNkE7o6l3Vu2xB2tUn1RzlzeLMkWzSR8W2BbIlidveELmFTzvqPVNxuUpcmUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779514617; c=relaxed/simple; bh=Ld1JJn+zGIIrv4OfEQcvAVuHm3e1kxZgfP5KYvnpil4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KeiezDmczTOsU9hnYZnpbb/WcGGmnEgg8E5CdLKoX1B1XK8CrGUPCFgC4JWgy6NKT53HwOa86vp2zv/QCQ130/QayOwn+cQm+f4NFCgPGOkY29LstxEwOKZibBPaBE2I8AqZ8OgUoFzicBKcf3UO0InJvcb/5yvVgLBqaSSCDvk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VQeeVL4Q; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VQeeVL4Q" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4891c0620bcso50383975e9.1 for ; Fri, 22 May 2026 22:36:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779514615; x=1780119415; darn=vger.kernel.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=nUwKR3yq6fKwgsxnrOqNBKyVRzqIoUnbsdF3bmKoKC4=; b=VQeeVL4QUyCLjLvwJHM1Yqzxhyzk5qt82EpvewGnJZENq4vOseqQLyuzzr1Vq17HRJ W2Qr/YFxC9ycyMYHMVD6YPD4AyIrQj12F/HHhg9k3hV+6x/7JtlzqxmuDbdWCnZapBmU pd9cwbOtTD4Z5fCR0wHOqHaaAKqjCYRjougNWfR65WBeDQ7+nyL65h6+0MkI8ZTNTqnO Sc1mYu/A4kIytUkJ55XLlLBsIeNvqtyyP4lXFNAyv2DJp4V0fU2eDpL0gFepv5zj9DF3 Z+EGcJrWbVJlFMtoc9W57WlhU9aoDPfvBsinFUnMzOPcfFQE9Q8W3kd5aw4Atrd4r08i IYPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779514615; x=1780119415; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=nUwKR3yq6fKwgsxnrOqNBKyVRzqIoUnbsdF3bmKoKC4=; b=BlPpT93MsjzpO2ptDUsJHlSjcmebSK6HW6R2fQIPfXvJGgx8kSFbYyOtSjQnLG0ISp lcbMtJZLommPjgaLprY2QkW1ti2ze+LUWiMtg0VSHgH7wv6FbXwv7Mzgd5iqgSHP/sKp VV/sac80TlelbiYOrp4aznku6YWsJYawvvkXx6x1hXqU144PyhEMEqyez46NvTSFpOl8 N/oZy0BscRqD/4jirsqv7qieQYxAF8nRJ1aLFZcyUb+1QAEhaE95bN+KcbE42hD9r14c LUx3UyEJFtqaXNzEuXB1se8kwl8a6HWfeC8ymqvR0e6vJu4V8jSmB0o1Wjr8yTaHiorc nwFA== X-Gm-Message-State: AOJu0YylmLbcmM7ZTwck13HJNfzPUEMmCOyJD85sNxpcNwDgDVo2Dz2M /1Hpzu/VmrIrpMIVP8F1YHSUxzIE7u/Ii1suQ8hBv6RCh/NvuieRDnydnkn+gA== X-Gm-Gg: Acq92OGE+4tesdg7QVJWvoIB6XOt6Ih9QM8HjLJ2tFF7VfxNbhDaywAyN72J++dgM5P 2TGqR5TN2JeSCV/8iHQnJzny9UcJ+PG5577v7+pBXlrWDADeWlqeIDjr9thN4wxw5lZk/WyGLot /B870p1d5wuI2R/hgpNwwqKvi7ZK1kx14bsh+wzfQhe+d1PWo8zclrLEkFoFNB9D4ZePaldsjBg xR0SNGU0ntjxYasoN8Jcj8Sh+OgkVssmA+CgLzvSoZAZ/tbxCah/jnJjabyTfM2Y5vqGRlA4Jrd t67we89C2LFdrHyUtd098z0ScwIIoJDyiIcEKZ4RT8eDV/hKTW+qz0AYLazvc1dSPLqaF1TcV3V XblAAeCyZF7pcya6nPgKnxv9AWrcMcIZQ8JmnJ47/3l4cQaPrErRhRoGWtXPQg+xWVqV33m7eHI jmw+MDtgn6PZMcaTWWbaACUaaEcp4SE/GNnGanaNH15pU+apKR4mfSMdyG4ZLPM049U3HTP5ueE 5mvrQ== X-Received: by 2002:a05:600c:6287:b0:48f:eb8b:997a with SMTP id 5b1f17b1804b1-49042ae285bmr93143975e9.31.1779514614442; Fri, 22 May 2026 22:36:54 -0700 (PDT) Received: from localhost (brnt-04-b2-v4wan-170138-cust2432.vm7.cable.virginm.net. [94.175.9.129]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-45eb6c9f6ffsm9336779f8f.1.2026.05.22.22.36.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 May 2026 22:36:53 -0700 (PDT) From: Stafford Horne To: LKML Cc: Linux OpenRISC , Stafford Horne , stable@vger.kernel.org, Jonas Bonn , Stefan Kristiansson , "Matthew Wilcox (Oracle)" , Zi Yan , Andrew Morton , Thomas Gleixner Subject: [PATCH 2/3] openrisc: Add full instruction cache invalidate functions Date: Sat, 23 May 2026 06:36:17 +0100 Message-ID: <20260523053624.630443-3-shorne@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260523053624.630443-1-shorne@gmail.com> References: <20260523053624.630443-1-shorne@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add functions to invalidate all cache lines which we will use for static_key patching. On OpenRISC there is no instruction to invalidate an entire cache so we loop and invalidate cache lines one by one. This is not extremely expensive on OpenRISC as we usually have only a few hundred cache lines. I considered using the invalidate cache page or range functions. However, tracking which ranges need invalidation would have been more expensive than flushing all pages. Cc: stable@vger.kernel.org Signed-off-by: Stafford Horne --- arch/openrisc/include/asm/cacheflush.h | 4 ++++ arch/openrisc/kernel/smp.c | 21 +++++++++++++++++++++ arch/openrisc/mm/cache.c | 16 ++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/arch/openrisc/include/asm/cacheflush.h b/arch/openrisc/include/asm/cacheflush.h index cd8f971c0fec..7b8c043a831d 100644 --- a/arch/openrisc/include/asm/cacheflush.h +++ b/arch/openrisc/include/asm/cacheflush.h @@ -26,6 +26,7 @@ extern void local_icache_page_inv(struct page *page); extern void local_dcache_range_flush(unsigned long start, unsigned long end); extern void local_dcache_range_inv(unsigned long start, unsigned long end); extern void local_icache_range_inv(unsigned long start, unsigned long end); +extern void local_icache_all_inv(void); /* * Data cache flushing always happen on the local cpu. Instruction cache @@ -35,10 +36,13 @@ extern void local_icache_range_inv(unsigned long start, unsigned long end); #ifndef CONFIG_SMP #define dcache_page_flush(page) local_dcache_page_flush(page) #define icache_page_inv(page) local_icache_page_inv(page) +#define icache_all_inv() local_icache_all_inv() #else /* CONFIG_SMP */ #define dcache_page_flush(page) local_dcache_page_flush(page) #define icache_page_inv(page) smp_icache_page_inv(page) +#define icache_all_inv() smp_icache_all_inv() extern void smp_icache_page_inv(struct page *page); +extern void smp_icache_all_inv(void); #endif /* CONFIG_SMP */ /* diff --git a/arch/openrisc/kernel/smp.c b/arch/openrisc/kernel/smp.c index 040ca201b692..65599252f3d4 100644 --- a/arch/openrisc/kernel/smp.c +++ b/arch/openrisc/kernel/smp.c @@ -346,3 +346,24 @@ void smp_icache_page_inv(struct page *page) on_each_cpu(ipi_icache_page_inv, page, 1); } EXPORT_SYMBOL(smp_icache_page_inv); + +static void ipi_icache_all_inv(void *arg) +{ + local_icache_all_inv(); +} + +void smp_icache_all_inv(void) +{ + if (num_online_cpus() < 2) { + local_icache_all_inv(); + return; + } + + /* + * Ensure stores complete before we request remote icaches + * to invalidate. + */ + mb(); + + on_each_cpu(ipi_icache_all_inv, NULL, 1); +} diff --git a/arch/openrisc/mm/cache.c b/arch/openrisc/mm/cache.c index f33df46dae4e..2667d90691b5 100644 --- a/arch/openrisc/mm/cache.c +++ b/arch/openrisc/mm/cache.c @@ -63,6 +63,22 @@ void local_icache_page_inv(struct page *page) } EXPORT_SYMBOL(local_icache_page_inv); +void local_icache_all_inv(void) +{ + if (cpu_cache_is_present(SPR_UPR_ICP)) { + unsigned long iccfgr = mfspr(SPR_ICCFGR); + unsigned long sets = 1 << ((iccfgr & SPR_ICCFGR_NCS) >> 3); + unsigned long block_size = 16 << ((iccfgr & SPR_ICCFGR_CBS) >> 7); + unsigned long paddr = 0; + unsigned long end = sets * block_size; + + while (paddr < end) { + mtspr(SPR_ICBIR, paddr); + paddr += block_size; + } + } +} + void local_dcache_range_flush(unsigned long start, unsigned long end) { cache_loop(start, end, SPR_DCBFR, SPR_UPR_DCP); -- 2.53.0