All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dixit, Ashutosh" <ashutosh.dixit@intel.com>
To: Umesh Nerlige Ramappa <umesh.nerlige.ramappa@intel.com>
Cc: igt-dev@lists.freedesktop.org,
	Lionel G Landwerlin <lionel.g.landwerlin@intel.com>
Subject: Re: [igt-dev] [PATCH 2/5] i915/perf: Add tests for mapped OA buffer
Date: Mon, 23 Aug 2021 14:31:38 -0700	[thread overview]
Message-ID: <87czq326h1.wl-ashutosh.dixit@intel.com> (raw)
In-Reply-To: <20210803200737.30843-2-umesh.nerlige.ramappa@intel.com>

On Tue, 03 Aug 2021 13:07:34 -0700, Umesh Nerlige Ramappa wrote:
>
> For applications that need a faster way to access reports in the OA
> buffer, i915 now provides a way to map the OA buffer to privileged user
> space. Validate the mapped OA buffer.
>
> v2: Fail on forked-privileged access to mapped oa buffer (Chris)

A few nits/questions below otherwise this is:

Reviewed-by: Ashutosh Dixit <ashutosh.dixit@intel.com>

> diff --git a/include/drm-uapi/i915_drm.h b/include/drm-uapi/i915_drm.h
> index a1c0030c..bb7d5e73 100644
> --- a/include/drm-uapi/i915_drm.h
> +++ b/include/drm-uapi/i915_drm.h
> @@ -2151,6 +2151,39 @@ struct drm_i915_perf_open_param {
>   */
>  #define I915_PERF_IOCTL_CONFIG	_IO('i', 0x2)
>
> +/*
> + * Returns OA buffer properties to be used with mmap.
> + *
> + * This ioctl is available in perf revision 8.
> + */
> +#define I915_PERF_IOCTL_GET_OA_BUFFER_INFO _IOWR('i', 0x3, struct drm_i915_perf_oa_buffer_info)
> +
> +/**
> + * OA buffer size and offset.
> + *
> + * OA output buffer
> + *   type: 0
> + *   flags: mbz
> + *
> + *   After querying the info, pass (size,offset) to mmap(),
> + *
> + *   mmap(0, info.size, PROT_READ, MAP_PRIVATE, perf_fd, info.offset).
> + *
> + *   Note that only a private (not shared between processes, or across fork())
> + *   read-only mmapping is allowed.
> + *
> + *   Userspace must treat the incoming data as tainted, but it conforms to the OA

What does tainted mean?

> diff --git a/tests/i915/perf.c b/tests/i915/perf.c
> index fa3840eb..4d4808ce 100644
> --- a/tests/i915/perf.c
> +++ b/tests/i915/perf.c
> @@ -5156,6 +5156,266 @@ static void test_oa_regs_whitelist(int paranoid)
>	intel_register_access_fini(&mmio_data);
>  }
>
> +#define OA_BUFFER_DATA(tail, head, oa_buffer_size) \
> +	(((tail) - (head)) & ((oa_buffer_size) - 1))
> +
> +#ifndef MAP_FAILED
> +#define MAP_FAILED ((void *)-1)
> +#endif

Shouldn't need this, should just '#include <sys/mman.h>'.

> +static uint32_t oa_status_reg(void)
> +{
> +	uint32_t status;
> +
> +	intel_register_access_init(&mmio_data, intel_get_pci_device(),
> +				   0, drm_fd);
> +	if (IS_HASWELL(devid))
> +		status = intel_register_read(&mmio_data, 0x2346) & 0x7;
> +	else if (IS_GEN12(devid))
> +		status = intel_register_read(&mmio_data, 0xdafc) & 0x7;
> +	else
> +		status = intel_register_read(&mmio_data, 0x2b08) & 0xf;

OK, looks like these can be read directly after they are whitelisted by the
kernel.

> +static void try_invalid_access(void *vaddr)
> +{
> +	sighandler_t old_sigsegv;
> +	uint32_t dummy;
> +
> +	old_sigsegv = signal(SIGSEGV, sigtrap);
> +	switch (sigsetjmp(jmp, SIGSEGV)) {
> +	case SIGSEGV:
> +		break;
> +	case 0:
> +		dummy = READ_ONCE(*((uint32_t *)vaddr + 1));

I would just read vaddr, not (vaddr + 1).

> +static void *map_oa_buffer(uint32_t *size)
> +{
> +	struct drm_i915_perf_oa_buffer_info oa_buffer = { 0 };
> +	void *vaddr;
> +
> +	do_ioctl(stream_fd, I915_PERF_IOCTL_GET_OA_BUFFER_INFO, &oa_buffer);
> +
> +	igt_debug("size        = %llu\n", oa_buffer.size);
> +	igt_debug("offset      = %llx\n", oa_buffer.offset);
> +
> +	igt_assert_eq(oa_buffer.size & (oa_buffer.size - 1), 0);
> +	igt_assert_eq(oa_status_reg(), 0);
> +
> +	vaddr = mmap(0, oa_buffer.size, PROT_READ, MAP_PRIVATE, stream_fd, oa_buffer.offset);
> +	igt_assert(vaddr != NULL);

Should probably be:
	igt_assert(vaddr != MAP_FAILED && vaddr != NULL);

  reply	other threads:[~2021-08-23 21:31 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-03 20:07 [igt-dev] [PATCH 1/5] i915/perf: add tests for triggered OA reports Umesh Nerlige Ramappa
2021-08-03 20:07 ` [igt-dev] [PATCH 2/5] i915/perf: Add tests for mapped OA buffer Umesh Nerlige Ramappa
2021-08-23 21:31   ` Dixit, Ashutosh [this message]
2021-08-24 18:58     ` Umesh Nerlige Ramappa
2021-08-24 19:18       ` Dixit, Ashutosh
2021-08-03 20:07 ` [igt-dev] [PATCH 3/5] lib/i915/perf: Add new record for mmaped " Umesh Nerlige Ramappa
2021-08-03 20:07 ` [igt-dev] [PATCH 4/5] tools/i915-perf: Add mmapped OA buffer support to i915-perf-recorder Umesh Nerlige Ramappa
2021-08-24  1:05   ` Dixit, Ashutosh
2021-08-24 19:14     ` Umesh Nerlige Ramappa
2021-08-24  1:45   ` Dixit, Ashutosh
2021-08-26 23:57     ` Umesh Nerlige Ramappa
2021-08-24  3:50   ` Dixit, Ashutosh
2021-08-24 18:50     ` Umesh Nerlige Ramappa
2021-08-24 19:40       ` Dixit, Ashutosh
2021-08-24 20:03         ` Dixit, Ashutosh
2021-08-03 20:07 ` [igt-dev] [PATCH 5/5] tools/i915-perf: Add a command to trigger a report in OA buffer Umesh Nerlige Ramappa
2021-08-03 20:39 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [1/5] i915/perf: add tests for triggered OA reports Patchwork
2021-08-03 23:21 ` [igt-dev] ✗ GitLab.Pipeline: warning " Patchwork
2021-08-04 20:13 ` [igt-dev] ✓ Fi.CI.IGT: success " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2021-08-30 19:33 [igt-dev] [PATCH 1/5] " Umesh Nerlige Ramappa
2021-08-30 19:33 ` [igt-dev] [PATCH 2/5] i915/perf: Add tests for mapped OA buffer Umesh Nerlige Ramappa

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=87czq326h1.wl-ashutosh.dixit@intel.com \
    --to=ashutosh.dixit@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=lionel.g.landwerlin@intel.com \
    --cc=umesh.nerlige.ramappa@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.