<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux/fs/sysfs, branch v3.13</title>
<subtitle>Linux kernel source tree</subtitle>
<id>https://git.amat.us/linux/atom/fs/sysfs?h=v3.13</id>
<link rel='self' href='https://git.amat.us/linux/atom/fs/sysfs?h=v3.13'/>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/'/>
<updated>2013-12-08T05:22:00Z</updated>
<entry>
<title>sysfs: give different locking key to regular and bin files</title>
<updated>2013-12-08T05:22:00Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-12-04T14:20:40Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=a8b14744429f90763f258ad0f69601cdcad610aa'/>
<id>urn:sha1:a8b14744429f90763f258ad0f69601cdcad610aa</id>
<content type='text'>
027a485d12e0 ("sysfs: use a separate locking class for open files
depending on mmap") assigned different lockdep key to
sysfs_open_file-&gt;mutex depending on whether the file implements mmap
or not in an attempt to avoid spurious lockdep warning caused by
merging of regular and bin file paths.

While this restored some of the original behavior of using different
locks (at least lockdep is concerned) for the different clases of
files.  The restoration wasn't full because now the lockdep key
assignment depends on whether the file has mmap or not instead of
whether it's a regular file or not.

This means that bin files which don't implement mmap will get assigned
the same lockdep class as regular files.  This is problematic because
file_operations for bin files still implements the mmap file operation
and checking whether the sysfs file actually implements mmap happens
in the file operation after grabbing @sysfs_open_file-&gt;mutex.  We
still end up adding locking dependency from mmap locking to
sysfs_open_file-&gt;mutex to the regular file mutex which triggers
spurious circular locking warning.

Fix it by restoring the original behavior fully by differentiating
lockdep key by whether the file is regular or bin, instead of the
existence of mmap.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Dave Jones &lt;davej@redhat.com&gt;
Link: http://lkml.kernel.org/g/20131203184324.GA11320@redhat.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Revert "sysfs: handle duplicate removal attempts in sysfs_remove_group()"</title>
<updated>2013-11-27T17:44:55Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2013-11-27T17:44:55Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=81440e73744446adbe5b5d1f19460203d275028f'/>
<id>urn:sha1:81440e73744446adbe5b5d1f19460203d275028f</id>
<content type='text'>
This reverts commit 54d71145a4548330313ca664a4a009772fe8b7dd.

The root cause of these "inverted" sysfs removals have now been found,
so there is no need for this patch.  Keep this functionality around so
that this type of error doesn't show up in driver code again.

Cc: Mika Westerberg &lt;mika.westerberg@linux.intel.com&gt;
Cc: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: use a separate locking class for open files depending on mmap</title>
<updated>2013-11-23T18:52:13Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-11-17T02:17:36Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=027a485d12e089314360d459b8d847104dd28702'/>
<id>urn:sha1:027a485d12e089314360d459b8d847104dd28702</id>
<content type='text'>
The following two commits implemented mmap support in the regular file
path and merged bin file support into the regular path.

 73d9714627ad ("sysfs: copy bin mmap support from fs/sysfs/bin.c to fs/sysfs/file.c")
 3124eb1679b2 ("sysfs: merge regular and bin file handling")

After the merge, the following commands trigger a spurious lockdep
warning.  "test-mmap-read" simply mmaps the file and dumps the
content.

  $ cat /sys/block/sda/trace/act_mask
  $ test-mmap-read /sys/devices/pci0000\:00/0000\:00\:03.0/resource0 4096

  ======================================================
  [ INFO: possible circular locking dependency detected ]
  3.12.0-work+ #378 Not tainted
  -------------------------------------------------------
  test-mmap-read/567 is trying to acquire lock:
   (&amp;of-&gt;mutex){+.+.+.}, at: [&lt;ffffffff8120a8df&gt;] sysfs_bin_mmap+0x4f/0x120

  but task is already holding lock:
   (&amp;mm-&gt;mmap_sem){++++++}, at: [&lt;ffffffff8114b399&gt;] vm_mmap_pgoff+0x49/0xa0

  which lock already depends on the new lock.

  the existing dependency chain (in reverse order) is:

  -&gt; #3 (&amp;mm-&gt;mmap_sem){++++++}:
  ...
  -&gt; #2 (sr_mutex){+.+.+.}:
  ...
  -&gt; #1 (&amp;bdev-&gt;bd_mutex){+.+.+.}:
  ...
  -&gt; #0 (&amp;of-&gt;mutex){+.+.+.}:
  ...

  other info that might help us debug this:

  Chain exists of:
   &amp;of-&gt;mutex --&gt; sr_mutex --&gt; &amp;mm-&gt;mmap_sem

   Possible unsafe locking scenario:

	 CPU0                    CPU1
	 ----                    ----
    lock(&amp;mm-&gt;mmap_sem);
				 lock(sr_mutex);
				 lock(&amp;mm-&gt;mmap_sem);
    lock(&amp;of-&gt;mutex);

   *** DEADLOCK ***

  1 lock held by test-mmap-read/567:
   #0:  (&amp;mm-&gt;mmap_sem){++++++}, at: [&lt;ffffffff8114b399&gt;] vm_mmap_pgoff+0x49/0xa0

  stack backtrace:
  CPU: 3 PID: 567 Comm: test-mmap-read Not tainted 3.12.0-work+ #378
  Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
   ffffffff81ed41a0 ffff880009441bc8 ffffffff81611ad2 ffffffff81eccb80
   ffff880009441c08 ffffffff8160f215 ffff880009441c60 ffff880009c75208
   0000000000000000 ffff880009c751e0 ffff880009c75208 ffff880009c74ac0
  Call Trace:
   [&lt;ffffffff81611ad2&gt;] dump_stack+0x4e/0x7a
   [&lt;ffffffff8160f215&gt;] print_circular_bug+0x2b0/0x2bf
   [&lt;ffffffff8109ca0a&gt;] __lock_acquire+0x1a3a/0x1e60
   [&lt;ffffffff8109d6ba&gt;] lock_acquire+0x9a/0x1d0
   [&lt;ffffffff81615547&gt;] mutex_lock_nested+0x67/0x3f0
   [&lt;ffffffff8120a8df&gt;] sysfs_bin_mmap+0x4f/0x120
   [&lt;ffffffff8115d363&gt;] mmap_region+0x3b3/0x5b0
   [&lt;ffffffff8115d8ae&gt;] do_mmap_pgoff+0x34e/0x3d0
   [&lt;ffffffff8114b3ba&gt;] vm_mmap_pgoff+0x6a/0xa0
   [&lt;ffffffff8115be3e&gt;] SyS_mmap_pgoff+0xbe/0x250
   [&lt;ffffffff81008282&gt;] SyS_mmap+0x22/0x30
   [&lt;ffffffff8161a4d2&gt;] system_call_fastpath+0x16/0x1b

This happens because one file nests sr_mutex, which nests mm-&gt;mmap_sem
under it, under of-&gt;mutex while mmap implementation naturally nests
of-&gt;mutex under mm-&gt;mmap_sem.  The warning is false positive as
of-&gt;mutex is per open-file and the two paths belong to two different
files.  This warning didn't trigger before regular and bin file
supports were merged because only bin file supported mmap and the
other side of locking happened only on regular files which used
equivalent but separate locking.

It'd be best if we give separate locking classes per file but we can't
easily do that.  Let's differentiate on -&gt;mmap() for now.  Later we'll
add explicit file operations struct and can add per-ops lockdep key
there.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Dave Jones &lt;davej@redhat.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: handle duplicate removal attempts in sysfs_remove_group()</title>
<updated>2013-11-23T18:52:13Z</updated>
<author>
<name>Mika Westerberg</name>
<email>mika.westerberg@linux.intel.com</email>
</author>
<published>2013-11-20T09:56:35Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=54d71145a4548330313ca664a4a009772fe8b7dd'/>
<id>urn:sha1:54d71145a4548330313ca664a4a009772fe8b7dd</id>
<content type='text'>
Commit bcdde7e221a8 (sysfs: make __sysfs_remove_dir() recursive) changed
the behavior so that directory removals will be done recursively. This
means that the sysfs group might already be removed if its parent directory
has been removed.

The current code outputs warnings similar to following log snippet when it
detects that there is no group for the given kobject:

 WARNING: CPU: 0 PID: 4 at fs/sysfs/group.c:214 sysfs_remove_group+0xc6/0xd0()
 sysfs group ffffffff81c6f1e0 not found for kobject 'host7'
 Modules linked in:
 CPU: 0 PID: 4 Comm: kworker/0:0 Not tainted 3.12.0+ #13
 Hardware name:                  /D33217CK, BIOS GKPPT10H.86A.0042.2013.0422.1439 04/22/2013
 Workqueue: kacpi_hotplug acpi_hotplug_work_fn
  0000000000000009 ffff8801002459b0 ffffffff817daab1 ffff8801002459f8
  ffff8801002459e8 ffffffff810436b8 0000000000000000 ffffffff81c6f1e0
  ffff88006d440358 ffff88006d440188 ffff88006e8b4c28 ffff880100245a48
 Call Trace:
  [&lt;ffffffff817daab1&gt;] dump_stack+0x45/0x56
  [&lt;ffffffff810436b8&gt;] warn_slowpath_common+0x78/0xa0
  [&lt;ffffffff81043727&gt;] warn_slowpath_fmt+0x47/0x50
  [&lt;ffffffff811ad319&gt;] ? sysfs_get_dirent_ns+0x49/0x70
  [&lt;ffffffff811ae526&gt;] sysfs_remove_group+0xc6/0xd0
  [&lt;ffffffff81432f7e&gt;] dpm_sysfs_remove+0x3e/0x50
  [&lt;ffffffff8142a0d0&gt;] device_del+0x40/0x1b0
  [&lt;ffffffff8142a24d&gt;] device_unregister+0xd/0x20
  [&lt;ffffffff8144131a&gt;] scsi_remove_host+0xba/0x110
  [&lt;ffffffff8145f526&gt;] ata_host_detach+0xc6/0x100
  [&lt;ffffffff8145f578&gt;] ata_pci_remove_one+0x18/0x20
  [&lt;ffffffff812e8f48&gt;] pci_device_remove+0x28/0x60
  [&lt;ffffffff8142d854&gt;] __device_release_driver+0x64/0xd0
  [&lt;ffffffff8142d8de&gt;] device_release_driver+0x1e/0x30
  [&lt;ffffffff8142d257&gt;] bus_remove_device+0xf7/0x140
  [&lt;ffffffff8142a1b1&gt;] device_del+0x121/0x1b0
  [&lt;ffffffff812e43d4&gt;] pci_stop_bus_device+0x94/0xa0
  [&lt;ffffffff812e437b&gt;] pci_stop_bus_device+0x3b/0xa0
  [&lt;ffffffff812e437b&gt;] pci_stop_bus_device+0x3b/0xa0
  [&lt;ffffffff812e44dd&gt;] pci_stop_and_remove_bus_device+0xd/0x20
  [&lt;ffffffff812fc743&gt;] trim_stale_devices+0x73/0xe0
  [&lt;ffffffff812fc78b&gt;] trim_stale_devices+0xbb/0xe0
  [&lt;ffffffff812fc78b&gt;] trim_stale_devices+0xbb/0xe0
  [&lt;ffffffff812fcb6e&gt;] acpiphp_check_bridge+0x7e/0xd0
  [&lt;ffffffff812fd90d&gt;] hotplug_event+0xcd/0x160
  [&lt;ffffffff812fd9c5&gt;] hotplug_event_work+0x25/0x60
  [&lt;ffffffff81316749&gt;] acpi_hotplug_work_fn+0x17/0x22
  [&lt;ffffffff8105cf3a&gt;] process_one_work+0x17a/0x430
  [&lt;ffffffff8105db29&gt;] worker_thread+0x119/0x390
  [&lt;ffffffff8105da10&gt;] ? manage_workers.isra.25+0x2a0/0x2a0
  [&lt;ffffffff81063a5d&gt;] kthread+0xcd/0xf0
  [&lt;ffffffff81063990&gt;] ? kthread_create_on_node+0x180/0x180
  [&lt;ffffffff817eb33c&gt;] ret_from_fork+0x7c/0xb0
  [&lt;ffffffff81063990&gt;] ? kthread_create_on_node+0x180/0x180

On this particular machine I see ~16 of these message during Thunderbolt
hot-unplug.

Fix this in similar way that was done for sysfs_remove_one() by checking
if the parent directory has already been removed and bailing out early.

Signed-off-by: Mika Westerberg &lt;mika.westerberg@linux.intel.com&gt;
Acked-by: Rafael J. Wysocki &lt;rafael.j.wysocki@intel.com&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Revert "sysfs: drop kobj_ns_type handling"</title>
<updated>2013-11-07T11:47:28Z</updated>
<author>
<name>Linus Torvalds</name>
<email>torvalds@linux-foundation.org</email>
</author>
<published>2013-11-07T11:47:28Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=a1212d278c05ca0a38f5cbd7ae90ac2e367228a8'/>
<id>urn:sha1:a1212d278c05ca0a38f5cbd7ae90ac2e367228a8</id>
<content type='text'>
This reverts commit cb26a311578e67769e92a39a0a63476533cb7e12.

It mysteriously causes NetworkManager to not find the wireless device
for me.  As far as I can tell, Tejun *meant* for this commit to not make
any semantic changes, but there clearly are some.  So revert it, taking
into account some of the calling convention changes that happened in
this area in subsequent commits.

Cc: Tejun Heo &lt;tj@kernel.org&gt;
Cc: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: rename sysfs_assoc_lock and explain what it's about</title>
<updated>2013-11-01T19:13:37Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-30T14:28:36Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=0cae60f91494e34a0c5391f1455f825d5849b05f'/>
<id>urn:sha1:0cae60f91494e34a0c5391f1455f825d5849b05f</id>
<content type='text'>
sysfs_assoc_lock is an odd piece of locking.  In general, whoever owns
a kobject is responsible for synchronizing sysfs operations and sysfs
proper assumes that, for example, removal won't race with any other
operation; however, this doesn't work for symlinking because an entity
performing symlink doesn't usually own the target kobject and thus has
no control over its removal.

sysfs_assoc_lock synchronizes symlink operations against kobj-&gt;sd
disassociation so that symlink code doesn't end up dereferencing
already freed sysfs_dirent by racing with removal of the target
kobject.

This is quite obscure and the generic name of the lock and lack of
comments make it difficult to understand its role.  Let's rename it to
sysfs_symlink_target_lock and add comments explaining what's going on.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: use generic_file_llseek() for sysfs_file_operations</title>
<updated>2013-11-01T19:13:37Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-11-01T17:16:53Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=044e3bc33391b1f2769d5ab2c04f246c3d8e04c3'/>
<id>urn:sha1:044e3bc33391b1f2769d5ab2c04f246c3d8e04c3</id>
<content type='text'>
13c589d5b0ac6 ("sysfs: use seq_file when reading regular files")
converted regular sysfs files to use seq_file.  The commit substituted
generic_file_llseek() with seq_lseek() for llseek implementation.

Before the change, all regular sysfs files were allowed to seek to any
position in [0, PAGE_SIZE] as the file size is always PAGE_SIZE and
generic_file_llseek() allows any seeking inside the range under file
size; however, seq_lseek()'s behavior is different.  It traverses the
output by repeatedly invoking -&gt;show() until it reaches the target
offset or traversal indicates EOF.  As seq_files are fully dynamic and
may not end at all, it doesn't support seeking from the end
(SEEK_END).

Apparently, there are userland tools which uses SEEK_END to discover
the buffer size to use and the switch to seq_lseek() disturbs them as
SEEK_END fails with -EINVAL.

The only benefits of using seq_lseek() instead of
generic_file_llseek() are

* Early failure.  If traversing to certain file position should fail,
  seq_lseek() will report such failures on lseek(2) instead of the
  following read/write operations.

* EOF detection.  While SEEK_END is not supported, SEEK_SET/CUR +
  large offset can be used to detect eof - eof at the time of the seek
  anyway as the file size may change dynamically.

Both aren't necessary for sysfs or prospect kernfs users.  Revert to
genefic_file_llseek() and preserve the original behavior.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Heiko Carstens &lt;heiko.carstens@de.ibm.com&gt;
Link: https://lkml.kernel.org/r/20131031114358.GA5551@osiris
Tested-by: Heiko Carstens &lt;heiko.carstens@de.ibm.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: return correct error code on unimplemented mmap()</title>
<updated>2013-10-30T17:21:39Z</updated>
<author>
<name>Vladimir Zapolskiy</name>
<email>vladimir_zapolskiy@mentor.com</email>
</author>
<published>2013-10-30T12:08:32Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=1c1365e374bfadf908eae02cded7abb9e672c9d4'/>
<id>urn:sha1:1c1365e374bfadf908eae02cded7abb9e672c9d4</id>
<content type='text'>
Both POSIX.1-2008 and Linux Programmer's Manual have a dedicated return
error code for a case, when a file doesn't support mmap(), it's ENODEV.

This change replaces overloaded EINVAL with ENODEV in a situation
described above for sysfs binary files.

Signed-off-by: Vladimir Zapolskiy &lt;vladimir_zapolskiy@mentor.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: separate out dup filename warning into a separate function</title>
<updated>2013-10-29T22:12:07Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-24T15:49:11Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=d1c1459e45944e336a968acce1e459c9effcde47'/>
<id>urn:sha1:d1c1459e45944e336a968acce1e459c9effcde47</id>
<content type='text'>
Separate out sysfs_warn_dup() out of sysfs_add_one().  This will help
separating out the core sysfs functionalities into kernfs so that it
can be used by non-sysfs users too.

This doesn't make any functional changes.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>sysfs: move sysfs_hash_and_remove() to fs/sysfs/dir.c</title>
<updated>2013-10-29T22:12:07Z</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-24T15:49:10Z</published>
<link rel='alternate' type='text/html' href='https://git.amat.us/linux/commit/?id=7eed6ecb0785681892ab1fe47188fc981241cfd0'/>
<id>urn:sha1:7eed6ecb0785681892ab1fe47188fc981241cfd0</id>
<content type='text'>
Most removal related logic is implemented in fs/sysfs/dir.c.  Move
sysfs_hash_and_remove() to fs/sysfs/dir.c so that __sysfs_remove()
doesn't have to be public.

This is pure relocation.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
