forked from torvalds/linux
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KVM: arm64: Add a buffer that can pass UBSan data from hyp/nVHE to ke…
…rnel Share a buffer between the kernel and the hyp/nVHE code by using the macros from kvm_debug_buffer.h. The hyp/nVHE code requires a write index which counts how many elements have been writtens inside the buffer and the kernel requires a read index which counts how many elements have been read from the buffer. The write index and the buffer are shared with the kernel in read-only. The kvm_debug_buffer_ind returns the reading and writing points of the circular buffer and updates the reading index. Data collected from UBSan handlers inside hyp/nVHE is stored in the kvm_ubsan_buffer. This buffer stores only UBSan data because it should not be preoccupied by other mechanisms data structures and functionalities. Also, for the moment the buffer is mapped inside .bss, where both the kernel and the hyp/nVHE code have Read/Write rights, but in the future this will change and the kernel will not be able to acess hyp/nVHE's .bss. At that point the buffer will only need to be mapped in order for this patch to work. Change-Id: I696409db1de629b082abfe4c7f6bf066f12b539f Signed-off-by: Elena Petrova <lenaptr@google.com>
- Loading branch information
1 parent
9eaabf2
commit aba3219
Showing
9 changed files
with
146 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* Author: George Popescu <georgepope@google.com> | ||
*/ | ||
|
||
#include <linux/percpu-defs.h> | ||
|
||
|
||
#define KVM_DEBUG_BUFFER_SIZE 1000 | ||
|
||
#ifdef __KVM_NVHE_HYPERVISOR__ | ||
#define DEFINE_KVM_DEBUG_BUFFER(type_name, buffer_name, write_ind, size)\ | ||
DEFINE_PER_CPU(type_name, buffer_name)[size]; \ | ||
DEFINE_PER_CPU(unsigned long, write_ind) = 0; | ||
|
||
#define DECLARE_KVM_DEBUG_BUFFER(type_name, buffer_name, write_ind, size)\ | ||
DECLARE_PER_CPU(type_name, buffer_name)[size]; \ | ||
DECLARE_PER_CPU(unsigned long, write_ind); | ||
#else | ||
#define DECLARE_KVM_DEBUG_BUFFER(type_name, buffer_name, write_ind, size)\ | ||
DECLARE_KVM_NVHE_PER_CPU(type_name, buffer_name)[size]; \ | ||
DECLARE_KVM_NVHE_PER_CPU(unsigned long, write_ind); | ||
#endif //__KVM_NVHE_HYPERVISOR__ | ||
|
||
#ifdef __ASSEMBLY__ | ||
#include <asm/assembler.h> | ||
|
||
.macro clear_buffer tmp1, tmp2, tmp3 | ||
mov \tmp1, 0 | ||
#ifdef CONFIG_UBSAN | ||
str_this_cpu kvm_ubsan_buff_wr_ind, \tmp1, \tmp2, \tmp3 | ||
#endif //CONFIG_UBSAN | ||
.endm | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-only */ | ||
/* | ||
* Copyright 2020 Google LLC | ||
* Author: George Popescu <georgepope@google.com> | ||
*/ | ||
|
||
#include <ubsan.h> | ||
|
||
#define UBSAN_MAX_TYPE 6 | ||
#define KVM_UBSAN_BUFFER_SIZE 1000 | ||
|
||
struct kvm_ubsan_info { | ||
int type; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
/* | ||
* Copyright 2020 Google LLC | ||
* Author: George Popescu <georgepope@google.com> | ||
*/ | ||
|
||
#include <linux/ctype.h> | ||
#include <linux/types.h> | ||
#include <asm/kvm_debug_buffer.h> | ||
#include <asm/kvm_arm.h> | ||
#include <asm/kvm_asm.h> | ||
#include <kvm/arm_pmu.h> | ||
|
||
#include <ubsan.h> | ||
#include <asm/kvm_ubsan.h> | ||
|
||
DECLARE_KVM_DEBUG_BUFFER(struct kvm_ubsan_info, kvm_ubsan_buffer, | ||
kvm_ubsan_buff_wr_ind, KVM_UBSAN_BUFFER_SIZE); | ||
|
||
|
||
void iterate_kvm_ubsan_buffer(unsigned long left, unsigned long right) | ||
{ | ||
unsigned long i; | ||
struct kvm_ubsan_info *slot; | ||
|
||
slot = (struct kvm_ubsan_info *) this_cpu_ptr_nvhe_sym(kvm_ubsan_buffer); | ||
for (i = left; i < right; ++i) { | ||
/* check ubsan data */ | ||
slot[i].type = 0; | ||
} | ||
} | ||
|
||
void __kvm_check_ubsan_buffer(void) | ||
{ | ||
unsigned long *write_ind; | ||
|
||
write_ind = (unsigned long *) this_cpu_ptr_nvhe_sym(kvm_ubsan_buff_wr_ind); | ||
iterate_kvm_ubsan_buffer(0, *write_ind); | ||
} | ||
|