From: Alejandro Jimenez <alejandro.j.jimenez@oracle.com>
To: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Peter Maydell" <peter.maydell@linaro.org>,
qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
Marcel Apfelbaum <marcel.apfelbaum@gmail.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: Re: [PATCH] hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb()
Date: Thu, 20 Feb 2025 10:55:09 -0500 [thread overview]
Message-ID: <75de7f2d-2cc6-4f89-87e5-b1676a3b00f8@oracle.com> (raw)
In-Reply-To: <5a220564-313a-44e9-8ae9-a2faec14ebb5@linaro.org>
+ Suravee
On 2/17/25 02:26, Philippe Mathieu-Daudé wrote:
> On 31/7/24 19:00, Peter Maydell wrote:
>> In amdvi_update_iotlb() we will only put a new entry in the hash
>> table if to_cache.perm is not IOMMU_NONE. However we allocate the
>> memory for the new AMDVIIOTLBEntry and for the hash table key
>> regardless. This means that in the IOMMU_NONE case we will leak the
>> memory we alloacted.
>>
>> Move the allocations into the if() to the point where we know we're
>> going to add the item to the hash table.
>>
>> Cc: qemu-stable@nongnu.org
>> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2452
>> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
>> ---
>> Tested with 'make check' and 'make check-avocado' only, but the
>> bug and fix seem straightforward...
>
> Oh now I remembered:
> https://lore.kernel.org/qemu-devel/CACGkMEtjmpX8G9HYZ0r3n5ErhAENKhQ81f4ocfCYrh=XoF=5hw@mail.gmail.com/
Re: AMD vIOMMU status, this recent series:
https://lore.kernel.org/all/20240927172913.121477-1-santosh.shukla@amd.com/
added support for using it with VFIO and the guest in passthrough mode.
I'm currently working on adding support for DMA remapping, and have a basic prototype that boots a guest with a VFIO assigned device and iommu.passthrough=0, which exercises the change in this patch.
I am using the fixes and optimizations that have gone into the VTD emulation code as a template to bring the AMDVi DMA remap up to a functional state. I'll send an RFC soon once I have fixed a remaining issue with the prototype.
Thank you,
Alejandro
>
>> ---
>> hw/i386/amd_iommu.c | 8 ++++----
>> 1 file changed, 4 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
>> index 6d4fde72f9b..87643d28917 100644
>> --- a/hw/i386/amd_iommu.c
>> +++ b/hw/i386/amd_iommu.c
>> @@ -357,12 +357,12 @@ static void amdvi_update_iotlb(AMDVIState *s, uint16_t devid,
>> uint64_t gpa, IOMMUTLBEntry to_cache,
>> uint16_t domid)
>> {
>> - AMDVIIOTLBEntry *entry = g_new(AMDVIIOTLBEntry, 1);
>> - uint64_t *key = g_new(uint64_t, 1);
>> - uint64_t gfn = gpa >> AMDVI_PAGE_SHIFT_4K;
>> -
>> /* don't cache erroneous translations */
>> if (to_cache.perm != IOMMU_NONE) {
>> + AMDVIIOTLBEntry *entry = g_new(AMDVIIOTLBEntry, 1);
>> + uint64_t *key = g_new(uint64_t, 1);
>> + uint64_t gfn = gpa >> AMDVI_PAGE_SHIFT_4K;
>> +
>> trace_amdvi_cache_update(domid, PCI_BUS_NUM(devid), PCI_SLOT(devid),
>> PCI_FUNC(devid), gpa, to_cache.translated_addr);
>
>
prev parent reply other threads:[~2025-02-20 15:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-31 17:00 [PATCH] hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb() Peter Maydell
2024-07-31 21:07 ` Philippe Mathieu-Daudé
2025-02-17 7:26 ` Philippe Mathieu-Daudé
2025-02-20 15:55 ` Alejandro Jimenez [this message]
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=75de7f2d-2cc6-4f89-87e5-b1676a3b00f8@oracle.com \
--to=alejandro.j.jimenez@oracle.com \
--cc=marcel.apfelbaum@gmail.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=suravee.suthikulpanit@amd.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;
as well as URLs for NNTP newsgroup(s).