From: Adrian Hunter <adrian.hunter@intel.com>
To: Namjae Jeon <linkinjeon@gmail.com>
Cc: dwmw2@infradead.org, axboe@kernel.dk, shli@kernel.org,
Paul.Clements@steeleye.com, npiggin@kernel.dk, neilb@suse.de,
cjb@laptop.org, linux-mtd@lists.infradead.org,
nbd-general@lists.sourceforge.net, linux-raid@vger.kernel.org,
linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
Namjae Jeon <namjae.jeon@samsung.com>,
Vivek Trivedi <t.vivek@samsung.com>
Subject: Re: [PATCH 2/8] mmc: fix max_discard_sectors
Date: Mon, 15 Apr 2013 10:20:22 +0300 [thread overview]
Message-ID: <516BAA36.9030500@intel.com> (raw)
In-Reply-To: <1365860309-21261-1-git-send-email-linkinjeon@gmail.com>
On 13/04/13 16:38, Namjae Jeon wrote:
> From: Namjae Jeon <namjae.jeon@samsung.com>
>
> https://lkml.org/lkml/2013/4/1/292
> As per above discussion, there is possibility that request's __data_len
> field may overflow when max_discard_sectors greater than UINT_MAX >> 9
>
> If multiple discard requests get merged, merged discard request's
> size exceeds 4GB, there is possibility that merged discard request's
> __data_len field may overflow.
>
> This patch fixes this issue.
>
> Reported-by: Max Filippov <jcmvbkbc@gmail.com>
> Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
> Signed-off-by: Vivek Trivedi <t.vivek@samsung.com>
> Tested-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
> drivers/mmc/card/queue.c | 2 +-
> drivers/mmc/core/core.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
> index 9447a0e..54726b7 100644
> --- a/drivers/mmc/card/queue.c
> +++ b/drivers/mmc/card/queue.c
> @@ -166,7 +166,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
> return;
>
> queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
> - q->limits.max_discard_sectors = max_discard;
> + blk_queue_max_discard_sectors(q, max_discard);
> if (card->erased_byte == 0 && !mmc_can_discard(card))
> q->limits.discard_zeroes_data = 1;
> q->limits.discard_granularity = card->pref_erase << 9;
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 7b435a3..6ee530c 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2058,7 +2058,7 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
> if (card->erase_shift)
> max_qty = UINT_MAX >> card->erase_shift;
> else if (mmc_card_sd(card))
> - max_qty = UINT_MAX;
> + max_qty = UINT_MAX >> 9;
No. This function calculates max discard for the card not the block layer.
Apply the block layer limitation at the block layer interface e.g.
in mmc_queue_setup_discard()
> else
> max_qty = UINT_MAX / card->erase_size;
>
> @@ -2100,7 +2100,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
> unsigned int max_discard, max_trim;
>
> if (!host->max_discard_to)
> - return UINT_MAX;
> + return UINT_MAX >> 9;
Ditto.
>
> /*
> * Without erase_group_def set, MMC erase timeout depends on clock
>
WARNING: multiple messages have this Message-ID (diff)
From: Adrian Hunter <adrian.hunter@intel.com>
To: Namjae Jeon <linkinjeon@gmail.com>
Cc: axboe@kernel.dk, nbd-general@lists.sourceforge.net,
Vivek Trivedi <t.vivek@samsung.com>,
npiggin@kernel.dk, neilb@suse.de, dwmw2@infradead.org,
Paul.Clements@steeleye.com, linux-kernel@vger.kernel.org,
linux-raid@vger.kernel.org, Namjae Jeon <namjae.jeon@samsung.com>,
linux-mtd@lists.infradead.org, linux-mmc@vger.kernel.org,
cjb@laptop.org, shli@kernel.org
Subject: Re: [PATCH 2/8] mmc: fix max_discard_sectors
Date: Mon, 15 Apr 2013 10:20:22 +0300 [thread overview]
Message-ID: <516BAA36.9030500@intel.com> (raw)
In-Reply-To: <1365860309-21261-1-git-send-email-linkinjeon@gmail.com>
On 13/04/13 16:38, Namjae Jeon wrote:
> From: Namjae Jeon <namjae.jeon@samsung.com>
>
> https://lkml.org/lkml/2013/4/1/292
> As per above discussion, there is possibility that request's __data_len
> field may overflow when max_discard_sectors greater than UINT_MAX >> 9
>
> If multiple discard requests get merged, merged discard request's
> size exceeds 4GB, there is possibility that merged discard request's
> __data_len field may overflow.
>
> This patch fixes this issue.
>
> Reported-by: Max Filippov <jcmvbkbc@gmail.com>
> Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
> Signed-off-by: Vivek Trivedi <t.vivek@samsung.com>
> Tested-by: Max Filippov <jcmvbkbc@gmail.com>
> ---
> drivers/mmc/card/queue.c | 2 +-
> drivers/mmc/core/core.c | 4 ++--
> 2 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/card/queue.c b/drivers/mmc/card/queue.c
> index 9447a0e..54726b7 100644
> --- a/drivers/mmc/card/queue.c
> +++ b/drivers/mmc/card/queue.c
> @@ -166,7 +166,7 @@ static void mmc_queue_setup_discard(struct request_queue *q,
> return;
>
> queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
> - q->limits.max_discard_sectors = max_discard;
> + blk_queue_max_discard_sectors(q, max_discard);
> if (card->erased_byte == 0 && !mmc_can_discard(card))
> q->limits.discard_zeroes_data = 1;
> q->limits.discard_granularity = card->pref_erase << 9;
> diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
> index 7b435a3..6ee530c 100644
> --- a/drivers/mmc/core/core.c
> +++ b/drivers/mmc/core/core.c
> @@ -2058,7 +2058,7 @@ static unsigned int mmc_do_calc_max_discard(struct mmc_card *card,
> if (card->erase_shift)
> max_qty = UINT_MAX >> card->erase_shift;
> else if (mmc_card_sd(card))
> - max_qty = UINT_MAX;
> + max_qty = UINT_MAX >> 9;
No. This function calculates max discard for the card not the block layer.
Apply the block layer limitation at the block layer interface e.g.
in mmc_queue_setup_discard()
> else
> max_qty = UINT_MAX / card->erase_size;
>
> @@ -2100,7 +2100,7 @@ unsigned int mmc_calc_max_discard(struct mmc_card *card)
> unsigned int max_discard, max_trim;
>
> if (!host->max_discard_to)
> - return UINT_MAX;
> + return UINT_MAX >> 9;
Ditto.
>
> /*
> * Without erase_group_def set, MMC erase timeout depends on clock
>
next prev parent reply other threads:[~2013-04-15 7:15 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-13 13:38 [PATCH 2/8] mmc: fix max_discard_sectors Namjae Jeon
2013-04-13 13:38 ` Namjae Jeon
2013-04-15 7:20 ` Adrian Hunter [this message]
2013-04-15 7:20 ` Adrian Hunter
[not found] ` <516BAA36.9030500-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2013-04-15 7:52 ` Namjae Jeon
2013-04-15 7:52 ` Namjae Jeon
2013-04-15 7:52 ` Namjae Jeon
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=516BAA36.9030500@intel.com \
--to=adrian.hunter@intel.com \
--cc=Paul.Clements@steeleye.com \
--cc=axboe@kernel.dk \
--cc=cjb@laptop.org \
--cc=dwmw2@infradead.org \
--cc=linkinjeon@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-raid@vger.kernel.org \
--cc=namjae.jeon@samsung.com \
--cc=nbd-general@lists.sourceforge.net \
--cc=neilb@suse.de \
--cc=npiggin@kernel.dk \
--cc=shli@kernel.org \
--cc=t.vivek@samsung.com \
/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.