<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/vfio/vfio.c, branch linux-5.1.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.1.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-5.1.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2019-06-15T09:53:00Z</updated>
<entry>
<title>vfio: Fix WARNING "do not call blocking ops when !TASK_RUNNING"</title>
<updated>2019-06-15T09:53:00Z</updated>
<author>
<name>Farhan Ali</name>
</author>
<published>2019-04-03T18:22:27Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6a3bde70488edd34a985e89043790bf20df96212'/>
<id>urn:sha1:6a3bde70488edd34a985e89043790bf20df96212</id>
<content type='text'>
[ Upstream commit 41be3e2618174fdf3361e49e64f2bf530f40c6b0 ]

vfio_dev_present() which is the condition to
wait_event_interruptible_timeout(), will call vfio_group_get_device
and try to acquire the mutex group-&gt;device_lock.

wait_event_interruptible_timeout() will set the state of the current
task to TASK_INTERRUPTIBLE, before doing the condition check. This
means that we will try to acquire the mutex while already in a
sleeping state. The scheduler warns us by giving the following
warning:

[ 4050.264464] ------------[ cut here ]------------
[ 4050.264508] do not call blocking ops when !TASK_RUNNING; state=1 set at [&lt;00000000b33c00e2&gt;] prepare_to_wait_event+0x14a/0x188
[ 4050.264529] WARNING: CPU: 12 PID: 35924 at kernel/sched/core.c:6112 __might_sleep+0x76/0x90
....

 4050.264756] Call Trace:
[ 4050.264765] ([&lt;000000000017bbaa&gt;] __might_sleep+0x72/0x90)
[ 4050.264774]  [&lt;0000000000b97edc&gt;] __mutex_lock+0x44/0x8c0
[ 4050.264782]  [&lt;0000000000b9878a&gt;] mutex_lock_nested+0x32/0x40
[ 4050.264793]  [&lt;000003ff800d7abe&gt;] vfio_group_get_device+0x36/0xa8 [vfio]
[ 4050.264803]  [&lt;000003ff800d87c0&gt;] vfio_del_group_dev+0x238/0x378 [vfio]
[ 4050.264813]  [&lt;000003ff8015f67c&gt;] mdev_remove+0x3c/0x68 [mdev]
[ 4050.264825]  [&lt;00000000008e01b0&gt;] device_release_driver_internal+0x168/0x268
[ 4050.264834]  [&lt;00000000008de692&gt;] bus_remove_device+0x162/0x190
[ 4050.264843]  [&lt;00000000008daf42&gt;] device_del+0x1e2/0x368
[ 4050.264851]  [&lt;00000000008db12c&gt;] device_unregister+0x64/0x88
[ 4050.264862]  [&lt;000003ff8015ed84&gt;] mdev_device_remove+0xec/0x130 [mdev]
[ 4050.264872]  [&lt;000003ff8015f074&gt;] remove_store+0x6c/0xa8 [mdev]
[ 4050.264881]  [&lt;000000000046f494&gt;] kernfs_fop_write+0x14c/0x1f8
[ 4050.264890]  [&lt;00000000003c1530&gt;] __vfs_write+0x38/0x1a8
[ 4050.264899]  [&lt;00000000003c187c&gt;] vfs_write+0xb4/0x198
[ 4050.264908]  [&lt;00000000003c1af2&gt;] ksys_write+0x5a/0xb0
[ 4050.264916]  [&lt;0000000000b9e270&gt;] system_call+0xdc/0x2d8
[ 4050.264925] 4 locks held by sh/35924:
[ 4050.264933]  #0: 000000001ef90325 (sb_writers#4){.+.+}, at: vfs_write+0x9e/0x198
[ 4050.264948]  #1: 000000005c1ab0b3 (&amp;of-&gt;mutex){+.+.}, at: kernfs_fop_write+0x1cc/0x1f8
[ 4050.264963]  #2: 0000000034831ab8 (kn-&gt;count#297){++++}, at: kernfs_remove_self+0x12e/0x150
[ 4050.264979]  #3: 00000000e152484f (&amp;dev-&gt;mutex){....}, at: device_release_driver_internal+0x5c/0x268
[ 4050.264993] Last Breaking-Event-Address:
[ 4050.265002]  [&lt;000000000017bbaa&gt;] __might_sleep+0x72/0x90
[ 4050.265010] irq event stamp: 7039
[ 4050.265020] hardirqs last  enabled at (7047): [&lt;00000000001cee7a&gt;] console_unlock+0x6d2/0x740
[ 4050.265029] hardirqs last disabled at (7054): [&lt;00000000001ce87e&gt;] console_unlock+0xd6/0x740
[ 4050.265040] softirqs last  enabled at (6416): [&lt;0000000000b8fe26&gt;] __udelay+0xb6/0x100
[ 4050.265049] softirqs last disabled at (6415): [&lt;0000000000b8fe06&gt;] __udelay+0x96/0x100
[ 4050.265057] ---[ end trace d04a07d39d99a9f9 ]---

Let's fix this as described in the article
https://lwn.net/Articles/628628/.

Signed-off-by: Farhan Ali &lt;alifm@linux.ibm.com&gt;
[remove now redundant vfio_dev_present()]
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
</entry>
<entry>
<title>vfio: expand minor range when registering chrdev region</title>
<updated>2019-02-12T20:20:56Z</updated>
<author>
<name>Chengguang Xu</name>
</author>
<published>2019-02-12T05:59:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=8bcb64a51065e957e170ada58cbbd766be6a9619'/>
<id>urn:sha1:8bcb64a51065e957e170ada58cbbd766be6a9619</id>
<content type='text'>
Actually, total amount of available minor number
for a single major is MINORMARK + 1. So expand
minor range when registering chrdev region.

Signed-off-by: Chengguang Xu &lt;cgxu519@gmx.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>vfio: use match_string() helper</title>
<updated>2018-06-08T16:24:33Z</updated>
<author>
<name>Yisheng Xie</name>
</author>
<published>2018-05-21T11:57:45Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e77addf018f0c8d947ddc0bef2cd6d4791da7dde'/>
<id>urn:sha1:e77addf018f0c8d947ddc0bef2cd6d4791da7dde</id>
<content type='text'>
match_string() returns the index of an array for a matching string,
which can be used intead of open coded variant.

Cc: Alex Williamson &lt;alex.williamson@redhat.com&gt;
Cc: kvm@vger.kernel.org
Signed-off-by: Yisheng Xie &lt;xieyisheng1@huawei.com&gt;
Reviewed-by: Andy Shevchenko &lt;andy.shevchenko@gmail.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>vfio: Simplify capability helper</title>
<updated>2017-12-20T16:53:54Z</updated>
<author>
<name>Alex Williamson</name>
</author>
<published>2017-12-12T19:59:39Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=dda01f787df9f9e46f1c0bf8aa11f246e300750d'/>
<id>urn:sha1:dda01f787df9f9e46f1c0bf8aa11f246e300750d</id>
<content type='text'>
The vfio_info_add_capability() helper requires the caller to pass a
capability ID, which it then uses to fill in header fields, assuming
hard coded versions.  This makes for an awkward and rigid interface.
The only thing we want this helper to do is allocate sufficient
space in the caps buffer and chain this capability into the list.
Reduce it to that simple task.

Reviewed-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Acked-by: Zhenyu Wang &lt;zhenyuw@linux.intel.com&gt;
Reviewed-by: Kirti Wankhede &lt;kwankhede@nvidia.com&gt;
Reviewed-by: Peter Xu &lt;peterx@redhat.com&gt;
Reviewed-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()</title>
<updated>2017-10-25T09:01:08Z</updated>
<author>
<name>Mark Rutland</name>
</author>
<published>2017-10-23T21:07:29Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6aa7de059173a986114ac43b8f50b297a86f09a8'/>
<id>urn:sha1:6aa7de059173a986114ac43b8f50b297a86f09a8</id>
<content type='text'>
Please do not apply this to mainline directly, instead please re-run the
coccinelle script shown below and apply its output.

For several reasons, it is desirable to use {READ,WRITE}_ONCE() in
preference to ACCESS_ONCE(), and new code is expected to use one of the
former. So far, there's been no reason to change most existing uses of
ACCESS_ONCE(), as these aren't harmful, and changing them results in
churn.

However, for some features, the read/write distinction is critical to
correct operation. To distinguish these cases, separate read/write
accessors must be used. This patch migrates (most) remaining
ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following
coccinelle script:

----
// Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and
// WRITE_ONCE()

// $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch

virtual patch

@ depends on patch @
expression E1, E2;
@@

- ACCESS_ONCE(E1) = E2
+ WRITE_ONCE(E1, E2)

@ depends on patch @
expression E;
@@

- ACCESS_ONCE(E)
+ READ_ONCE(E)
----

Signed-off-by: Mark Rutland &lt;mark.rutland@arm.com&gt;
Signed-off-by: Paul E. McKenney &lt;paulmck@linux.vnet.ibm.com&gt;
Cc: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: davem@davemloft.net
Cc: linux-arch@vger.kernel.org
Cc: mpe@ellerman.id.au
Cc: shuah@kernel.org
Cc: snitzer@redhat.com
Cc: thor.thayer@linux.intel.com
Cc: tj@kernel.org
Cc: viro@zeniv.linux.org.uk
Cc: will.deacon@arm.com
Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com
Signed-off-by: Ingo Molnar &lt;mingo@kernel.org&gt;
</content>
</entry>
<entry>
<title>vfio: Stall vfio_del_group_dev() for container group detach</title>
<updated>2017-08-30T20:02:16Z</updated>
<author>
<name>Alex Williamson</name>
</author>
<published>2017-08-18T04:10:20Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6586b561a91cd80a91c8f107ed0d144feb3eadc2'/>
<id>urn:sha1:6586b561a91cd80a91c8f107ed0d144feb3eadc2</id>
<content type='text'>
When the user unbinds the last device of a group from a vfio bus
driver, the devices within that group should be available for other
purposes.  We currently have a race that makes this generally, but
not always true.  The device can be unbound from the vfio bus driver,
but remaining IOMMU context of the group attached to the container
can result in errors as the next driver configures DMA for the device.

Wait for the group to be detached from the IOMMU backend before
allowing the bus driver remove callback to complete.

Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>vfio: fix noiommu vfio_iommu_group_get reference count</title>
<updated>2017-08-30T20:00:47Z</updated>
<author>
<name>Eric Auger</name>
</author>
<published>2017-08-11T13:16:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d935ad91f07d20268fca97b1ddc56a816ac71826'/>
<id>urn:sha1:d935ad91f07d20268fca97b1ddc56a816ac71826</id>
<content type='text'>
In vfio_iommu_group_get() we want to increase the reference
count of the iommu group.

In noiommu case, the group does not exist and is allocated.
iommu_group_add_device() increases the group ref count. However we
then call iommu_group_put() which decrements it.

This leads to a "refcount_t: underflow WARN_ON".

Only decrement the ref count in case of iommu_group_add_device
failure.

Signed-off-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
</content>
</entry>
<entry>
<title>vfio: Remove unnecessary uses of vfio_container.group_lock</title>
<updated>2017-07-07T21:37:38Z</updated>
<author>
<name>Alex Williamson</name>
</author>
<published>2017-07-07T21:37:38Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7f56c30bd0a232822aca38d288da475613bdff9b'/>
<id>urn:sha1:7f56c30bd0a232822aca38d288da475613bdff9b</id>
<content type='text'>
The original intent of vfio_container.group_lock is to protect
vfio_container.group_list, however over time it's become a crutch to
prevent changes in container composition any time we call into the
iommu driver backend.  This introduces problems when we start to have
more complex interactions, for example when a user's DMA unmap request
triggers a notification to an mdev vendor driver, who responds by
attempting to unpin mappings within that request, re-entering the
iommu backend.  We incorrectly assume that the use of read-locks here
allow for this nested locking behavior, but a poorly timed write-lock
could in fact trigger a deadlock.

The current use of group_lock seems to fall into the trap of locking
code, not data.  Correct that by removing uses of group_lock that are
not directly related to group_list.  Note that the vfio type1 iommu
backend has its own mutex, vfio_iommu.lock, which it uses to protect
itself for each of these interfaces anyway.  The group_lock appears to
be a redundancy for these interfaces and type1 even goes so far as to
release its mutex to allow for exactly the re-entrant code path above.

Reported-by: Chuanxiao Dong &lt;chuanxiao.dong@intel.com&gt;
Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
Acked-by: Alexey Kardashevskiy &lt;aik@ozlabs.ru&gt;
Cc: stable@vger.kernel.org # v4.10+
</content>
</entry>
<entry>
<title>vfio: New external user group/file match</title>
<updated>2017-06-28T19:50:05Z</updated>
<author>
<name>Alex Williamson</name>
</author>
<published>2017-06-28T19:50:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=5d6dee80a1e94cc284d03e06d930e60e8d3ecf7d'/>
<id>urn:sha1:5d6dee80a1e94cc284d03e06d930e60e8d3ecf7d</id>
<content type='text'>
At the point where the kvm-vfio pseudo device wants to release its
vfio group reference, we can't always acquire a new reference to make
that happen.  The group can be in a state where we wouldn't allow a
new reference to be added.  This new helper function allows a caller
to match a file to a group to facilitate this.  Given a file and
group, report if they match.  Thus the caller needs to already have a
group reference to match to the file.  This allows the deletion of a
group without acquiring a new reference.

Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
Reviewed-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Reviewed-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
Tested-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Cc: stable@vger.kernel.org
</content>
</entry>
<entry>
<title>vfio: Fix group release deadlock</title>
<updated>2017-06-28T19:49:38Z</updated>
<author>
<name>Alex Williamson</name>
</author>
<published>2017-06-19T15:10:32Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=811642d8d8a82c0cce8dc2debfdaf23c5a144839'/>
<id>urn:sha1:811642d8d8a82c0cce8dc2debfdaf23c5a144839</id>
<content type='text'>
If vfio_iommu_group_notifier() acquires a group reference and that
reference becomes the last reference to the group, then vfio_group_put
introduces a deadlock code path where we're trying to unregister from
the iommu notifier chain from within a callout of that chain.  Use a
work_struct to release this reference asynchronously.

Signed-off-by: Alex Williamson &lt;alex.williamson@redhat.com&gt;
Reviewed-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Tested-by: Eric Auger &lt;eric.auger@redhat.com&gt;
Cc: stable@vger.kernel.org
</content>
</entry>
</feed>
