linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Hunter <jonathanh@nvidia.com>
To: Gwendal Grignou <gwendal@chromium.org>,
	Ulf Hansson <ulf.hansson@linaro.org>
Cc: "linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	Seshagiri Holi <sholi@nvidia.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	Grant Grundler <grundler@google.com>,
	"Olof Johansson" <olofj@chromium.org>
Subject: Re: [PATCH V3] mmc: block: Add new ioctl to send multi commands
Date: Mon, 21 Sep 2015 12:19:50 +0100	[thread overview]
Message-ID: <55FFE7D6.7050603@nvidia.com> (raw)
In-Reply-To: <55FFD467.9020801@nvidia.com>


On 21/09/15 10:56, Jon Hunter wrote:
> 
> On 16/09/15 18:54, Gwendal Grignou wrote:
> 
> [snip]
> 
>>> +static int mmc_blk_ioctl_multi_cmd(struct block_device *bdev,
>>> +                                  struct mmc_ioc_multi_cmd __user *user)
>>> +{
>>> +       struct mmc_blk_ioc_data **idata = NULL;
>>> +       struct mmc_ioc_cmd __user *cmds = user->cmds;
>>> +       struct mmc_card *card;
>>> +       struct mmc_blk_data *md;
>>> +       int i, err = -EFAULT;
>>> +       __u64 num_of_cmds;
>>> +
>>> +       /*
>>> +        * The caller must have CAP_SYS_RAWIO, and must be calling this on the
>>> +        * whole block device, not on a partition.  This prevents overspray
>>> +        * between sibling partitions.
>>> +        */
>>> +       if ((!capable(CAP_SYS_RAWIO)) || (bdev != bdev->bd_contains))
>>> +               return -EPERM;
>>> +
>>> +       if (copy_from_user(&num_of_cmds, &user->num_of_cmds,
>>> +                          sizeof(num_of_cmds)))
>>> +               return -EFAULT;
>>> +
>>> +       if (num_of_cmds > MMC_IOC_MAX_CMDS)
>>> +               return -EINVAL;
>>> +
>>> +       idata = kcalloc(num_of_cmds, sizeof(*idata), GFP_KERNEL);
>>> +       if (!idata)
>>> +               return -ENOMEM;
>>> +
>>> +       for (i = 0; i < num_of_cmds; i++) {
>>> +               idata[i] = mmc_blk_ioctl_copy_from_user(&cmds[i]);
>>> +               if (IS_ERR(idata[i])) {
>>> +                       err = PTR_ERR(idata[i]);
>>> +                       num_of_cmds = i;
>>> +                       goto cmd_err;
>>> +               }
>>> +       }
>>> +
>>> +       md = mmc_blk_get(bdev->bd_disk);
>>> +       if (!md)
>>> +               goto cmd_err;
>>> +
>>> +       card = md->queue.card;
>>> +       if (IS_ERR(card)) {
>>> +               err = PTR_ERR(card);
>>> +               goto cmd_done;
>>> +       }
>>> +
>>> +       mmc_get_card(card);
>>> +
>>> +       for (i = 0; i < num_of_cmds; i++) {
>>> +               err = __mmc_blk_ioctl_cmd(card, md, idata[i]);
>>> +               if (err) {
>>> +                       mmc_put_card(card);
>>> +                       goto cmd_done;
>> Instead of exiting here, you should first copy to the user the data
>> and response of successful commands, mark the failed command as failed
>> and the remaining ones as "not executed".
>> This way, it will be easier for the user space application to find out
>> where the sequence failed. This especially true if some reverts are
>> needed.
> 
> Yes that sounds like a sensible thing to do. I will incorporate that change.

At first, I thought that may be the response field of the command could
be used to indicate the failed command. However, thinking about this
some more, I am not sure that it seems correct to use this field as this
is really used to carry the MMC response as defined by the MMC
specification.

Should the response field always be non-zero for a successful command?
If this is guaranteed, then may be the best thing to do would be to have
user-space clear the response field to field before submitting the
commands. It would then be easy to detect which command failed and which
were not attempted.

Ulf, what are your thoughts?

Cheers
Jon

  reply	other threads:[~2015-09-21 11:19 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-14 15:00 [PATCH V3] mmc: block: Add new ioctl to send multi commands Jon Hunter
2015-09-14 16:36 ` Grant Grundler
2015-09-16 11:08 ` Ulf Hansson
2015-09-16 16:01   ` Jon Hunter
2015-09-17  6:59     ` Ulf Hansson
2015-09-18 10:24       ` Jon Hunter
2015-09-16 17:54 ` Gwendal Grignou
2015-09-21  9:56   ` Jon Hunter
2015-09-21 11:19     ` Jon Hunter [this message]
2015-09-21 18:40       ` Grant Grundler
2015-09-22  9:29         ` Jon Hunter

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=55FFE7D6.7050603@nvidia.com \
    --to=jonathanh@nvidia.com \
    --cc=arnd@arndb.de \
    --cc=grundler@google.com \
    --cc=gwendal@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=olofj@chromium.org \
    --cc=sholi@nvidia.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;
as well as URLs for NNTP newsgroup(s).