public inbox for target-devel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support
@ 2025-10-10 14:15 John Garry
  2025-10-10 14:15 ` [PATCH v2 1/7] scsi: target: Rename target_configure_unmap_from_queue John Garry
                   ` (6 more replies)
  0 siblings, 7 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

This is a reposting of Mike's atomic writes support for the SCSI target.

Again, we are now only supporting target_core_iblock. It's implemented
similar to UNMAP where we do not do any emulation and instead pass the
operation to the block layer.

Changes since v1:
- Don't make atomic alignment configurable
- Drop atomic_supported configfs entry
- reformatting
- fix lba size in sbc_check_atomic()
- fix return code from sbc_check_atomic()

Mike Christie (7):
  scsi: target: Rename target_configure_unmap_from_queue
  scsi: target: Add atomic se_device fields
  scsi: target: Add helper to setup atomic values from block_device
  scsi: target: Add WRITE_ATOMIC_16 handler
  scsi: target: Report atomic values in INQUIRY
  scsi: target: Add WRITE_ATOMIC_16 support to RSOC
  scsi: target: Add atomic support to target_core_iblock

 drivers/target/target_core_configfs.c | 15 ++++++++
 drivers/target/target_core_device.c   | 23 +++++++++++--
 drivers/target/target_core_file.c     |  4 +--
 drivers/target/target_core_iblock.c   |  9 +++--
 drivers/target/target_core_sbc.c      | 49 +++++++++++++++++++++++++++
 drivers/target/target_core_spc.c      | 49 +++++++++++++++++++++++----
 include/target/target_core_backend.h  |  6 ++--
 include/target/target_core_base.h     |  6 ++++
 8 files changed, 146 insertions(+), 15 deletions(-)

-- 
2.43.5


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/7] scsi: target: Rename target_configure_unmap_from_queue
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-10 14:15 ` [PATCH v2 2/7] scsi: target: Add atomic se_device fields John Garry
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

Rename target_configure_unmap_from_queue to
target_configure_unmap_from_bdev since it now takes a bdev.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_device.c  | 6 +++---
 drivers/target/target_core_file.c    | 4 ++--
 drivers/target/target_core_iblock.c  | 4 ++--
 include/target/target_core_backend.h | 4 ++--
 4 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 7bb711b24c0d7..83fe3d9a9681c 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -844,8 +844,8 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
  * Check if the underlying struct block_device supports discard and if yes
  * configure the UNMAP parameters.
  */
-bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
-				       struct block_device *bdev)
+bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib,
+				      struct block_device *bdev)
 {
 	int block_size = bdev_logical_block_size(bdev);
 
@@ -863,7 +863,7 @@ bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
 		bdev_discard_alignment(bdev) / block_size;
 	return true;
 }
-EXPORT_SYMBOL(target_configure_unmap_from_queue);
+EXPORT_SYMBOL(target_configure_unmap_from_bdev);
 
 /*
  * Convert from blocksize advertised to the initiator to the 512 byte
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 2d78ef74633c8..b2610073e8cca 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -92,8 +92,8 @@ static bool fd_configure_unmap(struct se_device *dev)
 	struct inode *inode = file->f_mapping->host;
 
 	if (S_ISBLK(inode->i_mode))
-		return target_configure_unmap_from_queue(&dev->dev_attrib,
-							 I_BDEV(inode));
+		return target_configure_unmap_from_bdev(&dev->dev_attrib,
+							I_BDEV(inode));
 
 	/* Limit UNMAP emulation to 8k Number of LBAs (NoLB) */
 	dev->dev_attrib.max_unmap_lba_count = 0x2000;
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 66c292b7d74bc..281612b9830f8 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -84,8 +84,8 @@ static bool iblock_configure_unmap(struct se_device *dev)
 {
 	struct iblock_dev *ib_dev = IBLOCK_DEV(dev);
 
-	return target_configure_unmap_from_queue(&dev->dev_attrib,
-						 ib_dev->ibd_bd);
+	return target_configure_unmap_from_bdev(&dev->dev_attrib,
+						ib_dev->ibd_bd);
 }
 
 static int iblock_configure_device(struct se_device *dev)
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index 4063a701081b4..d394306f8f490 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -121,8 +121,8 @@ sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd,
 
 bool target_sense_desc_format(struct se_device *dev);
 sector_t target_to_linux_sector(struct se_device *dev, sector_t lb);
-bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
-				       struct block_device *bdev);
+bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib,
+				      struct block_device *bdev);
 
 static inline bool target_dev_configured(struct se_device *se_dev)
 {
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/7] scsi: target: Add atomic se_device fields
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
  2025-10-10 14:15 ` [PATCH v2 1/7] scsi: target: Rename target_configure_unmap_from_queue John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-10 14:15 ` [PATCH v2 3/7] scsi: target: Add helper to setup atomic values from block_device John Garry
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This adds atomic fields to the se_device and exports them in configfs.

Initially only target_core_iblock will be supported and we will inherit
all the settings from the block layer.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
jpg: Stop being allowed to configure atomic write alignment,
     remove atomic_supported member
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_configfs.c | 15 +++++++++++++++
 include/target/target_core_base.h     |  5 +++++
 2 files changed, 20 insertions(+)

diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 0904ecae253a8..31d1b28933e96 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -578,6 +578,11 @@ DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data);
 DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len);
 DEF_CONFIGFS_ATTRIB_SHOW(emulate_rsoc);
 DEF_CONFIGFS_ATTRIB_SHOW(submit_type);
+DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_len);
+DEF_CONFIGFS_ATTRIB_SHOW(atomic_alignment);
+DEF_CONFIGFS_ATTRIB_SHOW(atomic_granularity);
+DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_with_boundary);
+DEF_CONFIGFS_ATTRIB_SHOW(atomic_max_boundary);
 
 #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name)				\
 static ssize_t _name##_store(struct config_item *item, const char *page,\
@@ -1300,6 +1305,11 @@ CONFIGFS_ATTR(, max_write_same_len);
 CONFIGFS_ATTR(, alua_support);
 CONFIGFS_ATTR(, pgr_support);
 CONFIGFS_ATTR(, submit_type);
+CONFIGFS_ATTR_RO(, atomic_max_len);
+CONFIGFS_ATTR_RO(, atomic_alignment);
+CONFIGFS_ATTR_RO(, atomic_granularity);
+CONFIGFS_ATTR_RO(, atomic_max_with_boundary);
+CONFIGFS_ATTR_RO(, atomic_max_boundary);
 
 /*
  * dev_attrib attributes for devices using the target core SBC/SPC
@@ -1343,6 +1353,11 @@ struct configfs_attribute *sbc_attrib_attrs[] = {
 	&attr_pgr_support,
 	&attr_emulate_rsoc,
 	&attr_submit_type,
+	&attr_atomic_alignment,
+	&attr_atomic_max_len,
+	&attr_atomic_granularity,
+	&attr_atomic_max_with_boundary,
+	&attr_atomic_max_boundary,
 	NULL,
 };
 EXPORT_SYMBOL(sbc_attrib_attrs);
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index c4d9116904aa0..70ece58d30780 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -731,6 +731,11 @@ struct se_dev_attrib {
 	u32		unmap_granularity;
 	u32		unmap_granularity_alignment;
 	u32		max_write_same_len;
+	u32		atomic_max_len;
+	u32		atomic_alignment;
+	u32		atomic_granularity;
+	u32		atomic_max_with_boundary;
+	u32		atomic_max_boundary;
 	u8		submit_type;
 	struct se_device *da_dev;
 	struct config_group da_group;
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/7] scsi: target: Add helper to setup atomic values from block_device
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
  2025-10-10 14:15 ` [PATCH v2 1/7] scsi: target: Rename target_configure_unmap_from_queue John Garry
  2025-10-10 14:15 ` [PATCH v2 2/7] scsi: target: Add atomic se_device fields John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-10 14:15 ` [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler John Garry
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This adds a helper function that sets up the atomic value based on a
block_device similar to what we do for unmap.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
jpg: Set atomic alignment, drop atomic_supported reference
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_device.c  | 17 +++++++++++++++++
 include/target/target_core_backend.h |  2 ++
 2 files changed, 19 insertions(+)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 83fe3d9a9681c..39a2d9c3eb9e1 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -840,6 +840,23 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
 	return NULL;
 }
 
+void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib,
+					     struct block_device *bdev)
+{
+	struct request_queue *q = bdev_get_queue(bdev);
+	int block_size = bdev_logical_block_size(bdev);
+
+	if (!bdev_can_atomic_write(bdev))
+		return;
+
+	attrib->atomic_max_len = queue_atomic_write_max_bytes(q) / block_size;
+	attrib->atomic_granularity = attrib->atomic_alignment =
+		queue_atomic_write_unit_min_bytes(q) / block_size;
+	attrib->atomic_max_with_boundary = 0;
+	attrib->atomic_max_boundary = 0;
+}
+EXPORT_SYMBOL_GPL(target_configure_write_atomic_from_bdev);
+
 /*
  * Check if the underlying struct block_device supports discard and if yes
  * configure the UNMAP parameters.
diff --git a/include/target/target_core_backend.h b/include/target/target_core_backend.h
index d394306f8f490..e32de80854b6a 100644
--- a/include/target/target_core_backend.h
+++ b/include/target/target_core_backend.h
@@ -123,6 +123,8 @@ bool target_sense_desc_format(struct se_device *dev);
 sector_t target_to_linux_sector(struct se_device *dev, sector_t lb);
 bool target_configure_unmap_from_bdev(struct se_dev_attrib *attrib,
 				      struct block_device *bdev);
+void target_configure_write_atomic_from_bdev(struct se_dev_attrib *attrib,
+					     struct block_device *bdev);
 
 static inline bool target_dev_configured(struct se_device *se_dev)
 {
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
                   ` (2 preceding siblings ...)
  2025-10-10 14:15 ` [PATCH v2 3/7] scsi: target: Add helper to setup atomic values from block_device John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-12  1:38   ` kernel test robot
  2025-10-10 14:15 ` [PATCH v2 5/7] scsi: target: Report atomic values in INQUIRY John Garry
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This adds the core LIO code to process the WRITE_ATOMIC_16 command.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
jpg: fix return code from sbc_check_atomic, reformat
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_sbc.c  | 49 +++++++++++++++++++++++++++++++
 include/target/target_core_base.h |  1 +
 2 files changed, 50 insertions(+)

diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c
index fe8beb7dbab12..2878cbc3e79df 100644
--- a/drivers/target/target_core_sbc.c
+++ b/drivers/target/target_core_sbc.c
@@ -764,6 +764,47 @@ sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)
 	return 0;
 }
 
+static sense_reason_t
+sbc_check_atomic(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb)
+{
+	struct se_dev_attrib *attrib = &dev->dev_attrib;
+	u16 boundary, transfer_len;
+	u64 lba;
+
+	lba = transport_lba_64(cdb);
+	boundary = get_unaligned_be16(&cdb[10]);
+	transfer_len = get_unaligned_be16(&cdb[12]);
+
+	if (!attrib->atomic_max_len)
+		return TCM_UNSUPPORTED_SCSI_OPCODE;
+
+	if (boundary) {
+		if (transfer_len > attrib->atomic_max_with_boundary)
+			return TCM_INVALID_CDB_FIELD;
+
+		if (boundary > attrib->atomic_max_boundary)
+			return TCM_INVALID_CDB_FIELD;
+	} else {
+		if (transfer_len > attrib->atomic_max_len)
+			return TCM_INVALID_CDB_FIELD;
+	}
+
+	if (attrib->atomic_granularity) {
+		if (transfer_len % attrib->atomic_granularity)
+			return TCM_INVALID_CDB_FIELD;
+
+		if (boundary && boundary % attrib->atomic_granularity)
+			return TCM_INVALID_CDB_FIELD;
+	}
+
+	if (dev->dev_attrib.atomic_alignment) {
+		if (lba % dev->dev_attrib.atomic_alignment)
+			return TCM_INVALID_CDB_FIELD;
+	}
+
+	return 0;
+}
+
 sense_reason_t
 sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
 {
@@ -861,6 +902,7 @@ sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
 		break;
 	case WRITE_16:
 	case WRITE_VERIFY_16:
+	case WRITE_ATOMIC_16:
 		sectors = transport_get_sectors_16(cdb);
 		cmd->t_task_lba = transport_lba_64(cdb);
 
@@ -872,6 +914,13 @@ sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops)
 			return ret;
 
 		cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
+		if (cdb[0] == WRITE_ATOMIC_16) {
+			cmd->se_cmd_flags |= SCF_ATOMIC;
+
+			ret = sbc_check_atomic(dev, cmd, cdb);
+			if (ret)
+				return ret;
+		}
 		cmd->execute_cmd = sbc_execute_rw;
 		break;
 	case VARIABLE_LENGTH_CMD:
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 70ece58d30780..56333b5726c8b 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -158,6 +158,7 @@ enum se_cmd_flags_table {
 	SCF_TASK_ATTR_SET			= (1 << 17),
 	SCF_TREAT_READ_AS_NORMAL		= (1 << 18),
 	SCF_TASK_ORDERED_SYNC			= (1 << 19),
+	SCF_ATOMIC				= (1 << 20),
 };
 
 /*
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/7] scsi: target: Report atomic values in INQUIRY
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
                   ` (3 preceding siblings ...)
  2025-10-10 14:15 ` [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-10 14:15 ` [PATCH v2 6/7] scsi: target: Add WRITE_ATOMIC_16 support to RSOC John Garry
  2025-10-10 14:15 ` [PATCH v2 7/7] scsi: target: Add atomic support to target_core_iblock John Garry
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This reports the atomic values in the Block Limits VPD page.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
jpg: handle not having atomic_supported attribute
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_spc.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index aad0096afa21c..ddf8104645d1e 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -521,7 +521,6 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
 		have_tp = 1;
 
 	buf[0] = dev->transport->get_device_type(dev);
-	buf[3] = have_tp ? 0x3c : 0x10;
 
 	/* Set WSNZ to 1 */
 	buf[4] = 0x01;
@@ -562,11 +561,10 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
 	else
 		put_unaligned_be32(dev->dev_attrib.optimal_sectors, &buf[12]);
 
-	/*
-	 * Exit now if we don't support TP.
-	 */
+	put_unaligned_be16(12, &buf[2]);
+
 	if (!have_tp)
-		goto max_write_same;
+		goto try_atomic;
 
 	/*
 	 * Set MAXIMUM UNMAP LBA COUNT
@@ -595,9 +593,29 @@ spc_emulate_evpd_b0(struct se_cmd *cmd, unsigned char *buf)
 	/*
 	 * MAXIMUM WRITE SAME LENGTH
 	 */
-max_write_same:
 	put_unaligned_be64(dev->dev_attrib.max_write_same_len, &buf[36]);
 
+	put_unaligned_be16(40, &buf[2]);
+
+try_atomic:
+	/*
+	 * ATOMIC
+	 */
+	if (!dev->dev_attrib.atomic_max_len)
+		goto done;
+
+	if (dev->dev_attrib.atomic_max_len < io_max_blocks)
+		put_unaligned_be32(dev->dev_attrib.atomic_max_len, &buf[44]);
+	else
+		put_unaligned_be32(io_max_blocks, &buf[44]);
+
+	put_unaligned_be32(dev->dev_attrib.atomic_alignment, &buf[48]);
+	put_unaligned_be32(dev->dev_attrib.atomic_granularity, &buf[52]);
+	put_unaligned_be32(dev->dev_attrib.atomic_max_with_boundary, &buf[56]);
+	put_unaligned_be32(dev->dev_attrib.atomic_max_boundary, &buf[60]);
+
+	put_unaligned_be16(60, &buf[2]);
+done:
 	return 0;
 }
 
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/7] scsi: target: Add WRITE_ATOMIC_16 support to RSOC
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
                   ` (4 preceding siblings ...)
  2025-10-10 14:15 ` [PATCH v2 5/7] scsi: target: Report atomic values in INQUIRY John Garry
@ 2025-10-10 14:15 ` John Garry
  2025-10-10 14:15 ` [PATCH v2 7/7] scsi: target: Add atomic support to target_core_iblock John Garry
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This has us report if the device supports WRITE_ATOMIC_16 in the
REPORT_SUPPORTED_OPERATION_CODES command.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_spc.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index ddf8104645d1e..fe2b888bcb435 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -1470,6 +1470,24 @@ static const struct target_opcode_descriptor tcm_opcode_write_same32 = {
 	.update_usage_bits = set_dpofua_usage_bits32,
 };
 
+static bool tcm_is_atomic_enabled(const struct target_opcode_descriptor *descr,
+				  struct se_cmd *cmd)
+{
+	return cmd->se_dev->dev_attrib.atomic_max_len;
+}
+
+static struct target_opcode_descriptor tcm_opcode_write_atomic16 = {
+	.support = SCSI_SUPPORT_FULL,
+	.opcode = WRITE_ATOMIC_16,
+	.cdb_size = 16,
+	.usage_bits = {WRITE_ATOMIC_16, 0xf8, 0xff, 0xff,
+		       0xff, 0xff, 0xff, 0xff,
+		       0xff, 0xff, 0xff, 0xff,
+		       0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
+	.enabled = tcm_is_atomic_enabled,
+	.update_usage_bits = set_dpofua_usage_bits,
+};
+
 static bool tcm_is_caw_enabled(const struct target_opcode_descriptor *descr,
 			       struct se_cmd *cmd)
 {
@@ -2026,6 +2044,7 @@ static const struct target_opcode_descriptor *tcm_supported_opcodes[] = {
 	&tcm_opcode_write16,
 	&tcm_opcode_write_verify16,
 	&tcm_opcode_write_same32,
+	&tcm_opcode_write_atomic16,
 	&tcm_opcode_compare_write,
 	&tcm_opcode_read_capacity,
 	&tcm_opcode_read_capacity16,
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 7/7] scsi: target: Add atomic support to target_core_iblock
  2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
                   ` (5 preceding siblings ...)
  2025-10-10 14:15 ` [PATCH v2 6/7] scsi: target: Add WRITE_ATOMIC_16 support to RSOC John Garry
@ 2025-10-10 14:15 ` John Garry
  6 siblings, 0 replies; 9+ messages in thread
From: John Garry @ 2025-10-10 14:15 UTC (permalink / raw)
  To: martin.petersen
  Cc: target-devel, linux-kernel, linux-scsi, michael.christie,
	John Garry

From: Mike Christie <michael.christie@oracle.com>

This has target_core_iblock use the LIO helper function to translate its
block_device atomic settings to LIO settings. If we then get a write
that LIO has indicated is atomic via the SCF_ATOMIC flag, we use the
REQ_ATOMIC flag to tell the block layer to perform an atomic write.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: John Garry <john.g.garry@oracle.com>
---
 drivers/target/target_core_iblock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 281612b9830f8..8ec7b534ad760 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -152,6 +152,8 @@ static int iblock_configure_device(struct se_device *dev)
 	if (bdev_nonrot(bd))
 		dev->dev_attrib.is_nonrot = 1;
 
+	target_configure_write_atomic_from_bdev(&dev->dev_attrib, bd);
+
 	bi = bdev_get_integrity(bd);
 	if (!bi)
 		return 0;
@@ -773,6 +775,9 @@ iblock_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents,
 			else if (!bdev_write_cache(ib_dev->ibd_bd))
 				opf |= REQ_FUA;
 		}
+
+		if (cmd->se_cmd_flags & SCF_ATOMIC)
+			opf |= REQ_ATOMIC;
 	} else {
 		opf = REQ_OP_READ;
 		miter_dir = SG_MITER_FROM_SG;
-- 
2.43.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler
  2025-10-10 14:15 ` [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler John Garry
@ 2025-10-12  1:38   ` kernel test robot
  0 siblings, 0 replies; 9+ messages in thread
From: kernel test robot @ 2025-10-12  1:38 UTC (permalink / raw)
  To: John Garry, martin.petersen
  Cc: llvm, oe-kbuild-all, target-devel, linux-kernel, linux-scsi,
	michael.christie, John Garry

Hi John,

kernel test robot noticed the following build errors:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on linus/master v6.17 next-20251010]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/John-Garry/scsi-target-Rename-target_configure_unmap_from_queue/20251010-221915
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20251010141508.3695908-5-john.g.garry%40oracle.com
patch subject: [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler
config: arm-randconfig-001-20251012 (https://download.01.org/0day-ci/archive/20251012/202510120950.61bjguTF-lkp@intel.com/config)
compiler: clang version 19.1.7 (https://github.com/llvm/llvm-project cd708029e0b2869e80abe31ddb175f7c35361f90)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20251012/202510120950.61bjguTF-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202510120950.61bjguTF-lkp@intel.com/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__aeabi_uldivmod" [drivers/target/target_core_mod.ko] undefined!

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2025-10-12  1:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-10 14:15 [PATCH v2 0/7] scsi: target: Add WRITE_ATOMIC_16 support John Garry
2025-10-10 14:15 ` [PATCH v2 1/7] scsi: target: Rename target_configure_unmap_from_queue John Garry
2025-10-10 14:15 ` [PATCH v2 2/7] scsi: target: Add atomic se_device fields John Garry
2025-10-10 14:15 ` [PATCH v2 3/7] scsi: target: Add helper to setup atomic values from block_device John Garry
2025-10-10 14:15 ` [PATCH v2 4/7] scsi: target: Add WRITE_ATOMIC_16 handler John Garry
2025-10-12  1:38   ` kernel test robot
2025-10-10 14:15 ` [PATCH v2 5/7] scsi: target: Report atomic values in INQUIRY John Garry
2025-10-10 14:15 ` [PATCH v2 6/7] scsi: target: Add WRITE_ATOMIC_16 support to RSOC John Garry
2025-10-10 14:15 ` [PATCH v2 7/7] scsi: target: Add atomic support to target_core_iblock John Garry

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox