On Tue, Aug 01, 2023, Tianrui Zhao wrote:Thanks, I will simplify this comment.
Add kvm selftests header files for LoongArch, including processor.h,Nit, my preference is to not bother with these types of comments, it should be
sysreg.h, and kvm_util_base.h. Those mainly contain LoongArch CSR
register defines and page table information.
Based-on: <20230720062813.4126751-1-zhaotianrui@xxxxxxxxxxx>
Signed-off-by: Tianrui Zhao <zhaotianrui@xxxxxxxxxxx>
---
.../selftests/kvm/include/kvm_util_base.h | 5 ++
.../kvm/include/loongarch/processor.h | 28 ++++++
.../selftests/kvm/include/loongarch/sysreg.h | 89 +++++++++++++++++++
3 files changed, 122 insertions(+)
create mode 100644 tools/testing/selftests/kvm/include/loongarch/processor.h
create mode 100644 tools/testing/selftests/kvm/include/loongarch/sysreg.h
diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h
index 07732a157ccd..8747127e0bab 100644
--- a/tools/testing/selftests/kvm/include/kvm_util_base.h
+++ b/tools/testing/selftests/kvm/include/kvm_util_base.h
@@ -197,6 +197,11 @@ extern enum vm_guest_mode vm_mode_default;
#define MIN_PAGE_SHIFT 12U
#define ptes_per_page(page_size) ((page_size) / 8)
+#elif defined(__loongarch__)
+#define VM_MODE_DEFAULT VM_MODE_P36V47_16K
+#define MIN_PAGE_SHIFT 14U
+#define ptes_per_page(page_size) ((page_size) / 8)
+
#endif
#define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT)
diff --git a/tools/testing/selftests/kvm/include/loongarch/processor.h b/tools/testing/selftests/kvm/include/loongarch/processor.h
new file mode 100644
index 000000000000..d67796af51a0
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/loongarch/processor.h
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * LoongArch processor specific defines
quite obvious from the file name that that everything in here is LoongArch
specific.
Thanks, I will move the contents of sysreg.h into processor.h to make the file easier.
+ */Any reason these can't simply go in processor.h? Neither file is particular large,
+#ifndef SELFTEST_KVM_PROCESSOR_H
+#define SELFTEST_KVM_PROCESSOR_H
+
+#include <linux/compiler.h>
+#define _PAGE_VALID_SHIFT 0
+#define _PAGE_DIRTY_SHIFT 1
+#define _PAGE_PLV_SHIFT 2 /* 2~3, two bits */
+#define _CACHE_SHIFT 4 /* 4~5, two bits */
+#define _PAGE_PRESENT_SHIFT 7
+#define _PAGE_WRITE_SHIFT 8
+
+#define PLV_KERN 0
+#define PLV_USER 3
+#define PLV_MASK 0x3
+
+#define _PAGE_VALID (0x1UL << _PAGE_VALID_SHIFT)
+#define _PAGE_PRESENT (0x1UL << _PAGE_PRESENT_SHIFT)
+#define _PAGE_WRITE (0x1UL << _PAGE_WRITE_SHIFT)
+#define _PAGE_DIRTY (0x1UL << _PAGE_DIRTY_SHIFT)
+#define _PAGE_USER (PLV_USER << _PAGE_PLV_SHIFT)
+#define __READABLE (_PAGE_VALID)
+#define __WRITEABLE (_PAGE_DIRTY | _PAGE_WRITE)
+#define _CACHE_CC (0x1UL << _CACHE_SHIFT) /* Coherent Cached */
+#endif
diff --git a/tools/testing/selftests/kvm/include/loongarch/sysreg.h b/tools/testing/selftests/kvm/include/loongarch/sysreg.h
new file mode 100644
index 000000000000..04f53674c9d8
--- /dev/null
+++ b/tools/testing/selftests/kvm/include/loongarch/sysreg.h
especially for CPU definition files.
Ok, I will drop this comment.
@@ -0,0 +1,89 @@Definitely drop this comment, once the patch is applied the fact that checkpatch
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef SELFTEST_KVM_SYSREG_H
+#define SELFTEST_KVM_SYSREG_H
+
+/*
+ * note that this declaration raises a checkpatch warning, but
+ * no good way to avoid it.
+ */
complains is irrelevant.
+#define zero $r0