2023-09-14 21:06:57

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] misc: rtsx: Fix an error access Page fault

On Wed, 6 Sept 2023 at 10:03, Ricky WU <[email protected]> wrote:
>
> an error occurs on insert SD7.0 card.
> The pci slot of rtsx_pci will Link Down when the SD7.0 card inserted,
> but the rtsx_pci not exit from runtime_idle at that time,
> then do the power_saving function to access the wrong resource
>
> Fixes: 597568e8df04 ("misc: rtsx: Rework runtime power management flow")
> Cc: Kai-Heng Feng <[email protected]>
> Signed-off-by: Ricky Wu <[email protected]>

Applied for fixes, thanks!

Greg/Arnd, please let me know if you prefer to funnel this via your
trees instead.

Kind regards
Uffe


> ---
> drivers/misc/cardreader/rtsx_pcr.c | 14 ++++++++------
> drivers/mmc/host/rtsx_pci_sdmmc.c | 1 +
> include/linux/rtsx_pci.h | 1 +
> 3 files changed, 10 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/misc/cardreader/rtsx_pcr.c b/drivers/misc/cardreader/rtsx_pcr.c
> index a3f4b52bb159..536a3681fd5e 100644
> --- a/drivers/misc/cardreader/rtsx_pcr.c
> +++ b/drivers/misc/cardreader/rtsx_pcr.c
> @@ -1526,6 +1526,7 @@ static int rtsx_pci_probe(struct pci_dev *pcidev,
> pcr->host_sg_tbl_addr = pcr->rtsx_resv_buf_addr + HOST_CMDS_BUF_LEN;
> pcr->card_inserted = 0;
> pcr->card_removed = 0;
> + pcr->is_sd_express = false;
> INIT_DELAYED_WORK(&pcr->carddet_work, rtsx_pci_card_detect);
>
> pcr->msi_en = msi_en;
> @@ -1735,12 +1736,13 @@ static int rtsx_pci_runtime_idle(struct device *device)
>
> pcr->state = PDEV_STAT_IDLE;
>
> - if (pcr->ops->disable_auto_blink)
> - pcr->ops->disable_auto_blink(pcr);
> - if (pcr->ops->turn_off_led)
> - pcr->ops->turn_off_led(pcr);
> -
> - rtsx_pm_power_saving(pcr);
> + if (!pcr->is_sd_express) {
> + if (pcr->ops->disable_auto_blink)
> + pcr->ops->disable_auto_blink(pcr);
> + if (pcr->ops->turn_off_led)
> + pcr->ops->turn_off_led(pcr);
> + rtsx_pm_power_saving(pcr);
> + }
>
> mutex_unlock(&pcr->pcr_mutex);
>
> diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c
> index 87d78432a1e0..80b2f2a31fdc 100644
> --- a/drivers/mmc/host/rtsx_pci_sdmmc.c
> +++ b/drivers/mmc/host/rtsx_pci_sdmmc.c
> @@ -1393,6 +1393,7 @@ static int sdmmc_init_sd_express(struct mmc_host *mmc, struct mmc_ios *ios)
> RTS5261_MCU_BUS_SEL_MASK | RTS5261_MCU_CLOCK_SEL_MASK
> | RTS5261_DRIVER_ENABLE_FW,
> RTS5261_MCU_CLOCK_SEL_16M | RTS5261_DRIVER_ENABLE_FW);
> + pcr->is_sd_express = true;
> host->eject = true;
> return 0;
> }
> diff --git a/include/linux/rtsx_pci.h b/include/linux/rtsx_pci.h
> index 534038d962e4..295e92224fd0 100644
> --- a/include/linux/rtsx_pci.h
> +++ b/include/linux/rtsx_pci.h
> @@ -1262,6 +1262,7 @@ struct rtsx_pcr {
> u8 ocp_stat;
> u8 ocp_stat2;
> u8 rtd3_en;
> + bool is_sd_express;
> };
>
> #define PID_524A 0x524A
> --
> 2.25.1
>


2023-09-26 22:00:48

by Ulf Hansson

[permalink] [raw]
Subject: Re: [PATCH] misc: rtsx: Fix an error access Page fault

On Thu, 14 Sept 2023 at 16:47, Ulf Hansson <[email protected]> wrote:
>
> On Wed, 6 Sept 2023 at 10:03, Ricky WU <[email protected]> wrote:
> >
> > an error occurs on insert SD7.0 card.
> > The pci slot of rtsx_pci will Link Down when the SD7.0 card inserted,
> > but the rtsx_pci not exit from runtime_idle at that time,
> > then do the power_saving function to access the wrong resource
> >
> > Fixes: 597568e8df04 ("misc: rtsx: Rework runtime power management flow")
> > Cc: Kai-Heng Feng <[email protected]>
> > Signed-off-by: Ricky Wu <[email protected]>
>
> Applied for fixes, thanks!

This was not ready to be applied, my bad! Fortunately, I haven't
submitted a pull-request with this yet, so I am simply dropping the
patch for now, to make sure we find the proper solution.

[...]

Kind regards
Uffe

2023-10-06 05:01:02

by Kai-Heng Feng

[permalink] [raw]
Subject: Re: [PATCH] misc: rtsx: Fix an error access Page fault

Ricky,

On Tue, Sep 26, 2023 at 11:04 PM Ulf Hansson <[email protected]> wrote:
>
> On Thu, 14 Sept 2023 at 16:47, Ulf Hansson <[email protected]> wrote:
> >
> > On Wed, 6 Sept 2023 at 10:03, Ricky WU <[email protected]> wrote:
> > >
> > > an error occurs on insert SD7.0 card.
> > > The pci slot of rtsx_pci will Link Down when the SD7.0 card inserted,
> > > but the rtsx_pci not exit from runtime_idle at that time,
> > > then do the power_saving function to access the wrong resource
> > >
> > > Fixes: 597568e8df04 ("misc: rtsx: Rework runtime power management flow")
> > > Cc: Kai-Heng Feng <[email protected]>
> > > Signed-off-by: Ricky Wu <[email protected]>
> >
> > Applied for fixes, thanks!
>
> This was not ready to be applied, my bad! Fortunately, I haven't
> submitted a pull-request with this yet, so I am simply dropping the
> patch for now, to make sure we find the proper solution.

Can you please see if the following change helps:

diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
index ad12515a4a121..89480e31c2266 100644
--- a/drivers/pci/hotplug/pciehp_pci.c
+++ b/drivers/pci/hotplug/pciehp_pci.c
@@ -18,9 +18,18 @@
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/pci.h>
+#include <linux/pm_runtime.h>
#include "../pci.h"
#include "pciehp.h"

+int pciehp_pm_runtime_barrier(struct pci_dev *pdev, void *unused)
+{
+ pm_runtime_barrier(&pdev->dev);
+ pci_dev_set_disconnected(pdev, NULL);
+
+ return 0;
+}
+
/**
* pciehp_configure_device() - enumerate PCI devices below a hotplug bridge
* @ctrl: PCIe hotplug controller
@@ -98,7 +107,7 @@ void pciehp_unconfigure_device(struct controller
*ctrl, bool presence)
__func__, pci_domain_nr(parent), parent->number);

if (!presence)
- pci_walk_bus(parent, pci_dev_set_disconnected, NULL);
+ pci_walk_bus(parent, pciehp_pm_runtime_barrier, NULL);

pci_lock_rescan_remove();


>
> [...]
>
> Kind regards
> Uffe

2023-10-11 03:23:24

by Ricky Wu

[permalink] [raw]
Subject: RE: [PATCH] misc: rtsx: Fix an error access Page fault

Hi Kai-Heng,

I finished testing this patch it's working fine, re-plug card many time don't see the issue reproduce
I think this patch can fix the problem
thank you

Tested-by: Ricky Wu <[email protected]>

> Ricky,
>
> On Tue, Sep 26, 2023 at 11:04 PM Ulf Hansson <[email protected]>
> wrote:
> >
> > On Thu, 14 Sept 2023 at 16:47, Ulf Hansson <[email protected]> wrote:
> > >
> > > On Wed, 6 Sept 2023 at 10:03, Ricky WU <[email protected]> wrote:
> > > >
> > > > an error occurs on insert SD7.0 card.
> > > > The pci slot of rtsx_pci will Link Down when the SD7.0 card
> > > > inserted, but the rtsx_pci not exit from runtime_idle at that
> > > > time, then do the power_saving function to access the wrong
> > > > resource
> > > >
> > > > Fixes: 597568e8df04 ("misc: rtsx: Rework runtime power management
> > > > flow")
> > > > Cc: Kai-Heng Feng <[email protected]>
> > > > Signed-off-by: Ricky Wu <[email protected]>
> > >
> > > Applied for fixes, thanks!
> >
> > This was not ready to be applied, my bad! Fortunately, I haven't
> > submitted a pull-request with this yet, so I am simply dropping the
> > patch for now, to make sure we find the proper solution.
>
> Can you please see if the following change helps:
>
> diff --git a/drivers/pci/hotplug/pciehp_pci.c b/drivers/pci/hotplug/pciehp_pci.c
> index ad12515a4a121..89480e31c2266 100644
> --- a/drivers/pci/hotplug/pciehp_pci.c
> +++ b/drivers/pci/hotplug/pciehp_pci.c
> @@ -18,9 +18,18 @@
> #include <linux/kernel.h>
> #include <linux/types.h>
> #include <linux/pci.h>
> +#include <linux/pm_runtime.h>
> #include "../pci.h"
> #include "pciehp.h"
>
> +int pciehp_pm_runtime_barrier(struct pci_dev *pdev, void *unused) {
> + pm_runtime_barrier(&pdev->dev);
> + pci_dev_set_disconnected(pdev, NULL);
> +
> + return 0;
> +}
> +
> /**
> * pciehp_configure_device() - enumerate PCI devices below a hotplug
> bridge
> * @ctrl: PCIe hotplug controller
> @@ -98,7 +107,7 @@ void pciehp_unconfigure_device(struct controller *ctrl,
> bool presence)
> __func__, pci_domain_nr(parent), parent->number);
>
> if (!presence)
> - pci_walk_bus(parent, pci_dev_set_disconnected, NULL);
> + pci_walk_bus(parent, pciehp_pm_runtime_barrier, NULL);
>
> pci_lock_rescan_remove();
>
>
> >
> > [...]
> >
> > Kind regards
> > Uffe