From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4DAAC433C1 for ; Wed, 24 Mar 2021 10:25:06 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 41E4D61A07 for ; Wed, 24 Mar 2021 10:25:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41E4D61A07 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 99A436B02B2; Wed, 24 Mar 2021 06:25:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 94A086B02B3; Wed, 24 Mar 2021 06:25:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 72A606B02B4; Wed, 24 Mar 2021 06:25:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0197.hostedemail.com [216.40.44.197]) by kanga.kvack.org (Postfix) with ESMTP id 4C5566B02B2 for ; Wed, 24 Mar 2021 06:25:05 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0B459180ACC3C for ; Wed, 24 Mar 2021 10:25:05 +0000 (UTC) X-FDA: 77954384970.38.3EB5980 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf29.hostedemail.com (Postfix) with ESMTP id 52677F4 for ; Wed, 24 Mar 2021 10:25:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616581503; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yw1kaNhaKWkNGbfTKhYEtEQwGEa1stGjOuOGnel5N0M=; b=Qk/n0d1PLoc5C27+QDL8z/RIauaHBy+eLCzlqW4s2fSW9Dkh2U3rUQwzzGZaRlm5tNALNE 9lrjQaKG77tTy3h7rnX6uepRA+kkXeUhYNP/FS1krKE65/RgqYJxsJKSuoaI1BXOI0Hptb 55u4tXCpcbHFtSXjjmZ5tH+l2SAPeH0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-N9eGBdQ0P6u1S4NHnHY0aw-1; Wed, 24 Mar 2021 06:24:46 -0400 X-MC-Unique: N9eGBdQ0P6u1S4NHnHY0aw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E04468042C1; Wed, 24 Mar 2021 10:24:41 +0000 (UTC) Received: from t480s.redhat.com (ovpn-115-66.ams2.redhat.com [10.36.115.66]) by smtp.corp.redhat.com (Postfix) with ESMTP id E20C11002D71; Wed, 24 Mar 2021 10:24:13 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Linus Torvalds , Greg Kroah-Hartman , Andrew Morton , "Alexander A. Klimov" , Alexander Viro , Alexandre Belloni , Andrew Lunn , 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" , James Troup , Jiaxun Yang , Jonas Bonn , Jonathan Corbet , Kairui Song , Krzysztof Kozlowski , Kuninori Morimoto , 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 , openrisc@lists.librecores.org, 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 , sparclinux@vger.kernel.org, Stafford Horne , Stefan Kristiansson , Steven Rostedt , Sudeep Holla , Theodore Dubois , Thomas Bogendoerfer , Thomas Gleixner , uclinux-h8-devel@lists.sourceforge.jp, Vasily Gorbik , Viresh Kumar , William Cohen , Xiaoming Ni , Yoshinori Sato , linux-alpha@vger.kernel.org, Linux API , linux-arch@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, linux-xtensa@linux-xtensa.org Subject: [PATCH v1 1/3] drivers/char: remove /dev/kmem for good Date: Wed, 24 Mar 2021 11:23:49 +0100 Message-Id: <20210324102351.6932-2-david@redhat.com> In-Reply-To: <20210324102351.6932-1-david@redhat.com> References: <20210324102351.6932-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="US-ASCII" X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 52677F4 X-Stat-Signature: rdxph96ttijfo7fqe5c3847uxemzcfxa Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616581503-669964 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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 mig= ht 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 disable it: in Ubuntu it has been disabled for more than 10 years, in Debian since 2.6.31, in Fedora at least starti= ng with FC3, in RHEL starting with RHEL4, in SUSE starting from 15sp2, and OpenSUSE has it disabled as well. 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 drive= rs 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" [4] hasn't seen any updates since 2000 and seem= s 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=3D154796 Cc: Linus Torvalds Cc: Greg Kroah-Hartman Cc: Andrew Morton Cc: "Alexander A. Klimov" Cc: Alexander Viro Cc: Alexandre Belloni Cc: Andrew Lunn Cc: Andrey Zhizhikin Cc: Arnd Bergmann Cc: Benjamin Herrenschmidt Cc: Brian Cain Cc: Christian Borntraeger Cc: Christophe Leroy Cc: Chris Zankel Cc: Corentin Labbe Cc: "David S. Miller" Cc: "Eric W. Biederman" Cc: Geert Uytterhoeven Cc: Gerald Schaefer Cc: Greentime Hu Cc: Gregory Clement Cc: Heiko Carstens Cc: Helge Deller Cc: Hillf Danton Cc: huang ying Cc: Ingo Molnar Cc: Ivan Kokshaysky Cc: "James E.J. Bottomley" Cc: James Troup Cc: Jiaxun Yang Cc: Jonas Bonn Cc: Jonathan Corbet Cc: Kairui Song Cc: Krzysztof Kozlowski Cc: Kuninori Morimoto Cc: Liviu Dudau Cc: Lorenzo Pieralisi Cc: Luc Van Oostenryck Cc: Luis Chamberlain Cc: Matthew Wilcox Cc: Matt Turner Cc: Max Filippov Cc: Michael Ellerman Cc: Michal Hocko Cc: Mike Rapoport Cc: Mikulas Patocka Cc: Minchan Kim Cc: Niklas Schnelle Cc: Oleksiy Avramchenko Cc: openrisc@lists.librecores.org Cc: Palmer Dabbelt Cc: Paul Mackerras Cc: "Pavel Machek (CIP)" Cc: Pavel Machek Cc: "Peter Zijlstra (Intel)" Cc: Pierre Morel Cc: Randy Dunlap Cc: Richard Henderson Cc: Rich Felker Cc: Robert Richter Cc: Rob Herring Cc: Russell King Cc: Sam Ravnborg Cc: Sebastian Andrzej Siewior Cc: Sebastian Hesselbarth Cc: sparclinux@vger.kernel.org Cc: Stafford Horne Cc: Stefan Kristiansson Cc: Steven Rostedt Cc: Sudeep Holla Cc: Theodore Dubois Cc: Thomas Bogendoerfer Cc: Thomas Gleixner Cc: uclinux-h8-devel@lists.sourceforge.jp Cc: Vasily Gorbik Cc: Viresh Kumar Cc: William Cohen Cc: Xiaoming Ni Cc: Yoshinori Sato Cc: linux-alpha@vger.kernel.org Cc: Linux API Cc: linux-arch@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-doc@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org Cc: linux-hexagon@vger.kernel.org Cc: linux-ia64@vger.kernel.org Cc: linux-kernel@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: linux-xtensa@linux-xtensa.org Signed-off-by: David Hildenbrand --- 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 @@ =20 1 char Memory devices 1 =3D /dev/mem Physical memory access - 2 =3D /dev/kmem Kernel virtual memory access + 2 =3D /dev/kmem OBSOLETE - replaced by /proc/kcore 3 =3D /dev/null Null device 4 =3D /dev/port I/O port access 5 =3D /dev/zero Null byte source diff --git a/arch/arm/configs/dove_defconfig b/arch/arm/configs/dove_defc= onfig index e70c997d5f4c..b935162a8bba 100644 --- a/arch/arm/configs/dove_defconfig +++ b/arch/arm/configs/dove_defconfig @@ -63,7 +63,6 @@ CONFIG_INPUT_EVDEV=3Dy # CONFIG_MOUSE_PS2 is not set # CONFIG_SERIO is not set CONFIG_LEGACY_PTY_COUNT=3D16 -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_8250_RUNTIME_UARTS=3D2 diff --git a/arch/arm/configs/magician_defconfig b/arch/arm/configs/magic= ian_defconfig index b4670d42f378..abde1fb23b20 100644 --- a/arch/arm/configs/magician_defconfig +++ b/arch/arm/configs/magician_defconfig @@ -72,7 +72,6 @@ CONFIG_INPUT_TOUCHSCREEN=3Dy CONFIG_INPUT_MISC=3Dy CONFIG_INPUT_UINPUT=3Dm # CONFIG_SERIO is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_PXA=3Dy # 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=3Dy # CONFIG_SERIO is not set # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_8250_NR_UARTS=3D1 diff --git a/arch/arm/configs/mps2_defconfig b/arch/arm/configs/mps2_defc= onfig index 1d923dbb9928..89f4a6ff30bd 100644 --- a/arch/arm/configs/mps2_defconfig +++ b/arch/arm/configs/mps2_defconfig @@ -69,7 +69,6 @@ CONFIG_SMSC911X=3Dy # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set CONFIG_SERIAL_NONSTANDARD=3Dy -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_MPS2_UART_CONSOLE=3Dy CONFIG_SERIAL_MPS2_UART=3Dy # 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=3Dy CONFIG_KEYBOARD_GPIO=3Dy # CONFIG_INPUT_MOUSE is not set CONFIG_LEGACY_PTY_COUNT=3D16 -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_8250_RUNTIME_UARTS=3D2 diff --git a/arch/arm/configs/xcep_defconfig b/arch/arm/configs/xcep_defc= onfig index f1fbdfc5c8c6..4d8e7f2eaef7 100644 --- a/arch/arm/configs/xcep_defconfig +++ b/arch/arm/configs/xcep_defconfig @@ -53,7 +53,6 @@ CONFIG_NET_ETHERNET=3Dy # 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=3Dy CONFIG_SERIAL_PXA_CONSOLE=3Dy # 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=3Dy # 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=3Dy CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy # 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=3Dy # 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=3Dy CONFIG_SERIAL_SH_SCI_EARLYCON=3Dy # CONFIG_HW_RANDOM is not set diff --git a/arch/h8300/configs/h8s-sim_defconfig b/arch/h8300/configs/h8= s-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=3Dy # 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=3Dy CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy # 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=3Dy # CONFIG_SERIO is not set # CONFIG_CONSOLE_TRANSLATIONS is not set CONFIG_LEGACY_PTY_COUNT=3D64 -# CONFIG_DEVKMEM is not set # CONFIG_HW_RANDOM is not set CONFIG_SPI=3Dy CONFIG_SPI_DEBUG=3Dy diff --git a/arch/m68k/configs/amcore_defconfig b/arch/m68k/configs/amcor= e_defconfig index 3a84f24d41c8..6d9ed2198170 100644 --- a/arch/m68k/configs/amcore_defconfig +++ b/arch/m68k/configs/amcore_defconfig @@ -60,7 +60,6 @@ CONFIG_DM9000=3Dy # CONFIG_VT is not set # CONFIG_UNIX98_PTYS is not set # CONFIG_DEVMEM is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_MCF=3Dy CONFIG_SERIAL_MCF_BAUDRATE=3D115200 CONFIG_SERIAL_MCF_CONSOLE=3Dy diff --git a/arch/openrisc/configs/or1ksim_defconfig b/arch/openrisc/conf= igs/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=3Dy # CONFIG_SERIO is not set # CONFIG_VT is not set # CONFIG_LEGACY_PTYS is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_8250=3Dy CONFIG_SERIAL_8250_CONSOLE=3Dy CONFIG_SERIAL_OF_PLATFORM=3Dy diff --git a/arch/sh/configs/edosk7705_defconfig b/arch/sh/configs/edosk7= 705_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=3D31250000 # 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_de= fconfig index 315b04a8dd2f..601d062250d1 100644 --- a/arch/sh/configs/se7206_defconfig +++ b/arch/sh/configs/se7206_defconfig @@ -71,7 +71,6 @@ CONFIG_SMC91X=3Dy # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=3Dy CONFIG_SERIAL_SH_SCI_NR_UARTS=3D4 CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy diff --git a/arch/sh/configs/sh2007_defconfig b/arch/sh/configs/sh2007_de= fconfig index 99975db461d8..79f02f1c0dc8 100644 --- a/arch/sh/configs/sh2007_defconfig +++ b/arch/sh/configs/sh2007_defconfig @@ -75,7 +75,6 @@ CONFIG_INPUT_FF_MEMLESS=3Dy # CONFIG_INPUT_MOUSE is not set # CONFIG_SERIO is not set CONFIG_VT_HW_CONSOLE_BINDING=3Dy -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=3Dy CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy # CONFIG_LEGACY_PTYS is not set diff --git a/arch/sh/configs/sh7724_generic_defconfig b/arch/sh/configs/s= h7724_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=3Dy # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=3Dy CONFIG_SERIAL_SH_SCI_NR_UARTS=3D6 CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy diff --git a/arch/sh/configs/sh7770_generic_defconfig b/arch/sh/configs/s= h7770_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=3Dy # CONFIG_INPUT is not set # CONFIG_SERIO is not set # CONFIG_VT is not set -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=3Dy CONFIG_SERIAL_SH_SCI_NR_UARTS=3D6 CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy 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=3Dm CONFIG_INPUT_EVDEV=3Dy CONFIG_INPUT_EVBUG=3Dm CONFIG_VT_HW_CONSOLE_BINDING=3Dy -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SH_SCI=3Dy CONFIG_SERIAL_SH_SCI_NR_UARTS=3D6 CONFIG_SERIAL_SH_SCI_CONSOLE=3Dy diff --git a/arch/sparc/configs/sparc64_defconfig b/arch/sparc/configs/sp= arc64_defconfig index 12a4fb0bd52a..18099099583e 100644 --- a/arch/sparc/configs/sparc64_defconfig +++ b/arch/sparc/configs/sparc64_defconfig @@ -122,7 +122,6 @@ CONFIG_INPUT_SPARCSPKR=3Dy # CONFIG_SERIO_SERPORT is not set CONFIG_SERIO_PCIPS2=3Dm CONFIG_SERIO_RAW=3Dm -# CONFIG_DEVKMEM is not set CONFIG_SERIAL_SUNSU=3Dy CONFIG_SERIAL_SUNSU_CONSOLE=3Dy CONFIG_SERIAL_SUNSAB=3Dy diff --git a/arch/xtensa/configs/xip_kc705_defconfig b/arch/xtensa/config= s/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=3Dy # CONFIG_INPUT_KEYBOARD is not set # CONFIG_INPUT_MOUSE is not set # CONFIG_SERIO is not set -CONFIG_DEVKMEM=3Dy CONFIG_SERIAL_8250=3Dy # CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set CONFIG_SERIAL_8250_CONSOLE=3Dy 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". =20 -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_ar= ea_struct *vma) return 0; } =20 -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 =3D __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 =3D 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 =3D *ppos; - ssize_t low_count, read, sz; - char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */ - int err =3D 0; - - read =3D 0; - if (p < (unsigned long) high_memory) { - low_count =3D count; - if (count > (unsigned long)high_memory - p) - low_count =3D (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 =3D size_inside_page(p, low_count); - if (clear_user(buf, sz)) - return -EFAULT; - buf +=3D sz; - p +=3D sz; - read +=3D sz; - low_count -=3D sz; - count -=3D sz; - } -#endif - while (low_count > 0) { - sz =3D 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 =3D xlate_dev_kmem_ptr((void *)p); - if (!virt_addr_valid(kbuf)) - return -ENXIO; - - if (copy_to_user(buf, kbuf, sz)) - return -EFAULT; - buf +=3D sz; - p +=3D sz; - read +=3D sz; - low_count -=3D sz; - count -=3D sz; - if (should_stop_iteration()) { - count =3D 0; - break; - } - } - } - - if (count > 0) { - kbuf =3D (char *)__get_free_page(GFP_KERNEL); - if (!kbuf) - return -ENOMEM; - while (count > 0) { - sz =3D size_inside_page(p, count); - if (!is_vmalloc_or_module_addr((void *)p)) { - err =3D -ENXIO; - break; - } - sz =3D vread(kbuf, (char *)p, sz); - if (!sz) - break; - if (copy_to_user(buf, kbuf, sz)) { - err =3D -EFAULT; - break; - } - count -=3D sz; - buf +=3D sz; - read +=3D sz; - p +=3D sz; - if (should_stop_iteration()) - break; - } - free_page((unsigned long)kbuf); - } - *ppos =3D 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 =3D 0; -#ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED - /* we don't have page 0 mapped on sparc and m68k.. */ - if (p < PAGE_SIZE) { - sz =3D size_inside_page(p, count); - /* Hmm. Do something? */ - buf +=3D sz; - p +=3D sz; - count -=3D sz; - written +=3D sz; - } -#endif - - while (count > 0) { - void *ptr; - - sz =3D 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 =3D xlate_dev_kmem_ptr((void *)p); - if (!virt_addr_valid(ptr)) - return -ENXIO; - - copied =3D copy_from_user(ptr, buf, sz); - if (copied) { - written +=3D sz - copied; - if (written) - break; - return -EFAULT; - } - buf +=3D sz; - p +=3D sz; - count -=3D sz; - written +=3D sz; - if (should_stop_iteration()) - break; - } - - *ppos +=3D 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 =3D *ppos; - ssize_t wrote =3D 0; - ssize_t virtr =3D 0; - char *kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */ - int err =3D 0; - - if (p < (unsigned long) high_memory) { - unsigned long to_write =3D min_t(unsigned long, count, - (unsigned long)high_memory - p); - wrote =3D do_write_kmem(p, buf, to_write, ppos); - if (wrote !=3D to_write) - return wrote; - p +=3D wrote; - buf +=3D wrote; - count -=3D wrote; - } - - if (count > 0) { - kbuf =3D (char *)__get_free_page(GFP_KERNEL); - if (!kbuf) - return wrote ? wrote : -ENOMEM; - while (count > 0) { - unsigned long sz =3D size_inside_page(p, count); - unsigned long n; - - if (!is_vmalloc_or_module_addr((void *)p)) { - err =3D -ENXIO; - break; - } - n =3D copy_from_user(kbuf, buf, sz); - if (n) { - err =3D -EFAULT; - break; - } - vwrite(kbuf, (char *)p, sz); - count -=3D sz; - buf +=3D sz; - virtr +=3D sz; - p +=3D sz; - if (should_stop_iteration()) - break; - } - free_page((unsigned long)kbuf); - } - - *ppos =3D 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 =20 static const struct file_operations __maybe_unused mem_fops =3D { .llseek =3D memory_lseek, @@ -869,18 +653,6 @@ static const struct file_operations __maybe_unused m= em_fops =3D { #endif }; =20 -static const struct file_operations __maybe_unused kmem_fops =3D { - .llseek =3D memory_lseek, - .read =3D read_kmem, - .write =3D write_kmem, - .mmap =3D mmap_kmem, - .open =3D open_kmem, -#ifndef CONFIG_MMU - .get_unmapped_area =3D get_unmapped_area_mem, - .mmap_capabilities =3D memory_mmap_capabilities, -#endif -}; - static const struct file_operations null_fops =3D { .llseek =3D null_lseek, .read =3D read_null, @@ -924,9 +696,6 @@ static const struct memdev { } devlist[] =3D { #ifdef CONFIG_DEVMEM [DEVMEM_MINOR] =3D { "mem", 0, &mem_fops, FMODE_UNSIGNED_OFFSET }, -#endif -#ifdef CONFIG_DEVKMEM - [2] =3D { "kmem", 0, &kmem_fops, FMODE_UNSIGNED_OFFSET }, #endif [3] =3D { "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) =20 -/* 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) =20 /* 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 *add= r) } #endif =20 -/* 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); =20 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, un= signed 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 --=20 2.29.2