Message ID | 20220913195716.3966875-5-bvanassche@acm.org |
---|---|
State | New |
Headers | show |
Series | Prepare for constifying SCSI host templates | expand |
On 13/09/2022 20:57, Bart Van Assche wrote: > Instead of clearing the host template module pointer if the LLD kernel > module is being unloaded, set the 'drop_module_ref' SCSI device member. > This patch prepares for constifying the SCSI host template. > > Cc: Christoph Hellwig <hch@lst.de> > Cc: Ming Lei <ming.lei@redhat.com> > Cc: Hannes Reinecke <hare@suse.de> > Cc: John Garry <john.garry@huawei.com> > Cc: Mike Christie <michael.christie@oracle.com> > Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> > Signed-off-by: Bart Van Assche <bvanassche@acm.org> > --- > drivers/scsi/scsi_sysfs.c | 7 +++---- > include/scsi/scsi_device.h | 1 + > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c > index 5d61f58399dc..822ae60a64b9 100644 > --- a/drivers/scsi/scsi_sysfs.c > +++ b/drivers/scsi/scsi_sysfs.c > @@ -454,7 +454,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) > > sdev = container_of(work, struct scsi_device, ew.work); > > - mod = sdev->host->hostt->module; > + mod = sdev->drop_module_ref ? sdev->host->hostt->module : NULL; I suppose that this works. My reservation is that there were some concerns of current module referencing solution, so may not be better to build directly on it: https://lore.kernel.org/linux-scsi/Ynt0aFMX+z%2FUhGJ2@infradead.org/ Thanks, John > > scsi_dh_release_device(sdev); > > @@ -525,9 +525,8 @@ static void scsi_device_dev_release(struct device *dev) > { > struct scsi_device *sdp = to_scsi_device(dev); > > - /* Set module pointer as NULL in case of module unloading */ > - if (!try_module_get(sdp->host->hostt->module)) > - sdp->host->hostt->module = NULL; > + if (try_module_get(sdp->host->hostt->module)) > + sdp->drop_module_ref = true; > > execute_in_process_context(scsi_device_dev_release_usercontext, > &sdp->ew); > diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h > index 2493bd65351a..b03176b69056 100644 > --- a/include/scsi/scsi_device.h > +++ b/include/scsi/scsi_device.h > @@ -214,6 +214,7 @@ struct scsi_device { > * creation time */ > unsigned ignore_media_change:1; /* Ignore MEDIA CHANGE on resume */ > unsigned silence_suspend:1; /* Do not print runtime PM related messages */ > + unsigned drop_module_ref:1; > > unsigned int queue_stopped; /* request queue is quiesced */ > bool offline_already; /* Device offline message logged */ > > .
On 9/14/22 02:52, John Garry wrote: > On 13/09/2022 20:57, Bart Van Assche wrote: >> - mod = sdev->host->hostt->module; >> + mod = sdev->drop_module_ref ? sdev->host->hostt->module : NULL; > > I suppose that this works. > > My reservation is that there were some concerns of current module > referencing solution, so may not be better to build directly on it: > > https://lore.kernel.org/linux-scsi/Ynt0aFMX+z%2FUhGJ2@infradead.org/ Hi John, The above link points at a reply from Christoph Hellwig with the suggestion to use __module_get(). Implementing that suggestion would require to modify the kernel module implementation. My conclusion from reading the code in kernel/module/main.c is that increasing the module reference count after unloading has started currently has no effect. I have not found any code in the delete_module() system call implementation that waits for the reference count to drop to zero after try_stop_module() succeeded. I will look into this. Thanks, Bart.
diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c index 5d61f58399dc..822ae60a64b9 100644 --- a/drivers/scsi/scsi_sysfs.c +++ b/drivers/scsi/scsi_sysfs.c @@ -454,7 +454,7 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work) sdev = container_of(work, struct scsi_device, ew.work); - mod = sdev->host->hostt->module; + mod = sdev->drop_module_ref ? sdev->host->hostt->module : NULL; scsi_dh_release_device(sdev); @@ -525,9 +525,8 @@ static void scsi_device_dev_release(struct device *dev) { struct scsi_device *sdp = to_scsi_device(dev); - /* Set module pointer as NULL in case of module unloading */ - if (!try_module_get(sdp->host->hostt->module)) - sdp->host->hostt->module = NULL; + if (try_module_get(sdp->host->hostt->module)) + sdp->drop_module_ref = true; execute_in_process_context(scsi_device_dev_release_usercontext, &sdp->ew); diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 2493bd65351a..b03176b69056 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -214,6 +214,7 @@ struct scsi_device { * creation time */ unsigned ignore_media_change:1; /* Ignore MEDIA CHANGE on resume */ unsigned silence_suspend:1; /* Do not print runtime PM related messages */ + unsigned drop_module_ref:1; unsigned int queue_stopped; /* request queue is quiesced */ bool offline_already; /* Device offline message logged */
Instead of clearing the host template module pointer if the LLD kernel module is being unloaded, set the 'drop_module_ref' SCSI device member. This patch prepares for constifying the SCSI host template. Cc: Christoph Hellwig <hch@lst.de> Cc: Ming Lei <ming.lei@redhat.com> Cc: Hannes Reinecke <hare@suse.de> Cc: John Garry <john.garry@huawei.com> Cc: Mike Christie <michael.christie@oracle.com> Cc: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> Signed-off-by: Bart Van Assche <bvanassche@acm.org> --- drivers/scsi/scsi_sysfs.c | 7 +++---- include/scsi/scsi_device.h | 1 + 2 files changed, 4 insertions(+), 4 deletions(-)