Skip to content

Commit

Permalink
KVM: MMU: audit: inline audit function
Browse files Browse the repository at this point in the history
inline audit function and little cleanup

Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
  • Loading branch information
Xiao Guangrong authored and Avi Kivity committed Dec 27, 2011
1 parent d750ea2 commit e37fa78
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 29 deletions.
28 changes: 7 additions & 21 deletions arch/x86/kvm/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,6 @@ enum {
AUDIT_POST_SYNC
};

char *audit_point_name[] = {
"pre page fault",
"post page fault",
"pre pte write",
"post pte write",
"pre sync",
"post sync"
};

#ifdef CONFIG_KVM_MMU_AUDIT
static void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point);
#else
static void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) { }
#endif

#undef MMU_DEBUG

#ifdef MMU_DEBUG
Expand Down Expand Up @@ -1539,6 +1524,13 @@ static int kvm_sync_page_transient(struct kvm_vcpu *vcpu,
return ret;
}

#ifdef CONFIG_KVM_MMU_AUDIT
#include "mmu_audit.c"
#else
static void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point) { }
static void mmu_audit_disable(void) { }
#endif

static int kvm_sync_page(struct kvm_vcpu *vcpu, struct kvm_mmu_page *sp,
struct list_head *invalid_list)
{
Expand Down Expand Up @@ -4035,12 +4027,6 @@ void kvm_mmu_destroy(struct kvm_vcpu *vcpu)
mmu_free_memory_caches(vcpu);
}

#ifdef CONFIG_KVM_MMU_AUDIT
#include "mmu_audit.c"
#else
static void mmu_audit_disable(void) { }
#endif

void kvm_mmu_module_exit(void)
{
mmu_destroy_caches();
Expand Down
29 changes: 21 additions & 8 deletions arch/x86/kvm/mmu_audit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

#include <linux/ratelimit.h>

char const *audit_point_name[] = {
"pre page fault",
"post page fault",
"pre pte write",
"post pte write",
"pre sync",
"post sync"
};

#define audit_printk(kvm, fmt, args...) \
printk(KERN_ERR "audit: (%s) error: " \
fmt, audit_point_name[kvm->arch.audit_point], ##args)
Expand Down Expand Up @@ -227,18 +236,22 @@ static void audit_vcpu_spte(struct kvm_vcpu *vcpu)
static bool mmu_audit;
static struct jump_label_key mmu_audit_key;

static void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
static void __kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
{
static DEFINE_RATELIMIT_STATE(ratelimit_state, 5 * HZ, 10);

if (static_branch((&mmu_audit_key))) {
if (!__ratelimit(&ratelimit_state))
return;
if (!__ratelimit(&ratelimit_state))
return;

vcpu->kvm->arch.audit_point = point;
audit_all_active_sps(vcpu->kvm);
audit_vcpu_spte(vcpu);
}
vcpu->kvm->arch.audit_point = point;
audit_all_active_sps(vcpu->kvm);
audit_vcpu_spte(vcpu);
}

static inline void kvm_mmu_audit(struct kvm_vcpu *vcpu, int point)
{
if (static_branch((&mmu_audit_key)))
__kvm_mmu_audit(vcpu, point);
}

static void mmu_audit_enable(void)
Expand Down

0 comments on commit e37fa78

Please sign in to comment.