Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fs: move FMODE_UNSIGNED_OFFSET to fop_flags

This is another flag that is statically set and doesn't need to use up
an FMODE_* bit. Move it to ->fop_flags and free up another FMODE_* bit.

(1) mem_open() used from proc_mem_operations
(2) adi_open() used from adi_fops
(3) drm_open_helper():
(3.1) accel_open() used from DRM_ACCEL_FOPS
(3.2) drm_open() used from
(3.2.1) amdgpu_driver_kms_fops
(3.2.2) psb_gem_fops
(3.2.3) i915_driver_fops
(3.2.4) nouveau_driver_fops
(3.2.5) panthor_drm_driver_fops
(3.2.6) radeon_driver_kms_fops
(3.2.7) tegra_drm_fops
(3.2.8) vmwgfx_driver_fops
(3.2.9) xe_driver_fops
(3.2.10) DRM_GEM_FOPS
(3.2.11) DEFINE_DRM_GEM_DMA_FOPS
(4) struct memdev sets fmode flags based on type of device opened. For
devices using struct mem_fops unsigned offset is used.

Mark all these file operations as FOP_UNSIGNED_OFFSET and add asserts
into the open helper to ensure that the flag is always set.

Link: https://lore.kernel.org/r/20240809-work-fop_unsigned-v1-1-658e054d893e@kernel.org
Reviewed-by: Jeff Layton <jlayton@kernel.org>
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Christian Brauner <brauner@kernel.org>

+27 -21
+1 -7
drivers/char/adi.c
··· 14 14 15 15 #define MAX_BUF_SZ PAGE_SIZE 16 16 17 - static int adi_open(struct inode *inode, struct file *file) 18 - { 19 - file->f_mode |= FMODE_UNSIGNED_OFFSET; 20 - return 0; 21 - } 22 - 23 17 static int read_mcd_tag(unsigned long addr) 24 18 { 25 19 long err; ··· 200 206 static const struct file_operations adi_fops = { 201 207 .owner = THIS_MODULE, 202 208 .llseek = adi_llseek, 203 - .open = adi_open, 204 209 .read = adi_read, 205 210 .write = adi_write, 211 + .fop_flags = FOP_UNSIGNED_OFFSET, 206 212 }; 207 213 208 214 static struct miscdevice adi_miscdev = {
+2 -1
drivers/char/mem.c
··· 643 643 .get_unmapped_area = get_unmapped_area_mem, 644 644 .mmap_capabilities = memory_mmap_capabilities, 645 645 #endif 646 + .fop_flags = FOP_UNSIGNED_OFFSET, 646 647 }; 647 648 648 649 static const struct file_operations null_fops = { ··· 694 693 umode_t mode; 695 694 } devlist[] = { 696 695 #ifdef CONFIG_DEVMEM 697 - [DEVMEM_MINOR] = { "mem", &mem_fops, FMODE_UNSIGNED_OFFSET, 0 }, 696 + [DEVMEM_MINOR] = { "mem", &mem_fops, 0, 0 }, 698 697 #endif 699 698 [3] = { "null", &null_fops, FMODE_NOWAIT, 0666 }, 700 699 #ifdef CONFIG_DEVPORT
+1
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c
··· 2908 2908 #ifdef CONFIG_PROC_FS 2909 2909 .show_fdinfo = drm_show_fdinfo, 2910 2910 #endif 2911 + .fop_flags = FOP_UNSIGNED_OFFSET, 2911 2912 }; 2912 2913 2913 2914 int amdgpu_file_to_fpriv(struct file *filp, struct amdgpu_fpriv **fpriv)
+2 -1
drivers/gpu/drm/drm_file.c
··· 318 318 if (dev->switch_power_state != DRM_SWITCH_POWER_ON && 319 319 dev->switch_power_state != DRM_SWITCH_POWER_DYNAMIC_OFF) 320 320 return -EINVAL; 321 + if (WARN_ON_ONCE(!(filp->f_op->fop_flags & FOP_UNSIGNED_OFFSET))) 322 + return -EINVAL; 321 323 322 324 drm_dbg_core(dev, "comm=\"%s\", pid=%d, minor=%d\n", 323 325 current->comm, task_pid_nr(current), minor->index); ··· 337 335 } 338 336 339 337 filp->private_data = priv; 340 - filp->f_mode |= FMODE_UNSIGNED_OFFSET; 341 338 priv->filp = filp; 342 339 343 340 mutex_lock(&dev->filelist_mutex);
+1
drivers/gpu/drm/gma500/psb_drv.c
··· 498 498 .mmap = drm_gem_mmap, 499 499 .poll = drm_poll, 500 500 .read = drm_read, 501 + .fop_flags = FOP_UNSIGNED_OFFSET, 501 502 }; 502 503 503 504 static const struct drm_driver driver = {
+1
drivers/gpu/drm/i915/i915_driver.c
··· 1671 1671 #ifdef CONFIG_PROC_FS 1672 1672 .show_fdinfo = drm_show_fdinfo, 1673 1673 #endif 1674 + .fop_flags = FOP_UNSIGNED_OFFSET, 1674 1675 }; 1675 1676 1676 1677 static int
+1
drivers/gpu/drm/nouveau/nouveau_drm.c
··· 1274 1274 .compat_ioctl = nouveau_compat_ioctl, 1275 1275 #endif 1276 1276 .llseek = noop_llseek, 1277 + .fop_flags = FOP_UNSIGNED_OFFSET, 1277 1278 }; 1278 1279 1279 1280 static struct drm_driver
+1
drivers/gpu/drm/radeon/radeon_drv.c
··· 520 520 #ifdef CONFIG_COMPAT 521 521 .compat_ioctl = radeon_kms_compat_ioctl, 522 522 #endif 523 + .fop_flags = FOP_UNSIGNED_OFFSET, 523 524 }; 524 525 525 526 static const struct drm_ioctl_desc radeon_ioctls_kms[] = {
+1
drivers/gpu/drm/tegra/drm.c
··· 801 801 .read = drm_read, 802 802 .compat_ioctl = drm_compat_ioctl, 803 803 .llseek = noop_llseek, 804 + .fop_flags = FOP_UNSIGNED_OFFSET, 804 805 }; 805 806 806 807 static int tegra_drm_context_cleanup(int id, void *p, void *data)
+1
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
··· 1609 1609 .compat_ioctl = vmw_compat_ioctl, 1610 1610 #endif 1611 1611 .llseek = noop_llseek, 1612 + .fop_flags = FOP_UNSIGNED_OFFSET, 1612 1613 }; 1613 1614 1614 1615 static const struct drm_driver driver = {
+1
drivers/gpu/drm/xe/xe_device.c
··· 238 238 #ifdef CONFIG_PROC_FS 239 239 .show_fdinfo = drm_show_fdinfo, 240 240 #endif 241 + .fop_flags = FOP_UNSIGNED_OFFSET, 241 242 }; 242 243 243 244 static struct drm_driver driver = {
+4 -6
fs/proc/base.c
··· 827 827 828 828 static int mem_open(struct inode *inode, struct file *file) 829 829 { 830 - int ret = __mem_open(inode, file, PTRACE_MODE_ATTACH); 831 - 832 - /* OK to pass negative loff_t, we can catch out-of-range */ 833 - file->f_mode |= FMODE_UNSIGNED_OFFSET; 834 - 835 - return ret; 830 + if (WARN_ON_ONCE(!(file->f_op->fop_flags & FOP_UNSIGNED_OFFSET))) 831 + return -EINVAL; 832 + return __mem_open(inode, file, PTRACE_MODE_ATTACH); 836 833 } 837 834 838 835 static ssize_t mem_rw(struct file *file, char __user *buf, ··· 929 932 .write = mem_write, 930 933 .open = mem_open, 931 934 .release = mem_release, 935 + .fop_flags = FOP_UNSIGNED_OFFSET, 932 936 }; 933 937 934 938 static int environ_open(struct inode *inode, struct file *file)
+1 -1
fs/read_write.c
··· 36 36 37 37 static inline bool unsigned_offsets(struct file *file) 38 38 { 39 - return file->f_mode & FMODE_UNSIGNED_OFFSET; 39 + return file->f_op->fop_flags & FOP_UNSIGNED_OFFSET; 40 40 } 41 41 42 42 /**
+2 -1
include/drm/drm_accel.h
··· 28 28 .poll = drm_poll,\ 29 29 .read = drm_read,\ 30 30 .llseek = noop_llseek, \ 31 - .mmap = drm_gem_mmap 31 + .mmap = drm_gem_mmap, \ 32 + .fop_flags = FOP_UNSIGNED_OFFSET 32 33 33 34 /** 34 35 * DEFINE_DRM_ACCEL_FOPS() - macro to generate file operations for accelerators drivers
+2 -1
include/drm/drm_gem.h
··· 447 447 .poll = drm_poll,\ 448 448 .read = drm_read,\ 449 449 .llseek = noop_llseek,\ 450 - .mmap = drm_gem_mmap 450 + .mmap = drm_gem_mmap, \ 451 + .fop_flags = FOP_UNSIGNED_OFFSET 451 452 452 453 /** 453 454 * DEFINE_DRM_GEM_FOPS() - macro to generate file operations for GEM drivers
+1
include/drm/drm_gem_dma_helper.h
··· 267 267 .read = drm_read,\ 268 268 .llseek = noop_llseek,\ 269 269 .mmap = drm_gem_mmap,\ 270 + .fop_flags = FOP_UNSIGNED_OFFSET, \ 270 271 DRM_GEM_DMA_UNMAPPED_AREA_FOPS \ 271 272 } 272 273
+3 -2
include/linux/fs.h
··· 146 146 /* Expect random access pattern */ 147 147 #define FMODE_RANDOM ((__force fmode_t)(1 << 12)) 148 148 149 - /* File is huge (eg. /dev/mem): treat loff_t as unsigned */ 150 - #define FMODE_UNSIGNED_OFFSET ((__force fmode_t)(1 << 13)) 149 + /* FMODE_* bit 13 */ 151 150 152 151 /* File is opened with O_PATH; almost nothing can be done with it */ 153 152 #define FMODE_PATH ((__force fmode_t)(1 << 14)) ··· 2072 2073 #define FOP_DIO_PARALLEL_WRITE ((__force fop_flags_t)(1 << 3)) 2073 2074 /* Contains huge pages */ 2074 2075 #define FOP_HUGE_PAGES ((__force fop_flags_t)(1 << 4)) 2076 + /* Treat loff_t as unsigned (e.g., /dev/mem) */ 2077 + #define FOP_UNSIGNED_OFFSET ((__force fop_flags_t)(1 << 5)) 2075 2078 2076 2079 /* Wrap a directory iterator that needs exclusive inode access */ 2077 2080 int wrap_directory_iterator(struct file *, struct dir_context *,
+1 -1
mm/mmap.c
··· 1229 1229 return MAX_LFS_FILESIZE; 1230 1230 1231 1231 /* Special "we do even unsigned file positions" case */ 1232 - if (file->f_mode & FMODE_UNSIGNED_OFFSET) 1232 + if (file->f_op->fop_flags & FOP_UNSIGNED_OFFSET) 1233 1233 return 0; 1234 1234 1235 1235 /* Yes, random drivers might want more. But I'm tired of buggy drivers */