# How do I compile my kernel for AMD IOMMU PCI passthrough?

## RAKK

I have an AMD A4-5300 CPU with a motherboard that supports IOMMU and I am trying to enable IOMMU on my Gentoo Hardened 4.3.3-r4 kernel with the intention of using a graphics card on a KVM VM. I've already asked this question in this other forum thread and got an answer, but I just tried to do that and it didn't work.

According to the reply I got, I have to enable the following options on my Linux kernel and recompile it:

Device Drivers >> IOMMU Hardware Support

AMD IOMMU support

Support for Intel IOMMU using DMA Remapping Devices

Support for Interrupt Remapping

Bus options (PCI etc.) >> PCI Stub

So I did, and yet my kernel still won't pick up my IOMMU. When it works I'm supposed to get a message saying AMD-Vi was enabled if I issue the following command, but I just get nothing:

```
dmesg | grep AMD-Vi
```

I've already managed to get my IOMMU working on Debian Stretch on this same computer, so the point of failure is most definitely in my Gentoo system. Documentation on using IOMMU on Gentoo is very scarce though, all I can find online is for Linux distributions that Just Work Out of the Box™ like Ubuntu, Fedora or Debian. What can I do to enable my IOMMU on Gentoo?

----------

## i4dnf

Try just:

```
iommu=pt
```

in your kernel parameters

----------

## theotherjoe

```
localhost # dmesg | grep AMD-Vi

[    0.676298] AMD-Vi: Found IOMMU at 0000:00:00.2 cap 0x40

[    0.676379] AMD-Vi: Interrupt remapping enabled

[    0.676518] AMD-Vi: Lazy IO/TLB flushing enabled

localhost # 

```

```
localhost # grep IOMMU /usr/src/linux/.config

# CONFIG_GART_IOMMU is not set

# CONFIG_CALGARY_IOMMU is not set

CONFIG_IOMMU_HELPER=y

CONFIG_IOMMU_API=y

CONFIG_IOMMU_SUPPORT=y

# Generic IOMMU Pagetable Support

CONFIG_AMD_IOMMU=y

# CONFIG_AMD_IOMMU_STATS is not set

CONFIG_AMD_IOMMU_V2=y

# CONFIG_INTEL_IOMMU is not set

# CONFIG_IOMMU_STRESS is not set

```

----------

## RAKK

 *i4dnf wrote:*   

> Try just:
> 
> ```
> iommu=pt
> ```
> ...

 

Just tried this one, only amd_iommu=on and both at the same time. It didn't work.

----------

## RAKK

 *theotherjoe wrote:*   

> 
> 
> ```
> localhost # grep IOMMU /usr/src/linux/.config
> 
> ...

 

Just tried disabling GART_IOMMU and CALGARY_IOMMU. Kernel is rebuilding at the moment.

----------

## RAKK

Aaaaaaand no luck with GART_IOMMU and CALGARY_IOMMU disabled   :Sad: 

What else do I have to enable?

Edit: from this official kernel guide I'm trying booting with iommu=force:

```
    force              Force the use of the hardware IOMMU even when it is

                       not actually needed (e.g. because < 3 GB memory).
```

Edit 2: still no luck, my IOMMU is still not enabling.

----------

## theotherjoe

RAKK,

I don't have a series A  apu available to compare. the config snippet 

was from a system with a FX cpu.

Maybe the complete config and dmesg output can help you analyse your problem.

complete config: https://bpaste.net/show/e15d49194150

dmesg output: https://bpaste.net/show/6df62f665000

Since you mentioned that you have IOMMU available under Debian on

the same system I assume that IOMMU controller option or something

similar in your bios is turned on.

----------

## RAKK

 *theotherjoe wrote:*   

> RAKK,
> 
> I don't have a series A  apu available to compare. the config snippet 
> 
> was from a system with a FX cpu.
> ...

 

I just saw you have NUMA disabled. Turns out I enabled NUMA some months ago to deal with a memory problem I had on my kernel. I'm currently rebuilding mine with CONFIG_NUMA disabled. The issue I had can be found here: http://unix.stackexchange.com/questions/265629/gentoo-hardened-eats-3-gb-of-memory-after-running-for-12-hours-with-very-few-pr

If it works... that's going to be a problem, because that memory problem might appear again.

----------

## RAKK

And once again, IOMMU still won't work with NUMA disabled. This one is good news though.

Well... I'm running out of ideas...

Edit: Rehosting the previous paste files since they seem to have an expiration date.

Kernel config: http://pastebin.com/SncJT24v

dmesg: http://pastebin.com/c80b3Nev

----------

## RAKK

And after much wailing, complaining and head bashing, I finally figured out what was going on.

Turns out... that IOMMU was working all along, it's just that the kernel logs weren't showing it.

But the IOMMU driver was there, and I serendipiously found out when I mistakenly typed this:

```
rockshooter ~ # ps -ef | grep -i iommu

root        66     2  0 04:19 ?        00:00:00 [amd_iommu_v2]
```

When I saw that kernel thread running I thought, maybe my IOMMU is actually working? And lo and behold, I performed the same configuration steps I did previously for Debian, and one hour later I was on my virtual machine hooked up to my graphics card playing some games.

Please save this thread for future reference, because it took me some good 3 weeks to figure this out.

----------

