[PATCH v3 5/8] sg: add free list, rework locking

2018-10-26 Thread Douglas Gilbert
Remove fixed 16 sg_request object array and replace with an active
rq_list plus a request free list. Add finer grained spin lock to
sg_request and do a major rework on locking. sg_request objects now
are only de-allocated when the owning file descriptor is closed.
This simplifies locking issues.

Signed-off-by: Douglas Gilbert 
---

This patch is big and complex. Towards the end the diff program
completely loses the plot. Better to use difftool on a two pane
window, or simply view the before sg.c and the after sg.c .

The requirement to keep the patch small enough to be reviewable
but at the same time both compilable and buildable (i.e. no
undefines when kernel is built) are in conflict, especially when
the changes touch almost all functions in a driver. IMO you
should be able to mark a patch (in the middle of a patchset)
as "non compilable".

 drivers/scsi/sg.c | 1305 -
 1 file changed, 805 insertions(+), 500 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index a76395f16fb1..5fbdb0f40739 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -141,46 +141,58 @@ struct sg_scatter_hold { /* holding area for scsi 
scatter gather info */
 struct sg_device;  /* forward declarations */
 struct sg_fd;
 
-struct sg_request {/* SG_MAX_QUEUE requests outstanding per file */
-   struct list_head entry; /* list entry */
-   struct sg_fd *parentfp; /* NULL -> not in use */
+/*
+ * For any file descriptor: at any time a sg_request object must be a member
+ * of sg_fd::rq_list or sg_fd::rq_free_list. The only exception is within a
+ * rq_list_lock write lock when it is moving between those two lists.
+ */
+
+struct sg_request {/* active SCSI command or inactive on free list (fl) */
+   struct list_head rq_entry;  /* member of rq_list (active cmd) */
+   struct list_head free_entry;/* member of rq_free_list */
+   spinlock_t rq_entry_lck;
struct sg_scatter_hold data;/* hold buffer, perhaps scatter list */
union {
struct sg_io_hdr header;  /* see  */
-   struct sg_io_v4 hdr_v4;   /* see  */
+   struct sg_v4_hold v4_hold;/* related to  */
};
-   u8 sense_b[SCSI_SENSE_BUFFERSIZE];
-   bool hdr_v4_active; /* selector for anonymous union above */
-   bool res_used;  /* true -> use reserve buffer, false -> don't */
+   ktime_t start_ts;   /* used when sg_fd::time_in_ns is true */
+   enum sg_rq_state rq_state;/* tracks lifetime of each request */
+   bool v4_active; /* selector for autonomous union above */
bool orphan;/* true -> drop on sight, false -> normal */
-   bool sg_io_owned;   /* true -> packet belongs to SG_IO */
-   /* done protected by rq_list_lock */
-   char done;  /* 0->before bh, 1->before read, 2->read */
+   bool sync_invoc;/* true -> synchronous (e.g. from ioctl(SG_IO)) */
+   u8 sense_b[SCSI_SENSE_BUFFERSIZE];
+   struct sg_fd *parentfp;  /* pointer to owning fd, even when on fl */
+   struct sg_scatter_hold *d2p; /* optional 2nd data buffer for bidi */
struct request *rq;
struct bio *bio;
-   struct execute_work ew;
+   struct execute_work ew_orph;/* harvest orphan request */
 };
 
-struct sg_fd { /* holds the state of a file descriptor */
-   struct list_head sfd_siblings;  /* protected by device's sfd_lock */
+struct sg_fd { /* holds the state of a file descriptor */
+   struct list_head sfd_entry; /* member sg_device::sfds list */
struct sg_device *parentdp; /* owning device */
wait_queue_head_t read_wait;/* queue read until command done */
-   rwlock_t rq_list_lock;  /* protect access to list in req_arr */
struct mutex f_mutex;   /* protect against changes in this fd */
+   rwlock_t rq_list_lock;  /* protect access to sg_request lists */
+   struct list_head rq_list; /* head of inflight sg_request list */
+   struct list_head rq_free_list; /* head of sg_request free list */
int timeout;/* defaults to SG_DEFAULT_TIMEOUT  */
int timeout_user;   /* defaults to SG_DEFAULT_TIMEOUT_USER */
-   struct sg_scatter_hold reserve; /* one held for this file descriptor */
-   struct list_head rq_list; /* head of request list */
-   struct fasync_struct *async_qp; /* used by asynchronous notification */
-   struct sg_request req_arr[SG_MAX_QUEUE];/* used as singly-linked list */
+   int rem_sgat_thresh;/* > this, request's sgat cleared after use */
+   int tot_fd_thresh;  /* E2BIG if sum_of(dlen) > this, 0: ignore */
+   atomic_t sum_fd_dlens;  /* when tot_fd_thresh>0 this is sum_of(dlen) */
bool force_packid;  /* true -> pack_id input to read() */
bool cmd_q; /* true -> allow command queuing, false -> don't */
-   u8 next_cmd_len;

[PATCH v3 8/8] sg: user controls for q_at_head, read_value

2018-10-26 Thread Douglas Gilbert
Add a SG_SET_GET_EXTENDED ioctl control for whether commands
will be queued_at_head or queued_at_tail by the block layer
(together with the scsi mid-level). It has file scope.

Also add a read_value integer the can be used by write a
value from the SG_SEIRV_* group then the corresponding value
will be returned.

Signed-off-by: Douglas Gilbert 
---

The user can still override the new file scope setting on a
a per command basis with the SG_FLAG_Q_AT_HEAD and
SG_FLAG_Q_AT_TAIL in the sg v3 and v4 structures.

An example of read_value usage is to write the value
SG_SEIRV_FL_RQS to the read_value field. Then after the
SG_SET_GET_EXTENDED ioctl is run, the number of (inactive)
requests currently on this file descriptor's request free
list is placed in the read_value field.

Added in v3 is SG_SEIRV_DEV_FL_RQS which is an expansion of
SG_SEIRV_FL_RQS. SG_SEIRV_DEV_FL_RQS counts free list entries
on all sg file descriptors currently open on the device that
the file descriptor (given to ioctl()) is associated with.

 drivers/scsi/sg.c  | 160 +++--
 include/scsi/sg.h  |  32 ++---
 include/uapi/scsi/sg.h |  49 ++---
 3 files changed, 150 insertions(+), 91 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 3e89bbd508de..4d6966d40949 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -59,7 +59,7 @@ static int sg_version_num = 30901;/* 2 digits for each 
component */
 
 #ifdef CONFIG_SCSI_PROC_FS
 #include 
-static char *sg_version_date = "20181019";
+static char *sg_version_date = "20181024";
 
 static int sg_proc_init(void);
 #endif
@@ -95,6 +95,10 @@ enum sg_rq_state {
 #define SG_DEF_TIME_UNIT SG_TIME_UNIT_MS
 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
 
+#define SG_FD_Q_AT_TAIL true
+#define SG_FD_Q_AT_HEAD false
+#define SG_DEFAULT_Q_AT SG_FD_Q_AT_HEAD/* for backward compatibility */
+
 int sg_big_buff = SG_DEF_RESERVED_SIZE;
 /* N.B. This variable is readable and writeable via
/proc/scsi/sg/def_reserved_size . Each time sg_open() is called a buffer
@@ -187,6 +191,7 @@ struct sg_fd {  /* holds the state of a file 
descriptor */
bool keep_orphan;/* false -> drop (def), true -> keep for read() */
bool mmap_called;   /* false -> mmap() never called on this fd */
bool time_in_ns;/* report times in nanoseconds */
+   bool q_at_tail; /* queue at tail if true, head when false */
u8 next_cmd_len;/* 0: automatic, >0: use on next write() */
struct sg_request *reserve_srp; /* allocate on open(), starts on fl */
struct fasync_struct *async_qp; /* used by asynchronous notification */
@@ -238,7 +243,7 @@ static struct sg_request *sg_add_request(struct sg_fd *sfp, 
int dxfr_len,
 static void sg_remove_request(struct sg_fd *sfp, struct sg_request *srp);
 static struct sg_device *sg_get_dev(int min_dev);
 static void sg_device_destroy(struct kref *kref);
-static const char *sg_rq_state_str(u8 rq_state, bool long_str);
+static const char *sg_rq_state_str(enum sg_rq_state rq_state, bool long_str);
 static struct sg_request *sg_mk_srp(struct sg_fd *sfp, bool first,
rwlock_t *rwlp, unsigned long *iflagsp);
 
@@ -855,7 +860,7 @@ sg_common_write(struct sg_fd *sfp, const struct sg_io_hdr 
*hi_p,
 
if (h4p || !hi_p)
return ERR_PTR(-EOPNOTSUPP);
-   srp = sg_add_request(sfp, hi_p->dxfer_len, false);
+   srp = sg_add_request(sfp, hi_p->dxfer_len, sync);
if (IS_ERR(srp))
return srp;
srp->header = *hi_p;/* structure assignment, could memcpy */
@@ -897,9 +902,13 @@ sg_common_write(struct sg_fd *sfp, const struct sg_io_hdr 
*hi_p,
srp->start_ts = ktime_get_with_offset(TK_OFFS_BOOT);
else
hp->duration = jiffies_to_msecs(jiffies);
-   /* at tail if v3 or later interface and tail flag set */
-   at_head = !(hp->interface_id != '\0' &&
-   (SG_FLAG_Q_AT_TAIL & hp->flags));
+
+   if (hp->interface_id == '\0')   /* v1 and v2 interface */
+   at_head = true; /* backward compatibility */
+   else if (sfp->q_at_tail)  /* cmd flags can override sfd setting */
+   at_head = (hp->flags & SG_FLAG_Q_AT_HEAD);
+   else/* this sfd is defaulting to head */
+   at_head = !(hp->flags & SG_FLAG_Q_AT_TAIL);
 
srp->rq->timeout = timeout;
kref_get(>f_ref); /* sg_rq_end_io() does kref_put(). */
@@ -1084,30 +1093,30 @@ sg_reserved_sz(struct sg_fd *sfp, struct 
sg_extended_info *seip)
 {
bool free_n_srp = false;
int result = 0;
-   int val, mx_sect_bytes;
+   int new_sz, mx_sect_bytes;
unsigned long iflags;
-   struct sg_request *srp; /* prior reserve request */
+   struct sg_request *o_srp;   /* prior reserve request */
struct sg_request 

[PATCH v3 6/8] sg: complete locking changes on ioctl+debug

2018-10-26 Thread Douglas Gilbert
Complete the locking and structure changes of ioctl and debug
('cat /proc/scsi/sg/debug') handling.

Signed-off-by: Douglas Gilbert 
---

This was the code that was "#if 0'-ed out 2 patches ago. It
also shuts checkpatch.pl up as it doesn't like that technique
but offers no viable substitute.

 drivers/scsi/sg.c | 217 +-
 1 file changed, 136 insertions(+), 81 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 5fbdb0f40739..8b4a65340971 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -239,6 +239,7 @@ static struct sg_request *sg_add_request(struct sg_fd *sfp, 
int dxfr_len,
 static void sg_remove_request(struct sg_fd *sfp, struct sg_request *srp);
 static struct sg_device *sg_get_dev(int min_dev);
 static void sg_device_destroy(struct kref *kref);
+static const char *sg_rq_state_str(u8 rq_state, bool long_str);
 
 #define SZ_SG_HEADER sizeof(struct sg_header)  /* v1 and v2 header */
 #define SZ_SG_IO_HDR sizeof(struct sg_io_hdr)  /* v3 header */
@@ -359,7 +360,7 @@ sg_open(struct inode *inode, struct file *filp)
 
nonseekable_open(inode, filp);
if ((flags & O_EXCL) && (O_RDONLY == (flags & O_ACCMODE)))
-   return -EPERM; /* Can't lock it with read only access */
+   return -EPERM;/* not permitted, need write access for O_EXCL */
sdp = sg_get_dev(min_dev);
if (IS_ERR(sdp))
return PTR_ERR(sdp);
@@ -931,11 +932,6 @@ sg_ktime_sub_trunc(ktime_t now_ts, ktime_t ts0)
return 0;
 }
 
-/*
- * Annotation under function arguments (i.e. '__must_hold...') states that
- * this function expects that lock to be held, a read lock is sufficient in
- * this case.
- */
 static void
 sg_fill_request_element(struct sg_fd *sfp, struct sg_request *srp,
struct sg_req_info *rip)
@@ -982,7 +978,6 @@ sg_fill_request_element(struct sg_fd *sfp, struct 
sg_request *srp,
  * Populate up to max_num struct sg_req_info objects, first from the active
  * list then, if there is still room, from the free list. All elements in
  * the free list should have SG_RQ_INACTIVE status.
- * See sg_fill_request_element() for note about __must_hold annotation.
  */
 static void
 sg_fill_request_table(struct sg_fd *sfp, struct sg_req_info *rinfo,
@@ -1031,7 +1026,6 @@ srp_state_or_detaching(struct sg_device *sdp, struct 
sg_request *srp)
return ret;
 }
 
-#if 0  /* temporary to shorten big patch */
 static long
 sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
 {
@@ -1063,24 +1057,37 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, 
unsigned long arg)
return -ENXIO;
if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR))
return -EFAULT;
-   result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
-1, read_only, 1, );
+   result = sg_v3_write(sfp, filp, p, SZ_SG_IO_HDR, read_only,
+true, );
if (result < 0)
return result;
result = wait_event_interruptible(sfp->read_wait,
-   (srp_done(sfp, srp) || atomic_read(>detaching)));
-   if (atomic_read(>detaching))
+   srp_state_or_detaching(sdp, srp));
+
+   spin_lock_irqsave(>rq_entry_lck, iflags);
+   if (unlikely(result)) { /* -ERESTARTSYS because signal hit */
+   srp->orphan = true;
+   srp->rq_state = SG_RQ_INFLIGHT;
+   spin_unlock_irqrestore(>rq_entry_lck, iflags);
+   SG_LOG(1, sdp, "%s:  wait_event_interruptible-->%d\n",
+  __func__, result);
+   return result;
+   }
+   if (unlikely(atomic_read(>detaching))) {
+   srp->rq_state = SG_RQ_INACTIVE;
+   spin_unlock_irqrestore(>rq_entry_lck, iflags);
return -ENODEV;
-   write_lock_irq(>rq_list_lock);
-   if (srp->done) {
-   srp->done = 2;
-   write_unlock_irq(>rq_list_lock);
+   } else if (likely(srp->rq_state == SG_RQ_AWAIT_READ)) {
+   srp->rq_state = SG_RQ_DONE_READ;
+   spin_unlock_irqrestore(>rq_entry_lck, iflags);
result = sg_new_read(sfp, p, SZ_SG_IO_HDR, srp);
return (result < 0) ? result : 0;
}
-   srp->orphan = true;
-   write_unlock_irq(>rq_list_lock);
-   return result;  /* -ERESTARTSYS because signal hit process */
+   cp = sg_rq_state_str(srp->rq_state, true);
+   SG_LOG(1, sdp, "%s: unexpected srp=0x%p  state: %s\n", __func__,
+  srp, cp);
+   

Re: [PATCH 0/3] sd: Rely on the driver core for asynchronous probing

2018-10-26 Thread Hannes Reinecke

On 10/2/18 11:52 PM, Bart Van Assche wrote:

Hello Martin,

During the 2018 edition of LSF/MM there was a session about increasing SCSI
disk probing concurrency. This patch series implements what has been proposed
during that session, namely:
- Make sure that the driver core is aware of asynchronous SCSI LUN probing.
- Avoid unnecessary serialization between sd_probe() and sd_remove() because
   this could lead to a deadlock.

Please consider this patch series for kernel v4.20.

Thanks,

Bart.

Bart Van Assche (3):
   sd: Rely on the driver core for asynchronous probing
   sd: Inline sd_probe_part2()
   __device_release_driver(): Do not wait for asynchronous probing

  drivers/base/dd.c|   3 --
  drivers/scsi/scsi.c  |  14 -
  drivers/scsi/scsi_pm.c   |  22 +---
  drivers/scsi/scsi_priv.h |   3 --
  drivers/scsi/sd.c| 110 ---
  5 files changed, 46 insertions(+), 106 deletions(-)


Initially it looks ok-ish.
But I've has so many issues with asynchronous probing that I'd be really 
careful here.
However, inlining sd_probe_async() should amount for some contention to 
be removed; but I'd rather give it some more testing here.
I've found that testing on large configurations on iSER or SRP tend to 
excite the issues.

Can you check against those, too?
I'll see to give it a spin on my test bed.

Cheers,

Hannes
--
Dr. Hannes ReineckeTeamlead Storage & Networking
h...@suse.de   +49 911 74053 688
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: F. Imendörffer, J. Smithard, J. Guild, D. Upmanyu, G. Norton
HRB 21284 (AG Nürnberg)


[Bug 201199] hpsa blocking boot on HP smart Array P410

2018-10-26 Thread bugzilla-daemon
https://bugzilla.kernel.org/show_bug.cgi?id=201199

--- Comment #8 from Seb Lu (se...@seblu.net) ---
Hello,

Any idea? Any test I can do to find what's wrong?

-- 
You are receiving this mail because:
You are the assignee for the bug.


Re: [PATCH 0/3] sd: Rely on the driver core for asynchronous probing

2018-10-26 Thread Bart Van Assche
On Fri, 2018-10-26 at 15:58 +0200, Hannes Reinecke wrote:
> On 10/2/18 11:52 PM, Bart Van Assche wrote:
> > Hello Martin,
> > 
> > During the 2018 edition of LSF/MM there was a session about increasing SCSI
> > disk probing concurrency. This patch series implements what has been 
> > proposed
> > during that session, namely:
> > - Make sure that the driver core is aware of asynchronous SCSI LUN probing.
> > - Avoid unnecessary serialization between sd_probe() and sd_remove() because
> >this could lead to a deadlock.
> > 
> > Please consider this patch series for kernel v4.20.
> > 
> > Thanks,
> > 
> > Bart.
> > 
> > Bart Van Assche (3):
> >sd: Rely on the driver core for asynchronous probing
> >sd: Inline sd_probe_part2()
> >__device_release_driver(): Do not wait for asynchronous probing
> > 
> >   drivers/base/dd.c|   3 --
> >   drivers/scsi/scsi.c  |  14 -
> >   drivers/scsi/scsi_pm.c   |  22 +---
> >   drivers/scsi/scsi_priv.h |   3 --
> >   drivers/scsi/sd.c| 110 ---
> >   5 files changed, 46 insertions(+), 106 deletions(-)
> > 
> 
> Initially it looks ok-ish.
> But I've has so many issues with asynchronous probing that I'd be really 
> careful here.
> However, inlining sd_probe_async() should amount for some contention to 
> be removed; but I'd rather give it some more testing here.
> I've found that testing on large configurations on iSER or SRP tend to 
> excite the issues.
> Can you check against those, too?
> I'll see to give it a spin on my test bed.

Hi Hannes,

As you may have noticed the build bot was not very happy with the patches in
v2 of this series for the device driver core. Additional testing is welcome
but please start from the patches in the following branch for any tests:
https://github.com/bvanassche/linux/tree/for-next. On that branch my patches
for the device driver core have been replaced with patches from Alexander Duyck.

Thanks,

Bart.


[PATCH v3 3/8] sg: split header, expand and correct descriptions

2018-10-26 Thread Douglas Gilbert
Split scsi/sg.h into a smaller scsi/sg.h which includes a new header:
uapi/scsi/sg.h . Overall expand the twin header files with new
functionality in this patchset and functionality to be added in the
next patchset to implement SG_IOSUBMIT and friends. Adjust format to
modern kernel conventions. Correct and expand some comments.

Signed-off-by: Douglas Gilbert 
---

The new header file: uapi/scsi/sg.h is expected to be in the
kernel's public interface. This takes time (i.e. months or years)
to find its way into glibc and Linux distributions. So the sooner
it is presented and accepted the better.

>From the C perspective, nothing is removed or changed (or shouldn't
be), only additions. This means that the original typedefs stay (but
they are not used in the driver source file: sg.c) since user space
programs may be using them.

 include/scsi/sg.h  | 252 ++---
 include/uapi/scsi/sg.h | 419 +
 2 files changed, 430 insertions(+), 241 deletions(-)
 create mode 100644 include/uapi/scsi/sg.h

diff --git a/include/scsi/sg.h b/include/scsi/sg.h
index f91bcca604e4..596f68746f66 100644
--- a/include/scsi/sg.h
+++ b/include/scsi/sg.h
@@ -7,23 +7,23 @@
 /*
  * History:
  *  Started: Aug 9 by Lawrence Foard (entr...@world.std.com), to allow user
- *   process control of SCSI devices.
+ *  process control of SCSI devices.
  *  Development Sponsored by Killy Corp. NY NY
  *
  * Original driver (sg.h):
- *   Copyright (C) 1992 Lawrence Foard
+ *   Copyright (C) 1992 Lawrence Foard
  * Version 2 and 3 extensions to driver:
- * Copyright (C) 1998 - 2014 Douglas Gilbert
+ *   Copyright (C) 1998 - 2018 Douglas Gilbert
  *
- *  Version: 3.5.36 (20140603)
- *  This version is for 2.6 and 3 series kernels.
+ *  Version: 3.9.01 (20181016)
+ *  This version is for 2.6, 3 and 4 series kernels.
  *
  * Documentation
  * =
  * A web site for the SG device driver can be found at:
- * http://sg.danny.cz/sg  [alternatively check the MAINTAINERS file]
+ *   http://sg.danny.cz/sg  [alternatively check the MAINTAINERS file]
  * The documentation for the sg version 3 driver can be found at:
- * http://sg.danny.cz/sg/p/sg_v3_ho.html
+ *   http://sg.danny.cz/sg/p/sg_v3_ho.html
  * Also see: /Documentation/scsi/scsi-generic.txt
  *
  * For utility and test programs see: http://sg.danny.cz/sg/sg3_utils.html
@@ -33,242 +33,12 @@
 extern int sg_big_buff; /* for sysctl */
 #endif
 
+#include 
 
-typedef struct sg_iovec /* same structure as used by readv() Linux system */
-{   /* call. It defines one scatter-gather element. */
-void __user *iov_base;  /* Starting address  */
-size_t iov_len; /* Length in bytes  */
-} sg_iovec_t;
-
-
-typedef struct sg_io_hdr
-{
-int interface_id;   /* [i] 'S' for SCSI generic (required) */
-int dxfer_direction;/* [i] data transfer direction  */
-unsigned char cmd_len;  /* [i] SCSI command length */
-unsigned char mx_sb_len;/* [i] max length to write to sbp */
-unsigned short iovec_count; /* [i] 0 implies no scatter gather */
-unsigned int dxfer_len; /* [i] byte count of data transfer */
-void __user *dxferp;   /* [i], [*io] points to data transfer memory
- or scatter gather list */
-unsigned char __user *cmdp; /* [i], [*i] points to command to perform */
-void __user *sbp;  /* [i], [*o] points to sense_buffer memory */
-unsigned int timeout;   /* [i] MAX_UINT->no timeout (unit: millisec) */
-unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */
-int pack_id;/* [i->o] unused internally (normally) */
-void __user * usr_ptr;  /* [i->o] unused internally */
-unsigned char status;   /* [o] scsi status */
-unsigned char masked_status;/* [o] shifted, masked scsi status */
-unsigned char msg_status;   /* [o] messaging level data (optional) */
-unsigned char sb_len_wr;/* [o] byte count actually written to sbp */
-unsigned short host_status; /* [o] errors from host adapter */
-unsigned short driver_status;/* [o] errors from software driver */
-int resid;  /* [o] dxfer_len - actual_transferred */
-unsigned int duration;  /* [o] time taken by cmd (unit: millisec) */
-unsigned int info;  /* [o] auxiliary information */
-} sg_io_hdr_t;  /* 64 bytes long (on i386) */
-
-#define SG_INTERFACE_ID_ORIG 'S'
-
-/* Use negative values to flag difference from original sg_header structure */
-#define SG_DXFER_NONE (-1)  /* e.g. a SCSI Test Unit Ready command */
-#define SG_DXFER_TO_DEV (-2)/* e.g. a SCSI WRITE command */
-#define SG_DXFER_FROM_DEV (-3)  /* e.g. a SCSI READ command */
-#define SG_DXFER_TO_FROM_DEV (-4) /* treated like SG_DXFER_FROM_DEV with the
-  additional property than during indirect
-  

[PATCH v3 4/8] sg: expand request states

2018-10-26 Thread Douglas Gilbert
Introduce the new sg_rq_state enumerations for tracking the
lifetime of a sg_request. SG_RQ_DATA_THRESHOLD is a
default value that if the data length of a request exceeds
then, after that request is completed, the data buffer will
be freed up as the sg_request object is placed on the free
list. SG_TOT_FD_THRESHOLD is a default, per file descriptor
value that the sum of outstanding command data lengths is not
allowed to exceed.

Signed-off-by: Douglas Gilbert 
---

The '#if 0's are temporary and removed in a later patch.
They allow the following large and complex patch (5 of 8)
to be a bit shorter and still compile.

 drivers/scsi/sg.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 94e13a1d21a5..a76395f16fb1 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -75,6 +75,24 @@ static int sg_proc_init(void);
  */
 #define SG_MAX_CDB_SIZE 252
 
+/* Following enum contains the states of sg_request::rq_state */
+enum sg_rq_state {
+   SG_RQ_INACTIVE = 0, /* request not in use (e.g. on fl) */
+   SG_RQ_INFLIGHT, /* SCSI request issued, no response yet */
+   SG_RQ_AWAIT_READ,   /* response received, awaiting read */
+   SG_RQ_DONE_READ,/* read is ongoing or done */
+   SG_RQ_BUSY, /* example: reserve request changing size */
+};
+
+/* free up requests larger than this dlen size after use */
+#define SG_RQ_DATA_THRESHOLD (128 * 1024)
+
+/* If sum_of(dlen) of a fd exceeds this, write() will yield E2BIG */
+#define SG_TOT_FD_THRESHOLD (16 * 1024 * 1024)
+
+#define SG_TIME_UNIT_MS 0   /* milliseconds */
+#define SG_TIME_UNIT_NS 1   /* nanoseconds */
+#define SG_DEF_TIME_UNIT SG_TIME_UNIT_MS
 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
 
 int sg_big_buff = SG_DEF_RESERVED_SIZE;
@@ -950,6 +968,7 @@ sg_fill_request_table(struct sg_fd *sfp, struct sg_req_info 
*rinfo)
}
 }
 
+#if 0  /* temporary to shorten big patch */
 static long
 sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
 {
@@ -1227,6 +1246,7 @@ sg_compat_ioctl(struct file *filp, unsigned int cmd_in, 
unsigned long arg)
return -ENOIOCTLCMD;
 }
 #endif
+#endif /* temporary to shorten big patch */
 
 static __poll_t
 sg_poll(struct file *filp, poll_table * wait)
@@ -1496,10 +1516,12 @@ static const struct file_operations sg_fops = {
.read = sg_read,
.write = sg_write,
.poll = sg_poll,
+#if 0  /* temporary to shorten big patch */
.unlocked_ioctl = sg_ioctl,
 #ifdef CONFIG_COMPAT
.compat_ioctl = sg_compat_ioctl,
 #endif
+#endif /* temporary to shorten big patch */
.open = sg_open,
.mmap = sg_mmap,
.release = sg_release,
@@ -2422,12 +2444,16 @@ static const struct seq_operations devstrs_seq_ops = {
.show  = sg_proc_seq_show_devstrs,
 };
 
+#if 0  /* temporary to shorten big patch */
 static int sg_proc_seq_show_debug(struct seq_file *s, void *v);
+#endif /* temporary to shorten big patch */
 static const struct seq_operations debug_seq_ops = {
.start = dev_seq_start,
.next  = dev_seq_next,
.stop  = dev_seq_stop,
+#if 0  /* temporary to shorten big patch */
.show  = sg_proc_seq_show_debug,
+#endif /* temporary to shorten big patch */
 };
 
 static int
@@ -2601,6 +2627,8 @@ sg_proc_seq_show_devstrs(struct seq_file *s, void *v)
return 0;
 }
 
+#if 0  /* temporary to shorten big patch */
+
 /* must be called while holding sg_index_lock */
 static void
 sg_proc_debug_helper(struct seq_file *s, struct sg_device *sdp)
@@ -2704,6 +2732,7 @@ sg_proc_seq_show_debug(struct seq_file *s, void *v)
read_unlock_irqrestore(_index_lock, iflags);
return 0;
 }
+#endif /* temporary to shorten big patch */
 
 #endif /* CONFIG_SCSI_PROC_FS */
 
-- 
2.17.1



[PATCH v3 7/8] sg: rework ioctl handling

2018-10-26 Thread Douglas Gilbert
Rework ioctl handling, report clearly to the log which ioctl has
been invoked. Add a new "IOWR" ioctl: SG_SET_GET_EXTENDED which
permits several integer and boolean values to be "_SET_" (i.e.
passed into the driver, potentially changing its actions) and/or
read from the driver (the "_GET_" part) in a single operation.

Signed-off-by: Douglas Gilbert 
---

One feature of the new SG_SET_GET_EXTENDED ioctl is ability to
fetch the sg device minor number (e.g. the "3" in /dev/sg3)
associated with the current file descriptor. A boolean addition
is the ability to change command timekeeping on the current file
descriptor from units of milliseconds (the default) to
nanoseconds.

 drivers/scsi/sg.c | 535 +++---
 1 file changed, 409 insertions(+), 126 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 8b4a65340971..3e89bbd508de 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -90,8 +90,8 @@ enum sg_rq_state {
 /* If sum_of(dlen) of a fd exceeds this, write() will yield E2BIG */
 #define SG_TOT_FD_THRESHOLD (16 * 1024 * 1024)
 
-#define SG_TIME_UNIT_MS 0   /* milliseconds */
-#define SG_TIME_UNIT_NS 1   /* nanoseconds */
+#define SG_TIME_UNIT_MS 0  /* milliseconds */
+#define SG_TIME_UNIT_NS 1  /* nanoseconds */
 #define SG_DEF_TIME_UNIT SG_TIME_UNIT_MS
 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
 
@@ -186,7 +186,6 @@ struct sg_fd {  /* holds the state of a file 
descriptor */
bool cmd_q; /* true -> allow command queuing, false -> don't */
bool keep_orphan;/* false -> drop (def), true -> keep for read() */
bool mmap_called;   /* false -> mmap() never called on this fd */
-   bool sse_seen;  /* SG_SET_EXTENDED ioctl seen */
bool time_in_ns;/* report times in nanoseconds */
u8 next_cmd_len;/* 0: automatic, >0: use on next write() */
struct sg_request *reserve_srp; /* allocate on open(), starts on fl */
@@ -240,6 +239,8 @@ static void sg_remove_request(struct sg_fd *sfp, struct 
sg_request *srp);
 static struct sg_device *sg_get_dev(int min_dev);
 static void sg_device_destroy(struct kref *kref);
 static const char *sg_rq_state_str(u8 rq_state, bool long_str);
+static struct sg_request *sg_mk_srp(struct sg_fd *sfp, bool first,
+   rwlock_t *rwlp, unsigned long *iflagsp);
 
 #define SZ_SG_HEADER sizeof(struct sg_header)  /* v1 and v2 header */
 #define SZ_SG_IO_HDR sizeof(struct sg_io_hdr)  /* v3 header */
@@ -508,9 +509,9 @@ sg_read(struct file *filp, char __user *buf, size_t count, 
loff_t * ppos)
return IS_ERR(sfp) ? PTR_ERR(sfp) : -ENXIO;
}
sdp = sfp->parentdp;
+   SG_LOG(3, sdp, "%s: read() count=%d\n", __func__, (int)count);
if (IS_ERR_OR_NULL(sdp))
return IS_ERR(sdp) ? PTR_ERR(sdp) : -ENXIO;
-   SG_LOG(3, sdp, "%s: read() count=%d\n", __func__, (int)count);
 
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
@@ -815,11 +816,11 @@ sg_v3_write(struct sg_fd *sfp, struct file *file, const 
char __user *buf,
return -ENOSYS;
if (hp->flags & SG_FLAG_MMAP_IO) {
if (!list_empty(>rq_list))
-   return -EBUSY;  /* already active requests on fd */
+   return -EBUSY;  /* already active requests on fd */
if (hp->dxfer_len > sfp->reserve_srp->data.dlen)
-   return -ENOMEM; /* MMAP_IO size must fit in reserve */
+   return -ENOMEM; /* MMAP_IO size must fit in reserve */
if (hp->flags & SG_FLAG_DIRECT_IO)
-   return -EINVAL; /* not both MMAP_IO and DIRECT_IO */
+   return -EINVAL; /* not both MMAP_IO and DIRECT_IO */
}
sfp->cmd_q = true; /* when sg_io_hdr seen, set command queuing on */
ul_timeout = msecs_to_jiffies(hp->timeout);
@@ -857,7 +858,7 @@ sg_common_write(struct sg_fd *sfp, const struct sg_io_hdr 
*hi_p,
srp = sg_add_request(sfp, hi_p->dxfer_len, false);
if (IS_ERR(srp))
return srp;
-   srp->header = *hi_p;/* structure assignment, could memcpy */
+   srp->header = *hi_p;/* structure assignment, could memcpy */
hp = >header;
srp->data.cmd_opcode = cmnd[0]; /* hold opcode of command */
hp->status = 0;
@@ -1026,69 +1027,300 @@ srp_state_or_detaching(struct sg_device *sdp, struct 
sg_request *srp)
return ret;
 }
 
+/* For handling ioctl(SG_IO). Returns 0 on success else a negated errno */
+static int
+sg_sg_io(struct file *filp, struct sg_device *sdp, struct sg_fd *sfp,
+void __user *p)
+{
+   bool read_only = (O_RDWR != (filp->f_flags & O_ACCMODE));
+   int result;
+   unsigned long iflags;
+   struct sg_request *srp;
+   const char *cp;
+
+   SG_LOG(3, sdp, "%s:  

[PATCH v3 2/8] sg: introduce sg_log macro

2018-10-26 Thread Douglas Gilbert
Introduce the SG_LOG macro to replace long-winded
'SCSI_LOG_TIMEOUT(3, sg_printk ...' debug messages. Use __func__
wherever appropriate to make the debug messages more portable.

Signed-off-by: Douglas Gilbert 
---

Reviewers want SCSI_LOG_* style logging replaced. But with
what? One suggestion is the trace subsystem but that seems
data and event oriented whereas the current logging is call
based with extra messages when error paths are taken. There
are many debugging hours of work crafted into the current
SCSI_LOG_* messages that should not be thrown out for some
pretty solution without additional benefits.

 drivers/scsi/sg.c | 162 +-
 1 file changed, 72 insertions(+), 90 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 78a35e63d177..94e13a1d21a5 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -216,9 +216,24 @@ static void sg_device_destroy(struct kref *kref);
 /* #define SZ_SG_IOVEC sizeof(struct sg_iovec) synonym for 'struct iovec' */
 #define SZ_SG_REQ_INFO sizeof(struct sg_req_info)
 
-#define sg_printk(prefix, sdp, fmt, a...) \
-   sdev_prefix_printk(prefix, (sdp)->device,   \
-  (sdp)->disk->disk_name, fmt, ##a)
+/*
+ * Kernel needs to be built with CONFIG_SCSI_LOGGING to see log messages.
+ * 'depth' is a number between 1 (most severe) and 7 (most noisy, most
+ * information). All messages are logged as informational (KERN_INFO). In
+ * the unexpected situation where sdp is NULL the macro reverts to a pr_info
+ * and ignores CONFIG_SCSI_LOGGING and always prints to the log.
+ */
+#define SG_LOG(depth, sdp, fmt, a...)  \
+   do {\
+   if (IS_ERR_OR_NULL(sdp)) {  \
+   pr_info("sg: sdp=NULL_or_ERR, " fmt, ##a);  \
+   } else {\
+   SCSI_LOG_TIMEOUT(depth, sdev_prefix_printk( \
+KERN_INFO, (sdp)->device,  \
+(sdp)->disk->disk_name, fmt,   \
+##a)); \
+   }   \
+   } while (0)
 
 /*
  * The SCSI interfaces that use read() and write() as an asynchronous variant 
of
@@ -316,9 +331,8 @@ sg_open(struct inode *inode, struct file *filp)
sdp = sg_get_dev(min_dev);
if (IS_ERR(sdp))
return PTR_ERR(sdp);
-
-   SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp,
- "sg_open: flags=0x%x\n", flags));
+   SG_LOG(3, sdp, "%s: flags=0x%x; device open count prior=%d\n",
+  __func__, flags, sdp->open_cnt);
 
/* This driver's module count bumped by fops_get in  */
/* Prevent the device driver from vanishing while we sleep */
@@ -414,9 +428,10 @@ sg_release(struct inode *inode, struct file *filp)
return IS_ERR(sfp) ? PTR_ERR(sfp) : -ENXIO;
}
sdp = sfp->parentdp;
-   SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "sg_release\n"));
if (IS_ERR_OR_NULL(sdp))
return IS_ERR(sdp) ? PTR_ERR(sdp) : -ENXIO;
+   SG_LOG(3, sdp, "%s: device open count prior=%d\n", __func__,
+  sdp->open_cnt);
 
mutex_lock(>open_rel_lock);
scsi_autopm_put_device(sdp->device);
@@ -462,8 +477,7 @@ sg_read(struct file *filp, char __user *buf, size_t count, 
loff_t * ppos)
sdp = sfp->parentdp;
if (IS_ERR_OR_NULL(sdp))
return IS_ERR(sdp) ? PTR_ERR(sdp) : -ENXIO;
-   SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "%s: count=%d\n",
-__func__, (int)count));
+   SG_LOG(3, sdp, "%s: read() count=%d\n", __func__, (int)count);
 
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
@@ -663,10 +677,9 @@ sg_write(struct file *filp, const char __user *buf, size_t 
count, loff_t * ppos)
return IS_ERR(sfp) ? PTR_ERR(sfp) : -ENXIO;
}
sdp = sfp->parentdp;
+   SG_LOG(3, sdp, "%s: write(3rd arg) count=%d\n", __func__, (int)count);
if (IS_ERR_OR_NULL(sdp))
return IS_ERR(sdp) ? PTR_ERR(sdp) : -ENXIO;
-   SCSI_LOG_TIMEOUT(3, sg_printk(KERN_INFO, sdp, "%s: count=%d\n",
-__func__, (int)count));
if (atomic_read(>detaching))
return -ENODEV;
if (!((filp->f_flags & O_NONBLOCK) ||
@@ -687,8 +700,7 @@ sg_write(struct file *filp, const char __user *buf, size_t 
count, loff_t * ppos)
return -EIO;/* minimum scsi command length is 6 bytes */
 
if (!(srp = sg_add_request(sfp))) {
-   SCSI_LOG_TIMEOUT(1, sg_printk(KERN_INFO, sdp,
- "sg_write: queue 

[PATCH v3 1/8] sg: types and naming cleanup

2018-10-26 Thread Douglas Gilbert
Remove typedefs and use better type names like bool and u8 where
appropriate. Rename some variables and functions for clarity.
Adjust formatting (e.g. function definitions) to be more
consistent across the driver.

Signed-off-by: Douglas Gilbert 
---

The intention is to move to sg_version_num 40001 when a second
patchset implementing SG_IOSUBMIT and friends is applied. In
the meantime, move from the latest version number in the kernel
(30536) to 30901 to indicate a significant change but not yet
implementing the sg v4 interface.

 drivers/scsi/sg.c | 827 ++
 1 file changed, 467 insertions(+), 360 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c6ad00703c5b..78a35e63d177 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -7,7 +7,7 @@
  * Original driver (sg.c):
  *Copyright (C) 1992 Lawrence Foard
  * Version 2 and 3 extensions to driver:
- *Copyright (C) 1998 - 2014 Douglas Gilbert
+ *Copyright (C) 1998 - 2018 Douglas Gilbert
  *
  * 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
@@ -16,16 +16,9 @@
  *
  */
 
-static int sg_version_num = 30536; /* 2 digits for each component */
-#define SG_VERSION_STR "3.5.36"
+static int sg_version_num = 30901; /* 2 digits for each component */
+#define SG_VERSION_STR "3.9.01"
 
-/*
- *  D. P. Gilbert (dgilb...@interlog.com), notes:
- *  - scsi logging is available via SCSI_LOG_TIMEOUT macros. First
- *the kernel/module needs to be built with CONFIG_SCSI_LOGGING
- *(otherwise the macros compile to empty statements).
- *
- */
 #include 
 
 #include 
@@ -52,6 +45,8 @@ static int sg_version_num = 30536;/* 2 digits for each 
component */
 #include 
 #include 
 #include  /* for sg_check_file_access() */
+#include 
+#include 
 
 #include "scsi.h"
 #include 
@@ -64,7 +59,7 @@ static int sg_version_num = 30536;/* 2 digits for each 
component */
 
 #ifdef CONFIG_SCSI_PROC_FS
 #include 
-static char *sg_version_date = "20140603";
+static char *sg_version_date = "20181019";
 
 static int sg_proc_init(void);
 #endif
@@ -73,7 +68,8 @@ static int sg_proc_init(void);
 
 #define SG_MAX_DEVS 32768
 
-/* SG_MAX_CDB_SIZE should be 260 (spc4r37 section 3.1.30) however the type
+/*
+ * SG_MAX_CDB_SIZE should be 260 (spc4r37 section 3.1.30) however the type
  * of sg_io_hdr::cmd_len can only represent 255. All SCSI commands greater
  * than 16 bytes are "variable length" whose length is a multiple of 4
  */
@@ -100,44 +96,54 @@ static int sg_add_device(struct device *, struct 
class_interface *);
 static void sg_remove_device(struct device *, struct class_interface *);
 
 static DEFINE_IDR(sg_index_idr);
-static DEFINE_RWLOCK(sg_index_lock);   /* Also used to lock
-  file descriptor list 
for device */
+static DEFINE_RWLOCK(sg_index_lock); /* Also used to lock fd list for device */
 
 static struct class_interface sg_interface = {
.add_dev= sg_add_device,
.remove_dev = sg_remove_device,
 };
 
-typedef struct sg_scatter_hold { /* holding area for scsi scatter gather info 
*/
-   unsigned short k_use_sg; /* Count of kernel scatter-gather pieces */
-   unsigned sglist_len; /* size of malloc'd scatter-gather list ++ */
-   unsigned bufflen;   /* Size of (aggregate) data buffer */
-   struct page **pages;
-   int page_order;
-   char dio_in_use;/* 0->indirect IO (or mmap), 1->dio */
-   unsigned char cmd_opcode; /* first byte of command */
-} Sg_scatter_hold;
+struct sg_v4_hold {/* parts of sg_io_v4 object needed in async usage */
+   __user u8 *usr_ptr; /* derived from sg_io_v4::usr_ptr */
+   __user u8 *sbp; /* derived from sg_io_v4::response */
+   u16 cmd_len;/* truncated of sg_io_v4::request_len */
+   u16 max_sb_len; /* truncated of sg_io_v4::max_response_len */
+   u32 flags;  /* copy of sg_io_v4::flags */
+};
+
+struct sg_scatter_hold { /* holding area for scsi scatter gather info */
+   struct page **pages;/* num_sgat element array of struct page* */
+   int page_order; /* byte_len = (page_size * (2**page_order)) */
+   int dlen;   /* Byte length of data buffer */
+   unsigned short num_sgat;/* actual number of scatter-gather segments */
+   bool dio_in_use;/* false->indirect IO (or mmap), true->dio */
+   u8 cmd_opcode;  /* first byte of command */
+};
 
 struct sg_device;  /* forward declarations */
 struct sg_fd;
 
-typedef struct sg_request {/* SG_MAX_QUEUE requests outstanding per file */
+struct sg_request {/* SG_MAX_QUEUE requests outstanding per file */
struct list_head entry; /* list entry */
struct sg_fd *parentfp; /* NULL -> not in use */
-   Sg_scatter_hold 

[PATCH v3 0/8] sg: major cleanup, remove max_queue limit

2018-10-26 Thread Douglas Gilbert
The intention is to add two new ioctls as proposed by Linus Torvalds:
SG_IOSUBMIT and SG_IORECEIVE to replace the write()/read() async
interface.

But first, clean up the driver and remove the SG_MAX_QUEUE limit of
no more than 16 queued commands on a file descriptor at a time. A
free list has been added and the de-allocation of sg_request
objects is deferred until the close() of a file. Locking is
extensively reworked, especially at the struct sg_fd and
sg_request level.

A new SG_SET_GET_EXTENDED ioctl has been added. It allows multiple
integer values and booleans to be written to and/or read from the
driver. An example is changing and/or reading the reserved request
data length (there is one of these per fd). An example of a new
feature is changing and/or reading the per-fd upper limit on the
sum of outstanding data buffer sizes (default is 16 MB). An
example of a boolean is a bit to do all following command
timekeeping in nanoseconds rather that the default millseconds.

A later patchset will add implementations for the SG_IOSUBMIT and
SG_IORECEIVE plus handling of the sg v4 interface with the
existing SG_IO ioctl.

This patchset is against Martin Petersen's 4.20/scsi-queue branch.

ToDo:
  - work out more modern technique for logging function invocations
info with some error paths.

Changes since v2:
  - fix problem with reserve request not being placed on fl
  - fix locking problem with sg_reserved_sz()
  - fix sum_fd_dlens counting problem
  - change new ioctl base numbers back to 0x22
  - arrange fl in ascending dlen order apart from dlen=0
entries at tail
  - SG_GET_REQUEST_TABLE ioctl first fill from active list
then, if there is room, it fills from the free list
  - add SG_SEIRV_DEV_FL_RQS to fetch count of all free list
entries on the device the fd is associated with

Changes since v1:
  - remove redundant casts from private_data field
  - introduce atomic to address locking problems around
sg_fd::sum_fd_dlens
  - replace rq_state defines with an enumeration
  - add __must_hold() annotation to sg_fill_request_table()
  - fix compile/build problem around the 4th and 5th patches
  - add read_value[SG_SEIRV_*] options in SG_SET_GET_EXTENDED
ioctl and increase structure size from 64 to 96 bytes


Douglas Gilbert (8):
  sg: types and naming cleanup
  sg: introduce sg_log macro
  sg: split header, expand and correct descriptions
  sg: expand request states
  sg: add free list, rework locking
  sg: complete locking changes on ioctl+debug
  sg: rework ioctl handling
  sg: user controls for q_at_head, read_value

 drivers/scsi/sg.c  | 2621 ++--
 include/scsi/sg.h  |  268 +---
 include/uapi/scsi/sg.h |  414 +++
 3 files changed, 2156 insertions(+), 1147 deletions(-)
 create mode 100644 include/uapi/scsi/sg.h

-- 
2.17.1



Re: [PATCH v3 2/5] qla2xxx_nvmet: Add files for FC-NVMe Target support

2018-10-26 Thread Madhani, Himanshu
Hi James, 

> On Oct 25, 2018, at 11:23 AM, James Smart  wrote:
> 
> External Email
> 
> On 9/28/2018 3:46 PM, Himanshu Madhani wrote:
>> + .target_features= NVMET_FCTGTFEAT_READDATA_RSP |
>> + NVMET_FCTGTFEAT_CMD_IN_ISR |
>> + NVMET_FCTGTFEAT_OPDONE_IN_ISR,
>> 
> 
> Himanshu,
> 
> I'm looking at these but had a quick question.   Did you really want the
> IN_ISR flags set ?  they schedule processing vs calling the nvmet
> routines inline. The intent was the queueing was only needed if in the
> hard isr routine. Last contact I had with your group said you were in
> soft isr routines and inline calling would be used.  I'm asking because
> I had intended to remove these flags/features.
> 
> -- james
> 

Looks like there was a miss to remove these flags when we rebased code on 
4.20/scsi-queue. 
After the original submission where this flag was present, we have removed this 
flag in our 
internal testing but the code sent out after rebase missed that update. I’ll 
send v4 with 
the flag removed. 

Please let me know you have any other comments that I can incorporate in v4 

Thanks,
- Himanshu



Re: [PATCH] bsg: convert to use blk-mq

2018-10-26 Thread Jens Axboe
On 10/26/18 10:06 AM, Benjamin Block wrote:
> On Thu, Oct 25, 2018 at 05:12:59PM -0600, Jens Axboe wrote:
>> On 10/23/18 12:07 PM, Jens Axboe wrote:
>>> On 10/23/18 11:40 AM, Benjamin Block wrote:

 So I tried 4.19.0 with only the two patches from you:
 http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=2b2ffa16193e9a69a076595ed64429b8cc9b42aa
 http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=142dc9f36e3113b6a76d472978c33c8c2a2b702c

 This fixed the first warning from before, as you suggested, but it still
 crash like this:

 [ ] Unable to handle kernel pointer dereference in virtual kernel address 
 space
 [ ] Failing address:  TEID: 0483
 [ ] Fault in home space mode while using kernel ASCE.
 [ ] AS:025f0007 R3:dffb8007 S:dffbf000 
 P:013d
 [ ] Oops: 0004 ilc:3 [#1] PREEMPT SMP DEBUG_PAGEALLOC
 [ ] Modules linked in: 
 [ ] CPU: 2 PID: 609 Comm: kworker/2:1H Kdump: loaded Tainted: GW   
   4.19.0-bb-next+ #1
 [ ] Hardware name: IBM 3906 M03 704 (LPAR)
 [ ] Workqueue: kblockd blk_mq_run_work_fn
 [ ] Krnl PSW : 0704e0018000 03ff806a6b40 
 (zfcp_fc_exec_bsg_job+0x1c0/0x440 [zfcp])
 [ ]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
 [ ] Krnl GPRS:  83e0f3c0  
 0300
 [ ]0300 03ff806a6b3a a86b5948 
 a86b5988
 [ ]83e0f3f0  a86b5938 
 984aee80
 [ ]a86b5800 03ff806ba950 03ff806a6b3a 
 98a5ed88
 [ ] Krnl Code: 03ff806a6b30: b9040029lgr %r2,%r9
03ff806a6b34: c0e58b7ebrasl   
 %r14,3ff80698230
   #03ff806a6b3a: e310f0a4lg  %r1,160(%r15)
   >03ff806a6b40: e3109024stg %r1,0(%r9)
03ff806a6b46: 4120a040la  %r2,64(%r10)
03ff806a6b4a: c0e58ae7brasl   
 %r14,3ff80698118
03ff806a6b50: e310a044lg  %r1,64(%r10)
03ff806a6b56: e310f0a00024stg %r1,160(%r15)
 [ ] Call Trace:
 [ ] ([<03ff806a6aa2>] zfcp_fc_exec_bsg_job+0x122/0x440 [zfcp])
 [ ]  [<03ff8061e928>] fc_bsg_dispatch+0x310/0x398 [scsi_transport_fc]
 [ ]  [<00d2995a>] bsg_queue_rq+0x15a/0x198
 [ ]  [<00d03566>] blk_mq_dispatch_rq_list+0x966/0xf90
 [ ]  [<00d0e37a>] blk_mq_sched_dispatch_requests+0x3fa/0x410
 [ ]  [<00cfc230>] __blk_mq_run_hw_queue+0x218/0x248
 [ ]  [<001cb124>] process_one_work+0x8c4/0xe90
 [ ]  [<001cbe58>] worker_thread+0x768/0xbb0
 [ ]  [<001dc67a>] kthread+0x22a/0x248
 [ ]  [<0137b812>] kernel_thread_starter+0x6/0xc
 [ ]  [<0137b80c>] kernel_thread_starter+0x0/0xc
 [ ] INFO: lockdep is turned off.
 [ ] Last Breaking-Event-Address:
 [ ]  [<005d9b08>] __asan_store8+0x98/0xa0
 [ ]
 [ ] Kernel panic - not syncing: Fatal exception: panic_on_oops

 zfcp_fc_exec_bsg_job+0x1c0 is here:

 int zfcp_fc_exec_bsg_job(struct bsg_job *job)
 {
 struct Scsi_Host *shost;
 struct zfcp_adapter *adapter;
 struct zfcp_fsf_ct_els *ct_els = job->dd_data;
 struct fc_bsg_request *bsg_request = job->request;
 struct fc_rport *rport = fc_bsg_to_rport(job);

 shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
 adapter = (struct zfcp_adapter *)shost->hostdata[0];

 if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
 return -EINVAL;

 ==> ct_els->req = job->request_payload.sg_list;
 ct_els->resp = job->reply_payload.sg_list;
 ct_els->handler_data = job;

 switch (bsg_request->msgcode) {
 case FC_BSG_RPT_ELS:
 case FC_BSG_HST_ELS_NOLOGIN:
 return zfcp_fc_exec_els_job(job, adapter);
 case FC_BSG_RPT_CT:
 case FC_BSG_HST_CT:
 return zfcp_fc_exec_ct_job(job, adapter);
 default:
 return -EINVAL;
 }
 }

 I took a dump to find out how struct bsg_job looks like when it crashes
 (register clobbering isn't as bad here and I verified that job->dev is 
 valid).

 crash> print *((struct bsg_job *)0xa86b5938)
 $5 = {
   dev = 0x9af10358,
   kref = {
 refcount = {
   refs = {
 

Re: [PATCH] bsg: convert to use blk-mq

2018-10-26 Thread Benjamin Block
On Thu, Oct 25, 2018 at 05:12:59PM -0600, Jens Axboe wrote:
> On 10/23/18 12:07 PM, Jens Axboe wrote:
> > On 10/23/18 11:40 AM, Benjamin Block wrote:
> >>
> >> So I tried 4.19.0 with only the two patches from you:
> >> http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=2b2ffa16193e9a69a076595ed64429b8cc9b42aa
> >> http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=142dc9f36e3113b6a76d472978c33c8c2a2b702c
> >>
> >> This fixed the first warning from before, as you suggested, but it still
> >> crash like this:
> >>
> >> [ ] Unable to handle kernel pointer dereference in virtual kernel address 
> >> space
> >> [ ] Failing address:  TEID: 0483
> >> [ ] Fault in home space mode while using kernel ASCE.
> >> [ ] AS:025f0007 R3:dffb8007 S:dffbf000 
> >> P:013d
> >> [ ] Oops: 0004 ilc:3 [#1] PREEMPT SMP DEBUG_PAGEALLOC
> >> [ ] Modules linked in: 
> >> [ ] CPU: 2 PID: 609 Comm: kworker/2:1H Kdump: loaded Tainted: GW   
> >>   4.19.0-bb-next+ #1
> >> [ ] Hardware name: IBM 3906 M03 704 (LPAR)
> >> [ ] Workqueue: kblockd blk_mq_run_work_fn
> >> [ ] Krnl PSW : 0704e0018000 03ff806a6b40 
> >> (zfcp_fc_exec_bsg_job+0x1c0/0x440 [zfcp])
> >> [ ]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3
> >> [ ] Krnl GPRS:  83e0f3c0  
> >> 0300
> >> [ ]0300 03ff806a6b3a a86b5948 
> >> a86b5988
> >> [ ]83e0f3f0  a86b5938 
> >> 984aee80
> >> [ ]a86b5800 03ff806ba950 03ff806a6b3a 
> >> 98a5ed88
> >> [ ] Krnl Code: 03ff806a6b30: b9040029lgr %r2,%r9
> >>03ff806a6b34: c0e58b7ebrasl   
> >> %r14,3ff80698230
> >>   #03ff806a6b3a: e310f0a4lg  %r1,160(%r15)
> >>   >03ff806a6b40: e3109024stg %r1,0(%r9)
> >>03ff806a6b46: 4120a040la  %r2,64(%r10)
> >>03ff806a6b4a: c0e58ae7brasl   
> >> %r14,3ff80698118
> >>03ff806a6b50: e310a044lg  %r1,64(%r10)
> >>03ff806a6b56: e310f0a00024stg %r1,160(%r15)
> >> [ ] Call Trace:
> >> [ ] ([<03ff806a6aa2>] zfcp_fc_exec_bsg_job+0x122/0x440 [zfcp])
> >> [ ]  [<03ff8061e928>] fc_bsg_dispatch+0x310/0x398 [scsi_transport_fc]
> >> [ ]  [<00d2995a>] bsg_queue_rq+0x15a/0x198
> >> [ ]  [<00d03566>] blk_mq_dispatch_rq_list+0x966/0xf90
> >> [ ]  [<00d0e37a>] blk_mq_sched_dispatch_requests+0x3fa/0x410
> >> [ ]  [<00cfc230>] __blk_mq_run_hw_queue+0x218/0x248
> >> [ ]  [<001cb124>] process_one_work+0x8c4/0xe90
> >> [ ]  [<001cbe58>] worker_thread+0x768/0xbb0
> >> [ ]  [<001dc67a>] kthread+0x22a/0x248
> >> [ ]  [<0137b812>] kernel_thread_starter+0x6/0xc
> >> [ ]  [<0137b80c>] kernel_thread_starter+0x0/0xc
> >> [ ] INFO: lockdep is turned off.
> >> [ ] Last Breaking-Event-Address:
> >> [ ]  [<005d9b08>] __asan_store8+0x98/0xa0
> >> [ ]
> >> [ ] Kernel panic - not syncing: Fatal exception: panic_on_oops
> >>
> >> zfcp_fc_exec_bsg_job+0x1c0 is here:
> >>
> >> int zfcp_fc_exec_bsg_job(struct bsg_job *job)
> >> {
> >> struct Scsi_Host *shost;
> >> struct zfcp_adapter *adapter;
> >> struct zfcp_fsf_ct_els *ct_els = job->dd_data;
> >> struct fc_bsg_request *bsg_request = job->request;
> >> struct fc_rport *rport = fc_bsg_to_rport(job);
> >>
> >> shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
> >> adapter = (struct zfcp_adapter *)shost->hostdata[0];
> >>
> >> if (!(atomic_read(>status) & ZFCP_STATUS_COMMON_OPEN))
> >> return -EINVAL;
> >>
> >> ==> ct_els->req = job->request_payload.sg_list;
> >> ct_els->resp = job->reply_payload.sg_list;
> >> ct_els->handler_data = job;
> >>
> >> switch (bsg_request->msgcode) {
> >> case FC_BSG_RPT_ELS:
> >> case FC_BSG_HST_ELS_NOLOGIN:
> >> return zfcp_fc_exec_els_job(job, adapter);
> >> case FC_BSG_RPT_CT:
> >> case FC_BSG_HST_CT:
> >> return zfcp_fc_exec_ct_job(job, adapter);
> >> default:
> >> return -EINVAL;
> >> }
> >> }
> >>
> >> I took a dump to find out how struct bsg_job looks like when it crashes
> >> (register clobbering isn't as bad here and I verified that job->dev is 
> >> valid).
> >>
> >> crash> print *((struct bsg_job *)0xa86b5938)
> >> $5 = {
> >>   dev = 0x9af10358,
> >>   kref = {
> >> refcount = {
> >>   refs = {
> >> counter = 0x1
> >>   }
> >> }
> >>  

[PATCH v3.5 8/8] sg: user controls for q_at_head, read_value

2018-10-26 Thread Douglas Gilbert
Add a SG_SET_GET_EXTENDED ioctl control for whether commands
will be queued_at_head or queued_at_tail by the block layer
(together with the scsi mid-level). It has file scope.

Also add a read_value integer the can be used by write a
value from the SG_SEIRV_* group then the corresponding value
will be returned.

Signed-off-by: Douglas Gilbert 
---

The user can still override the new file scope setting on a
a per command basis with the SG_FLAG_Q_AT_HEAD and
SG_FLAG_Q_AT_TAIL in the sg v3 and v4 structures.

An example of read_value usage is to write the value
SG_SEIRV_FL_RQS to the read_value field. Then after the
SG_SET_GET_EXTENDED ioctl is run, the number of (inactive)
requests currently on this file descriptor's request free
list is placed in the read_value field.

Added in v3 is SG_SEIRV_DEV_FL_RQS which is an expansion of
SG_SEIRV_FL_RQS. SG_SEIRV_DEV_FL_RQS counts free list entries
on all sg file descriptors currently open on the device that
the file descriptor (given to ioctl()) is associated with.


Change since v3 [patches 1 to 7 of 8 are unchanged, this for 8/8]:
  - move sg_version_date definition from inside CONFIG_SCSI_PROC_FS
conditional out to full file scope and near related definitions

 drivers/scsi/sg.c  | 160 +++--
 include/scsi/sg.h  |  32 ++---
 include/uapi/scsi/sg.h |  49 ++---
 3 files changed, 150 insertions(+), 91 deletions(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 3e89bbd508de..5ba92f112481 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -18,6 +18,7 @@
 
 static int sg_version_num = 30901; /* 2 digits for each component */
 #define SG_VERSION_STR "3.9.01"
+static char *sg_version_date = "20181024";
 
 #include 
 
@@ -59,7 +60,6 @@ static int sg_version_num = 30901;/* 2 digits for each 
component */
 
 #ifdef CONFIG_SCSI_PROC_FS
 #include 
-static char *sg_version_date = "20181019";
 
 static int sg_proc_init(void);
 #endif
@@ -95,6 +95,10 @@ enum sg_rq_state {
 #define SG_DEF_TIME_UNIT SG_TIME_UNIT_MS
 #define SG_DEFAULT_TIMEOUT mult_frac(SG_DEFAULT_TIMEOUT_USER, HZ, USER_HZ)
 
+#define SG_FD_Q_AT_TAIL true
+#define SG_FD_Q_AT_HEAD false
+#define SG_DEFAULT_Q_AT SG_FD_Q_AT_HEAD/* for backward compatibility */
+
 int sg_big_buff = SG_DEF_RESERVED_SIZE;
 /* N.B. This variable is readable and writeable via
/proc/scsi/sg/def_reserved_size . Each time sg_open() is called a buffer
@@ -187,6 +191,7 @@ struct sg_fd {  /* holds the state of a file 
descriptor */
bool keep_orphan;/* false -> drop (def), true -> keep for read() */
bool mmap_called;   /* false -> mmap() never called on this fd */
bool time_in_ns;/* report times in nanoseconds */
+   bool q_at_tail; /* queue at tail if true, head when false */
u8 next_cmd_len;/* 0: automatic, >0: use on next write() */
struct sg_request *reserve_srp; /* allocate on open(), starts on fl */
struct fasync_struct *async_qp; /* used by asynchronous notification */
@@ -238,7 +243,7 @@ static struct sg_request *sg_add_request(struct sg_fd *sfp, 
int dxfr_len,
 static void sg_remove_request(struct sg_fd *sfp, struct sg_request *srp);
 static struct sg_device *sg_get_dev(int min_dev);
 static void sg_device_destroy(struct kref *kref);
-static const char *sg_rq_state_str(u8 rq_state, bool long_str);
+static const char *sg_rq_state_str(enum sg_rq_state rq_state, bool long_str);
 static struct sg_request *sg_mk_srp(struct sg_fd *sfp, bool first,
rwlock_t *rwlp, unsigned long *iflagsp);
 
@@ -855,7 +860,7 @@ sg_common_write(struct sg_fd *sfp, const struct sg_io_hdr 
*hi_p,
 
if (h4p || !hi_p)
return ERR_PTR(-EOPNOTSUPP);
-   srp = sg_add_request(sfp, hi_p->dxfer_len, false);
+   srp = sg_add_request(sfp, hi_p->dxfer_len, sync);
if (IS_ERR(srp))
return srp;
srp->header = *hi_p;/* structure assignment, could memcpy */
@@ -897,9 +902,13 @@ sg_common_write(struct sg_fd *sfp, const struct sg_io_hdr 
*hi_p,
srp->start_ts = ktime_get_with_offset(TK_OFFS_BOOT);
else
hp->duration = jiffies_to_msecs(jiffies);
-   /* at tail if v3 or later interface and tail flag set */
-   at_head = !(hp->interface_id != '\0' &&
-   (SG_FLAG_Q_AT_TAIL & hp->flags));
+
+   if (hp->interface_id == '\0')   /* v1 and v2 interface */
+   at_head = true; /* backward compatibility */
+   else if (sfp->q_at_tail)  /* cmd flags can override sfd setting */
+   at_head = (hp->flags & SG_FLAG_Q_AT_HEAD);
+   else/* this sfd is defaulting to head */
+   at_head = !(hp->flags & SG_FLAG_Q_AT_TAIL);
 
srp->rq->timeout = timeout;
kref_get(>f_ref); /* sg_rq_end_io() does kref_put(). */
@@ -1084,30 +1093,30 @@ sg_reserved_sz(struct sg_fd *sfp, struct 

Re: [PATCH v3 8/8] sg: user controls for q_at_head, read_value

2018-10-26 Thread kbuild test robot
Hi linux-scsi-owner,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on v4.19 next-20181019]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/linux-scsi-owner-vger-kernel-org/sg-types-and-naming-cleanup/20181026-220008
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: x86_64-randconfig-r0-10262157 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All errors (new ones prefixed by >>):

   In file included from include/linux/kernel.h:14:0,
from include/linux/list.h:9,
from include/linux/module.h:9,
from drivers/scsi/sg.c:22:
   drivers/scsi/sg.c: In function 'init_sg':
>> drivers/scsi/sg.c:2277:3: error: 'sg_version_date' undeclared (first use in 
>> this function)
  sg_version_date);
  ^
   include/linux/printk.h:315:34: note: in definition of macro 'pr_info'
 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
 ^~~
   drivers/scsi/sg.c:2277:3: note: each undeclared identifier is reported only 
once for each function it appears in
  sg_version_date);
  ^
   include/linux/printk.h:315:34: note: in definition of macro 'pr_info'
 printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
 ^~~
   drivers/scsi/sg.c: At top level:
   drivers/scsi/sg.c:246:20: warning: 'sg_rq_state_str' used but never defined
static const char *sg_rq_state_str(enum sg_rq_state rq_state, bool 
long_str);
   ^~~

vim +/sg_version_date +2277 drivers/scsi/sg.c

  2256  
  2257  static int __init
  2258  init_sg(void)
  2259  {
  2260  int rc;
  2261  
  2262  if (scatter_elem_sz < PAGE_SIZE) {
  2263  scatter_elem_sz = PAGE_SIZE;
  2264  scatter_elem_sz_prev = scatter_elem_sz;
  2265  }
  2266  if (def_reserved_size >= 0)
  2267  sg_big_buff = def_reserved_size;
  2268  else
  2269  def_reserved_size = sg_big_buff;
  2270  
  2271  rc = register_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), 
  2272  SG_MAX_DEVS, "sg");
  2273  if (rc)
  2274  return rc;
  2275  pr_info("Registered %s[char major=0x%x], version: %s, date: 
%s\n",
  2276  "sg device ", SCSI_GENERIC_MAJOR, SG_VERSION_STR,
> 2277  sg_version_date);
  2278  sg_sysfs_class = class_create(THIS_MODULE, "scsi_generic");
  2279  if ( IS_ERR(sg_sysfs_class) ) {
  2280  rc = PTR_ERR(sg_sysfs_class);
  2281  goto err_out;
  2282  }
  2283  sg_sysfs_valid = 1;
  2284  rc = scsi_register_interface(_interface);
  2285  if (0 == rc) {
  2286  #ifdef CONFIG_SCSI_PROC_FS
  2287  sg_proc_init();
  2288  #endif  /* CONFIG_SCSI_PROC_FS */
  2289  return 0;
  2290  }
  2291  class_destroy(sg_sysfs_class);
  2292  err_out:
  2293  unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), 
SG_MAX_DEVS);
  2294  return rc;
  2295  }
  2296  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: application/gzip


Re: [PATCH] bsg: convert to use blk-mq

2018-10-26 Thread Benjamin Block
On Fri, Oct 26, 2018 at 10:08:30AM -0600, Jens Axboe wrote:
> On 10/26/18 10:06 AM, Benjamin Block wrote:
> > On Thu, Oct 25, 2018 at 05:12:59PM -0600, Jens Axboe wrote:
> >> On 10/23/18 12:07 PM, Jens Axboe wrote:
> >>> On 10/23/18 11:40 AM, Benjamin Block wrote:
> 
>  So I tried 4.19.0 with only the two patches from you:
>  http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=2b2ffa16193e9a69a076595ed64429b8cc9b42aa
>  http://git.kernel.dk/cgit/linux-block/commit/?h=mq-conversions=142dc9f36e3113b6a76d472978c33c8c2a2b702c
> 
>  This fixed the first warning from before, as you suggested, but it still
>  crash like this:
> 
>  [ ] Unable to handle kernel pointer dereference in virtual kernel 
>  address space
>  [ ] Failing address:  TEID: 0483
>  [ ] Fault in home space mode while using kernel ASCE.
>  [ ] AS:025f0007 R3:dffb8007 S:dffbf000 
>  P:013d
>  [ ] Oops: 0004 ilc:3 [#1] PREEMPT SMP DEBUG_PAGEALLOC
>  [ ] Modules linked in: 
>  [ ] CPU: 2 PID: 609 Comm: kworker/2:1H Kdump: loaded Tainted: GW 
>  4.19.0-bb-next+ #1
>  [ ] Hardware name: IBM 3906 M03 704 (LPAR)
>  [ ] Workqueue: kblockd blk_mq_run_work_fn
>  [ ] Krnl PSW : 0704e0018000 03ff806a6b40 
>  (zfcp_fc_exec_bsg_job+0x1c0/0x440 [zfcp])
>  [ ]R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 
>  EA:3
>  [ ] Krnl GPRS:  83e0f3c0  
>  0300
>  [ ]0300 03ff806a6b3a a86b5948 
>  a86b5988
>  [ ]83e0f3f0  a86b5938 
>  984aee80
>  [ ]a86b5800 03ff806ba950 03ff806a6b3a 
>  98a5ed88
>  [ ] Krnl Code: 03ff806a6b30: b9040029lgr %r2,%r9
> 03ff806a6b34: c0e58b7ebrasl   
>  %r14,3ff80698230
>    #03ff806a6b3a: e310f0a4lg  
>  %r1,160(%r15)
>    >03ff806a6b40: e3109024stg %r1,0(%r9)
> 03ff806a6b46: 4120a040la  %r2,64(%r10)
> 03ff806a6b4a: c0e58ae7brasl   
>  %r14,3ff80698118
> 03ff806a6b50: e310a044lg  %r1,64(%r10)
> 03ff806a6b56: e310f0a00024stg 
>  %r1,160(%r15)
>  [ ] Call Trace:
>  [ ] ([<03ff806a6aa2>] zfcp_fc_exec_bsg_job+0x122/0x440 [zfcp])
>  [ ]  [<03ff8061e928>] fc_bsg_dispatch+0x310/0x398 [scsi_transport_fc]
>  [ ]  [<00d2995a>] bsg_queue_rq+0x15a/0x198
>  [ ]  [<00d03566>] blk_mq_dispatch_rq_list+0x966/0xf90
>  [ ]  [<00d0e37a>] blk_mq_sched_dispatch_requests+0x3fa/0x410
>  [ ]  [<00cfc230>] __blk_mq_run_hw_queue+0x218/0x248
>  [ ]  [<001cb124>] process_one_work+0x8c4/0xe90
>  [ ]  [<001cbe58>] worker_thread+0x768/0xbb0
>  [ ]  [<001dc67a>] kthread+0x22a/0x248
>  [ ]  [<0137b812>] kernel_thread_starter+0x6/0xc
>  [ ]  [<0137b80c>] kernel_thread_starter+0x0/0xc
>  [ ] INFO: lockdep is turned off.
>  [ ] Last Breaking-Event-Address:
>  [ ]  [<005d9b08>] __asan_store8+0x98/0xa0
>  [ ]
>  [ ] Kernel panic - not syncing: Fatal exception: panic_on_oops
> 
>  zfcp_fc_exec_bsg_job+0x1c0 is here:
> 
>  int zfcp_fc_exec_bsg_job(struct bsg_job *job)
>  {
>  struct Scsi_Host *shost;
>  struct zfcp_adapter *adapter;
>  struct zfcp_fsf_ct_els *ct_els = job->dd_data;
>  struct fc_bsg_request *bsg_request = job->request;
>  struct fc_rport *rport = fc_bsg_to_rport(job);
> 
>  shost = rport ? rport_to_shost(rport) : fc_bsg_to_shost(job);
>  adapter = (struct zfcp_adapter *)shost->hostdata[0];
> 
>  if (!(atomic_read(>status) & 
>  ZFCP_STATUS_COMMON_OPEN))
>  return -EINVAL;
> 
>  ==> ct_els->req = job->request_payload.sg_list;
>  ct_els->resp = job->reply_payload.sg_list;
>  ct_els->handler_data = job;
> 
>  switch (bsg_request->msgcode) {
>  case FC_BSG_RPT_ELS:
>  case FC_BSG_HST_ELS_NOLOGIN:
>  return zfcp_fc_exec_els_job(job, adapter);
>  case FC_BSG_RPT_CT:
>  case FC_BSG_HST_CT:
>  return zfcp_fc_exec_ct_job(job, adapter);
>  default:
>  return -EINVAL;
>  }
>  }
> 
>  I took a dump to find out how struct bsg_job looks like when it crashes
>  

Re: [PATCH v3 8/8] sg: user controls for q_at_head, read_value

2018-10-26 Thread Douglas Gilbert

On 2018-10-26 12:48 p.m., Douglas Gilbert wrote:

Add a SG_SET_GET_EXTENDED ioctl control for whether commands
will be queued_at_head or queued_at_tail by the block layer
(together with the scsi mid-level). It has file scope.

Also add a read_value integer the can be used by write a
value from the SG_SEIRV_* group then the corresponding value
will be returned.

Signed-off-by: Douglas Gilbert 
---


See "v3.5" of this patch to fix the compile error when
CONFIG_SCSI_PROC_FS is not defined in a kernel build.

Doug Gilbert



Re: [PATCH 5/5] qla2xxx: use lower_32_bits and upper_32_bits instead of reinventing them

2018-10-26 Thread Christoph Hellwig
On Thu, Oct 18, 2018 at 09:43:25PM -0700, Bart Van Assche wrote:
> Hi Christoph,
>
> Have you considered to use put_unaligned_le64() instead of storing the 
> lower and upper 32 bits separately?

I really don't want to touch this old driver all that much, just
get rid of the buggy existing helpers.