[PATCH 2/5] arcmsr: Support Hibernation

2013-02-06 Thread NickCheng
From: Nick Cheng nick.ch...@areca.com.tw

Support hibernation for whole series of RAID controllers
Signed-off-by: Nick Cheng nick.ch...@areca.com.tw
---


patch2
Description: Binary data


[PATCH 3/5] arcmsr: Support MSI and MSI-X

2013-02-06 Thread NickCheng
From: Nick Cheng nick.ch...@areca.com.tw

Support MSI or MSI-X for whole series of RAID controllers. Meanwhile correct 
the register access as iowrite32/ioread32 
Signed-off-by: Nick Cheng nick.ch...@areca.com.tw
---


patch3
Description: Binary data


[PATCH 5/5] arcmsr: Modify ARC-1214 Inband Messages Behavior

2013-02-06 Thread NickCheng
From: Nick Cheng nick.ch...@areca.com.tw

Modify ARC-1214 inband messages behavior to make up for HW seldom malfunction.
Signed-off-by: Nick Cheng nick.ch...@areca.com.tw
---


patch5
Description: Binary data


[PATCH RESEND 1/1] Drivers: scsi: storvsc: Initialize the sglist

2013-02-06 Thread K. Y. Srinivasan
Properly initialize scatterlist before using it.

Signed-off-by: K. Y. Srinivasan k...@microsoft.com
Cc: sta...@vger.kernel.org
---
 drivers/scsi/storvsc_drv.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 270b3cf..5ada1d0 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -467,6 +467,7 @@ static struct scatterlist *create_bounce_buffer(struct 
scatterlist *sgl,
if (!bounce_sgl)
return NULL;
 
+   sg_init_table(bounce_sgl, num_pages);
for (i = 0; i  num_pages; i++) {
page_buf = alloc_page(GFP_ATOMIC);
if (!page_buf)
-- 
1.7.4.1

--
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: [SCSI] csiostor: Chelsio FCoE offload driver

2013-02-06 Thread Dan Carpenter
Hopefully, you recieved an email about this last November, but this
is a follow up because the bug is still there.

Smatch complains about a buffer overflow in this:

drivers/scsi/csiostor/csio_rnode.c:872 csio_rnode_fwevt_handler()
error: buffer overflow '(rn)-stats.n_evt_fw' 22 = 26

   859  void
   860  csio_rnode_fwevt_handler(struct csio_rnode *rn, uint8_t fwevt)
   861  {
   862  struct csio_lnode *ln = csio_rnode_to_lnode(rn);
   863  enum csio_rn_ev evt;
   864  
   865  evt = CSIO_FWE_TO_RNFE(fwevt);
   866  if (!evt) {

Events greater than PROTO_ERR_IMPL_LOGO are invalid.

   867  csio_ln_err(ln, ssni:x%x Unhandled FW Rdev event: 
%d\n,
   868  csio_rn_flowid(rn), fwevt);
   869  CSIO_INC_STATS(rn, n_evt_unexp);
   870  return;
   871  }
   872  CSIO_INC_STATS(rn, n_evt_fw[fwevt]);

It looks like new events were added and the size of the n_evt_fw[]
array wasn't updated to hold them.  Everything after RSCN_DEV_LOST
causes memory corruption.

   RSCN_DEV_LOST   = 0x16,
   SCR_ACC_RCVD= 0x17,
   ADISC_RJT_RCVD  = 0x18,
   LOGO_SNT= 0x19,
   PROTO_ERR_IMPL_LOGO = 0x1a,

There is a related bug in the lnode version of this code which
Smatch does not catch.

drivers/scsi/csiostor/csio_lnode.c
  1555  /* save previous event for debugging */
  1556  ln-prev_evt = ln-cur_evt;
  1557  ln-cur_evt = rdev_wr-event_cause;
  1558  CSIO_INC_STATS(ln, 
n_evt_fw[rdev_wr-event_cause]);

^^
Memory corruption.

  1559  
  1560  /* Translate all the fabric events to lnode SM 
events */
  1561  evt = CSIO_FWE_TO_LNE(rdev_wr-event_cause);
  1562  if (evt) {

Valid events handled here but we already corrupted memory three
lines earlier.

  1563  csio_ln_dbg(ln,
  1564  Posting event to lnode 
event:%d 
  1565  cause:%d flowid:x%x\n, evt,
  1566  rdev_wr-event_cause, 
rdev_flowid);
  1567  csio_post_event(ln-sm, evt);
  1568  }
  1569  

I wasn't a part of the discussion in November, but the fix for this
seems trivial.  I'm probably missing something?

regards,
dan carpenter
--
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 v2 00/14] Corrections and customization of the SG_IO command whitelist (CVE-2012-4542)

2013-02-06 Thread Paolo Bonzini
This series regards the whitelist that is used for the SG_IO ioctl.  This
whitelist has three problems:

* the bitmap of allowed commands is designed for MMC devices (roughly,
  play/burn CDs without requiring root) but some opcodes overlap across SCSI
  device classes and have different meanings for different classes.

* also because the bitmap of allowed commands is designed for MMC devices
  only, some commands are missing even though they are generally useful and
  not insecure.  At least not more insecure than anything else you can
  do if you have access to /dev/sdX or /dev/stX nodes.

* the whitelist can be disabled per-process but not per-disk.  In addition,
  the required capability (CAP_SYS_RAWIO) gives access to a range of other 
  resources, enough to make it insecure.

The series corrects these problems.  Patches 1-4 solve the first problem,
which also has an assigned CVE, by using different bitmaps for the various
device classes.  Patches 5-11 solve the second by adding more commands
to the bitmaps.  Patches 12 and 13 solve the third, and were already
posted but ignored by the maintainers despite multiple pings.

Note: checkpatch hates the formatting of the command table.  I know about this,
and ensured that there are no errors in the rest of the code.  The current
formatting is IMHO quite handy, and roughly based on the files available
from the SCSI standard body.

Ok for the next merge window?

Paolo

v1-v2: remove 2 MMC commands and 6 SBC commands (see patches 6 and 9
for details).  Added patch 14 and added a few more scanner
commands based on SANE (scanners are not whitelisted by default,
also were not in v1, but this makes it possible to opt into the
whitelist out of paranoia).  Removed C++ comments.  Removed the
large #if 0'd list of commands that the kernel does not pass
though.  Marked blk_set_cmd_filter_defaults as __init.


Paolo Bonzini (14):
  sg_io: pass request_queue to blk_verify_command
  sg_io: reorganize list of allowed commands
  sg_io: use different default filters for each device class
  sg_io: resolve conflicts between commands assigned to multiple
classes (CVE-2012-4542)
  sg_io: whitelist a few more commands for rare  obsolete device types
  sg_io: whitelist another command for multimedia devices
  sg_io: whitelist a few more commands for media changers
  sg_io: whitelist a few more commands for tapes
  sg_io: whitelist a few more commands for disks
  sg_io: whitelist a few obsolete commands
  sg_io: mark blk_set_cmd_filter_defaults as __init
  sg_io: remove remnants of sysfs SG_IO filters
  sg_io: introduce unpriv_sgio queue flag
  sg_io: use unpriv_sgio to disable whitelisting for scanners

 Documentation/block/queue-sysfs.txt |8 +
 block/blk-sysfs.c   |   33 +++
 block/bsg.c |2 +-
 block/scsi_ioctl.c  |  369 ++-
 drivers/scsi/scsi_scan.c|   14 ++-
 drivers/scsi/sg.c   |6 +-
 include/linux/blkdev.h  |8 +-
 include/linux/genhd.h   |9 -
 include/scsi/scsi.h |3 +
 9 files changed, 344 insertions(+), 108 deletions(-)

--
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 v2 14/14] sg_io: use unpriv_sgio to disable whitelisting for scanners

2013-02-06 Thread Paolo Bonzini
Scanners allow all commands because vendor-specific commands are common.
The queue flag we just added lets us keep this behavior by default,
while making it possible to disable it.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 drivers/scsi/scsi_scan.c |   12 +++-
 drivers/scsi/sg.c|3 ---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 86940f3..702b0ef 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -785,13 +785,23 @@ static int scsi_add_lun(struct scsi_device *sdev, 
unsigned char *inq_result,
sdev-request_queue-sgio_type = sdev-type;
 
switch (sdev-type) {
+   case TYPE_SCANNER:
+   /*
+* Scanners often use(d) vendor-specific commands.  A bunch
+* of them is whitelisted, but just allow everything by
+* default for maximum compatibility.
+*/
+   __set_bit(QUEUE_FLAG_UNPRIV_SGIO,
+ sdev-request_queue-queue_flags);
+   sdev-writeable = 1;
+   break;
+
case TYPE_RBC:
case TYPE_TAPE:
case TYPE_DISK:
case TYPE_PRINTER:
case TYPE_MOD:
case TYPE_PROCESSOR:
-   case TYPE_SCANNER:
case TYPE_MEDIUM_CHANGER:
case TYPE_ENCLOSURE:
case TYPE_COMM:
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index cab816f..1c35628 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -219,9 +219,6 @@ static int sg_allow_access(struct file *filp, unsigned char 
*cmd)
struct sg_fd *sfp = filp-private_data;
struct request_queue *q = sfp-parentdp-device-request_queue;
 
-   if (sfp-parentdp-device-type == TYPE_SCANNER)
-   return 0;
-
return blk_verify_command(q, cmd, filp-f_mode  FMODE_WRITE);
 }
 
-- 
1.7.1

--
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 v2 12/14] sg_io: remove remnants of sysfs SG_IO filters

2013-02-06 Thread Paolo Bonzini
Some defines and structs remained when support was removed for SG_IO
filters in sysfs.  Remove them.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 include/linux/genhd.h |9 -
 1 files changed, 0 insertions(+), 9 deletions(-)

diff --git a/include/linux/genhd.h b/include/linux/genhd.h
index 79b8bba..d3bc249 100644
--- a/include/linux/genhd.h
+++ b/include/linux/genhd.h
@@ -144,15 +144,6 @@ enum {
DISK_EVENT_EJECT_REQUEST= 1  1, /* eject requested */
 };
 
-#define BLK_SCSI_MAX_CMDS  (256)
-#define BLK_SCSI_CMD_PER_LONG  (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
-
-struct blk_scsi_cmd_filter {
-   unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
-   unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
-   struct kobject kobj;
-};
-
 struct disk_part_tbl {
struct rcu_head rcu_head;
int len;
-- 
1.7.1


--
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 v2 13/14] sg_io: introduce unpriv_sgio queue flag

2013-02-06 Thread Paolo Bonzini
This queue flag will let unprivileged users send any SG_IO command to
the device, without any filtering.

This is useful for virtualization, where some trusted guests would like
to send commands such as persistent reservations, but still the virtual
machine monitor should run with restricted permissions.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 Documentation/block/queue-sysfs.txt |8 
 block/blk-sysfs.c   |   33 +
 block/scsi_ioctl.c  |4 +++-
 include/linux/blkdev.h  |3 +++
 4 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/Documentation/block/queue-sysfs.txt 
b/Documentation/block/queue-sysfs.txt
index e54ac1d..341e781 100644
--- a/Documentation/block/queue-sysfs.txt
+++ b/Documentation/block/queue-sysfs.txt
@@ -133,6 +133,14 @@ control of this block device to that new IO scheduler. 
Note that writing
 an IO scheduler name to this file will attempt to load that IO scheduler
 module, if it isn't already present in the system.
 
+unpriv_sgio (RW)
+
+When a process runs without CAP_SYS_RAWIO, access to some SCSI commands
+with the SG_IO ioctl is restricted.  If this option is '0', the whitelist
+is applied for all file descriptors belonging to unprivileged processes.
+If this option is '1', the whitelist is only applied for file descriptors
+that are opened read-only; other file descriptors can send all SCSI commands,
+and no restrictions are applied by the kernel.
 
 
 Jens Axboe jens.ax...@oracle.com, February 2009
diff --git a/block/blk-sysfs.c b/block/blk-sysfs.c
index 7881477..ab2947d 100644
--- a/block/blk-sysfs.c
+++ b/block/blk-sysfs.c
@@ -215,6 +215,32 @@ static ssize_t queue_max_hw_sectors_show(struct 
request_queue *q, char *page)
return queue_var_show(max_hw_sectors_kb, (page));
 }
 
+static ssize_t
+queue_show_unpriv_sgio(struct request_queue *q, char *page)
+{
+   int bit;
+   bit = test_bit(QUEUE_FLAG_UNPRIV_SGIO, q-queue_flags);
+   return queue_var_show(bit, page);
+}
+static ssize_t
+queue_store_unpriv_sgio(struct request_queue *q, const char *page, size_t 
count)
+{
+   unsigned long val;
+   ssize_t ret;
+
+   if (!capable(CAP_SYS_ADMIN))
+   return -EPERM;
+
+   ret = queue_var_store(val, page, count);
+   spin_lock_irq(q-queue_lock);
+   if (val)
+   queue_flag_set(QUEUE_FLAG_UNPRIV_SGIO, q);
+   else
+   queue_flag_clear(QUEUE_FLAG_UNPRIV_SGIO, q);
+   spin_unlock_irq(q-queue_lock);
+   return ret;
+}
+
 #define QUEUE_SYSFS_BIT_FNS(name, flag, neg)   \
 static ssize_t \
 queue_show_##name(struct request_queue *q, char *page) \
@@ -403,6 +429,12 @@ static struct queue_sysfs_entry queue_nonrot_entry = {
.store = queue_store_nonrot,
 };
 
+static struct queue_sysfs_entry queue_unpriv_sgio_entry = {
+   .attr = {.name = unpriv_sgio, .mode = S_IRUGO | S_IWUSR },
+   .show = queue_show_unpriv_sgio,
+   .store = queue_store_unpriv_sgio,
+};
+
 static struct queue_sysfs_entry queue_nomerges_entry = {
.attr = {.name = nomerges, .mode = S_IRUGO | S_IWUSR },
.show = queue_nomerges_show,
@@ -445,6 +477,7 @@ static struct attribute *default_attrs[] = {
queue_discard_max_entry.attr,
queue_discard_zeroes_data_entry.attr,
queue_write_same_max_entry.attr,
+   queue_unpriv_sgio_entry.attr,
queue_nonrot_entry.attr,
queue_nomerges_entry.attr,
queue_rq_affinity_entry.attr,
diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 3830faf..b46564b 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -398,7 +398,9 @@ int blk_verify_command(struct request_queue *q,
return 0;
 
/* Write-safe commands require a writable open */
-   if (has_write_perm  filter-write_ok[cmd[0]]  (1  q-sgio_type))
+   if (has_write_perm 
+   (blk_queue_unpriv_sgio(q) ||
+(filter-write_ok[cmd[0]]  (1  q-sgio_type
return 0;
 
return -EPERM;
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index b376d37..71312ec 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -459,6 +459,7 @@ struct request_queue {
 #define QUEUE_FLAG_SECDISCARD  17  /* supports SECDISCARD */
 #define QUEUE_FLAG_SAME_FORCE  18  /* force complete on same CPU */
 #define QUEUE_FLAG_DEAD19  /* queue tear-down finished */
+#define QUEUE_FLAG_UNPRIV_SGIO 20  /* SG_IO free for unprivileged users */
 
 #define QUEUE_FLAG_DEFAULT ((1  QUEUE_FLAG_IO_STAT) |\
 (1  QUEUE_FLAG_STACKABLE)|   \
@@ -534,6 +535,8 @@ static inline void queue_flag_clear(unsigned int flag, 

[PATCH v2 09/14] sg_io: whitelist a few more commands for disks

2013-02-06 Thread Paolo Bonzini
This adds missing commands to the table from SBC and related standards.
Only commands that affect the medium are added.  Commands that affect
other state of the LUN are all privileged, with the sole exception of START
STOP UNIT (which has always been allowed for all file descriptors.  I do not
really agree with that and it's probably an artifact of when /dev/cdrom had
r--r--r-- permissions, but I'm not trying to change that.

I left these out after discussion with Tejun who prefers not to whitelist
obsolete or really rarely used commands:

sgio_bitmap_set(0x29, D|  W|R|O  , read);  /* READ 
GENERATION */
sgio_bitmap_set(0x34, D|  W|  O|K, read);  /* 
PRE-FETCH(10) */
sgio_bitmap_set(0x90, D|  W|  O|  B  , read);  /* 
PRE-FETCH(16) */

sgio_bitmap_set(0x07, D|  W|  O  , write); /* REASSIGN 
BLOCKS */
sgio_bitmap_set(0x2C, D|R|O  , write); /* ERASE(10) 
*/
sgio_bitmap_set(0x8B, D  , write); /* ORWRITE */

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
v1-v2: leave out the commands listed in the commit message

 block/scsi_ioctl.c |   17 +++--
 1 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index a9c2caf..e100ee3 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -167,12 +167,15 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x08, D|T|W|  O  , read);  /* 
READ(6) */
sgio_bitmap_set(0x25, D|  W|R|O|  B|K, read);  /* READ 
CAPACITY(10) */
sgio_bitmap_set(0x28, D|  W|R|O|  B|K, read);  /* 
READ(10) */
+   sgio_bitmap_set(0x2D, O  , read);  /* READ 
UPDATED BLOCK */
sgio_bitmap_set(0x2F, D|  W|R|O  , read);  /* 
VERIFY(10) */
sgio_bitmap_set(0x37, D|  O  , read);  /* READ 
DEFECT DATA(10) */
sgio_bitmap_set(0x3E, D|  W|  O  , read);  /* READ 
LONG(10) */
sgio_bitmap_set(0x88, D|T|W|  O|  B  , read);  /* 
READ(16) */
sgio_bitmap_set(0x8F, D|T|W|  O|  B  , read);  /* 
VERIFY(16) */
sgio_bitmap_set(0xA8, D|  W|R|O  , read);  /* 
READ(12) */
+   sgio_bitmap_set(0xAF, D|  W|  O  , read);  /* 
VERIFY(12) */
+   sgio_bitmap_set(0xB7, D|  O  , read);  /* READ 
DEFECT DATA(12) */
 
/* write */
 
@@ -181,11 +184,21 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x2A, D|  W|R|O|  B|K, write); /* 
WRITE(10) */
sgio_bitmap_set(0x2E, D|  W|R|O|  B|K, write); /* WRITE 
AND VERIFY(10) */
sgio_bitmap_set(0x35, D|  W|R|O|  B|K, write); /* 
SYNCHRONIZE CACHE(10) */
+   sgio_bitmap_set(0x38, W|  O|K, write); /* 
MEDIUM SCAN */
+   sgio_bitmap_set(0x3D, O  , write); /* 
UPDATE BLOCK */
sgio_bitmap_set(0x3F, D|  W|  O  , write); /* WRITE 
LONG(10) */
+   sgio_bitmap_set(0x41, D  , write); /* WRITE 
SAME(10) */
sgio_bitmap_set(0x42, D  , write); /* UNMAP 
*/
sgio_bitmap_set(0x48, D|  B  , write); /* 
SANITIZE */
sgio_bitmap_set(0x51, D  , write); /* 
XPWRITE(10) */
+   sgio_bitmap_set(0x53, D  , write); /* 
XDWRITEREAD(10) */
+   sgio_bitmap_set(0x85, D|  B  , write); /* ATA 
PASS-THROUGH(16) */
+   sgio_bitmap_set(0x89, D  , write); /* 
COMPARE AND WRITE */
sgio_bitmap_set(0x8A, D|T|W|  O|  B  , write); /* 
WRITE(16) */
+   sgio_bitmap_set(0x8E, D|  W|  O|  B  , write); /* WRITE 
AND VERIFY(16) */
+   sgio_bitmap_set(0x91, D|  W|  O|  B  , write); /* 
SYNCHRONIZE CACHE(16) */
+   sgio_bitmap_set(0x93, D  , write); /* WRITE 
SAME(16) */
+   sgio_bitmap_set(0xA1, D|  B  , write); /* ATA 
PASS-THROUGH(12) */
sgio_bitmap_set(0xAA, D|  W|R|O  , write); /* 
WRITE(12) */
sgio_bitmap_set(0xAC, O  , write); /* 
ERASE(12) */
sgio_bitmap_set(0xAE, D|  W|  O  , write); /* WRITE 
AND VERIFY(12) */
@@ -235,12 +248,12 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0xBD,   R, read);  /* 
MECHANISM STATUS */

[PATCH v2 04/14] sg_io: resolve conflicts between commands assigned to multiple classes (CVE-2012-4542)

2013-02-06 Thread Paolo Bonzini
Some SCSI commands can be sent to disks via SG_IO even by unprivileged
users.  Unfortunately, some opcodes overlap across SCSI device classes
and have different meanings for different classes.  Four of them can
be used for read-only file descriptors on MMC, but should be limited to
descriptors opened for read-write on SBC:

The current bitmap of allowed commands is designed for MMC devices
(roughly, play/burn CDs without requiring root).

- READ SUBCHANNEL - UNMAP (destructive, but no control on written
  data)

- GET PERFORMANCE - ERASE (not really a problem, no one supports
  ERASE anyway)

- READ DISC INFORMATION - XPWRITE (not commonly implemented but
  most dangerous)

- PLAY AUDIO TI - SANITIZE (a very new command)

To fix this, the series splits the bitmap entries for these four
commands into two entries, one read-only for MMC and one read-write
for the other device classes.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 block/scsi_ioctl.c |   12 
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index c4c42dd..7ea3428 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -182,29 +182,33 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x2E, D|  W|R|O|  B|K, write); /* WRITE 
AND VERIFY(10) */
sgio_bitmap_set(0x35, D|  W|R|O|  B|K, write); /* 
SYNCHRONIZE CACHE(10) */
sgio_bitmap_set(0x3F, D|  W|  O  , write); /* WRITE 
LONG(10) */
+   sgio_bitmap_set(0x42, D  , write); /* UNMAP 
*/
+   sgio_bitmap_set(0x48, D|  B  , write); /* 
SANITIZE */
+   sgio_bitmap_set(0x51, D  , write); /* 
XPWRITE(10) */
sgio_bitmap_set(0x8A, D|T|W|  O|  B  , write); /* 
WRITE(16) */
sgio_bitmap_set(0xAA, D|  W|R|O|  C  , write); /* 
WRITE(12) */
+   sgio_bitmap_set(0xAC, O  , write); /* 
ERASE(12) */
sgio_bitmap_set(0xAE, D|  W|  O  , write); /* WRITE 
AND VERIFY(12) */
sgio_bitmap_set(0xEA, D|  W|  O  , write); /* 
WRITE_LONG_2 ?? */
 
/* (mostly) MMC */
 
sgio_bitmap_set(0x23,   R, read);  /* READ 
FORMAT CAPACITIES */
-   sgio_bitmap_set(0x42, D|R, read);  /* READ 
SUB-CHANNEL / UNMAP !! */
+   sgio_bitmap_set(0x42,   R, read);  /* READ 
SUB-CHANNEL */
sgio_bitmap_set(0x43,   R, read);  /* READ 
TOC/PMA/ATIP */
sgio_bitmap_set(0x44,   T|  R|V  , read);  /* READ 
HEADER */
sgio_bitmap_set(0x45,   R, read);  /* PLAY 
AUDIO(10) */
sgio_bitmap_set(0x46,   R, read);  /* GET 
CONFIGURATION */
sgio_bitmap_set(0x47,   R, read);  /* PLAY 
AUDIO MSF */
-   sgio_bitmap_set(0x48, D|R|B  , read);  /* PLAY 
AUDIO TI / SANITIZE !! */
+   sgio_bitmap_set(0x48,   R, read);  /* PLAY 
AUDIO TI */
sgio_bitmap_set(0x4A,   R, read);  /* GET 
EVENT STATUS NOTIFICATION */
sgio_bitmap_set(0x4B,   R, read);  /* 
PAUSE/RESUME */
sgio_bitmap_set(0x4E,   R, read);  /* STOP 
PLAY/SCAN */
-   sgio_bitmap_set(0x51, D|R, read);  /* READ 
DISC INFORMATION / XPWRITE(10) !! */
+   sgio_bitmap_set(0x51,   R, read);  /* READ 
DISC INFORMATION */
sgio_bitmap_set(0x52,   R, read);  /* READ 
TRACK INFORMATION */
sgio_bitmap_set(0x5C,   R, read);  /* READ 
BUFFER CAPACITY */
sgio_bitmap_set(0xA4,   R, read);  /* 
REPORT KEY */
-   sgio_bitmap_set(0xAC,   R|O  , read);  /* GET 
PERFORMANCE / ERASE !! */
+   sgio_bitmap_set(0xAC,   R, read);  /* GET 
PERFORMANCE */
sgio_bitmap_set(0xAD,   R, read);  /* READ 
DVD STRUCTURE */
sgio_bitmap_set(0xB9,   R, read);  /* READ 
CD MSF */
sgio_bitmap_set(0xBA,   R, read);  /* SCAN 
*/
-- 
1.7.1


--
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 v2 08/14] sg_io: whitelist a few more commands for tapes

2013-02-06 Thread Paolo Bonzini
Tapes have no problematic overlap, but quite a few commands
are missing that are useful when operating tapes with /dev/sg.
This patch adds them.

START STOP UNIT, FORMAT UNIT and SEEK(10) have similar meanings
but different names for tapes, so move them to the tape section
of the whitelist.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 block/scsi_ioctl.c |   30 +-
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 8cda426..a9c2caf 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -142,9 +142,9 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x03, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* 
REQUEST SENSE */
sgio_bitmap_set(0x12, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* 
INQUIRY */
sgio_bitmap_set(0x1A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(6) */
-   sgio_bitmap_set(0x1B, D|T|W|R|O|  A|  B|K|V|F, read);  /* START 
STOP UNIT */
+   sgio_bitmap_set(0x1B, D|  W|R|O|  A|  B|K|  F, read);  /* START 
STOP UNIT */
sgio_bitmap_set(0x1C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* 
RECEIVE DIAGNOSTIC RESULTS */
-   sgio_bitmap_set(0x2B, D|T|W|R|O|K, read);  /* 
SEEK(10) */
+   sgio_bitmap_set(0x2B, D|  W|R|O|K, read);  /* 
SEEK(10) */
sgio_bitmap_set(0x3C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* READ 
BUFFER */
sgio_bitmap_set(0x4D, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* LOG 
SENSE */
sgio_bitmap_set(0x5A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(10) */
@@ -176,8 +176,8 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
 
/* write */
 
-   sgio_bitmap_set(0x04, D|T|L|R|O  , write); /* 
FORMAT UNIT */
-   sgio_bitmap_set(0x0A, D|T|L|  W|  O  , write); /* 
WRITE(6) */
+   sgio_bitmap_set(0x04, D|R|O  , write); /* 
FORMAT UNIT */
+   sgio_bitmap_set(0x0A, D|T|W|  O  , write); /* 
WRITE(6) */
sgio_bitmap_set(0x2A, D|  W|R|O|  B|K, write); /* 
WRITE(10) */
sgio_bitmap_set(0x2E, D|  W|R|O|  B|K, write); /* WRITE 
AND VERIFY(10) */
sgio_bitmap_set(0x35, D|  W|R|O|  B|K, write); /* 
SYNCHRONIZE CACHE(10) */
@@ -215,7 +215,7 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x23,   R, read);  /* READ 
FORMAT CAPACITIES */
sgio_bitmap_set(0x42,   R, read);  /* READ 
SUB-CHANNEL */
sgio_bitmap_set(0x43,   R, read);  /* READ 
TOC/PMA/ATIP */
-   sgio_bitmap_set(0x44,   T|  R|V  , read);  /* READ 
HEADER */
+   sgio_bitmap_set(0x44,   R, read);  /* READ 
HEADER */
sgio_bitmap_set(0x45,   R, read);  /* PLAY 
AUDIO(10) */
sgio_bitmap_set(0x46,   R, read);  /* GET 
CONFIGURATION */
sgio_bitmap_set(0x47,   R, read);  /* PLAY 
AUDIO MSF */
@@ -251,7 +251,27 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
 
/* (mostly) tape */
 
+   sgio_bitmap_set(0x01,   T, read);  /* 
REWIND */
+   sgio_bitmap_set(0x05,   T, read);  /* READ 
BLOCK LIMITS */
+   sgio_bitmap_set(0x0F,   T, read);  /* READ 
REVERSE(6) */
+   sgio_bitmap_set(0x13,   T, read);  /* 
VERIFY(6) */
+   sgio_bitmap_set(0x1B,   T|V  , read);  /* LOAD 
UNLOAD */
+   sgio_bitmap_set(0x2B,   T, read);  /* 
LOCATE(10) */
+   sgio_bitmap_set(0x34,   T, read);  /* READ 
POSITION */
+   sgio_bitmap_set(0x44,   T|V  , read);  /* 
REPORT DENSITY SUPPORT */
+   sgio_bitmap_set(0x81,   T, read);  /* READ 
REVERSE(16) */
+   sgio_bitmap_set(0x92,   T, read);  /* 
LOCATE(16) */
+
+   sgio_bitmap_set(0x04,   T, write); /* 
FORMAT MEDIUM */
+   sgio_bitmap_set(0x0B,   T, write); /* SET 
CAPACITY */
+   sgio_bitmap_set(0x10,   T, write); /* WRITE 
FILEMARKS(6) */
+   sgio_bitmap_set(0x11,   T, write); /* 
SPACE(6) */
+   sgio_bitmap_set(0x14,   T|L  , write); /* 
RECOVER BUFFERED DATA */
sgio_bitmap_set(0x19,   T, write); /* 

[PATCH v2 07/14] sg_io: whitelist a few more commands for media changers

2013-02-06 Thread Paolo Bonzini
Besides CD-ROMs, three more device types are interesting for SG_IO:
media changers, tapes and of course disks.

Starting with this patch, we will whitelist a few more commands for
these devices.  For media changers, enable INITIALIZE ELEMENT STATUS
and REQUEST VOLUME ELEMENT ADDRESS.  A few changer-specific commands
were already enabled by chance because they overlapped commands that
are valid for other classes: EXCHANGE MEDIUM and SEND VOLUME TAG,
INITIALIZE ELEMENT STATUS WITH RANGE.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 block/scsi_ioctl.c |   21 -
 1 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index fa2a1fc..8cda426 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -142,9 +142,9 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x03, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* 
REQUEST SENSE */
sgio_bitmap_set(0x12, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* 
INQUIRY */
sgio_bitmap_set(0x1A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(6) */
-   sgio_bitmap_set(0x1B, D|T|W|R|O|M|A|  B|K|V|F, read);  /* START 
STOP UNIT */
+   sgio_bitmap_set(0x1B, D|T|W|R|O|  A|  B|K|V|F, read);  /* START 
STOP UNIT */
sgio_bitmap_set(0x1C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* 
RECEIVE DIAGNOSTIC RESULTS */
-   sgio_bitmap_set(0x2B, D|T|W|R|O|M|  K, read);  /* 
SEEK(10) */
+   sgio_bitmap_set(0x2B, D|T|W|R|O|K, read);  /* 
SEEK(10) */
sgio_bitmap_set(0x3C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* READ 
BUFFER */
sgio_bitmap_set(0x4D, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* LOG 
SENSE */
sgio_bitmap_set(0x5A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(10) */
@@ -168,7 +168,7 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x25, D|  W|R|O|  B|K, read);  /* READ 
CAPACITY(10) */
sgio_bitmap_set(0x28, D|  W|R|O|  B|K, read);  /* 
READ(10) */
sgio_bitmap_set(0x2F, D|  W|R|O  , read);  /* 
VERIFY(10) */
-   sgio_bitmap_set(0x37, D|  O|M, read);  /* READ 
DEFECT DATA(10) */
+   sgio_bitmap_set(0x37, D|  O  , read);  /* READ 
DEFECT DATA(10) */
sgio_bitmap_set(0x3E, D|  W|  O  , read);  /* READ 
LONG(10) */
sgio_bitmap_set(0x88, D|T|W|  O|  B  , read);  /* 
READ(16) */
sgio_bitmap_set(0x8F, D|T|W|  O|  B  , read);  /* 
VERIFY(16) */
@@ -199,6 +199,17 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x10, L  , write); /* 
SYNCHRONIZE BUFFER */
sgio_bitmap_set(0x1B, L  , write); /* STOP 
PRINT */
 
+   /* media changer */
+
+   sgio_bitmap_set(0x07,   M, read);  /* 
INITIALIZE ELEMENT STATUS */
+   sgio_bitmap_set(0x1B,   M, read);  /* 
OPEN/CLOSE IMPORT/EXPORT ELEMENT */
+   sgio_bitmap_set(0x2B,   M, read);  /* 
POSITION TO ELEMENT */
+   sgio_bitmap_set(0x37,   M, read);  /* 
INITIALIZE ELEMENT STATUS WITH RANGE */
+   sgio_bitmap_set(0xB5,   M, read);  /* 
REQUEST VOLUME ELEMENT ADDRESS */
+
+   sgio_bitmap_set(0xA6,   M, write); /* 
EXCHANGE MEDIUM */
+   sgio_bitmap_set(0xB6,   M, write); /* SEND 
VOLUME TAG */
+
/* (mostly) MMC */
 
sgio_bitmap_set(0x23,   R, read);  /* READ 
FORMAT CAPACITIES */
@@ -232,9 +243,9 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0xA1, D|R|B  , write); /* BLANK 
/ ATA PASS-THROUGH(12) */
sgio_bitmap_set(0xA2,   R, write); /* SEND 
EVENT */
sgio_bitmap_set(0xA3,   R, write); /* SEND 
KEY */
-   sgio_bitmap_set(0xA6,   R|  M, write); /* 
LOAD/UNLOAD C/DVD */
+   sgio_bitmap_set(0xA6,   R, write); /* 
LOAD/UNLOAD C/DVD */
sgio_bitmap_set(0xA7,   R, write); /* SET 
READ AHEAD */
-   sgio_bitmap_set(0xB6,   R|  M, write); /* SET 
STREAMING */
+   sgio_bitmap_set(0xB6,   R, write); /* SET 
STREAMING */
sgio_bitmap_set(0xBB,   R, write); /* SET 
CD SPEED */
sgio_bitmap_set(0xBF,   R, write); 

[PATCH v2 06/14] sg_io: whitelist another command for multimedia devices

2013-02-06 Thread Paolo Bonzini
Three MMC commands were never included: PLAY AUDIO(12), SERVICE ACTION
IN(12), MECHANISM STATUS.  Add MECHANISM STATUS, the only one that has
not been obsoleted in recent versions of the standard.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
v1-v2: leave out PLAY AUDIO(12), SERVICE ACTION IN(12)

 block/scsi_ioctl.c |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index e71cd42..fa2a1fc 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -221,6 +221,7 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0xB9,   R, read);  /* READ 
CD MSF */
sgio_bitmap_set(0xBA,   R, read);  /* SCAN 
*/
sgio_bitmap_set(0xBC,   R, read);  /* PLAY 
CD */
+   sgio_bitmap_set(0xBD,   R, read);  /* 
MECHANISM STATUS */
sgio_bitmap_set(0xBE,   R, read);  /* READ 
CD */
 
sgio_bitmap_set(0x53, D|R, write); /* 
RESERVE TRACK / XDWRITEREAD(10) */
-- 
1.7.1


--
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 v2 10/14] sg_io: whitelist a few obsolete commands

2013-02-06 Thread Paolo Bonzini
These are added to their own section of the table, together with SEEK(10)
which has always been permitted.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 block/scsi_ioctl.c |   22 +-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index e100ee3..4942314 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -144,7 +144,6 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x1A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(6) */
sgio_bitmap_set(0x1B, D|  W|R|O|  A|  B|K|  F, read);  /* START 
STOP UNIT */
sgio_bitmap_set(0x1C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* 
RECEIVE DIAGNOSTIC RESULTS */
-   sgio_bitmap_set(0x2B, D|  W|R|O|K, read);  /* 
SEEK(10) */
sgio_bitmap_set(0x3C, D|T|B|O|W|R|O|M|A|E|  K|V|F|C|S, read);  /* READ 
BUFFER */
sgio_bitmap_set(0x4D, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* LOG 
SENSE */
sgio_bitmap_set(0x5A, D|T|L|P|W|R|O|M|A|E|B|K|V|F|C|S, read);  /* MODE 
SENSE(10) */
@@ -286,6 +285,27 @@ static void blk_set_cmd_filter_defaults(struct 
blk_cmd_filter *filter)
sgio_bitmap_set(0x91,   T, write); /* 
SPACE(16) */
sgio_bitmap_set(0x93,   T, write); /* 
ERASE(16) */
 
+   /* various obsolete */
+
+   sgio_bitmap_set(0x0B, D|  W|R|O  , read);  /* 
SEEK(6) */
+   sgio_bitmap_set(0x2B, D|  W|R|O|K, read);  /* 
SEEK(10) */
+   sgio_bitmap_set(0x30, D|  W|R|O  , read);  /* 
SEARCH DATA HIGH(10) */
+   sgio_bitmap_set(0x31, D|  W|R|O  , read);  /* 
SEARCH DATA EQUAL(10) */
+   sgio_bitmap_set(0x32, D|  W|R|O  , read);  /* 
SEARCH DATA LOW(10) */
+   sgio_bitmap_set(0x39, D|T|L|P|W|R|O|K, read);  /* 
COMPARE */
+   sgio_bitmap_set(0x52, D  , read);  /* 
XDREAD(10) */
+   sgio_bitmap_set(0xB0, W|R|O  , read);  /* 
SEARCH DATA HIGH(12) */
+   sgio_bitmap_set(0xB1, W|R|O  , read);  /* 
SEARCH DATA EQUAL(12) */
+   sgio_bitmap_set(0xB2, W|R|O  , read);  /* 
SEARCH DATA LOW(12) */
+   sgio_bitmap_set(0xB4, D|T|W|R|O  , read);  /* READ 
ELEMENT STATUS ATTACHED */
+   sgio_bitmap_set(0xB8,   T|W|R|O|M, read);  /* READ 
ELEMENT STATUS */
+
+   sgio_bitmap_set(0x01, D|  W|R|O|M, write); /* 
REZERO UNIT */
+   sgio_bitmap_set(0x18, D|T|L|P|W|R|O|K, write); /* COPY 
*/
+   sgio_bitmap_set(0x3A, D|T|L|P|W|R|O|K, write); /* COPY 
AND VERIFY */
+   sgio_bitmap_set(0x50, D  , write); /* 
XDWRITE(10) */
+   sgio_bitmap_set(0x80, D  , write); /* 
XDWRITE EXTENDED(16) */
+
/* communication devices (obsolete) */
 
sgio_bitmap_set(0x08, C  , write); /* GET 
MESSAGE(6) */
-- 
1.7.1


--
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 v2 03/14] sg_io: use different default filters for each device class

2013-02-06 Thread Paolo Bonzini
Store the filters in a 256-entry array, and pick an appropriate filter
for SCSI devices.  Apart from SCSI disks, SG_IO is supported for CCISS,
ide-floppy and virtio-blk devices; TYPE_DISK (which is zero, i.e. the
default) is more appropriate for these devices than TYPE_ROM.

This patch already introduces some semantic change, albeit very limited;
in addition to the above change for CCISS/ide-floppy/virtio-blk, a few
commands are now forbidden for devices of type other than TYPE_ROM,
where they are reserved or vendor-specific.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
 block/scsi_ioctl.c   |   14 +-
 drivers/scsi/scsi_scan.c |2 ++
 include/linux/blkdev.h   |2 +-
 include/scsi/scsi.h  |1 +
 4 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index 9e15784..c4c42dd 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -34,8 +34,8 @@
 #include scsi/scsi_cmnd.h
 
 struct blk_cmd_filter {
-   unsigned long read_ok[BLK_SCSI_CMD_PER_LONG];
-   unsigned long write_ok[BLK_SCSI_CMD_PER_LONG];
+   u32 read_ok[BLK_SCSI_MAX_CMDS];
+   u32 write_ok[BLK_SCSI_MAX_CMDS];
 };
 
 static struct blk_cmd_filter blk_default_cmd_filter;
@@ -116,7 +116,7 @@ static int sg_emulated_host(struct request_queue *q, int 
__user *p)
 static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
 {
 #define sgio_bitmap_set(cmd, mask, rw) \
-   if ((mask) != 0) __set_bit((cmd), filter-rw##_ok)
+   filter-rw##_ok[(cmd)] |= (mask);
 
 #define D (1u  TYPE_DISK)   /* Direct Access Block Device (SBC-3) */
 #define T (1u  TYPE_TAPE)   /* Sequential Access Device (SSC-3) */
@@ -257,16 +257,12 @@ int blk_verify_command(struct request_queue *q,
if (capable(CAP_SYS_RAWIO))
return 0;
 
-   /* if there's no filter set, assume we're filtering everything out */
-   if (!filter)
-   return -EPERM;
-
/* Anybody who can open the device can do a read-safe command */
-   if (test_bit(cmd[0], filter-read_ok))
+   if (filter-read_ok[cmd[0]]  (1  q-sgio_type))
return 0;
 
/* Write-safe commands require a writable open */
-   if (test_bit(cmd[0], filter-write_ok)  has_write_perm)
+   if (has_write_perm  filter-write_ok[cmd[0]]  (1  q-sgio_type))
return 0;
 
return -EPERM;
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index 3e58b22..86940f3 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -782,6 +782,8 @@ static int scsi_add_lun(struct scsi_device *sdev, unsigned 
char *inq_result,
sdev-removable = (inq_result[1]  0x80)  7;
}
 
+   sdev-request_queue-sgio_type = sdev-type;
+
switch (sdev-type) {
case TYPE_RBC:
case TYPE_TAPE:
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 0782336..b376d37 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -256,7 +256,6 @@ struct blk_queue_tag {
 };
 
 #define BLK_SCSI_MAX_CMDS  (256)
-#define BLK_SCSI_CMD_PER_LONG  (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8))
 
 struct queue_limits {
unsigned long   bounce_pfn;
@@ -403,6 +402,7 @@ struct request_queue {
 */
unsigned intsg_timeout;
unsigned intsg_reserved_size;
+   unsigned char   sgio_type;
int node;
 #ifdef CONFIG_BLK_DEV_IO_TRACE
struct blk_trace*blk_trace;
diff --git a/include/scsi/scsi.h b/include/scsi/scsi.h
index b67553f..06cc93e 100644
--- a/include/scsi/scsi.h
+++ b/include/scsi/scsi.h
@@ -327,6 +327,7 @@ static inline int scsi_status_is_good(int status)
 #define TYPE_OCRW   0x0f
 #define TYPE_ADC0x10
 #define TYPE_OSD0x11
+#define TYPE_MAX0x1f
 #define TYPE_NO_LUN 0x7f
 
 /* SCSI protocols; these are taken from SPC-3 section 7.5 */
-- 
1.7.1


--
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 v2 02/14] sg_io: reorganize list of allowed commands

2013-02-06 Thread Paolo Bonzini
To prepare for the next patches, reorganize the list of commands into
a two-way table of command numbers and device types.

One command (READ CAPACITY) was listed twice in the old table, hence
the new table has one entry less than the old one.

Right now, there is still just one bitmap and the mask is ignored,
so there is no semantic change yet.

Of course, checkpatch hates this table.  It has long lines and
non-standard spacing.  IMO the improved readability trumps the problems
reported by checkpatch.

Cc: James E.J. Bottomley jbottom...@parallels.com
Cc: linux-scsi@vger.kernel.org
Cc: Jens Axboe ax...@kernel.dk
Signed-off-by: Paolo Bonzini pbonz...@redhat.com
---
v1-v2: do not use C++ commands, add definitions for missing types
in include/scsi/scsi.h

 block/scsi_ioctl.c  |  210 ---
 include/scsi/scsi.h |2 +
 2 files changed, 133 insertions(+), 79 deletions(-)

diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
index a737562..9e15784 100644
--- a/block/scsi_ioctl.c
+++ b/block/scsi_ioctl.c
@@ -115,85 +115,137 @@ static int sg_emulated_host(struct request_queue *q, int 
__user *p)
 
 static void blk_set_cmd_filter_defaults(struct blk_cmd_filter *filter)
 {
-   /* Basic read-only commands */
-   __set_bit(TEST_UNIT_READY, filter-read_ok);
-   __set_bit(REQUEST_SENSE, filter-read_ok);
-   __set_bit(READ_6, filter-read_ok);
-   __set_bit(READ_10, filter-read_ok);
-   __set_bit(READ_12, filter-read_ok);
-   __set_bit(READ_16, filter-read_ok);
-   __set_bit(READ_BUFFER, filter-read_ok);
-   __set_bit(READ_DEFECT_DATA, filter-read_ok);
-   __set_bit(READ_CAPACITY, filter-read_ok);
-   __set_bit(READ_LONG, filter-read_ok);
-   __set_bit(INQUIRY, filter-read_ok);
-   __set_bit(MODE_SENSE, filter-read_ok);
-   __set_bit(MODE_SENSE_10, filter-read_ok);
-   __set_bit(LOG_SENSE, filter-read_ok);
-   __set_bit(START_STOP, filter-read_ok);
-   __set_bit(GPCMD_VERIFY_10, filter-read_ok);
-   __set_bit(VERIFY_16, filter-read_ok);
-   __set_bit(REPORT_LUNS, filter-read_ok);
-   __set_bit(SERVICE_ACTION_IN, filter-read_ok);
-   __set_bit(RECEIVE_DIAGNOSTIC, filter-read_ok);
-   __set_bit(MAINTENANCE_IN, filter-read_ok);
-   __set_bit(GPCMD_READ_BUFFER_CAPACITY, filter-read_ok);
-
-   /* Audio CD commands */
-   __set_bit(GPCMD_PLAY_CD, filter-read_ok);
-   __set_bit(GPCMD_PLAY_AUDIO_10, filter-read_ok);
-   __set_bit(GPCMD_PLAY_AUDIO_MSF, filter-read_ok);
-   __set_bit(GPCMD_PLAY_AUDIO_TI, filter-read_ok);
-   __set_bit(GPCMD_PAUSE_RESUME, filter-read_ok);
-
-   /* CD/DVD data reading */
-   __set_bit(GPCMD_READ_CD, filter-read_ok);
-   __set_bit(GPCMD_READ_CD_MSF, filter-read_ok);
-   __set_bit(GPCMD_READ_DISC_INFO, filter-read_ok);
-   __set_bit(GPCMD_READ_CDVD_CAPACITY, filter-read_ok);
-   __set_bit(GPCMD_READ_DVD_STRUCTURE, filter-read_ok);
-   __set_bit(GPCMD_READ_HEADER, filter-read_ok);
-   __set_bit(GPCMD_READ_TRACK_RZONE_INFO, filter-read_ok);
-   __set_bit(GPCMD_READ_SUBCHANNEL, filter-read_ok);
-   __set_bit(GPCMD_READ_TOC_PMA_ATIP, filter-read_ok);
-   __set_bit(GPCMD_REPORT_KEY, filter-read_ok);
-   __set_bit(GPCMD_SCAN, filter-read_ok);
-   __set_bit(GPCMD_GET_CONFIGURATION, filter-read_ok);
-   __set_bit(GPCMD_READ_FORMAT_CAPACITIES, filter-read_ok);
-   __set_bit(GPCMD_GET_EVENT_STATUS_NOTIFICATION, filter-read_ok);
-   __set_bit(GPCMD_GET_PERFORMANCE, filter-read_ok);
-   __set_bit(GPCMD_SEEK, filter-read_ok);
-   __set_bit(GPCMD_STOP_PLAY_SCAN, filter-read_ok);
-
-   /* Basic writing commands */
-   __set_bit(WRITE_6, filter-write_ok);
-   __set_bit(WRITE_10, filter-write_ok);
-   __set_bit(WRITE_VERIFY, filter-write_ok);
-   __set_bit(WRITE_12, filter-write_ok);
-   __set_bit(WRITE_VERIFY_12, filter-write_ok);
-   __set_bit(WRITE_16, filter-write_ok);
-   __set_bit(WRITE_LONG, filter-write_ok);
-   __set_bit(WRITE_LONG_2, filter-write_ok);
-   __set_bit(ERASE, filter-write_ok);
-   __set_bit(GPCMD_MODE_SELECT_10, filter-write_ok);
-   __set_bit(MODE_SELECT, filter-write_ok);
-   __set_bit(LOG_SELECT, filter-write_ok);
-   __set_bit(GPCMD_BLANK, filter-write_ok);
-   __set_bit(GPCMD_CLOSE_TRACK, filter-write_ok);
-   __set_bit(GPCMD_FLUSH_CACHE, filter-write_ok);
-   __set_bit(GPCMD_FORMAT_UNIT, filter-write_ok);
-   __set_bit(GPCMD_REPAIR_RZONE_TRACK, filter-write_ok);
-   __set_bit(GPCMD_RESERVE_RZONE_TRACK, filter-write_ok);
-   __set_bit(GPCMD_SEND_DVD_STRUCTURE, filter-write_ok);
-   __set_bit(GPCMD_SEND_EVENT, filter-write_ok);
-   __set_bit(GPCMD_SEND_KEY, filter-write_ok);
-   __set_bit(GPCMD_SEND_OPC, filter-write_ok);
-   __set_bit(GPCMD_SEND_CUE_SHEET, filter-write_ok);
-   __set_bit(GPCMD_SET_SPEED, filter-write_ok);
-   

Re: [PATCH v9 4/4] sd: change to auto suspend mode

2013-02-06 Thread Alan Stern
On Wed, 6 Feb 2013, Aaron Lu wrote:

  The if (err == -EAGAIN) test and the call to pm_schedule_suspend seem
  to have been dropped since v8 of this series.  It looks like they ought
  to be moved into sdev_runtime_suspend.
 
 I thought they were no longer needed...

You did not mention this in the patch description.

 For sd, we have request based rutime PM and the PM core will always try
 to autosuspend the device with the timer; and for sr, the poll will
 trigger suspend constantly.

What if the poll has been disabled?

 And for both, we don't return -EAGAIN anyway.
 So I suppose that code is not necessary?

You could replace it with WARN_ON(err == -EAGAIN).  That way if some 
SCSI driver does return -EAGAIN in the future, people will know 
something is wrong.

 BTW, I'll be on vocation till 02/17, and I don't have access to the
 internet in my hometown, but please feel free to drop any comments and
 I'll check them when I get back.

I'm going on vacation next week too.  Enjoy your trip.

Alan Stern

--
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/2] virtio-scsi: reset virtqueue affinity when doing cpu hotplug

2013-02-06 Thread Paolo Bonzini
Il 16/01/2013 04:55, Wanlong Gao ha scritto:
  Add hot cpu notifier to reset the request virtqueue affinity
  when doing cpu hotplug.
  
  You need to be careful to get_online_cpus() and put_online_cpus() here,
  so CPUs can't go up and down in the middle of operations.
  
  In particular, get_online_cpus()/put_online_cpus() around calls to
  virtscsi_set_affinity() (except within notifiers).
 Yes, I'll take care of this, thank you.
 

I squashed patch 1 (plus changes to get/put_online_cpus) in my
multiqueue series, and applied this one as a separate patch.

Paolo
--
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: [SCSI] sd: Ensure we correctly disable devices with unknown protection type

2013-02-06 Thread Dan Carpenter
This patch wasn't applied.  Probably because it didn't have
[PATCH] in the email subject.

regards,
dan carpenter

On Wed, Sep 26, 2012 at 10:39:44PM -0400, Martin K. Petersen wrote:
  Dan == Dan Carpenter dan.carpen...@oracle.com writes:
 
 Dan,
 
 Dan   warn: buffer overflow 'cap' 4 = 4
 
 Argh, yes. Type 3 is 4 because it's a bitmask.
 
 -- 
 Martin K. PetersenOracle Linux Engineering
 
 
 SCSI: Fix range check in scsi_host.h
 
 The range checking from fe542396 was bad. We would still end up walking
 beyond the array as Type 3 is defined to be 4 in the protection
 bitmask. Instead use ARRAY_SIZE() for the range check.
 
 Reported-by: Dan Carpenter dan.carpen...@oracle.com
 Signed-off-by: Martin K. Petersen martin.peter...@oracle.com
 
 diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
 index 4908480..2b6956e 100644
 --- a/include/scsi/scsi_host.h
 +++ b/include/scsi/scsi_host.h
 @@ -873,7 +873,7 @@ static inline unsigned int scsi_host_dif_capable(struct 
 Scsi_Host *shost, unsign
  SHOST_DIF_TYPE2_PROTECTION,
  SHOST_DIF_TYPE3_PROTECTION };
  
 - if (target_type  SHOST_DIF_TYPE3_PROTECTION)
 + if (target_type = ARRAY_SIZE(cap))
   return 0;
  
   return shost-prot_capabilities  cap[target_type] ? target_type : 0;
 @@ -887,7 +887,7 @@ static inline unsigned int scsi_host_dix_capable(struct 
 Scsi_Host *shost, unsign
  SHOST_DIX_TYPE2_PROTECTION,
  SHOST_DIX_TYPE3_PROTECTION };
  
 - if (target_type  SHOST_DIX_TYPE3_PROTECTION)
 + if (target_type = ARRAY_SIZE(cap))
   return 0;
  
   return shost-prot_capabilities  cap[target_type];
--
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 60/77] scsi/bfa: convert to idr_alloc()

2013-02-06 Thread Tejun Heo
Convert to the much saner new idr interface.

Only compile tested.

Signed-off-by: Tejun Heo t...@kernel.org
Cc: Krishna C Gudipati kgudi...@brocade.com
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/bfa/bfad_im.c | 15 ---
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 8f92732..5864f98 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -523,20 +523,13 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct 
bfad_im_port_s *im_port,
int error = 1;
 
mutex_lock(bfad_mutex);
-   if (!idr_pre_get(bfad_im_port_index, GFP_KERNEL)) {
+   error = idr_alloc(bfad_im_port_index, im_port, 0, 0, GFP_KERNEL);
+   if (error  0) {
mutex_unlock(bfad_mutex);
-   printk(KERN_WARNING idr_pre_get failure\n);
+   printk(KERN_WARNING idr_alloc failure\n);
goto out;
}
-
-   error = idr_get_new(bfad_im_port_index, im_port,
-im_port-idr_id);
-   if (error) {
-   mutex_unlock(bfad_mutex);
-   printk(KERN_WARNING idr_get_new failure\n);
-   goto out;
-   }
-
+   im_port-idr_id = error;
mutex_unlock(bfad_mutex);
 
im_port-shost = bfad_scsi_host_alloc(im_port, bfad);
-- 
1.8.1

--
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


[LSF/MM TOPIC][ATTEND] protection information and userspace

2013-02-06 Thread Ben Myers
Hi,

I'm interested in discussing how to pass protection information to and from
userspace.  Maybe Martin could be enlisted for the discussion.

I read that some work has already been done in this area but have not been able
to locate it.  It looks like the bio-integrity code already makes it possible
to generate the t10-dif crc in the filesystem.  It would be good to be able to
get the guard and application tags back out to backup applications such as
xfsdump.  Enabling other applications to generate their own tags in userspace
is also interesting.

Regards,
Ben
--
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 63/77] scsi/lpfc: convert to idr_alloc()

2013-02-06 Thread Tejun Heo
Convert to the much saner new idr interface.

Only compile tested.

Signed-off-by: Tejun Heo t...@kernel.org
Cc: James Smart james.sm...@emulex.com
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/lpfc/lpfc_init.c | 12 
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 26ca2ef..314b4f6 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -3165,14 +3165,10 @@ destroy_port(struct lpfc_vport *vport)
 int
 lpfc_get_instance(void)
 {
-   int instance = 0;
-
-   /* Assign an unused number */
-   if (!idr_pre_get(lpfc_hba_index, GFP_KERNEL))
-   return -1;
-   if (idr_get_new(lpfc_hba_index, NULL, instance))
-   return -1;
-   return instance;
+   int ret;
+
+   ret = idr_alloc(lpfc_hba_index, NULL, 0, 0, GFP_KERNEL);
+   return ret  0 ? -1 : ret;
 }
 
 /**
-- 
1.8.1

--
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 62/77] target/iscsi: convert to idr_alloc()

2013-02-06 Thread Tejun Heo
Convert to the much saner new idr interface.

Only compile tested.

Signed-off-by: Tejun Heo t...@kernel.org
Cc: Nicholas A. Bellinger n...@linux-iscsi.org
Cc: linux-scsi@vger.kernel.org
Cc: target-de...@vger.kernel.org
---
 drivers/target/iscsi/iscsi_target.c   | 15 ---
 drivers/target/iscsi/iscsi_target_login.c | 15 ++-
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/drivers/target/iscsi/iscsi_target.c 
b/drivers/target/iscsi/iscsi_target.c
index 339f97f..f1fdf4f 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -144,23 +144,24 @@ struct iscsi_tiqn *iscsit_add_tiqn(unsigned char *buf)
spin_lock_init(tiqn-login_stats.lock);
spin_lock_init(tiqn-logout_stats.lock);
 
-   if (!idr_pre_get(tiqn_idr, GFP_KERNEL)) {
-   pr_err(idr_pre_get() for tiqn_idr failed\n);
-   kfree(tiqn);
-   return ERR_PTR(-ENOMEM);
-   }
tiqn-tiqn_state = TIQN_STATE_ACTIVE;
 
+   idr_preload(GFP_KERNEL);
spin_lock(tiqn_lock);
-   ret = idr_get_new(tiqn_idr, NULL, tiqn-tiqn_index);
+
+   ret = idr_alloc(tiqn_idr, NULL, 0, 0, GFP_NOWAIT);
if (ret  0) {
-   pr_err(idr_get_new() failed for tiqn-tiqn_index\n);
+   pr_err(idr_alloc() failed for tiqn-tiqn_index\n);
spin_unlock(tiqn_lock);
+   idr_preload_end();
kfree(tiqn);
return ERR_PTR(ret);
}
+   tiqn-tiqn_index = ret;
list_add_tail(tiqn-tiqn_list, g_tiqn_list);
+
spin_unlock(tiqn_lock);
+   idr_preload_end();
 
pr_debug(CORE[0] - Added iSCSI Target IQN: %s\n, tiqn-tiqn);
 
diff --git a/drivers/target/iscsi/iscsi_target_login.c 
b/drivers/target/iscsi/iscsi_target_login.c
index fdb632f..2535d4d 100644
--- a/drivers/target/iscsi/iscsi_target_login.c
+++ b/drivers/target/iscsi/iscsi_target_login.c
@@ -247,19 +247,16 @@ static int iscsi_login_zero_tsih_s1(
spin_lock_init(sess-session_usage_lock);
spin_lock_init(sess-ttt_lock);
 
-   if (!idr_pre_get(sess_idr, GFP_KERNEL)) {
-   pr_err(idr_pre_get() for sess_idr failed\n);
-   iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
-   ISCSI_LOGIN_STATUS_NO_RESOURCES);
-   kfree(sess);
-   return -ENOMEM;
-   }
+   idr_preload(GFP_KERNEL);
spin_lock_bh(sess_idr_lock);
-   ret = idr_get_new(sess_idr, NULL, sess-session_index);
+   ret = idr_alloc(sess_idr, NULL, 0, 0, GFP_NOWAIT);
+   if (ret = 0)
+   sess-session_index = ret;
spin_unlock_bh(sess_idr_lock);
+   idr_preload_end();
 
if (ret  0) {
-   pr_err(idr_get_new() for sess_idr failed\n);
+   pr_err(idr_alloc() for sess_idr failed\n);
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES);
kfree(sess);
-- 
1.8.1

--
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 61/77] scsi: convert to idr_alloc()

2013-02-06 Thread Tejun Heo
Convert to the much saner new idr interface.

Only compile tested.

Signed-off-by: Tejun Heo t...@kernel.org
Cc: James E.J. Bottomley james.bottom...@hansenpartnership.com
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/ch.c | 21 +
 drivers/scsi/sg.c | 43 +--
 drivers/scsi/st.c | 27 ---
 3 files changed, 34 insertions(+), 57 deletions(-)

diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index a15474e..2a32374 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -895,7 +895,7 @@ static int ch_probe(struct device *dev)
 {
struct scsi_device *sd = to_scsi_device(dev);
struct device *class_dev;
-   int minor, ret = -ENOMEM;
+   int ret;
scsi_changer *ch;
 
if (sd-type != TYPE_MEDIUM_CHANGER)
@@ -905,22 +905,19 @@ static int ch_probe(struct device *dev)
if (NULL == ch)
return -ENOMEM;
 
-   if (!idr_pre_get(ch_index_idr, GFP_KERNEL))
-   goto free_ch;
-
+   idr_preload(GFP_KERNEL);
spin_lock(ch_index_lock);
-   ret = idr_get_new(ch_index_idr, ch, minor);
+   ret = idr_alloc(ch_index_idr, ch, 0, CH_MAX_DEVS + 1, GFP_NOWAIT);
spin_unlock(ch_index_lock);
+   idr_preload_end();
 
-   if (ret)
+   if (ret  0) {
+   if (ret == -ENOSPC)
+   ret = -ENODEV;
goto free_ch;
-
-   if (minor  CH_MAX_DEVS) {
-   ret = -ENODEV;
-   goto remove_idr;
}
 
-   ch-minor = minor;
+   ch-minor = ret;
sprintf(ch-name,ch%d,ch-minor);
 
class_dev = device_create(ch_sysfs_class, dev,
@@ -944,7 +941,7 @@ static int ch_probe(struct device *dev)
 
return 0;
 remove_idr:
-   idr_remove(ch_index_idr, minor);
+   idr_remove(ch_index_idr, ch-minor);
 free_ch:
kfree(ch);
return ret;
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index afa5bfc..df5e961 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1392,24 +1392,23 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct 
scsi_device *scsidp)
return ERR_PTR(-ENOMEM);
}
 
-   if (!idr_pre_get(sg_index_idr, GFP_KERNEL)) {
-   printk(KERN_WARNING idr expansion Sg_device failure\n);
-   error = -ENOMEM;
-   goto out;
-   }
-
+   idr_preload(GFP_KERNEL);
write_lock_irqsave(sg_index_lock, iflags);
 
-   error = idr_get_new(sg_index_idr, sdp, k);
-   if (error) {
-   write_unlock_irqrestore(sg_index_lock, iflags);
-   printk(KERN_WARNING idr allocation Sg_device failure: %d\n,
-  error);
-   goto out;
+   error = idr_alloc(sg_index_idr, sdp, 0, SG_MAX_DEVS, GFP_NOWAIT);
+   if (error  0) {
+   if (error == -ENOSPC) {
+   sdev_printk(KERN_WARNING, scsidp,
+   Unable to attach sg device type=%d, minor 
number exceeds %d\n,
+   scsidp-type, SG_MAX_DEVS - 1);
+   error = -ENODEV;
+   } else {
+   printk(KERN_WARNING
+  idr allocation Sg_device failure: %d\n, error);
+   }
+   goto out_unlock;
}
-
-   if (unlikely(k = SG_MAX_DEVS))
-   goto overflow;
+   k = error;
 
SCSI_LOG_TIMEOUT(3, printk(sg_alloc: dev=%d \n, k));
sprintf(disk-disk_name, sg%d, k);
@@ -1421,25 +1420,17 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct 
scsi_device *scsidp)
sdp-sg_tablesize = queue_max_segments(q);
sdp-index = k;
kref_init(sdp-d_ref);
+   error = 0;
 
+out_unlock:
write_unlock_irqrestore(sg_index_lock, iflags);
+   idr_preload_end();
 
-   error = 0;
- out:
if (error) {
kfree(sdp);
return ERR_PTR(error);
}
return sdp;
-
- overflow:
-   idr_remove(sg_index_idr, k);
-   write_unlock_irqrestore(sg_index_lock, iflags);
-   sdev_printk(KERN_WARNING, scsidp,
-   Unable to attach sg device type=%d, minor 
-   number exceeds %d\n, scsidp-type, SG_MAX_DEVS - 1);
-   error = -ENODEV;
-   goto out;
 }
 
 static int
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index 98156a9..7c6edca 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4076,7 +4076,7 @@ static int st_probe(struct device *dev)
struct st_modedef *STm;
struct st_partstat *STps;
struct st_buffer *buffer;
-   int i, dev_num, error;
+   int i, error;
char *stp;
 
if (SDp-type != TYPE_TAPE)
@@ -4178,27 +4178,17 @@ static int st_probe(struct device *dev)
tpnt-blksize_changed = 0;
mutex_init(tpnt-lock);
 
-   if (!idr_pre_get(st_index_idr, GFP_KERNEL)) {
-   pr_warn(st: 

Re: [LSF/MM TOPIC][ATTEND] protection information and userspace

2013-02-06 Thread Darrick J. Wong
On Wed, Feb 06, 2013 at 01:51:22PM -0600, Ben Myers wrote:
 Hi,
 
 I'm interested in discussing how to pass protection information to and from
 userspace.  Maybe Martin could be enlisted for the discussion.
 
 I read that some work has already been done in this area but have not been 
 able
 to locate it.  It looks like the bio-integrity code already makes it possible
 to generate the t10-dif crc in the filesystem.  It would be good to be able to
 get the guard and application tags back out to backup applications such as
 xfsdump.  Enabling other applications to generate their own tags in userspace
 is also interesting.

This one's been on my list for a couple of years (and companies) too.  A few
years ago Joel Becker had support for it in his sys_dio proposal (that hasn't
gone anywhere), and more recently I've theorized that we could add a magic
fcntl/ioctl to make the kernel recognize, say, the first iovec of a O_DIRECT
*{read,write}v call as the PI buffer, which I think is similar to how DIX gets
PI data to a disk.  But it's not like I have any code to show for it.

I /think/ it's fairly straightforward to change the directio submit code to
find the userspace PI buffer and amend the block integrity code to attach our
own PI buffer.  You'd still have to let the block layer set the sector # field,
but afaik that won't affect the crc or the app tag.

I hear that the NFS guys want to propose some sort of protocol for transmitting
PI data (across NFS), but I haven't seen anything concrete yet.

Well, I hope I'll scrape together the time to hack together a PoC before LSF...
on the other hand, I ran the discussion about PI userland interfaces at LPC2011
and (shamefully) haven't done anything yet.

end rambling

--D
 
 Regards,
   Ben
 --
 To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
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: [LSF/MM TOPIC][ATTEND] protection information and userspace

2013-02-06 Thread Chuck Lever

On Feb 6, 2013, at 3:24 PM, Darrick J. Wong darrick.w...@oracle.com wrote:

 On Wed, Feb 06, 2013 at 01:51:22PM -0600, Ben Myers wrote:
 Hi,
 
 I'm interested in discussing how to pass protection information to and from
 userspace.  Maybe Martin could be enlisted for the discussion.
 
 I read that some work has already been done in this area but have not been 
 able
 to locate it.  It looks like the bio-integrity code already makes it possible
 to generate the t10-dif crc in the filesystem.  It would be good to be able 
 to
 get the guard and application tags back out to backup applications such as
 xfsdump.  Enabling other applications to generate their own tags in userspace
 is also interesting.
 
 This one's been on my list for a couple of years (and companies) too.  A few
 years ago Joel Becker had support for it in his sys_dio proposal (that hasn't
 gone anywhere), and more recently I've theorized that we could add a magic
 fcntl/ioctl to make the kernel recognize, say, the first iovec of a O_DIRECT
 *{read,write}v call as the PI buffer, which I think is similar to how DIX gets
 PI data to a disk.  But it's not like I have any code to show for it.
 
 I /think/ it's fairly straightforward to change the directio submit code to
 find the userspace PI buffer and amend the block integrity code to attach our
 own PI buffer.  You'd still have to let the block layer set the sector # 
 field,
 but afaik that won't affect the crc or the app tag.
 
 I hear that the NFS guys want to propose some sort of protocol for 
 transmitting
 PI data (across NFS), but I haven't seen anything concrete yet.

I'm writing a requirements document for the NFS protocol which I can discuss at 
LSF.  The use cases for NFS for now would be virtual disk devices (hypervisors) 
or direct NFS access to storage from user space.

Like everyone else we are waiting for a magical VFS and user space API to 
appear that can pass PI to and from storage.

 Well, I hope I'll scrape together the time to hack together a PoC before 
 LSF...
 on the other hand, I ran the discussion about PI userland interfaces at 
 LPC2011
 and (shamefully) haven't done anything yet.
 
 end rambling
 
 --D
 
 Regards,
  Ben
 --
 To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 --
 To unsubscribe from this list: send the line unsubscribe linux-fsdevel in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Chuck Lever
chuck[dot]lever[at]oracle[dot]com




--
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


targetcli-fb and rtslib-fb update, Feb '13

2013-02-06 Thread Andy Grover

Hi all,

I don't know how many of you follow my work on github so I just wanted 
to give an update on some stuff I've been working on, for my branches of 
the kernel target user space configuration tools.


The biggest recent rtslib change is that we've gone back to using Python 
classes to describe the differences between fabrics. See

https://github.com/agrover/rtslib-fb/blob/master/rtslib/fabric.py
for how things look now. This significantly simplifies the 
implementation of FabricModule, and other classes that use it. Having to 
write Python to add support for a new fabric seems like a very small 
price to pay.


The biggest recent targetcli change is a WWN-handling overhaul. All 
fabric WWNs are prefixed by their type, either iqn., eui. or naa. 
This lets us do a better job checking WWNs are valid, and we allow 
fabrics that allow multiple WWN formats, like iSCSI, to use any of 
these, but still check for correctness. But we aren't WWN format zealots 
-- when possible we convert user input to the correct WWN format if 
possible. This should make cut n paste of FCoE initiator WWNs much less 
aggravating, for example.


Here are some highlights of other things we've added since my last 
update to the list in Jan 2012:


targetcli:
* Only show fabric modules that are present, or don't need HW WWNs
* targetcli cmd executes the command and exits
* restoreconfig now emits specific info on each recoverable error when 
parsing the savefile

* ipv6 and localhost addresses allowed for portals
* Creating a NodeACL MappedLUN can take a storage object, and tpg lun 
will be automatically created

* sbp (1394) fabric support
* More info in storageobject and target summaries
* read-only parameter on block backstores
* sessions command to list iscsi sessions
* Added targetcli.8 man page
* rd_mcp backstore shown as ramdisk
* iblock backstore shown as block
* Change summary formats to things: num from num thing{s}

rtslib:
* Don't load fabric kernel modules until used
* Remove class Backstore from API - now handled as StorageObject 
implementation detail

* Remove legacy code
* Improve performance of listing 500 luns from 6 min to 3 sec
* lines of code reduced 20% (not counting .spec removal)
* Removed python-ipaddr, python-netifaces and python-configobj dependencies
* Use python-kmod for module loading if present

Regards -- Andy
--
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 v8 0/10] More device removal fixes

2013-02-06 Thread Joe Lawrence
On Tue, 5 Feb 2013, Bart Van Assche wrote:

 Fix a few race conditions that can be triggered by removing a device:
 - Fix a race between starved list processing and device removal.
 - Avoid that a SCSI LLD callback can get invoked after
   scsi_remove_host() finished.
 - Speed up device removal by stopping error handling as soon as
   the SHOST_DEL or SHOST_DEL_RECOVERY state has been reached.
 - Save and restore the host_scribble field during error handling
 
 These patches have been tested on top of kernel v3.8-rc6 and are also
 available here: http://github.com/bvanassche/linux/tree/device-removal-fixes.

Hi Bart,

I gave your patchset a spin on our ftServer, which supports hotplug of PCI
devices.  Before attempting a surprise HW removal of an LSI Fusion SAS-2
SCSI controller, I issued an orderly removal through our hotplug driver.
The device removal appeared to hang (this does not occur with vanilla
3.8.0-rc6):
 
  PID: 3331   TASK: 88083e968000  CPU: 28  COMMAND: java
   #0 [88084fd5da48] __schedule at 8165e8f4
   #1 [88084fd5dac0] schedule at 8165f0d9
   #3 [88084fd5db30] _scsih_remove at a008416d [mpt2sas]
   #4 [88084fd5db80] pci_device_remove at 81335e66
   #5 [88084fd5dbb0] __device_release_driver at 813fd23c
   #6 [88084fd5dbd0] device_release_driver at 813fd57c
   #7 [88084fd5dbf0] bus_remove_device at 813fccde
   #8 [88084fd5dc20] device_del at 813fa0ba
   #9 [88084fd5dc50] device_unregister at 813fa172
  #10 [88084fd5dc70] pci_stop_bus_device at 8132fce4
  #11 [88084fd5dca0] pci_stop_bus_device at 8132fc8d
  #12 [88084fd5dcd0] pci_stop_bus_device at 8132fc8d
  #13 [88084fd5dd00] pci_stop_bus_device at 8132fc8d
  #14 [88084fd5dd30] pci_stop_bus_device at 8132fc8d
  #15 [88084fd5dd60] pci_stop_and_remove_bus_device at 8132fe46

And to further pin down where we are...

  crash sym _scsih_remove
  a0084010 (t) _scsih_remove [mpt2sas]
  crash p/x 0xa008416d - 0xa0084010
  $9 = 0x15d
  
  crash dis -l _scsih_remove
_scsih_remove+0x140:  callq  0xa0011ea0 sas_remove_host
_scsih_remove+0x145:  mov%r13,%rdi
_scsih_remove+0x148:  callq  0xa00766c0 mpt2sas_base_detach
_scsih_remove+0x14d:  mov%r13,%rdi
_scsih_remove+0x150:  callq  0x8131b930 list_del
_scsih_remove+0x155:  mov%r12,%rdi
_scsih_remove+0x158:  callq  0x8141dcf0 scsi_remove_host
_scsih_remove+0x15d:  mov%r12,%rdi
_scsih_remove+0x160:  callq  0x8141d770 scsi_host_put
_scsih_remove+0x165:  add$0x18,%rsp

We're stuck in the mpt2sas driver's call to scsi_remove_host(), which
[PATCH v8 07/10] Make scsi_remove_host() wait for device removal
modifies.

I re-ran the test with some additional debugging so I could figure out the
Scsi_Host it was operating on and found:

  crash struct Scsi_Host 0x8808513a4290 | grep eh_active
eh_active = 0

However, its __devices list was not empty:

  crash struct Scsi_Host 0x8808513a4290 | grep __devices -A3
__devices = {
  next = 0x880851232530, 
  prev = 0x880851235398
},

So scsi_remove_host loops while the __devices list is never cleared. 

See a complete dump of Scsi_Host and the __devices_list scsi_devices
below.

Regards,

-- Joe


crash struct Scsi_Host 0x8808513a4290  shost

struct Scsi_Host {
  __devices = {
next = 0x880851232530, 
prev = 0x880851235398
  }, 
  __targets = {
next = 0x881054377980, 
prev = 0x88084ed99528
  }, 
  cmd_pool = 0x81c956c0, 
  free_list_lock = {
{
  rlock = {
raw_lock = {
  {
head_tail = 0x2e2e, 
tickets = {
  head = 0x2e, 
  tail = 0x2e
}
  }
}
  }
}
  }, 
  free_list = {
next = 0x88084fb6c008, 
prev = 0x88084fb6c008
  }, 
  starved_list = {
next = 0x8808513a42d0, 
prev = 0x8808513a42d0
  }, 
  default_lock = {
{
  rlock = {
raw_lock = {
  {
head_tail = 0xe5e5, 
tickets = {
  head = 0xe5, 
  tail = 0xe5
}
  }
}
  }
}
  }, 
  host_lock = 0x8808513a42e0, 
  scan_mutex = {
count = {
  counter = 0x1
}, 
wait_lock = {
  {
rlock = {
  raw_lock = {
{
  head_tail = 0x0, 
  tickets = {
head = 0x0, 
tail = 0x0
  }
}
  }
}
  }
}, 
wait_list = {
  next = 0x8808513a42f8, 
  prev = 0x8808513a42f8
}, 
owner = 0x0
  }, 
  eh_cmd_q = {
next = 0x8808513a4310, 
prev = 0x8808513a4310
  }, 
  ehandler = 0x8808512d1890, 
  eh_action = 0x0, 
  eh_active = 0x0, 
  host_wait = {

RE: Linux Libsas/Libata updates/releases

2013-02-06 Thread Mahesh Rajashekhara
** Resending in TEXT/PLAIN, earlier sent email bounce back **

Adding linux-scsi group to this email...

I would like to check with you if anyone had encountered similar issues
with upper layers older libsas/libata drivers. It would be of great help
if anyone can shed some light on this issue.  

Please advise!

Sincerely,
Mahesh

From: Tony Ruiz 
Sent: Tuesday, February 05, 2013 6:15 AM
To: 'James Bottomley'
Cc: Mahesh Rajashekhara
Subject: Linux Libsas/Libata updates/releases


Hi James,

I am the manager for the PMC-Sierra driver team working on the arcsas
and pmc8001 drivers.   

We are in the Beta testing phase of the pmc8001 Linux driver with newer
ASIC support.  When we use the updated libsas/libata libraries like
those in RHEL 6.3 or SuSe SP3 Beta, medium error handling works fine.
When we use kernels with older libsas/libata libraries with medium error
(details below) the system crashes.   We worked with SuSe and they
provided the updated libraries which work well and asked us to opened a
bug with SLES to make sure they include the latest into their kernel:
798738 - SLES 11 SP2 does not contain several libsas/libata backport
commits for handling ATA errors.

My question is:
-   Is there a recommend way to release our driver with these
updated libraries?
-   If there are none, is there an easy solution for customers' to
update only these components instead of the entire kernel?

Thanks in advanced.

Tony Ruiz
Manager of Host Software
PMC-Sierra, Inc.



Details of the issue:
1.  If a target/drive has medium error and IO has been aborted,
during this phase LibATA has some issues in this Error Handling Path and
system eventually crashes.
a.  This is very consistent with SUSE11SP2 (3.0.13) Kernel, but the
private branch of SLES11SP3 (3.0.57) which is still in BETA has all the
LibATA Error Handling back ported, this resolved all these error
handling issues.
b.  This very same issue with Debian 6.0.3 till 6.0.6
c.  With RHEL6.3 everything is working fine, since the Libsas/LibATA
changes are back-ported from 3.4 kernels to their RHEL6.3 Kernel
(2.6.32-279).
Sequence:
-   Medium Error Reported by drive for an IO either Read/Write_FPDMA
(NCQ Command) 
-   Firmware Raise NCQ Event 
-   Holds the IO expects RLE and puts the drive into Error State
-   Internally driver is issuing RLE because we don't have the IO
Context 
-   FW/Drive processes RLE 
-   Driver Receives RLE Response
-   Issues Abort ALL (as per SATA Spec)
-   FW releases all IO's by completing as IO Aborted
-   Driver Completes these to Midlayer

In the Successful case the sequence follows:
-   Receives RLE, but driver is faking it now
-   then receives Hard-Resetting Link
-   Domain Revalidation
-   Rediscover
-   IO's Successfully restarted.

In the Failure case the sequence follows:
-   System hangs
--
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