public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: Alex Williamson <alex.williamson@redhat.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Qian Cai <cai@lca.pw>,
	kvm@vger.kernel.org
Subject: Re: [PATCH AUTOSEL 5.7 280/388] vfio/pci: fix memory leaks of eventfd ctx
Date: Thu, 18 Jun 2020 10:29:43 -0400	[thread overview]
Message-ID: <20200618142943.GS1931@sasha-vm> (raw)
In-Reply-To: <20200617192501.2310afe6@x1.home>

On Wed, Jun 17, 2020 at 07:25:01PM -0600, Alex Williamson wrote:
>On Wed, 17 Jun 2020 21:06:17 -0400
>Sasha Levin <sashal@kernel.org> wrote:
>
>> From: Qian Cai <cai@lca.pw>
>>
>> [ Upstream commit 1518ac272e789cae8c555d69951b032a275b7602 ]
>>
>> Finished a qemu-kvm (-device vfio-pci,host=0001:01:00.0) triggers a few
>> memory leaks after a while because vfio_pci_set_ctx_trigger_single()
>> calls eventfd_ctx_fdget() without the matching eventfd_ctx_put() later.
>> Fix it by calling eventfd_ctx_put() for those memory in
>> vfio_pci_release() before vfio_device_release().
>>
>> unreferenced object 0xebff008981cc2b00 (size 128):
>>   comm "qemu-kvm", pid 4043, jiffies 4294994816 (age 9796.310s)
>>   hex dump (first 32 bytes):
>>     01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de  ....kkkk.....N..
>>     ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff  ....kkkk........
>>   backtrace:
>>     [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c
>>     [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4
>>     [<000000005fcec025>] do_eventfd+0x54/0x1ac
>>     [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44
>>     [<00000000b819758c>] do_el0_svc+0x128/0x1dc
>>     [<00000000b244e810>] el0_sync_handler+0xd0/0x268
>>     [<00000000d495ef94>] el0_sync+0x164/0x180
>> unreferenced object 0x29ff008981cc4180 (size 128):
>>   comm "qemu-kvm", pid 4043, jiffies 4294994818 (age 9796.290s)
>>   hex dump (first 32 bytes):
>>     01 00 00 00 6b 6b 6b 6b 00 00 00 00 ad 4e ad de  ....kkkk.....N..
>>     ff ff ff ff 6b 6b 6b 6b ff ff ff ff ff ff ff ff  ....kkkk........
>>   backtrace:
>>     [<00000000917e8f8d>] slab_post_alloc_hook+0x74/0x9c
>>     [<00000000df0f2aa2>] kmem_cache_alloc_trace+0x2b4/0x3d4
>>     [<000000005fcec025>] do_eventfd+0x54/0x1ac
>>     [<0000000082791a69>] __arm64_sys_eventfd2+0x34/0x44
>>     [<00000000b819758c>] do_el0_svc+0x128/0x1dc
>>     [<00000000b244e810>] el0_sync_handler+0xd0/0x268
>>     [<00000000d495ef94>] el0_sync+0x164/0x180
>>
>> Signed-off-by: Qian Cai <cai@lca.pw>
>> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>> Signed-off-by: Sasha Levin <sashal@kernel.org>
>> ---
>>  drivers/vfio/pci/vfio_pci.c | 4 ++++
>>  1 file changed, 4 insertions(+)
>>
>> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
>> index 6c6b37b5c04e..080e6608f297 100644
>> --- a/drivers/vfio/pci/vfio_pci.c
>> +++ b/drivers/vfio/pci/vfio_pci.c
>> @@ -519,6 +519,10 @@ static void vfio_pci_release(void *device_data)
>>  		vfio_pci_vf_token_user_add(vdev, -1);
>>  		vfio_spapr_pci_eeh_release(vdev->pdev);
>>  		vfio_pci_disable(vdev);
>> +		if (vdev->err_trigger)
>> +			eventfd_ctx_put(vdev->err_trigger);
>> +		if (vdev->req_trigger)
>> +			eventfd_ctx_put(vdev->req_trigger);
>>  	}
>>
>>  	mutex_unlock(&vdev->reflck->lock);
>
>
>This has a fix pending, I'd suggest not picking it on its own:
>
>https://lore.kernel.org/kvm/20200616085052.sahrunsesjyjeyf2@beryllium.lan/
>https://lore.kernel.org/kvm/159234276956.31057.6902954364435481688.stgit@gimli.home/

Thanks! I'll hold off on this until the fix is in too.

-- 
Thanks,
Sasha

  reply	other threads:[~2020-06-18 14:29 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20200618010805.600873-1-sashal@kernel.org>
2020-06-18  1:02 ` [PATCH AUTOSEL 5.7 060/388] vfio/pci: fix memory leaks in alloc_perm_bits() Sasha Levin
2020-06-18  1:02 ` [PATCH AUTOSEL 5.7 077/388] scsi: vhost: Notify TCM about the maximum sg entries supported per command Sasha Levin
2020-06-18  1:05 ` [PATCH AUTOSEL 5.7 228/388] vfio-pci: Mask cap zero Sasha Levin
2020-06-18  1:06 ` [PATCH AUTOSEL 5.7 280/388] vfio/pci: fix memory leaks of eventfd ctx Sasha Levin
2020-06-18  1:25   ` Alex Williamson
2020-06-18 14:29     ` Sasha Levin [this message]
2020-06-18  1:06 ` [PATCH AUTOSEL 5.7 308/388] vfio/mdev: Fix reference count leak in add_mdev_supported_type Sasha Levin
2020-06-18  1:07 ` [PATCH AUTOSEL 5.7 342/388] KVM: selftests: Fix build with "make ARCH=x86_64" Sasha Levin

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=20200618142943.GS1931@sasha-vm \
    --to=sashal@kernel.org \
    --cc=alex.williamson@redhat.com \
    --cc=cai@lca.pw \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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