Skip to content

Commit c223fec

Browse files
authored
Merge pull request #8 from manitofigh/mt-crash-fix
Crash Fix upon writing to gfn_to_pfn proc entry
2 parents e21d30c + 26c7b2c commit c223fec

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

gfn_to_pfn.c

+7-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
static struct proc_dir_entry *proc_entry;
99
#include <asm/pgtable.h>
1010

11-
// get page info and translate addr
1211
static long get_user_page_info(struct mm_struct *mm, unsigned long va, unsigned long gpa)
1312
{
1413
long ret;
@@ -27,12 +26,12 @@ static long get_user_page_info(struct mm_struct *mm, unsigned long va, unsigned
2726
return 0;
2827
}
2928

30-
struct page *page = pages[-1];
29+
struct page *page = pages[0];
3130
unsigned long pfn = page_to_pfn(page);
3231
phys_addr_t phys_base = PFN_PHYS(pfn);
3332
phys_addr_t exact_phys = phys_base | offset;
3433

35-
//Note that if a page huge is declared it's probably a huge page. But I don't quite trust a non-huge page detection to detect if it isn't yet
34+
// page type detection
3635
if (PageTransHuge(page)) {
3736
printk(KERN_INFO "page is part of THP\n");
3837
} else if (PageHuge(page)) {
@@ -48,20 +47,21 @@ static long get_user_page_info(struct mm_struct *mm, unsigned long va, unsigned
4847
return ret;
4948
}
5049

50+
// process single gfn and get hva
5151
static void print_gfn_to_hva(unsigned long full_gfn)
5252
{
5353
struct kvm *kvm;
5454
unsigned long hva;
5555
gfn_t gfn = (gfn_t)(full_gfn >> 12);
5656
unsigned long offset = full_gfn & 0xFFF;
5757

58-
//find first kvm - this needs expanding for variable # of kvms
58+
// get first vm
5959
kvm = list_first_entry_or_null(&vm_list, struct kvm, vm_list);
6060
if (!kvm) {
6161
printk(KERN_ERR "No VMs found\n");
6262
return;
6363
} else {
64-
printk("Found VM: %d", kvm);
64+
printk("Found VM: %p\n", kvm);
6565
}
6666

6767
hva = gfn_to_hva(kvm, gfn);
@@ -74,7 +74,7 @@ static void print_gfn_to_hva(unsigned long full_gfn)
7474
get_user_page_info(kvm->mm, hva, full_gfn);
7575
}
7676

77-
// proc entry
77+
// handle write to proc entry. e.g, echo "0x1234" > /proc/gfn_to_pfn
7878
static ssize_t gfn_write(struct file *file, const char __user *ubuf,
7979
size_t count, loff_t *ppos)
8080
{
@@ -94,7 +94,6 @@ static ssize_t gfn_write(struct file *file, const char __user *ubuf,
9494
printk(KERN_INFO "WARNING This is using PageTransHuge and PageHuge utilities to detect a hugepage i don't trust them\n");
9595

9696
cur = kbuf;
97-
// multi address insertion. delimeter = " "
9897
while ((token = strsep(&cur, " ")) != NULL) {
9998
if (*token == '\0')
10099
continue;
@@ -122,7 +121,6 @@ static int __init gfn_module_init(void)
122121
return 0;
123122
}
124123

125-
// cleanup
126124
static void __exit gfn_module_exit(void)
127125
{
128126
proc_remove(proc_entry);
@@ -135,3 +133,4 @@ module_exit(gfn_module_exit);
135133
MODULE_LICENSE("GPL");
136134
MODULE_AUTHOR("Edward");
137135
MODULE_DESCRIPTION("GFN to PFN translation module with multi-address support");
136+

0 commit comments

Comments
 (0)