<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux.git/fs/sysfs/file.c, branch v3.13</title>
<subtitle>Linux kernel source tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/'/>
<entry>
<title>sysfs: give different locking key to regular and bin files</title>
<updated>2013-12-08T05:22:00+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-12-04T14:20:40+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=a8b14744429f90763f258ad0f69601cdcad610aa'/>
<id>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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: use a separate locking class for open files depending on mmap</title>
<updated>2013-11-23T18:52:13+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-11-17T02:17:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=027a485d12e089314360d459b8d847104dd28702'/>
<id>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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: use generic_file_llseek() for sysfs_file_operations</title>
<updated>2013-11-01T19:13:37+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-11-01T17:16:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=044e3bc33391b1f2769d5ab2c04f246c3d8e04c3'/>
<id>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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: return correct error code on unimplemented mmap()</title>
<updated>2013-10-30T17:21:39+00:00</updated>
<author>
<name>Vladimir Zapolskiy</name>
<email>vladimir_zapolskiy@mentor.com</email>
</author>
<published>2013-10-30T12:08:32+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=1c1365e374bfadf908eae02cded7abb9e672c9d4'/>
<id>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>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
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;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr</title>
<updated>2013-10-29T22:12:06+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-24T15:49:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=56b3f3b884652395e1025a8e4f1c4bd47bc112c4'/>
<id>56b3f3b884652395e1025a8e4f1c4bd47bc112c4</id>
<content type='text'>
3124eb1679 ("sysfs: merge regular and bin file handling") folded bin
file handling into regular file handling.  Among other things, bin
file now shares the same open path including sysfs_open_dirent
association using sysfs_dirent-&gt;s_attr.open.  This is buggy because
-&gt;s_bin_attr lives in the same union and doesn't have the field.  This
bug doesn't trigger because sysfs_elem_bin_attr doesn't have an active
field at the conflicting position.  It does have a field "buffers" but
it isn't used anymore.

This patch collapses sysfs_elem_bin_attr into sysfs_elem_attr so that
the bin_attr is accessed through -&gt;s_attr.bin_attr which lives with
-&gt;s_attr.attr in an anonymous union.  The code paths already assume
bin_attr contains attr as the first element, so this doesn't add any
more assumptions while making it explicit that the two types are
handled together.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
3124eb1679 ("sysfs: merge regular and bin file handling") folded bin
file handling into regular file handling.  Among other things, bin
file now shares the same open path including sysfs_open_dirent
association using sysfs_dirent-&gt;s_attr.open.  This is buggy because
-&gt;s_bin_attr lives in the same union and doesn't have the field.  This
bug doesn't trigger because sysfs_elem_bin_attr doesn't have an active
field at the conflicting position.  It does have a field "buffers" but
it isn't used anymore.

This patch collapses sysfs_elem_bin_attr into sysfs_elem_attr so that
the bin_attr is accessed through -&gt;s_attr.bin_attr which lives with
-&gt;s_attr.attr in an anonymous union.  The code paths already assume
bin_attr contains attr as the first element, so this doesn't add any
more assumptions while making it explicit that the two types are
handled together.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: fix sysfs_write_file for bin file</title>
<updated>2013-10-25T04:46:27+00:00</updated>
<author>
<name>Ming Lei</name>
<email>ming.lei@canonical.com</email>
</author>
<published>2013-10-23T13:44:53+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=b9c0622516b73170fa9abffece3079920b78ed6f'/>
<id>b9c0622516b73170fa9abffece3079920b78ed6f</id>
<content type='text'>
Before patch(sysfs: prepare path write for unified regular / bin
file handling), when size of bin file is zero, writting still can
continue, but this patch changes the behaviour.

The worse thing is that firmware loader is broken by this patch,
and user space application can't write to firmware bin file any more
because both firmware loader and drivers can't know at advance how
large the firmware file is and have to set its initialized size as
zero.

This patch fixes the problem and keeps behaviour of writting to bin
as before.

Reported-by: Lothar Waßmann &lt;LW@karo-electronics.de&gt;
Tested-by: Lothar Waßmann &lt;LW@karo-electronics.de&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Ming Lei &lt;ming.lei@canonical.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Before patch(sysfs: prepare path write for unified regular / bin
file handling), when size of bin file is zero, writting still can
continue, but this patch changes the behaviour.

The worse thing is that firmware loader is broken by this patch,
and user space application can't write to firmware bin file any more
because both firmware loader and drivers can't know at advance how
large the firmware file is and have to set its initialized size as
zero.

This patch fixes the problem and keeps behaviour of writting to bin
as before.

Reported-by: Lothar Waßmann &lt;LW@karo-electronics.de&gt;
Tested-by: Lothar Waßmann &lt;LW@karo-electronics.de&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Ming Lei &lt;ming.lei@canonical.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs/bin: Fix size handling overflow for bin_attribute</title>
<updated>2013-10-14T17:07:19+00:00</updated>
<author>
<name>Benjamin Herrenschmidt</name>
<email>benh@kernel.crashing.org</email>
</author>
<published>2013-10-10T07:03:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=d723a92dd465d549bf79dd481c09d59f0be02936'/>
<id>d723a92dd465d549bf79dd481c09d59f0be02936</id>
<content type='text'>
While looking at the code, I noticed that bin_attribute read() and write()
ops copy the inode size into an int for futher comparisons.

Some bin_attributes can be fairly large. For example, pci creates some for
BARs set to the BAR size and giant BARs are around the corner, so this is
going to break something somewhere eventually.

Let's use the right type.

[adjust for seqfile conversions, only needed for bin_read() - gkh]

Signed-off-by: Benjamin Herrenschmidt &lt;benh@kernel.crashing.org&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
While looking at the code, I noticed that bin_attribute read() and write()
ops copy the inode size into an int for futher comparisons.

Some bin_attributes can be fairly large. For example, pci creates some for
BARs set to the BAR size and giant BARs are around the corner, so this is
going to break something somewhere eventually.

Let's use the right type.

[adjust for seqfile conversions, only needed for bin_read() - gkh]

Signed-off-by: Benjamin Herrenschmidt &lt;benh@kernel.crashing.org&gt;
Cc: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: make sysfs_file_ops() follow ignore_lockdep flag</title>
<updated>2013-10-14T15:40:39+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-14T13:27:11+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=785a162d147a547bc7a577c1c28f6fb9dbeb4f16'/>
<id>785a162d147a547bc7a577c1c28f6fb9dbeb4f16</id>
<content type='text'>
375b611e60 ("sysfs: remove sysfs_buffer-&gt;ops") introduced
sysfs_file_ops() which determines the associated file operation of a
given sysfs_dirent.  As file ops access should be protected by an
active reference, the new function includes a lockdep assertion on the
sysfs_dirent; unfortunately, I forgot to take attr-&gt;ignore_lockdep
flag into account and the lockdep assertion trips spuriously for files
which opt out from active reference lockdep checking.

# cat /sys/devices/pci0000:00/0000:00:01.2/usb1/authorized

 ------------[ cut here ]------------
 WARNING: CPU: 1 PID: 540 at /work/os/work/fs/sysfs/file.c:79 sysfs_file_ops+0x4e/0x60()
 Modules linked in:
 CPU: 1 PID: 540 Comm: cat Not tainted 3.11.0-work+ #3
 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
  0000000000000009 ffff880016205c08 ffffffff81ca0131 0000000000000000
  ffff880016205c40 ffffffff81096d0d ffff8800166cb898 ffff8800166f6f60
  ffffffff8125a220 ffff880011ab1ec0 ffff88000aff0c78 ffff880016205c50
 Call Trace:
  [&lt;ffffffff81ca0131&gt;] dump_stack+0x4e/0x82
  [&lt;ffffffff81096d0d&gt;] warn_slowpath_common+0x7d/0xa0
  [&lt;ffffffff81096dea&gt;] warn_slowpath_null+0x1a/0x20
  [&lt;ffffffff8125994e&gt;] sysfs_file_ops+0x4e/0x60
  [&lt;ffffffff8125a274&gt;] sysfs_open_file+0x54/0x300
  [&lt;ffffffff811df612&gt;] do_dentry_open.isra.17+0x182/0x280
  [&lt;ffffffff811df820&gt;] finish_open+0x30/0x40
  [&lt;ffffffff811f0623&gt;] do_last+0x503/0xd90
  [&lt;ffffffff811f0f6b&gt;] path_openat+0xbb/0x6d0
  [&lt;ffffffff811f23ba&gt;] do_filp_open+0x3a/0x90
  [&lt;ffffffff811e09a9&gt;] do_sys_open+0x129/0x220
  [&lt;ffffffff811e0abe&gt;] SyS_open+0x1e/0x20
  [&lt;ffffffff81caf3c2&gt;] system_call_fastpath+0x16/0x1b
 ---[ end trace aa48096b111dafdb ]---

Rename fs/sysfs/dir.c::ignore_lockdep() to sysfs_ignore_lockdep() and
move it to fs/sysfs/sysfs.h and make sysfs_file_ops() skip lockdep
assertion if sysfs_ignore_lockdep() is true.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Yinghai Lu &lt;yinghai@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
375b611e60 ("sysfs: remove sysfs_buffer-&gt;ops") introduced
sysfs_file_ops() which determines the associated file operation of a
given sysfs_dirent.  As file ops access should be protected by an
active reference, the new function includes a lockdep assertion on the
sysfs_dirent; unfortunately, I forgot to take attr-&gt;ignore_lockdep
flag into account and the lockdep assertion trips spuriously for files
which opt out from active reference lockdep checking.

# cat /sys/devices/pci0000:00/0000:00:01.2/usb1/authorized

 ------------[ cut here ]------------
 WARNING: CPU: 1 PID: 540 at /work/os/work/fs/sysfs/file.c:79 sysfs_file_ops+0x4e/0x60()
 Modules linked in:
 CPU: 1 PID: 540 Comm: cat Not tainted 3.11.0-work+ #3
 Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
  0000000000000009 ffff880016205c08 ffffffff81ca0131 0000000000000000
  ffff880016205c40 ffffffff81096d0d ffff8800166cb898 ffff8800166f6f60
  ffffffff8125a220 ffff880011ab1ec0 ffff88000aff0c78 ffff880016205c50
 Call Trace:
  [&lt;ffffffff81ca0131&gt;] dump_stack+0x4e/0x82
  [&lt;ffffffff81096d0d&gt;] warn_slowpath_common+0x7d/0xa0
  [&lt;ffffffff81096dea&gt;] warn_slowpath_null+0x1a/0x20
  [&lt;ffffffff8125994e&gt;] sysfs_file_ops+0x4e/0x60
  [&lt;ffffffff8125a274&gt;] sysfs_open_file+0x54/0x300
  [&lt;ffffffff811df612&gt;] do_dentry_open.isra.17+0x182/0x280
  [&lt;ffffffff811df820&gt;] finish_open+0x30/0x40
  [&lt;ffffffff811f0623&gt;] do_last+0x503/0xd90
  [&lt;ffffffff811f0f6b&gt;] path_openat+0xbb/0x6d0
  [&lt;ffffffff811f23ba&gt;] do_filp_open+0x3a/0x90
  [&lt;ffffffff811e09a9&gt;] do_sys_open+0x129/0x220
  [&lt;ffffffff811e0abe&gt;] SyS_open+0x1e/0x20
  [&lt;ffffffff81caf3c2&gt;] system_call_fastpath+0x16/0x1b
 ---[ end trace aa48096b111dafdb ]---

Rename fs/sysfs/dir.c::ignore_lockdep() to sysfs_ignore_lockdep() and
move it to fs/sysfs/sysfs.h and make sysfs_file_ops() skip lockdep
assertion if sysfs_ignore_lockdep() is true.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Reported-by: Yinghai Lu &lt;yinghai@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: merge regular and bin file handling</title>
<updated>2013-10-06T00:27:40+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-01T21:42:09+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=3124eb1679b28726eacbc8973a891235dca3ed99'/>
<id>3124eb1679b28726eacbc8973a891235dca3ed99</id>
<content type='text'>
With the previous changes, sysfs regular file code is ready to handle
bin files too.  This patch makes bin files share the regular file
path.

* sysfs_create/remove_bin_file() are moved to fs/sysfs/file.c.

* sysfs_init_inode() is updated to use the new sysfs_bin_operations
  instead of bin_fops for bin files.

* fs/sysfs/bin.c and the related pieces are removed.

This patch shouldn't introduce any behavior difference to bin file
accesses.

Overall, this unification reduces the amount of duplicate logic, makes
behaviors more consistent and paves the road for building simpler and
more versatile interface which will allow other subsystems to make use
of sysfs for their pseudo filesystems.

v2: Stale fs/sysfs/bin.c reference dropped from
    Documentation/DocBook/filesystems.tmpl.  Reported by kbuild test
    robot.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: kbuild test robot &lt;fengguang.wu@intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
With the previous changes, sysfs regular file code is ready to handle
bin files too.  This patch makes bin files share the regular file
path.

* sysfs_create/remove_bin_file() are moved to fs/sysfs/file.c.

* sysfs_init_inode() is updated to use the new sysfs_bin_operations
  instead of bin_fops for bin files.

* fs/sysfs/bin.c and the related pieces are removed.

This patch shouldn't introduce any behavior difference to bin file
accesses.

Overall, this unification reduces the amount of duplicate logic, makes
behaviors more consistent and paves the road for building simpler and
more versatile interface which will allow other subsystems to make use
of sysfs for their pseudo filesystems.

v2: Stale fs/sysfs/bin.c reference dropped from
    Documentation/DocBook/filesystems.tmpl.  Reported by kbuild test
    robot.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Cc: Kay Sievers &lt;kay@vrfy.org&gt;
Cc: kbuild test robot &lt;fengguang.wu@intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>sysfs: prepare open path for unified regular / bin file handling</title>
<updated>2013-10-06T00:27:40+00:00</updated>
<author>
<name>Tejun Heo</name>
<email>tj@kernel.org</email>
</author>
<published>2013-10-01T21:42:08+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux.git/commit/?id=49fe604781cbb03eb6ff12a7bc4ad8eef8b830c4'/>
<id>49fe604781cbb03eb6ff12a7bc4ad8eef8b830c4</id>
<content type='text'>
sysfs bin file handling will be merged into the regular file support.
This patch prepares the open path.

This patch updates sysfs_open_file() such that it can handle both
regular and bin files.

This is a preparation and the new bin file path isn't used yet.

Signed-off-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
sysfs bin file handling will be merged into the regular file support.
This patch prepares the open path.

This patch updates sysfs_open_file() such that it can handle both
regular and bin files.

This is a preparation and the new bin file path isn't used yet.

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