From nobody Fri Oct 3 06:34:58 2025 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (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 E8C4729AAEA; Thu, 4 Sep 2025 10:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980093; cv=none; b=hAvVO8WfNzWEOp/JeZpqbtZwgmUF5q+G/eentU2PJOjDRSeo5S8AUsdPvom3+ls4WVik9/DI0jq2Y6EYsvHtHfm0vpDNXMz83UL7xHoClPyz/j7L1Fu2X5ehWMA23c6ZZjMNyMhloW4yolgJEYOwewAMdq8zBQhhMTiTYO0fNWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980093; c=relaxed/simple; bh=4ImLcomq9EQTR8O9rxQWRk5p25evmsL6lS0oArtOnTY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CQPUs2DEWFfHrQyRm23akqJ3Ekh6bGXCLlfGMZkQig1lXRDYlQDpHnaNFmO2dAddLN5JZgOMYWOKnw5Z26yLz8a5Qc8MQKvj9pj09BVZskn7VAKbLAXafALjxKncpmhAvQIDwDv02ae78bdTTIKcCXNGY4hkMAmlfjhLZu2Lcyw= 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=XpOvGX/s; arc=none smtp.client-ip=209.85.210.176 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="XpOvGX/s" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-7722bcb989aso651786b3a.1; Thu, 04 Sep 2025 03:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756980090; x=1757584890; 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=N41B+ZHzPjNtp4wsALI7xhZWCUSTwRgGtFg4TpEdbnI=; b=XpOvGX/sxTfXy4Uz3CYb7pt2qfXHQiUByr0URHTQI56+9tn7O/Uq138Wjvh0QYypS7 Rs0XGlDIlEo8qfJNUvsyhw+t9n20YZoqX/03gUV5FOMYHGr5KYe/wxmrqXsyORVVOyFs 6kvmX5dX2EaJBwSr8Wi8sY5LEKldptAsQBvsE8ZTLaQZOsBgeORlsOalTUOpFhggCEbb YOR0PxxKiVse/WqqnuuFU7rFa734RQqSgbCrJ1li4JRxivTgnryIfS4Jt3HcN3ugOlQe lhc8QcrybbxfWHcpxtWmxFEYNO1JmhiH/CvwWZSm1BRfTrvv6ysWz3aW2qJBh75fSg5U sD2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756980090; x=1757584890; 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=N41B+ZHzPjNtp4wsALI7xhZWCUSTwRgGtFg4TpEdbnI=; b=c/6i1yQKTZ3DpLP7e2XPXr/wjlrsSg8QLBi8K+GDxZaBVvtcGpIZpbDIoJCMxo3AYL lPofzKuRd8UJUktfQ5G71FApq6/r7E69fRcYvqcYZsOMogfe/heWqFUV9JfZd9ZzM4S+ 72bbuPTz5IdYTPDH/0SuTVfmqZSBc2Pj1Z3SR9Xuzy75xgUaEWtu4wQJKWliBUr/Al/H uhZ0iSnfED4jcbFm0t70z0ZGAeaIYLhXYB22lti99LZY5JZ6vFLjZPmw6+NI8sOd2xSx 6q/6OYFP1EZgqMP4vnqTkL0OlagR/8txz15fOOx6mR0mqdM9PNxj002oaVY0aHiZncRd O3PA== X-Forwarded-Encrypted: i=1; AJvYcCWoZSlHChWt5awRCrtjYsI4pA9RhriF04giW6bRSMwpuaz5R9M6IXn0n90eDbL1kyClFO44xnyxY+h+poPjzg==@vger.kernel.org X-Gm-Message-State: AOJu0YzlhmlFxPTzp1y28prkwBA0qbl5gQiFsmE6HfvH+PWyZPwFEkxG y+RVchfvMy7l2R7tLPbZCNCeTf+9oYelr8O5rTFN8tpETdmMfkVjjA7HDE1jr0mM6kUm2CeK X-Gm-Gg: ASbGncuviVcrS4JiwrAXGg2uD51bj7LtYecobQkscY937SXuzPizZWvw8KG9ImXHYDZ Ydm4ri2Ja7ChOlJOJ9RpGjccjL7ozvTJaOoAVO3i3uVjEKheIqY/Gn1AyzfAlz8xwXH3zSaNBUv voOosdQHFx9jZFRffwFaQEDWn71g9GeHpZk/AEWIHc09OR37P7gam0lW7wwy2JKNE27unzqfOlg WNJ7nHt+G6oL44lHgQU/IXiQSupYxbul3VJDx9LyYJSrjzWNwOJAW96rb2cTjSwpsNT1RNUtIJo 7FqCI9ubp3QaRmDiaJAiHHO5EByMciSL+tYPJzoVsE7tRLkAcUyUZtjMHsJDoJZurFB3uq9J1Jh X/YMMgkaZfwnxkLdj0eUhV7jhPCE14A9oQY0D21XPdX3MNnuXqUNmMRqSMXddbA== X-Google-Smtp-Source: AGHT+IEhsjFp1NibtjGx54wEWDNQHrHEVnvf81wB1ddDTJzWtfmVX0nktkLI4k1cniU2BMRD7U3MEA== X-Received: by 2002:a05:6a20:78a1:b0:244:58:c155 with SMTP id adf61e73a8af0-2440058c43amr12075380637.15.1756980090114; Thu, 04 Sep 2025 03:01:30 -0700 (PDT) Received: from nyaos.. (v133-18-108-210.vir.kagoya.net. [133.18.108.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32b747c2d66sm3510656a91.28.2025.09.04.03.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 03:01:29 -0700 (PDT) From: ChenMiao To: Linux Kernel , Linux OpenRISC Cc: chenmiao , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Geert Uytterhoeven , Andrew Morton , "Mike Rapoport (Microsoft)" , Luis Chamberlain , Johannes Berg , Nicolas Schier , Sahil Siddiq , Masahiro Yamada , Dave Hansen Subject: [PATCH v4 1/4] openrisc: Add text patching API support Date: Thu, 4 Sep 2025 10:00:49 +0000 Message-ID: <20250904100109.688033-2-chenmiao.ku@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250904100109.688033-1-chenmiao.ku@gmail.com> References: <20250904100109.688033-1-chenmiao.ku@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: chenmiao Add text patching api's to use in subsequent jump_label implementation. We= use a new fixmap FIX_TEXT_POKE0 entry to temporarily override MMU mappings to a= llow read only text pages to be written to. Previously, __set_fix was marked with __init as it was only used during the EARLYCON stage. Now that TEXT_POKE mappings require post-init usage (e.g., FIX_TEXT_POKE0), keeping __init would cause runtime bugs whenset_fix= map accesses invalid memory. Thus, we remove the __init flag to ensure __set_fix remains valid beyond initialization. A new function patch_insn_write is exposed to allow single instruction patc= hing. Link: https://lore.kernel.org/openrisc/aJIC8o1WmVHol9RY@antec/T/#t Signed-off-by: chenmiao --- Changes in V4: - Fixed incorrect macro definitions and malformed comments. Changes in V3: - Removed the unimplemented and unsupported is_exit_text, added comments for the set_fixmap modification explaining why __init was removed, and added new comments for patch_insn_write. Changes in V2: - We modify the patch_insn_write(void *addr, const void *insn) API to patch_insn_write(void *addr, u32 insn), derectly support a single u32 instruction write to map memory. - Create a new file named insn-def.h to define the or1k insn macro size and more define in the future. Signed-off-by: chenmiao --- arch/openrisc/include/asm/Kbuild | 1 - arch/openrisc/include/asm/fixmap.h | 1 + arch/openrisc/include/asm/insn-def.h | 12 ++++ arch/openrisc/include/asm/text-patching.h | 13 ++++ arch/openrisc/kernel/Makefile | 1 + arch/openrisc/kernel/patching.c | 79 +++++++++++++++++++++++ arch/openrisc/mm/init.c | 6 +- 7 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 arch/openrisc/include/asm/insn-def.h create mode 100644 arch/openrisc/include/asm/text-patching.h create mode 100644 arch/openrisc/kernel/patching.c diff --git a/arch/openrisc/include/asm/Kbuild b/arch/openrisc/include/asm/K= build index 2b1a6b00cdac..cef49d60d74c 100644 --- a/arch/openrisc/include/asm/Kbuild +++ b/arch/openrisc/include/asm/Kbuild @@ -9,4 +9,3 @@ generic-y +=3D spinlock.h generic-y +=3D qrwlock_types.h generic-y +=3D qrwlock.h generic-y +=3D user.h -generic-y +=3D text-patching.h diff --git a/arch/openrisc/include/asm/fixmap.h b/arch/openrisc/include/asm= /fixmap.h index aaa6a26a3e92..74000215064d 100644 --- a/arch/openrisc/include/asm/fixmap.h +++ b/arch/openrisc/include/asm/fixmap.h @@ -28,6 +28,7 @@ =20 enum fixed_addresses { FIX_EARLYCON_MEM_BASE, + FIX_TEXT_POKE0, __end_of_fixed_addresses }; =20 diff --git a/arch/openrisc/include/asm/insn-def.h b/arch/openrisc/include/a= sm/insn-def.h new file mode 100644 index 000000000000..e28a9a9604fc --- /dev/null +++ b/arch/openrisc/include/asm/insn-def.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Chen Miao + */ + +#ifndef __ASM_OPENRISC_INSN_DEF_H +#define __ASM_OPENRISC_INSN_DEF_H + +/* or1k instructions are always 32 bits. */ +#define OPENRISC_INSN_SIZE 4 + +#endif /* __ASM_OPENRISC_INSN_DEF_H */ diff --git a/arch/openrisc/include/asm/text-patching.h b/arch/openrisc/incl= ude/asm/text-patching.h new file mode 100644 index 000000000000..d19098dac0cc --- /dev/null +++ b/arch/openrisc/include/asm/text-patching.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Chen Miao + */ + +#ifndef _ASM_OPENRISC_PATCHING_H +#define _ASM_OPENRISC_PATCHING_H + +#include + +int patch_insn_write(void *addr, u32 insn); + +#endif /* _ASM_OPENRISC_PATCHING_H */ diff --git a/arch/openrisc/kernel/Makefile b/arch/openrisc/kernel/Makefile index 58e6a1b525b7..f0957ce16d6b 100644 --- a/arch/openrisc/kernel/Makefile +++ b/arch/openrisc/kernel/Makefile @@ -13,5 +13,6 @@ obj-$(CONFIG_SMP) +=3D smp.o sync-timer.o obj-$(CONFIG_STACKTRACE) +=3D stacktrace.o obj-$(CONFIG_MODULES) +=3D module.o obj-$(CONFIG_OF) +=3D prom.o +obj-y +=3D patching.o =20 clean: diff --git a/arch/openrisc/kernel/patching.c b/arch/openrisc/kernel/patchin= g.c new file mode 100644 index 000000000000..d186172beb33 --- /dev/null +++ b/arch/openrisc/kernel/patching.c @@ -0,0 +1,79 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright (C) 2020 SiFive + * Copyright (C) 2025 Chen Miao + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +static DEFINE_RAW_SPINLOCK(patch_lock); + +static __always_inline void *patch_map(void *addr, int fixmap) +{ + uintptr_t uaddr =3D (uintptr_t) addr; + phys_addr_t phys; + + if (core_kernel_text(uaddr)) { + phys =3D __pa_symbol(addr); + } else { + struct page *page =3D vmalloc_to_page(addr); + BUG_ON(!page); + phys =3D page_to_phys(page) + offset_in_page(addr); + } + + return (void *)set_fixmap_offset(fixmap, phys); +} + +static void patch_unmap(int fixmap) +{ + clear_fixmap(fixmap); +} + +static int __patch_insn_write(void *addr, u32 insn) +{ + void *waddr =3D addr; + unsigned long flags =3D 0; + int ret; + + raw_spin_lock_irqsave(&patch_lock, flags); + + waddr =3D patch_map(addr, FIX_TEXT_POKE0); + + ret =3D copy_to_kernel_nofault(waddr, &insn, OPENRISC_INSN_SIZE); + local_icache_range_inv((unsigned long)waddr, + (unsigned long)waddr + OPENRISC_INSN_SIZE); + + patch_unmap(FIX_TEXT_POKE0); + + raw_spin_unlock_irqrestore(&patch_lock, flags); + + return ret; +} + +/* + * patch_insn_write - Write a single instruction to a specified memory loc= ation + * This API provides a single-instruction patching, primarily used for run= time + * code modification. + * By the way, the insn size must be 4 bytes. + */ +int patch_insn_write(void *addr, u32 insn) +{ + u32 *tp =3D addr; + int ret; + + if ((uintptr_t) tp & 0x3) + return -EINVAL; + + ret =3D __patch_insn_write(tp, insn); + + return ret; +} diff --git a/arch/openrisc/mm/init.c b/arch/openrisc/mm/init.c index e4904ca6f0a0..9382d9a0ec78 100644 --- a/arch/openrisc/mm/init.c +++ b/arch/openrisc/mm/init.c @@ -226,7 +226,11 @@ static int __init map_page(unsigned long va, phys_addr= _t pa, pgprot_t prot) return 0; } =20 -void __init __set_fixmap(enum fixed_addresses idx, +/* + * __set_fix must now support both EARLYCON and TEXT_POKE mappings, + * which are used at different stages of kernel execution. + */ +void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot) { unsigned long address =3D __fix_to_virt(idx); --=20 2.45.2 From nobody Fri Oct 3 06:34:58 2025 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 E58192F83BC; Thu, 4 Sep 2025 10:01:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980097; cv=none; b=O7stb7iTF4JShKmpGHyHCeCRbxpIU1rtPfnjiSgqfK7Loy1B2FvlzwJkwpRF9BaQQ8YrEOebxUnweMqjuiRw/U2kM8Cia8Hx2UkFM+ImqXxkY785ULHNfca9+HoAvvIbLK6uxpDP2qK2eC5anOFEeXMgCIOIT57CtyUvQjBPSmU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980097; c=relaxed/simple; bh=PsVd6C4psph+e1gqARopkSzWhgv+MiZt61T+Lfmzr0U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nXdeprr7iBxyORGIH1hGavweER4QCFTxTpowkDJ/7g2uPSpSJLMxvZJD6EW6qyHohhlKLcNO0HRwMvA/0d2Yq5B1xBR0fxlk2u5bAp8Y8pGeWnyRUgKfzy8jiZ9tRhQwtICItCksccwFEsFx5jPYuLzTVBbvDWKgvrjI34AtwKs= 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=hYoeHyYo; arc=none smtp.client-ip=209.85.210.169 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="hYoeHyYo" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-772627dd50aso2195966b3a.1; Thu, 04 Sep 2025 03:01:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756980095; x=1757584895; 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=F9IQSACqPH+hbfEranj10Cab4WP4xbeC5eLzb0sRCnw=; b=hYoeHyYouPHGsiUZuHEg6ccFt5/v6JrO+5ZEBy3y5HS1ijWfaW5wt40cnkLmeL2jsG vBuoRX+cDC1rb0d+H+5bm5uZcdLFAo4Hs3OYeIjIhb1c0vtxIcZ/AoxPzPORTLEbwypT +N1EualeNHYPO4GisKAwGWNCoow25goBOFbREGWYWreiyZ7LbWg0LCbzu+Oezxxo2hX1 zMdzUKhJ4sYB41gWO07Lp09xmG43CcNrP1cp6S7XPk5H83N8UyYwy6xUjNe3KckvlJVZ VmhYhXyQmp1jMNUWEpEBgyyR93JGVM1Mh6ufjkpdI41p1RGk4M1JdHnZIRSURqc8GX4m kjLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756980095; x=1757584895; 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=F9IQSACqPH+hbfEranj10Cab4WP4xbeC5eLzb0sRCnw=; b=gssUp01BIWhKzX2gLNF70wA6hPD59n7Hus8BnAN5FEyb2dtSxOCDfFzKBULWCrAQy8 CD2oJskoFiteQyxz9BwLi6Y8vAtK/KPbO/xRs6LMcMNlMUp+UIoXKA9XzKv4KHJ2PJsb UTiWiVXLFCGilSXt//eHxgSIMhIs5Mvwbpb8o1u7P7Z+zZ+6r1XqENfYIM6vKsMdkhLp HohnIsNlty7azynrJ3UKIetV1Nx8MD+qEdoecccZ3Q+zckEOEYEyzPj72OOxlX8McaRR 0hOs8VbDsIQ++29EL8+EXBUPafkrOLxtHQtDp9E0bfJkunNiYQPN9lQnqwn+PJhlBdjI Bcmw== X-Forwarded-Encrypted: i=1; AJvYcCVs3iLNnn4k3SvCBJ2fzE+ROv87NUHJBLtLnQ3tm+aS07h//NUYD5JfS+eACntI9H3HhRwKgOGNaUu70lxrew==@vger.kernel.org X-Gm-Message-State: AOJu0Ywb9DOrglzD2BgLqPDLX8qw0011TZIZVVQKRgK7k2VuvVA4loTl soLESeAlLeRnWpP83kGGM6Qgn0bCuNo8KIqhFfd4D/11YFVBmnn461fft7rbfIhlYnghwg== X-Gm-Gg: ASbGncvciwXLQ9DMUA2ztR54fkJllGFcVV6nAGuB1A5YxMBrDuxEnFTYiXPqT45cjbT Q50M2gBOBVCXotOM6y8529NlRrgoUKUNU31dyHhxdawfrwiDGbWvHVxqZzFdnjJDFlzu1gwpsCe XCtkk9EvCVfoKggfeNDuL4xb+9LZb2Trhl0bRlUyUnqp5cHr27L24IeXCwAmsT+cyF3R91lbu34 bAKRm24sN39zX0oJrvokZh/J850QTAB4rTuqvBttJyniSBkjttKQl1OqlZfhF9qXnIcITceE5BM Bl8803/2JK95eGq7viP0loj421Xp3GhobhndPPkImQTbjjJsvKpJXobOaT+sA/wHm2+OOuZ+iSV W4Ee2qjGNh6QdDu0yVe3NFtCd2gaueDd9oK05o+K6ZA3ps01nBOY= X-Google-Smtp-Source: AGHT+IHzQMj8c5qJHFR/gXnIa+VhPovTRzVcLhcra+3HhxRfU2Ln+KtDiVxVHnWN0JdyMq1sCbQJyA== X-Received: by 2002:a05:6a20:938c:b0:246:5be:ca90 with SMTP id adf61e73a8af0-24605becdb2mr9234751637.10.1756980094729; Thu, 04 Sep 2025 03:01:34 -0700 (PDT) Received: from nyaos.. (v133-18-108-210.vir.kagoya.net. [133.18.108.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32b747c2d66sm3510656a91.28.2025.09.04.03.01.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 03:01:33 -0700 (PDT) From: ChenMiao To: Linux Kernel , Linux OpenRISC Cc: chenmiao , Jonas Bonn , Stefan Kristiansson , Stafford Horne Subject: [PATCH v4 2/4] openrisc: Add R_OR1K_32_PCREL relocation type module support Date: Thu, 4 Sep 2025 10:00:50 +0000 Message-ID: <20250904100109.688033-3-chenmiao.ku@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250904100109.688033-1-chenmiao.ku@gmail.com> References: <20250904100109.688033-1-chenmiao.ku@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: chenmiao To ensure the proper functioning of the jump_label test module, this patch adds support for the R_OR1K_32_PCREL relocation type. The implementation calculates the PC-relative offset by subtracting the instruction location from the target value and stores the result at the specified location. Signed-off-by: chenmiao --- arch/openrisc/kernel/module.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/openrisc/kernel/module.c b/arch/openrisc/kernel/module.c index c9ff4c4a0b29..4ac4fbaa827c 100644 --- a/arch/openrisc/kernel/module.c +++ b/arch/openrisc/kernel/module.c @@ -55,6 +55,10 @@ int apply_relocate_add(Elf32_Shdr *sechdrs, value |=3D *location & 0xfc000000; *location =3D value; break; + case R_OR1K_32_PCREL: + value -=3D (uint32_t)location; + *location =3D value; + break; case R_OR1K_AHI16: /* Adjust the operand to match with a signed LO16. */ value +=3D 0x8000; --=20 2.45.2 From nobody Fri Oct 3 06:34:58 2025 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (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 1EB8B2F99B5; Thu, 4 Sep 2025 10:01:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980103; cv=none; b=cwNm3qQCTo2eSVSIe7C1rIs9dYV8QpAqlC4OxEeZA71pzqwHN2DU8AOAJQgcq1mrGs7HhxTdDi+6VeJoa6jc1QDlrbEDbuon4Z2Nom1uC/xPjdkao9Uem/gYHpIFpHZ1WCUvAa1VsduEpUN4lr69Zkqe8vQ8w7+GigxLXTjasZM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980103; c=relaxed/simple; bh=AIZqPgluwqpePOPT3MvDMxrsH2xlD8v9qId4APJeL3o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iIm8qGuN4nFmUSp5b8DmlW6z/SrLUS4qwW+SZLbQfqe3nqbnIL77qkKRasCHuzsk/MbE5+Bw5ZsybSAG6Vb5tpHHvtSM4Apzxi9ii+ZaIf1w0MHJtUoIV0xcqKzOcFpH5OrZfH5vNVgkt4Pp77BLggGo3j/hcHY51Z96Qx74zrM= 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=VaBMNMFb; arc=none smtp.client-ip=209.85.215.172 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="VaBMNMFb" Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-b4e84a61055so543415a12.0; Thu, 04 Sep 2025 03:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756980101; x=1757584901; 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=rRBZvA6tPDIGNoeLji756p9DxOWg2MHueudkSvigYAI=; b=VaBMNMFbwXTrQs+zrG67hTFaccSnLByJAb0bUv6xRmONBXpGWfs4/kfisRm6vITSPy EwOQFqjwHsSBu3GYvGZc9O0hbIDYLisnCH9t//CMq2syva4F5rQGGiNdJGnhJGS8WpiE vqltaIVM1vqLKWRv0ium57UKmx4S8BFuatqh0Iuzlohql2BZydMysKrKsJewtfU+I43u NrQAY1wawf49k/81VEcQRc/g1ydEIpfZlZ2RkP9AUv/9VZ5YUe8crMPQ44xaXtAyA+T/ 7KFAxSsviSJQCzd1snjY0BkMLROpWZqo5a5Dq99Ged+cCrH7ZgIuQzMyuC7whKgQAiQj +LNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756980101; x=1757584901; 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=rRBZvA6tPDIGNoeLji756p9DxOWg2MHueudkSvigYAI=; b=lvEtXB6Yhh/LK19/d8TZCBzObMEDrES0Ht9f8HAnD4Kao5t8121NHAJ1PI3GjhGWfM X7KybXbLycRfqpAdrVKCEbGiQYuHuYRyjYzQPgarc3nIxBU7TR2jWq+CRg0ajcutjUZq A0IwlMhKuEv3SsHQrdN1zy23f2GHlTQmdCPU0AoIqN2uT1TetyCZnj9OxfQoewtWTyxN F/wXB0kXuWOG95xawY4fdAwz2j2i3kljHN+pQi1ep0R16pgS+TOduY7Udm0LqxExkBYN di0g8YCJDNlFSfGCYhuxIShIzLtj49nhp8zKazfSb6wslrOy+M+/SD6xPiVIrl6i3U/d NDFA== X-Forwarded-Encrypted: i=1; AJvYcCXcMWwKuvpIlx/Dy2ceipt5OmxJMMW+zA3SUWIb4yurvAqfRkzec3l7ce/rfVJ55MA4ZKWtu0UxZyyp5idUbQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwJMJxiggsYuPxoErywRTa2UeE+aTSCAWLJEBr/8s+4OG3kxOJe i0sDOkb/Ys9StvrZwT1quUDZVN0q4/g3CvXBH5r8itOEPmitT2btWSsD4sy4JftwwN/q4Q== X-Gm-Gg: ASbGncs98yhnkUo1TwBIQoniKc6EdeIP9XoO92mSfdCfhrW8i5TqZj/uC6ZcFE8icKQ nkIjNJn0C4Zp5Fhi5nTzPHRZ3Clf3A1WCTCi/bpQb+zxdK4TTom85moIN3gyfbiz4XFs0EMsFAA MlUBlVsBX/9wNrc8lBWTkU20njpUyF2wHLDD0jnQXes8jl38ILB+tIUs3gwjQrUfS01q8G+g3L+ W0HY0CXCHXbzHnE89MhTO7ZfgmSeSyT6NSH20FJm6SeB6BjCLQ8Ia9z1W4j7QKAUEDucWlSngNL IBMQZXb6g/3sa0CaAf8omX7Tjts2DUj+ms4faW2+xWcMSWfaQ2WPeaCFYOSTAuHjh3vBGOHXtPR GpjTYtX/alKOKmAxyp27VgnEzO9fJF8+CSE7M8MEgFCyLwj+vxGo= X-Google-Smtp-Source: AGHT+IGLYPl3TxMWSwxIUVbUGsljF0qkmh52JVvNkBVe+C640U3h7jC99A2ZKRvMhv7tjxkLCSrUUA== X-Received: by 2002:a17:90b:17cb:b0:327:ea30:b with SMTP id 98e67ed59e1d1-328156baa8bmr26043452a91.18.1756980100728; Thu, 04 Sep 2025 03:01:40 -0700 (PDT) Received: from nyaos.. (v133-18-108-210.vir.kagoya.net. [133.18.108.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32b747c2d66sm3510656a91.28.2025.09.04.03.01.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 03:01:39 -0700 (PDT) From: ChenMiao To: Linux Kernel , Linux OpenRISC Cc: chenmiao , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Masahiro Yamada Subject: [PATCH v4 3/4] openrisc: Regenerate defconfigs. Date: Thu, 4 Sep 2025 10:00:51 +0000 Message-ID: <20250904100109.688033-4-chenmiao.ku@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250904100109.688033-1-chenmiao.ku@gmail.com> References: <20250904100109.688033-1-chenmiao.ku@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: chenmiao Regenerating defconfigs allows subsequent changes to the configs to be related only to the corresponding modifications, without mixing changes from other configs. Signed-off-by: chenmiao --- arch/openrisc/configs/or1ksim_defconfig | 18 ++++++------------ arch/openrisc/configs/virt_defconfig | 1 - 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/arch/openrisc/configs/or1ksim_defconfig b/arch/openrisc/config= s/or1ksim_defconfig index 59fe33cefba2..58e27d8fdb4e 100644 --- a/arch/openrisc/configs/or1ksim_defconfig +++ b/arch/openrisc/configs/or1ksim_defconfig @@ -3,26 +3,22 @@ CONFIG_LOG_BUF_SHIFT=3D14 CONFIG_BLK_DEV_INITRD=3Dy # CONFIG_RD_GZIP is not set CONFIG_EXPERT=3Dy -# CONFIG_KALLSYMS is not set # CONFIG_EPOLL is not set # CONFIG_TIMERFD is not set # CONFIG_EVENTFD is not set # CONFIG_AIO is not set -# CONFIG_VM_EVENT_COUNTERS is not set -# CONFIG_COMPAT_BRK is not set -CONFIG_SLUB=3Dy -CONFIG_SLUB_TINY=3Dy -CONFIG_MODULES=3Dy -# CONFIG_BLOCK is not set +# CONFIG_KALLSYMS is not set CONFIG_BUILTIN_DTB_NAME=3D"or1ksim" CONFIG_HZ_100=3Dy +CONFIG_MODULES=3Dy +# CONFIG_BLOCK is not set +CONFIG_SLUB_TINY=3Dy +# CONFIG_COMPAT_BRK is not set +# CONFIG_VM_EVENT_COUNTERS is not set CONFIG_NET=3Dy CONFIG_PACKET=3Dy CONFIG_UNIX=3Dy CONFIG_INET=3Dy -# CONFIG_INET_XFRM_MODE_TRANSPORT is not set -# CONFIG_INET_XFRM_MODE_TUNNEL is not set -# CONFIG_INET_XFRM_MODE_BEET is not set # CONFIG_INET_DIAG is not set CONFIG_TCP_CONG_ADVANCED=3Dy # CONFIG_TCP_CONG_BIC is not set @@ -35,7 +31,6 @@ CONFIG_DEVTMPFS=3Dy CONFIG_DEVTMPFS_MOUNT=3Dy # CONFIG_PREVENT_FIRMWARE_BUILD is not set # CONFIG_FW_LOADER is not set -CONFIG_PROC_DEVICETREE=3Dy CONFIG_NETDEVICES=3Dy CONFIG_ETHOC=3Dy CONFIG_MICREL_PHY=3Dy @@ -53,4 +48,3 @@ CONFIG_SERIAL_OF_PLATFORM=3Dy # CONFIG_DNOTIFY is not set CONFIG_TMPFS=3Dy CONFIG_NFS_FS=3Dy -# CONFIG_ENABLE_MUST_CHECK is not set diff --git a/arch/openrisc/configs/virt_defconfig b/arch/openrisc/configs/v= irt_defconfig index c1b69166c500..8a581e932766 100644 --- a/arch/openrisc/configs/virt_defconfig +++ b/arch/openrisc/configs/virt_defconfig @@ -55,7 +55,6 @@ CONFIG_DRM=3Dy # CONFIG_DRM_FBDEV_EMULATION is not set CONFIG_DRM_VIRTIO_GPU=3Dy CONFIG_FB=3Dy -CONFIG_FIRMWARE_EDID=3Dy CONFIG_FRAMEBUFFER_CONSOLE=3Dy CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=3Dy CONFIG_LOGO=3Dy --=20 2.45.2 From nobody Fri Oct 3 06:34:58 2025 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 E5CA82F8BDC; Thu, 4 Sep 2025 10:01:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980117; cv=none; b=Xy6HG//ZetAmPeln1zRdoLwMOOqzSnt5dLkmsszs1Ich25bXlvAFzGil8UAzVlkIL7c7YnjnW1AfeD3rq7JzIdatKmCaqPqhKw2x5Daol0kp9ulju3A/LjEAfBfLXroFpImyC4i0cIDCpXn4iecw4q8r26heiYncEi80UKthG1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756980117; c=relaxed/simple; bh=NI2gdVs45WVB1gFpA+90fTTDAN7mr3Doc1EeTEzIFSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DsPijDAbu441Bxaxp/7yniNGVfT2Eyuv7ci4qzWTHmmmz5OyyidlMVh6/faG5LCrGmy4tFyMCmRE6TAVaGwMV6fbqGjjdiqPCmloOToHFU0MHA2h1Cj+xs91ejo5Ww+K2z3fdqSKn0nECUNczXBJWgncmwFCm82OnzEP/VMRMqg= 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=kB86vZ35; arc=none smtp.client-ip=209.85.216.51 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="kB86vZ35" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-32326793a85so577295a91.1; Thu, 04 Sep 2025 03:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1756980114; x=1757584914; 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=2Ux6xZQMdjwKk/vRBn6PyB6Gtcuu2vGEScUhbUr4eb0=; b=kB86vZ35y4Fe2clJkgnjRWOLM5lKzfXQsdOrTBi0zzR/4FYCqO+xr7bwj4k8XNI302 JNAKlpSYVem+XPiAe+irrGWgwg2rNk/Xw2Csn4FxuQtQh5zxMD9gbCXca7PDWQ1JXQ93 sJwQlnYLHajdHffzD2mAsDhWUTzYkNF6MfTL6KqH9Ud6vx2U3uj/Yxz8G561Q/E92WFj IRzhv+iz2papt5tkuXTLOXCM4EUgDV2pzJjCGrW1WbjKrVIYAh3yzNFosbEnZgInqM7g mX/rARZcWBW8NWUFsvKI+MmBLiNraxwgCDnHBIlVXfdfrXIcrGWRQ8hGBR5jPe/DE3gO 0sZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1756980114; x=1757584914; 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=2Ux6xZQMdjwKk/vRBn6PyB6Gtcuu2vGEScUhbUr4eb0=; b=Pws9nVzRyDP7quCFhhzfL+wi03l/3KGP4dP/rqbOngwTIqxQ23WE3nZrltGcoqIZBq Mp7FkudEcQ6cl7112qsBc5yX3pc7+H4/Np28Qbdl9qTBzYTC4SZacg8wa/OvbVM+aitb ygaJcE+T/zWGH1hBH7EyGGWuOsxvEY7pfD06zYlV5rmnTbu0V+96VETBg5/bDCIuPP5l hUXkRkQmz3ZZ/QizpjJUsWSZerHTWdpGE1gunf8uusixaWiG0TOv0JBfVximDR9RfwlI Qy5sR6BtrOd0H9bbg10UAc3FzfKZoAFRJ8I3yGszEwOYOr5R1YphCvx6ke8VoRrXScmM DfhA== X-Forwarded-Encrypted: i=1; AJvYcCWC/vWolXLWGCltZAmaRX+zjGn/X1v/9NxLCj5TSaWh1plZFhC9MefRBkrju0Ez7DTCeO9/Gj8KPO/gBpOjbQw=@vger.kernel.org, AJvYcCXp47d0FMOOY91yhjMo2G49TYKVOj5Eb/ATX6VAnmWcJPQSzX4Dhw1E4AZ6p1buEpcdueRcvRcaA8Y=@vger.kernel.org X-Gm-Message-State: AOJu0YysRqbM+Bnb58pDK3gJAbxCshxMapbpFjjbnPn8b+7jSy+Y49WR RxEbmUS6mq5+qDaXkh1HwwVOJrlBDZiNMxdDHOM7SGM9nNxFczY0wGB4RepoQ8FrANQzaS9i X-Gm-Gg: ASbGncuHx3mIoZbk1O1kGC5+QdYkmVn5oeUQZ6bUYctLmn+j7nwIsCeUQmqJjxegxIW Zzf2hYIMXZvB4C/lKJJrAr1LL5/9zmcyFasj/E12rom882qj9SFC4jS/eOUObycLaCpTt7rShh+ IM7kTobbjf99CfviAy7CjMlY/yD7ZI1XD3W4QntIw9Tq+1eePkbv+9k6xx2yQo1rI80V+myghDa XPl+pdHPUGFKEzfc4f/fngAPHWxlnXLV+daIt89SuLm8wDfsU+Q/e/eYOG4wmNo7XWEhUuCIgAf vEaqDYosOouwDR4yl0ZkMlltZ3ymuO1RK8cC4WQfT0pifxgJOpQ98HdP2u0uazty3LolamFtdLZ WsGiXVIEhkkPhdbfeI+75oJo/GcbpOaZcaYPX5S67MPB94yw616TzRRf7cUXSejfAv9ZjEnqv X-Google-Smtp-Source: AGHT+IHLHyRU6l7Pn1nPlsndiEWAG9LdZv5Q0RUp1kZVGxs0uOrPf5/nJArGnEEw7dCPnZkk6gA/qw== X-Received: by 2002:a17:90b:3d8e:b0:327:e98b:6981 with SMTP id 98e67ed59e1d1-328156e566cmr22489264a91.36.1756980113417; Thu, 04 Sep 2025 03:01:53 -0700 (PDT) Received: from nyaos.. (v133-18-108-210.vir.kagoya.net. [133.18.108.210]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-32b747c2d66sm3510656a91.28.2025.09.04.03.01.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Sep 2025 03:01:52 -0700 (PDT) From: ChenMiao To: Linux Kernel , Linux OpenRISC Cc: chenmiao , Jonathan Corbet , Jonas Bonn , Stefan Kristiansson , Stafford Horne , Peter Zijlstra , Josh Poimboeuf , Jason Baron , Steven Rostedt , Ard Biesheuvel , Masahiro Yamada , Johannes Berg , Nicolas Schier , Sahil Siddiq , linux-doc@vger.kernel.org Subject: [PATCH v4 4/4] openrisc: Add jump label support Date: Thu, 4 Sep 2025 10:00:52 +0000 Message-ID: <20250904100109.688033-5-chenmiao.ku@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250904100109.688033-1-chenmiao.ku@gmail.com> References: <20250904100109.688033-1-chenmiao.ku@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: quoted-printable Content-Type: text/plain; charset="utf-8" From: chenmiao Supported a complete jump_label implementation based on the ARM64 and RV64 version and add the CONFIG_JUMP_LABEL=3Dy to the defconfig. Testing was conducted using a dedicated test module (jump-label-test, provided in the link below) with the following environment: Below is a brief usage and test report of this module. For detailed steps, please refer to the README in the provided link. Link: https://github.com/ChenMiaoi/GSoC-2025-Final-Report/tree/main/tests/j= ump-label-test Test Environment: - Hardware: QEMU emulated OR1K - Kernel Version: 6.17.0-rc3-dirty - Configs: CONFIG_MODULES=3Dy,CONFIG_MODULE_UNLOAD=3Dy - Toolchain: or1k-none-linux-musl-gcc 15.1.0 Test Procedure: 1. Build and install modules (make modules_install) 2. Build the jump-label-test module 3. Boot kernel in QEMU 4. Transfer jump_label_test.ko via NFS 5. Load module and observe results Test Results: $ insmod jump_label_test.ko [ 32.590000] Jump label performance test module loaded [ 35.250000] Normal branch time: 1241327150 ns (124 ns per iteration) [ 35.250000] Jump label (false) time: 706422700 ns (70 ns per iteration) [ 35.250000] Jump label (true) time: 708913450 ns (70 ns per iteration) $ rmmod jump_label_test.ko [ 72.210000] Jump label test module unloaded The results show approximately 43% improvement in branch performance when using jump labels compared to traditional branches. Link: https://lore.kernel.org/openrisc/aK3O6kOMqgDb6zZj@antec/T/#u Signed-off-by: chenmiao --- Changes in V4: - Add appropriate comments. - Added testing for jump_label Changes in V3: - Ensure the two defconfig using the make savedefconfig. - modify the __ASSEMBLY__ to __ASSEMBLER__, modify the __ASM_JUMP_LABEL_H to __ASM_OPENRISC_JUMP_LABEL_H and remove invalid comment. Changes in V2: - using the patch_insn_write(void *addr, u32 insn) not the const void *insn. - add new macro OPENRISC_INSN_NOP in insn-def.h to use. Signed-off-by: chenmiao --- .../core/jump-labels/arch-support.txt | 2 +- arch/openrisc/Kconfig | 2 + arch/openrisc/configs/or1ksim_defconfig | 1 + arch/openrisc/configs/virt_defconfig | 1 + arch/openrisc/include/asm/insn-def.h | 3 + arch/openrisc/include/asm/jump_label.h | 72 +++++++++++++++++++ arch/openrisc/kernel/Makefile | 1 + arch/openrisc/kernel/jump_label.c | 52 ++++++++++++++ arch/openrisc/kernel/setup.c | 2 + 9 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 arch/openrisc/include/asm/jump_label.h create mode 100644 arch/openrisc/kernel/jump_label.c diff --git a/Documentation/features/core/jump-labels/arch-support.txt b/Doc= umentation/features/core/jump-labels/arch-support.txt index ccada815569f..683de7c15058 100644 --- a/Documentation/features/core/jump-labels/arch-support.txt +++ b/Documentation/features/core/jump-labels/arch-support.txt @@ -17,7 +17,7 @@ | microblaze: | TODO | | mips: | ok | | nios2: | TODO | - | openrisc: | TODO | + | openrisc: | ok | | parisc: | ok | | powerpc: | ok | | riscv: | ok | diff --git a/arch/openrisc/Kconfig b/arch/openrisc/Kconfig index b38fee299bc4..9156635dd264 100644 --- a/arch/openrisc/Kconfig +++ b/arch/openrisc/Kconfig @@ -24,6 +24,8 @@ config OPENRISC select GENERIC_PCI_IOMAP select GENERIC_IOREMAP select GENERIC_CPU_DEVICES + select HAVE_ARCH_JUMP_LABEL + select HAVE_ARCH_JUMP_LABEL_RELATIVE select HAVE_PCI select HAVE_UID16 select HAVE_PAGE_SIZE_8KB diff --git a/arch/openrisc/configs/or1ksim_defconfig b/arch/openrisc/config= s/or1ksim_defconfig index 58e27d8fdb4e..769705ac24d5 100644 --- a/arch/openrisc/configs/or1ksim_defconfig +++ b/arch/openrisc/configs/or1ksim_defconfig @@ -10,6 +10,7 @@ CONFIG_EXPERT=3Dy # CONFIG_KALLSYMS is not set CONFIG_BUILTIN_DTB_NAME=3D"or1ksim" CONFIG_HZ_100=3Dy +CONFIG_JUMP_LABEL=3Dy CONFIG_MODULES=3Dy # CONFIG_BLOCK is not set CONFIG_SLUB_TINY=3Dy diff --git a/arch/openrisc/configs/virt_defconfig b/arch/openrisc/configs/v= irt_defconfig index 8a581e932766..a93a3e1e4f87 100644 --- a/arch/openrisc/configs/virt_defconfig +++ b/arch/openrisc/configs/virt_defconfig @@ -12,6 +12,7 @@ CONFIG_NR_CPUS=3D8 CONFIG_SMP=3Dy CONFIG_HZ_100=3Dy # CONFIG_OPENRISC_NO_SPR_SR_DSX is not set +CONFIG_JUMP_LABEL=3Dy # CONFIG_COMPAT_BRK is not set CONFIG_NET=3Dy CONFIG_PACKET=3Dy diff --git a/arch/openrisc/include/asm/insn-def.h b/arch/openrisc/include/a= sm/insn-def.h index e28a9a9604fc..1e0c028a5b95 100644 --- a/arch/openrisc/include/asm/insn-def.h +++ b/arch/openrisc/include/asm/insn-def.h @@ -9,4 +9,7 @@ /* or1k instructions are always 32 bits. */ #define OPENRISC_INSN_SIZE 4 =20 +/* or1k nop instruction code */ +#define OPENRISC_INSN_NOP 0x15000000U + #endif /* __ASM_OPENRISC_INSN_DEF_H */ diff --git a/arch/openrisc/include/asm/jump_label.h b/arch/openrisc/include= /asm/jump_label.h new file mode 100644 index 000000000000..3ec0f4e19f9c --- /dev/null +++ b/arch/openrisc/include/asm/jump_label.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (C) 2025 Chen Miao + * + * Based on arch/arm/include/asm/jump_label.h + */ +#ifndef __ASM_OPENRISC_JUMP_LABEL_H +#define __ASM_OPENRISC_JUMP_LABEL_H + +#ifndef __ASSEMBLER__ + +#include +#include + +#define HAVE_JUMP_LABEL_BATCH + +#define JUMP_LABEL_NOP_SIZE OPENRISC_INSN_SIZE + +/** + * JUMP_TABLE_ENTRY - Create a jump table entry + * @key: Jump key identifier (typically a symbol address) + * @label: Target label address + * + * This macro creates a jump table entry in the dedicated kernel section (= __jump_table). + * Each entry contains the following information: + * Offset from current instruction to jump instruction (1b - .) + * Offset from current instruction to target label (label - .) + * Offset from current instruction to key identifier (key - .) + */ +#define JUMP_TABLE_ENTRY(key, label) \ + ".pushsection __jump_table, \"aw\" \n\t" \ + ".align 4 \n\t" \ + ".long 1b - ., " label " - . \n\t" \ + ".long " key " - . \n\t" \ + ".popsection \n\t" + +#define ARCH_STATIC_BRANCH_ASM(key, label) \ + ".align 4 \n\t" \ + "1: l.nop \n\t" \ + " l.nop \n\t" \ + JUMP_TABLE_ENTRY(key, label) + +static __always_inline bool arch_static_branch(struct static_key *const ke= y, + const bool branch) +{ + asm goto (ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]") + ::"i"(&((char *)key)[branch])::l_yes); + + return false; +l_yes: + return true; +} + +#define ARCH_STATIC_BRANCH_JUMP_ASM(key, label) \ + ".align 4 \n\t" \ + "1: l.j " label " \n\t" \ + " l.nop \n\t" \ + JUMP_TABLE_ENTRY(key, label) + +static __always_inline bool +arch_static_branch_jump(struct static_key *const key, const bool branch) +{ + asm goto (ARCH_STATIC_BRANCH_JUMP_ASM("%0", "%l[l_yes]") + ::"i"(&((char *)key)[branch])::l_yes); + + return false; +l_yes: + return true; +} + +#endif /* __ASSEMBLER__ */ +#endif /* __ASM_OPENRISC_JUMP_LABEL_H */ diff --git a/arch/openrisc/kernel/Makefile b/arch/openrisc/kernel/Makefile index f0957ce16d6b..19e0eb94f2eb 100644 --- a/arch/openrisc/kernel/Makefile +++ b/arch/openrisc/kernel/Makefile @@ -9,6 +9,7 @@ obj-y :=3D head.o setup.o or32_ksyms.o process.o dma.o \ traps.o time.o irq.o entry.o ptrace.o signal.o \ sys_call_table.o unwinder.o cacheinfo.o =20 +obj-$(CONFIG_JUMP_LABEL) +=3D jump_label.o obj-$(CONFIG_SMP) +=3D smp.o sync-timer.o obj-$(CONFIG_STACKTRACE) +=3D stacktrace.o obj-$(CONFIG_MODULES) +=3D module.o diff --git a/arch/openrisc/kernel/jump_label.c b/arch/openrisc/kernel/jump_= label.c new file mode 100644 index 000000000000..071dacad885c --- /dev/null +++ b/arch/openrisc/kernel/jump_label.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2025 Chen Miao + * + * Based on arch/arm/kernel/jump_label.c + */ +#include +#include +#include +#include +#include +#include + +bool arch_jump_label_transform_queue(struct jump_entry *entry, + enum jump_label_type type) +{ + void *addr =3D (void *)jump_entry_code(entry); + u32 insn; + + if (type =3D=3D JUMP_LABEL_JMP) { + long offset; + + offset =3D jump_entry_target(entry) - jump_entry_code(entry); + /* + * The actual maximum range of the l.j instruction's offset is -134,217,= 728 + * ~ 134,217,724 (sign 26-bit imm). + * For the original jump range, we need to right-shift N by 2 to obtain = the + * instruction's offset. + */ + if (unlikely(offset < -134217728 || offset > 134217724)) { + WARN_ON_ONCE(true); + } + /* 26bit imm mask */ + offset =3D (offset >> 2) & 0x03ffffff; + + insn =3D offset; + } else { + insn =3D OPENRISC_INSN_NOP; + } + + if (early_boot_irqs_disabled) { + copy_to_kernel_nofault(addr, &insn, sizeof(insn)); + } else { + patch_insn_write(addr, insn); + } + return true; +} + +void arch_jump_label_transform_apply(void) +{ + kick_all_cpus_sync(); +} diff --git a/arch/openrisc/kernel/setup.c b/arch/openrisc/kernel/setup.c index a9fb9cc6779e..000a9cc10e6f 100644 --- a/arch/openrisc/kernel/setup.c +++ b/arch/openrisc/kernel/setup.c @@ -249,6 +249,8 @@ void __init setup_arch(char **cmdline_p) initrd_below_start_ok =3D 1; } #endif + /* perform jump_table sorting before paging_init locks down read only mem= ory */ + jump_label_init(); =20 /* paging_init() sets up the MMU and marks all pages as reserved */ paging_init(); --=20 2.45.2