0
votes

I'm trying to call two exported (maybe) kernel functions from the KVM - kvm_write_guest and kvm_get_segment but when I compile a kernel driver that will call these two functions I get a warning saying they are undefined.

WARNING: "kvm_write_guest" [/home/driver.ko] undefined!
WARNING: "kvm_get_segment" [/home/driver.ko] undefined!

When I executed the commands:

cat /proc/kallsyms | grep kvm_get_segment
cat /proc/kallsyms | grep kvm_write_guest

to check to see if they are exported I get the following:

0000000000000000 t kvm_write_guest  [kvm]
0000000000000000 t kvm_get_segment  [kvm]

Below are the protocols and includes that I have in the header file that is included in the .c file that calls these functions. I pulled the prototypes from the kvm_main.c code.

#include <linux/kvm.h>
#include <linux/kvm_types.h>
#include <linux/kvm_host.h>
int kvm_write_guest(struct kvm *kvm, gpa_t gpa, const void *data, unsigned long len);
void kvm_get_segment(struct kvm_vcpu *vcpu, struct kvm_segment *var, int seg);

When I dig into the kvm_main.c source code for kvm_write_guest they don't seem to be exported using the following code:

EXPORT_SYMBOL_GPL(kvm_write_guest);

When I dig into the x86.c code for kvm_get_segment it isn't exported using that method either. It doesn't seem that they are in fact exported but I want to make sure I'm not doing something wrong. I'd like to avoid patching the code and recompiling if I can. Thank in advance for any help it is greatly appreciated!

2

2 Answers

0
votes

You're not doing anything wrong. If they're not exported with EXPORT_SYMBOL or EXPORT_SYMBOL_GPL, you won't be able to call them from a module.

0
votes

Looks like you have two different problems. kvm_get_segment is only defined in arch/x86/kvm/x86.c and is not exported. So another module can't link to it (without patching the source or playing complicated tricks at runtime).

On the other hand, as you point out, kvm_write-guest is exported, with:

EXPORT_SYMBOL_GPL(kvm_write_guest);

That means only GPL-licensed modules can link to it; you'll need to put

MODULE_LICENSE("GPL");

in your driver to use that symbol. (And make sure you understand the legal implications of doing that)