linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
@ 2021-03-19 14:34 David Hildenbrand
  2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
                   ` (6 more replies)
  0 siblings, 7 replies; 21+ messages in thread
From: David Hildenbrand @ 2021-03-19 14:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linus Torvalds, Linux API, Liviu Dudau,
	Lorenzo Pieralisi, Luc Van Oostenryck, Luis Chamberlain,
	Matthew Wilcox, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Mike Rapoport, Mikulas Patocka, Minchan Kim,
	Niklas Schnelle, Oleksiy Avramchenko, Palmer Dabbelt,
	Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

Let's start a discussion if /dev/kmem is worth keeping around and
fixing/maintaining or if we should just remove it now for good.

More details / findings in patch #1. Patch #2 and #3 perform minor cleanups
based on removed /dev/kmem support.

Only compile-tested on x86-64 -- good enough for discussing the general
topic (RFC).

David Hildenbrand (3):
  drivers/char: remove /dev/kmem for good
  mm: remove xlate_dev_kmem_ptr()
  mm/vmalloc: remove vwrite()

 Documentation/admin-guide/devices.txt     |   2 +-
 arch/alpha/include/asm/io.h               |   5 -
 arch/arm/configs/dove_defconfig           |   1 -
 arch/arm/configs/magician_defconfig       |   1 -
 arch/arm/configs/moxart_defconfig         |   1 -
 arch/arm/configs/mps2_defconfig           |   1 -
 arch/arm/configs/mvebu_v5_defconfig       |   1 -
 arch/arm/configs/xcep_defconfig           |   1 -
 arch/arm/include/asm/io.h                 |   5 -
 arch/h8300/configs/edosk2674_defconfig    |   1 -
 arch/h8300/configs/h8300h-sim_defconfig   |   1 -
 arch/h8300/configs/h8s-sim_defconfig      |   1 -
 arch/hexagon/configs/comet_defconfig      |   1 -
 arch/hexagon/include/asm/io.h             |   1 -
 arch/ia64/include/asm/io.h                |   1 -
 arch/ia64/include/asm/uaccess.h           |  18 --
 arch/m68k/configs/amcore_defconfig        |   1 -
 arch/m68k/include/asm/io_mm.h             |   5 -
 arch/mips/include/asm/io.h                |   5 -
 arch/openrisc/configs/or1ksim_defconfig   |   1 -
 arch/parisc/include/asm/io.h              |   5 -
 arch/powerpc/include/asm/io.h             |   5 -
 arch/s390/include/asm/io.h                |   5 -
 arch/sh/configs/edosk7705_defconfig       |   1 -
 arch/sh/configs/se7206_defconfig          |   1 -
 arch/sh/configs/sh2007_defconfig          |   1 -
 arch/sh/configs/sh7724_generic_defconfig  |   1 -
 arch/sh/configs/sh7770_generic_defconfig  |   1 -
 arch/sh/configs/sh7785lcr_32bit_defconfig |   1 -
 arch/sh/include/asm/io.h                  |   5 -
 arch/sparc/configs/sparc64_defconfig      |   1 -
 arch/sparc/include/asm/io_64.h            |   5 -
 arch/xtensa/configs/xip_kc705_defconfig   |   1 -
 drivers/char/Kconfig                      |  10 -
 drivers/char/mem.c                        | 231 ----------------------
 include/asm-generic/io.h                  |  11 --
 include/linux/fs.h                        |   2 +-
 include/linux/vmalloc.h                   |   3 +-
 kernel/configs/android-base.config        |   1 -
 mm/ksm.c                                  |   2 +-
 mm/vmalloc.c                              | 113 +----------
 41 files changed, 5 insertions(+), 455 deletions(-)

-- 
2.29.2



^ permalink raw reply	[flat|nested] 21+ messages in thread

* [PATCH RFC 1/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
@ 2021-03-19 14:34 ` David Hildenbrand
  2021-03-22 13:35   ` Michal Hocko
  2021-04-05 17:16   ` Kees Cook
  2021-03-19 14:34 ` [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr() David Hildenbrand
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 21+ messages in thread
From: David Hildenbrand @ 2021-03-19 14:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Andrew Morton, Hillf Danton,
	Michal Hocko, Matthew Wilcox, Oleksiy Avramchenko,
	Steven Rostedt, Minchan Kim, huang ying, Jonathan Corbet,
	Russell King, Liviu Dudau, Sudeep Holla, Lorenzo Pieralisi,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Yoshinori Sato, Brian Cain, Geert Uytterhoeven, Jonas Bonn,
	Stefan Kristiansson, Stafford Horne, Rich Felker,
	David S. Miller, Chris Zankel, Max Filippov, Arnd Bergmann,
	Greg Kroah-Hartman, Alexander Viro, Rob Herring,
	Pavel Machek (CIP),
	Theodore Dubois, Alexander A. Klimov, Pavel Machek, Sam Ravnborg,
	Alexandre Belloni, Andrey Zhizhikin, Randy Dunlap,
	Krzysztof Kozlowski, Viresh Kumar, Eric W. Biederman,
	Thomas Gleixner, Xiaoming Ni, Robert Richter, William Cohen,
	Corentin Labbe, Kairui Song, Linus Torvalds, linux-doc,
	linux-arm-kernel, uclinux-h8-devel, linux-hexagon, linux-m68k,
	openrisc, linux-sh, sparclinux, linux-xtensa, linux-fsdevel,
	Linux API

Exploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and
memory ballooning, I started questioning the existance of /dev/kmem.

Comparing it with the /proc/kcore implementation, it does not seem to be
able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem)
  -> kern_addr_valid(). virt_addr_valid() is not sufficient.
b) Special cases like gart aperture memory that is not to be touched
  -> mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might
fault/crash the machine.

Looks like its existance has been questioned before in 2005 and 2010
[1], after ~11 additional years, it might make sense to revive the
discussion.

CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by
mistake?). All distributions I looked at disable it.

1) /dev/kmem was popular for rootkits [2] before it got disabled
   basically everywhere. Ubuntu documents [3] "There is no modern user of
   /dev/kmem any more beyond attackers using it to load kernel rootkits.".
   RHEL documents in a BZ [5] "it served no practical purpose other than to
   serve as a potential security problem or to enable binary module drivers
   to access structures/functions they shouldn't be touching"

2) /proc/kcore is a decent interface to have a controlled way to read
   kernel memory for debugging puposes. (will need some extensions to
   deal with memory offlining/unplug, memory ballooning, and poisoned
   pages, though)

3) It might be useful for corner case debugging [1]. KDB/KGDB might be a
   better fit, especially, to write random memory; harder to shoot
   yourself into the foot.

4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems
   to be incompatible with 64bit [1]. For educational purposes,
   /proc/kcore might be used to monitor value updates -- or older
   kernels can be used.

5) It's broken on arm64, and therefore, completely disabled there.

Looks like it's essentially unused and has been replaced by better
suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's
just remove it.

[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: huang ying <huang.ying.caritas@gmail.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Liviu Dudau <liviu.dudau@arm.com>
Cc: Sudeep Holla <sudeep.holla@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Gregory Clement <gregory.clement@bootlin.com>
Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Rich Felker <dalias@libc.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Chris Zankel <chris@zankel.net>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Rob Herring <robh@kernel.org>
Cc: "Pavel Machek (CIP)" <pavel@denx.de>
Cc: Theodore Dubois <tblodt@icloud.com>
Cc: "Alexander A. Klimov" <grandmaster@al2klimov.de>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Sam Ravnborg <sam@ravnborg.org>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Andrey Zhizhikin <andrey.zhizhikin@leica-geosystems.com>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Xiaoming Ni <nixiaoming@huawei.com>
Cc: Robert Richter <rric@kernel.org>
Cc: William Cohen <wcohen@redhat.com>
Cc: Corentin Labbe <clabbe@baylibre.com>
Cc: Kairui Song <kasong@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: linux-doc@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: uclinux-h8-devel@lists.sourceforge.jp
Cc: linux-hexagon@vger.kernel.org
Cc: linux-m68k@lists.linux-m68k.org
Cc: openrisc@lists.librecores.org
Cc: linux-sh@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Cc: linux-xtensa@linux-xtensa.org
Cc: linux-fsdevel@vger.kernel.org
Cc: Linux API <linux-api@vger.kernel.org>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 Documentation/admin-guide/devices.txt     |   2 +-
 arch/arm/configs/dove_defconfig           |   1 -
 arch/arm/configs/magician_defconfig       |   1 -
 arch/arm/configs/moxart_defconfig         |   1 -
 arch/arm/configs/mps2_defconfig           |   1 -
 arch/arm/configs/mvebu_v5_defconfig       |   1 -
 arch/arm/configs/xcep_defconfig           |   1 -
 arch/h8300/configs/edosk2674_defconfig    |   1 -
 arch/h8300/configs/h8300h-sim_defconfig   |   1 -
 arch/h8300/configs/h8s-sim_defconfig      |   1 -
 arch/hexagon/configs/comet_defconfig      |   1 -
 arch/m68k/configs/amcore_defconfig        |   1 -
 arch/openrisc/configs/or1ksim_defconfig   |   1 -
 arch/sh/configs/edosk7705_defconfig       |   1 -
 arch/sh/configs/se7206_defconfig          |   1 -
 arch/sh/configs/sh2007_defconfig          |   1 -
 arch/sh/configs/sh7724_generic_defconfig  |   1 -
 arch/sh/configs/sh7770_generic_defconfig  |   1 -
 arch/sh/configs/sh7785lcr_32bit_defconfig |   1 -
 arch/sparc/configs/sparc64_defconfig      |   1 -
 arch/xtensa/configs/xip_kc705_defconfig   |   1 -
 drivers/char/Kconfig                      |  10 -
 drivers/char/mem.c                        | 231 ----------------------
 include/linux/fs.h                        |   2 +-
 include/linux/vmalloc.h                   |   2 +-
 kernel/configs/android-base.config        |   1 -
 mm/ksm.c                                  |   2 +-
 mm/vmalloc.c                              |   2 +-
 28 files changed, 5 insertions(+), 267 deletions(-)

diff --git a/Documentation/admin-guide/devices.txt b/Documentation/admin-guide/devices.txt
index 63fd4e6a014b..beffd5e9130a 100644
--- a/Documentation/admin-guide/devices.txt
+++ b/Documentation/admin-guide/devices.txt
@@ -4,7 +4,7 @@
 
    1 char	Memory devices
 		  1 = /dev/mem		Physical memory access
-		  2 = /dev/kmem		Kernel virtual memory access
+		  2 = /dev/kmem		OBSOLETE - replaced by /proc/kcore
 		  3 = /dev/null		Null device
 		  4 = /dev/port		I/O port access
 		  5 = /dev/zero		Null byte source
diff --git a/arch/arm/configs/dove_defconfig b/arch/arm/configs/dove_defconfig
index e70c997d5f4c..b935162a8bba 100644
--- a/arch/arm/configs/dove_defconfig
+++ b/arch/arm/configs/dove_defconfig
@@ -63,7 +63,6 @@ CONFIG_INPUT_EVDEV=y
 # CONFIG_MOUSE_PS2 is not set
 # CONFIG_SERIO is not set
 CONFIG_LEGACY_PTY_COUNT=16
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_RUNTIME_UARTS=2
diff --git a/arch/arm/configs/magician_defconfig b/arch/arm/configs/magician_defconfig
index b4670d42f378..abde1fb23b20 100644
--- a/arch/arm/configs/magician_defconfig
+++ b/arch/arm/configs/magician_defconfig
@@ -72,7 +72,6 @@ CONFIG_INPUT_TOUCHSCREEN=y
 CONFIG_INPUT_MISC=y
 CONFIG_INPUT_UINPUT=m
 # CONFIG_SERIO is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_PXA=y
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/arm/configs/moxart_defconfig b/arch/arm/configs/moxart_defconfig
index 6834e97af348..eacc089d86c5 100644
--- a/arch/arm/configs/moxart_defconfig
+++ b/arch/arm/configs/moxart_defconfig
@@ -79,7 +79,6 @@ CONFIG_INPUT_EVBUG=y
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_NR_UARTS=1
diff --git a/arch/arm/configs/mps2_defconfig b/arch/arm/configs/mps2_defconfig
index 1d923dbb9928..89f4a6ff30bd 100644
--- a/arch/arm/configs/mps2_defconfig
+++ b/arch/arm/configs/mps2_defconfig
@@ -69,7 +69,6 @@ CONFIG_SMSC911X=y
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
 CONFIG_SERIAL_NONSTANDARD=y
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_MPS2_UART_CONSOLE=y
 CONFIG_SERIAL_MPS2_UART=y
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/arm/configs/mvebu_v5_defconfig b/arch/arm/configs/mvebu_v5_defconfig
index 4f16716bfc32..d57ff30dabff 100644
--- a/arch/arm/configs/mvebu_v5_defconfig
+++ b/arch/arm/configs/mvebu_v5_defconfig
@@ -100,7 +100,6 @@ CONFIG_INPUT_EVDEV=y
 CONFIG_KEYBOARD_GPIO=y
 # CONFIG_INPUT_MOUSE is not set
 CONFIG_LEGACY_PTY_COUNT=16
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_8250_RUNTIME_UARTS=2
diff --git a/arch/arm/configs/xcep_defconfig b/arch/arm/configs/xcep_defconfig
index f1fbdfc5c8c6..4d8e7f2eaef7 100644
--- a/arch/arm/configs/xcep_defconfig
+++ b/arch/arm/configs/xcep_defconfig
@@ -53,7 +53,6 @@ CONFIG_NET_ETHERNET=y
 # CONFIG_INPUT_KEYBOARD is not set
 # CONFIG_INPUT_MOUSE is not set
 # CONFIG_SERIO is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_PXA=y
 CONFIG_SERIAL_PXA_CONSOLE=y
 # CONFIG_LEGACY_PTYS is not set
diff --git a/arch/h8300/configs/edosk2674_defconfig b/arch/h8300/configs/edosk2674_defconfig
index 23791dcf6c25..7137883ff4c7 100644
--- a/arch/h8300/configs/edosk2674_defconfig
+++ b/arch/h8300/configs/edosk2674_defconfig
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y
 # CONFIG_VT is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/h8300/configs/h8300h-sim_defconfig b/arch/h8300/configs/h8300h-sim_defconfig
index 7fc9c2f0acc0..d4e066a1529a 100644
--- a/arch/h8300/configs/h8300h-sim_defconfig
+++ b/arch/h8300/configs/h8300h-sim_defconfig
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y
 # CONFIG_VT is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_EARLYCON=y
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/h8300/configs/h8s-sim_defconfig b/arch/h8300/configs/h8s-sim_defconfig
index 23791dcf6c25..7137883ff4c7 100644
--- a/arch/h8300/configs/h8s-sim_defconfig
+++ b/arch/h8300/configs/h8s-sim_defconfig
@@ -32,7 +32,6 @@ CONFIG_BINFMT_FLAT=y
 # CONFIG_VT is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/hexagon/configs/comet_defconfig b/arch/hexagon/configs/comet_defconfig
index f19ae2ab0aaa..c5a214716a38 100644
--- a/arch/hexagon/configs/comet_defconfig
+++ b/arch/hexagon/configs/comet_defconfig
@@ -34,7 +34,6 @@ CONFIG_NET_ETHERNET=y
 # CONFIG_SERIO is not set
 # CONFIG_CONSOLE_TRANSLATIONS is not set
 CONFIG_LEGACY_PTY_COUNT=64
-# CONFIG_DEVKMEM is not set
 # CONFIG_HW_RANDOM is not set
 CONFIG_SPI=y
 CONFIG_SPI_DEBUG=y
diff --git a/arch/m68k/configs/amcore_defconfig b/arch/m68k/configs/amcore_defconfig
index 3a84f24d41c8..6d9ed2198170 100644
--- a/arch/m68k/configs/amcore_defconfig
+++ b/arch/m68k/configs/amcore_defconfig
@@ -60,7 +60,6 @@ CONFIG_DM9000=y
 # CONFIG_VT is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_DEVMEM is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_MCF=y
 CONFIG_SERIAL_MCF_BAUDRATE=115200
 CONFIG_SERIAL_MCF_CONSOLE=y
diff --git a/arch/openrisc/configs/or1ksim_defconfig b/arch/openrisc/configs/or1ksim_defconfig
index 75f2da324d0e..6e1e004047c7 100644
--- a/arch/openrisc/configs/or1ksim_defconfig
+++ b/arch/openrisc/configs/or1ksim_defconfig
@@ -43,7 +43,6 @@ CONFIG_MICREL_PHY=y
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
 # CONFIG_LEGACY_PTYS is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_8250=y
 CONFIG_SERIAL_8250_CONSOLE=y
 CONFIG_SERIAL_OF_PLATFORM=y
diff --git a/arch/sh/configs/edosk7705_defconfig b/arch/sh/configs/edosk7705_defconfig
index ef7cc31997b1..9ee35269bee2 100644
--- a/arch/sh/configs/edosk7705_defconfig
+++ b/arch/sh/configs/edosk7705_defconfig
@@ -23,7 +23,6 @@ CONFIG_SH_PCLK_FREQ=31250000
 # CONFIG_INPUT is not set
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
-# CONFIG_DEVKMEM is not set
 # CONFIG_UNIX98_PTYS is not set
 # CONFIG_LEGACY_PTYS is not set
 # CONFIG_HW_RANDOM is not set
diff --git a/arch/sh/configs/se7206_defconfig b/arch/sh/configs/se7206_defconfig
index 315b04a8dd2f..601d062250d1 100644
--- a/arch/sh/configs/se7206_defconfig
+++ b/arch/sh/configs/se7206_defconfig
@@ -71,7 +71,6 @@ CONFIG_SMC91X=y
 # CONFIG_INPUT is not set
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_NR_UARTS=4
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
diff --git a/arch/sh/configs/sh2007_defconfig b/arch/sh/configs/sh2007_defconfig
index 99975db461d8..79f02f1c0dc8 100644
--- a/arch/sh/configs/sh2007_defconfig
+++ b/arch/sh/configs/sh2007_defconfig
@@ -75,7 +75,6 @@ CONFIG_INPUT_FF_MEMLESS=y
 # CONFIG_INPUT_MOUSE is not set
 # CONFIG_SERIO is not set
 CONFIG_VT_HW_CONSOLE_BINDING=y
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
 # CONFIG_LEGACY_PTYS is not set
diff --git a/arch/sh/configs/sh7724_generic_defconfig b/arch/sh/configs/sh7724_generic_defconfig
index 2c46c0004780..cbc9389a89a8 100644
--- a/arch/sh/configs/sh7724_generic_defconfig
+++ b/arch/sh/configs/sh7724_generic_defconfig
@@ -18,7 +18,6 @@ CONFIG_CPU_IDLE=y
 # CONFIG_INPUT is not set
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
diff --git a/arch/sh/configs/sh7770_generic_defconfig b/arch/sh/configs/sh7770_generic_defconfig
index 88193153e51b..ee2357deba0f 100644
--- a/arch/sh/configs/sh7770_generic_defconfig
+++ b/arch/sh/configs/sh7770_generic_defconfig
@@ -20,7 +20,6 @@ CONFIG_CPU_IDLE=y
 # CONFIG_INPUT is not set
 # CONFIG_SERIO is not set
 # CONFIG_VT is not set
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
diff --git a/arch/sh/configs/sh7785lcr_32bit_defconfig b/arch/sh/configs/sh7785lcr_32bit_defconfig
index 9b885c14c400..5c725c75fcef 100644
--- a/arch/sh/configs/sh7785lcr_32bit_defconfig
+++ b/arch/sh/configs/sh7785lcr_32bit_defconfig
@@ -66,7 +66,6 @@ CONFIG_INPUT_FF_MEMLESS=m
 CONFIG_INPUT_EVDEV=y
 CONFIG_INPUT_EVBUG=m
 CONFIG_VT_HW_CONSOLE_BINDING=y
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SH_SCI=y
 CONFIG_SERIAL_SH_SCI_NR_UARTS=6
 CONFIG_SERIAL_SH_SCI_CONSOLE=y
diff --git a/arch/sparc/configs/sparc64_defconfig b/arch/sparc/configs/sparc64_defconfig
index 12a4fb0bd52a..18099099583e 100644
--- a/arch/sparc/configs/sparc64_defconfig
+++ b/arch/sparc/configs/sparc64_defconfig
@@ -122,7 +122,6 @@ CONFIG_INPUT_SPARCSPKR=y
 # CONFIG_SERIO_SERPORT is not set
 CONFIG_SERIO_PCIPS2=m
 CONFIG_SERIO_RAW=m
-# CONFIG_DEVKMEM is not set
 CONFIG_SERIAL_SUNSU=y
 CONFIG_SERIAL_SUNSU_CONSOLE=y
 CONFIG_SERIAL_SUNSAB=y
diff --git a/arch/xtensa/configs/xip_kc705_defconfig b/arch/xtensa/configs/xip_kc705_defconfig
index 4f1ff9531f6a..062148e17135 100644
--- a/arch/xtensa/configs/xip_kc705_defconfig
+++ b/arch/xtensa/configs/xip_kc705_defconfig
@@ -72,7 +72,6 @@ CONFIG_MARVELL_PHY=y
 # CONFIG_INPUT_KEYBOARD is not set
 # CONFIG_INPUT_MOUSE is not set
 # CONFIG_SERIO is not set
-CONFIG_DEVKMEM=y
 CONFIG_SERIAL_8250=y
 # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
 CONFIG_SERIAL_8250_CONSOLE=y
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index d229a2d0c017..b151e0fcdeb5 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -334,16 +334,6 @@ config DEVMEM
 	  memory.
 	  When in doubt, say "Y".
 
-config DEVKMEM
-	bool "/dev/kmem virtual device support"
-	# On arm64, VMALLOC_START < PAGE_OFFSET, which confuses kmem read/write
-	depends on !ARM64
-	help
-	  Say Y here if you want to support the /dev/kmem device. The
-	  /dev/kmem device is rarely used, but can be used for certain
-	  kind of kernel debugging operations.
-	  When in doubt, say "N".
-
 config NVRAM
 	tristate "/dev/nvram support"
 	depends on X86 || HAVE_ARCH_NVRAM_OPS
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 869b9f5e8e03..15dc54fa1d47 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -403,221 +403,6 @@ static int mmap_mem(struct file *file, struct vm_area_struct *vma)
 	return 0;
 }
 
-static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
-{
-	unsigned long pfn;
-
-	/* Turn a kernel-virtual address into a physical page frame */
-	pfn = __pa((u64)vma->vm_pgoff << PAGE_SHIFT) >> PAGE_SHIFT;
-
-	/*
-	 * RED-PEN: on some architectures there is more mapped memory than
-	 * available in mem_map which pfn_valid checks for. Perhaps should add a
-	 * new macro here.
-	 *
-	 * RED-PEN: vmalloc is not supported right now.
-	 */
-	if (!pfn_valid(pfn))
-		return -EIO;
-
-	vma->vm_pgoff = pfn;
-	return mmap_mem(file, vma);
-}
-
-/*
- * This function reads the *virtual* memory as seen by the kernel.
- */
-static ssize_t read_kmem(struct file *file, char __user *buf,
-			 size_t count, loff_t *ppos)
-{
-	unsigned long p = *ppos;
-	ssize_t low_count, read, sz;
-	char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
-	int err = 0;
-
-	read = 0;
-	if (p < (unsigned long) high_memory) {
-		low_count = count;
-		if (count > (unsigned long)high_memory - p)
-			low_count = (unsigned long)high_memory - p;
-
-#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
-		/* we don't have page 0 mapped on sparc and m68k.. */
-		if (p < PAGE_SIZE && low_count > 0) {
-			sz = size_inside_page(p, low_count);
-			if (clear_user(buf, sz))
-				return -EFAULT;
-			buf += sz;
-			p += sz;
-			read += sz;
-			low_count -= sz;
-			count -= sz;
-		}
-#endif
-		while (low_count > 0) {
-			sz = size_inside_page(p, low_count);
-
-			/*
-			 * On ia64 if a page has been mapped somewhere as
-			 * uncached, then it must also be accessed uncached
-			 * by the kernel or data corruption may occur
-			 */
-			kbuf = xlate_dev_kmem_ptr((void *)p);
-			if (!virt_addr_valid(kbuf))
-				return -ENXIO;
-
-			if (copy_to_user(buf, kbuf, sz))
-				return -EFAULT;
-			buf += sz;
-			p += sz;
-			read += sz;
-			low_count -= sz;
-			count -= sz;
-			if (should_stop_iteration()) {
-				count = 0;
-				break;
-			}
-		}
-	}
-
-	if (count > 0) {
-		kbuf = (char *)__get_free_page(GFP_KERNEL);
-		if (!kbuf)
-			return -ENOMEM;
-		while (count > 0) {
-			sz = size_inside_page(p, count);
-			if (!is_vmalloc_or_module_addr((void *)p)) {
-				err = -ENXIO;
-				break;
-			}
-			sz = vread(kbuf, (char *)p, sz);
-			if (!sz)
-				break;
-			if (copy_to_user(buf, kbuf, sz)) {
-				err = -EFAULT;
-				break;
-			}
-			count -= sz;
-			buf += sz;
-			read += sz;
-			p += sz;
-			if (should_stop_iteration())
-				break;
-		}
-		free_page((unsigned long)kbuf);
-	}
-	*ppos = p;
-	return read ? read : err;
-}
-
-
-static ssize_t do_write_kmem(unsigned long p, const char __user *buf,
-				size_t count, loff_t *ppos)
-{
-	ssize_t written, sz;
-	unsigned long copied;
-
-	written = 0;
-#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
-	/* we don't have page 0 mapped on sparc and m68k.. */
-	if (p < PAGE_SIZE) {
-		sz = size_inside_page(p, count);
-		/* Hmm. Do something? */
-		buf += sz;
-		p += sz;
-		count -= sz;
-		written += sz;
-	}
-#endif
-
-	while (count > 0) {
-		void *ptr;
-
-		sz = size_inside_page(p, count);
-
-		/*
-		 * On ia64 if a page has been mapped somewhere as uncached, then
-		 * it must also be accessed uncached by the kernel or data
-		 * corruption may occur.
-		 */
-		ptr = xlate_dev_kmem_ptr((void *)p);
-		if (!virt_addr_valid(ptr))
-			return -ENXIO;
-
-		copied = copy_from_user(ptr, buf, sz);
-		if (copied) {
-			written += sz - copied;
-			if (written)
-				break;
-			return -EFAULT;
-		}
-		buf += sz;
-		p += sz;
-		count -= sz;
-		written += sz;
-		if (should_stop_iteration())
-			break;
-	}
-
-	*ppos += written;
-	return written;
-}
-
-/*
- * This function writes to the *virtual* memory as seen by the kernel.
- */
-static ssize_t write_kmem(struct file *file, const char __user *buf,
-			  size_t count, loff_t *ppos)
-{
-	unsigned long p = *ppos;
-	ssize_t wrote = 0;
-	ssize_t virtr = 0;
-	char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
-	int err = 0;
-
-	if (p < (unsigned long) high_memory) {
-		unsigned long to_write = min_t(unsigned long, count,
-					       (unsigned long)high_memory - p);
-		wrote = do_write_kmem(p, buf, to_write, ppos);
-		if (wrote != to_write)
-			return wrote;
-		p += wrote;
-		buf += wrote;
-		count -= wrote;
-	}
-
-	if (count > 0) {
-		kbuf = (char *)__get_free_page(GFP_KERNEL);
-		if (!kbuf)
-			return wrote ? wrote : -ENOMEM;
-		while (count > 0) {
-			unsigned long sz = size_inside_page(p, count);
-			unsigned long n;
-
-			if (!is_vmalloc_or_module_addr((void *)p)) {
-				err = -ENXIO;
-				break;
-			}
-			n = copy_from_user(kbuf, buf, sz);
-			if (n) {
-				err = -EFAULT;
-				break;
-			}
-			vwrite(kbuf, (char *)p, sz);
-			count -= sz;
-			buf += sz;
-			virtr += sz;
-			p += sz;
-			if (should_stop_iteration())
-				break;
-		}
-		free_page((unsigned long)kbuf);
-	}
-
-	*ppos = p;
-	return virtr + wrote ? : err;
-}
-
 static ssize_t read_port(struct file *file, char __user *buf,
 			 size_t count, loff_t *ppos)
 {
@@ -855,7 +640,6 @@ static int open_port(struct inode *inode, struct file *filp)
 #define write_zero	write_null
 #define write_iter_zero	write_iter_null
 #define open_mem	open_port
-#define open_kmem	open_mem
 
 static const struct file_operations __maybe_unused mem_fops = {
 	.llseek		= memory_lseek,
@@ -869,18 +653,6 @@ static const struct file_operations __maybe_unused mem_fops = {
 #endif
 };
 
-static const struct file_operations __maybe_unused kmem_fops = {
-	.llseek		= memory_lseek,
-	.read		= read_kmem,
-	.write		= write_kmem,
-	.mmap		= mmap_kmem,
-	.open		= open_kmem,
-#ifndef CONFIG_MMU
-	.get_unmapped_area = get_unmapped_area_mem,
-	.mmap_capabilities = memory_mmap_capabilities,
-#endif
-};
-
 static const struct file_operations null_fops = {
 	.llseek		= null_lseek,
 	.read		= read_null,
@@ -924,9 +696,6 @@ static const struct memdev {
 } devlist[] = {
 #ifdef CONFIG_DEVMEM
 	 [DEVMEM_MINOR] = { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET },
-#endif
-#ifdef CONFIG_DEVKMEM
-	 [2] = { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET },
 #endif
 	 [3] = { "null", 0666, &null_fops, 0 },
 #ifdef CONFIG_DEVPORT
diff --git a/include/linux/fs.h b/include/linux/fs.h
index ec8f3ddf4a6a..a727186ef4cd 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -144,7 +144,7 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
 /* Expect random access pattern */
 #define FMODE_RANDOM		((__force fmode_t)0x1000)
 
-/* File is huge (eg. /dev/kmem): treat loff_t as unsigned */
+/* File is huge (eg. /dev/mem): treat loff_t as unsigned */
 #define FMODE_UNSIGNED_OFFSET	((__force fmode_t)0x2000)
 
 /* File is opened with O_PATH; almost nothing can be done with it */
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index df92211cf771..390af680e916 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -198,7 +198,7 @@ static inline void set_vm_flush_reset_perms(void *addr)
 }
 #endif
 
-/* for /dev/kmem */
+/* for /proc/kcore */
 extern long vread(char *buf, char *addr, unsigned long count);
 extern long vwrite(char *buf, char *addr, unsigned long count);
 
diff --git a/kernel/configs/android-base.config b/kernel/configs/android-base.config
index d3fd428f4b92..eb701b2ac72f 100644
--- a/kernel/configs/android-base.config
+++ b/kernel/configs/android-base.config
@@ -1,5 +1,4 @@
 #  KEEP ALPHABETICALLY SORTED
-# CONFIG_DEVKMEM is not set
 # CONFIG_DEVMEM is not set
 # CONFIG_FHANDLE is not set
 # CONFIG_INET_LRO is not set
diff --git a/mm/ksm.c b/mm/ksm.c
index 9694ee2c71de..901cab89299d 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -461,7 +461,7 @@ static inline bool ksm_test_exit(struct mm_struct *mm)
  * but taking great care only to touch a ksm page, in a VM_MERGEABLE vma,
  * in case the application has unmapped and remapped mm,addr meanwhile.
  * Could a ksm page appear anywhere else?  Actually yes, in a VM_PFNMAP
- * mmap of /dev/mem or /dev/kmem, where we would not want to touch it.
+ * mmap of /dev/mem, where we would not want to touch it.
  *
  * FAULT_FLAG/FOLL_REMOTE are because we do this outside the context
  * of the process that owns 'vma'.  We also do not want to enforce
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 4f5f8c907897..ccb405b82581 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2875,7 +2875,7 @@ static int aligned_vwrite(char *buf, char *addr, unsigned long count)
  * Note: In usual ops, vread() is never necessary because the caller
  * should know vmalloc() area is valid and can use memcpy().
  * This is for routines which have to access vmalloc area without
- * any information, as /dev/kmem.
+ * any information, as /proc/kcore.
  *
  * Return: number of bytes for which addr and buf should be increased
  * (same number as @count) or %0 if [addr...addr+count) doesn't
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr()
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
  2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
@ 2021-03-19 14:34 ` David Hildenbrand
  2021-03-19 14:54   ` Geert Uytterhoeven
  2021-03-19 14:34 ` [PATCH RFC 3/3] mm/vmalloc: remove vwrite() David Hildenbrand
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand @ 2021-03-19 14:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Richard Henderson, Ivan Kokshaysky,
	Matt Turner, Russell King, Brian Cain, Geert Uytterhoeven,
	Thomas Bogendoerfer, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Yoshinori Sato, Rich Felker, David S. Miller, Arnd Bergmann,
	Andrew Morton, Krzysztof Kozlowski, Mikulas Patocka,
	Luc Van Oostenryck, Mike Rapoport, Palmer Dabbelt,
	Luis Chamberlain, Greentime Hu, Sebastian Andrzej Siewior,
	Randy Dunlap, Jiaxun Yang, Peter Zijlstra (Intel),
	Christophe Leroy, Gerald Schaefer, Niklas Schnelle, Pierre Morel,
	Ingo Molnar, Kuninori Morimoto, linux-alpha, linux-arm-kernel,
	linux-hexagon, linux-ia64, linux-m68k, linux-mips, linux-parisc,
	linuxppc-dev, linux-s390, linux-sh, sparclinux, linux-arch

Since /dev/kmem has been removed, let's remove the xlate_dev_kmem_ptr()
leftovers.

Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Brian Cain <bcain@codeaurora.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: Helge Deller <deller@gmx.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Cc: Rich Felker <dalias@libc.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Mikulas Patocka <mpatocka@redhat.com>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Palmer Dabbelt <palmerdabbelt@google.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Greentime Hu <green.hu@gmail.com>
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: "Peter Zijlstra (Intel)" <peterz@infradead.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Niklas Schnelle <schnelle@linux.ibm.com>
Cc: Pierre Morel <pmorel@linux.ibm.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Cc: linux-alpha@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-hexagon@vger.kernel.org
Cc: linux-ia64@vger.kernel.org
Cc: linux-m68k@lists.linux-m68k.org
Cc: linux-mips@vger.kernel.org
Cc: linux-parisc@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: linux-s390@vger.kernel.org
Cc: linux-sh@vger.kernel.org
Cc: sparclinux@vger.kernel.org
Cc: linux-arch@vger.kernel.org
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/alpha/include/asm/io.h     |  5 -----
 arch/arm/include/asm/io.h       |  5 -----
 arch/hexagon/include/asm/io.h   |  1 -
 arch/ia64/include/asm/io.h      |  1 -
 arch/ia64/include/asm/uaccess.h | 18 ------------------
 arch/m68k/include/asm/io_mm.h   |  5 -----
 arch/mips/include/asm/io.h      |  5 -----
 arch/parisc/include/asm/io.h    |  5 -----
 arch/powerpc/include/asm/io.h   |  5 -----
 arch/s390/include/asm/io.h      |  5 -----
 arch/sh/include/asm/io.h        |  5 -----
 arch/sparc/include/asm/io_64.h  |  5 -----
 include/asm-generic/io.h        | 11 -----------
 13 files changed, 76 deletions(-)

diff --git a/arch/alpha/include/asm/io.h b/arch/alpha/include/asm/io.h
index 1f6a909d1fa5..0fab5ac90775 100644
--- a/arch/alpha/include/asm/io.h
+++ b/arch/alpha/include/asm/io.h
@@ -602,11 +602,6 @@ extern void outsl (unsigned long port, const void *src, unsigned long count);
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #endif /* __KERNEL__ */
 
 #endif /* __ALPHA_IO_H */
diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index fc748122f1e0..f74944c6fe8d 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -430,11 +430,6 @@ extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #include <asm-generic/io.h>
 
 #ifdef CONFIG_MMU
diff --git a/arch/hexagon/include/asm/io.h b/arch/hexagon/include/asm/io.h
index bda2a9c2df78..c33241425a5c 100644
--- a/arch/hexagon/include/asm/io.h
+++ b/arch/hexagon/include/asm/io.h
@@ -64,7 +64,6 @@ static inline void *phys_to_virt(unsigned long address)
  * convert a physical pointer to a virtual kernel pointer for
  * /dev/mem access.
  */
-#define xlate_dev_kmem_ptr(p)    __va(p)
 #define xlate_dev_mem_ptr(p)    __va(p)
 
 /*
diff --git a/arch/ia64/include/asm/io.h b/arch/ia64/include/asm/io.h
index 3d666a11a2de..6d93b923b379 100644
--- a/arch/ia64/include/asm/io.h
+++ b/arch/ia64/include/asm/io.h
@@ -277,7 +277,6 @@ extern void memset_io(volatile void __iomem *s, int c, long n);
 #define memcpy_fromio memcpy_fromio
 #define memcpy_toio memcpy_toio
 #define memset_io memset_io
-#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
 #define xlate_dev_mem_ptr xlate_dev_mem_ptr
 #include <asm-generic/io.h>
 #undef PCI_IOBASE
diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
index 179243c3dfc7..e19d2dcc0ced 100644
--- a/arch/ia64/include/asm/uaccess.h
+++ b/arch/ia64/include/asm/uaccess.h
@@ -272,22 +272,4 @@ xlate_dev_mem_ptr(phys_addr_t p)
 	return ptr;
 }
 
-/*
- * Convert a virtual cached kernel memory pointer to an uncached pointer
- */
-static __inline__ void *
-xlate_dev_kmem_ptr(void *p)
-{
-	struct page *page;
-	void *ptr;
-
-	page = virt_to_page((unsigned long)p);
-	if (PageUncached(page))
-		ptr = (void *)__pa(p) + __IA64_UNCACHED_OFFSET;
-	else
-		ptr = p;
-
-	return ptr;
-}
-
 #endif /* _ASM_IA64_UACCESS_H */
diff --git a/arch/m68k/include/asm/io_mm.h b/arch/m68k/include/asm/io_mm.h
index 819f611dccf2..d41fa488453b 100644
--- a/arch/m68k/include/asm/io_mm.h
+++ b/arch/m68k/include/asm/io_mm.h
@@ -397,11 +397,6 @@ static inline void isa_delay(void)
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #define readb_relaxed(addr)	readb(addr)
 #define readw_relaxed(addr)	readw(addr)
 #define readl_relaxed(addr)	readl(addr)
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 78537aa23500..e6373e7ac892 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -552,11 +552,6 @@ extern void (*_dma_cache_inv)(unsigned long start, unsigned long size);
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 void __ioread64_copy(void *to, const void __iomem *from, size_t count);
 
 #endif /* _ASM_IO_H */
diff --git a/arch/parisc/include/asm/io.h b/arch/parisc/include/asm/io.h
index 8a11b8cf4719..0b5259102319 100644
--- a/arch/parisc/include/asm/io.h
+++ b/arch/parisc/include/asm/io.h
@@ -316,11 +316,6 @@ extern void iowrite64be(u64 val, void __iomem *addr);
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 extern int devmem_is_allowed(unsigned long pfn);
 
 #endif
diff --git a/arch/powerpc/include/asm/io.h b/arch/powerpc/include/asm/io.h
index 273edd208ec5..f130783c8301 100644
--- a/arch/powerpc/include/asm/io.h
+++ b/arch/powerpc/include/asm/io.h
@@ -662,11 +662,6 @@ static inline void name at					\
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 /*
  * We don't do relaxed operations yet, at least not with this semantic
  */
diff --git a/arch/s390/include/asm/io.h b/arch/s390/include/asm/io.h
index 28664ee0abc1..e3882b012bfa 100644
--- a/arch/s390/include/asm/io.h
+++ b/arch/s390/include/asm/io.h
@@ -20,11 +20,6 @@ void *xlate_dev_mem_ptr(phys_addr_t phys);
 #define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
 void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #define IO_SPACE_LIMIT 0
 
 void __iomem *ioremap_prot(phys_addr_t addr, size_t size, unsigned long prot);
diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
index 6d5c6463bc07..cf9a3ec32406 100644
--- a/arch/sh/include/asm/io.h
+++ b/arch/sh/include/asm/io.h
@@ -283,11 +283,6 @@ static inline void __iomem *ioremap_prot(phys_addr_t offset, unsigned long size,
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
 int valid_phys_addr_range(phys_addr_t addr, size_t size);
 int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
diff --git a/arch/sparc/include/asm/io_64.h b/arch/sparc/include/asm/io_64.h
index 9bb27e5c22f1..ff6fe387d78c 100644
--- a/arch/sparc/include/asm/io_64.h
+++ b/arch/sparc/include/asm/io_64.h
@@ -450,11 +450,6 @@ void sbus_set_sbus64(struct device *, int);
  */
 #define xlate_dev_mem_ptr(p)	__va(p)
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#define xlate_dev_kmem_ptr(p)	p
-
 #endif
 
 #endif /* !(__SPARC64_IO_H) */
diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
index c6af40ce03be..33d4746b086f 100644
--- a/include/asm-generic/io.h
+++ b/include/asm-generic/io.h
@@ -1045,17 +1045,6 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
 #endif
 #endif /* CONFIG_GENERIC_IOMAP */
 
-/*
- * Convert a virtual cached pointer to an uncached pointer
- */
-#ifndef xlate_dev_kmem_ptr
-#define xlate_dev_kmem_ptr xlate_dev_kmem_ptr
-static inline void *xlate_dev_kmem_ptr(void *addr)
-{
-	return addr;
-}
-#endif
-
 #ifndef xlate_dev_mem_ptr
 #define xlate_dev_mem_ptr xlate_dev_mem_ptr
 static inline void *xlate_dev_mem_ptr(phys_addr_t addr)
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* [PATCH RFC 3/3] mm/vmalloc: remove vwrite()
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
  2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
  2021-03-19 14:34 ` [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr() David Hildenbrand
@ 2021-03-19 14:34 ` David Hildenbrand
  2021-03-22 13:36   ` Michal Hocko
  2021-03-19 14:45 ` [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand @ 2021-03-19 14:34 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, David Hildenbrand, Andrew Morton, Hillf Danton,
	Michal Hocko, Matthew Wilcox, Oleksiy Avramchenko,
	Steven Rostedt, Minchan Kim, huang ying

The last user (/dev/kmem) is gone. Let's drop it.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Hillf Danton <hdanton@sina.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: huang ying <huang.ying.caritas@gmail.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 include/linux/vmalloc.h |   1 -
 mm/vmalloc.c            | 111 ----------------------------------------
 2 files changed, 112 deletions(-)

diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 390af680e916..9c1b17c7dd95 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -200,7 +200,6 @@ static inline void set_vm_flush_reset_perms(void *addr)
 
 /* for /proc/kcore */
 extern long vread(char *buf, char *addr, unsigned long count);
-extern long vwrite(char *buf, char *addr, unsigned long count);
 
 /*
  *	Internals.  Dont't use..
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index ccb405b82581..07a39881f9d6 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2820,43 +2820,6 @@ static int aligned_vread(char *buf, char *addr, unsigned long count)
 	return copied;
 }
 
-static int aligned_vwrite(char *buf, char *addr, unsigned long count)
-{
-	struct page *p;
-	int copied = 0;
-
-	while (count) {
-		unsigned long offset, length;
-
-		offset = offset_in_page(addr);
-		length = PAGE_SIZE - offset;
-		if (length > count)
-			length = count;
-		p = vmalloc_to_page(addr);
-		/*
-		 * To do safe access to this _mapped_ area, we need
-		 * lock. But adding lock here means that we need to add
-		 * overhead of vmalloc()/vfree() calles for this _debug_
-		 * interface, rarely used. Instead of that, we'll use
-		 * kmap() and get small overhead in this access function.
-		 */
-		if (p) {
-			/*
-			 * we can expect USER0 is not used (see vread/vwrite's
-			 * function description)
-			 */
-			void *map = kmap_atomic(p);
-			memcpy(map + offset, buf, length);
-			kunmap_atomic(map);
-		}
-		addr += length;
-		buf += length;
-		copied += length;
-		count -= length;
-	}
-	return copied;
-}
-
 /**
  * vread() - read vmalloc area in a safe way.
  * @buf:     buffer for reading data
@@ -2936,80 +2899,6 @@ long vread(char *buf, char *addr, unsigned long count)
 	return buflen;
 }
 
-/**
- * vwrite() - write vmalloc area in a safe way.
- * @buf:      buffer for source data
- * @addr:     vm address.
- * @count:    number of bytes to be read.
- *
- * This function checks that addr is a valid vmalloc'ed area, and
- * copy data from a buffer to the given addr. If specified range of
- * [addr...addr+count) includes some valid address, data is copied from
- * proper area of @buf. If there are memory holes, no copy to hole.
- * IOREMAP area is treated as memory hole and no copy is done.
- *
- * If [addr...addr+count) doesn't includes any intersects with alive
- * vm_struct area, returns 0. @buf should be kernel's buffer.
- *
- * Note: In usual ops, vwrite() is never necessary because the caller
- * should know vmalloc() area is valid and can use memcpy().
- * This is for routines which have to access vmalloc area without
- * any information, as /dev/kmem.
- *
- * Return: number of bytes for which addr and buf should be
- * increased (same number as @count) or %0 if [addr...addr+count)
- * doesn't include any intersection with valid vmalloc area
- */
-long vwrite(char *buf, char *addr, unsigned long count)
-{
-	struct vmap_area *va;
-	struct vm_struct *vm;
-	char *vaddr;
-	unsigned long n, buflen;
-	int copied = 0;
-
-	/* Don't allow overflow */
-	if ((unsigned long) addr + count < count)
-		count = -(unsigned long) addr;
-	buflen = count;
-
-	spin_lock(&vmap_area_lock);
-	list_for_each_entry(va, &vmap_area_list, list) {
-		if (!count)
-			break;
-
-		if (!va->vm)
-			continue;
-
-		vm = va->vm;
-		vaddr = (char *) vm->addr;
-		if (addr >= vaddr + get_vm_area_size(vm))
-			continue;
-		while (addr < vaddr) {
-			if (count == 0)
-				goto finished;
-			buf++;
-			addr++;
-			count--;
-		}
-		n = vaddr + get_vm_area_size(vm) - addr;
-		if (n > count)
-			n = count;
-		if (!(vm->flags & VM_IOREMAP)) {
-			aligned_vwrite(buf, addr, n);
-			copied++;
-		}
-		buf += n;
-		addr += n;
-		count -= n;
-	}
-finished:
-	spin_unlock(&vmap_area_lock);
-	if (!copied)
-		return 0;
-	return buflen;
-}
-
 /**
  * remap_vmalloc_range_partial - map vmalloc pages to userspace
  * @vma:		vma to cover
-- 
2.29.2



^ permalink raw reply related	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
                   ` (2 preceding siblings ...)
  2021-03-19 14:34 ` [PATCH RFC 3/3] mm/vmalloc: remove vwrite() David Hildenbrand
@ 2021-03-19 14:45 ` David Hildenbrand
  2021-03-19 17:14 ` Linus Torvalds
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2021-03-19 14:45 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-mm, Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linus Torvalds, Linux API, Liviu Dudau,
	Lorenzo Pieralisi, Luc Van Oostenryck, Luis Chamberlain,
	Matthew Wilcox, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Mike Rapoport, Mikulas Patocka, Minchan Kim,
	Niklas Schnelle, Oleksiy Avramchenko, Palmer Dabbelt,
	Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On 19.03.21 15:34, David Hildenbrand wrote:
> Let's start a discussion if /dev/kmem is worth keeping around and
> fixing/maintaining or if we should just remove it now for good.
> 
> More details / findings in patch #1. Patch #2 and #3 perform minor cleanups
> based on removed /dev/kmem support.

As some arch maintainers are only cced on patch #2 (grml), patch #1 is

https://lkml.kernel.org/r/20210319143452.25948-2-david@redhat.com

and the description is:

"
Exploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and
memory ballooning, I started questioning the existance of /dev/kmem.

Comparing it with the /proc/kcore implementation, it does not seem to be
able to deal with things like
a) Pages unmapped from the direct mapping (e.g., to be used by secretmem)
   -> kern_addr_valid(). virt_addr_valid() is not sufficient.
b) Special cases like gart aperture memory that is not to be touched
   -> mem_pfn_is_ram()
Unless I am missing something, it's at least broken in some cases and might
fault/crash the machine.

Looks like its existance has been questioned before in 2005 and 2010
[1], after ~11 additional years, it might make sense to revive the
discussion.

CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by
mistake?). All distributions I looked at disable it.

1) /dev/kmem was popular for rootkits [2] before it got disabled
    basically everywhere. Ubuntu documents [3] "There is no modern user of
    /dev/kmem any more beyond attackers using it to load kernel rootkits.".
    RHEL documents in a BZ [5] "it served no practical purpose other than to
    serve as a potential security problem or to enable binary module drivers
    to access structures/functions they shouldn't be touching"

2) /proc/kcore is a decent interface to have a controlled way to read
    kernel memory for debugging puposes. (will need some extensions to
    deal with memory offlining/unplug, memory ballooning, and poisoned
    pages, though)

3) It might be useful for corner case debugging [1]. KDB/KGDB might be a
    better fit, especially, to write random memory; harder to shoot
    yourself into the foot.

4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems
    to be incompatible with 64bit [1]. For educational purposes,
    /proc/kcore might be used to monitor value updates -- or older
    kernels can be used.

5) It's broken on arm64, and therefore, completely disabled there.

Looks like it's essentially unused and has been replaced by better
suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's
just remove it.

[1] https://lwn.net/Articles/147901/
[2] https://www.linuxjournal.com/article/10505
[3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
[4] https://sourceforge.net/projects/kme/
[5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
"

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr()
  2021-03-19 14:34 ` [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr() David Hildenbrand
@ 2021-03-19 14:54   ` Geert Uytterhoeven
  0 siblings, 0 replies; 21+ messages in thread
From: Geert Uytterhoeven @ 2021-03-19 14:54 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Linux Kernel Mailing List, Linux MM, Richard Henderson,
	Ivan Kokshaysky, Matt Turner, Russell King, Brian Cain,
	Thomas Bogendoerfer, James E.J. Bottomley, Helge Deller,
	Michael Ellerman, Benjamin Herrenschmidt, Paul Mackerras,
	Heiko Carstens, Vasily Gorbik, Christian Borntraeger,
	Yoshinori Sato, Rich Felker, David S. Miller, Arnd Bergmann,
	Andrew Morton, Krzysztof Kozlowski, Mikulas Patocka,
	Luc Van Oostenryck, Mike Rapoport, Palmer Dabbelt,
	Luis Chamberlain, Greentime Hu, Sebastian Andrzej Siewior,
	Randy Dunlap, Jiaxun Yang, Peter Zijlstra (Intel),
	Christophe Leroy, Gerald Schaefer, Niklas Schnelle, Pierre Morel,
	Ingo Molnar, Kuninori Morimoto, alpha, Linux ARM,
	open list:QUALCOMM HEXAGON...,
	linux-ia64, linux-m68k, open list:BROADCOM NVRAM DRIVER,
	Parisc List, linuxppc-dev, linux-s390, Linux-sh list, sparclinux,
	Linux-Arch

On Fri, Mar 19, 2021 at 3:36 PM David Hildenbrand <david@redhat.com> wrote:
> Since /dev/kmem has been removed, let's remove the xlate_dev_kmem_ptr()
> leftovers.

> Signed-off-by: David Hildenbrand <david@redhat.com>

>  arch/m68k/include/asm/io_mm.h   |  5 -----

Acked-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
                   ` (3 preceding siblings ...)
  2021-03-19 14:45 ` [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
@ 2021-03-19 17:14 ` Linus Torvalds
  2021-03-19 17:33   ` Sebastian Andrzej Siewior
                     ` (3 more replies)
  2021-03-19 18:10 ` Steven Rostedt
  2021-03-23 13:16 ` Greg Kroah-Hartman
  6 siblings, 4 replies; 21+ messages in thread
From: Linus Torvalds @ 2021-03-19 17:14 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: Linux Kernel Mailing List, Linux-MM, Alexander A. Klimov,
	Alexander Viro, Alexandre Belloni, Andrew Lunn, Andrew Morton,
	Andrey Zhizhikin, Arnd Bergmann, Benjamin Herrenschmidt,
	Brian Cain, Christian Borntraeger, Christophe Leroy,
	Chris Zankel, Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Mike Rapoport, Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
>
> Let's start a discussion if /dev/kmem is worth keeping around and
> fixing/maintaining or if we should just remove it now for good.

I'll happily do this for the next merge window, but would really want
distros to confirm that they don't enable it.

I can confirm that it's certainly not enabled on any of the machines I
have, but..

             Linus


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 17:14 ` Linus Torvalds
@ 2021-03-19 17:33   ` Sebastian Andrzej Siewior
  2021-03-31 15:08     ` Enrico Weigelt, metux IT consult
  2021-03-19 18:55   ` James Troup
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Sebastian Andrzej Siewior @ 2021-03-19 17:33 UTC (permalink / raw)
  To: Linus Torvalds, carnil
  Cc: David Hildenbrand, Linux Kernel Mailing List, Linux-MM,
	Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Mike Rapoport, Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Hesselbarth, Stafford Horne, Stefan Kristiansson,
	Steven Rostedt, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On 2021-03-19 10:14:02 [-0700], Linus Torvalds wrote:
> On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
> >
> > Let's start a discussion if /dev/kmem is worth keeping around and
> > fixing/maintaining or if we should just remove it now for good.
> 
> I'll happily do this for the next merge window, but would really want
> distros to confirm that they don't enable it.
> 
> I can confirm that it's certainly not enabled on any of the machines I
> have, but..

Debian has CONFIG_DEVKMEM disabled since 2.6.31.

>              Linus

Sebastian


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
                   ` (4 preceding siblings ...)
  2021-03-19 17:14 ` Linus Torvalds
@ 2021-03-19 18:10 ` Steven Rostedt
  2021-03-22 10:08   ` David Hildenbrand
  2021-03-23 13:16 ` Greg Kroah-Hartman
  6 siblings, 1 reply; 21+ messages in thread
From: Steven Rostedt @ 2021-03-19 18:10 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linus Torvalds, Linux API, Liviu Dudau,
	Lorenzo Pieralisi, Luc Van Oostenryck, Luis Chamberlain,
	Matthew Wilcox, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Mike Rapoport, Mikulas Patocka, Minchan Kim,
	Niklas Schnelle, Oleksiy Avramchenko, Palmer Dabbelt,
	Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On Fri, 19 Mar 2021 15:34:49 +0100
David Hildenbrand <david@redhat.com> wrote:

> Let's start a discussion if /dev/kmem is worth keeping around and
> fixing/maintaining or if we should just remove it now for good.

The last time I used /dev/kmem was in 2003. While in Germany, my home
firewall (in the US) got rooted. I could ssh into the box but had no way to
shut it down because the rootkit took over all those commands (luckily it
still allowed me to become root). I finally killed the box with:

 # ls -lR / > /dev/kmem

 ;-)

But today I have other means of killing the box (or at least crippling it).
Thus, it's obsolete in my book.

-- Steve


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 17:14 ` Linus Torvalds
  2021-03-19 17:33   ` Sebastian Andrzej Siewior
@ 2021-03-19 18:55   ` James Troup
  2021-03-22  9:57   ` David Hildenbrand
  2021-03-22 13:34   ` Michal Hocko
  3 siblings, 0 replies; 21+ messages in thread
From: James Troup @ 2021-03-19 18:55 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: David Hildenbrand, Linux Kernel Mailing List, Linux-MM,
	Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Mike Rapoport, Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

Linus Torvalds <torvalds@linux-foundation.org> writes:

> On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
>>
>> Let's start a discussion if /dev/kmem is worth keeping around and
>> fixing/maintaining or if we should just remove it now for good.
>
> I'll happily do this for the next merge window, but would really want
> distros to confirm that they don't enable it.

FWIW, it's been disabled in Ubuntu for over 10 years now:

 https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled

-- 
James


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 17:14 ` Linus Torvalds
  2021-03-19 17:33   ` Sebastian Andrzej Siewior
  2021-03-19 18:55   ` James Troup
@ 2021-03-22  9:57   ` David Hildenbrand
  2021-03-22 13:34   ` Michal Hocko
  3 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2021-03-22  9:57 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: Linux Kernel Mailing List, Linux-MM, Alexander A. Klimov,
	Alexander Viro, Alexandre Belloni, Andrew Lunn, Andrew Morton,
	Andrey Zhizhikin, Arnd Bergmann, Benjamin Herrenschmidt,
	Brian Cain, Christian Borntraeger, Christophe Leroy,
	Chris Zankel, Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Mike Rapoport, Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On 19.03.21 18:14, Linus Torvalds wrote:
> On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
>>
>> Let's start a discussion if /dev/kmem is worth keeping around and
>> fixing/maintaining or if we should just remove it now for good.
> 
> I'll happily do this for the next merge window, but would really want
> distros to confirm that they don't enable it.
> 

Thanks, let's wait if someone speaks up. I'll add any details that come 
up to patch #1 and resend before the next merge window, properly 
compile-testing on other archs.

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 18:10 ` Steven Rostedt
@ 2021-03-22 10:08   ` David Hildenbrand
  2021-03-22 15:18     ` Steven Rostedt
  0 siblings, 1 reply; 21+ messages in thread
From: David Hildenbrand @ 2021-03-22 10:08 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: linux-kernel, linux-mm, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linus Torvalds, Linux API, Liviu Dudau,
	Lorenzo Pieralisi, Luc Van Oostenryck, Luis Chamberlain,
	Matthew Wilcox, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Mike Rapoport, Mikulas Patocka, Minchan Kim,
	Niklas Schnelle, Oleksiy Avramchenko, Palmer Dabbelt,
	Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On 19.03.21 19:10, Steven Rostedt wrote:
> On Fri, 19 Mar 2021 15:34:49 +0100
> David Hildenbrand <david@redhat.com> wrote:
> 
>> Let's start a discussion if /dev/kmem is worth keeping around and
>> fixing/maintaining or if we should just remove it now for good.
> 
> The last time I used /dev/kmem was in 2003. While in Germany, my home
> firewall (in the US) got rooted. I could ssh into the box but had no way to
> shut it down because the rootkit took over all those commands (luckily it
> still allowed me to become root). I finally killed the box with:
> 
>   # ls -lR / > /dev/kmem
> 
>   ;-)


Wonder if "echo c > /proc/sysrq-trigger" already existed and would have 
worked back then. :)


-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 17:14 ` Linus Torvalds
                     ` (2 preceding siblings ...)
  2021-03-22  9:57   ` David Hildenbrand
@ 2021-03-22 13:34   ` Michal Hocko
  3 siblings, 0 replies; 21+ messages in thread
From: Michal Hocko @ 2021-03-22 13:34 UTC (permalink / raw)
  To: Linus Torvalds
  Cc: David Hildenbrand, Linux Kernel Mailing List, Linux-MM,
	Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Mike Rapoport,
	Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On Fri 19-03-21 10:14:02, Linus Torvalds wrote:
> On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
> >
> > Let's start a discussion if /dev/kmem is worth keeping around and
> > fixing/maintaining or if we should just remove it now for good.
> 
> I'll happily do this for the next merge window, but would really want
> distros to confirm that they don't enable it.

SLES (starting from 15sp2) and OpenSUSE kernels have it disabled as well.
-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 1/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
@ 2021-03-22 13:35   ` Michal Hocko
  2021-04-05 17:16   ` Kees Cook
  1 sibling, 0 replies; 21+ messages in thread
From: Michal Hocko @ 2021-03-22 13:35 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Andrew Morton, Hillf Danton,
	Matthew Wilcox, Oleksiy Avramchenko, Steven Rostedt, Minchan Kim,
	huang ying, Jonathan Corbet, Russell King, Liviu Dudau,
	Sudeep Holla, Lorenzo Pieralisi, Andrew Lunn, Gregory Clement,
	Sebastian Hesselbarth, Yoshinori Sato, Brian Cain,
	Geert Uytterhoeven, Jonas Bonn, Stefan Kristiansson,
	Stafford Horne, Rich Felker, David S. Miller, Chris Zankel,
	Max Filippov, Arnd Bergmann, Greg Kroah-Hartman, Alexander Viro,
	Rob Herring, Pavel Machek (CIP),
	Theodore Dubois, Alexander A. Klimov, Pavel Machek, Sam Ravnborg,
	Alexandre Belloni, Andrey Zhizhikin, Randy Dunlap,
	Krzysztof Kozlowski, Viresh Kumar, Eric W. Biederman,
	Thomas Gleixner, Xiaoming Ni, Robert Richter, William Cohen,
	Corentin Labbe, Kairui Song, Linus Torvalds, linux-doc,
	linux-arm-kernel, uclinux-h8-devel, linux-hexagon, linux-m68k,
	openrisc, linux-sh, sparclinux, linux-xtensa, linux-fsdevel,
	Linux API

On Fri 19-03-21 15:34:50, David Hildenbrand wrote:
> Exploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and
> memory ballooning, I started questioning the existance of /dev/kmem.
> 
> Comparing it with the /proc/kcore implementation, it does not seem to be
> able to deal with things like
> a) Pages unmapped from the direct mapping (e.g., to be used by secretmem)
>   -> kern_addr_valid(). virt_addr_valid() is not sufficient.
> b) Special cases like gart aperture memory that is not to be touched
>   -> mem_pfn_is_ram()
> Unless I am missing something, it's at least broken in some cases and might
> fault/crash the machine.
> 
> Looks like its existance has been questioned before in 2005 and 2010
> [1], after ~11 additional years, it might make sense to revive the
> discussion.
> 
> CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by
> mistake?). All distributions I looked at disable it.
> 
> 1) /dev/kmem was popular for rootkits [2] before it got disabled
>    basically everywhere. Ubuntu documents [3] "There is no modern user of
>    /dev/kmem any more beyond attackers using it to load kernel rootkits.".
>    RHEL documents in a BZ [5] "it served no practical purpose other than to
>    serve as a potential security problem or to enable binary module drivers
>    to access structures/functions they shouldn't be touching"
> 
> 2) /proc/kcore is a decent interface to have a controlled way to read
>    kernel memory for debugging puposes. (will need some extensions to
>    deal with memory offlining/unplug, memory ballooning, and poisoned
>    pages, though)
> 
> 3) It might be useful for corner case debugging [1]. KDB/KGDB might be a
>    better fit, especially, to write random memory; harder to shoot
>    yourself into the foot.
> 
> 4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems
>    to be incompatible with 64bit [1]. For educational purposes,
>    /proc/kcore might be used to monitor value updates -- or older
>    kernels can be used.
> 
> 5) It's broken on arm64, and therefore, completely disabled there.
> 
> Looks like it's essentially unused and has been replaced by better
> suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's
> just remove it.
> 
> [1] https://lwn.net/Articles/147901/
> [2] https://www.linuxjournal.com/article/10505
> [3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
> [4] https://sourceforge.net/projects/kme/
> [5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Hillf Danton <hdanton@sina.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: huang ying <huang.ying.caritas@gmail.com>
> Cc: Jonathan Corbet <corbet@lwn.net>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Liviu Dudau <liviu.dudau@arm.com>
> Cc: Sudeep Holla <sudeep.holla@arm.com>
> Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
> Cc: Andrew Lunn <andrew@lunn.ch>
> Cc: Gregory Clement <gregory.clement@bootlin.com>
> Cc: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
> Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
> Cc: Brian Cain <bcain@codeaurora.org>
> Cc: Geert Uytterhoeven <geert@linux-m68k.org>
> Cc: Jonas Bonn <jonas@southpole.se>
> Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
> Cc: Stafford Horne <shorne@gmail.com>
> Cc: Rich Felker <dalias@libc.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: Chris Zankel <chris@zankel.net>
> Cc: Max Filippov <jcmvbkbc@gmail.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Alexander Viro <viro@zeniv.linux.org.uk>
> Cc: Rob Herring <robh@kernel.org>
> Cc: "Pavel Machek (CIP)" <pavel@denx.de>
> Cc: Theodore Dubois <tblodt@icloud.com>
> Cc: "Alexander A. Klimov" <grandmaster@al2klimov.de>
> Cc: Pavel Machek <pavel@ucw.cz>
> Cc: Sam Ravnborg <sam@ravnborg.org>
> Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
> Cc: Andrey Zhizhikin <andrey.zhizhikin@leica-geosystems.com>
> Cc: Randy Dunlap <rdunlap@infradead.org>
> Cc: Krzysztof Kozlowski <krzk@kernel.org>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Cc: "Eric W. Biederman" <ebiederm@xmission.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Xiaoming Ni <nixiaoming@huawei.com>
> Cc: Robert Richter <rric@kernel.org>
> Cc: William Cohen <wcohen@redhat.com>
> Cc: Corentin Labbe <clabbe@baylibre.com>
> Cc: Kairui Song <kasong@redhat.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: linux-doc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-arm-kernel@lists.infradead.org
> Cc: uclinux-h8-devel@lists.sourceforge.jp
> Cc: linux-hexagon@vger.kernel.org
> Cc: linux-m68k@lists.linux-m68k.org
> Cc: openrisc@lists.librecores.org
> Cc: linux-sh@vger.kernel.org
> Cc: sparclinux@vger.kernel.org
> Cc: linux-xtensa@linux-xtensa.org
> Cc: linux-fsdevel@vger.kernel.org
> Cc: Linux API <linux-api@vger.kernel.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Acked-by: Michal Hocko <mhocko@suse.com>
-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 3/3] mm/vmalloc: remove vwrite()
  2021-03-19 14:34 ` [PATCH RFC 3/3] mm/vmalloc: remove vwrite() David Hildenbrand
@ 2021-03-22 13:36   ` Michal Hocko
  0 siblings, 0 replies; 21+ messages in thread
From: Michal Hocko @ 2021-03-22 13:36 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Andrew Morton, Hillf Danton,
	Matthew Wilcox, Oleksiy Avramchenko, Steven Rostedt, Minchan Kim,
	huang ying

On Fri 19-03-21 15:34:52, David Hildenbrand wrote:
> The last user (/dev/kmem) is gone. Let's drop it.
> 
> Cc: Andrew Morton <akpm@linux-foundation.org>
> Cc: Hillf Danton <hdanton@sina.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Matthew Wilcox <willy@infradead.org>
> Cc: Oleksiy Avramchenko <oleksiy.avramchenko@sonymobile.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: huang ying <huang.ying.caritas@gmail.com>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Acked-by: Michal Hocko <mhocko@suse.com>

> ---
>  include/linux/vmalloc.h |   1 -
>  mm/vmalloc.c            | 111 ----------------------------------------
>  2 files changed, 112 deletions(-)
> 
> diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
> index 390af680e916..9c1b17c7dd95 100644
> --- a/include/linux/vmalloc.h
> +++ b/include/linux/vmalloc.h
> @@ -200,7 +200,6 @@ static inline void set_vm_flush_reset_perms(void *addr)
>  
>  /* for /proc/kcore */
>  extern long vread(char *buf, char *addr, unsigned long count);
> -extern long vwrite(char *buf, char *addr, unsigned long count);
>  
>  /*
>   *	Internals.  Dont't use..
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index ccb405b82581..07a39881f9d6 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2820,43 +2820,6 @@ static int aligned_vread(char *buf, char *addr, unsigned long count)
>  	return copied;
>  }
>  
> -static int aligned_vwrite(char *buf, char *addr, unsigned long count)
> -{
> -	struct page *p;
> -	int copied = 0;
> -
> -	while (count) {
> -		unsigned long offset, length;
> -
> -		offset = offset_in_page(addr);
> -		length = PAGE_SIZE - offset;
> -		if (length > count)
> -			length = count;
> -		p = vmalloc_to_page(addr);
> -		/*
> -		 * To do safe access to this _mapped_ area, we need
> -		 * lock. But adding lock here means that we need to add
> -		 * overhead of vmalloc()/vfree() calles for this _debug_
> -		 * interface, rarely used. Instead of that, we'll use
> -		 * kmap() and get small overhead in this access function.
> -		 */
> -		if (p) {
> -			/*
> -			 * we can expect USER0 is not used (see vread/vwrite's
> -			 * function description)
> -			 */
> -			void *map = kmap_atomic(p);
> -			memcpy(map + offset, buf, length);
> -			kunmap_atomic(map);
> -		}
> -		addr += length;
> -		buf += length;
> -		copied += length;
> -		count -= length;
> -	}
> -	return copied;
> -}
> -
>  /**
>   * vread() - read vmalloc area in a safe way.
>   * @buf:     buffer for reading data
> @@ -2936,80 +2899,6 @@ long vread(char *buf, char *addr, unsigned long count)
>  	return buflen;
>  }
>  
> -/**
> - * vwrite() - write vmalloc area in a safe way.
> - * @buf:      buffer for source data
> - * @addr:     vm address.
> - * @count:    number of bytes to be read.
> - *
> - * This function checks that addr is a valid vmalloc'ed area, and
> - * copy data from a buffer to the given addr. If specified range of
> - * [addr...addr+count) includes some valid address, data is copied from
> - * proper area of @buf. If there are memory holes, no copy to hole.
> - * IOREMAP area is treated as memory hole and no copy is done.
> - *
> - * If [addr...addr+count) doesn't includes any intersects with alive
> - * vm_struct area, returns 0. @buf should be kernel's buffer.
> - *
> - * Note: In usual ops, vwrite() is never necessary because the caller
> - * should know vmalloc() area is valid and can use memcpy().
> - * This is for routines which have to access vmalloc area without
> - * any information, as /dev/kmem.
> - *
> - * Return: number of bytes for which addr and buf should be
> - * increased (same number as @count) or %0 if [addr...addr+count)
> - * doesn't include any intersection with valid vmalloc area
> - */
> -long vwrite(char *buf, char *addr, unsigned long count)
> -{
> -	struct vmap_area *va;
> -	struct vm_struct *vm;
> -	char *vaddr;
> -	unsigned long n, buflen;
> -	int copied = 0;
> -
> -	/* Don't allow overflow */
> -	if ((unsigned long) addr + count < count)
> -		count = -(unsigned long) addr;
> -	buflen = count;
> -
> -	spin_lock(&vmap_area_lock);
> -	list_for_each_entry(va, &vmap_area_list, list) {
> -		if (!count)
> -			break;
> -
> -		if (!va->vm)
> -			continue;
> -
> -		vm = va->vm;
> -		vaddr = (char *) vm->addr;
> -		if (addr >= vaddr + get_vm_area_size(vm))
> -			continue;
> -		while (addr < vaddr) {
> -			if (count == 0)
> -				goto finished;
> -			buf++;
> -			addr++;
> -			count--;
> -		}
> -		n = vaddr + get_vm_area_size(vm) - addr;
> -		if (n > count)
> -			n = count;
> -		if (!(vm->flags & VM_IOREMAP)) {
> -			aligned_vwrite(buf, addr, n);
> -			copied++;
> -		}
> -		buf += n;
> -		addr += n;
> -		count -= n;
> -	}
> -finished:
> -	spin_unlock(&vmap_area_lock);
> -	if (!copied)
> -		return 0;
> -	return buflen;
> -}
> -
>  /**
>   * remap_vmalloc_range_partial - map vmalloc pages to userspace
>   * @vma:		vma to cover
> -- 
> 2.29.2

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-22 10:08   ` David Hildenbrand
@ 2021-03-22 15:18     ` Steven Rostedt
  0 siblings, 0 replies; 21+ messages in thread
From: Steven Rostedt @ 2021-03-22 15:18 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Greg Kroah-Hartman, Gregory Clement, Heiko Carstens,
	Helge Deller, Hillf Danton, huang ying, Ingo Molnar,
	Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang, Jonas Bonn,
	Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linus Torvalds, Linux API, Liviu Dudau,
	Lorenzo Pieralisi, Luc Van Oostenryck, Luis Chamberlain,
	Matthew Wilcox, Matt Turner, Max Filippov, Michael Ellerman,
	Michal Hocko, Mike Rapoport, Mikulas Patocka, Minchan Kim,
	Niklas Schnelle, Oleksiy Avramchenko, Palmer Dabbelt,
	Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On Mon, 22 Mar 2021 11:08:47 +0100
David Hildenbrand <david@redhat.com> wrote:

> 
> Wonder if "echo c > /proc/sysrq-trigger" already existed and would have 
> worked back then. :)
> 
> 

Looks like sysrq-c was added in 2005:

commit 86b1ae38c0a62 ("kdump: sysrq trigger mechanism for kexec based crashdumps")

Thus the answer is "No, it would not have worked back then".

-- Steve


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
                   ` (5 preceding siblings ...)
  2021-03-19 18:10 ` Steven Rostedt
@ 2021-03-23 13:16 ` Greg Kroah-Hartman
  2021-03-23 13:44   ` David Hildenbrand
  6 siblings, 1 reply; 21+ messages in thread
From: Greg Kroah-Hartman @ 2021-03-23 13:16 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Gregory Clement, Heiko Carstens, Helge Deller, Hillf Danton,
	huang ying, Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley,
	Jiaxun Yang, Jonas Bonn, Jonathan Corbet, Kairui Song,
	Krzysztof Kozlowski, Kuninori Morimoto, Linus Torvalds,
	Linux API, Liviu Dudau, Lorenzo Pieralisi, Luc Van Oostenryck,
	Luis Chamberlain, Matthew Wilcox, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Mike Rapoport, Mikulas Patocka,
	Minchan Kim, Niklas Schnelle, Oleksiy Avramchenko,
	Palmer Dabbelt, Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On Fri, Mar 19, 2021 at 03:34:49PM +0100, David Hildenbrand wrote:
> Let's start a discussion if /dev/kmem is worth keeping around and
> fixing/maintaining or if we should just remove it now for good.
> 
> More details / findings in patch #1. Patch #2 and #3 perform minor cleanups
> based on removed /dev/kmem support.
> 
> Only compile-tested on x86-64 -- good enough for discussing the general
> topic (RFC).

I'll gladly take this in my char/misc tree for now, to show up in
linux-next to get some testing to see if anyone complains.

Let me know if that will help out.

thanks,

greg k-h


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-23 13:16 ` Greg Kroah-Hartman
@ 2021-03-23 13:44   ` David Hildenbrand
  0 siblings, 0 replies; 21+ messages in thread
From: David Hildenbrand @ 2021-03-23 13:44 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-kernel, linux-mm, Alexander A. Klimov, Alexander Viro,
	Alexandre Belloni, Andrew Lunn, Andrew Morton, Andrey Zhizhikin,
	Arnd Bergmann, Benjamin Herrenschmidt, Brian Cain,
	Christian Borntraeger, Christophe Leroy, Chris Zankel,
	Corentin Labbe, David S. Miller, Eric W. Biederman,
	Geert Uytterhoeven, Gerald Schaefer, Greentime Hu,
	Gregory Clement, Heiko Carstens, Helge Deller, Hillf Danton,
	huang ying, Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley,
	Jiaxun Yang, Jonas Bonn, Jonathan Corbet, Kairui Song,
	Krzysztof Kozlowski, Kuninori Morimoto, Linus Torvalds,
	Linux API, Liviu Dudau, Lorenzo Pieralisi, Luc Van Oostenryck,
	Luis Chamberlain, Matthew Wilcox, Matt Turner, Max Filippov,
	Michael Ellerman, Michal Hocko, Mike Rapoport, Mikulas Patocka,
	Minchan Kim, Niklas Schnelle, Oleksiy Avramchenko,
	Palmer Dabbelt, Paul Mackerras, Pavel Machek (CIP),
	Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Andrzej Siewior, Sebastian Hesselbarth, Stafford Horne,
	Stefan Kristiansson, Steven Rostedt, Sudeep Holla,
	Theodore Dubois, Thomas Bogendoerfer, Thomas Gleixner,
	Vasily Gorbik, Viresh Kumar, William Cohen, Xiaoming Ni,
	Yoshinori Sato

On 23.03.21 14:16, Greg Kroah-Hartman wrote:
> On Fri, Mar 19, 2021 at 03:34:49PM +0100, David Hildenbrand wrote:
>> Let's start a discussion if /dev/kmem is worth keeping around and
>> fixing/maintaining or if we should just remove it now for good.
>>
>> More details / findings in patch #1. Patch #2 and #3 perform minor cleanups
>> based on removed /dev/kmem support.
>>
>> Only compile-tested on x86-64 -- good enough for discussing the general
>> topic (RFC).
> 
> I'll gladly take this in my char/misc tree for now, to show up in
> linux-next to get some testing to see if anyone complains.
> 
> Let me know if that will help out.

Sure! I'll resend as v1 this week (also removing vwrite() from nommu 
code in patch #3).

Thanks

-- 
Thanks,

David / dhildenb



^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-19 17:33   ` Sebastian Andrzej Siewior
@ 2021-03-31 15:08     ` Enrico Weigelt, metux IT consult
  2021-03-31 15:19       ` Michal Hocko
  0 siblings, 1 reply; 21+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2021-03-31 15:08 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, Linus Torvalds, carnil
  Cc: David Hildenbrand, Linux Kernel Mailing List, Linux-MM,
	Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Michal Hocko,
	Mike Rapoport, Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Hesselbarth, Stafford Horne, Stefan Kristiansson,
	Steven Rostedt, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On 19.03.21 18:33, Sebastian Andrzej Siewior wrote:
> On 2021-03-19 10:14:02 [-0700], Linus Torvalds wrote:
>> On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
>>>
>>> Let's start a discussion if /dev/kmem is worth keeping around and
>>> fixing/maintaining or if we should just remove it now for good.
>>
>> I'll happily do this for the next merge window, but would really want
>> distros to confirm that they don't enable it.
>>
>> I can confirm that it's certainly not enabled on any of the machines I
>> have, but..
> 
> Debian has CONFIG_DEVKMEM disabled since 2.6.31.

SLES, too. (but no idea since when exactly)

--mtx

-- 
---
Hinweis: unverschlüsselte E-Mails können leicht abgehört und manipuliert
werden ! Für eine vertrauliche Kommunikation senden Sie bitte ihren
GPG/PGP-Schlüssel zu.
---
Enrico Weigelt, metux IT consult
Free software and Linux embedded engineering
info@metux.net -- +49-151-27565287


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good
  2021-03-31 15:08     ` Enrico Weigelt, metux IT consult
@ 2021-03-31 15:19       ` Michal Hocko
  0 siblings, 0 replies; 21+ messages in thread
From: Michal Hocko @ 2021-03-31 15:19 UTC (permalink / raw)
  To: Enrico Weigelt, metux IT consult
  Cc: Sebastian Andrzej Siewior, Linus Torvalds, carnil,
	David Hildenbrand, Linux Kernel Mailing List, Linux-MM,
	Alexander A. Klimov, Alexander Viro, Alexandre Belloni,
	Andrew Lunn, Andrew Morton, Andrey Zhizhikin, Arnd Bergmann,
	Benjamin Herrenschmidt, Brian Cain, Christian Borntraeger,
	Christophe Leroy, Chris Zankel, Corentin Labbe, David S. Miller,
	Eric W. Biederman, Geert Uytterhoeven, Gerald Schaefer,
	Greentime Hu, Greg Kroah-Hartman, Gregory Clement,
	Heiko Carstens, Helge Deller, Hillf Danton, huang ying,
	Ingo Molnar, Ivan Kokshaysky, James E.J. Bottomley, Jiaxun Yang,
	Jonas Bonn, Jonathan Corbet, Kairui Song, Krzysztof Kozlowski,
	Kuninori Morimoto, Linux API, Liviu Dudau, Lorenzo Pieralisi,
	Luc Van Oostenryck, Luis Chamberlain, Matthew Wilcox,
	Matt Turner, Max Filippov, Michael Ellerman, Mike Rapoport,
	Mikulas Patocka, Minchan Kim, Niklas Schnelle,
	Oleksiy Avramchenko, Palmer Dabbelt, Paul Mackerras,
	Pavel Machek (CIP), Pavel Machek, Peter Zijlstra (Intel),
	Pierre Morel, Randy Dunlap, Richard Henderson, Rich Felker,
	Robert Richter, Rob Herring, Russell King, Sam Ravnborg,
	Sebastian Hesselbarth, Stafford Horne, Stefan Kristiansson,
	Steven Rostedt, Sudeep Holla, Theodore Dubois,
	Thomas Bogendoerfer, Thomas Gleixner, Vasily Gorbik,
	Viresh Kumar, William Cohen, Xiaoming Ni, Yoshinori Sato

On Wed 31-03-21 17:08:03, Enrico Weigelt, metux IT consult wrote:
> On 19.03.21 18:33, Sebastian Andrzej Siewior wrote:
> > On 2021-03-19 10:14:02 [-0700], Linus Torvalds wrote:
> > > On Fri, Mar 19, 2021 at 7:35 AM David Hildenbrand <david@redhat.com> wrote:
> > > > 
> > > > Let's start a discussion if /dev/kmem is worth keeping around and
> > > > fixing/maintaining or if we should just remove it now for good.
> > > 
> > > I'll happily do this for the next merge window, but would really want
> > > distros to confirm that they don't enable it.
> > > 
> > > I can confirm that it's certainly not enabled on any of the machines I
> > > have, but..
> > 
> > Debian has CONFIG_DEVKMEM disabled since 2.6.31.
> 
> SLES, too. (but no idea since when exactly)

15-SP2 IIRC

-- 
Michal Hocko
SUSE Labs


^ permalink raw reply	[flat|nested] 21+ messages in thread

* Re: [PATCH RFC 1/3] drivers/char: remove /dev/kmem for good
  2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
  2021-03-22 13:35   ` Michal Hocko
@ 2021-04-05 17:16   ` Kees Cook
  1 sibling, 0 replies; 21+ messages in thread
From: Kees Cook @ 2021-04-05 17:16 UTC (permalink / raw)
  To: David Hildenbrand
  Cc: linux-kernel, linux-mm, Andrew Morton, Hillf Danton,
	Michal Hocko, Matthew Wilcox, Oleksiy Avramchenko,
	Steven Rostedt, Minchan Kim, huang ying, Jonathan Corbet,
	Russell King, Liviu Dudau, Sudeep Holla, Lorenzo Pieralisi,
	Andrew Lunn, Gregory Clement, Sebastian Hesselbarth,
	Yoshinori Sato, Brian Cain, Geert Uytterhoeven, Jonas Bonn,
	Stefan Kristiansson, Stafford Horne, Rich Felker,
	David S. Miller, Chris Zankel, Max Filippov, Arnd Bergmann,
	Greg Kroah-Hartman, Alexander Viro, Rob Herring,
	Pavel Machek (CIP),
	Theodore Dubois, Alexander A. Klimov, Pavel Machek, Sam Ravnborg,
	Alexandre Belloni, Andrey Zhizhikin, Randy Dunlap,
	Krzysztof Kozlowski, Viresh Kumar, Eric W. Biederman,
	Thomas Gleixner, Xiaoming Ni, Robert Richter, William Cohen,
	Corentin Labbe, Kairui Song, Linus Torvalds, linux-doc,
	linux-arm-kernel, uclinux-h8-devel, linux-hexagon, linux-m68k,
	openrisc, linux-sh, sparclinux, linux-xtensa, linux-fsdevel,
	Linux API

On Fri, Mar 19, 2021 at 03:34:50PM +0100, David Hildenbrand wrote:
> Exploring /dev/kmem and /dev/mem in the context of memory hot(un)plug and
> memory ballooning, I started questioning the existance of /dev/kmem.
> 
> Comparing it with the /proc/kcore implementation, it does not seem to be
> able to deal with things like
> a) Pages unmapped from the direct mapping (e.g., to be used by secretmem)
>   -> kern_addr_valid(). virt_addr_valid() is not sufficient.
> b) Special cases like gart aperture memory that is not to be touched
>   -> mem_pfn_is_ram()
> Unless I am missing something, it's at least broken in some cases and might
> fault/crash the machine.
> 
> Looks like its existance has been questioned before in 2005 and 2010
> [1], after ~11 additional years, it might make sense to revive the
> discussion.
> 
> CONFIG_DEVKMEM is only enabled in a single defconfig (on purpose or by
> mistake?). All distributions I looked at disable it.
> 
> 1) /dev/kmem was popular for rootkits [2] before it got disabled
>    basically everywhere. Ubuntu documents [3] "There is no modern user of
>    /dev/kmem any more beyond attackers using it to load kernel rootkits.".
>    RHEL documents in a BZ [5] "it served no practical purpose other than to
>    serve as a potential security problem or to enable binary module drivers
>    to access structures/functions they shouldn't be touching"
> 
> 2) /proc/kcore is a decent interface to have a controlled way to read
>    kernel memory for debugging puposes. (will need some extensions to
>    deal with memory offlining/unplug, memory ballooning, and poisoned
>    pages, though)
> 
> 3) It might be useful for corner case debugging [1]. KDB/KGDB might be a
>    better fit, especially, to write random memory; harder to shoot
>    yourself into the foot.
> 
> 4) "Kernel Memory Editor" hasn't seen any updates since 2000 and seems
>    to be incompatible with 64bit [1]. For educational purposes,
>    /proc/kcore might be used to monitor value updates -- or older
>    kernels can be used.
> 
> 5) It's broken on arm64, and therefore, completely disabled there.
> 
> Looks like it's essentially unused and has been replaced by better
> suited interfaces for individual tasks (/proc/kcore, KDB/KGDB). Let's
> just remove it.
> 
> [1] https://lwn.net/Articles/147901/
> [2] https://www.linuxjournal.com/article/10505
> [3] https://wiki.ubuntu.com/Security/Features#A.2Fdev.2Fkmem_disabled
> [4] https://sourceforge.net/projects/kme/
> [5] https://bugzilla.redhat.com/show_bug.cgi?id=154796
> 
> [...]
> Cc: Linux API <linux-api@vger.kernel.org>
> Signed-off-by: David Hildenbrand <david@redhat.com>

Yes please! As James Troup pointed out already, this was turned off in
Ubuntu in 2008. I don't remember a single complaint from anyone who
wasn't a rootkit author. ;)

Acked-by: Kees Cook <keescook@chromium.org>

-- 
Kees Cook


^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2021-04-05 17:16 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-19 14:34 [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
2021-03-19 14:34 ` [PATCH RFC 1/3] " David Hildenbrand
2021-03-22 13:35   ` Michal Hocko
2021-04-05 17:16   ` Kees Cook
2021-03-19 14:34 ` [PATCH RFC 2/3] mm: remove xlate_dev_kmem_ptr() David Hildenbrand
2021-03-19 14:54   ` Geert Uytterhoeven
2021-03-19 14:34 ` [PATCH RFC 3/3] mm/vmalloc: remove vwrite() David Hildenbrand
2021-03-22 13:36   ` Michal Hocko
2021-03-19 14:45 ` [PATCH RFC 0/3] drivers/char: remove /dev/kmem for good David Hildenbrand
2021-03-19 17:14 ` Linus Torvalds
2021-03-19 17:33   ` Sebastian Andrzej Siewior
2021-03-31 15:08     ` Enrico Weigelt, metux IT consult
2021-03-31 15:19       ` Michal Hocko
2021-03-19 18:55   ` James Troup
2021-03-22  9:57   ` David Hildenbrand
2021-03-22 13:34   ` Michal Hocko
2021-03-19 18:10 ` Steven Rostedt
2021-03-22 10:08   ` David Hildenbrand
2021-03-22 15:18     ` Steven Rostedt
2021-03-23 13:16 ` Greg Kroah-Hartman
2021-03-23 13:44   ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).