Skip to contentSkip to conversation

kvmtool: ARM: madvise mergeable and hugepage separately

PATCH In review Stefan Agner 3 participants 3 messages Aug 8, 2016 – Aug 25, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kvmtool: ARM: madvise mergeable and hugepage separately

The madvise behavior is not a bit field and hence can not be or'ed. Also madvise_behavior_valid checks the flag using a case statement hence only one behavior is supposed to be supplied. Call madvise twice, once for MERGEABLE and once for HUGEPAGE.

---
 arm/kvm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arm/kvm.c +4 -1
index ce40897..3cfa90a 100644
@@ -80,7 +80,10 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 					SZ_2M);
 
 	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_MERGEABLE | MADV_HUGEPAGE);
+		MADV_MERGEABLE);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_HUGEPAGE);
 
 	/* Create the virtual GIC. */
 	if (gic__create(kvm, kvm->cfg.arch.irqchip))
Signature · 1 line
2.9.0
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 4 lines · Stefan Agner

The madvise behavior is not a bit field and hence can not be or'ed. Also madvise_behavior_valid checks the flag using a case statement hence only one behavior is supposed to be supplied. Call madvise twice, once for MERGEABLE and once for HUGEPAGE.

thanks for that catch! Indeed we are only setting HUGEPAGE right now, dropping MERGEABLE due to the OR'ing.

Cheers,
Andre.

Quoted 23 lines
---
 arm/kvm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arm/kvm.c +4 -1
index ce40897..3cfa90a 100644
@@ -80,7 +80,10 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 					SZ_2M);
 
 	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_MERGEABLE | MADV_HUGEPAGE);
+		MADV_MERGEABLE);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_HUGEPAGE);
 
 	/* Create the virtual GIC. */
 	if (gic__create(kvm, kvm->cfg.arch.irqchip))
#2 lore raw
In reply to Stefan Agner
Quoted 15 lines · Stefan Agner

The madvise behavior is not a bit field and hence can not be or'ed. Also madvise_behavior_valid checks the flag using a case statement hence only one behavior is supposed to be supplied. Call madvise twice, once for MERGEABLE and once for HUGEPAGE.

---
 arm/kvm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arm/kvm.c +0 -0
index ce40897..3cfa90a 100644

arm/kvm.c void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size) · line 86

Quoted 8 lines
arm/kvm.c +4 -1
@@ -80,7 +80,10 @@ void kvm__arch_init(struct kvm *kvm, const char *hugetlbfs_path, u64 ram_size)
 					SZ_2M);
 
 	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
-		MADV_MERGEABLE | MADV_HUGEPAGE);
+		MADV_MERGEABLE);
+
+	madvise(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size,
+		MADV_HUGEPAGE);

Should we also do a MADV_DONTDUMP for guest RAM pages ? This is a security option to strip off any guest data in case of crash in kvmtool. This could also help to reduce the size of the kvmtool core dumps. I think Qemu does this already.

Suzuki