linux/drivers
Ryan Roberts c33c794828 mm: ptep_get() conversion
Convert all instances of direct pte_t* dereferencing to instead use
ptep_get() helper.  This means that by default, the accesses change from a
C dereference to a READ_ONCE().  This is technically the correct thing to
do since where pgtables are modified by HW (for access/dirty) they are
volatile and therefore we should always ensure READ_ONCE() semantics.

But more importantly, by always using the helper, it can be overridden by
the architecture to fully encapsulate the contents of the pte.  Arch code
is deliberately not converted, as the arch code knows best.  It is
intended that arch code (arm64) will override the default with its own
implementation that can (e.g.) hide certain bits from the core code, or
determine young/dirty status by mixing in state from another source.

Conversion was done using Coccinelle:

----

// $ make coccicheck \
//          COCCI=ptepget.cocci \
//          SPFLAGS="--include-headers" \
//          MODE=patch

virtual patch

@ depends on patch @
pte_t *v;
@@

- *v
+ ptep_get(v)

----

Then reviewed and hand-edited to avoid multiple unnecessary calls to
ptep_get(), instead opting to store the result of a single call in a
variable, where it is correct to do so.  This aims to negate any cost of
READ_ONCE() and will benefit arch-overrides that may be more complex.

Included is a fix for an issue in an earlier version of this patch that
was pointed out by kernel test robot.  The issue arose because config
MMU=n elides definition of the ptep helper functions, including
ptep_get().  HUGETLB_PAGE=n configs still define a simple
huge_ptep_clear_flush() for linking purposes, which dereferences the ptep.
So when both configs are disabled, this caused a build error because
ptep_get() is not defined.  Fix by continuing to do a direct dereference
when MMU=n.  This is safe because for this config the arch code cannot be
trying to virtualize the ptes because none of the ptep helpers are
defined.

Link: https://lkml.kernel.org/r/20230612151545.3317766-4-ryan.roberts@arm.com
Reported-by: kernel test robot <lkp@intel.com>
Link: https://lore.kernel.org/oe-kbuild-all/202305120142.yXsNEo6H-lkp@intel.com/
Signed-off-by: Ryan Roberts <ryan.roberts@arm.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andrey Konovalov <andreyknvl@gmail.com>
Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Dave Airlie <airlied@gmail.com>
Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jérôme Glisse <jglisse@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Lorenzo Stoakes <lstoakes@gmail.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Mike Rapoport (IBM) <rppt@kernel.org>
Cc: Muchun Song <muchun.song@linux.dev>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naoya Horiguchi <naoya.horiguchi@nec.com>
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Cc: Pavel Tatashin <pasha.tatashin@soleen.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>
Cc: SeongJae Park <sj@kernel.org>
Cc: Shakeel Butt <shakeelb@google.com>
Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Yu Zhao <yuzhao@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2023-06-19 16:19:25 -07:00
..
accel accel/qaic: Fix NNC message corruption 2023-05-23 09:51:38 -06:00
accessibility
acpi
amba
android binder: fix UAF of alloc->vma in race with munmap() 2023-05-20 17:56:23 +01:00
ata
atm
auxdisplay
base drivers/base: use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN 2023-06-19 16:19:20 -07:00
bcma
block xen: branch for v6.4-rc4 2023-05-27 09:42:56 -07:00
bluetooth Bluetooth: btnxpuart: Fix compiler warnings 2023-05-19 15:38:29 -07:00
bus
cdrom
cdx
char parisc architecture fixes for kernel v6.4-rc4: 2023-05-25 18:50:18 -07:00
clk
clocksource
comedi
connector
counter
cpufreq cpufreq: amd-pstate: Update policy->cur in amd_pstate_adjust_perf() 2023-05-25 19:35:13 +02:00
cpuidle
crypto
cxl cxl: Explicitly initialize resources when media is not ready 2023-05-26 13:34:39 -07:00
dax
dca
devfreq
dio
dma
dma-buf
edac
eisa
extcon
firewire
firmware Arm FF-A fixes for v6.4 2023-05-26 16:49:15 +02:00
fpga
fsi
gnss
gpio gpio-f7188x: fix chip name and pin count on Nuvoton chip 2023-05-23 10:47:41 +02:00
gpu mm: ptep_get() conversion 2023-06-19 16:19:25 -07:00
greybus
hid
hsi
hte
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband mm/gup: remove vmas parameter from pin_user_pages() 2023-06-09 16:25:26 -07:00
input
interconnect
iommu iommu/dma: force bouncing if the size is not cacheline-aligned 2023-06-19 16:19:23 -07:00
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md dm-crypt: use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN 2023-06-19 16:19:21 -07:00
media mm/gup: remove vmas parameter from pin_user_pages() 2023-06-09 16:25:26 -07:00
memory
memstick
message
mfd
misc mm: ptep_get() conversion 2023-06-19 16:19:25 -07:00
mmc
most
mtd
mux
net net: phy: mscc: enable VSC8501/2 RGMII RX clock 2023-05-24 22:14:23 -07:00
nfc
ntb
nubus
nvdimm
nvme NVMe: Add MAXIO 1602 to bogus nid list. 2023-05-26 08:21:50 -07:00
nvmem
of
opp
parisc
parport
pci scatterlist: add dedicated config for DMA flags 2023-06-19 16:19:22 -07:00
pcmcia
peci
perf
phy
pinctrl
platform platform/x86/intel/ifs: Annotate work queue on stack so object debug does not complain 2023-05-23 12:55:16 +02:00
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator regulator: mt6359: add read check for PMIC MT6359 2023-05-18 19:24:47 +09:00
remoteproc
reset
rpmsg
rtc
s390 block-6.4-2023-05-20 2023-05-20 08:48:04 -07:00
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi drivers/spi: use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN 2023-06-19 16:19:21 -07:00
spmi
ssb
staging
target
tc
tee Fixes an uninitialized variable in OP-TEE driver 2023-05-25 17:16:52 +02:00
thermal thermal: intel: int340x: Add new line for UUID display 2023-05-24 19:50:04 +02:00
thunderbolt
tty
ufs
uio
usb drivers/usb: use ARCH_DMA_MINALIGN instead of ARCH_KMALLOC_MINALIGN 2023-06-19 16:19:21 -07:00
vdpa mm/gup: remove vmas parameter from pin_user_pages() 2023-06-09 16:25:26 -07:00
vfio mm: ptep_get() conversion 2023-06-19 16:19:25 -07:00
vhost mm/gup: remove vmas parameter from pin_user_pages() 2023-06-09 16:25:26 -07:00
video fbdev: stifb: Whitespace cleanups 2023-05-20 22:48:46 +02:00
virt
virtio
vlynq
w1
watchdog
xen mm: ptep_get() conversion 2023-06-19 16:19:25 -07:00
zorro
Kconfig
Makefile