Linux SCSI subsystem development
 help / color / mirror / Atom feed
From: "Peter Wang (王信友)" <peter.wang@mediatek.com>
To: "sashiko-reviews@lists.linux.dev" <sashiko-reviews@lists.linux.dev>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: Re: [PATCH v2 2/2] ufs: serialize AHIT register access between sysfs and host driver
Date: Mon, 14 Sep 2026 12:44:29 +0000	[thread overview]
Message-ID: <d20fabf29c8e3609abfbf7364bb46b11bba994a8.camel@mediatek.com> (raw)
In-Reply-To: <20260914091357.489F01F000FF@smtp.kernel.org>

On Mon, 2026-09-14 at 09:13 +0000, sashiko-bot@kernel.org wrote:
> [Severity: High]
> This isn't a bug introduced by this patch, but can this dereference a
> NULL pointer?
> 
> Sysfs attributes are exposed in ufshcd_init() via
> ufs_sysfs_add_nodes()
> before hba->ufs_device_wlun is allocated.  The initialization is
> deferred
> to the ufshcd_async_scan worker.
> 
> If a user writes to the sysfs node before ufshcd_add_lus() allocates
> hba->ufs_device_wlun, can auto_hibern8_store() call
> ufshcd_auto_hibern8_update() and locklessly dereference a NULL
> pointer here?
> 

This patch focuses on the current issue.
The previous issue can be addressed with a separate patch, 
but not with this one.

> >  		ufshcd_rpm_get_sync(hba);
> 
> [Severity: High]
> This is a pre-existing issue, but is it safe to ignore the return
> value
> of ufshcd_rpm_get_sync() here?
> 
> If the runtime PM resume fails (e.g., due to a power domain failure
> or
> device removal), pm_runtime_get_sync() returns a negative error code.
> 
> Does ignoring this error allow the function to proceed and write to
> REG_AUTO_HIBERNATE_IDLE_TIMER on a potentially suspended device,
> causing a
> synchronous external abort?
> 

Same, pre-existing issue should be addressed with a separate patch.


> >  		ufshcd_hold(hba);
> > -		ufshcd_configure_auto_hibern8(hba);
> > +		/*
> > +		 * Serialize with the host driver's AHIT control.
> > Skip the
> > +		 * register write while the driver has AHIT forced
> > off; the
> > +		 * driver programs hba->ahit back when it re-
> > enables it.
> > +		 * Mutex is taken here (not across the rpm calls
> > above) so it
> > +		 * never blocks a resume that the driver's path
> > may need.
> > +		 */
> > +		mutex_lock(&hba->ahit_mutex);
> > +		if (!hba->ahit_disable_depth)
> > +			ufshcd_configure_auto_hibern8(hba);
> > +		mutex_unlock(&hba->ahit_mutex);
> >  		ufshcd_release(hba);
> >  		ufshcd_rpm_put_sync(hba);
> >  	}
> 
> [ ... ]
> 
> [Severity: High]
> This is a pre-existing issue, but does the UFS core driver handle
> shared
> IRQs correctly?
> 

Same, pre-existing issue should be addressed with a separate patch.


> The driver registers its IRQ with IRQF_SHARED. When the UFS
> controller enters
> runtime suspend, ufshcd_suspend() disables the interrupt line
> entirely:
> 
> drivers/ufs/core/ufshcd.c:ufshcd_suspend() {
>     ...
> 	ufshcd_disable_irq(hba);
>     ...
> }
> 
> Does calling disable_irq() mask interrupts for any other devices
> sharing the
> line? Should this use synchronize_irq() instead?
> 
> Additionally, ufshcd_intr() reads the hardware register
> unconditionally:
> 
> drivers/ufs/core/ufshcd.c:ufshcd_intr() {
>     ...
> 	last_intr_status = intr_status = ufshcd_readl(hba,
> REG_INTERRUPT_STATUS);
>     ...
> }
> 
> Can this access powered-off hardware if the interrupt belongs to
> another
> device on the same shared line? Should this verify the device is
> actively
> powered using pm_runtime_get_if_active() before accessing registers?
> 


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

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-14  8:49 [PATCH v2 0/2] ufs: fix POST_CHANGE pairing and AHIT race condition peter.wang
2026-09-14  8:49 ` [PATCH v2 1/2] ufs: always notify POST_CHANGE even on gear switch failure peter.wang
2026-09-14  9:02   ` sashiko-bot
2026-09-14 12:42     ` Peter Wang (王信友)
2026-09-14  8:49 ` [PATCH v2 2/2] ufs: serialize AHIT register access between sysfs and host driver peter.wang
2026-09-14  9:13   ` sashiko-bot
2026-09-14 12:44     ` Peter Wang (王信友) [this message]
2026-09-22 10:06 ` [PATCH v2 0/2] ufs: fix POST_CHANGE pairing and AHIT race condition chun-hung.wu
2026-09-26  2:30 ` Martin K. Petersen (Oracle)
2026-10-05 15:45   ` Sandeep Dhavale
2026-10-06  2:42     ` Martin K. Petersen
2026-10-06  2:44 ` Martin K. Petersen (Oracle)

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=d20fabf29c8e3609abfbf7364bb46b11bba994a8.camel@mediatek.com \
    --to=peter.wang@mediatek.com \
    --cc=linux-scsi@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox