Skip to content

[PW_SID:1080480] riscv: KVM: Fix memory leak in vector context allocation#1757

Closed
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1080480
Closed

[PW_SID:1080480] riscv: KVM: Fix memory leak in vector context allocation#1757
linux-riscv-bot wants to merge 1 commit into
workflow__riscv__fixesfrom
pw1080480

Conversation

@linux-riscv-bot
Copy link
Copy Markdown

PR for series 1080480 applied to workflow__riscv__fixes

Name: riscv: KVM: Fix memory leak in vector context allocation
URL: https://patchwork.kernel.org/project/linux-riscv/list/?series=1080480
Version: 1

When the second kzalloc() for host_context vector data fails,
the already-allocated guest_context vector data is not freed,
causing a memory leak. This is triggerable from userspace via:

  ioctl(vm_fd, KVM_CREATE_VCPU)
    → kvm_vm_ioctl_create_vcpu()
      → kvm_arch_vcpu_create()
        → kvm_riscv_vcpu_alloc_vector_context()

Note also that kvm_vm_ioctl_create_vcpu() does not call
kvm_arch_vcpu_destroy() on kvm_arch_vcpu_create() failure:

  kvm_arch_vcpu_create()           ← fails, returns error
      goto vcpu_free_run_page;     ← line 4209

  ...
  arch_vcpu_destroy:               ← SKIPPED
      kvm_arch_vcpu_destroy(vcpu); ← which would call free_vector_context
  vcpu_free_run_page:              ← lands HERE, below arch_vcpu_destroy
      free_page(vcpu->run);
  vcpu_free:
      kmem_cache_free(vcpu);

so kvm_riscv_vcpu_free_vector_context() is never called to
clean up the partial allocation.

Fixes: 0f4b825 ("RISC-V: KVM: Add vector lazy save/restore support")
Assisted-By: Claude Opus 4.6 (1M context)
Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Linux RISC-V bot <linux.riscv.bot@gmail.com>
@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
build-rv32-defconfig
Desc: Builds riscv32 defconfig
Duration: 135.70 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
build-rv64-clang-allmodconfig
Desc: Builds riscv64 allmodconfig with Clang, and checks for errors and added warnings
Duration: 1026.92 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
build-rv64-gcc-allmodconfig
Desc: Builds riscv64 allmodconfig with GCC, and checks for errors and added warnings
Duration: 1387.45 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
build-rv64-nommu-k210-defconfig
Desc: Builds riscv64 defconfig with NOMMU for K210
Duration: 24.86 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
build-rv64-nommu-k210-virt
Desc: Builds riscv64 defconfig with NOMMU for the virt platform
Duration: 26.10 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
checkpatch
Desc: Runs checkpatch.pl on the patch
Duration: 1.81 seconds
Result: ERROR
Output:

WARNING: Please use correct Fixes: style 'Fixes: <12+ chars of sha1> ("<title line>")' - ie: 'Fixes: 0f4b82579716 ("riscv: KVM: Add vector lazy save/restore support")'
#35: 
Fixes: 0f4b82579716 ("RISC-V: KVM: Add vector lazy save/restore support")

WARNING: Non-standard signature: Assisted-By:
#36: 
Assisted-By: Claude Opus 4.6 (1M context)

WARNING: 'Assisted-by:' is the preferred signature form
#36: 
Assisted-By: Claude Opus 4.6 (1M context)

ERROR: Unrecognized email address: 'Claude Opus 4.6 (1M context)'
#36: 
Assisted-By: Claude Opus 4.6 (1M context)

total: 1 errors, 3 warnings, 0 checks, 11 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

Commit ca6de4e91c7b ("riscv: KVM: Fix memory leak in vector context allocation") has style problems, please review.

NOTE: Ignored message types: ALLOC_SIZEOF_STRUCT CAMELCASE COMMIT_LOG_LONG_LINE GIT_COMMIT_ID MACRO_ARG_REUSE NO_AUTHOR_SIGN_OFF

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.
ERROR: Unrecognized email address: 'Claude Opus 4.6 (1M context)'
WARNING: 'Assisted-by:' is the preferred signature form
WARNING: Non-standard signature: Assisted-By:
WARNING: Please use correct Fixes: style 'Fixes: <12+ chars of sha1> ("<title line>")' - ie: 'Fixes: 0f4b82579716 ("riscv: KVM: Add vector lazy save/restore support")'


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
dtb-warn-rv64
Desc: Checks for Device Tree warnings/errors
Duration: 82.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
header-inline
Desc: Detects static functions without inline keyword in header files
Duration: 0.23 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
kdoc
Desc: Detects for kdoc errors
Duration: 0.82 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
module-param
Desc: Detect module_param changes
Duration: 0.24 seconds
Result: PASS

@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
verify-fixes
Desc: Verifies that the Fixes: tags exist
Duration: 1.29 seconds
Result: ERROR
Output:

Commit: ca6de4e91c7b8 ("riscv: KVM: Fix memory leak in vector context allocation")
	Fixes tag: Fixes: 0f4b82579716 ("RISC-V: KVM: Add vector lazy save/restore support")
	Has these problem(s):
		- Subject does not match target commit subject
		  Just use
			git log -1 --format='Fixes: %h ("%s")'
Problems with Fixes tag: 1


@linux-riscv-bot
Copy link
Copy Markdown
Author

Patch 1: "riscv: KVM: Fix memory leak in vector context allocation"
verify-signedoff
Desc: Verifies that Signed-off-by: tags are correct
Duration: 0.29 seconds
Result: PASS

@linux-riscv-bot linux-riscv-bot deleted the pw1080480 branch April 21, 2026 01:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants