[PATCH OLK-6.6 0/2] fix bug in hdbss

Jinqian Yang (2): KVM: arm64: do not support hdbss in nvhe KVM: arm64: fix memory leak in HDBSS arch/arm64/kvm/arm.c | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) -- 2.33.0

virt inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICUHW4 -------------------------------------------------------------------- In nVHE mode, after hdbss size is configured, the host still reports call trace messages duringlive migration. The modification in this commit ensures that after configuring the hdbss size in nvhe, the host will report nvhe does not support hdbss during live migration. Fixes: bd6106e348d7 ("arm64/kvm: using ioctl to enable/disable the HDBSS feature") Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com> Signed-off-by: Eillon <yezhenyu2@huawei.com> --- arch/arm64/kvm/arm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 4a9cb1d8070a..ce3edd7a50c5 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -144,6 +144,11 @@ static int kvm_cap_arm_enable_hdbss(struct kvm *kvm, return -EINVAL; } + if (!is_kernel_in_hyp_mode()) { + kvm_err("Do not support HDBSS in non-VHE mode!\n"); + return -EINVAL; + } + if (size < 0 || size > HDBSS_MAX_SIZE) { kvm_err("Invalid HDBSS buffer size: %d!\n", size); return -EINVAL; -- 2.33.0

virt inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/ICUHW4 -------------------------------------------------------------------- Allocate hdbss page for each vcpu. If the allocation fails midway, the previously allocated page will not be released, causing a memory leak. This patch solves this problem. Fixes: bd6106e348d7 ("arm64/kvm: using ioctl to enable/disable the HDBSS feature") Signed-off-by: Jinqian Yang <yangjinqian1@huawei.com> --- arch/arm64/kvm/arm.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index ce3edd7a50c5..01a3651a7395 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -131,6 +131,29 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu) } #ifdef CONFIG_ARM64_HDBSS +static void kvm_clear_hdbss(struct kvm *kvm) +{ + unsigned long i; + struct kvm_vcpu *vcpu; + struct page *hdbss_pg; + + kvm->arch.vtcr &= ~(VTCR_EL2_HD | VTCR_EL2_HDBSS); + + kvm_for_each_vcpu(i, vcpu, kvm) { + /* Kick vcpus to flush hdbss buffer. */ + kvm_vcpu_kick(vcpu); + + hdbss_pg = phys_to_page(HDBSSBR_BADDR(vcpu->arch.hdbss.br_el2)); + if (hdbss_pg) + __free_pages(hdbss_pg, HDBSSBR_SZ(vcpu->arch.hdbss.br_el2)); + + vcpu->arch.hdbss.br_el2 = 0; + vcpu->arch.hdbss.prod_el2 = 0; + } + + kvm->enable_hdbss = false; +} + static int kvm_cap_arm_enable_hdbss(struct kvm *kvm, struct kvm_enable_cap *cap) { @@ -163,6 +186,7 @@ static int kvm_cap_arm_enable_hdbss(struct kvm *kvm, hdbss_pg = alloc_pages(GFP_KERNEL, size); if (!hdbss_pg) { kvm_err("Alloc HDBSS buffer failed!\n"); + kvm_clear_hdbss(kvm); return -EINVAL; } @@ -179,21 +203,7 @@ static int kvm_cap_arm_enable_hdbss(struct kvm *kvm, kvm_info("Enable HDBSS success, HDBSS buffer size: %d\n", size); } else if (kvm->enable_hdbss) { - kvm->arch.vtcr &= ~(VTCR_EL2_HD | VTCR_EL2_HDBSS); - - kvm_for_each_vcpu(i, vcpu, kvm) { - /* Kick vcpus to flush hdbss buffer. */ - kvm_vcpu_kick(vcpu); - - hdbss_pg = phys_to_page(HDBSSBR_BADDR(vcpu->arch.hdbss.br_el2)); - if (hdbss_pg) - __free_pages(hdbss_pg, HDBSSBR_SZ(vcpu->arch.hdbss.br_el2)); - - vcpu->arch.hdbss.br_el2 = 0; - vcpu->arch.hdbss.prod_el2 = 0; - } - - kvm->enable_hdbss = false; + kvm_clear_hdbss(kvm); kvm_info("Disable HDBSS success\n"); } -- 2.33.0

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17748 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/4DY... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17748 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/4DY...
participants (2)
-
Jinqian Yang
-
patchwork bot