未验证 提交 7c5fbbe0 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!806 [sync] PR-760: LoongArch: kvm: fix bug of kvm's hugepage

Merge Pull Request from: @openeuler-sync-bot 
 

Origin pull request: 
https://gitee.com/openeuler/kernel/pulls/760 
 
The virtual machine will cause the physical machine to die when using the huge page because kvm does not enable the huge page feature,
In order to fix this problem,kvm need to enable the huge page feature when the physical machine enable the huge page feature at the same time.

Test passed with below step:
1.Allocate huge page resources to virtual machines
echo 68 > /sys/kernel/mm/hugepages/hugepages-32768kB/nr_hugepages
mount -t hugetlbfs -o pagesize=32768K none /mnt/kvm_hugepage

2.Start a virtual machine with huge page
MALLOC_PERTURB_=1  /usr/libexec/qemu-kvm
    -name 'avocado-vt-vm1'
    -machine loongson7a,memory-backend=mem-machine_mem
    -device pcie-root-port,id=pcie-root-port-0,multifunction=on,bus=pcie.0,addr=0x1,chassis=1
    -device pcie-pci-bridge,id=pcie-pci-bridge-0,addr=0x0,bus=pcie-root-port-0 
    -nodefaults
    -device qxl-vga,bus=pcie.0,addr=0x2
    -m 2048
    -object memory-backend-file,size=2048M,mem-path=/mnt/kvm_hugepage,id=mem-machine_mem 
    -smp 2,maxcpus=2,cores=2,threads=1,sockets=1 
    -cpu 'Loongson-3A5000'
    -device pcie-root-port,id=pcie-root-port-1,port=0x1,addr=0x1.0x1,bus=pcie.0,chassis=2
    -device qemu-xhci,id=usb1,bus=pcie-root-port-1,addr=0x0
    -device usb-tablet,id=usb-tablet1,bus=usb1.0,port=1
    -device pcie-root-port,id=pcie-root-port-2,port=0x2,addr=0x1.0x2,bus=pcie.0,chassis=3
    -device virtio-scsi-pci,id=virtio_scsi_pci0,bus=pcie-root-port-2,addr=0x0
    -blockdev node-name=file_image1,driver=file,filename=/root/avocado/data/avocado-vt/images/openEuler-22.03-loongarch64.qcow2
    -blockdev node-name=drive_image1,driver=qcow2,file=file_image1
    -device scsi-hd,id=image1,drive=drive_image1
    -device pcie-root-port,id=pcie-root-port-3,port=0x3,addr=0x1.0x3,bus=pcie.0,chassis=4
    -device virtio-net-pci,mac=9a:ab:6e:88:2f:5b,id=idk4GfF4,netdev=idwjd54m,bus=pcie-root-port-3,addr=0x0 
    -netdev tap,id=idwjd54m 
    -vnc :0 
    -rtc base=utc,clock=host 
    -boot menu=off,order=cdn,once=c,strict=off
    -bios /usr/share/qemu/loongarch_bios.bin
    -enable-kvm
    -monitor telnet:localhost:4444,server,nowait
    -serial stdio 
 
Link:https://gitee.com/openeuler/kernel/pulls/806 

Reviewed-by: Jialin Zhang <zhangjialin11@huawei.com> 
Signed-off-by: Jialin Zhang <zhangjialin11@huawei.com> 
......@@ -13,6 +13,10 @@
#include <asm/tlb.h>
#include "kvm_compat.h"
#if defined(CONFIG_HUGETLB_PAGE) || defined(CONFIG_TRANSPARENT_HUGEPAGE)
#define KVM_HUGE_TLB_SUPPORT
#endif
/*
* KVM_MMU_CACHE_MIN_PAGES is the number of GPA page table translation levels
* for which pages need to be cached.
......@@ -34,7 +38,7 @@ static int kvm_tlb_flush_gpa(struct kvm_vcpu *vcpu, unsigned long gpa)
static inline int kvm_pmd_huge(pmd_t pmd)
{
#ifdef CONFIG_LOONGARCH_HUGE_TLB_SUPPORT
#ifdef KVM_HUGE_TLB_SUPPORT
return (pmd_val(pmd) & _PAGE_HUGE) != 0;
#else
return 0;
......@@ -43,7 +47,7 @@ static inline int kvm_pmd_huge(pmd_t pmd)
static inline int kvm_pud_huge(pud_t pud)
{
#ifdef CONFIG_LOONGARCH_HUGE_TLB_SUPPORT
#ifdef KVM_HUGE_TLB_SUPPORT
return (pud_val(pud) & _PAGE_HUGE) != 0;
#else
return 0;
......@@ -52,7 +56,7 @@ static inline int kvm_pud_huge(pud_t pud)
static inline pmd_t kvm_pmd_mkhuge(pmd_t pmd)
{
#ifdef CONFIG_LOONGARCH_HUGE_TLB_SUPPORT
#ifdef KVM_HUGE_TLB_SUPPORT
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
return pmd_mkhuge(pmd);
#else
......@@ -68,7 +72,7 @@ static inline pmd_t kvm_pmd_mkhuge(pmd_t pmd)
static inline pmd_t kvm_pmd_mkclean(pmd_t pmd)
{
#ifdef CONFIG_LOONGARCH_HUGE_TLB_SUPPORT
#ifdef KVM_HUGE_TLB_SUPPORT
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
return pmd_mkclean(pmd);
#else
......@@ -84,7 +88,7 @@ static inline pmd_t kvm_pmd_mkclean(pmd_t pmd)
static inline pmd_t kvm_pmd_mkold(pmd_t pmd)
{
#ifdef CONFIG_LOONGARCH_HUGE_TLB_SUPPORT
#ifdef KVM_HUGE_TLB_SUPPORT
#ifdef CONFIG_TRANSPARENT_HUGEPAGE
return pmd_mkold(pmd);
#else
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册