Re: [RFC PATCH v4 4/4] selftests/sgx: Add test for madvise(..., WILLNEED)

Huang, Kai
2023-02-15T02:39:08Z

On Fri, 2023-01-27 at 20:55 -0800, Haitao Huang wrote:
> +/*
> + * Compare performance with and without madvise call before EACCEPT'ing
> + * different size of regions.
> + */
> +TEST_F_TIMEOUT(enclave, augment_via_madvise, TIMEOUT_DEFAULT)
> +{
>
[...]

> +
> + for (i = 0; i < self->encl.nr_segments; i++) {
> + struct encl_segment *seg = &self->encl.segment_tbl[i];
> +
> + total_size += seg->size;
> + }
> +
> + for (i = 1; i < 52 && advise_size < max_advise_size; i++) {
> + addr = mmap((void *)self->encl.encl_base + total_size, advise_size,
> +     PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED,
> + self->encl.fd, 0);

I see the problem now. Here 'pgoff' is always 0. I think this is wrong.

Shouldn't you use the actual offset relative to the file as pgoff, which is

total_size >> PAGE_SHIFT

?

[...]

> +     munmap(addr, advise_size);

Incorrect indent here?

Perhaps you should use checkpatch.pl?

> + advise_size = (advise_size << 1UL);
> + }
> + encl_delete(&self->encl);
> +}
> +