linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Do not flush cache when it is disabled
@ 2021-04-20 13:46 Avri Altman
  2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Avri Altman @ 2021-04-20 13:46 UTC (permalink / raw)
  To: Ulf Hansson, linux-mmc, Adrian Hunter; +Cc: linux-kernel, Avri Altman

v3 -> v4
 - Attend Adrian's comments
 - Add Acked-by tag

v2 -> v3:
 - rebase onto recent cache changes

v1 -> v2:
 - Attend Adrian's comments

Cache is a temporary storage space in an eMMC device. Volatile by
nature, the cache should in typical case reduce the access time compared
to an access to the main nonvolatile storage.

The cache function can be turned ON and OFF. Once OFF, the host is not
expected to issue a flush-cache command to the device.

Avri Altman (2):
  mmc: block: Issue flush only if allowed
  mmc: block: Update ext_csd.cache_ctrl if it was written

 drivers/mmc/core/block.c   | 21 +++++++++++++++++++++
 drivers/mmc/core/mmc.c     |  2 +-
 drivers/mmc/core/mmc_ops.h |  5 +++++
 3 files changed, 27 insertions(+), 1 deletion(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v4 1/2] mmc: block: Issue flush only if allowed
  2021-04-20 13:46 [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
@ 2021-04-20 13:46 ` Avri Altman
  2021-04-20 14:02   ` Adrian Hunter
  2021-04-23  8:14   ` Ulf Hansson
  2021-04-20 13:46 ` [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written Avri Altman
  2021-04-22  9:41 ` [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
  2 siblings, 2 replies; 8+ messages in thread
From: Avri Altman @ 2021-04-20 13:46 UTC (permalink / raw)
  To: Ulf Hansson, linux-mmc, Adrian Hunter
  Cc: linux-kernel, Avri Altman, Brendan Peter

The cache may be flushed to the nonvolatile storage by writing to
FLUSH_CACHE byte (EXT_CSD byte [32]). When in command queueing mode, the
cache may be flushed by issuing a CMDQ_TASK_ DEV_MGMT (CMD48) with a
FLUSH_CACHE op-code.  Either way, verify that The cache function is
turned ON before doing so.

fixes: 1e8e55b67030 (mmc: block: Add CQE support)

Reported-by: Brendan Peter <bpeter@lytx.com>
Tested-by: Brendan Peter <bpeter@lytx.com>
Signed-off-by: Avri Altman <avri.altman@wdc.com>
---
 drivers/mmc/core/block.c   | 9 +++++++++
 drivers/mmc/core/mmc.c     | 2 +-
 drivers/mmc/core/mmc_ops.h | 5 +++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 8bfd4d95b386..24e1ecbdd510 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -2186,6 +2186,11 @@ static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host)
 	return mmc_blk_rw_wait(mq, NULL);
 }
 
+static bool mmc_blk_cache_disabled(struct mmc_card *card)
+{
+	return mmc_card_mmc(card) && !mmc_flush_allowed(card);
+}
+
 enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
 {
 	struct mmc_blk_data *md = mq->blkdata;
@@ -2225,6 +2230,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
 	case MMC_ISSUE_ASYNC:
 		switch (req_op(req)) {
 		case REQ_OP_FLUSH:
+			if (mmc_blk_cache_disabled(mq->card)) {
+				blk_mq_end_request(req, BLK_STS_OK);
+				return MMC_REQ_FINISHED;
+			}
 			ret = mmc_blk_cqe_issue_flush(mq, req);
 			break;
 		case REQ_OP_READ:
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index 9ad4aa537867..e3da62ffcb5e 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -2037,7 +2037,7 @@ static int _mmc_flush_cache(struct mmc_card *card)
 {
 	int err = 0;
 
-	if (card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1) {
+	if (mmc_flush_allowed(card)) {
 		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
 				 EXT_CSD_FLUSH_CACHE, 1,
 				 CACHE_FLUSH_TIMEOUT_MS);
diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
index 5782fdf4e8e9..2682bf66708a 100644
--- a/drivers/mmc/core/mmc_ops.h
+++ b/drivers/mmc/core/mmc_ops.h
@@ -19,6 +19,11 @@ enum mmc_busy_cmd {
 struct mmc_host;
 struct mmc_card;
 
+static inline bool mmc_flush_allowed(struct mmc_card *card)
+{
+	return card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1;
+}
+
 int mmc_select_card(struct mmc_card *card);
 int mmc_deselect_cards(struct mmc_host *host);
 int mmc_set_dsr(struct mmc_host *host);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written
  2021-04-20 13:46 [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
  2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
@ 2021-04-20 13:46 ` Avri Altman
  2021-04-23  8:14   ` Ulf Hansson
  2021-04-22  9:41 ` [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
  2 siblings, 1 reply; 8+ messages in thread
From: Avri Altman @ 2021-04-20 13:46 UTC (permalink / raw)
  To: Ulf Hansson, linux-mmc, Adrian Hunter; +Cc: linux-kernel, Avri Altman

The cache function can be turned ON and OFF by writing to the CACHE_CTRL
byte (EXT_CSD byte [33]).  However,  card->ext_csd.cache_ctrl is only
set on init if cache size > 0.

Fix that by explicitly setting ext_csd.cache_ctrl on ext-csd write.

Signed-off-by: Avri Altman <avri.altman@wdc.com>
Acked-by: Adrian Hunter <adrian.hunter@intel.com>
---
 drivers/mmc/core/block.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
index 24e1ecbdd510..7e70f11e85e2 100644
--- a/drivers/mmc/core/block.c
+++ b/drivers/mmc/core/block.c
@@ -572,6 +572,18 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
 		main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
 	}
 
+	/*
+	 * Make sure to update CACHE_CTRL in case it was changed. The cache
+	 * will get turned back on if the card is re-initialized, e.g.
+	 * suspend/resume or hw reset in recovery.
+	 */
+	if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_CACHE_CTRL) &&
+	    (cmd.opcode == MMC_SWITCH)) {
+		u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg) & 1;
+
+		card->ext_csd.cache_ctrl = value;
+	}
+
 	/*
 	 * According to the SD specs, some commands require a delay after
 	 * issuing the command.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/2] mmc: block: Issue flush only if allowed
  2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
@ 2021-04-20 14:02   ` Adrian Hunter
  2021-04-23  8:14   ` Ulf Hansson
  1 sibling, 0 replies; 8+ messages in thread
From: Adrian Hunter @ 2021-04-20 14:02 UTC (permalink / raw)
  To: Avri Altman, Ulf Hansson, linux-mmc; +Cc: linux-kernel, Brendan Peter

On 20/04/21 4:46 pm, Avri Altman wrote:
> The cache may be flushed to the nonvolatile storage by writing to
> FLUSH_CACHE byte (EXT_CSD byte [32]). When in command queueing mode, the
> cache may be flushed by issuing a CMDQ_TASK_ DEV_MGMT (CMD48) with a
> FLUSH_CACHE op-code.  Either way, verify that The cache function is
> turned ON before doing so.
> 
> fixes: 1e8e55b67030 (mmc: block: Add CQE support)
> 
> Reported-by: Brendan Peter <bpeter@lytx.com>
> Tested-by: Brendan Peter <bpeter@lytx.com>
> Signed-off-by: Avri Altman <avri.altman@wdc.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/core/block.c   | 9 +++++++++
>  drivers/mmc/core/mmc.c     | 2 +-
>  drivers/mmc/core/mmc_ops.h | 5 +++++
>  3 files changed, 15 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 8bfd4d95b386..24e1ecbdd510 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -2186,6 +2186,11 @@ static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host)
>  	return mmc_blk_rw_wait(mq, NULL);
>  }
>  
> +static bool mmc_blk_cache_disabled(struct mmc_card *card)
> +{
> +	return mmc_card_mmc(card) && !mmc_flush_allowed(card);
> +}
> +
>  enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
>  {
>  	struct mmc_blk_data *md = mq->blkdata;
> @@ -2225,6 +2230,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
>  	case MMC_ISSUE_ASYNC:
>  		switch (req_op(req)) {
>  		case REQ_OP_FLUSH:
> +			if (mmc_blk_cache_disabled(mq->card)) {
> +				blk_mq_end_request(req, BLK_STS_OK);
> +				return MMC_REQ_FINISHED;
> +			}
>  			ret = mmc_blk_cqe_issue_flush(mq, req);
>  			break;
>  		case REQ_OP_READ:
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index 9ad4aa537867..e3da62ffcb5e 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -2037,7 +2037,7 @@ static int _mmc_flush_cache(struct mmc_card *card)
>  {
>  	int err = 0;
>  
> -	if (card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1) {
> +	if (mmc_flush_allowed(card)) {
>  		err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
>  				 EXT_CSD_FLUSH_CACHE, 1,
>  				 CACHE_FLUSH_TIMEOUT_MS);
> diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
> index 5782fdf4e8e9..2682bf66708a 100644
> --- a/drivers/mmc/core/mmc_ops.h
> +++ b/drivers/mmc/core/mmc_ops.h
> @@ -19,6 +19,11 @@ enum mmc_busy_cmd {
>  struct mmc_host;
>  struct mmc_card;
>  
> +static inline bool mmc_flush_allowed(struct mmc_card *card)
> +{
> +	return card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1;
> +}
> +
>  int mmc_select_card(struct mmc_card *card);
>  int mmc_deselect_cards(struct mmc_host *host);
>  int mmc_set_dsr(struct mmc_host *host);
> 


^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v4 0/2] Do not flush cache when it is disabled
  2021-04-20 13:46 [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
  2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
  2021-04-20 13:46 ` [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written Avri Altman
@ 2021-04-22  9:41 ` Avri Altman
  2 siblings, 0 replies; 8+ messages in thread
From: Avri Altman @ 2021-04-22  9:41 UTC (permalink / raw)
  To: Avri Altman, Ulf Hansson, linux-mmc, Adrian Hunter; +Cc: linux-kernel

Ulf - Would you consider picking this sires up now?
I was hoping to close this bug.

Thanks,
Avri

> -----Original Message-----
> From: Avri Altman <avri.altman@wdc.com>
> Sent: Tuesday, 20 April 2021 16:47
> To: Ulf Hansson <ulf.hansson@linaro.org>; linux-mmc@vger.kernel.org; Adrian
> Hunter <adrian.hunter@intel.com>
> Cc: linux-kernel@vger.kernel.org; Avri Altman <Avri.Altman@wdc.com>
> Subject: [PATCH v4 0/2] Do not flush cache when it is disabled
> 
> v3 -> v4
>  - Attend Adrian's comments
>  - Add Acked-by tag
> 
> v2 -> v3:
>  - rebase onto recent cache changes
> 
> v1 -> v2:
>  - Attend Adrian's comments
> 
> Cache is a temporary storage space in an eMMC device. Volatile by
> nature, the cache should in typical case reduce the access time compared
> to an access to the main nonvolatile storage.
> 
> The cache function can be turned ON and OFF. Once OFF, the host is not
> expected to issue a flush-cache command to the device.
> 
> Avri Altman (2):
>   mmc: block: Issue flush only if allowed
>   mmc: block: Update ext_csd.cache_ctrl if it was written
> 
>  drivers/mmc/core/block.c   | 21 +++++++++++++++++++++
>  drivers/mmc/core/mmc.c     |  2 +-
>  drivers/mmc/core/mmc_ops.h |  5 +++++
>  3 files changed, 27 insertions(+), 1 deletion(-)
> 
> --
> 2.25.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 1/2] mmc: block: Issue flush only if allowed
  2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
  2021-04-20 14:02   ` Adrian Hunter
@ 2021-04-23  8:14   ` Ulf Hansson
  2021-04-24 18:28     ` Avri Altman
  1 sibling, 1 reply; 8+ messages in thread
From: Ulf Hansson @ 2021-04-23  8:14 UTC (permalink / raw)
  To: Avri Altman
  Cc: linux-mmc, Adrian Hunter, Linux Kernel Mailing List, Brendan Peter

On Tue, 20 Apr 2021 at 15:46, Avri Altman <avri.altman@wdc.com> wrote:
>
> The cache may be flushed to the nonvolatile storage by writing to
> FLUSH_CACHE byte (EXT_CSD byte [32]). When in command queueing mode, the
> cache may be flushed by issuing a CMDQ_TASK_ DEV_MGMT (CMD48) with a
> FLUSH_CACHE op-code.  Either way, verify that The cache function is
> turned ON before doing so.
>
> fixes: 1e8e55b67030 (mmc: block: Add CQE support)
>
> Reported-by: Brendan Peter <bpeter@lytx.com>
> Tested-by: Brendan Peter <bpeter@lytx.com>
> Signed-off-by: Avri Altman <avri.altman@wdc.com>
> ---
>  drivers/mmc/core/block.c   | 9 +++++++++
>  drivers/mmc/core/mmc.c     | 2 +-
>  drivers/mmc/core/mmc_ops.h | 5 +++++
>  3 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 8bfd4d95b386..24e1ecbdd510 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -2186,6 +2186,11 @@ static int mmc_blk_wait_for_idle(struct mmc_queue *mq, struct mmc_host *host)
>         return mmc_blk_rw_wait(mq, NULL);
>  }
>
> +static bool mmc_blk_cache_disabled(struct mmc_card *card)
> +{
> +       return mmc_card_mmc(card) && !mmc_flush_allowed(card);

It's these kinds of use with mmc_card_mmc() that I think we need to
strive towards avoiding when going forward.

For example, newer SD cards support both cache and command queueing
nowadays, which means that we need to make the code in the mmc block
layer more agnostic. To do that, I think we should use the bus_ops
callbacks. That's why I started out by adding the ->flush_cache()
callback in the other patch.

> +}
> +
>  enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
>  {
>         struct mmc_blk_data *md = mq->blkdata;
> @@ -2225,6 +2230,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct request *req)
>         case MMC_ISSUE_ASYNC:
>                 switch (req_op(req)) {
>                 case REQ_OP_FLUSH:
> +                       if (mmc_blk_cache_disabled(mq->card)) {

I suggest that you add a new bus ops callback ->cache_enabled() and
implement it for the mmc bus type.

From the mmc block layer point of view, it would then mean that if the
callback isn't implemented, the cache ctrl isn't supported (which
would be the case for SD then)

> +                               blk_mq_end_request(req, BLK_STS_OK);
> +                               return MMC_REQ_FINISHED;
> +                       }
>                         ret = mmc_blk_cqe_issue_flush(mq, req);

>                         break;
>                 case REQ_OP_READ:
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index 9ad4aa537867..e3da62ffcb5e 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -2037,7 +2037,7 @@ static int _mmc_flush_cache(struct mmc_card *card)
>  {
>         int err = 0;
>
> -       if (card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1) {
> +       if (mmc_flush_allowed(card)) {
>                 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
>                                  EXT_CSD_FLUSH_CACHE, 1,
>                                  CACHE_FLUSH_TIMEOUT_MS);
> diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
> index 5782fdf4e8e9..2682bf66708a 100644
> --- a/drivers/mmc/core/mmc_ops.h
> +++ b/drivers/mmc/core/mmc_ops.h
> @@ -19,6 +19,11 @@ enum mmc_busy_cmd {
>  struct mmc_host;
>  struct mmc_card;
>
> +static inline bool mmc_flush_allowed(struct mmc_card *card)
> +{
> +       return card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1;
> +}
> +
>  int mmc_select_card(struct mmc_card *card);
>  int mmc_deselect_cards(struct mmc_host *host);
>  int mmc_set_dsr(struct mmc_host *host);
> --
> 2.25.1
>

Having said the above, we clearly want to tag $subject patch for
stable kernels as well, which means we need a simple patch as
possible.

Clearly $subject patch should have come first, prior to my patch where
I added the ->flush_cache() bus ops callback, as it messes things up.

Therefore, I decided to rebase my next branch to drop the patch adding
the ->flush_cache() bus ops (I will re-post the patch after we have
got your changes in).

Can you please re-base $subject patch and address my comments? My
apologies for the mess!

Kind regards
Uffe

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written
  2021-04-20 13:46 ` [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written Avri Altman
@ 2021-04-23  8:14   ` Ulf Hansson
  0 siblings, 0 replies; 8+ messages in thread
From: Ulf Hansson @ 2021-04-23  8:14 UTC (permalink / raw)
  To: Avri Altman; +Cc: linux-mmc, Adrian Hunter, Linux Kernel Mailing List

On Tue, 20 Apr 2021 at 15:46, Avri Altman <avri.altman@wdc.com> wrote:
>
> The cache function can be turned ON and OFF by writing to the CACHE_CTRL
> byte (EXT_CSD byte [33]).  However,  card->ext_csd.cache_ctrl is only
> set on init if cache size > 0.
>
> Fix that by explicitly setting ext_csd.cache_ctrl on ext-csd write.
>
> Signed-off-by: Avri Altman <avri.altman@wdc.com>
> Acked-by: Adrian Hunter <adrian.hunter@intel.com>

This can go separate from patch 1, so I have applied this for next and
by adding a stable tag to it.

Thanks and kind regards
Uffe


> ---
>  drivers/mmc/core/block.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> index 24e1ecbdd510..7e70f11e85e2 100644
> --- a/drivers/mmc/core/block.c
> +++ b/drivers/mmc/core/block.c
> @@ -572,6 +572,18 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md,
>                 main_md->part_curr = value & EXT_CSD_PART_CONFIG_ACC_MASK;
>         }
>
> +       /*
> +        * Make sure to update CACHE_CTRL in case it was changed. The cache
> +        * will get turned back on if the card is re-initialized, e.g.
> +        * suspend/resume or hw reset in recovery.
> +        */
> +       if ((MMC_EXTRACT_INDEX_FROM_ARG(cmd.arg) == EXT_CSD_CACHE_CTRL) &&
> +           (cmd.opcode == MMC_SWITCH)) {
> +               u8 value = MMC_EXTRACT_VALUE_FROM_ARG(cmd.arg) & 1;
> +
> +               card->ext_csd.cache_ctrl = value;
> +       }
> +
>         /*
>          * According to the SD specs, some commands require a delay after
>          * issuing the command.
> --
> 2.25.1
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH v4 1/2] mmc: block: Issue flush only if allowed
  2021-04-23  8:14   ` Ulf Hansson
@ 2021-04-24 18:28     ` Avri Altman
  0 siblings, 0 replies; 8+ messages in thread
From: Avri Altman @ 2021-04-24 18:28 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: linux-mmc, Adrian Hunter, Linux Kernel Mailing List, Brendan Peter

> On Tue, 20 Apr 2021 at 15:46, Avri Altman <avri.altman@wdc.com> wrote:
> >
> > The cache may be flushed to the nonvolatile storage by writing to
> > FLUSH_CACHE byte (EXT_CSD byte [32]). When in command queueing mode,
> the
> > cache may be flushed by issuing a CMDQ_TASK_ DEV_MGMT (CMD48) with a
> > FLUSH_CACHE op-code.  Either way, verify that The cache function is
> > turned ON before doing so.
> >
> > fixes: 1e8e55b67030 (mmc: block: Add CQE support)
> >
> > Reported-by: Brendan Peter <bpeter@lytx.com>
> > Tested-by: Brendan Peter <bpeter@lytx.com>
> > Signed-off-by: Avri Altman <avri.altman@wdc.com>
> > ---
> >  drivers/mmc/core/block.c   | 9 +++++++++
> >  drivers/mmc/core/mmc.c     | 2 +-
> >  drivers/mmc/core/mmc_ops.h | 5 +++++
> >  3 files changed, 15 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c
> > index 8bfd4d95b386..24e1ecbdd510 100644
> > --- a/drivers/mmc/core/block.c
> > +++ b/drivers/mmc/core/block.c
> > @@ -2186,6 +2186,11 @@ static int mmc_blk_wait_for_idle(struct
> mmc_queue *mq, struct mmc_host *host)
> >         return mmc_blk_rw_wait(mq, NULL);
> >  }
> >
> > +static bool mmc_blk_cache_disabled(struct mmc_card *card)
> > +{
> > +       return mmc_card_mmc(card) && !mmc_flush_allowed(card);
> 
> It's these kinds of use with mmc_card_mmc() that I think we need to
> strive towards avoiding when going forward.
> 
> For example, newer SD cards support both cache and command queueing
> nowadays, which means that we need to make the code in the mmc block
> layer more agnostic. To do that, I think we should use the bus_ops
> callbacks. That's why I started out by adding the ->flush_cache()
> callback in the other patch.
Understood.

> 
> > +}
> > +
> >  enum mmc_issued mmc_blk_mq_issue_rq(struct mmc_queue *mq, struct
> request *req)
> >  {
> >         struct mmc_blk_data *md = mq->blkdata;
> > @@ -2225,6 +2230,10 @@ enum mmc_issued mmc_blk_mq_issue_rq(struct
> mmc_queue *mq, struct request *req)
> >         case MMC_ISSUE_ASYNC:
> >                 switch (req_op(req)) {
> >                 case REQ_OP_FLUSH:
> > +                       if (mmc_blk_cache_disabled(mq->card)) {
> 
> I suggest that you add a new bus ops callback ->cache_enabled() and
> implement it for the mmc bus type.
> 
> From the mmc block layer point of view, it would then mean that if the
> callback isn't implemented, the cache ctrl isn't supported (which
> would be the case for SD then)
Done.

> 
> > +                               blk_mq_end_request(req, BLK_STS_OK);
> > +                               return MMC_REQ_FINISHED;
> > +                       }
> >                         ret = mmc_blk_cqe_issue_flush(mq, req);
> 
> >                         break;
> >                 case REQ_OP_READ:
> > diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> > index 9ad4aa537867..e3da62ffcb5e 100644
> > --- a/drivers/mmc/core/mmc.c
> > +++ b/drivers/mmc/core/mmc.c
> > @@ -2037,7 +2037,7 @@ static int _mmc_flush_cache(struct mmc_card
> *card)
> >  {
> >         int err = 0;
> >
> > -       if (card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1) {
> > +       if (mmc_flush_allowed(card)) {
> >                 err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
> >                                  EXT_CSD_FLUSH_CACHE, 1,
> >                                  CACHE_FLUSH_TIMEOUT_MS);
> > diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h
> > index 5782fdf4e8e9..2682bf66708a 100644
> > --- a/drivers/mmc/core/mmc_ops.h
> > +++ b/drivers/mmc/core/mmc_ops.h
> > @@ -19,6 +19,11 @@ enum mmc_busy_cmd {
> >  struct mmc_host;
> >  struct mmc_card;
> >
> > +static inline bool mmc_flush_allowed(struct mmc_card *card)
> > +{
> > +       return card->ext_csd.cache_size > 0 && card->ext_csd.cache_ctrl & 1;
> > +}
> > +
> >  int mmc_select_card(struct mmc_card *card);
> >  int mmc_deselect_cards(struct mmc_host *host);
> >  int mmc_set_dsr(struct mmc_host *host);
> > --
> > 2.25.1
> >
> 
> Having said the above, we clearly want to tag $subject patch for
> stable kernels as well, which means we need a simple patch as
> possible.
> 
> Clearly $subject patch should have come first, prior to my patch where
> I added the ->flush_cache() bus ops callback, as it messes things up.
> 
> Therefore, I decided to rebase my next branch to drop the patch adding
> the ->flush_cache() bus ops (I will re-post the patch after we have
> got your changes in).
> 
> Can you please re-base $subject patch and address my comments? My
> apologies for the mess!
Done.

Thanks,
Avri

> 
> Kind regards
> Uffe

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-04-24 18:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-20 13:46 [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman
2021-04-20 13:46 ` [PATCH v4 1/2] mmc: block: Issue flush only if allowed Avri Altman
2021-04-20 14:02   ` Adrian Hunter
2021-04-23  8:14   ` Ulf Hansson
2021-04-24 18:28     ` Avri Altman
2021-04-20 13:46 ` [PATCH v4 2/2] mmc: block: Update ext_csd.cache_ctrl if it was written Avri Altman
2021-04-23  8:14   ` Ulf Hansson
2021-04-22  9:41 ` [PATCH v4 0/2] Do not flush cache when it is disabled Avri Altman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).