public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Brett Creeley <brett.creeley@amd.com>
To: <jgg@ziepe.ca>, <yishaih@nvidia.com>,
	<shameerali.kolothum.thodi@huawei.com>, <kevin.tian@intel.com>,
	<alex.williamson@redhat.com>, <dan.carpenter@linaro.org>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<brett.creeley@amd.com>, <shannon.nelson@amd.com>
Subject: [PATCH vfio 1/3] pds/vfio: Fix spinlock bad magic BUG
Date: Thu, 14 Sep 2023 12:15:38 -0700	[thread overview]
Message-ID: <20230914191540.54946-2-brett.creeley@amd.com> (raw)
In-Reply-To: <20230914191540.54946-1-brett.creeley@amd.com>

The following BUG was found when running on a kernel with
CONFIG_DEBUG_SPINLOCK=y set:

[  675.116953] BUG: spinlock bad magic on CPU#2, bash/2481
[  675.116966]  lock: 0xffff8d6052a88f50, .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0
[  675.116978] CPU: 2 PID: 2481 Comm: bash Tainted: G S                 6.6.0-rc1-next-20230911 #1
[  675.116986] Hardware name: HPE ProLiant DL360 Gen10/ProLiant DL360 Gen10, BIOS U32 01/23/2021
[  675.116991] Call Trace:
[  675.116997]  <TASK>
[  675.117002]  dump_stack_lvl+0x36/0x50
[  675.117014]  do_raw_spin_lock+0x79/0xc0
[  675.117032]  pds_vfio_reset+0x1d/0x60 [pds_vfio_pci]
[  675.117049]  pci_reset_function+0x4b/0x70
[  675.117061]  reset_store+0x5b/0xa0
[  675.117074]  kernfs_fop_write_iter+0x137/0x1d0
[  675.117087]  vfs_write+0x2de/0x410
[  675.117101]  ksys_write+0x5d/0xd0
[  675.117111]  do_syscall_64+0x3b/0x90
[  675.117122]  entry_SYSCALL_64_after_hwframe+0x6e/0xd8
[  675.117135] RIP: 0033:0x7f9ebbd1fa28
[  675.117141] Code: 89 02 48 c7 c0 ff ff ff ff eb b3 0f 1f 80 00 00 00 00 f3 0f 1e fa 48 8d 05 15 4d 2a 00 8b 00 85 c0 75 17 b8 01 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 58 c3 0f 1f 80 00 00 00 00 41 54 49 89 d4 55
[  675.117148] RSP: 002b:00007ffdff410728 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[  675.117156] RAX: ffffffffffffffda RBX: 0000000000000002 RCX: 00007f9ebbd1fa28
[  675.117161] RDX: 0000000000000002 RSI: 000055ffc5fdf7c0 RDI: 0000000000000001
[  675.117166] RBP: 000055ffc5fdf7c0 R08: 000000000000000a R09: 00007f9ebbd7fae0
[  675.117170] R10: 000000000000000a R11: 0000000000000246 R12: 00007f9ebbfc06e0
[  675.117174] R13: 0000000000000002 R14: 00007f9ebbfbb860 R15: 0000000000000002
[  675.117180]  </TASK>

As shown, the .magic: 00000000, does not match the expected value. This
is because spin_lock_init() is never called for the reset_lock. Fix
this by calling spin_lock_init(&pds_vfio->reset_lock) when initializing
the device.

Signed-off-by: Brett Creeley <brett.creeley@amd.com>
Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>
---
 drivers/vfio/pci/pds/vfio_dev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/vfio/pci/pds/vfio_dev.c b/drivers/vfio/pci/pds/vfio_dev.c
index b46174f5eb09..147a543a7c39 100644
--- a/drivers/vfio/pci/pds/vfio_dev.c
+++ b/drivers/vfio/pci/pds/vfio_dev.c
@@ -155,6 +155,8 @@ static int pds_vfio_init_device(struct vfio_device *vdev)
 
 	pds_vfio->vf_id = vf_id;
 
+	spin_lock_init(&pds_vfio->reset_lock);
+
 	vdev->migration_flags = VFIO_MIGRATION_STOP_COPY | VFIO_MIGRATION_P2P;
 	vdev->mig_ops = &pds_vfio_lm_ops;
 	vdev->log_ops = &pds_vfio_log_ops;
-- 
2.17.1


  reply	other threads:[~2023-09-14 19:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-14 19:15 [PATCH vfio 0/3] pds/vfio: Fixes for locking bugs Brett Creeley
2023-09-14 19:15 ` Brett Creeley [this message]
2023-09-14 19:15 ` [PATCH vfio 2/3] pds/vfio: Fix mutex lock->magic != lock warning Brett Creeley
2023-09-14 19:15 ` [PATCH vfio 3/3] pds/vfio: Fix possible sleep while in atomic context Brett Creeley
2023-09-14 22:38   ` Alex Williamson
2023-09-15 15:54     ` Brett Creeley
2023-09-19 18:59     ` Jason Gunthorpe
2023-09-21 14:49       ` Brett Creeley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230914191540.54946-2-brett.creeley@amd.com \
    --to=brett.creeley@amd.com \
    --cc=alex.williamson@redhat.com \
    --cc=dan.carpenter@linaro.org \
    --cc=jgg@ziepe.ca \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shameerali.kolothum.thodi@huawei.com \
    --cc=shannon.nelson@amd.com \
    --cc=yishaih@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox