Bug 198431 - Vnode info not provided for memory mapped tmpfs files in various places
Summary: Vnode info not provided for memory mapped tmpfs files in various places
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 10.0-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Eric van Gyzen
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-08 17:51 UTC by Eric Badger
Modified: 2015-10-02 14:49 UTC (History)
1 user (show)

See Also:


Attachments
Proposed patch (4.45 KB, patch)
2015-03-08 17:51 UTC, Eric Badger
no flags Details | Diff
Proposed patch v2 (4.21 KB, patch)
2015-03-26 15:02 UTC, Eric Badger
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Badger 2015-03-08 17:51:44 UTC
Created attachment 154029 [details]
Proposed patch

Since r250030, when a superfluous VM object for tmpfs VREG files was eliminated, various interfaces (e.g. procfs, KERN_PROC sysctl) that return info about memory maps for processes stopped returning vnode info for tmpfs files. Instead, the mappings would appear as swap type with no further detail. This prevents tools using this information (e.g. dtrace's pid provider) from working correctly. 

Attached a proposed patch. It will, in cases where a VM object with type OBJT_SWAP and OBJ_TMPFS flag is found, populate the vnode pointer appropriately so the vnode information can be extracted. It will also (where applicable) set the memory mapping to appear as a vnode type (this matches FreeBSD 9 behavior, and, per advice from jhb@ and kib@, is desirable because it hides implementation details). In the case where the VM object has the OBJ_TMPFS_NODE but not OBJ_TMPFS flag (i.e. vnode has been recycled), the mapping is still returned as a vnode type, but the vnode pointer is not populated.

The proposed patch covers procstat (-v), procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY).
Comment 1 Eric Badger 2015-03-26 15:02:16 UTC
Created attachment 154829 [details]
Proposed patch v2
Comment 2 Eric Badger 2015-03-26 15:03:28 UTC
Per out of band comment from vangyzen@, I believe the "v2" patch is more correct (doesn't vref with vm_map read locked).
Comment 3 commit-hook freebsd_committer freebsd_triage 2015-06-02 18:37:52 UTC
A commit references this bug:

Author: vangyzen
Date: Tue Jun  2 18:37:06 UTC 2015
New revision: 283924
URL: https://svnweb.freebsd.org/changeset/base/283924

Log:
  Provide vnode in memory map info for files on tmpfs

  When providing memory map information to userland, populate the vnode pointer
  for tmpfs files.  Set the memory mapping to appear as a vnode type, to match
  FreeBSD 9 behavior.

  This fixes the use of tmpfs files with the dtrace pid provider,
  procstat -v, procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY).

  Submitted by:   Eric Badger <eric@badgerio.us> (initial revision)
  Obtained from:  Dell Inc.
  PR:             198431
  MFC after:      2 weeks
  Reviewed by:    jhb
  Approved by:    kib (mentor)

Changes:
  head/sys/compat/linprocfs/linprocfs.c
  head/sys/dev/hwpmc/hwpmc_mod.c
  head/sys/fs/procfs/procfs_map.c
  head/sys/kern/kern_proc.c
  head/sys/kern/sys_process.c
  head/sys/vm/vm_object.c
  head/sys/vm/vm_object.h
Comment 4 commit-hook freebsd_committer freebsd_triage 2015-10-02 14:37:14 UTC
A commit references this bug:

Author: vangyzen
Date: Fri Oct  2 14:36:43 UTC 2015
New revision: 288499
URL: https://svnweb.freebsd.org/changeset/base/288499

Log:
  MFC r283924

  Provide vnode in memory map info for files on tmpfs

  When providing memory map information to userland, populate the vnode pointer
  for tmpfs files.  Set the memory mapping to appear as a vnode type, to match
  FreeBSD 9 behavior.

  This fixes the use of tmpfs files with the dtrace pid provider,
  procstat -v, procfs, linprocfs, pmc (pmcstat), and ptrace (PT_VM_ENTRY).

  Submitted by:   Eric Badger <eric@badgerio.us> (initial revision)
  Obtained from:  Dell Inc.
  PR:             198431

Changes:
_U  stable/10/
  stable/10/sys/compat/linprocfs/linprocfs.c
  stable/10/sys/dev/hwpmc/hwpmc_mod.c
  stable/10/sys/fs/procfs/procfs_map.c
  stable/10/sys/kern/kern_proc.c
  stable/10/sys/kern/sys_process.c
  stable/10/sys/vm/vm_object.c
  stable/10/sys/vm/vm_object.h
Comment 5 Eric van Gyzen freebsd_committer freebsd_triage 2015-10-02 14:49:14 UTC
This only affects 10 and later, so no merge to stable/9 is needed.