Re: [PATCH 0/7] hw/i386/amd_iommu: Cleanups and fixes

2025-07-18 Thread Alejandro Jimenez
On 7/18/25 9:28 AM, Vasant Hegde wrote: Alejandro, Sairaj, On 7/17/2025 7:18 PM, Alejandro Jimenez wrote: On 7/17/25 2:07 AM, Michael S. Tsirkin wrote: On Thu, Jul 17, 2025 at 11:17:05AM +0530, Sairaj Kodilkar wrote: On 7/16/2025 6:59 PM, Michael S. Tsirkin wrote: On Wed, Jul 16

Re: [PATCH 0/7] hw/i386/amd_iommu: Cleanups and fixes

2025-07-17 Thread Alejandro Jimenez
On 7/17/25 2:07 AM, Michael S. Tsirkin wrote: On Thu, Jul 17, 2025 at 11:17:05AM +0530, Sairaj Kodilkar wrote: On 7/16/2025 6:59 PM, Michael S. Tsirkin wrote: On Wed, Jul 16, 2025 at 06:26:37PM +0530, Sairaj Kodilkar wrote: On 7/16/2025 6:07 PM, Philippe Mathieu-Daudé wrote: On 16/7/25

Re: [PATCH v2 16/20] amd_iommu: Set all address spaces to default translation mode on reset

2025-06-23 Thread Alejandro Jimenez
On 6/13/25 4:46 AM, Sairaj Kodilkar wrote: On 5/31/2025 3:00 AM, Alejandro Jimenez wrote: Hey Sairaj, On 5/29/25 2:16 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:46 AM, Alejandro Jimenez wrote: On reset, restore the default address translation mode for all the address spaces managed by

[PATCH v4 6/8] amd_iommu: Fix the calculation for Device Table size

2025-06-17 Thread Alejandro Jimenez
Correctly calculate the Device Table size using the format encoded in the Device Table Base Address Register (MMIO Offset h). Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/a

[PATCH v4 1/8] amd_iommu: Fix Miscellaneous Information Register 0 encoding

2025-06-17 Thread Alejandro Jimenez
...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Co-developed-by: Ethan MILON Signed-off-by: Ethan MILON Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iom

[PATCH v4 2/8] amd_iommu: Fix Device ID decoding for INVALIDATE_IOTLB_PAGES command

2025-06-17 Thread Alejandro Jimenez
The DeviceID bits are extracted using an incorrect offset in the call to amdvi_iotlb_remove_page(). This field is read (correctly) earlier, so use the value already retrieved for devid. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by:

[PATCH v4 0/8] amd_iommu: Fixes to align with AMDVi specification

2025-06-17 Thread Alejandro Jimenez
han fixing truncation bug. Thank you, Alejandro v3: https://lore.kernel.org/all/20250529193023.3590780-1-alejandro.j.jime...@oracle.com/ Alejandro Jimenez (7): amd_iommu: Fix Miscellaneous Information Register 0 encoding amd_iommu: Fix Device ID decoding for INVALIDATE_IOTLB_PAGES command amd_iom

[PATCH v4 3/8] amd_iommu: Update bitmasks representing DTE reserved fields

2025-06-17 Thread Alejandro Jimenez
not yet implemented. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.c | 7 --- hw/i386/amd_iommu.h | 9 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH v4 8/8] amd_iommu: Fix truncation of oldval in amdvi_writeq

2025-06-17 Thread Alejandro Jimenez
From: Ethan Milon The variable `oldval` was incorrectly declared as a 32-bit `uint32_t`. This could lead to truncation and incorrect behavior where the upper read-only 32 bits are significant. Fix the type of `oldval` to match the return type of `ldq_le_p()`. Cc: qemu-sta...@nongnu.org Fixes: d

[PATCH v4 4/8] amd_iommu: Fix masks for various IOMMU MMIO Registers

2025-06-17 Thread Alejandro Jimenez
definitions independent. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 38 +++--- 1 file changed, 19 insertions(+), 19 deletions(-) diff

[PATCH v4 5/8] amd_iommu: Fix mask to retrieve Interrupt Table Root Pointer from DTE

2025-06-17 Thread Alejandro Jimenez
Table Root Pointer[51:6] field in the Device Table Entry format. Cc: qemu-sta...@nongnu.org Fixes: b44159fe0078 ("x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 2 +- 1 file

[PATCH v4 7/8] amd_iommu: Remove duplicated definitions

2025-06-17 Thread Alejandro Jimenez
No functional change. Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 4 1 file changed, 4 deletions(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 96fc5b621e609..8b42913ed8dab 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386

Re: [PATCH v3 0/7] amd_iommu: Fixes to align with AMDVi specification

2025-06-16 Thread Alejandro Jimenez
Hi Phil, On 6/16/25 2:59 AM, Philippe Mathieu-Daudé wrote: Hi Alejandro, On 12/6/25 22:59, Alejandro Jimenez wrote: Hi Ethan, On 6/12/25 4:36 AM, Ethan MILON wrote: Hi, Is this series the right place to include the following minor fix? I would defer this change for two reasons: 1) This

Re: [PATCH v2 11/20] amd_iommu: Use iova_tree records to determine large page size on UNMAP

2025-06-13 Thread Alejandro Jimenez
On 6/11/25 4:29 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:45 AM, Alejandro Jimenez wrote:   next: -    iova = iova_next; +    iova = (iova & ~(pagesize - 1)) + pagesize; Hi Alejandro, While experimenting with iommu.forcedac=1, I found that above line causes unsigned int

Re: [PATCH v2 06/20] amd_iommu: Return an error when unable to read PTE from guest memory

2025-06-13 Thread Alejandro Jimenez
On 6/12/25 6:37 AM, Vasant Hegde wrote: Alejandro, On 5/2/2025 7:45 AM, Alejandro Jimenez wrote: Make amdvi_get_pte_entry() return an error value (-1) in cases where the memory read fails, versus the current return of 0 to indicate failure. The reason is that 0 is also a valid PTE value

Re: [PATCH v2 01/20] memory: Adjust event ranges to fit within notifier boundaries

2025-06-12 Thread Alejandro Jimenez
On 6/12/25 2:54 AM, Vasant Hegde wrote: Alejandro, On 5/2/2025 7:45 AM, Alejandro Jimenez wrote: Invalidating the entire address space (i.e. range of [0, ~0ULL]) is a valid and required operation by vIOMMU implementations. However, such invalidations currently trigger an assertion unless

Re: [PATCH 18/18] hw/i386/x86-iommu: Remove X86IOMMUState::pt_supported field

2025-06-12 Thread Alejandro Jimenez
On 6/6/25 9:42 AM, Igor Mammedov wrote: On Thu, 1 May 2025 23:04:56 +0200 Philippe Mathieu-Daudé wrote: @@ -1486,15 +1485,8 @@ static AddressSpace *amdvi_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) AMDVI_INT_ADDR_FIRST,

Re: [PATCH v3 0/7] amd_iommu: Fixes to align with AMDVi specification

2025-06-12 Thread Alejandro Jimenez
o this series. Alejandro Thanks, Ethan On 5/29/25 9:30 PM, Alejandro Jimenez wrote: Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe. The main reason for sending this new revision so soon is that

Re: [PATCH v2 16/20] amd_iommu: Set all address spaces to default translation mode on reset

2025-05-30 Thread Alejandro Jimenez
Hey Sairaj, On 5/29/25 2:16 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:46 AM, Alejandro Jimenez wrote: On reset, restore the default address translation mode for all the address spaces managed by the vIOMMU. Signed-off-by: Alejandro Jimenez ---   hw/i386/amd_iommu.c | 28

Re: [PATCH v2 00/20] AMD vIOMMU: DMA remapping support for VFIO devices

2025-05-30 Thread Alejandro Jimenez
On 5/30/25 7:41 AM, Michael S. Tsirkin wrote: On Fri, May 02, 2025 at 02:15:45AM +, Alejandro Jimenez wrote: This series adds support for guests using the AMD vIOMMU to enable DMA remapping for VFIO devices. In addition to the currently supported passthrough (PT) mode, guest kernels are

[PATCH v3 2/7] amd_iommu: Fix Device ID decoding for INVALIDATE_IOTLB_PAGES command

2025-05-29 Thread Alejandro Jimenez
The DeviceID bits are extracted using an incorrect offset in the call to amdvi_iotlb_remove_page(). This field is read (correctly) earlier, so use the value already retrieved for devid. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by:

[PATCH v3 6/7] amd_iommu: Fix the calculation for Device Table size

2025-05-29 Thread Alejandro Jimenez
Correctly calculate the Device Table size using the format encoded in the Device Table Base Address Register (MMIO Offset h). Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/a

[PATCH v3 3/7] amd_iommu: Update bitmasks representing DTE reserved fields

2025-05-29 Thread Alejandro Jimenez
not yet implemented. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.c | 7 --- hw/i386/amd_iommu.h | 9 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH v3 1/7] amd_iommu: Fix Miscellaneous Information Register 0 offsets

2025-05-29 Thread Alejandro Jimenez
The definitions encoding the maximum Virtual, Physical, and Guest Virtual Address sizes supported by the IOMMU are using incorrect offsets i.e. the VASize and GVASize offsets are switched. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by:

[PATCH v3 7/7] amd_iommu: Remove duplicated definitions

2025-05-29 Thread Alejandro Jimenez
No functional change. Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 4 1 file changed, 4 deletions(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 1836b7061d848..31e473924fa20 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386

[PATCH v3 0/7] amd_iommu: Fixes to align with AMDVi specification

2025-05-29 Thread Alejandro Jimenez
/). - Added 'Fixes:' tag to [PATCH 5/7]. - Added Vasant's R-b to patches 4,5,7. Thank you, Alejandro v2: https://lore.kernel.org/qemu-devel/20250528221725.3554040-1-alejandro.j.jime...@oracle.com/ v1: https://lore.kernel.org/all/20250311152446.45086-1-alejandro.j.jime...@oracle.c

[PATCH v3 4/7] amd_iommu: Fix masks for various IOMMU MMIO Registers

2025-05-29 Thread Alejandro Jimenez
definitions independent. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 38 +++--- 1 file changed, 19 insertions(+), 19 deletions(-) diff

[PATCH v3 5/7] amd_iommu: Fix mask to retrieve Interrupt Table Root Pointer from DTE

2025-05-29 Thread Alejandro Jimenez
Table Root Pointer[51:6] field in the Device Table Entry format. Cc: qemu-sta...@nongnu.org Fixes: b44159fe0078 ("x86_iommu/amd: Add interrupt remap support when VAPIC is not enabled") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.h | 2 +- 1 file

Re: [PATCH v2 0/7] amd_iommu: Fixes to align with AMDVi specification

2025-05-29 Thread Alejandro Jimenez
On 5/29/25 1:26 AM, Vasant Hegde wrote: Hi, On 5/29/2025 3:47 AM, Alejandro Jimenez wrote: Correct mistakes in bitmasks, offsets, decoding of fields, and behavior that do not match the latest AMD I/O Virtualization Technology (IOMMU) Specification. These bugs do not trigger problems today

Re: [PATCH v2 4/7] amd_iommu: Fix masks for various IOMMU MMIO Registers

2025-05-29 Thread Alejandro Jimenez
On 5/29/25 1:23 AM, Vasant Hegde wrote: On 5/29/2025 3:47 AM, Alejandro Jimenez wrote: Address various issues with definitions of the MMIO registers e.g. for the Device Table Address Register, the size mask currently encompasses reserved bits [11:9], so change it to only extract the bits

[PATCH v2 2/7] amd_iommu: Fix Device ID decoding for INVALIDATE_IOTLB_PAGES command

2025-05-28 Thread Alejandro Jimenez
The DeviceID bits are extracted using an incorrect offset in the call to amdvi_iotlb_remove_page(). This field is read (correctly) earlier, so use the value already retrieved for devid. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by:

[PATCH v2 3/7] amd_iommu: Update bitmasks representing DTE reserved fields

2025-05-28 Thread Alejandro Jimenez
not yet implemented. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/amd_iommu.c | 7 --- hw/i386/amd_iommu.h | 9 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH v2 0/7] amd_iommu: Fixes to align with AMDVi specification

2025-05-28 Thread Alejandro Jimenez
acle.com/ [1] https://lore.kernel.org/all/20250311152446.45086-1-alejandro.j.jime...@oracle.com/ Alejandro Jimenez (7): amd_iommu: Fix Miscellanous Information Register 0 offsets amd_iommu: Fix Device ID decoding for INVALIDATE_IOTLB_PAGES command amd_iommu: Update bitmasks representing DTE reserved fie

[PATCH v2 7/7] amd_iommu: Remove duplicated definitions

2025-05-28 Thread Alejandro Jimenez
No functional change. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.h | 4 1 file changed, 4 deletions(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 1836b7061d848..31e473924fa20 100644 --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -206,10 +206,6

[PATCH v2 4/7] amd_iommu: Fix masks for various IOMMU MMIO Registers

2025-05-28 Thread Alejandro Jimenez
definitions independent. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.h | 38 +++--- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/hw/i386/amd_iommu.h

[PATCH v2 6/7] amd_iommu: Fix the calculation for Device Table size

2025-05-28 Thread Alejandro Jimenez
Correctly calculate the Device Table size using the format encoded in the Device Table Base Address Register (MMIO Offset h). Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez Reviewed-by: Vasant Hegde --- hw/i386/a

[PATCH v2 1/7] amd_iommu: Fix Miscellanous Information Register 0 offsets

2025-05-28 Thread Alejandro Jimenez
The definitions encoding the maximum Virtual, Physical, and Guest Virtual Address sizes supported by the IOMMU are using incorrect offsets i.e. the VASize and GVASize offsets are switched. Cc: qemu-sta...@nongnu.org Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by:

[PATCH v2 5/7] amd_iommu: Fix mask to retrieve Interrupt Table Root Pointer from DTE

2025-05-28 Thread Alejandro Jimenez
Table Root Pointer[51:6] field in the Device Table Entry format. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 09352672bdcc2..1836b7061d848 100644

[PATCH v2 5/7] amd_iommu: Fix mask to retrive Interrupt Table Root Pointer from DTE

2025-05-28 Thread Alejandro Jimenez
Table Root Pointer[51:6] field in the Device Table Entry format. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/i386/amd_iommu.h b/hw/i386/amd_iommu.h index 09352672bdcc2..1836b7061d848 100644

Re: [PATCH v2 05/20] amd_iommu: Add helper function to extract the DTE

2025-05-21 Thread Alejandro Jimenez
Hi Ethan, On 5/20/25 6:18 AM, Ethan MILON wrote: Hi, On 5/2/25 4:15 AM, Alejandro Jimenez wrote: Extracting the DTE from a given AMDVIAddressSpace pointer structure is a common operation required for syncing the shadow page tables. Implement a helper to do it and check for common error

Re: [PATCH v2 00/20] AMD vIOMMU: DMA remapping support for VFIO devices

2025-05-20 Thread Alejandro Jimenez
Hi Sairaj On 5/16/25 4:07 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:45 AM, Alejandro Jimenez wrote: Hi Alejandro, Tested the v2, everything looks good when I boot guest with upstream kernel. But I observed that NVME driver fails to load with guest kernel version 4.15.0-213-generic. This is

Re: [PATCH v2 19/20] amd_iommu: Do not assume passthrough translation when DTE[TV]=0

2025-05-14 Thread Alejandro Jimenez
On 5/12/25 3:00 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:46 AM, Alejandro Jimenez wrote: -    if (pte & AMDVI_DEV_TRANSLATION_VALID) { -    level = get_pte_translation_mode(pte); -    if (level >= 7) { -    trace_amdvi_mode_invalid(level, addr); +    if

Re: [PATCH v2 05/20] amd_iommu: Add helper function to extract the DTE

2025-05-14 Thread Alejandro Jimenez
On 5/12/25 2:45 AM, Sairaj Kodilkar wrote: On 5/2/2025 7:45 AM, Alejandro Jimenez wrote: @@ -1035,13 +1070,13 @@ static void amdvi_do_translate(AMDVIAddressSpace *as, hwaddr addr,   return;   } -    if (!amdvi_get_dte(s, devid, entry)) { -    return; -    } +    dte_ret

[PATCH v2 09/20] amd_iommu: Add basic structure to support IOMMU notifier updates

2025-05-01 Thread Alejandro Jimenez
that enable the synchronization of guest I/O page tables with host IOMMU state, at which point an amd-iommu device property will be introduced to control this capability. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 26 +++--- hw/i386/amd_iommu.h | 3 +++ 2 files

[PATCH v2 20/20] amd_iommu: Refactor amdvi_page_walk() to use common code for page walk

2025-05-01 Thread Alejandro Jimenez
Simplify amdvi_page_walk() by making it call the fetch_pte() helper that is already in use by the shadow page synchronization code. Ensures all code uses the same page table walking algorithm. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 59

[PATCH v2 12/20] amd_iommu: Unmap all address spaces under the AMD IOMMU on reset

2025-05-01 Thread Alejandro Jimenez
Support dropping all existing mappings on reset. When the guest kernel reboots it will create new ones, but other components that run before the kernel (e.g. OVMF) should not be able to use existing mappings from the previous boot. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 74

[PATCH v2 00/20] AMD vIOMMU: DMA remapping support for VFIO devices

2025-05-01 Thread Alejandro Jimenez
nt testing by Sairaj (thank you!) Thank you, Alejandro [0] https://lore.kernel.org/all/20250414020253.443831-1-alejandro.j.jime...@oracle.com/ Alejandro Jimenez (20): memory: Adjust event ranges to fit within notifier boundaries amd_iommu: Document '-device amd-iommu' common options

[PATCH v2 02/20] amd_iommu: Document '-device amd-iommu' common options

2025-05-01 Thread Alejandro Jimenez
g list threads. Signed-off-by: Alejandro Jimenez --- qemu-options.hx | 23 +++ 1 file changed, 23 insertions(+) diff --git a/qemu-options.hx b/qemu-options.hx index dc694a99a30a..198acab48e8e 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1226,6 +1226,29 @@ SRST `

[PATCH v2 15/20] amd_iommu: Toggle memory regions based on address translation mode

2025-05-01 Thread Alejandro Jimenez
whether the specific address space is using address translation (via the newly introduced addr_translation field). Later, region activation will also be controlled by availability of DMA remapping capability (via dma-remap property to be introduced in follow up changes). Signed-off-by: Alejandro Jimenez

[PATCH v2 13/20] amd_iommu: Add replay callback

2025-05-01 Thread Alejandro Jimenez
les on the host. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 24 1 file changed, 24 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 7bcba47a01ba..5ce74f2c052d 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -879

[PATCH v2 17/20] amd_iommu: Add dma-remap property to AMD vIOMMU device

2025-05-01 Thread Alejandro Jimenez
configured with the NpCache capability, so a guest driver issues IOMMU invalidations for both map() and unmap() operations. This capability is already set by default and written to the configuration in amdvi_pci_realize() as part of AMDVI_CAPAB_FEATURES. Signed-off-by: Alejandro Jimenez --- hw

[PATCH v2 19/20] amd_iommu: Do not assume passthrough translation when DTE[TV]=0

2025-05-01 Thread Alejandro Jimenez
encountered. Do not assume that addresses for a device with DTE[TV]=0 are passed through (i.e. not remapped) and instead terminate the page table walk early. Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez --- hw/i386/amd_io

[PATCH v2 11/20] amd_iommu: Use iova_tree records to determine large page size on UNMAP

2025-05-01 Thread Alejandro Jimenez
and used to issue the UNMAP notification. Using the correct size is essential since the VFIO IOMMU Type1v2 driver in the host kernel will reject unmap requests that do not fully cover previous mappings. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 91

[PATCH v2 01/20] memory: Adjust event ranges to fit within notifier boundaries

2025-05-01 Thread Alejandro Jimenez
u/amd: Remove redundant domain flush from attach_device()"). Remove the assertion altogether and adjust the range to ensure it does not cross notifier boundaries. Signed-off-by: Alejandro Jimenez --- system/memory.c | 10 +++--- 1 file changed, 3 insertions(+), 7 deletions(-) diff --gi

[PATCH v2 06/20] amd_iommu: Return an error when unable to read PTE from guest memory

2025-05-01 Thread Alejandro Jimenez
. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 5322a614f5d6..698967cc1a88 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -496,7 +496,7 @@ static inline

[PATCH v2 16/20] amd_iommu: Set all address spaces to default translation mode on reset

2025-05-01 Thread Alejandro Jimenez
On reset, restore the default address translation mode for all the address spaces managed by the vIOMMU. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 28 1 file changed, 28 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH v2 10/20] amd_iommu: Sync shadow page tables on page invalidation

2025-05-01 Thread Alejandro Jimenez
. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 82 - 1 file changed, 74 insertions(+), 8 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 2f69459ab68d..bddfe2f93136 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386

[PATCH v2 05/20] amd_iommu: Add helper function to extract the DTE

2025-05-01 Thread Alejandro Jimenez
Extracting the DTE from a given AMDVIAddressSpace pointer structure is a common operation required for syncing the shadow page tables. Implement a helper to do it and check for common error conditions. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 45

[PATCH v2 14/20] amd_iommu: Invalidate address translations on INVALIDATE_IOMMU_ALL

2025-05-01 Thread Alejandro Jimenez
and UNMAP events. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 48 + 1 file changed, 48 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 5ce74f2c052d..fa5dbc3cc700 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386

[PATCH v2 07/20] amd_iommu: Add helpers to walk AMD v1 Page Table format

2025-05-01 Thread Alejandro Jimenez
The current amdvi_page_walk() is designed to be called by the replay() method. Rather than drastically altering it, introduce helpers to fetch guest PTEs that will be used by a page walker implementation. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 123

[PATCH v2 04/20] amd_iommu: Helper to decode size of page invalidation command

2025-05-01 Thread Alejandro Jimenez
The size of the region to invalidate depends on the S bit and address encoded in the command. Add a helper to extract this information, which will be used to sync shadow page tables in upcoming changes. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 34

[PATCH v2 18/20] amd_iommu: Toggle address translation mode on devtab entry invalidation

2025-05-01 Thread Alejandro Jimenez
address translation for the address space if needed. Requires dma-remap=on. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 78 +++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH v2 08/20] amd_iommu: Add a page walker to sync shadow page tables on invalidation

2025-05-01 Thread Alejandro Jimenez
For the specified address range, walk the page table identifying regions as mapped or unmapped and invoke registered notifiers with the corresponding event type. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 75 + 1 file changed, 75

[PATCH v2 03/20] amd_iommu: Reorder device and page table helpers

2025-05-01 Thread Alejandro Jimenez
only, no functional change intended. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 170 ++-- 1 file changed, 85 insertions(+), 85 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 2cf7e24a21d8..9e500121f6e8 100644 --- a

Re: [PATCH 14/18] amd_iommu: Toggle address translation on device table entry invalidation

2025-04-29 Thread Alejandro Jimenez
On 4/22/25 8:48 AM, Sairaj Kodilkar wrote: On 4/14/2025 7:32 AM, Alejandro Jimenez wrote: +    if ((ret < 0) || (!ret && !dte_mode)) { +    /* + * The DTE could not be retrieved, it is not valid, or it is not setup + * for paging. In either case, ens

Re: [PATCH 11/18] amd_iommu: Sync shadow page tables on page invalidation

2025-04-29 Thread Alejandro Jimenez
On 4/22/25 8:38 AM, Sairaj Kodilkar wrote: On 4/14/2025 7:32 AM, Alejandro Jimenez wrote: When the guest issues an INVALIDATE_IOMMU_PAGES command, decode the address and size of the invalidation and sync the guest page table state with the host. This requires walking the guest page table

Re: [PATCH 08/18] amd_iommu: Helper to decode size of page invalidation command

2025-04-28 Thread Alejandro Jimenez
On 4/22/25 8:26 AM, Sairaj Kodilkar wrote: On 4/14/2025 7:32 AM, Alejandro Jimenez wrote: The size of the region to invalidate depends on the S bit and address encoded in the command. Add a helper to extract this information, which will be used to sync shadow page tables in upcoming

Re: [PATCH 05/18] amd_iommu: Toggle memory regions based on address translation mode

2025-04-28 Thread Alejandro Jimenez
On 4/22/25 8:17 AM, Sairaj Kodilkar wrote: On 4/14/2025 7:32 AM, Alejandro Jimenez wrote: Enable the appropriate memory region for an address space depending on the address translation mode selected for it. This is currently based on a generic x86 IOMMMU property, and only done during the

Re: [PATCH 03/18] amd_iommu: Add support for IOMMU notifier

2025-04-17 Thread Alejandro Jimenez
On 4/17/25 6:19 AM, Sairaj Kodilkar wrote: On 4/17/2025 3:47 AM, Alejandro Jimenez wrote: On 4/16/25 8:14 AM, Sairaj Kodilkar wrote: + +    /* DMA address translation */ +    bool dma_remap; I think you should use this flag in the remapping path as well. I am aware that you are

Re: [PATCH 10/18] amd_iommu: Add a page walker to sync shadow page tables on invalidation

2025-04-17 Thread Alejandro Jimenez
On 4/17/25 11:14 AM, Ethan MILON wrote: Hi, On 4/13/25 10:02 PM, Alejandro Jimenez wrote: For the specified address range, walk the page table identifying regions as mapped or unmapped and invoke registered notifiers with the corresponding event type. Signed-off-by: Alejandro Jimenez

Re: [PATCH 09/18] amd_iommu: Add helpers to walk AMD v1 Page Table format

2025-04-17 Thread Alejandro Jimenez
On 4/17/25 8:40 AM, CLEMENT MATHIEU--DRIF wrote: On 14/04/2025 4:02 am, Alejandro Jimenez wrote: Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe. The current amdvi_page_walk() is designed to be

Re: [PATCH 02/18] amd_iommu: Add helper function to extract the DTE

2025-04-16 Thread Alejandro Jimenez
On 4/16/25 2:50 PM, Michael S. Tsirkin wrote: On Wed, Apr 16, 2025 at 09:29:23AM -0400, Alejandro Jimenez wrote: On 4/16/25 7:36 AM, Sairaj Kodilkar wrote: +static int amdvi_as_to_dte(AMDVIAddressSpace *as, uint64_t *dte); + No need to have this function declaration as it is a

Re: [PATCH 03/18] amd_iommu: Add support for IOMMU notifier

2025-04-16 Thread Alejandro Jimenez
On 4/16/25 8:14 AM, Sairaj Kodilkar wrote: + +    /* DMA address translation support */ +    IOMMUNotifierFlag notifier_flags; +    /* entry in list of Address spaces with registered notifiers */ +    QLIST_ENTRY(AMDVIAddressSpace) next; +    /* DMA address translation active */ +    bool add

Re: [PATCH 02/18] amd_iommu: Add helper function to extract the DTE

2025-04-16 Thread Alejandro Jimenez
On 4/16/25 7:36 AM, Sairaj Kodilkar wrote: On 4/14/2025 7:32 AM, Alejandro Jimenez wrote: Hi Alejandro, Extracting the DTE from a given AMDVIAddressSpace pointer structure is a common operation required for syncing the shadow page tables. Implement a helper to do it and check for common

Re: [PATCH 1/2] hw/i386/amd_iommu: Fix device setup failure when PT is on.

2025-04-15 Thread Alejandro Jimenez
On 4/15/25 2:38 AM, Sairaj Kodilkar wrote: Hi Alejandro, On 4/15/2025 1:56 AM, Alejandro Jimenez wrote: Hi Sairaj, I'm conflicted by the implementation of the change, so I'd like to make sure I fully understand... On 4/10/25 2:44 AM, Sairaj Kodilkar wrote: Fix th

Re: [PATCH 1/2] hw/i386/amd_iommu: Fix device setup failure when PT is on.

2025-04-14 Thread Alejandro Jimenez
Hi Sairaj, I'm conflicted by the implementation of the change, so I'd like to make sure I fully understand... On 4/10/25 2:44 AM, Sairaj Kodilkar wrote: Current amd_iommu enables the iommu_nodma address space when pt_supported flag is on. As it should, that is the intended purpose of the i

[PATCH 04/18] amd_iommu: Unmap all address spaces under the AMD IOMMU on reset

2025-04-13 Thread Alejandro Jimenez
Support dropping all existing mappings on reset. When the guest kernel reboots it will create new ones, but other components that run before the kernel (e.g. OVMF) should not be able to use existing mappings from the previous boot. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 68

[PATCH 17/18] amd_iommu: Refactor amdvi_page_walk() to use common code for page walk

2025-04-13 Thread Alejandro Jimenez
Simplify amdvi_page_walk() by making it call the fetch_pte() helper that is already in use by the shadow page synchronization code. Ensures all code uses the same page table walking algorithm. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 60

[PATCH 16/18] amd_iommu: Do not assume passthrough translation when DTE[TV]=0

2025-04-13 Thread Alejandro Jimenez
encountered. Do not assume that addresses for a device with DTE[TV]=0 are passed through (i.e. not remapped) and instead terminate the page table walk early. Fixes: d29a09ca6842 ("hw/i386: Introduce AMD IOMMU") Signed-off-by: Alejandro Jimenez --- hw/i386/amd_io

[PATCH 08/18] amd_iommu: Helper to decode size of page invalidation command

2025-04-13 Thread Alejandro Jimenez
The size of the region to invalidate depends on the S bit and address encoded in the command. Add a helper to extract this information, which will be used to sync shadow page tables in upcoming changes. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 34

[PATCH 15/18] amd_iommu: Use iova_tree records to determine large page size on UNMAP

2025-04-13 Thread Alejandro Jimenez
and used to issue the UNMAP notification. Using the correct size is essential since the VFIO IOMMU Type1v2 driver in the host kernel will reject unmap requests that do not fully cover previous mappings. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 98

[PATCH 14/18] amd_iommu: Toggle address translation on device table entry invalidation

2025-04-13 Thread Alejandro Jimenez
address translation for the address space if needed. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 68 - 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 3bfa08419ffe..abdd67f6b12c

[PATCH 06/18] amd_iommu: Set all address spaces to default translation mode on reset

2025-04-13 Thread Alejandro Jimenez
On reset, restore the default address translation mode for all the address spaces managed by the vIOMMU. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 28 1 file changed, 28 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index

[PATCH 09/18] amd_iommu: Add helpers to walk AMD v1 Page Table format

2025-04-13 Thread Alejandro Jimenez
The current amdvi_page_walk() is designed to be called by the replay() method. Rather than drastically altering it, introduce helpers to fetch guest PTEs that will be used by a page walker implementation. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 125

[PATCH 11/18] amd_iommu: Sync shadow page tables on page invalidation

2025-04-13 Thread Alejandro Jimenez
. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 110 1 file changed, 102 insertions(+), 8 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 6789e1e9b688..cf83ac607064 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386

[PATCH 10/18] amd_iommu: Add a page walker to sync shadow page tables on invalidation

2025-04-13 Thread Alejandro Jimenez
For the specified address range, walk the page table identifying regions as mapped or unmapped and invoke registered notifiers with the corresponding event type. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 74 + 1 file changed, 74

[PATCH 12/18] amd_iommu: Add replay callback

2025-04-13 Thread Alejandro Jimenez
les on the host. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 23 +++ 1 file changed, 23 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index cf83ac607064..e24eab34c9e0 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -1902,

[PATCH 05/18] amd_iommu: Toggle memory regions based on address translation mode

2025-04-13 Thread Alejandro Jimenez
whether DMA remapping is available as a global capability, and if the specific address space is using address translation. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 30 -- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/hw/i386/amd_iommu.c b

[PATCH 02/18] amd_iommu: Add helper function to extract the DTE

2025-04-13 Thread Alejandro Jimenez
Extracting the DTE from a given AMDVIAddressSpace pointer structure is a common operation required for syncing the shadow page tables. Implement a helper to do it and check for common error conditions. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 47

[PATCH 03/18] amd_iommu: Add support for IOMMU notifier

2025-04-13 Thread Alejandro Jimenez
: Alejandro Jimenez --- hw/i386/amd_iommu.c | 34 -- hw/i386/amd_iommu.h | 6 ++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 22d648c2e0e3..8dbb10d91339 100644 --- a/hw/i386/amd_iommu.c +++ b/hw

[PATCH 07/18] amd_iommu: Return an error when unable to read PTE from guest memory

2025-04-13 Thread Alejandro Jimenez
. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 0df658712ec0..5f55be1f4d36 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386/amd_iommu.c @@ -958,7 +958,7 @@ static inline

[PATCH 00/18] AMD vIOMMU: DMA remapping support for VFIO devices

2025-04-13 Thread Alejandro Jimenez
evice vfio-pci,host=0000:a1:00.1,id=net0 --- Alejandro Jimenez (18): memory: Adjust event ranges to fit within notifier boundaries amd_iommu: Add helper function to extract the DTE amd_iommu: Add support for IOMMU notifier amd_iommu: Unmap all address spaces under the AMD IOMMU on reset a

[PATCH 18/18] amd_iommu: Do not emit I/O page fault events during replay()

2025-04-13 Thread Alejandro Jimenez
regions where a mapping doesn't currently exist, which is not correct. Note that after this change there are no users of amdvi_page_fault(), but since the IO page fault handling will be addressed in upcoming work, I am choosing to mark it as unused rather than deleting it. Signed-off-by: Alej

[PATCH 13/18] amd_iommu: Invalidate address translations on INVALIDATE_IOMMU_ALL

2025-04-13 Thread Alejandro Jimenez
and UNMAP events. Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 49 + 1 file changed, 49 insertions(+) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index e24eab34c9e0..3bfa08419ffe 100644 --- a/hw/i386/amd_iommu.c +++ b/hw/i386

[PATCH 01/18] memory: Adjust event ranges to fit within notifier boundaries

2025-04-13 Thread Alejandro Jimenez
u/amd: Remove redundant domain flush from attach_device()"). Remove the assertion altogether and adjust the range to ensure it does not cross notifier boundaries. Signed-off-by: Alejandro Jimenez --- system/memory.c | 10 +++--- 1 file changed, 3 insertions(+), 7 deletions(-) diff --gi

Re: [PATCH 2/2] hw/i386/amd_iommu: Fix xtsup when vcpus < 255

2025-04-10 Thread Alejandro Jimenez
en as it fails to call kvm_enable_x2apic(). Fix this by adding back kvm_enable_x2apic() call when xtsup=on. Fixes: 8c6619f3e692 ("hw/i386/amd_iommu: Simplify non-KVM checks on XTSup feature") Reported-by: Alejandro Jimenez Cc: Philippe Mathieu-Daudé Cc: Joao Martins Signed-off-by: V

Re: [PATCH 6/6] amd_iommu: Do not assume passthrough translation for devices with DTE[TV]=0

2025-04-05 Thread Alejandro Jimenez
Hi Sairaj Kodilkar, On 3/20/25 1:11 AM, Arun Kodilkar, Sairaj wrote: On 3/11/2025 8:54 PM, Alejandro Jimenez wrote: The AMD I/O Virtualization Technology (IOMMU) Specification (see Table 8: V, TV, and GV Fields in Device Table Entry), specifies that a DTE with V=0, TV=1 does not contain a

Re: [PATCH 6/6] amd_iommu: Do not assume passthrough translation for devices with DTE[TV]=0

2025-03-19 Thread Alejandro Jimenez
On 3/19/25 2:06 AM, Vasant Hegde wrote: Alejandro, On 3/11/2025 8:54 PM, Alejandro Jimenez wrote: The AMD I/O Virtualization Technology (IOMMU) Specification (see Table 8: V, TV, and GV Fields in Device Table Entry), specifies that a DTE with V=0, TV=1 does not contain a valid address

Re: [PATCH 3/6] amd_iommu: Update bitmasks representing DTE reserved fields

2025-03-13 Thread Alejandro Jimenez
On 3/12/25 12:12 AM, Arun Kodilkar, Sairaj wrote: Hi Alejandro, On 3/11/2025 8:54 PM, Alejandro Jimenez wrote: [...] --- a/hw/i386/amd_iommu.h +++ b/hw/i386/amd_iommu.h @@ -25,6 +25,8 @@   #include "hw/i386/x86-iommu.h"   #include "qom/object.h" +#define GENMASK64(h,

[PATCH 3/6] amd_iommu: Update bitmasks representing DTE reserved fields

2025-03-11 Thread Alejandro Jimenez
not yet implemented. Cc: qemu-sta...@nongnu.org Signed-off-by: Alejandro Jimenez --- hw/i386/amd_iommu.c | 7 --- hw/i386/amd_iommu.h | 9 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c index 068eeb0cae..8b97abe28c 100644

  1   2   >