All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Himal Prasad Ghimiray" <himal.prasad.ghimiray@intel.com>
Cc: intel-xe@lists.freedesktop.org
Subject: Re: [RFC v2 13/21] drm/xe: Add xe_guc_access_counter layer
Date: Wed, 09 Sep 2026 12:54:24 +0000	[thread overview]
Message-ID: <20260909125424.E1DCC1F00ADF@smtp.kernel.org> (raw)
In-Reply-To: <20260909124457.1610890-36-himal.prasad.ghimiray@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Incorrect address computation in `xe_guc_access_counter_page_va` causes middle bits of the virtual address to be lost and shifts the tracking window improperly.
- [High] Handling a G2H access counter notification when the USM feature is disabled causes a kernel crash due to an uninitialized spinlock and a NULL pointer dereference.
--

commit 94395d3f68cfb99d219c20819de2d7f8aae519a8
Author: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>

    drm/xe: Add xe_guc_access_counter layer
    
    Add GuC to host (G2H) access counter notification handler to parse
    GuC firmware messages into struct xe_access_counter and forward to
    xe_access_counter_handler for processing.

> diff --git a/drivers/gpu/drm/xe/xe_guc_access_counter.c b/drivers/gpu/drm/xe/xe_guc_access_counter.c
> new file mode 100644
> index 0000000000000..7e9b835e1ed67
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_guc_access_counter.c
> @@ -0,0 +1,74 @@
[ ... ]
> +static u64 xe_guc_access_counter_page_va(struct xe_device *xe, u64 addr, u8 gran)
> +{
> +	u64 gran_size = xe_access_counter_granularity_to_size(gran);
> +	u64 sub_gran_size = gran_size / 32;
> +	u64 region_base = ALIGN_DOWN(addr, gran_size);
> +	u64 offset_in_subchunk = addr & (sub_gran_size - 1);
> +	u64 page_va = region_base + offset_in_subchunk;

[Severity: High]
Does this logic compute the correct virtual address? 

By adding offset_in_subchunk (which only keeps the lowest log2(sub_gran_size)
bits) to region_base (which clears the lower log2(gran_size) bits), any bits
between sub_gran_size and gran_size are completely discarded.

> +
> +	xe_dbg(xe, "gran_size = %llx, addr = = %llx, region_base = %llx, page_va=%llx\n",
> +	       gran_size, addr, region_base, page_va);
> +	return page_va;
> +}
> +
> +/**
> + * xe_guc_access_counter_handler() - G2H access counter handler
[ ... ]
> +	addr = ((u64)(msg[3] & ACC_VIRTUAL_ADDR_RANGE_HI) << 32) |
> +		(msg[2] & ACC_VIRTUAL_ADDR_RANGE_LO);
> +	ac.consumer.page_va = xe_guc_access_counter_page_va(xe, addr, ac.consumer.granularity);
> +	ac.gran_end = ac.consumer.page_va +
> +		      xe_access_counter_granularity_to_size(ac.consumer.granularity);

[Severity: High]
If the page_va computation is missing the middle bits of the address, does this
also cause gran_end to be misaligned? This could improperly shift the tracking
window and cause incorrect VMA lookups.

> +	ac.consumer.asid = FIELD_GET(ACC_ASID, msg[1]);
> +	ac.consumer.engine_class = FIELD_GET(ACC_ENG_CLASS, msg[1]);
> +	ac.consumer.engine_instance = FIELD_GET(ACC_ENG_INSTANCE, msg[1]);
> +	ac.consumer.vfid = FIELD_GET(ACC_VFID, msg[2]);
> +#undef GUC_ACC_MSG_LEN_DW
> +
> +	return xe_access_counter_handler(xe, &ac);

[Severity: High]
Is it safe to unconditionally forward this message to the access counter backend?

If the system is initialized with has_usm == false, the access counter queue
is not fully initialized. Receiving an unexpected access counter notification
message from the GuC could lead to:

drivers/gpu/drm/xe/xe_access_counter.c:xe_access_counter_handler() {
    ...
    spin_lock_irqsave(&ac_queue->lock, flags);
    ...
    xe_usm_queue_push(ac_queue, ac);
    ...
}

Attempting to acquire an uninitialized spinlock, followed by a NULL pointer
dereference of ac_queue->data in xe_usm_queue_push(). Should we verify if the
feature is supported before processing the notification?

> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260909124457.1610890-23-himal.prasad.ghimiray@intel.com?part=13

  reply	other threads:[~2026-09-09 12:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-09 12:44 [RFC v2 00/21] drm/xe: Access counter support for migration hints Himal Prasad Ghimiray
2026-09-09 12:44 ` [RFC v2 01/21] drm/xe: Add xe_usm_queue generic USM circular buffer Himal Prasad Ghimiray
2026-09-09 12:51   ` sashiko-bot
2026-09-09 12:44 ` [RFC v2 02/21] drm/xe: Stub out new access_counter layer Himal Prasad Ghimiray
2026-09-09 12:44 ` [RFC v2 03/21] drm/xe: Implement xe_access_counter_init Himal Prasad Ghimiray
2026-09-09 12:55   ` sashiko-bot
2026-09-09 12:44 ` [RFC v2 04/21] drm/xe: Implement xe_access_counter_handler Himal Prasad Ghimiray
2026-09-09 12:58   ` sashiko-bot
2026-09-09 12:44 ` [RFC v2 05/21] drm/xe: Extract xe_vma_lock_and_validate helper Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 06/21] drm/xe: Move ASID to FAULT VM lookup to xe_device Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 07/21] drm/xe/pf: Use xe_device_asid_to_vm in xe_pagefault_save_to_vm Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 08/21] drm/xe: Implement xe_access_counter_queue_work Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 09/21] drm/xe: Implement xe_access_counter_service Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 10/21] drm/xe/trace: Add xe_vma_acc trace event for access counter notifications Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 11/21] drm/xe/svm: Handle svm vma for acc_ctr trigger Himal Prasad Ghimiray
2026-09-09 12:52   ` sashiko-bot
2026-09-09 12:45 ` [RFC v2 12/21] drm/xe: Service all VMAs in an access counter granularity window Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 13/21] drm/xe: Add xe_guc_access_counter layer Himal Prasad Ghimiray
2026-09-09 12:54   ` sashiko-bot [this message]
2026-09-09 12:45 ` [RFC v2 14/21] drm/xe/uapi: Add access counter parameter extension for exec queue Himal Prasad Ghimiray
2026-09-09 12:52   ` sashiko-bot
2026-09-09 12:45 ` [RFC v2 15/21] drm/xe/lrc: Pass exec_queue to xe_lrc_create for access counter params Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 16/21] drm/xe/vm: Add xe_vma_supports_access_ctr() helper Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 17/21] drm/xe/pt: Set NC PTE bit for VMAs ineligible for access counting Himal Prasad Ghimiray
2026-09-09 12:56   ` sashiko-bot
2026-09-09 12:45 ` [RFC v2 18/21] drm/xe/svm: Define access counter migration policy Himal Prasad Ghimiray
2026-09-09 13:01   ` sashiko-bot
2026-09-09 12:45 ` [RFC v2 19/21] drm/xe/svm: Add MIGRATE_ON_ACCESS_COUNTER bind flag Himal Prasad Ghimiray
2026-09-09 12:57   ` sashiko-bot
2026-09-09 12:45 ` [RFC v2 20/21] drm/xe/svm: Move EVICTED PAGES debug log to callers Himal Prasad Ghimiray
2026-09-09 12:45 ` [RFC v2 21/21] drm/xe/svm: Distinguish access-counter-triggered range setup in logs Himal Prasad Ghimiray
2026-09-09 12:58   ` sashiko-bot

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=20260909125424.E1DCC1F00ADF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.