2021-11-07 19:53:16

by Longpeng(Mike)

[permalink] [raw]
Subject: [PATCH v5 0/4] Merge contiguous physical memory regions

From: Longpeng <[email protected]>

Hi guys,

This patchset try to merge the contiguous physical memory regions when
set user memory regions, you can see message in PATCH 1 for details.
Please review when you free, thank!

Changes v4 -> v5:
Patch 1:
- "Physical contiguous memory regions" -> "Contiguous physical memory
regions." [Andra]
- fix the warning of aligment that reported by the checkpath.pl [Andra]
Patch 4:
- fix the warning of aligment that reported by the checkpath.pl [Andra]
- remove unnecessary comparison of NULL. [Andra]

Changes v3 -> v4:
Patch 1:
- move "#include <linux/range.h>" according to the alphabetical order. [Andra]
- rename several variables, parameters, structures and functions. [Andra]
- add missing "Context" in the comments. [Andra]
- some other changes to makes the code much neater. [Andra]
Patch 2:
- add missing "Context" in the comments. [Andra]
- move the comment in ne_merge_phys_contig_memory_regions() before
the "if (...)". [Andra]
Patch 3:
- Nitro enclaves -> Nitro Enclaves [Andra]
- check the return code of "ne_misc_dev_test_init()" [Andra]
- GPL-2.0-or-later -> GPL-2.0 [Andra]
Patch 4:
- "int expect_num" -> "unsigned long expect_num" [Andra]
- rename several variables and structures [Andra]
- invoke "kunit_kfree" to free the "regions" [Andra]

Changes v2 -> v3:
Patch 1:
- update the commit title and commit message. [Andra]
- use 'struct range' to instead of 'struct phys_mem_region'. [Andra, Greg KH]
- add comments before the function definition. [Andra]
- rename several variables, parameters and function. [Andra]
Patch 2:
- update the commit title and commit message. [Andra]
- add comments before the function definition. [Andra]
- remove 'inline' attribute of ne_sanity_check_phys_mem_region. [Andra]
- leave a blank line before return. [Andra]
- move sanity check in ne_merge_phys_contig_memory_regions to
the beginning of the function. [Andra]
- double sanity checking after the merge of physical contiguous
memory regions has been completed. [Andra]
Patch 3:
- update the commit title and commit message. [Andra]
- use "misc_dev"/"misc device"/"MISC_DEV" to be more specific. [Andra]
Patch 4:
- update the commit title and commit message. [Andra]
- align the fileds in 'struct phys_regions_test'. [Andra]
- rename 'phys_regions_testcases' to 'phys_regions_test_cases'. [Andra]
- add comments before each test cases. [Andra]
- initialize the variables in ne_misc_dev_test_merge_phys_contig_memory_regions. [Andra]

Changes v1 -> v2:
- update the commit message as Andra's suggestion [Andra]
- remove TODO completely in ne_set_user_memory_region_ioctl [Andra]
- extract the physical memory regions setup into individual
function
- add kunit tests [Andra]

Longpeng (4):
nitro_enclaves: Merge contiguous physical memory regions
nitro_enclaves: Sanity check physical memory regions during merging
nitro_enclaves: Add KUnit tests setup for the misc device
functionality
nitro_enclaves: Add KUnit tests for contiguous physical memory regions
merging

drivers/virt/nitro_enclaves/Kconfig | 9 ++
drivers/virt/nitro_enclaves/ne_misc_dev.c | 174 ++++++++++++++++++-------
drivers/virt/nitro_enclaves/ne_misc_dev_test.c | 157 ++++++++++++++++++++++
3 files changed, 296 insertions(+), 44 deletions(-)
create mode 100644 drivers/virt/nitro_enclaves/ne_misc_dev_test.c

--
1.8.3.1


2021-11-07 20:23:22

by Longpeng(Mike)

[permalink] [raw]
Subject: [PATCH v5 3/4] nitro_enclaves: Add KUnit tests setup for the misc device functionality

From: Longpeng <[email protected]>

Add the initial setup for the KUnit tests that will target the Nitro
Enclaves misc device functionality.

Signed-off-by: Longpeng <[email protected]>
Reviewed-by: Andra Paraschiv <[email protected]>
---
drivers/virt/nitro_enclaves/Kconfig | 9 ++++++++
drivers/virt/nitro_enclaves/ne_misc_dev.c | 31 ++++++++++++++++++++++++++
drivers/virt/nitro_enclaves/ne_misc_dev_test.c | 17 ++++++++++++++
3 files changed, 57 insertions(+)
create mode 100644 drivers/virt/nitro_enclaves/ne_misc_dev_test.c

diff --git a/drivers/virt/nitro_enclaves/Kconfig b/drivers/virt/nitro_enclaves/Kconfig
index f53740b..2d3d981 100644
--- a/drivers/virt/nitro_enclaves/Kconfig
+++ b/drivers/virt/nitro_enclaves/Kconfig
@@ -14,3 +14,12 @@ config NITRO_ENCLAVES

To compile this driver as a module, choose M here.
The module will be called nitro_enclaves.
+
+config NITRO_ENCLAVES_MISC_DEV_TEST
+ bool "Tests for the misc device functionality of the Nitro Enclaves"
+ depends on NITRO_ENCLAVES && KUNIT=y
+ help
+ Enable KUnit tests for the misc device functionality of the Nitro
+ Enclaves. Select this option only if you will boot the kernel for
+ the purpose of running unit tests (e.g. under UML or qemu). If
+ unsure, say N.
diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c
index 83ed9b5..51ba4ca 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -1756,8 +1756,37 @@ static long ne_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
return 0;
}

+#if defined(CONFIG_NITRO_ENCLAVES_MISC_DEV_TEST)
+#include "ne_misc_dev_test.c"
+
+static inline int ne_misc_dev_test_init(void)
+{
+ return __kunit_test_suites_init(ne_misc_dev_test_suites);
+}
+
+static inline void ne_misc_dev_test_exit(void)
+{
+ __kunit_test_suites_exit(ne_misc_dev_test_suites);
+}
+#else
+static inline int ne_misc_dev_test_init(void)
+{
+ return 0;
+}
+
+static inline void ne_misc_dev_test_exit(void)
+{
+}
+#endif
+
static int __init ne_init(void)
{
+ int rc = 0;
+
+ rc = ne_misc_dev_test_init();
+ if (rc < 0)
+ return rc;
+
mutex_init(&ne_cpu_pool.mutex);

return pci_register_driver(&ne_pci_driver);
@@ -1768,6 +1797,8 @@ static void __exit ne_exit(void)
pci_unregister_driver(&ne_pci_driver);

ne_teardown_cpu_pool();
+
+ ne_misc_dev_test_exit();
}

module_init(ne_init);
diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev_test.c b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c
new file mode 100644
index 0000000..6862e99
--- /dev/null
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c
@@ -0,0 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <kunit/test.h>
+
+static struct kunit_case ne_misc_dev_test_cases[] = {
+ {}
+};
+
+static struct kunit_suite ne_misc_dev_test_suite = {
+ .name = "ne_misc_dev_test",
+ .test_cases = ne_misc_dev_test_cases,
+};
+
+static struct kunit_suite *ne_misc_dev_test_suites[] = {
+ &ne_misc_dev_test_suite,
+ NULL
+};
--
1.8.3.1