51 lines
2.0 KiB
Diff
51 lines
2.0 KiB
Diff
|
|
From 1b0d08faf1daaed39809ed1a3516eaa0f7d61534 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Peter Maydell <peter.maydell@linaro.org>
|
||
|
|
Date: Wed, 31 Jul 2024 18:00:19 +0100
|
||
|
|
Subject: [PATCH] hw/i386/amd_iommu: Don't leak memory in amdvi_update_iotlb()
|
||
|
|
|
||
|
|
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>
|
||
|
|
Message-Id: <20240731170019.3590563-1-peter.maydell@linaro.org>
|
||
|
|
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
|
||
|
|
(cherry picked from commit 9a45b0761628cc59267b3283a85d15294464ac31)
|
||
|
|
Signed-off-by: zhujun2 <zhujun2_yewu@cmss.chinamobile.com>
|
||
|
|
---
|
||
|
|
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 4203144da9..12742b1433 100644
|
||
|
|
--- a/hw/i386/amd_iommu.c
|
||
|
|
+++ b/hw/i386/amd_iommu.c
|
||
|
|
@@ -346,12 +346,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);
|
||
|
|
|
||
|
|
--
|
||
|
|
2.41.0.windows.1
|
||
|
|
|