Re: [PATCH] scsi: do not print 'reservation conflict' for TEST UNIT READY

2016-09-13 Thread James Bottomley
On Tue, 2016-09-13 at 15:05 -0400, Ewan D. Milne wrote:
> On Tue, 2016-09-13 at 08:06 -0700, James Bottomley wrote:
> > On Tue, 2016-09-13 at 16:24 +0200, Hannes Reinecke wrote:
> > > On 09/13/2016 04:04 PM, James Bottomley wrote:
> > > > You could argue that the entire message needs removing, since
> > > > it's
> > > > reporting stuff that mostly only shows when systems using 
> > > > reservations correctly are in operation.
> > > > 
> > > Oh, I'm perfectly fine with that.
> > > I'm happy to send a patch removing that line altogether.
> > 
> > OK, how about lowering the priority to KERN_DEBUG so it can still
> > be
> > seen, just not usually.
> > 
> > James
> > 
> 
> So, if we do this, and someone else does a SCSI-2 RESERVE on the LUN
> while we have a file system mounted, what error will we end up
> getting?
> I would assume that we would still see the usual SCSI error message
> with the CDB printed, and that the "reservation conflict" message was
> supplemental?  Or does the message get suppressed?  I'll have to try
> this...

It will print out the CDB and the return code, which should say Read
(or Write) [ACTION_FAIL in scsi_io_completion()].  However, it looks
like scsi_print_result() doesn't actually print the device byte, which
is where the reservation conflict is, so perhaps that should also be
fixed.

James

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: do not print 'reservation conflict' for TEST UNIT READY

2016-09-13 Thread Ewan D. Milne
On Tue, 2016-09-13 at 08:06 -0700, James Bottomley wrote:
> On Tue, 2016-09-13 at 16:24 +0200, Hannes Reinecke wrote:
> > On 09/13/2016 04:04 PM, James Bottomley wrote:
> > > You could argue that the entire message needs removing, since it's
> > > reporting stuff that mostly only shows when systems using 
> > > reservations correctly are in operation.
> > > 
> > Oh, I'm perfectly fine with that.
> > I'm happy to send a patch removing that line altogether.
> 
> OK, how about lowering the priority to KERN_DEBUG so it can still be
> seen, just not usually.
> 
> James
> 

So, if we do this, and someone else does a SCSI-2 RESERVE on the LUN
while we have a file system mounted, what error will we end up getting?
I would assume that we would still see the usual SCSI error message
with the CDB printed, and that the "reservation conflict" message was
supplemental?  Or does the message get suppressed?  I'll have to try
this...

-Ewan


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi:Prevent deletion of SCSI block device in use

2016-09-13 Thread Ewan D. Milne
On Tue, 2016-09-13 at 22:08 +0530, Gurunath, Vasundhara wrote:
> From: "Gurunath, Vasundhara" 
> 
> SCSI block device can be removed, using write to sysfs
> delete file as below:
> echo 1 > /sys/block/sdX/device/delete
> If the device is in use by applications, or part of
> system configuration such as boot device, removal can
> result in application disruptions or system down time.
> 
> An additional write option ? is added to SCSI sysfs
> interface as below, in order to prevent accidental
> deletion of devices in use.
> echo ? > /sys/block/sdX/device/delete
> 
> In the absence of any usage, this option proceeds with
> device deletion.  If the device is open, deletion is
> prevented, and active Open and IO counts at the time of
> deletion is logged. Information logged during latest
> delete attempt can be obtained by issuing a read to the
> delete file as below:
> cat  /sys/block/sdX/device/delete
> 

This looks like debugging code added to find some culprit
who deleted a device they weren't supposed to, and make it
more difficult for them.

I don't think we'd want this in normal usage.

-Ewan



--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [REPOST PATCH 1/5] scsi: bnx2i: convert to kworker

2016-09-13 Thread Chad Dupuis

On Fri, 9 Sep 2016, 11:28am -, Martin K. Petersen wrote:

> > "Johannes" == Johannes Thumshirn  writes:
> 
> >> On Wed, Aug 17, 2016 at 12:09:59PM +0200, Sebastian Andrzej Siewior
> wrote:
> >> The driver creates its own per-CPU threads which are updated based on
> >> CPU hotplug events. It is also possible to use kworkers and remove
> >> some of the infrastructure get the same job done while saving a few
> >> lines of code.
> 
> Johannes> I'm sorry it took so long but for the whole series: Tested-by:
> Johannes> Johannes Thumshirn  Acked-by: Johannes
> Johannes> Thumshirn 
> 
> Johannes> Testing was conducted by booting from a QLogic BCM57840 CNA.
> 
> Chad?
> 

We're regression testing the patches now.  Please hold off on applying 
them. 
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: TRIM/UNMAP/DISCARD via ATA Passthrough

2016-09-13 Thread Henrique de Moraes Holschuh
On Mon, 12 Sep 2016, Jason A. Donenfeld wrote:
> I was wondering if it'd be possible to have the uas driver -- or
> perhaps somewhere else in the stack -- fall back to using
> ATA-passthrough-TRIM for UNMAP, so that discard can work properly.
> AFAIK, the Windows drivers do exactly this.
> 
> If the answer is, "yes we want this! but we don't have the man power,"
> please tell me where I can start looking, so that I can submit the
> patch myself.

Whomever implements this, please add a "chicken bit" to allow the user
to disable it if the enclosure misbehaves.

-- 
  Henrique Holschuh
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi:Prevent deletion of SCSI block device in use

2016-09-13 Thread James Bottomley
On Tue, 2016-09-13 at 22:08 +0530, Gurunath, Vasundhara wrote:
> From: "Gurunath, Vasundhara" 
> 
> SCSI block device can be removed, using write to sysfs
> delete file as below:
> echo 1 > /sys/block/sdX/device/delete
> If the device is in use by applications, or part of
> system configuration such as boot device, removal can
> result in application disruptions or system down time.
> 
> An additional write option ? is added to SCSI sysfs
> interface as below, in order to prevent accidental
> deletion of devices in use.
> echo ? > /sys/block/sdX/device/delete
> 
> In the absence of any usage, this option proceeds with
> device deletion.  If the device is open, deletion is
> prevented, and active Open and IO counts at the time of
> deletion is logged. Information logged during latest
> delete attempt can be obtained by issuing a read to the
> delete file as below:
> cat  /sys/block/sdX/device/delete

OK, so I'm not too keen on this because our entire system is (finally)
designed to be hot plug, so echoing 1 to delete simulates a hotplug
event, and they can come in at any time.

Can you elaborate on why this is necessary?  Right at the moment, only
root is allowed to write to this file and cause a deletion ... plus the
file is pretty hard to find, buried as it is in sysfs; So I would have
thought it was pretty safe from accidental misuse; why does it need
additional protection?

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Query related to the UPIU endianess

2016-09-13 Thread Sangamesh O Shetty
Hi all,

I have a query related to the endianess of the UPIU packet.

The JESD223C document mentions that the CDB should be in big-endian.
The JESD220C document section 10.7 mentions the layout of all the UFS
UPIU's. It mentions that the first byte is transaction type, second
byte is flags and so forth. So when the UPIU is encoded in the UTRD
descriptor then the UPIU's transaction type will come as the third
byte of CDB and task tag will comes as first byte of CDB after
converting to big-endian.

But when I looked at the Linux driver(refer here the macro
UPIU_HEADER_DWORD), the transaction type is considered as byte zero
and task tag as byte three after it is converted to big-endian.

So my query is that what is the endianess of the UPIU packed that is
described in the JESD220C document.

wwr,
Sangamesh
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] scsi:Prevent deletion of SCSI block device in use

2016-09-13 Thread Gurunath, Vasundhara
From: "Gurunath, Vasundhara" 

SCSI block device can be removed, using write to sysfs
delete file as below:
echo 1 > /sys/block/sdX/device/delete
If the device is in use by applications, or part of
system configuration such as boot device, removal can
result in application disruptions or system down time.

An additional write option ? is added to SCSI sysfs
interface as below, in order to prevent accidental
deletion of devices in use.
echo ? > /sys/block/sdX/device/delete

In the absence of any usage, this option proceeds with
device deletion.  If the device is open, deletion is
prevented, and active Open and IO counts at the time of
deletion is logged. Information logged during latest
delete attempt can be obtained by issuing a read to the
delete file as below:
cat  /sys/block/sdX/device/delete

Signed-off-by: Vasundhara Gurunath 
---
 drivers/scsi/scsi_sysfs.c  | 52 +-
 drivers/scsi/sd.c  |  4 
 include/scsi/scsi_device.h |  2 ++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
index 0734927..b0cbfbb 100644
--- a/drivers/scsi/scsi_sysfs.c
+++ b/drivers/scsi/scsi_sysfs.c
@@ -12,6 +12,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -457,6 +459,8 @@ static void scsi_device_dev_release_usercontext(struct 
work_struct *work)
kfree(sdev->vpd_pg83);
kfree(sdev->vpd_pg80);
kfree(sdev->inquiry);
+   if (sdev->delete_msg_buf != NULL)
+   kfree(sdev->delete_msg_buf);
kfree(sdev);
 
if (parent)
@@ -709,11 +713,57 @@ static ssize_t
 sdev_store_delete(struct device *dev, struct device_attribute *attr,
  const char *buf, size_t count)
 {
+   struct scsi_device *sdev = to_scsi_device(dev);
+   struct timeval tv;
+   struct tm tms;
+
+   if (buf[0] == '?')  {
+   if (sdev->usage_count) {
+   /*
+   * Buffer to hold I/O statistics on delete attempt.
+   */
+   if (sdev->delete_msg_buf == NULL) {
+   sdev->delete_msg_buf =
+   kmalloc(128, GFP_KERNEL);
+   memset(sdev->delete_msg_buf, 0, 128);
+   }
+   do_gettimeofday();
+   time_to_tm(tv.tv_sec, 0, );
+   sprintf(sdev->delete_msg_buf,
+   "Last delete attempt: %d:%d:%ld %02d:%02d\n"
+   "Open Count : %d\n"
+   "IO Active Count : %d\n"
+   "IO Done Count : %d\n",
+   tms.tm_mday, tms.tm_mon + 1,
+   tms.tm_year + 1900,
+   tms.tm_hour, tms.tm_min,
+   sdev->usage_count,
+   sdev->iorequest_cnt.counter,
+   sdev->iodone_cnt.counter);
+
+   return count;
+   }
+   }
+
+
if (device_remove_file_self(dev, attr))
scsi_remove_device(to_scsi_device(dev));
return count;
 };
-static DEVICE_ATTR(delete, S_IWUSR, NULL, sdev_store_delete);
+
+static ssize_t sdev_show_delete(struct device *dev,
+   struct device_attribute *attr, char *buf) {
+
+   struct scsi_device *sdev = to_scsi_device(dev);
+
+   if (sdev->delete_msg_buf != NULL)
+   return sprintf(buf, "%s", sdev->delete_msg_buf);
+   else
+   return 0;
+}
+
+static DEVICE_ATTR(delete, S_IRUGO | S_IWUSR,
+   sdev_show_delete, sdev_store_delete);
 
 static ssize_t
 store_state_field(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index d3e852a..67d3406 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -1235,6 +1235,7 @@ static int sd_open(struct block_device *bdev, fmode_t 
mode)
if (scsi_block_when_processing_errors(sdev))
scsi_set_medium_removal(sdev, SCSI_REMOVAL_PREVENT);
}
+   sdev->usage_count = sdkp->openers.counter;
 
return 0;
 
@@ -1267,6 +1268,7 @@ static void sd_release(struct gendisk *disk, fmode_t mode)
if (scsi_block_when_processing_errors(sdev))
scsi_set_medium_removal(sdev, SCSI_REMOVAL_ALLOW);
}
+   sdev->usage_count = sdkp->openers.counter;
 
/*
 * XXX and what if there are packets in flight and this close()
@@ -3082,6 +3084,8 @@ static int sd_probe(struct device *dev)
atomic_set(>openers, 0);
atomic_set(>device->ioerr_cnt, 0);
 
+   sdp->usage_count = sdkp->openers.counter;
+
if (!sdp->request_queue->rq_timeout) {
if (sdp->type != TYPE_MOD)
  

Re: [PATCH] scsi: do not print 'reservation conflict' for TEST UNIT READY

2016-09-13 Thread James Bottomley
On Tue, 2016-09-13 at 16:24 +0200, Hannes Reinecke wrote:
> On 09/13/2016 04:04 PM, James Bottomley wrote:
> > You could argue that the entire message needs removing, since it's
> > reporting stuff that mostly only shows when systems using 
> > reservations correctly are in operation.
> > 
> Oh, I'm perfectly fine with that.
> I'm happy to send a patch removing that line altogether.

OK, how about lowering the priority to KERN_DEBUG so it can still be
seen, just not usually.

James


--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: do not print 'reservation conflict' for TEST UNIT READY

2016-09-13 Thread Hannes Reinecke
On 09/13/2016 04:04 PM, James Bottomley wrote:
> On Mon, 2016-09-12 at 10:20 +0200, Hannes Reinecke wrote:
>> SPC-2 and SPC-3 (or later) differ in the handling of reservation
>> conflict for TEST UNIT READY. SPC-2 will return 'reservation 
>> conflict', whereas SPC-3 will return GOOD status.
>> On a mixed system with both SPC-2 and SPC-3 targets one will
>> see lots of 'reservation conflict' messages from the SPC-2 system but
>> no messages from the SPC-3 system when eg multipath path checkers.
>> These messages might confuse the unsuspecting user although in fact
>> they just signal normal operation.
> 
> I don't agree with this: a SCSI-2 device will not get properly
> configured if it's reserved by something else, so you get other strange
> artifacts of this condition.
> 
It's not about SCSI-2, it's for later arrays. See below.

>> So we should not be printing out 'reservation conflict' for
>> TEST UNIT READY responses.
> 
> This doesn't sound like a good rationale to me.  The way I see it, if
> this message is actually useful, people would like to see it when they
> get a reservation conflict.  That does mean even when SCSI-2
> reservations give one where SCSI-3 would not.  The other reason is that
> it tells you why your device didn't get configured properly: both Test
> Unit Ready and Read Capacity get conflicts with SCSI-2, whereas they do
> with SPC-3+ devices (trying to forget SPC-2).
> 
This specific issue occurred with a customer which had a mix of SPC-2
and SPC-3 arrays.
So I can't just 'forget' SPC-2 :-)
The system works just as designed, _except_ that one array is printing
this message (the SPC-2 one) whereas the other one doesn't.
So the message has zero value in this case.

> You could argue that the entire message needs removing, since it's
> reporting stuff that mostly only shows when systems using reservations
> correctly are in operation.
> 
Oh, I'm perfectly fine with that.
I'm happy to send a patch removing that line altogether.

Cheers,

Hannes
-- 
Dr. Hannes Reinecke   zSeries & Storage
h...@suse.de  +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: J. Hawn, J. Guild, F. Imendörffer, HRB 16746 (AG Nürnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] scsi: do not print 'reservation conflict' for TEST UNIT READY

2016-09-13 Thread James Bottomley
On Mon, 2016-09-12 at 10:20 +0200, Hannes Reinecke wrote:
> SPC-2 and SPC-3 (or later) differ in the handling of reservation
> conflict for TEST UNIT READY. SPC-2 will return 'reservation 
> conflict', whereas SPC-3 will return GOOD status.
> On a mixed system with both SPC-2 and SPC-3 targets one will
> see lots of 'reservation conflict' messages from the SPC-2 system but
> no messages from the SPC-3 system when eg multipath path checkers.
> These messages might confuse the unsuspecting user although in fact
> they just signal normal operation.

I don't agree with this: a SCSI-2 device will not get properly
configured if it's reserved by something else, so you get other strange
artifacts of this condition.

> So we should not be printing out 'reservation conflict' for
> TEST UNIT READY responses.

This doesn't sound like a good rationale to me.  The way I see it, if
this message is actually useful, people would like to see it when they
get a reservation conflict.  That does mean even when SCSI-2
reservations give one where SCSI-3 would not.  The other reason is that
it tells you why your device didn't get configured properly: both Test
Unit Ready and Read Capacity get conflicts with SCSI-2, whereas they do
with SPC-3+ devices (trying to forget SPC-2).

You could argue that the entire message needs removing, since it's
reporting stuff that mostly only shows when systems using reservations
correctly are in operation.

James

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 2/9] rpmb: enable emmc specific read data fixup

2016-09-13 Thread Tomas Winkler
For eMMC the block count of the RPMB read operation is not indicated in
the original RPMB Data Read Request packet.
This might be different then the implementation of other protocol
standards.
This patch implements a fixup for this behavior.


Signed-off-by: Tomas Winkler 
---
V6: new in the series

 drivers/char/rpmb/core.c | 36 +---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/drivers/char/rpmb/core.c b/drivers/char/rpmb/core.c
index ff10cbb7b644..8cfbbb721538 100644
--- a/drivers/char/rpmb/core.c
+++ b/drivers/char/rpmb/core.c
@@ -117,6 +117,35 @@ static int rpmb_request_verify(struct rpmb_dev *rdev, 
struct rpmb_data *rpmbd)
 }
 
 /**
+ * rpmb_cmd_fixup - fixup rpmb command
+ *
+ * @rdev: rpmb device
+ * @cmds: rpmb command list
+ * @ncmds: number of commands
+ *
+ */
+static void rpmb_cmd_fixup(struct rpmb_dev *rdev,
+  struct rpmb_cmd *cmds, u32 ncmds)
+{
+   int i;
+
+   if (rdev->ops->type != RPMB_TYPE_EMMC)
+   return;
+
+   /* Fixup RPMB_READ_DATA specific to eMMC
+* The block count of the RPMB read operation is not indicated
+* in the original RPMB Data Read Request packet.
+* This is different then implementation for other protocol
+* standards.
+*/
+   for (i = 0; i < ncmds; i++)
+   if (cmds->frames->req_resp == cpu_to_be16(RPMB_READ_DATA)) {
+   dev_dbg(>dev, "Fixing up READ_DATA frame to 
block_count=0\n");
+   cmds->frames->block_count = 0;
+   }
+}
+
+/**
  * rpmb_cmd_seq - send RPMB command sequence
  *
  * @rdev: rpmb device
@@ -136,10 +165,11 @@ int rpmb_cmd_seq(struct rpmb_dev *rdev, struct rpmb_cmd 
*cmds, u32 ncmds)
return -EINVAL;
 
mutex_lock(>lock);
-   if (rdev->ops && rdev->ops->cmd_seq)
+   err = -EOPNOTSUPP;
+   if (rdev->ops && rdev->ops->cmd_seq) {
+   rpmb_cmd_fixup(rdev, cmds, ncmds);
err = rdev->ops->cmd_seq(rdev->dev.parent, cmds, ncmds);
-   else
-   err = -EOPNOTSUPP;
+   }
mutex_unlock(>lock);
return err;
 }
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 8/9] mmc: block: register RPMB partition with the RPMB subsystem

2016-09-13 Thread Tomas Winkler
Register eMMC RPMB partition with the RPMB subsystem and provide
implementation for the RPMB access operations abstracting
actual multi step process.

Signed-off-by: Tomas Winkler 
Signed-off-by: Alexander Usyskin 
---
V2: resend
V3: commit message fix
V4: Kconfig: use select RPMB to ensure valid configuration
Switch back to main area after RPMB access
V5: Revamp code using new sequence command
Support for 8K packets in e.MMC v5.1
V5: resend

 drivers/mmc/card/Kconfig |   1 +
 drivers/mmc/card/block.c | 258 ++-
 2 files changed, 256 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/card/Kconfig b/drivers/mmc/card/Kconfig
index 5562308699bc..537d0bc82781 100644
--- a/drivers/mmc/card/Kconfig
+++ b/drivers/mmc/card/Kconfig
@@ -7,6 +7,7 @@ comment "MMC/SD/SDIO Card Drivers"
 config MMC_BLOCK
tristate "MMC block device driver"
depends on BLOCK
+   select RPMB
default y
help
  Say Y here to enable the MMC block device driver support.
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 2206d4477dbb..51d7e60226f5 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -42,6 +42,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -111,6 +112,7 @@ struct mmc_blk_data {
 #define MMC_BLK_WRITE  BIT(1)
 #define MMC_BLK_DISCARDBIT(2)
 #define MMC_BLK_SECDISCARD BIT(3)
+#define MMC_BLK_RPMB   BIT(4)
 
/*
 * Only set in main mmc_blk_data associated
@@ -401,8 +403,8 @@ static int mmc_blk_ioctl_copy_to_user(struct mmc_ioc_cmd 
__user *ic_ptr,
return 0;
 }
 
-static int ioctl_rpmb_card_status_poll(struct mmc_card *card, u32 *status,
-  u32 retries_max)
+static int mmc_blk_rpmb_status_poll(struct mmc_card *card, u32 *status,
+   u32 retries_max)
 {
int err;
u32 retry_count = 0;
@@ -575,7 +577,7 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, 
struct mmc_blk_data *md,
 * Ensure RPMB command has completed by polling CMD13
 * "Send Status".
 */
-   err = ioctl_rpmb_card_status_poll(card, , 5);
+   err = mmc_blk_rpmb_status_poll(card, , 5);
if (err)
dev_err(mmc_dev(card->host),
"%s: Card Status=0x%08X, error %d\n",
@@ -1165,6 +1167,252 @@ int mmc_access_rpmb(struct mmc_queue *mq)
return false;
 }
 
+static int mmc_rpmb_send_cmd(struct mmc_card *card,
+unsigned int data_type, bool do_rel_wr,
+void *buf, u16 blks)
+{
+   int err;
+   u32 status;
+   struct mmc_command sbc = {
+   .opcode = MMC_SET_BLOCK_COUNT,
+   .flags  = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC,
+   };
+
+   struct mmc_command cmd = {
+   .flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC,
+   };
+
+   struct mmc_data data = {
+   .blksz = 512,
+   };
+   struct mmc_request mrq = {
+   .sbc= ,
+   .cmd= ,
+   .data   = ,
+   .stop   = NULL,
+   };
+   struct scatterlist sg;
+
+   /*  set CMD23 */
+   sbc.arg = blks & 0x;
+   if (do_rel_wr)
+   sbc.arg |= MMC_CMD23_ARG_REL_WR;
+
+   /*  set CMD25/18 */
+   cmd.opcode = (data_type == MMC_DATA_WRITE) ?
+   MMC_WRITE_MULTIPLE_BLOCK : MMC_READ_MULTIPLE_BLOCK;
+
+   sg_init_one(, buf, 512 * blks);
+
+   data.blocks = blks;
+   data.sg = 
+   data.sg_len = 1;
+   data.flags  = data_type;
+   mmc_set_data_timeout(, card);
+
+   mmc_wait_for_req(card->host, );
+
+   if (cmd.error) {
+   dev_err(mmc_dev(card->host), "cmd error (%d)\n", cmd.error);
+   return cmd.error;
+   }
+
+   if (data.error) {
+   dev_err(mmc_dev(card->host), "data error (%d)\n", data.error);
+   return data.error;
+   }
+
+   err = mmc_blk_rpmb_status_poll(card, , 5);
+   if (err)
+   dev_err(mmc_dev(card->host), "Card Status=0x%08X, error %d\n",
+   status, err);
+   return err;
+}
+
+static int mmc_blk_rpmb_sequence(struct mmc_card *card,
+struct rpmb_cmd *cmds, u32 ncmds)
+{
+   int err, i;
+   struct rpmb_cmd *cmd;
+   unsigned int data_type;
+   bool do_rel_wr;
+
+   for (err = 0, i = 0; i < ncmds && !err; i++) {
+   cmd = [i];
+   if (cmd->flags & RPMB_F_WRITE) {
+   data_type = MMC_DATA_WRITE;
+   do_rel_wr = !!(cmd->flags & RPMB_F_REL_WRITE);
+   } else {
+   data_type = MMC_DATA_READ;
+  

[PATCH v6 7/9] tools rpmb: add RPBM access tool

2016-09-13 Thread Tomas Winkler
Add simple RPMB host testing tool. It can be used
to program key, write and read data block, and retrieve
write counter.

Signed-off-by: Tomas Winkler 
---
V2: resend
V3: fix missing objtool
V4: add verbose option
V5: 1. Adjust to the new API.
2. Exercise both request and sequence ioctls.
V6: 1. Add includes to openssl/rand.h and endian.h
2. Fix some signed, unsigned comparisons
3. Check results more thoroughly
4. use HOSTCFLAGS in compilation
5. Allocate frames dynamically.

 MAINTAINERS   |1 +
 tools/Makefile|   14 +-
 tools/rpmb/.gitignore |2 +
 tools/rpmb/Makefile   |   34 ++
 tools/rpmb/rpmb.c | 1031 +
 5 files changed, 1077 insertions(+), 5 deletions(-)
 create mode 100644 tools/rpmb/.gitignore
 create mode 100644 tools/rpmb/Makefile
 create mode 100644 tools/rpmb/rpmb.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a092b90add3..786ed2a1d2bf 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10002,6 +10002,7 @@ F:  drivers/char/rpmb/*
 F: include/uapi/linux/rpmb.h
 F: include/linux/rpmb.h
 F: Documentation/ABI/testing/sysfs-class-rpmb
+F: tools/rpmb/
 
 RTL2830 MEDIA DRIVER
 M: Antti Palosaari 
diff --git a/tools/Makefile b/tools/Makefile
index daa8fb3e4363..1d481b78063f 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -20,6 +20,7 @@ help:
@echo '  lguest - a minimal 32-bit x86 hypervisor'
@echo '  net- misc networking tools'
@echo '  perf   - Linux performance measurement and 
analysis tool'
+   @echo '  rpmb   - Replay protected memory block access 
tool'
@echo '  selftests  - various kernel selftests'
@echo '  spi- spi tools'
@echo '  objtool- an ELF object analysis tool'
@@ -56,7 +57,7 @@ acpi: FORCE
 cpupower: FORCE
$(call descend,power/$@)
 
-cgroup firewire hv guest spi usb virtio vm net iio gpio objtool: FORCE
+cgroup firewire hv guest rpmb spi usb virtio vm net iio gpio objtool: FORCE
$(call descend,$@)
 
 liblockdep: FORCE
@@ -86,7 +87,7 @@ freefall: FORCE
$(call descend,laptop/$@)
 
 all: acpi cgroup cpupower gpio hv firewire lguest \
-   perf selftests turbostat usb \
+   perf rpmb selftests turbostat usb \
virtio vm net x86_energy_perf_policy \
tmon freefall objtool
 
@@ -96,7 +97,7 @@ acpi_install:
 cpupower_install:
$(call descend,power/$(@:_install=),install)
 
-cgroup_install firewire_install gpio_install hv_install lguest_install 
perf_install usb_install virtio_install vm_install net_install objtool_install:
+cgroup_install firewire_install gpio_install hv_install lguest_install 
perf_install rpmb_install usb_install virtio_install vm_install net_install 
objtool_install:
$(call descend,$(@:_install=),install)
 
 selftests_install:
@@ -116,7 +117,7 @@ kvm_stat_install:
 
 install: acpi_install cgroup_install cpupower_install gpio_install \
hv_install firewire_install lguest_install \
-   perf_install selftests_install turbostat_install usb_install \
+   perf_install rpmb_install selftests_install turbostat_install 
usb_install \
virtio_install vm_install net_install 
x86_energy_perf_policy_install \
tmon_install freefall_install objtool_install kvm_stat_install
 
@@ -145,6 +146,9 @@ perf_clean:
$(Q)mkdir -p $(PERF_O) .
$(Q)$(MAKE) --no-print-directory -C perf O=$(PERF_O) subdir= clean
 
+rpmb_clean:
+   $(call descend,$(@:_clean=),clean)
+
 selftests_clean:
$(call descend,testing/$(@:_clean=),clean)
 
@@ -161,7 +165,7 @@ build_clean:
$(call descend,build,clean)
 
 clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean 
lguest_clean \
-   perf_clean selftests_clean turbostat_clean spi_clean usb_clean 
virtio_clean \
+   perf_clean rpmb_clean selftests_clean turbostat_clean spi_clean 
usb_clean virtio_clean \
vm_clean net_clean iio_clean x86_energy_perf_policy_clean 
tmon_clean \
freefall_clean build_clean libbpf_clean libsubcmd_clean 
liblockdep_clean \
gpio_clean objtool_clean
diff --git a/tools/rpmb/.gitignore b/tools/rpmb/.gitignore
new file mode 100644
index ..218f680548e6
--- /dev/null
+++ b/tools/rpmb/.gitignore
@@ -0,0 +1,2 @@
+*.o
+rpmb
diff --git a/tools/rpmb/Makefile b/tools/rpmb/Makefile
new file mode 100644
index ..debb5a6bc208
--- /dev/null
+++ b/tools/rpmb/Makefile
@@ -0,0 +1,34 @@
+CC = $(CROSS_COMPILE)gcc
+LD = $(CROSS_COMPILE)ld
+PKG_CONFIG = $(CROSS_COMPILE)pkg-config
+
+ifeq ($(srctree),)
+srctree := $(patsubst %/,%,$(dir $(shell pwd)))
+srctree := $(patsubst %/,%,$(dir $(srctree)))
+#$(info Determined 'srctree' to be $(srctree))

[PATCH v6 1/9] rpmb: add Replay Protected Memory Block (RPMB) subsystem

2016-09-13 Thread Tomas Winkler
Few storage technologies such is EMMC, UFS, and NVMe support RPMB
hardware partition with common protocol and frame layout.
The RPMB partition cannot be accessed via standard block layer,
but by a set of specific commands: WRITE, READ, GET_WRITE_COUNTER,
and PROGRAM_KEY.
Such a partition provides authenticated and replay protected access,
hence suitable as a secure storage.

The RPMB layer aims to provide in-kernel API for Trusted Execution
Environment (TEE) devices that are capable to securely compute block
frame signature. In case a TEE device wish to store a replay protected
data, it creates an RPMB frame with requested data and computes HMAC of
the frame, then it requests the storage device via RPMB layer to store
the data.
A TEE device driver can claim the RPMB interface, for example, via
class_interface_register ().
The layer provides two APIs rpmb_cmd_req() for issuing one of RPMB
specific commands and rpmb_cmd_seq() for issuing of raw RPMB protocol
frames sequence.
The major difference between the APIs is that for rpmb_cmd_req() the
framework performs RPMB_RESULT_READ operation on behalf of a user.
The RPMB_RESULT_READ is used for retrieving result of the commands
that carry data in the write cycle and need one more step to retrieve
the result.

A storage device registers its RPMB (eMMC) partition or RPMB
W-LUN (UFS) with the RPMB layer providing an implementation for
rpmb_cmd_seq() handler. The interface enables sending sequence of RPMB
standard frames.

Signed-off-by: Tomas Winkler 
Signed-off-by: Alexander Usyskin 
---
V2: added short workflow description in the commit message
V3: commit message fix
V4: resend
V5: add rpmb sequence interface.
V6: 1. More info in the commit message
2. Define simulation device type

 MAINTAINERS|   7 +
 drivers/char/Kconfig   |   2 +
 drivers/char/Makefile  |   1 +
 drivers/char/rpmb/Kconfig  |   8 +
 drivers/char/rpmb/Makefile |   4 +
 drivers/char/rpmb/core.c   | 414 +
 include/linux/rpmb.h   | 232 +
 7 files changed, 668 insertions(+)
 create mode 100644 drivers/char/rpmb/Kconfig
 create mode 100644 drivers/char/rpmb/Makefile
 create mode 100644 drivers/char/rpmb/core.c
 create mode 100644 include/linux/rpmb.h

diff --git a/MAINTAINERS b/MAINTAINERS
index bd69bc0ed717..d6f5f134f55d 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9994,6 +9994,13 @@ F:   include/net/rose.h
 F: include/uapi/linux/rose.h
 F: net/rose/
 
+RPMB SUBSYSTEM
+M: Tomas Winkler 
+L: linux-ker...@vger.kernel.org
+S: Supported
+F: drivers/char/rpmb/*
+F: include/linux/rpmb.h
+
 RTL2830 MEDIA DRIVER
 M: Antti Palosaari 
 L: linux-me...@vger.kernel.org
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index dcc09739a54e..f2f4e0474ee6 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -590,5 +590,7 @@ config TILE_SROM
 
 source "drivers/char/xillybus/Kconfig"
 
+source "drivers/char/rpmb/Kconfig"
+
 endmenu
 
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 6e6c244a66a0..3a0cac3ff2dc 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -60,3 +60,4 @@ js-rtc-y = rtc.o
 obj-$(CONFIG_TILE_SROM)+= tile-srom.o
 obj-$(CONFIG_XILLYBUS) += xillybus/
 obj-$(CONFIG_POWERNV_OP_PANEL) += powernv-op-panel.o
+obj-$(CONFIG_RPMB) += rpmb/
diff --git a/drivers/char/rpmb/Kconfig b/drivers/char/rpmb/Kconfig
new file mode 100644
index ..c5e6e909efce
--- /dev/null
+++ b/drivers/char/rpmb/Kconfig
@@ -0,0 +1,8 @@
+config RPMB
+   tristate "RPMB partition interface"
+   help
+ Unified RPMB partition interface for eMMC and UFS.
+ Provides interface for in kernel security controllers to
+ access RPMB partition.
+
+ If unsure, select N.
diff --git a/drivers/char/rpmb/Makefile b/drivers/char/rpmb/Makefile
new file mode 100644
index ..812b3ed264c0
--- /dev/null
+++ b/drivers/char/rpmb/Makefile
@@ -0,0 +1,4 @@
+obj-$(CONFIG_RPMB) += rpmb.o
+rpmb-objs += core.o
+
+ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/char/rpmb/core.c b/drivers/char/rpmb/core.c
new file mode 100644
index ..ff10cbb7b644
--- /dev/null
+++ b/drivers/char/rpmb/core.c
@@ -0,0 +1,414 @@
+/*
+ * Copyright (C) 2015-2016 Intel Corp. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 

[PATCH v6 9/9] scsi: ufs: connect to RPMB subsystem

2016-09-13 Thread Tomas Winkler
Register UFS RPMB LUN with the RPMB subsystem and provide
implementation for the RPMB access operations. RPMB partition is
accessed via a sequence of security protocol in and security protocol
out commands with UFS specific parameters. This multi step process is
abstracted into 4 basic RPMB commands.

Signed-off-by: Alexander Usyskin 
Signed-off-by: Tomas Winkler 
---
V2: resend
V3: resend
V4: Kconfig: use select RPMB to ensure valid configuration
V5: Revamp code using new sequence command.
V5: resend

 drivers/scsi/ufs/Kconfig  |   1 +
 drivers/scsi/ufs/ufshcd.c | 183 ++
 drivers/scsi/ufs/ufshcd.h |   2 +
 3 files changed, 186 insertions(+)

diff --git a/drivers/scsi/ufs/Kconfig b/drivers/scsi/ufs/Kconfig
index 47966909286d..86bbf3a16dbf 100644
--- a/drivers/scsi/ufs/Kconfig
+++ b/drivers/scsi/ufs/Kconfig
@@ -38,6 +38,7 @@ config SCSI_UFSHCD
select PM_DEVFREQ
select DEVFREQ_GOV_SIMPLE_ONDEMAND
select NLS
+   select RPMB
---help---
This selects the support for UFS devices in Linux, say Y and make
  sure that you know the name of your UFS host adapter (the card
diff --git a/drivers/scsi/ufs/ufshcd.c b/drivers/scsi/ufs/ufshcd.c
index f08d41a2d70b..2a18e6b26641 100644
--- a/drivers/scsi/ufs/ufshcd.c
+++ b/drivers/scsi/ufs/ufshcd.c
@@ -37,10 +37,13 @@
  * license terms, and distributes only under these terms.
  */
 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+
 #include "ufshcd.h"
 #include "ufs_quirks.h"
 #include "unipro.h"
@@ -4750,6 +4753,178 @@ static void ufshcd_init_icc_levels(struct ufs_hba *hba)
 
 }
 
+#define SEC_PROTOCOL_UFS  0xEC
+#define   SEC_SPECIFIC_UFS_RPMB 0x0001
+
+#define SEC_PROTOCOL_CMD_SIZE 12
+#define SEC_PROTOCOL_RETRIES 3
+#define SEC_PROTOCOL_RETRIES_ON_RESET 10
+#define SEC_PROTOCOL_TIMEOUT msecs_to_jiffies(1000)
+
+static int
+ufshcd_rpmb_security_out(struct scsi_device *sdev,
+struct rpmb_frame *frames, u32 cnt)
+{
+   struct scsi_sense_hdr sshdr;
+   u32 trans_len = cnt * sizeof(struct rpmb_frame);
+   int reset_retries = SEC_PROTOCOL_RETRIES_ON_RESET;
+   int ret;
+   u8 cmd[SEC_PROTOCOL_CMD_SIZE];
+
+   memset(cmd, 0, SEC_PROTOCOL_CMD_SIZE);
+   cmd[0] = SECURITY_PROTOCOL_OUT;
+   cmd[1] = SEC_PROTOCOL_UFS;
+   put_unaligned_be16(SEC_SPECIFIC_UFS_RPMB, cmd + 2);
+   cmd[4] = 0;  /* inc_512 bit 7 set to 0 */
+   put_unaligned_be32(trans_len, cmd + 6);  /* transfer length */
+
+retry:
+   ret = scsi_execute_req_flags(sdev, cmd, DMA_TO_DEVICE,
+frames, trans_len, ,
+SEC_PROTOCOL_TIMEOUT, SEC_PROTOCOL_RETRIES,
+NULL, 0);
+
+   if (ret && scsi_sense_valid() &&
+   sshdr.sense_key == UNIT_ATTENTION &&
+   sshdr.asc == 0x29 && sshdr.ascq == 0x00)
+   /*
+* Device reset might occur several times,
+* give it one more chance
+*/
+   if (--reset_retries > 0)
+   goto retry;
+
+   if (ret)
+   dev_err(>sdev_gendev, "%s: failed with err %0x\n",
+   __func__, ret);
+
+   if (driver_byte(ret) & DRIVER_SENSE)
+   scsi_print_sense_hdr(sdev, "rpmb: security out", );
+
+   return ret;
+}
+
+static int
+ufshcd_rpmb_security_in(struct scsi_device *sdev,
+   struct rpmb_frame *frames, u32 cnt)
+{
+   struct scsi_sense_hdr sshdr;
+   u32 alloc_len = cnt * sizeof(struct rpmb_frame);
+   int reset_retries = SEC_PROTOCOL_RETRIES_ON_RESET;
+   int ret;
+   u8 cmd[SEC_PROTOCOL_CMD_SIZE];
+
+   memset(cmd, 0, SEC_PROTOCOL_CMD_SIZE);
+   cmd[0] = SECURITY_PROTOCOL_IN;
+   cmd[1] = SEC_PROTOCOL_UFS;
+   put_unaligned_be16(SEC_SPECIFIC_UFS_RPMB, cmd + 2);
+   cmd[4] = 0; /* inc_512 bit 7 set to 0 */
+   put_unaligned_be32(alloc_len, cmd + 6); /* allocation length */
+
+retry:
+   ret = scsi_execute_req_flags(sdev, cmd, DMA_FROM_DEVICE,
+frames, alloc_len, ,
+SEC_PROTOCOL_TIMEOUT, SEC_PROTOCOL_RETRIES,
+NULL, 0);
+
+   if (ret && scsi_sense_valid() &&
+   sshdr.sense_key == UNIT_ATTENTION &&
+   sshdr.asc == 0x29 && sshdr.ascq == 0x00)
+   /*
+* Device reset might occur several times,
+* give it one more chance
+   */
+   if (--reset_retries > 0)
+   goto retry;
+
+   if (ret)
+   dev_err(>sdev_gendev, "%s: failed with err %0x\n",
+   __func__, ret);
+
+   if (driver_byte(ret) & DRIVER_SENSE)
+   

[PATCH v6 5/9] char: rpmb: provide a user space interface

2016-09-13 Thread Tomas Winkler
The user space API is achieved via two synchronous IOCTLs.
Simplified one, RPMB_IOC_REQ_CMD, were read result cycles is performed
by the framework on behalf the user and second, RPMB_IOC_SEQ_CMD where
the whole RPMB sequence including RESULT_READ is supplied by the caller.
The latter is intended for easier adjusting of the applications that
use MMC_IOC_MULTI_CMD ioctl.

Signed-off-by: Tomas Winkler 
---
V2: use memdup_user
V3: commit message fix
V4: resend
V5: 1. Add RPMB_IOC_SEQ_CMD API.
2. Export uapi rpmb.h header
V6: 1. remove #include 
2. Add ioctl documentation

 Documentation/ioctl/ioctl-number.txt |   1 +
 MAINTAINERS  |   1 +
 drivers/char/rpmb/Kconfig|   7 +
 drivers/char/rpmb/Makefile   |   1 +
 drivers/char/rpmb/cdev.c | 317 +++
 drivers/char/rpmb/core.c |   9 +-
 drivers/char/rpmb/rpmb-cdev.h|  25 +++
 include/linux/rpmb.h |  81 +
 include/uapi/linux/Kbuild|   1 +
 include/uapi/linux/rpmb.h| 152 +
 10 files changed, 521 insertions(+), 74 deletions(-)
 create mode 100644 drivers/char/rpmb/cdev.c
 create mode 100644 drivers/char/rpmb/rpmb-cdev.h
 create mode 100644 include/uapi/linux/rpmb.h

diff --git a/Documentation/ioctl/ioctl-number.txt 
b/Documentation/ioctl/ioctl-number.txt
index 81c7f2bb7daf..f645543866c7 100644
--- a/Documentation/ioctl/ioctl-number.txt
+++ b/Documentation/ioctl/ioctl-number.txt
@@ -321,6 +321,7 @@ Code  Seq#(hex) Include FileComments
 0xB1   00-1F   PPPoX   
 0xB3   00  linux/mmc/ioctl.h
 0xB4   00-0F   linux/gpio.h
+0xB5   00-01   linux/uapi/linux/rpmb.h 
 0xC0   00-0F   linux/usb/iowarrior.h
 0xCA   00-0F   uapi/misc/cxl.h
 0xCA   80-8F   uapi/scsi/cxlflash_ioctl.h
diff --git a/MAINTAINERS b/MAINTAINERS
index d701a972c83a..3a092b90add3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -,6 +,7 @@ M:Tomas Winkler 
 L: linux-ker...@vger.kernel.org
 S: Supported
 F: drivers/char/rpmb/*
+F: include/uapi/linux/rpmb.h
 F: include/linux/rpmb.h
 F: Documentation/ABI/testing/sysfs-class-rpmb
 
diff --git a/drivers/char/rpmb/Kconfig b/drivers/char/rpmb/Kconfig
index c5e6e909efce..6794be9fcc5e 100644
--- a/drivers/char/rpmb/Kconfig
+++ b/drivers/char/rpmb/Kconfig
@@ -6,3 +6,10 @@ config RPMB
  access RPMB partition.
 
  If unsure, select N.
+
+config RPMB_INTF_DEV
+   bool "RPMB character device interface /dev/rpmbN"
+   depends on RPMB
+   help
+ Say yes here if you want to access RPMB from user space
+ via character device interface /dev/rpmb%d
diff --git a/drivers/char/rpmb/Makefile b/drivers/char/rpmb/Makefile
index 812b3ed264c0..b5dc087b1299 100644
--- a/drivers/char/rpmb/Makefile
+++ b/drivers/char/rpmb/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_RPMB) += rpmb.o
 rpmb-objs += core.o
+rpmb-$(CONFIG_RPMB_INTF_DEV) += cdev.o
 
 ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/char/rpmb/cdev.c b/drivers/char/rpmb/cdev.c
new file mode 100644
index ..837c32e722ec
--- /dev/null
+++ b/drivers/char/rpmb/cdev.c
@@ -0,0 +1,317 @@
+/*
+ * Copyright (C) 2015-2016 Intel Corp. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "rpmb-cdev.h"
+
+static dev_t rpmb_devt;
+#define RPMB_MAX_DEVS  MINORMASK
+
+#define RPMB_DEV_OPEN0  /** single open bit (position) */
+/* from MMC_IOC_MAX_CMDS */
+#define RPMB_MAX_FRAMES 255
+
+/**
+ * rpmb_open - the open function
+ *
+ * @inode: pointer to inode structure
+ * @fp: pointer to file structure
+ *
+ * Return: 0 on success, <0 on error
+ */
+static int rpmb_open(struct inode *inode, struct file *fp)
+{
+   struct rpmb_dev *rdev;
+
+   rdev = container_of(inode->i_cdev, struct rpmb_dev, cdev);
+   if (!rdev)
+   return -ENODEV;
+
+   /* the rpmb is single open! */
+   if (test_and_set_bit(RPMB_DEV_OPEN, >status))
+   return -EBUSY;
+
+   mutex_lock(>lock);
+
+   fp->private_data = rdev;
+
+   mutex_unlock(>lock);
+
+   return nonseekable_open(inode, fp);
+}
+
+/**
+ * rpmb_open - the open function
+ *
+ * @inode: pointer to inode structure
+ * @fp: pointer to file 

[PATCH v6 3/9] rpmb: add sysfs-class ABI documentation

2016-09-13 Thread Tomas Winkler
Signed-off-by: Tomas Winkler 
---
V2: resend
V3: add more verbose description
V4: resend
V5: adjust date and kernel version
V6: adjust date and kernel version

 Documentation/ABI/testing/sysfs-class-rpmb | 20 
 MAINTAINERS|  1 +
 2 files changed, 21 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-rpmb

diff --git a/Documentation/ABI/testing/sysfs-class-rpmb 
b/Documentation/ABI/testing/sysfs-class-rpmb
new file mode 100644
index ..9b840e660274
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-rpmb
@@ -0,0 +1,20 @@
+What:  /sys/class/rpmb/
+Date:  Sep 2016
+KernelVersion:  4.9
+Contact:   Tomas Winkler 
+Description:
+   The rpmb/ class sub-directory belongs to RPMB device class.
+
+   Few storage technologies such is EMMC, UFS, and NVMe support
+   Replay Protected Memory Block (RPMB) hardware partition with
+   common protocol and frame layout.
+   Such a partition provides authenticated and replay protected 
access,
+   hence suitable as a secure storage.
+
+What:  /sys/class/rpmb/rpmbN/
+Date:  Sep 2016
+KernelVersion: 4.9
+Contact:   Tomas Winkler 
+Description:
+   The /sys/class/rpmb/rpmbN directory is created for
+   each RPMB registered device.
diff --git a/MAINTAINERS b/MAINTAINERS
index d6f5f134f55d..d701a972c83a 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1,6 +1,7 @@ L:  linux-ker...@vger.kernel.org
 S: Supported
 F: drivers/char/rpmb/*
 F: include/linux/rpmb.h
+F: Documentation/ABI/testing/sysfs-class-rpmb
 
 RTL2830 MEDIA DRIVER
 M: Antti Palosaari 
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 4/9] char: rpmb: add device attributes

2016-09-13 Thread Tomas Winkler
Add attribute type that displays underlay storage type technology
EMMC, UFS, and attribute id, that displays underlay storage device id.
For EMMC this would be content of CID and for UFS serial number from
the device descriptor.

Signed-off-by: Tomas Winkler 
---
V2: resend
V3: set kernel version to 4.7
V4: update target date to Maj
V5: update date and kernel version
V6: 1. Add simulation device type
2. Update date and kernel version
3. Use binary attribute for id
4. use simple sprintf instead of scnprintf
5. Add more verbose documenation

 Documentation/ABI/testing/sysfs-class-rpmb | 27 +++
 drivers/char/rpmb/core.c   | 72 ++
 2 files changed, 99 insertions(+)

diff --git a/Documentation/ABI/testing/sysfs-class-rpmb 
b/Documentation/ABI/testing/sysfs-class-rpmb
index 9b840e660274..2fe100eb5aa7 100644
--- a/Documentation/ABI/testing/sysfs-class-rpmb
+++ b/Documentation/ABI/testing/sysfs-class-rpmb
@@ -18,3 +18,30 @@ Contact: Tomas Winkler 
 Description:
The /sys/class/rpmb/rpmbN directory is created for
each RPMB registered device.
+
+What:  /sys/class/rpmb/rpmbN/type
+Date:  Sep 2016
+KernelVersion: 4.9
+Contact:   Tomas Winkler 
+Description:
+   The /sys/class/rpmb/rpmbN/type file contains device
+   underlaying storage type technology: EMMC, UFS, SIM.
+
+What:  /sys/class/rpmb/rpmbN/id
+Date:  Sep 2016
+KernelVersion: 4.9
+Contact:   Tomas Winkler 
+Description:
+   The /sys/class/rpmb/rpmbN/id file contains unique device id
+   in a binary form as defined by underlying storage device.
+   In case of multiple RPMB devices a user can determine correct
+   device.
+   The content can be parsed according the storage device type.
+
+What:  /sys/class/rpmb/rpmbN/reliable_wr_cnt
+Date:  Sep 2016
+KernelVersion: 4.9
+Contact:   Tomas Winkler 
+Description:
+   The /sys/class/rpmb/rpmbN/reliable_wr_cnt file contains
+   number of blocks that can be reliable written in a single 
request.
diff --git a/drivers/char/rpmb/core.c b/drivers/char/rpmb/core.c
index 8cfbbb721538..f6b4cabb0982 100644
--- a/drivers/char/rpmb/core.c
+++ b/drivers/char/rpmb/core.c
@@ -338,6 +338,76 @@ struct rpmb_dev *rpmb_dev_find_by_device(struct device 
*parent)
 }
 EXPORT_SYMBOL_GPL(rpmb_dev_find_by_device);
 
+static ssize_t type_show(struct device *dev,
+struct device_attribute *attr, char *buf)
+{
+   struct rpmb_dev *rdev = to_rpmb_dev(dev);
+   ssize_t ret;
+
+   switch (rdev->ops->type) {
+   case RPMB_TYPE_EMMC:
+   ret = sprintf(buf, "EMMC\n");
+   break;
+   case RPMB_TYPE_UFS:
+   ret = sprintf(buf, "UFS\n");
+   break;
+   case RPMB_TYPE_SIM:
+   ret = sprintf(buf, "SIM\n");
+   break;
+   default:
+   ret = sprintf(buf, "UNKNOWN\n");
+   break;
+   }
+
+   return ret;
+}
+static DEVICE_ATTR_RO(type);
+
+static ssize_t id_read(struct file *file, struct kobject *kobj,
+  struct bin_attribute *attr, char *buf,
+  loff_t off, size_t count)
+{
+   struct device *dev = kobj_to_dev(kobj);
+   struct rpmb_dev *rdev = to_rpmb_dev(dev);
+   size_t sz = min_t(size_t, rdev->ops->dev_id_len, PAGE_SIZE);
+
+   if (!rdev->ops->dev_id)
+   return 0;
+
+   return memory_read_from_buffer(buf, count, , rdev->ops->dev_id, sz);
+}
+static BIN_ATTR_RO(id, 0);
+
+static ssize_t reliable_wr_cnt_show(struct device *dev,
+   struct device_attribute *attr, char *buf)
+{
+   struct rpmb_dev *rdev = to_rpmb_dev(dev);
+
+   return sprintf(buf, "%u\n", rdev->ops->reliable_wr_cnt);
+}
+static DEVICE_ATTR_RO(reliable_wr_cnt);
+
+static struct attribute *rpmb_attrs[] = {
+   _attr_type.attr,
+   _attr_reliable_wr_cnt.attr,
+   NULL,
+};
+
+static struct bin_attribute *rpmb_bin_attributes[] = {
+   _attr_id,
+   NULL,
+};
+
+static struct attribute_group rpmb_attr_group = {
+   .attrs = rpmb_attrs,
+   .bin_attrs = rpmb_bin_attributes,
+};
+
+static const struct attribute_group *rpmb_attr_groups[] = {
+   _attr_group,
+   NULL
+};
+
 /**
  * rpmb_dev_unregister - unregister RPMB partition from the RPMB subsystem
  *
@@ -407,6 +477,8 @@ struct rpmb_dev *rpmb_dev_register(struct device *dev,
dev_set_name(>dev, "rpmb%d", id);
rdev->dev.class = _class;
rdev->dev.parent = dev;
+   rdev->dev.groups = rpmb_attr_groups;
+
ret = device_register(>dev);
if (ret)
goto exit;
-- 
2.7.4

--
To unsubscribe from this list: send 

[PATCH v6 6/9] char: rpmb: add RPMB simulation device

2016-09-13 Thread Tomas Winkler
The RPMB partition simulation device is a virtual device that
provides simulation of the RPMB protocol and use kernel memory
as storage.

Be aware it doesn't promise any real security. This driver is
suitable only for testing of the RPMB subsystem or RPMB
applications prior to RPMB key provisioning, as RPMB key
programming can be perfomed only once in the life time of the
storage device.

The module currently supports two configuration options via
module parameters
1. max_wr_blks: for specifying max blocks that can be written
in a single command
2. daunits:  used to set storage capacity in 128K units.

V2: remove .owner setting, it is set automatically
V3: 1. Add shutdown handler (similar to ufshcd)
2. Commit message fix
V4: Use select RPMB in Kconfg to ensure valid configuration.
V5: Revamp the code using the sequence command.
V6: 1. Be more verbose about some errors, after all this is a testing
module.
2. Fix RPMB_READ_DATA:
   a. The number of blocks for eMMC request frame should be 0
   b. Fix missing return before bailing on error
   c. Copy all the frames back
3. Fix RPMB_WRITE_DATA:
   a. Compute MAC on result packet
   b. Also address should be set in the result frame.
4. Remove platform device
5. Update the commit message

Signed-off-by: Tomas Winkler 
---
 drivers/char/rpmb/Kconfig|  17 +
 drivers/char/rpmb/Makefile   |   1 +
 drivers/char/rpmb/rpmb_sim.c | 744 +++
 3 files changed, 762 insertions(+)
 create mode 100644 drivers/char/rpmb/rpmb_sim.c

diff --git a/drivers/char/rpmb/Kconfig b/drivers/char/rpmb/Kconfig
index 6794be9fcc5e..533d813e9ed5 100644
--- a/drivers/char/rpmb/Kconfig
+++ b/drivers/char/rpmb/Kconfig
@@ -13,3 +13,20 @@ config RPMB_INTF_DEV
help
  Say yes here if you want to access RPMB from user space
  via character device interface /dev/rpmb%d
+
+
+config RPMB_SIM
+   tristate "RPMB partition device simulator"
+   default n
+   select RPMB
+   select CRYPTO_SHA256
+   select CRYPTO_HMAC
+   help
+ RPMB partition simulation device is a virtual device that
+ provides simulation of the RPMB protocol and use kernel memory
+ as storage.
+
+ Be aware it doesn't promise any real security. This driver is
+ suitable only for testing of the RPMB subsystem or RPMB applications
+ prior to RPMB key provisioning.
+  Most people should say N here.
diff --git a/drivers/char/rpmb/Makefile b/drivers/char/rpmb/Makefile
index b5dc087b1299..81f924fd9a87 100644
--- a/drivers/char/rpmb/Makefile
+++ b/drivers/char/rpmb/Makefile
@@ -1,5 +1,6 @@
 obj-$(CONFIG_RPMB) += rpmb.o
 rpmb-objs += core.o
 rpmb-$(CONFIG_RPMB_INTF_DEV) += cdev.o
+obj-$(CONFIG_RPMB_SIM) += rpmb_sim.o
 
 ccflags-y += -D__CHECK_ENDIAN__
diff --git a/drivers/char/rpmb/rpmb_sim.c b/drivers/char/rpmb/rpmb_sim.c
new file mode 100644
index ..429a08bd67d7
--- /dev/null
+++ b/drivers/char/rpmb/rpmb_sim.c
@@ -0,0 +1,744 @@
+/**
+ * This file is provided under a dual BSD/GPLv2 license.  When using or
+ * redistributing this file, you may do so under either license.
+ *
+ * GPL LICENSE SUMMARY
+ *
+ * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * The full GNU General Public License is included in this distribution
+ * in the file called LICENSE.GPL.
+ *
+ * Contact Information:
+ * Intel Corporation.
+ * linux-...@linux.intel.com
+ * http://www.intel.com
+ *
+ * BSD LICENSE
+ *
+ * Copyright(c) 2016 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ *  * Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in
+ *the documentation and/or other materials provided with the
+ *distribution.
+ *  * Neither the name Intel Corporation nor the names of its
+ *contributors may be used to endorse or promote products derived
+ *from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS 

[PATCH v6 0/9] Replay Protected Memory Block (RPMB) subsystem

2016-09-13 Thread Tomas Winkler

Few storage technologies such is EMMC, UFS, and NVMe support RPMB
hardware partition with common protocol and frame layout.
The RPMB partition cannot be accessed via standard block layer, but by a
set of specific commands: WRITE, READ, GET_WRITE_COUNTER, and
PROGRAM_KEY.
Such a partition provides authenticated and replay protected access,
hence suitable as a secure storage.

The RPMB layer aims to provide in-kernel API for Trusted Execution
Environment (TEE) devices that are capable to securely compute block
frame signature. In case a TEE device wish to store a replay protected
data, it creates an RPMB frame with requested data and computes HMAC of
the frame, then it requests the storage device via RPMB layer to store
the data.

The layer provides two APIs, for rpmb_req_cmd() for issuing one of RPMB
specific commands and rpmb_seq_cmd() for issuing of raw RPMB protocol
frames,  which is close to the functionality provided by emmc multi ioctl
interface.

A TEE driver can claim the RPMB interface, for example, via
class_interface_register ().

A storage device registers its RPMB hardware (eMMC) partition or RPMB
W-LUN (UFS) with the RPMB layer providing an implementation for
rpmb_seq_cmd() handler. The interface enables sending sequence of RPMB
standard frames.

A parallel user space API is provided via /dev/rpmbX character
device with two IOCTL commands.
Simplified one, RPMB_IOC_REQ_CMD, were read result cycles is performed
by the framework on behalf the user and second, RPMB_IOC_SEQ_CMD where
the whole RPMB sequence, including RESULT_READ is supplied by the caller.
The latter is intended for easier adjusting of the applications that
use MMC_IOC_MULTI_CMD ioctl, such as
https://android.googlesource.com/trusty/app/storage/

There is a also sample tool under tools/rpmb/ directory that exercises
these interfaces and a simulation device that implements the device part.

The code is also available from:

https://github.com/tomasbw/linux-mei.git rpmb

Tomas Winkler (9):
  rpmb: add Replay Protected Memory Block (RPMB) subsystem
  rpmb: enable emmc specific read data fixup
  rpmb: add sysfs-class ABI documentation
  char: rpmb: add device attributes
  char: rpmb: provide a user space interface
  char: rpmb: add RPMB simulation device
  tools rpmb: add RPBM access tool
  mmc: block: register RPMB partition with the RPMB subsystem
  scsi: ufs: connect to RPMB subsystem

 Documentation/ABI/testing/sysfs-class-rpmb |   47 ++
 Documentation/ioctl/ioctl-number.txt   |1 +
 MAINTAINERS|   10 +
 drivers/char/Kconfig   |2 +
 drivers/char/Makefile  |1 +
 drivers/char/rpmb/Kconfig  |   32 +
 drivers/char/rpmb/Makefile |6 +
 drivers/char/rpmb/cdev.c   |  317 +
 drivers/char/rpmb/core.c   |  523 ++
 drivers/char/rpmb/rpmb-cdev.h  |   25 +
 drivers/char/rpmb/rpmb_sim.c   |  744 
 drivers/mmc/card/Kconfig   |1 +
 drivers/mmc/card/block.c   |  258 ++-
 drivers/scsi/ufs/Kconfig   |1 +
 drivers/scsi/ufs/ufshcd.c  |  183 +
 drivers/scsi/ufs/ufshcd.h  |2 +
 include/linux/rpmb.h   |  167 +
 include/uapi/linux/Kbuild  |1 +
 include/uapi/linux/rpmb.h  |  152 
 tools/Makefile |   14 +-
 tools/rpmb/.gitignore  |2 +
 tools/rpmb/Makefile|   34 +
 tools/rpmb/rpmb.c  | 1031 
 23 files changed, 3546 insertions(+), 8 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-rpmb
 create mode 100644 drivers/char/rpmb/Kconfig
 create mode 100644 drivers/char/rpmb/Makefile
 create mode 100644 drivers/char/rpmb/cdev.c
 create mode 100644 drivers/char/rpmb/core.c
 create mode 100644 drivers/char/rpmb/rpmb-cdev.h
 create mode 100644 drivers/char/rpmb/rpmb_sim.c
 create mode 100644 include/linux/rpmb.h
 create mode 100644 include/uapi/linux/rpmb.h
 create mode 100644 tools/rpmb/.gitignore
 create mode 100644 tools/rpmb/Makefile
 create mode 100644 tools/rpmb/rpmb.c

-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH] scsi: megaraid_sas: add in missing white space in error message text

2016-09-13 Thread Sumit Saxena
>-Original Message-
>From: Colin King [mailto:colin.k...@canonical.com]
>Sent: Monday, September 12, 2016 6:12 PM
>To: Kashyap Desai; Sumit Saxena; Uday Lingala; James E . J . Bottomley;
>Martin K
>. Petersen; megaraidlinux@avagotech.com; linux-scsi@vger.kernel.org
>Cc: linux-ker...@vger.kernel.org
>Subject: [PATCH] scsi: megaraid_sas: add in missing white space in error
>message
>text
>
>From: Colin Ian King 
>
>A dev_printk message spans two lines and the literal string is missing a
>white
>space between words. Add the white space.
>
>Signed-off-by: Colin Ian King 
>---
> drivers/scsi/megaraid/megaraid_sas_base.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
>diff --git a/drivers/scsi/megaraid/megaraid_sas_base.c
>b/drivers/scsi/megaraid/megaraid_sas_base.c
>index 2d62d71..c236c4d 100644
>--- a/drivers/scsi/megaraid/megaraid_sas_base.c
>+++ b/drivers/scsi/megaraid/megaraid_sas_base.c
>@@ -5782,7 +5782,7 @@ static int megasas_probe_one(struct pci_dev *pdev,
>>consumer_h);
>
>   if (!instance->producer || !instance->consumer) {
>-  dev_printk(KERN_DEBUG, >dev, "Failed to
>allocate"
>+  dev_printk(KERN_DEBUG, >dev, "Failed to
>allocate "
>  "memory for producer, consumer\n");
>   goto fail_alloc_dma_buf;
>   }
Acked-by: Sumit Saxena 
>--
>2.9.3
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Question] Calling request_firmware under the spinlocks in file advansys.c

2016-09-13 Thread Vaishali Thakkar
Hi,

In the file drivers/scsi/advansys.c we are calling function AdvISR at 2 
instances
[in the function advansys_reset and advansys_interrupt] while holding spinlock.
Function AdvISR eventually calls request_firmware following this sequence of
routines: 

AdvISR -> adv_async_callback -> AdvResetChipAndSB -> AdvInitAsc3550Driver ->
request_firmware

According to the definition of request_firmware it should be called from user
context where sleeping is allowed. And usually sleeping under the spin lock is
not allowed. Is it really necessary to call AdvISR under spinlocks here? Are
we taking care of sleeping related concern of request_firmware or am I
overlooking something here?

Thank you.

-- 
Vaishali
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/3] virtio_scsi: use complete() instead complete_all()

2016-09-13 Thread Daniel Wagner
From: Daniel Wagner 

There is only one waiter for the completion, therefore there is no need
to use complete_all(). Let's make that clear by using complete() instead
of complete_all().

The usage pattern of the completion is:

waiter context  waker context

virtscsi_tmf()
  DECLARE_COMPLETION_ONSTACK()
  virtscsi_kick_cmd()
  wait_for_completion()

virtscsi_complete_free()
  complete()

Signed-off-by: Daniel Wagner 
---
 drivers/scsi/virtio_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c
index 7dbbb29..86924ff 100644
--- a/drivers/scsi/virtio_scsi.c
+++ b/drivers/scsi/virtio_scsi.c
@@ -258,7 +258,7 @@ static void virtscsi_complete_free(struct virtio_scsi 
*vscsi, void *buf)
struct virtio_scsi_cmd *cmd = buf;
 
if (cmd->comp)
-   complete_all(cmd->comp);
+   complete(cmd->comp);
 }
 
 static void virtscsi_ctrl_done(struct virtqueue *vq)
-- 
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/3] sym53c8xx_2: use complete() instead complete_all()

2016-09-13 Thread Daniel Wagner
From: Daniel Wagner 

There is only one waiter for the completion, therefore there is no need
to use complete_all(). Let's make that clear by using complete() instead
of complete_all().

The usage pattern of the completion is:

waiter context  waker context

sym_eh_handler()
  struct completion eh_done
  init_completion(eh_done)
  pci_channel_offline()
  wait_for_completion_timeout(eh_done)

sym2_io_resume()
  complete(eh_done)

Signed-off-by: Daniel Wagner 
---
 drivers/scsi/sym53c8xx_2/sym_glue.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c 
b/drivers/scsi/sym53c8xx_2/sym_glue.c
index 5d00e51..d32e3ba 100644
--- a/drivers/scsi/sym53c8xx_2/sym_glue.c
+++ b/drivers/scsi/sym53c8xx_2/sym_glue.c
@@ -1874,7 +1874,7 @@ static void sym2_io_resume(struct pci_dev *pdev)
 
spin_lock_irq(shost->host_lock);
if (sym_data->io_reset)
-   complete_all(sym_data->io_reset);
+   complete(sym_data->io_reset);
spin_unlock_irq(shost->host_lock);
 }
 
-- 
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/3] wireless: Use complete() instead complete_all()

2016-09-13 Thread Daniel Wagner
From: Daniel Wagner 

Hi,

Using complete_all() is not wrong per se but it suggest that there
might be more than one waiter. For -rt I am reviewing all
complete_all() users and would like to leave only the real ones in the
tree. The main problem for -rt about complete_all() is that it can be
uses inside IRQ context and that can lead to unbounded amount work
inside the interrupt handler. That is a no no for -rt.

The patches grouped per subsystem and in small batches to allow
reviewing.

Patch #1 fixes a minor bug in the completion API usage. The current code
works but it could work better.

cheers,
daniel

Daniel Wagner (3):
  csiostor: fix completion usage
  sym53c8xx_2: use complete() instead complete_all()
  virtio_scsi: use complete() instead complete_all()

 drivers/scsi/csiostor/csio_scsi.c   | 5 ++---
 drivers/scsi/sym53c8xx_2/sym_glue.c | 2 +-
 drivers/scsi/virtio_scsi.c  | 2 +-
 3 files changed, 4 insertions(+), 5 deletions(-)

-- 
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/3] csiostor: fix completion usage

2016-09-13 Thread Daniel Wagner
From: Daniel Wagner 

The (re)initialzing of the completion object should be done before we
trigger the transfer. Doing this after triggering the hardware opens up
a race window. Without the timeout we would problaly even deadlock. Use
also reinit_completion because we initalize the whole data structure in
csio_scscim_init().

There is only one waiter for the completion, therefore there is no need
to use complete_all(). Let's make that clear by using complete() instead
of complete_all().

The usage pattern of the completion is:

waiter context  waker context

csio_eh_abort_handler()
  reinit_completion()
  wait_for_completion_timeout()

csio_scsi_err_handler()
  complete()

Signed-off-by: Daniel Wagner 
---
 drivers/scsi/csiostor/csio_scsi.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/scsi/csiostor/csio_scsi.c 
b/drivers/scsi/csiostor/csio_scsi.c
index c2a6f9f..89a52b9 100644
--- a/drivers/scsi/csiostor/csio_scsi.c
+++ b/drivers/scsi/csiostor/csio_scsi.c
@@ -1721,7 +1721,7 @@ csio_scsi_err_handler(struct csio_hw *hw, struct 
csio_ioreq *req)
 
/* Wake up waiting threads */
csio_scsi_cmnd(req) = NULL;
-   complete_all(>cmplobj);
+   complete(>cmplobj);
 }
 
 /*
@@ -1945,6 +1945,7 @@ csio_eh_abort_handler(struct scsi_cmnd *cmnd)
ready = csio_is_lnode_ready(ln);
tmo = CSIO_SCSI_ABRT_TMO_MS;
 
+   reinit_completion(>cmplobj);
spin_lock_irq(>lock);
rv = csio_do_abrt_cls(hw, ioreq, (ready ? SCSI_ABORT : SCSI_CLOSE));
spin_unlock_irq(>lock);
@@ -1964,8 +1965,6 @@ csio_eh_abort_handler(struct scsi_cmnd *cmnd)
goto inval_scmnd;
}
 
-   /* Wait for completion */
-   init_completion(>cmplobj);
wait_for_completion_timeout(>cmplobj, msecs_to_jiffies(tmo));
 
/* FW didnt respond to abort within our timeout */
-- 
2.7.4
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] sd: move DIF protection types to t10-pi.h

2016-09-13 Thread Bart Van Assche

On 09/11/2016 07:35 PM, Christoph Hellwig wrote:

These should go together with the rest of the T10 protection
information defintions.


Reviewed-by: Bart Van Assche 
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/3] qla2xxx: use struct t10_pi_tuple

2016-09-13 Thread Bart Van Assche

On 09/11/2016 07:35 PM, Christoph Hellwig wrote:

Instead of defining a local version of it.


Reviewed-by: Bart Van Assche 
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] scsi_debug: use struct t10_pi_tuple instead of struct sd_dif_tuple

2016-09-13 Thread Bart Van Assche

On 09/11/2016 07:35 PM, Christoph Hellwig wrote:

And remove the declaration of the latter in sd.h as scsi_debug was the
only user.


Reviewed-by: Bart Van Assche 
--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html