본문 바로가기

CXL_QEMU

01. How To Emulate CXL Devices using KVM and QEMU

 

https://stevescargall.com/blog/2022/01/20/how-to-emulate-cxl-devices-using-kvm-and-qemu/

 

How To Emulate CXL Devices using KVM and QEMU

What is CXL? Compute Express Link (CXL) is an open standard for high-speed central processing unit-to-device and CPU-to-memory connections, designed for high-performance data center computers. CXL is built on the PCI Express physical and electrical interfa

stevescargall.com

 

01. What is CXL?

  • CXL is an open standard for high-speed central processing unit-to-device and CPU-to-memory connections,
    designed for high-performance data center computers.
  • CXL is built on the PCIe Physical and Electrical interface with protocols in three areas:
    • CXL.io
    • CXL.mem
    • CXL.cache

02. Who should read this articls

  • H/W가 없는 환경에서 유용하지만, 나의 경우 cxl device-driver, kernel 패치를 위해 QEMU 환경이 필요
  • 개발자들은 어떻게 CXL의 application들이 새로운 CXL H/W에서 구동되는지 알아야 한다.
  • 시스템 관리자들은 OS에서 CXL 메모리가 어떻게 보이는지 알아야 한다
  • H/W, S/W, Solution Architects는 그들의 환경에서 어떻게 CXL을 활용해야 하는지 알아야 한다

03. Prerequisites

  • 초기 버전의 CXL 드라이버는 kernel v5.12에 업스트림 되었다. (기능 구현보단, plumbing)
  • 커널 버전은 가급적 최신 버전 사용
  • 필요한 요구 조건
    • 가상화 기능이 enabled BIOS (for KVM acceleration)
    • QEMU
    • virt-install, libvirt, and libvirt-daemon-kvm 
    • A recent Linux distro for the Host OS 
    • A recent Linux distro for the Guest OS 
    • git command
    • build tools
  • install prerequisites for building qemu and ntctl;
//Fedora
$ sudo dnf install git gcc autoconf automake asciidoc asciidoctor xmlto libtool pkg-config glib2 glib2-devel libfabric libfabric-devel doxygen graphviz pandoc ncurses kmod kmod-devel libudev-devel libuuid-devel json-c-devel keyutils-libs-devel iniparser iniparser-devel bash-completion ninja-build sparse pixman pixman-devel
$ sudo dnf install virt-install libvirt libvirt-daemon-kvm qemu-img cloud-init genisoimage

//Ubuntu 
$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-daemon virtinst bridge-utils libosinfo-bin
  • 이외에도 필요한 패키지를 상황에 맞춰 설치 (아래의 패키지들 참조) 
autoconf automake asciidoc asciidoctor xmlto libtool pkg-config
glib2 glib glib2 glib2-devel libglib2.0-dev libglib2.0 libfabric
libfabric-dev libfabric doxygen graphbiz graphviz pandoc ncurses
libncurses libncurses5-dev libncursesw5-dev kmod kmod-devel libudev-devel
libudev-dev libuuid-devel uuid-dev json-c-devel libjson-c-dev keyutils-libs-devel
iniparser iniparser-devel bash-completion ninja-build sparse pixman pixman-devel
virt-install libvirt libvirt-daemon-kvm qemu-img pixman-1 libpixman-1-dev flex bison
  • 이 블로그에서는 아래의 version을 사용
    • QEMU: 8.2.1
    • Kernel: 6.8.0-rc2

04. Enable Virtualization

  • BIOS에서 가상화 기능을 키는 것은 KVM acceleration을 활용할 수 있게 한다.
dhkang@dhkang-Z97-HD3:~$ sudo lscpu | grep Virtualization
Virtualization:                     VT-x
  • VT-x가 의미하는 것은 Intel CPU에서 가상화 기능이 켜졌다는 것을 의미
  • AMD-V가 의미하는 것은 (역시나) AMD CPU가 가상화 기능이 켜졌다는 것을 의미

05. Install QEMU

  • 이 블로그가 작성된 시점엔 최신 QEMU(6.2.0)는 CXL을 지원하지 않았음. 
    • cxl-2.0v4 development 브랜치(from Ben Widawsky)를 사용할 예정
  • QEMU-8.2.1 version 사용
  • 다양한 버전을 시도했으나, build error, option 미일치, CXL 미지원등 여러 문제가 존재
wget https://download.qemu.org/qemu-8.2.1.tar.xz
tar xvJf qemu-8.2.1.tar.xz
cd qemu-8.2.1

06. Build QEME

  • QEMU의 configuration은 feature들을 확인하는 동안 조용(에러 메시지X)할 것임
    • 에러가 발생했을 때만 표시할 것이며 빌드 완료 후에는 활성화된 최종 feature들만 표시함
  • QEMU의 개발 브랜치이기 때문에 "/opt/qemu-cxl" 경로에 설치하는 것을 권장 
    • 이미 기존에 존재하거나 추후 설치될 QEMU와의 인터페이싱을 방지하기 위해
    • 대안으로 "make install" 명령을 실행하지 않아야 함
      ("build" 디렉토리에서 생성된 바이너리 파일과 라이브러리를 직접 참조해야 함) 
  • Build QEMU
$ mkdir build
$ cd build
$ ../configure --prefix=/opt/qemu-cxl
$ make -j all
$ make install

07. Configure the Host Networking 

  • IP forwarding이 활성화(enabled)되어 있는지 확인
$ sudo cat /proc/sys/net/ipv4/ip_forward 
1
$ sudo cat /proc/sys/net/ipv6/conf/default/forwarding
1
  • 만약 필요하다면 다음 부팅 까지 forwarding을 활성화 할 수 있음
$sudo echo 1 > /proc/sys/net/ipv4/ip_forward
$sudo echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
  • 영구적으로 셋업 하려면 아래의 코드 참조
$ sudo vim /etc/sysctl.d/50-enable-forwarding.conf
# local customizations
#
# enable forwarding for dual stack
net.ipv4.ip_forwarding=1
net.ipv6.conf.all.forwarding=1

08. Disabling Appamor

 

**. Disabling Appamor

systemctl disable appamor
https://hkjeon2.tistory.com/102

 

sudo virt-install --connect qemu:///system --name CXL-Test --memory 4096 --cpu host --vcpus 4 --os-type linux --os-variant fedora35 --import --graphics none --disk /var/lib/libvirt/images/CXL-Test.qcow2,format=qcow2,bus=virtio --network direct,source=enpXsY,source_mode=route,model=virtio --network bridge=virbr0,model=virtio --cloud-init

-> 이 명령이 잘 안됨,, network setting에 문제가 있는것 같음

 

sudo virt-install --connect qemu:///system --name CXL-Test --memory 4096 --cpu host --vcpus 4 --os-type linux --os-variant fedora35 --import --graphics none --disk /var/lib/libvirt/images/CXL-Test.qcow2,format=qcow2,bus=virtio --network default,model=virtio --cloud-init

q6ZDqE1nVKFGc8Nu -> 암호 변경 (linux) 

 

sudo virsh shutdown DH_CXL-Test

sudo virsh start DH_CXL-Test

sudo virsh console DH_CXL-Test or index:2 

 

 

slirp 패키지 설치 후 qemu 재빌드

https://stackoverflow.com/questions/75641274/network-backend-user-is-not-compiled-into-this-binary

 

network backend 'user' is not compiled into this binary

I have build qemu-7.2.0 and then, when running it I am getting qemu-system-x86_64: -nic user,model=virtio: network backend 'user' is not compiled into this binary Apparently, I should enable this

stackoverflow.com

 

그리고 나서 아래 아래 페이지 참조하여 네트워크 셋팅 변경 후 qemu 실행

hostfwd=udp:127.0.0.1:6664-:664 

https://github.com/openbmc/docs/issues/60

 

 

그래도 잘 안된다....

브랜치가 너무 옜날 거인가???? 

https://gitlab.com/jic23/qemu/-/commit/65416ea6962c374995285c93336e80507d48ef13

 

cxl/vendor: SK hynix Niagara Multi-Headed SLD Device (65416ea6) · Commits · Jonathan / Qemu · GitLab

Create a new device to emulate the SK hynix Niagara MHSLD platform. This device has custom CCI commands that allow for applying isolation to each memory block between hosts. This...

gitlab.com

 

커널 빌드 참조

https://5equal0.tistory.com/entry/Linux-Kernel-Kernel-%EB%B9%8C%EB%93%9C-%EB%B0%8F-%EC%84%A4%EC%B9%98