mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Paraschiv, Andra-Irina" <andraprs@amazon.com>
To: "Longpeng(Mike)" <longpeng2@huawei.com>
Cc: <arei.gonglei@huawei.com>, <gregkh@linuxfoundation.org>,
	<kamal@canonical.com>, <pbonzini@redhat.com>,
	<sgarzare@redhat.com>, <stefanha@redhat.com>,
	<vkuznets@redhat.com>, <linux-kernel@vger.kernel.org>,
	<ne-devel-upstream@amazon.com>, <lexnv@amazon.com>,
	<alcioa@amazon.com>
Subject: Re: [PATCH v3 4/4] nitro_enclaves: Add KUnit tests for contiguous physical memory regions merging
Date: Fri, 15 Oct 2021 17:28:41 +0300	[thread overview]
Message-ID: <c078d7fd-7c32-8a3a-3958-c0b79a67ddc7@amazon.com> (raw)
In-Reply-To: <20211009013248.1174-5-longpeng2@huawei.com>



On 09/10/2021 04:32, Longpeng(Mike) wrote:
> From: Longpeng <longpeng2@huawei.com>
> 
> Add KUnit tests for the contiguous physical memory regions merging
> functionality from the Nitro Enclaves misc device logic.
> 
> We'll see the following message using dmesg if everything goes well:
> 
> [...]     # Subtest: ne_misc_dev_test
> [...]     1..1
> [...] (NULL device *): Physical mem region address is not 2 MiB aligned
> [...] (NULL device *): Physical mem region size is not multiple of 2 MiB
> [...] (NULL device *): Physical mem region address is not 2 MiB aligned
> [...]     ok 1 - ne_misc_dev_test_merge_phys_contig_memory_regions
> [...] ok 1 - ne_misc_dev_test
> 
> Signed-off-by: Longpeng <longpeng2@huawei.com>
> ---
> Changes v2 -> v3:
>    - 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]
> ---
>   drivers/virt/nitro_enclaves/ne_misc_dev_test.c | 136 +++++++++++++++++++++++++
>   1 file changed, 136 insertions(+)
> 
> diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev_test.c b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c
> index bcb755e..7bd6b34 100644
> --- a/drivers/virt/nitro_enclaves/ne_misc_dev_test.c
> +++ b/drivers/virt/nitro_enclaves/ne_misc_dev_test.c
> @@ -2,7 +2,143 @@
>   
>   #include <kunit/test.h>
>   
> +#define MAX_PHYS_REGIONS	16
> +#define INVALID_VALUE		(~0ull)
> +
> +struct phys_regions_test {
> +	u64 paddr;
> +	u64 size;
> +	int expect_rc;
> +	int expect_num;

Please keep the same field type as "num": "unsigned long".

And just align the field names as mentioned in the first patch of the 
series, so they are easily visualized.

> +	u64 expect_last_paddr;
> +	u64 expect_last_size;
> +} phys_regions_test_cases[] = {
> +	/*
> +	 * Add the region from 0x1000 to (0x1000 + 0x200000 - 1):
> +	 *   Expected result:
> +	 *       Failed, start address is not 2M-aligned
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 0
> +	 *   region = {}
> +	 */
> +	{0x1000, 0x200000, -EINVAL, 0, INVALID_VALUE, INVALID_VALUE},
> +
> +	/*
> +	 * Add the region from 0x200000 to (0x200000 + 0x1000 - 1):
> +	 *   Expected result:
> +	 *       Failed, size is not 2M-aligned
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 0
> +	 *   region = {}
> +	 */
> +	{0x200000, 0x1000, -EINVAL, 0, INVALID_VALUE, INVALID_VALUE},
> +
> +	/*
> +	 * Add the region from 0x200000 to (0x200000 + 0x200000 - 1):
> +	 *   Expected result:
> +	 *       Successful
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 1
> +	 *   region = {
> +	 *       {start=0x200000, end=0x3fffff}, // len=0x200000
> +	 *   }
> +	 */
> +	{0x200000, 0x200000, 0, 1, 0x200000, 0x200000},
> +
> +	/*
> +	 * Add the region from 0x0 to (0x0 + 0x200000 - 1):
> +	 *   Expected result:
> +	 *       Successful
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 2
> +	 *   region = {
> +	 *       {start=0x200000, end=0x3fffff}, // len=0x200000
> +	 *       {start=0x0,      end=0x1fffff}, // len=0x200000
> +	 *   }
> +	 */
> +	{0x0, 0x200000, 0, 2, 0x0, 0x200000},
> +
> +	/*
> +	 * Add the region from 0x600000 to (0x600000 + 0x400000 - 1):
> +	 *   Expected result:
> +	 *       Successful
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 3
> +	 *   region = {
> +	 *       {start=0x200000, end=0x3fffff}, // len=0x200000
> +	 *       {start=0x0,      end=0x1fffff}, // len=0x200000
> +	 *       {start=0x600000, end=0x9fffff}, // len=0x400000
> +	 *   }
> +	 */
> +	{0x600000, 0x400000, 0, 3, 0x600000, 0x400000},
> +
> +	/*
> +	 * Add the region from 0xa00000 to (0xa00000 + 0x400000 - 1):
> +	 *   Expected result:
> +	 *       Successful, merging case!
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 3
> +	 *   region = {
> +	 *       {start=0x200000, end=0x3fffff}, // len=0x200000
> +	 *       {start=0x0,      end=0x1fffff}, // len=0x200000
> +	 *       {start=0x600000, end=0xdfffff}, // len=0x800000
> +	 *   }
> +	 */
> +	{0xa00000, 0x400000, 0, 3, 0x600000, 0x800000},
> +
> +	/*
> +	 * Add the region from 0x1000 to (0x1000 + 0x200000 - 1):
> +	 *   Expected result:
> +	 *       Failed, start address is not 2M-aligned
> +	 *
> +	 * Now the instance of struct phys_contig_mem_regions is:
> +	 *   num = 3
> +	 *   region = {
> +	 *       {start=0x200000, end=0x3fffff}, // len=0x200000
> +	 *       {start=0x0,      end=0x1fffff}, // len=0x200000
> +	 *       {start=0x600000, end=0xdfffff}, // len=0x800000
> +	 *   }
> +	 */
> +	{0x1000, 0x200000, -EINVAL, 3, 0x600000, 0x800000},

Nice, I like how the comments are structured.

Please also update from "region" to "regions" and "struct 
phys_contig_mem_regions" to "ne_phys_contig_mem_regions", after the 
suggested naming changes in the first patch of the series.

> +};
> +
> +static void ne_misc_dev_test_merge_phys_contig_memory_regions(struct kunit *test)
> +{
> +	struct phys_contig_mem_regions *regions;

struct phys_contig_mem_regions *regions; => struct 
ne_phys_contig_mem_regions phys_contig_mem_regions = {};

> +	size_t sz = 0;
> +	int rc = 0;
> +	int i = 0;
> +
> +	sz = sizeof(*regions) + MAX_PHYS_REGIONS * sizeof(struct range);
> +	regions = kunit_kzalloc(test, sz, GFP_KERNEL);

And then can alloc the necessary memory for the "regions" field:

phys_contig_mem_regions.regions = kunit_kcalloc(test, MAX_PHYS_REGIONS, 
sizeof(*phys_contig_mem_regions.regions), GFP_KERNEL);

> +	KUNIT_ASSERT_TRUE(test, regions != NULL);
> +
> +	for (i = 0; i < ARRAY_SIZE(phys_regions_test_cases); i++) {
> +		struct phys_regions_test *entry = phys_regions_test_cases + i;

Could rename "entry" to "test_case".

Can also add:

unsigned long num = 0;

> +
> +		rc = ne_merge_phys_contig_memory_regions(regions,
> +							 entry->paddr, entry->size);

And then can update it here and use it further on:

num = phys_contig_mem_regions.num;

> +		KUNIT_EXPECT_EQ(test, rc, entry->expect_rc);
> +		KUNIT_EXPECT_EQ(test, regions->num, entry->expect_num);
> +
> +		if (entry->expect_last_paddr == INVALID_VALUE)
> +			continue;
> +
> +		KUNIT_EXPECT_EQ(test, regions->region[regions->num - 1].start,
> +				entry->expect_last_paddr);
> +		KUNIT_EXPECT_EQ(test, range_len(&regions->region[regions->num - 1]),
> +				entry->expect_last_size);
> +	}

At the end need to also free the allocated memory for the "regions" 
field using "kunit_free" [1].

[1] 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/kunit/test.h#n631

Thanks,
Andra

> +}
> +
>   static struct kunit_case ne_misc_dev_test_cases[] = {
> +	KUNIT_CASE(ne_misc_dev_test_merge_phys_contig_memory_regions),
>   	{}
>   };
>   
> 



Amazon Development Center (Romania) S.R.L. registered office: 27A Sf. Lazar Street, UBC5, floor 2, Iasi, Iasi County, 700045, Romania. Registered in Romania. Registration number J22/2621/2005.

  reply	other threads:[~2021-10-15 14:29 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-09  1:32 [PATCH v3 0/4] Merge contiguous physical memory regions Longpeng(Mike)
2021-10-09  1:32 ` [PATCH v3 1/4] nitro_enclaves: " Longpeng(Mike)
2021-10-15 13:33   ` Paraschiv, Andra-Irina
2021-11-03 13:54     ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2021-11-03 18:34       ` Paraschiv, Andra-Irina
2021-10-09  1:32 ` [PATCH v3 2/4] nitro_enclaves: Sanity check physical memory regions during merging Longpeng(Mike)
2021-10-15 13:49   ` Paraschiv, Andra-Irina
2021-10-09  1:32 ` [PATCH v3 3/4] nitro_enclaves: Add KUnit tests setup for the misc device functionality Longpeng(Mike)
2021-10-15 13:58   ` Paraschiv, Andra-Irina
2021-10-09  1:32 ` [PATCH v3 4/4] nitro_enclaves: Add KUnit tests for contiguous physical memory regions merging Longpeng(Mike)
2021-10-15 14:28   ` Paraschiv, Andra-Irina [this message]
2021-10-11 15:47 ` [PATCH v3 0/4] Merge contiguous physical memory regions Paraschiv, Andra-Irina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c078d7fd-7c32-8a3a-3958-c0b79a67ddc7@amazon.com \
    --to=andraprs@amazon.com \
    --cc=alcioa@amazon.com \
    --cc=arei.gonglei@huawei.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kamal@canonical.com \
    --cc=lexnv@amazon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longpeng2@huawei.com \
    --cc=ne-devel-upstream@amazon.com \
    --cc=pbonzini@redhat.com \
    --cc=sgarzare@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=vkuznets@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome