From e419ddeabe7edd89650a19f411f928eea12b35b1 Mon Sep 17 00:00:00 2001 From: Greg Ungerer Date: Mon, 13 Nov 2023 23:32:09 +1000 Subject: [PATCH 1/5] m68k: Use kernel's generic muldi3 libgcc function Use the kernels own generic lib/muldi3.c implementation of muldi3 for 68K machines. Some 68K CPUs support 64bit multiplies so move the arch specific umul_ppmm() macro into a header file that is included by lib/muldi3.c. That way it can take advantage of the single instruction when available. There does not appear to be any existing mechanism for the generic lib/muldi3.c code to pick up an external arch definition of umul_ppmm(). Create an arch specific libgcc.h that can optionally be included by the system include/linux/libgcc.h to allow for this. Somewhat oddly there is also a similar definition of umul_ppmm() in the non-architecture code in lib/crypto/mpi/longlong.h for a wide range or machines. Its presence ends up complicating the include setup and means not being able to use something like compiler.h instead. Actually there is a few other defines of umul_ppmm() macros spread around in various architectures, but not directly usable for the m68k case. Signed-off-by: Greg Ungerer Link: https://lore.kernel.org/20231113133209.1367286-1-gerg@linux-m68k.org Reviewed-by: Geert Uytterhoeven Reviewed-by: Arnd Bergmann Signed-off-by: Geert Uytterhoeven --- arch/Kconfig | 8 +++ arch/m68k/Kconfig | 2 + arch/m68k/include/asm/libgcc.h | 20 +++++++ arch/m68k/lib/Makefile | 2 +- arch/m68k/lib/muldi3.c | 97 ---------------------------------- include/linux/libgcc.h | 4 ++ 6 files changed, 35 insertions(+), 98 deletions(-) create mode 100644 arch/m68k/include/asm/libgcc.h delete mode 100644 arch/m68k/lib/muldi3.c diff --git a/arch/Kconfig b/arch/Kconfig index 6682b2a53e34..b8a4ff365582 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -1526,6 +1526,14 @@ config HAVE_ARCH_COMPILER_H linux/compiler-*.h in order to override macro definitions that those headers generally provide. +config HAVE_ARCH_LIBGCC_H + bool + help + An architecture can select this if it provides an + asm/libgcc.h header that should be included after + linux/libgcc.h in order to override macro definitions that + header generally provides. + config HAVE_ARCH_PREL32_RELOCATIONS bool help diff --git a/arch/m68k/Kconfig b/arch/m68k/Kconfig index 7c4f7bcc89d7..b2ed0308c0ea 100644 --- a/arch/m68k/Kconfig +++ b/arch/m68k/Kconfig @@ -23,7 +23,9 @@ config M68K select GENERIC_LIB_ASHLDI3 select GENERIC_LIB_ASHRDI3 select GENERIC_LIB_LSHRDI3 + select GENERIC_LIB_MULDI3 select HAS_IOPORT if PCI || ISA || ATARI_ROM_ISA + select HAVE_ARCH_LIBGCC_H select HAVE_ARCH_SECCOMP select HAVE_ARCH_SECCOMP_FILTER select HAVE_ASM_MODVERSIONS diff --git a/arch/m68k/include/asm/libgcc.h b/arch/m68k/include/asm/libgcc.h new file mode 100644 index 000000000000..1cce6d130d80 --- /dev/null +++ b/arch/m68k/include/asm/libgcc.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_M68K_LIBGCC_H +#define __ASM_M68K_LIBGCC_H + +#ifndef CONFIG_CPU_HAS_NO_MULDIV64 +/* + * For those 68K CPUs that support 64bit multiply define umul_ppm() + * for the common muldi3 libgcc helper function (in lib/muldi3.c). + * CPUs that don't have it (like the original 68000 and ColdFire) + * will fallback to using the C-coded version of umul_ppmm(). + */ +#define umul_ppmm(w1, w0, u, v) \ + __asm__ ("mulu%.l %3,%1:%0" \ + : "=d" ((unsigned long)(w0)), \ + "=d" ((unsigned long)(w1)) \ + : "%0" ((unsigned long)(u)), \ + "dmi" ((unsigned long)(v))) +#endif /* !CONFIG_CPU_HAS_NO_MULDIV64 */ + +#endif /* __ASM_M68K_LIBGCC_H */ diff --git a/arch/m68k/lib/Makefile b/arch/m68k/lib/Makefile index 9158688e6cc6..15278a95259e 100644 --- a/arch/m68k/lib/Makefile +++ b/arch/m68k/lib/Makefile @@ -4,7 +4,7 @@ # Makefile for m68k-specific library files.. # -lib-y := muldi3.o memcpy.o memset.o memmove.o +lib-y := memcpy.o memset.o memmove.o lib-$(CONFIG_MMU) += uaccess.o lib-$(CONFIG_CPU_HAS_NO_MULDIV64) += mulsi3.o divsi3.o udivsi3.o diff --git a/arch/m68k/lib/muldi3.c b/arch/m68k/lib/muldi3.c deleted file mode 100644 index 5012a9b218c7..000000000000 --- a/arch/m68k/lib/muldi3.c +++ /dev/null @@ -1,97 +0,0 @@ -/* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and - gcc-2.7.2.3/longlong.h which is: */ -/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc. - -This file is part of GNU CC. - -GNU CC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2, or (at your option) -any later version. - -GNU CC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. */ - -#include -#include -#include - -#ifdef CONFIG_CPU_HAS_NO_MULDIV64 - -#define SI_TYPE_SIZE 32 -#define __BITS4 (SI_TYPE_SIZE / 4) -#define __ll_B (1L << (SI_TYPE_SIZE / 2)) -#define __ll_lowpart(t) ((USItype) (t) % __ll_B) -#define __ll_highpart(t) ((USItype) (t) / __ll_B) - -#define umul_ppmm(w1, w0, u, v) \ - do { \ - USItype __x0, __x1, __x2, __x3; \ - USItype __ul, __vl, __uh, __vh; \ - \ - __ul = __ll_lowpart (u); \ - __uh = __ll_highpart (u); \ - __vl = __ll_lowpart (v); \ - __vh = __ll_highpart (v); \ - \ - __x0 = (USItype) __ul * __vl; \ - __x1 = (USItype) __ul * __vh; \ - __x2 = (USItype) __uh * __vl; \ - __x3 = (USItype) __uh * __vh; \ - \ - __x1 += __ll_highpart (__x0);/* this can't give carry */ \ - __x1 += __x2; /* but this indeed can */ \ - if (__x1 < __x2) /* did we get it? */ \ - __x3 += __ll_B; /* yes, add it in the proper pos. */ \ - \ - (w1) = __x3 + __ll_highpart (__x1); \ - (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0); \ - } while (0) - -#else - -#define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mulu%.l %3,%1:%0" \ - : "=d" ((USItype)(w0)), \ - "=d" ((USItype)(w1)) \ - : "%0" ((USItype)(u)), \ - "dmi" ((USItype)(v))) - -#endif - -#define __umulsidi3(u, v) \ - ({DIunion __w; \ - umul_ppmm (__w.s.high, __w.s.low, u, v); \ - __w.ll; }) - -typedef int SItype __mode(SI); -typedef unsigned int USItype __mode(SI); -typedef int DItype __mode(DI); -typedef int word_type __mode(__word__); - -struct DIstruct {SItype high, low;}; - -typedef union -{ - struct DIstruct s; - DItype ll; -} DIunion; - -DItype -__muldi3 (DItype u, DItype v) -{ - DIunion w; - DIunion uu, vv; - - uu.ll = u; - vv.ll = v; - - w.ll = __umulsidi3 (uu.s.low, vv.s.low); - w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high - + (USItype) uu.s.high * (USItype) vv.s.low); - - return w.ll; -} -EXPORT_SYMBOL(__muldi3); diff --git a/include/linux/libgcc.h b/include/linux/libgcc.h index fc388da6a027..0d68f9d6a6a7 100644 --- a/include/linux/libgcc.h +++ b/include/linux/libgcc.h @@ -34,4 +34,8 @@ long long notrace __lshrdi3(long long u, word_type b); long long notrace __muldi3(long long u, long long v); word_type notrace __ucmpdi2(unsigned long long a, unsigned long long b); +#ifdef CONFIG_HAVE_ARCH_LIBGCC_H +#include +#endif + #endif /* __ASM_LIBGCC_H */ From f6031436a27c49123d0113444a726348c8f35d10 Mon Sep 17 00:00:00 2001 From: Thorsten Blum Date: Fri, 6 Dec 2024 12:56:32 +0100 Subject: [PATCH 2/5] m68k: atari: Use str_on_off() helper in atari_nvram_proc_read() Remove hard-coded strings by using the str_on_off() helper function. Signed-off-by: Thorsten Blum Reviewed-by: Geert Uytterhoeven Link: https://lore.kernel.org/20241206115634.47332-2-thorsten.blum@linux.dev Signed-off-by: Geert Uytterhoeven --- arch/m68k/atari/nvram.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/m68k/atari/nvram.c b/arch/m68k/atari/nvram.c index 7000d2443aa3..ededc31375c3 100644 --- a/arch/m68k/atari/nvram.c +++ b/arch/m68k/atari/nvram.c @@ -16,7 +16,9 @@ #include #include #include +#include #include + #include #include @@ -198,7 +200,7 @@ static void atari_nvram_proc_read(unsigned char *nvram, struct seq_file *seq, seq_printf(seq, "0x%02x (undefined)\n", nvram[1]); seq_printf(seq, "SCSI arbitration : %s\n", - (nvram[16] & 0x80) ? "on" : "off"); + str_on_off(nvram[16] & 0x80)); seq_puts(seq, "SCSI host ID : "); if (nvram[16] & 0x80) seq_printf(seq, "%d\n", nvram[16] & 7); @@ -236,7 +238,7 @@ static void atari_nvram_proc_read(unsigned char *nvram, struct seq_file *seq, vmode & 16 ? "VGA" : "TV", vmode & 32 ? "PAL" : "NTSC"); seq_printf(seq, " %soverscan, compat. mode %s%s\n", - vmode & 64 ? "" : "no ", vmode & 128 ? "on" : "off", + vmode & 64 ? "" : "no ", str_on_off(vmode & 128), vmode & 256 ? (vmode & 16 ? ", line doubling" : ", half screen") : ""); } From 738fa3feb2e38bb603616093ff2e089f5bf8e103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Wei=C3=9Fschuh?= Date: Mon, 16 Dec 2024 13:30:54 +0100 Subject: [PATCH 3/5] zorro: Constify 'struct bin_attribute' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The sysfs core now allows instances of 'struct bin_attribute' to be moved into read-only memory. Make use of that to protect them against accidental or malicious modifications. Signed-off-by: Thomas Weißschuh Reviewed-by: Geert Uytterhoeven Link: https://lore.kernel.org/20241216-sysfs-const-bin_attr-zorro-v1-1-220a38d49507@weissschuh.net Signed-off-by: Geert Uytterhoeven --- drivers/zorro/zorro-sysfs.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/zorro/zorro-sysfs.c b/drivers/zorro/zorro-sysfs.c index 3d34dba9bb2d..10aedcd21363 100644 --- a/drivers/zorro/zorro-sysfs.c +++ b/drivers/zorro/zorro-sysfs.c @@ -81,7 +81,7 @@ static struct attribute *zorro_device_attrs[] = { }; static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, - struct bin_attribute *bin_attr, + const struct bin_attribute *bin_attr, char *buf, loff_t off, size_t count) { struct zorro_dev *z = to_zorro_dev(kobj_to_dev(kobj)); @@ -98,23 +98,23 @@ static ssize_t zorro_read_config(struct file *filp, struct kobject *kobj, return memory_read_from_buffer(buf, count, &off, &cd, sizeof(cd)); } -static struct bin_attribute zorro_config_attr = { +static const struct bin_attribute zorro_config_attr = { .attr = { .name = "config", .mode = S_IRUGO, }, .size = sizeof(struct ConfigDev), - .read = zorro_read_config, + .read_new = zorro_read_config, }; -static struct bin_attribute *zorro_device_bin_attrs[] = { +static const struct bin_attribute *const zorro_device_bin_attrs[] = { &zorro_config_attr, NULL }; static const struct attribute_group zorro_device_attr_group = { .attrs = zorro_device_attrs, - .bin_attrs = zorro_device_bin_attrs, + .bin_attrs_new = zorro_device_bin_attrs, }; const struct attribute_group *zorro_device_attribute_groups[] = { From 53036937a101b5faeaf98e7438555fa854a1a844 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Tue, 7 Jan 2025 10:58:56 +0100 Subject: [PATCH 4/5] m68k: vga: Fix I/O defines Including m68k's in vga.h on nommu platforms results in conflicting defines with io_no.h for various I/O macros from the __raw_read and __raw_write families. An example error is In file included from arch/m68k/include/asm/vga.h:12, from include/video/vga.h:22, from include/linux/vgaarb.h:34, from drivers/video/aperture.c:12: >> arch/m68k/include/asm/raw_io.h:39: warning: "__raw_readb" redefined 39 | #define __raw_readb in_8 | In file included from arch/m68k/include/asm/io.h:6, from include/linux/io.h:13, from include/linux/irq.h:20, from include/asm-generic/hardirq.h:17, from ./arch/m68k/include/generated/asm/hardirq.h:1, from include/linux/hardirq.h:11, from include/linux/interrupt.h:11, from include/linux/trace_recursion.h:5, from include/linux/ftrace.h:10, from include/linux/kprobes.h:28, from include/linux/kgdb.h:19, from include/linux/fb.h:6, from drivers/video/aperture.c:5: arch/m68k/include/asm/io_no.h:16: note: this is the location of the previous definition 16 | #define __raw_readb(addr) \ | Include , which avoids raw_io.h on nommu platforms. Also change the defined values of some of the read/write symbols in vga.h to __raw_read/__raw_write as the raw_in/raw_out symbols are not generally available. Signed-off-by: Thomas Zimmermann Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202501071629.DNEswlm8-lkp@intel.com/ Fixes: 5c3f968712ce ("m68k/video: Create ") Cc: Geert Uytterhoeven Cc: linux-fbdev@vger.kernel.org Cc: dri-devel@lists.freedesktop.org Cc: Helge Deller Cc: stable@vger.kernel.org # v3.5+ Reviewed-by: Geert Uytterhoeven Link: https://lore.kernel.org/20250107095912.130530-1-tzimmermann@suse.de Signed-off-by: Geert Uytterhoeven --- arch/m68k/include/asm/vga.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/m68k/include/asm/vga.h b/arch/m68k/include/asm/vga.h index 4742e6bc3ab8..cdd414fa8710 100644 --- a/arch/m68k/include/asm/vga.h +++ b/arch/m68k/include/asm/vga.h @@ -9,7 +9,7 @@ */ #ifndef CONFIG_PCI -#include +#include #include /* @@ -29,9 +29,9 @@ #define inw_p(port) 0 #define outb_p(port, val) do { } while (0) #define outw(port, val) do { } while (0) -#define readb raw_inb -#define writeb raw_outb -#define writew raw_outw +#define readb __raw_readb +#define writeb __raw_writeb +#define writew __raw_writew #endif /* CONFIG_PCI */ #endif /* _ASM_M68K_VGA_H */ From bb2e0fb1e6aa9f737d6e0cbcf6494c51180e6d6d Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Wed, 8 Jan 2025 18:22:00 +0100 Subject: [PATCH 5/5] m68k: libgcc: Fix lvalue abuse in umul_ppmm() lib/muldi3.c:53:28: warning: asm output is not an lvalue lib/muldi3.c:53:28: warning: asm output is not an lvalue lib/muldi3.c:53:28: error: not addressable lib/muldi3.c:53:28: warning: generating address of non-lvalue (11) lib/muldi3.c:53:28: warning: generating address of non-lvalue (11) Fix the lvalue warnings by replacing the casts on the output operands by intermediate variables of the right type. Fix the "not addressable" error by replacing the cast on the second input operand by an intermediate variable, too. Treat the other input operand the same for consistency. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202501030516.uZrwnuQQ-lkp@intel.com/ Suggested-by: Linus Torvalds Signed-off-by: Geert Uytterhoeven Acked-by: Greg Ungerer Link: https://lore.kernel.org/c408cfb85bfde8929dcaa4ebea29ade4e1452d8e.1736356696.git.geert@linux-m68k.org --- arch/m68k/include/asm/libgcc.h | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/m68k/include/asm/libgcc.h b/arch/m68k/include/asm/libgcc.h index 1cce6d130d80..27e17195bd7b 100644 --- a/arch/m68k/include/asm/libgcc.h +++ b/arch/m68k/include/asm/libgcc.h @@ -10,11 +10,18 @@ * will fallback to using the C-coded version of umul_ppmm(). */ #define umul_ppmm(w1, w0, u, v) \ - __asm__ ("mulu%.l %3,%1:%0" \ - : "=d" ((unsigned long)(w0)), \ - "=d" ((unsigned long)(w1)) \ - : "%0" ((unsigned long)(u)), \ - "dmi" ((unsigned long)(v))) + do { \ + unsigned long __u = (u), __v = (v); \ + unsigned long __w0, __w1; \ + \ + __asm__ ("mulu%.l %3,%1:%0" \ + : "=d" (__w0), \ + "=d" (__w1) \ + : "%0" (__u), \ + "dmi" (__v)); \ + \ + (w0) = __w0; (w1) = __w1; \ + } while (0) #endif /* !CONFIG_CPU_HAS_NO_MULDIV64 */ #endif /* __ASM_M68K_LIBGCC_H */