From: Tabby Kitten <nyanpasu256@gmail.com>
To: Adrian Hunter <adrian.hunter@intel.com>,
Ulf Hansson <ulf.hansson@linaro.org>,
ricky_wu@realtek.com
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: rtsx_pci_sdmmc aborts suspend when /sys/power/wakeup_count is enabled
Date: Thu, 8 Jan 2026 18:46:02 -0800 [thread overview]
Message-ID: <b488f3d6-68bc-49ac-8cb3-0f9f05f41020@gmail.com> (raw)
In-Reply-To: <f91584df-eee3-4c26-b1da-a8049a4d77bd@intel.com>
On 1/5/26 4:31 AM, Adrian Hunter wrote:
> Seems reasonable, but isn't there also:
> bus_ops->suspend() == mmc_sd_suspend()
> _mmc_sd_suspend()
> mmc_claim_host(host)
>
> In general, it looks difficult to avoid runtime resume on
> the suspend path. PCI will usually runtime resume anyway
> i.e. from pci_pm_suspend():
>
> /*
> * PCI devices suspended at run time may need to be resumed at this
> * point, because in general it may be necessary to reconfigure them for
> * system suspend. Namely, if the device is expected to wake up the
> * system from the sleep state, it may have to be reconfigured for this
> * purpose, or if the device is not expected to wake up the system from
> * the sleep state, it should be prevented from signaling wakeup events
> * going forward.
> *
> * Also if the driver of the device does not indicate that its system
> * suspend callbacks can cope with runtime-suspended devices, it is
> * better to resume the device from runtime suspend here.
> */
> if (!dev_pm_smart_suspend(dev) || pci_dev_need_resume(pci_dev)) {
> pm_runtime_resume(dev);
>
> So maybe alter rtsx_pci_runtime_resume() to avoid calling
> pcr->slots[RTSX_SD_CARD].card_event() == rtsx_pci_sdmmc_card_event()
> when suspending. Perhaps along the lines of the hack below:
>
> static int rtsx_pci_runtime_resume(struct device *device)
> {
> struct pci_dev *pcidev = to_pci_dev(device);
> struct pcr_handle *handle = pci_get_drvdata(pcidev);
> struct rtsx_pcr *pcr = handle->pcr;
>
> dev_dbg(device, "--> %s\n", __func__);
>
> mutex_lock(&pcr->pcr_mutex);
>
> rtsx_pci_write_register(pcr, HOST_SLEEP_STATE, 0x03, 0x00);
>
> rtsx_pci_init_hw(pcr);
>
> if (pcr->slots[RTSX_SD_CARD].p_dev != NULL) {
> +#if IS_ENABLED(CONFIG_SUSPEND)
> + if (pm_suspend_target_state == PM_SUSPEND_ON)
> +#endif
> pcr->slots[RTSX_SD_CARD].card_event(
> pcr->slots[RTSX_SD_CARD].p_dev);
> }
>
> mutex_unlock(&pcr->pcr_mutex);
> return 0;
> }
>
>> WIP
>>
>> Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
>> ---
>> drivers/mmc/core/core.c | 18 ++++++++++++------
>> drivers/mmc/core/core.h | 11 ++++++++---
>> drivers/mmc/core/queue.c | 4 ++--
>> drivers/mmc/core/sdio_irq.c | 2 +-
>> 4 files changed, 23 insertions(+), 12 deletions(-)
>>
>> ...
Me earlier:
> I'm attemping to manually replicate the changes on Fedora 43's
> kernel-6.18.3 checkout
> (https://docs.fedoraproject.org/en-US/quick-docs/kernel-build-custom/),
> though I'm much less experienced building kernels here than on Arch
> Linux (the Arch SSD is currently in another computer). I will be
> replying back with results once I can build and test these patches.
I've built a test kernel based on Fedora's 6.18.3 along with these two
patches. Now `sudo badsleep.sh` successfully completes on the machine
with the Realtek card reader.
* Adrian's code would not compile until I edited
drivers/misc/cardreader/rtsx_pcr.c and added #include <linux/suspend.h>.
* It looks a bit janky that the inner line of code is tied to a
different natural indentation level based on a compile-time flag.
With suspend enabled, the function call is on the same indentation
level as the if statement!
o One possibility is to indent the inner code one more level
(which is an extraneous indentation if the #if is inactive)
o Another is to move the added condition into the surrounding `if
(pcr->slots[RTSX_SD_CARD].p_dev != NULL)`, but this prevents us
from adding code that /doesn't/ check pm_suspend_target_state.
I ran into a possible bug:
* On my first boot attempt, I tried running badsleep.sh, waking the
system, and inserted a microSD card. The card was not recognized in
Dolphin or listed in lsblk. rtsx_pci_sdmmc was present in lsmod, and
I saw no references to rtsx or mmc in the journal.
* I could not reproduce this error on subsequent boots. I rebooted the
computer, then tried badsleep.sh (with or without regular KDE sleep
beforehand), then inserted the microSD card. At this point it was
recognized properly. I also tried inserting the card /while/ the
system was asleep, which worked too. I'm not sure why it failed the
first time... dirty contacts? random bug?
next prev parent reply other threads:[~2026-01-09 2:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-26 9:08 Tabby Kitten
2025-12-09 15:08 ` Ulf Hansson
2026-01-01 5:11 ` Tabby Kitten
[not found] ` <CAL57YxZagMaZF1X1bpx-nB76s=vZMWhUDiVbvB9P3CLiXG-qHQ@mail.gmail.com>
2026-01-03 11:12 ` Ulf Hansson
2026-01-05 12:31 ` Adrian Hunter
2026-01-09 2:46 ` Tabby Kitten [this message]
2026-01-12 7:39 ` Adrian Hunter
2026-01-07 22:06 ` Tabby Kitten
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=b488f3d6-68bc-49ac-8cb3-0f9f05f41020@gmail.com \
--to=nyanpasu256@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ricky_wu@realtek.com \
--cc=ulf.hansson@linaro.org \
/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
all inboxes | Powered by JetHome®