Giter Club home page Giter Club logo

fedora-acs-override's Introduction

Fedora 40 + PCI passthrough

Note

OpenSSF Scorecard (more about this metric and what it means at securityscorecards.dev) - track progress on anything surfaced by it here

Prerequisites

  • Fedora 40 (fresh install off the live USB image)
  • Computer with
    • Two graphics cards
    • Motherboard with the Intel 200 series chipset (Union Point) or newer
  • A fresh backup of anything you don't care to lose

๐Ÿ†• Just want the RPMs? Go to the latest workflow run and download the RPMs as a build artifact, as shown below:

download-rpms

Tip

The two graphics cards can be different models. If your cards are identical, you'll need to do some extra steps that are prefaced with (ACS only). These steps include compiling your own kernel to include Alex Williamson's patch to allow any PCIe device to use Access Control Services. More information on this patch, why it's necessary, and what it does available here. If your cards aren't identical, skip these steps.

Setup and configuration of the host machine

  1. Add RPM Fusion

    sudo dnf install https://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm https://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-$(rpm -E %fedora).noarch.rpm
  2. (ACS only) - Install the dependencies to start building your own kernel.

    sudo dnf install fedpkg fedora-packager rpmdevtools ncurses-devel pesign bpftool
  3. (ACS only) - Set up your home build directory (if you haven't ever built any RPMs before)

    rpmdev-setuptree
  4. (ACS only) - Install the kernel source and finish installing dependencies.

    koji download-build --arch=src kernel-6.2.15-300.fc40.src.rpm
    rpm -Uvh kernel-6.2.15-300.fc40.src.rpm
    cd rpmbuild/SPECS/
    sudo dnf builddep kernel.spec
  5. (ACS only) - Add the ACS patch (link) as ~/rpmbuild/SOURCES/add-acs-override.patch.

    curl -o ~/rpmbuild/SOURCES/add-acs-override.patch https://raw.githubusercontent.com/some-natalie/fedora-acs-override/main/acs/add-acs-override.patch    
  6. (ACS only) - Edit ~/rpmbuild/SPECS/kernel.spec to set the build ID and add the patch. Since each release of the spec file could change, it's not much help giving line numbers, but both of these should be near the top of the file. To set the build id, add the two lines near the top of the spec file with the other release information.

    # Set buildid
    %define buildid .acs

    To add the patch, add the two lines below to the spec file in the section for patches (usually right below the sources).

    # ACS override patch
    Patch1000: add-acs-override.patch

    Then tell it to apply the patch in the prep section. It will be below the ApplyOptionalPatch() function definition, normally right above the # END OF PATCH APPLICATIONS comment.

    ApplyOptionalPatch add-acs-override.patch
  7. (ACS only) - Compile! This takes a long time.

    rpmbuild -bb kernel.spec
  8. (ACS only) - Install the new packages!

    cd ~/rpmbuild/RPMS/x86_64
    sudo dnf localinstall *.rpm

    โ„น๏ธ You should now have at least the following packages installed: kernel, kernel-core, kernel-devel, kernel-modules, and kernel-modules-extra.

  9. Update and reboot

    sudo dnf clean all
    sudo dnf update -y
    sudo reboot
  10. Install virtualization software and add yourself to the user group

    sudo dnf install @virtualization
    sudo usermod -G libvirt -a $(whoami)
    sudo usermod -G kvm -a $(whoami)
  11. Install (proprietary) nVidia drivers and remove/blacklist (open source) nouveau drivers.

    sudo su -
    dnf install xorg-x11-drv-nvidia akmod-nvidia "kernel-devel-uname-r == $(uname -r)" xorg-x11-drv-nvidia-cuda vulkan vdpauinfo libva-vdpau-driver libva-utils
    dnf remove *nouveau*
    echo "blacklist nouveau" >> /etc/modprobe.d/blacklist.conf
  12. Reboot again!

    sudo reboot
  13. Verify that the nVidia drivers are installed correctly.

    lsmod | grep nouveau   # This should display nothing
    lsmod | grep nvidia    # This should display at least a couple things
  14. Edit /etc/default/grub to enable IOMMU, blacklist nouveau, and load vfio-pci first.

    If your video cards are different:

    GRUB_CMDLINE_LINUX="rd.driver.pre=vfio-pci rd.driver.blacklist=nouveau modprobe.blacklist=nouveau rd.lvm.lv=fedora/root rd.lvm.lv=fedora/swap rhgb quiet intel_iommu=on iommu=pt"

    If your video cards are identical, use this instead:

    GRUB_CMDLINE_LINUX="rd.driver.pre=vfio-pci rd.driver.blacklist=nouveau modprobe.blacklist=nouveau nvidia-drm.modeset=1 resume=/dev/mapper/arch-swap rd.lvm.lv=arch/root rd.lvm.lv=arch/swap rhgb quiet intel_iommu=on iommu=pt pcie_acs_override=downstream"
  15. Rebuild GRUB's configuration

    sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
  16. Edit /etc/modprobe.d/kvm.conf. These two lines are edited out due to stability concerns. YMMV.

    #options kvm_intel nested=1
    #options kvm_amd nested=1
  17. Create or edit /etc/modprobe.d/local.conf, adding the line below:

    install vfio-pci /sbin/vfio-pci-override.sh
  18. Create or edit /etc/dracut.conf.d/local.conf, adding the line below:

    add_drivers+= " vfio vfio_iommu_type1 vfio_pci vfio_virqfd "
    install_items+=" /sbin/vfio-pci-override.sh /usr/bin/find /usr/bin/dirname "
  19. Create a file /sbin/vfio-pci-override.sh with permissions 755 (file in this directory of the repo).

  20. Rebuild using dracut

    sudo dracut -f --kver `uname -r`
  21. Reboot again!

  22. Verify that your target hardware is using vfio-pci as the driver. Omit the -s 00:02:00 on another machine to get the entire output, as this argument narrows the output down to the device specified.

    nataliepc /h/n/k/kernel $ lspci -vv -n -s 00:02:00
    02:00.0 0300: 10de:1c82 (rev a1) (prog-if 00 [VGA controller])
      Subsystem: 3842:6251
      Control: I/O- Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
      Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
      Interrupt: pin A routed to IRQ 10
      Region 0: Memory at dc000000 (32-bit, non-prefetchable) [disabled] [size=16M]
      Region 1: Memory at a0000000 (64-bit, prefetchable) [disabled] [size=256M]
      Region 3: Memory at b0000000 (64-bit, prefetchable) [disabled] [size=32M]
      Region 5: I/O ports at d000 [disabled] [size=128]
      Expansion ROM at dd000000 [disabled] [size=512K]
      Capabilities: <access denied>
      Kernel driver in use: vfio-pci
      Kernel modules: nouveau, nvidia_drm, nvidia
    
    02:00.1 0403: 10de:0fb9 (rev a1)
      Subsystem: 3842:6251
      Control: I/O- Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx-
      Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
      Interrupt: pin B routed to IRQ 11
      Region 0: Memory at dd080000 (32-bit, non-prefetchable) [disabled] [size=16K]
      Capabilities: <access denied>
      Kernel driver in use: vfio-pci
      Kernel modules: snd_hda_intel
  23. Proceed to set up your virtual machine.

Resources

  • Alex Williamson's blog on the VFIO tips and tricks - link
  • Arch Linux wiki post on PCI passthrough - link

Disclaimer

I put this together based on my own machine at home because I knew I'd forget this process if I ever had to do it again. There was a lot of reading of Bugzilla, StackOverflow, and a bunch of blogs/forums/mailing lists all over the internet. Thanks to everyone who did something similar so I could cobble together something from all of them that Works On My Machine. This is by no means the only way to solve the problem. ๐Ÿ˜ƒ

fedora-acs-override's People

Contributors

dependabot[bot] avatar evanjarrett avatar evernow avatar parndt avatar some-natalie avatar stefanleh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

fedora-acs-override's Issues

"To add the patch, add the two lines below to the spec file in the section for patches (usually right below the sources)."

Where?

I'm getting,

# don't apply patch if it's empty
ApplyOptionalPatch()                                                                                                    {                                                                                                                         local patch=$1                                                                                                          shift
  if [ ! -f $RPM_SOURCE_DIR/$patch ]; then                                                                                  exit 1                                                                                                                fi
  local C=$(wc -l $RPM_SOURCE_DIR/$patch | awk '{print $1}')
  if [ "$C" -gt 9 ]; then
    ApplyPatch $patch ${1+"$@"}
  fi
}                                                                                                                                                                                                                                               %setup -q -n kernel-5.17.12 -c
mv linux-5.17.12 linux-%{KVERREL}                                                                                                                                                                                                               cd linux-%{KVERREL}                                                                                                     cp -a %{SOURCE1} .                                                                                                                                                                                                                              %if !%{nopatches}                                                                                                                                                                                                                               ApplyOptionalPatch patch-%{patchversion}-redhat.patch                                                                   %endif                                                                                                                                                                                                                                          ApplyOptionalPatch linux-kernel-test.patch
ApplyOptionalPatch add-acs-override.patch
# END OF PATCH APPLICATIONS
                                                                                                                        # Any further pre-build tree manipulations happen here.                                                                                                                                                                                         chmod +x scripts/checkpatch.pl                                                                                                                                                                                                                  "kernel.spec" 5561L, 269302B written
[star@fedora SPECS]$ rpmbuild -bb kernel.spec
warning: Macro expanded in comment on line 191: %define with_kabichk   %{?_without_kabichk:   0} %{?!_without_kabichk:   1}

setting SOURCE_DATE_EPOCH=1653868800
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.Rw5RzT
+ umask 022
+ cd /home/star/rpmbuild/BUILD
+ patch_command='patch -p1 -F1 -s'
+ cd /home/star/rpmbuild/BUILD
+ rm -rf kernel-5.17.12
+ /usr/bin/mkdir -p kernel-5.17.12
+ cd kernel-5.17.12
+ /usr/bin/xz -dc /home/star/rpmbuild/SOURCES/linux-5.17.12.tar.xz
+ /usr/bin/tar -xof -
+ STATUS=0
+ '[' 0 -ne 0 ']'
+ /usr/bin/chmod -Rf a+rX,u+w,g-w,o-w .
+ mv linux-5.17.12 linux-5.17.12-300.acs.fc36.x86_64
+ cd linux-5.17.12-300.acs.fc36.x86_64
+ cp -a /home/star/rpmbuild/SOURCES/Makefile.rhelver .
+ ApplyOptionalPatch patch-5.17-redhat.patch
+ local patch=patch-5.17-redhat.patch
+ shift
+ '[' '!' -f /home/star/rpmbuild/SOURCES/patch-5.17-redhat.patch ']'
++ wc -l /home/star/rpmbuild/SOURCES/patch-5.17-redhat.patch
++ awk '{print $1}'
+ local C=2112
+ '[' 2112 -gt 9 ']'
+ ApplyPatch patch-5.17-redhat.patch
+ local patch=patch-5.17-redhat.patch
+ shift
+ '[' '!' -f /home/star/rpmbuild/SOURCES/patch-5.17-redhat.patch ']'
+ case "$patch" in
+ patch -p1 -F1 -s
+ ApplyOptionalPatch linux-kernel-test.patch
+ local patch=linux-kernel-test.patch
+ shift
+ '[' '!' -f /home/star/rpmbuild/SOURCES/linux-kernel-test.patch ']'
++ wc -l /home/star/rpmbuild/SOURCES/linux-kernel-test.patch
++ awk '{print $1}'
+ local C=0
+ '[' 0 -gt 9 ']'
+ ApplyOptionalPatch add-acs-override.patch
+ local patch=add-acs-override.patch
+ shift
+ '[' '!' -f /home/star/rpmbuild/SOURCES/add-acs-override.patch ']'
++ wc -l /home/star/rpmbuild/SOURCES/add-acs-override.patch
++ awk '{print $1}'
+ local C=192
+ '[' 192 -gt 9 ']'
+ ApplyPatch add-acs-override.patch
+ local patch=add-acs-override.patch
+ shift
+ '[' '!' -f /home/star/rpmbuild/SOURCES/add-acs-override.patch ']'
Patch1000: add-acs-override.patch
+ case "$patch" in
+ patch -p1 -F1 -s
1 out of 2 hunks FAILED -- saving rejects to file drivers/pci/quirks.c.rej
error: Bad exit status from /var/tmp/rpm-tmp.Rw5RzT (%prep)

RPM build warnings:
    Macro expanded in comment on line 191: %define with_kabichk   %{?_without_kabichk:   0} %{?!_without_kabichk:   1}


RPM build errors:
    Bad exit status from /var/tmp/rpm-tmp.Rw5RzT (%prep)

Is F34 build still relevant?

Hello all,

please comment if you are still using F34 and need ACS kernels for this release.
As i was the one asking for F34 kernels for my home server, i feel obligated to ask for deprecation.

Best regards,
Stefan

Does this work with AMD?

Maybe a stupid question since it explicitly says one needs an Intel CPU for this. Any reason it should not work on a Ryzen CPU?

FC 37 EOL

Hi Natalie,

Happy new Year! :)
Just wanted to remind you that FC 37 is EOL since end of last year.
Maybe you want to do a little spring cleaning?

Best regards, Stefan

last build 3 weeks ago

hi natalie, the last build is 3 weeks in the past and there is a 6.6 kernel for fc38 in the official repo. would be nice to run a new build. tnx in advance, stefan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.