2015-08-14 02:47:43 +00:00
|
|
|
/*
|
|
|
|
* CXL Flash Device Driver
|
|
|
|
*
|
|
|
|
* Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
|
|
|
|
* Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 IBM Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version
|
|
|
|
* 2 of the License, or (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
|
2018-05-11 19:06:19 +00:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
|
2015-08-14 02:47:43 +00:00
|
|
|
#include <scsi/scsi_host.h>
|
|
|
|
#include <uapi/scsi/cxlflash_ioctl.h>
|
|
|
|
|
|
|
|
#include "sislite.h"
|
|
|
|
#include "common.h"
|
2015-08-14 02:47:53 +00:00
|
|
|
#include "vlun.h"
|
2015-08-14 02:47:43 +00:00
|
|
|
#include "superpipe.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create_local() - allocate and initialize a local LUN information structure
|
|
|
|
* @sdev: SCSI device associated with LUN.
|
|
|
|
* @wwid: World Wide Node Name for LUN.
|
|
|
|
*
|
|
|
|
* Return: Allocated local llun_info structure on success, NULL on failure
|
|
|
|
*/
|
|
|
|
static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)
|
|
|
|
{
|
2017-01-12 01:19:47 +00:00
|
|
|
struct cxlflash_cfg *cfg = shost_priv(sdev->host);
|
|
|
|
struct device *dev = &cfg->dev->dev;
|
2015-08-14 02:47:43 +00:00
|
|
|
struct llun_info *lli = NULL;
|
|
|
|
|
|
|
|
lli = kzalloc(sizeof(*lli), GFP_KERNEL);
|
|
|
|
if (unlikely(!lli)) {
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_err(dev, "%s: could not allocate lli\n", __func__);
|
2015-08-14 02:47:43 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
lli->sdev = sdev;
|
|
|
|
lli->host_no = sdev->host->host_no;
|
2015-08-14 02:47:53 +00:00
|
|
|
lli->in_table = false;
|
2015-08-14 02:47:43 +00:00
|
|
|
|
|
|
|
memcpy(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
|
|
|
|
out:
|
|
|
|
return lli;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* create_global() - allocate and initialize a global LUN information structure
|
|
|
|
* @sdev: SCSI device associated with LUN.
|
|
|
|
* @wwid: World Wide Node Name for LUN.
|
|
|
|
*
|
|
|
|
* Return: Allocated global glun_info structure on success, NULL on failure
|
|
|
|
*/
|
|
|
|
static struct glun_info *create_global(struct scsi_device *sdev, u8 *wwid)
|
|
|
|
{
|
2017-01-12 01:19:47 +00:00
|
|
|
struct cxlflash_cfg *cfg = shost_priv(sdev->host);
|
|
|
|
struct device *dev = &cfg->dev->dev;
|
2015-08-14 02:47:43 +00:00
|
|
|
struct glun_info *gli = NULL;
|
|
|
|
|
|
|
|
gli = kzalloc(sizeof(*gli), GFP_KERNEL);
|
|
|
|
if (unlikely(!gli)) {
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_err(dev, "%s: could not allocate gli\n", __func__);
|
2015-08-14 02:47:43 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_init(&gli->mutex);
|
|
|
|
memcpy(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
|
|
|
|
out:
|
|
|
|
return gli;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
* lookup_local() - find a local LUN information structure by WWID
|
2015-08-14 02:47:43 +00:00
|
|
|
* @cfg: Internal structure associated with the host.
|
|
|
|
* @wwid: WWID associated with LUN.
|
|
|
|
*
|
|
|
|
* Return: Found local lun_info structure on success, NULL on failure
|
|
|
|
*/
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
static struct llun_info *lookup_local(struct cxlflash_cfg *cfg, u8 *wwid)
|
2015-08-14 02:47:43 +00:00
|
|
|
{
|
|
|
|
struct llun_info *lli, *temp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(lli, temp, &cfg->lluns, list)
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
if (!memcmp(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN))
|
2015-08-14 02:47:43 +00:00
|
|
|
return lli;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* lookup_global() - find a global LUN information structure by WWID
|
|
|
|
* @wwid: WWID associated with LUN.
|
|
|
|
*
|
|
|
|
* Return: Found global lun_info structure on success, NULL on failure
|
|
|
|
*/
|
|
|
|
static struct glun_info *lookup_global(u8 *wwid)
|
|
|
|
{
|
|
|
|
struct glun_info *gli, *temp;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(gli, temp, &global.gluns, list)
|
|
|
|
if (!memcmp(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN))
|
|
|
|
return gli;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* find_and_create_lun() - find or create a local LUN information structure
|
|
|
|
* @sdev: SCSI device associated with LUN.
|
|
|
|
* @wwid: WWID associated with LUN.
|
|
|
|
*
|
|
|
|
* The LUN is kept both in a local list (per adapter) and in a global list
|
|
|
|
* (across all adapters). Certain attributes of the LUN are local to the
|
2015-10-21 20:10:31 +00:00
|
|
|
* adapter (such as index, port selection mask, etc.).
|
|
|
|
*
|
2015-08-14 02:47:43 +00:00
|
|
|
* The block allocation map is shared across all adapters (i.e. associated
|
|
|
|
* wih the global list). Since different attributes are associated with
|
|
|
|
* the per adapter and global entries, allocate two separate structures for each
|
|
|
|
* LUN (one local, one global).
|
|
|
|
*
|
|
|
|
* Keep a pointer back from the local to the global entry.
|
|
|
|
*
|
2015-10-21 20:10:31 +00:00
|
|
|
* This routine assumes the caller holds the global mutex.
|
|
|
|
*
|
2015-08-14 02:47:43 +00:00
|
|
|
* Return: Found/Allocated local lun_info structure on success, NULL on failure
|
|
|
|
*/
|
|
|
|
static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid)
|
|
|
|
{
|
2017-01-12 01:19:47 +00:00
|
|
|
struct cxlflash_cfg *cfg = shost_priv(sdev->host);
|
|
|
|
struct device *dev = &cfg->dev->dev;
|
2015-08-14 02:47:43 +00:00
|
|
|
struct llun_info *lli = NULL;
|
|
|
|
struct glun_info *gli = NULL;
|
|
|
|
|
|
|
|
if (unlikely(!wwid))
|
|
|
|
goto out;
|
|
|
|
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
lli = lookup_local(cfg, wwid);
|
2015-08-14 02:47:43 +00:00
|
|
|
if (lli)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
lli = create_local(sdev, wwid);
|
|
|
|
if (unlikely(!lli))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
gli = lookup_global(wwid);
|
|
|
|
if (gli) {
|
|
|
|
lli->parent = gli;
|
|
|
|
list_add(&lli->list, &cfg->lluns);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
gli = create_global(sdev, wwid);
|
|
|
|
if (unlikely(!gli)) {
|
|
|
|
kfree(lli);
|
|
|
|
lli = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
lli->parent = gli;
|
|
|
|
list_add(&lli->list, &cfg->lluns);
|
|
|
|
|
|
|
|
list_add(&gli->list, &global.gluns);
|
|
|
|
|
|
|
|
out:
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_dbg(dev, "%s: returning lli=%p, gli=%p\n", __func__, lli, gli);
|
2015-08-14 02:47:43 +00:00
|
|
|
return lli;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxlflash_term_local_luns() - Delete all entries from local LUN list, free.
|
|
|
|
* @cfg: Internal structure associated with the host.
|
|
|
|
*/
|
|
|
|
void cxlflash_term_local_luns(struct cxlflash_cfg *cfg)
|
|
|
|
{
|
|
|
|
struct llun_info *lli, *temp;
|
|
|
|
|
|
|
|
mutex_lock(&global.mutex);
|
|
|
|
list_for_each_entry_safe(lli, temp, &cfg->lluns, list) {
|
|
|
|
list_del(&lli->list);
|
|
|
|
kfree(lli);
|
|
|
|
}
|
|
|
|
mutex_unlock(&global.mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxlflash_list_init() - initializes the global LUN list
|
|
|
|
*/
|
|
|
|
void cxlflash_list_init(void)
|
|
|
|
{
|
|
|
|
INIT_LIST_HEAD(&global.gluns);
|
|
|
|
mutex_init(&global.mutex);
|
|
|
|
global.err_page = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxlflash_term_global_luns() - frees resources associated with global LUN list
|
|
|
|
*/
|
|
|
|
void cxlflash_term_global_luns(void)
|
|
|
|
{
|
|
|
|
struct glun_info *gli, *temp;
|
|
|
|
|
|
|
|
mutex_lock(&global.mutex);
|
|
|
|
list_for_each_entry_safe(gli, temp, &global.gluns, list) {
|
|
|
|
list_del(&gli->list);
|
2015-08-14 02:47:53 +00:00
|
|
|
cxlflash_ba_terminate(&gli->blka.ba_lun);
|
2015-08-14 02:47:43 +00:00
|
|
|
kfree(gli);
|
|
|
|
}
|
|
|
|
mutex_unlock(&global.mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxlflash_manage_lun() - handles LUN management activities
|
|
|
|
* @sdev: SCSI device associated with LUN.
|
|
|
|
* @manage: Manage ioctl data structure.
|
|
|
|
*
|
|
|
|
* This routine is used to notify the driver about a LUN's WWID and associate
|
|
|
|
* SCSI devices (sdev) with a global LUN instance. Additionally it serves to
|
|
|
|
* change a LUN's operating mode: legacy or superpipe.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, -errno on failure
|
|
|
|
*/
|
|
|
|
int cxlflash_manage_lun(struct scsi_device *sdev,
|
|
|
|
struct dk_cxlflash_manage_lun *manage)
|
|
|
|
{
|
2017-01-12 01:19:47 +00:00
|
|
|
struct cxlflash_cfg *cfg = shost_priv(sdev->host);
|
|
|
|
struct device *dev = &cfg->dev->dev;
|
2015-08-14 02:47:43 +00:00
|
|
|
struct llun_info *lli = NULL;
|
2017-01-12 01:19:47 +00:00
|
|
|
int rc = 0;
|
2015-08-14 02:47:43 +00:00
|
|
|
u64 flags = manage->hdr.flags;
|
|
|
|
u32 chan = sdev->channel;
|
|
|
|
|
2015-10-21 20:10:31 +00:00
|
|
|
mutex_lock(&global.mutex);
|
2015-08-14 02:47:43 +00:00
|
|
|
lli = find_and_create_lun(sdev, manage->wwid);
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_dbg(dev, "%s: WWID=%016llx%016llx, flags=%016llx lli=%p\n",
|
|
|
|
__func__, get_unaligned_be64(&manage->wwid[0]),
|
|
|
|
get_unaligned_be64(&manage->wwid[8]), manage->hdr.flags, lli);
|
2015-08-14 02:47:43 +00:00
|
|
|
if (unlikely(!lli)) {
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE) {
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
/*
|
|
|
|
* Update port selection mask based upon channel, store off LUN
|
|
|
|
* in unpacked, AFU-friendly format, and hang LUN reference in
|
|
|
|
* the sdev.
|
|
|
|
*/
|
2017-04-12 19:14:05 +00:00
|
|
|
lli->port_sel |= CHAN2PORTMASK(chan);
|
2015-08-14 02:47:43 +00:00
|
|
|
lli->lun_id[chan] = lun_to_lunid(sdev->lun);
|
|
|
|
sdev->hostdata = lli;
|
|
|
|
} else if (flags & DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE) {
|
|
|
|
if (lli->parent->mode != MODE_NONE)
|
|
|
|
rc = -EBUSY;
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
else {
|
2016-11-29 00:41:19 +00:00
|
|
|
/*
|
|
|
|
* Clean up local LUN for this port and reset table
|
|
|
|
* tracking when no more references exist.
|
|
|
|
*/
|
2015-08-14 02:47:43 +00:00
|
|
|
sdev->hostdata = NULL;
|
2017-04-12 19:14:05 +00:00
|
|
|
lli->port_sel &= ~CHAN2PORTMASK(chan);
|
2016-11-29 00:41:19 +00:00
|
|
|
if (lli->port_sel == 0U)
|
|
|
|
lli->in_table = false;
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
}
|
2015-08-14 02:47:43 +00:00
|
|
|
}
|
|
|
|
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_dbg(dev, "%s: port_sel=%08x chan=%u lun_id=%016llx\n",
|
|
|
|
__func__, lli->port_sel, chan, lli->lun_id[chan]);
|
cxlflash: Fix to avoid corrupting port selection mask
The port selection mask of a LUN can be corrupted when the manage LUN
ioctl (DK_CXLFLASH_MANAGE_LUN) is issued more than once for any device.
This mask indicates to the AFU which port[s] can be used for a data
transfer to/from a particular LUN. The mask is critical to ensuring the
correct behavior when using the virtual LUN function of this adapter.
When the mask is configured for both ports, an I/O may be sent to either
port as the AFU assumes that each port has access to the same physical
device (specified by LUN ID in the port LUN table).
In a situation where the mask becomes incorrectly configured to reflect
access to both ports when in fact there is only access through a single
port, an I/O can be targeted to the wrong physical device. This can lead
to data corruption among other ill effects (e.g. security leaks).
The cause for this corruption is the assumption that the ioctl will only
be called a second time for a LUN when it is being configured for access
via a second port. A boolean 'newly_created' variable is used to
differentiate between a LUN that was created (and subsequently configured
for single port access) and one that is destined for access across both
ports. While initially set to 'true', this sticky boolean is toggled to
the 'false' state during a lookup on any next ioctl performed on a device
with a matching WWN/WWID. The code fails to realize that the match could
in fact be the same device calling in again. From here, an assumption is
made that any LUN with 'newly_created' set to 'false' is configured for
access over both ports and the port selection mask is set to reflect this.
Any future attempts to use this LUN for hosting a virtual LUN will result
in the port LUN table being incorrectly programmed.
As a remedy, the 'newly_created' concept was removed entirely and replaced
with code that always constructs the port selection mask based upon the
SCSI channel of the LUN being accessed. The bits remain sticky, therefore
allowing for a device to be accessed over both ports when that is in fact
the correct physical configuration.
Also included in this commit are a few minor related changes to enhance
the fix and provide better debug information for port selection mask and
port LUN table bugs in the future. These include renaming refresh_local()
to lookup_local(), tracing the WWN/WWID as a big-endian entity, and
tracing the port selection mask, SCSI channel, and LUN ID each time the
port LUN table is programmed.
Signed-off-by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>
Acked-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: James Bottomley <JBottomley@Odin.com>
2015-10-21 20:16:15 +00:00
|
|
|
|
2015-08-14 02:47:43 +00:00
|
|
|
out:
|
2015-10-21 20:10:31 +00:00
|
|
|
mutex_unlock(&global.mutex);
|
2017-01-12 01:19:47 +00:00
|
|
|
dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
|
2015-08-14 02:47:43 +00:00
|
|
|
return rc;
|
|
|
|
}
|