git: 1123986db5f0 - main - device_pager: Add cdev_pager_get_path to retrieve the "path" for an object
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 27 Mar 2025 20:48:41 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=1123986db5f0b0b3bfc68840a6d8e12f93d6ca3e commit 1123986db5f0b0b3bfc68840a6d8e12f93d6ca3e Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-03-27 20:44:33 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-03-27 20:44:33 +0000 device_pager: Add cdev_pager_get_path to retrieve the "path" for an object This wraps a new optional cdev_pg_path method in struct cdev_pager_ops. If the method pointer is NULL, the function does nothing. The old device pager reads the pathname of the cdev stored in the object handle to match the existing code. Retire the OBJ_CDEVH flag as it is no longer needed. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D49335 --- sys/kern/kern_proc.c | 22 ++++++---------------- sys/vm/device_pager.c | 21 ++++++++++++++++++++- sys/vm/vm_mmap.c | 3 --- sys/vm/vm_object.c | 18 ++++-------------- sys/vm/vm_object.h | 1 - sys/vm/vm_pager.h | 2 ++ 6 files changed, 32 insertions(+), 35 deletions(-) diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 463ecb025317..ee15efb5fb31 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -91,6 +91,7 @@ #include <vm/vm_map.h> #include <vm/vm_object.h> #include <vm/vm_page.h> +#include <vm/vm_pager.h> #include <vm/uma.h> #include <fs/devfs/devfs.h> @@ -2615,11 +2616,9 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) struct ucred *cred; struct vnode *vp; struct vmspace *vm; - struct cdev *cdev; - struct cdevsw *csw; vm_offset_t addr; unsigned int last_timestamp; - int error, ref; + int error; key_t key; unsigned short seq; bool guard, super; @@ -2715,19 +2714,10 @@ kern_proc_vmmap_out(struct proc *p, struct sbuf *sb, ssize_t maxlen, int flags) kve->kve_ref_count = obj->ref_count; kve->kve_shadow_count = obj->shadow_count; - if ((obj->type == OBJT_DEVICE || - obj->type == OBJT_MGTDEVICE) && - (obj->flags & OBJ_CDEVH) != 0) { - cdev = obj->un_pager.devp.handle; - if (cdev != NULL) { - csw = dev_refthread(cdev, &ref); - if (csw != NULL) { - strlcpy(kve->kve_path, - cdev->si_name, sizeof( - kve->kve_path)); - dev_relthread(cdev, ref); - } - } + if (obj->type == OBJT_DEVICE || + obj->type == OBJT_MGTDEVICE) { + cdev_pager_get_path(obj, kve->kve_path, + sizeof(kve->kve_path)); } VM_OBJECT_RUNLOCK(obj); if ((lobj->flags & OBJ_SYSVSHM) != 0) { diff --git a/sys/vm/device_pager.c b/sys/vm/device_pager.c index 15626938ba95..96c3e97d97a6 100644 --- a/sys/vm/device_pager.c +++ b/sys/vm/device_pager.c @@ -97,11 +97,13 @@ static int old_dev_pager_ctor(void *handle, vm_ooffset_t size, vm_prot_t prot, static void old_dev_pager_dtor(void *handle); static int old_dev_pager_fault(vm_object_t object, vm_ooffset_t offset, int prot, vm_page_t *mres); +static void old_dev_pager_path(void *handle, char *path, size_t len); static const struct cdev_pager_ops old_dev_pager_ops = { .cdev_pg_ctor = old_dev_pager_ctor, .cdev_pg_dtor = old_dev_pager_dtor, - .cdev_pg_fault = old_dev_pager_fault + .cdev_pg_fault = old_dev_pager_fault, + .cdev_pg_path = old_dev_pager_path }; static void @@ -262,6 +264,14 @@ dev_pager_alloc(void *handle, vm_ooffset_t size, vm_prot_t prot, size, prot, foff, cred)); } +void +cdev_pager_get_path(vm_object_t object, char *path, size_t sz) +{ + if (object->un_pager.devp.ops->cdev_pg_path != NULL) + object->un_pager.devp.ops->cdev_pg_path( + object->un_pager.devp.handle, path, sz); +} + void cdev_pager_free_page(vm_object_t object, vm_page_t m) { @@ -537,3 +547,12 @@ old_dev_pager_dtor(void *handle) dev_rel(handle); } + +static void +old_dev_pager_path(void *handle, char *path, size_t len) +{ + struct cdev *cdev = handle; + + if (cdev != NULL) + dev_copyname(cdev, path, len); +} diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index c3672f884f25..afc25965d73c 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1407,9 +1407,6 @@ vm_mmap_cdev(struct thread *td, vm_size_t objsize, vm_prot_t prot, td->td_ucred); if (obj == NULL) return (EINVAL); - VM_OBJECT_WLOCK(obj); - vm_object_set_flag(obj, OBJ_CDEVH); - VM_OBJECT_WUNLOCK(obj); *objp = obj; *flagsp = flags; return (0); diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index 592f48296c22..4ab20a86e155 100644 --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -2485,10 +2485,8 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only) struct vattr va; vm_object_t obj; vm_page_t m; - struct cdev *cdev; - struct cdevsw *csw; u_long sp; - int count, error, ref; + int count, error; key_t key; unsigned short seq; bool want_path; @@ -2577,17 +2575,9 @@ vm_object_list_handler(struct sysctl_req *req, bool swap_only) sp = swap_pager_swapped_pages(obj); kvo->kvo_swapped = sp > UINT32_MAX ? UINT32_MAX : sp; } - if ((obj->type == OBJT_DEVICE || obj->type == OBJT_MGTDEVICE) && - (obj->flags & OBJ_CDEVH) != 0) { - cdev = obj->un_pager.devp.handle; - if (cdev != NULL) { - csw = dev_refthread(cdev, &ref); - if (csw != NULL) { - strlcpy(kvo->kvo_path, cdev->si_name, - sizeof(kvo->kvo_path)); - dev_relthread(cdev, ref); - } - } + if (obj->type == OBJT_DEVICE || obj->type == OBJT_MGTDEVICE) { + cdev_pager_get_path(obj, kvo->kvo_path, + sizeof(kvo->kvo_path)); } VM_OBJECT_RUNLOCK(obj); if ((obj->flags & OBJ_SYSVSHM) != 0) { diff --git a/sys/vm/vm_object.h b/sys/vm/vm_object.h index fabd21809036..68cc41731b73 100644 --- a/sys/vm/vm_object.h +++ b/sys/vm/vm_object.h @@ -204,7 +204,6 @@ struct vm_object { #define OBJ_PAGERPRIV2 0x00008000 /* Pager private */ #define OBJ_SYSVSHM 0x00010000 /* SysV SHM */ #define OBJ_POSIXSHM 0x00020000 /* Posix SHM */ -#define OBJ_CDEVH 0x00040000 /* OBJT_DEVICE handle is cdev */ /* * Helpers to perform conversion between vm_object page indexes and offsets. diff --git a/sys/vm/vm_pager.h b/sys/vm/vm_pager.h index c4a9b5e9dcb9..785717628685 100644 --- a/sys/vm/vm_pager.h +++ b/sys/vm/vm_pager.h @@ -293,6 +293,7 @@ struct cdev_pager_ops { int (*cdev_pg_ctor)(void *handle, vm_ooffset_t size, vm_prot_t prot, vm_ooffset_t foff, struct ucred *cred, u_short *color); void (*cdev_pg_dtor)(void *handle); + void (*cdev_pg_path)(void *handle, char *path, size_t len); }; vm_object_t cdev_pager_allocate(void *handle, enum obj_type tp, @@ -302,6 +303,7 @@ vm_object_t cdev_pager_lookup(void *handle); void cdev_pager_free_page(vm_object_t object, vm_page_t m); void cdev_mgtdev_pager_free_page(struct pctrie_iter *pages, vm_page_t m); void cdev_mgtdev_pager_free_pages(vm_object_t object); +void cdev_pager_get_path(vm_object_t object, char *path, size_t sz); struct phys_pager_ops { int (*phys_pg_getpages)(vm_object_t vm_obj, vm_page_t *m, int count,