All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND v2 0/4] target: fix bugs in Persistent Reservations
@ 2022-12-02 10:33 Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 1/4] target: core: fix preempt and abort for allreg res Dmitry Bogdanov
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:33 UTC (permalink / raw)
  To: Martin Petersen, target-devel; +Cc: linux-scsi, linux, Dmitry Bogdanov

This patch set fixes few rare bugs and deviations from standard in
PREEMPT AND ABORT and REGISTER AND MOVE operations.

v2:
  remove superfluous parentheses
  fix indentation

Dmitry Bogdanov (4):
  target: core: fix preempt and abort for allreg res
  target: core: fix memory leak in preempt_and_abort
  target: core: abort all preempted regs if requested
  target: core: new key must be used for moved PR

 drivers/target/target_core_pr.c | 33 ++++++++++++++++++++++++++-------
 1 file changed, 26 insertions(+), 7 deletions(-)

-- 
2.25.1


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

* [RESEND v2 1/4] target: core: fix preempt and abort for allreg res
  2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
@ 2022-12-02 10:33 ` Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 2/4] target: core: fix memory leak in preempt_and_abort Dmitry Bogdanov
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:33 UTC (permalink / raw)
  To: Martin Petersen, target-devel
  Cc: linux-scsi, linux, Dmitry Bogdanov, Mike Christie

Match a key only if SARK is not zero according to SPC-4 and the comment
above the code:
 If an all registrants persistent reservation is present and the SERVICE
 ACTION RESERVATION KEY field is set to zero, then all registrations
 shall be removed except for that of the I_T nexus that is being used
 for the PERSISTENT RESERVE OUT command;

Without this patch in case of SARK==0 no registrants will be removed.

Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
v2:
  remove superfluous parentheses
---
 drivers/target/target_core_pr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index a1d67554709f..1521a97ddac2 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -3022,7 +3022,7 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
 		if (calling_it_nexus)
 			continue;
 
-		if (pr_reg->pr_res_key != sa_res_key)
+		if (sa_res_key && pr_reg->pr_res_key != sa_res_key)
 			continue;
 
 		pr_reg_nacl = pr_reg->pr_reg_nacl;
-- 
2.25.1


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

* [RESEND v2 2/4] target: core: fix memory leak in preempt_and_abort
  2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 1/4] target: core: fix preempt and abort for allreg res Dmitry Bogdanov
@ 2022-12-02 10:33 ` Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 3/4] target: core: abort all preempted regs if requested Dmitry Bogdanov
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:33 UTC (permalink / raw)
  To: Martin Petersen, target-devel
  Cc: linux-scsi, linux, Dmitry Bogdanov, Mike Christie

Always release preempt_and_abort_list to avoid memory leak of
t10_pr_registration objects in it.

Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
 drivers/target/target_core_pr.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 1521a97ddac2..e3869576f254 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -2956,13 +2956,14 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
 			__core_scsi3_complete_pro_preempt(dev, pr_reg_n,
 				(preempt_type == PREEMPT_AND_ABORT) ? &preempt_and_abort_list : NULL,
 				type, scope, preempt_type);
-
-			if (preempt_type == PREEMPT_AND_ABORT)
-				core_scsi3_release_preempt_and_abort(
-					&preempt_and_abort_list, pr_reg_n);
 		}
+
 		spin_unlock(&dev->dev_reservation_lock);
 
+		if (preempt_type == PREEMPT_AND_ABORT)
+			core_scsi3_release_preempt_and_abort(
+				&preempt_and_abort_list, pr_reg_n);
+
 		if (pr_tmpl->pr_aptpl_active)
 			core_scsi3_update_and_write_aptpl(cmd->se_dev, true);
 
-- 
2.25.1


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

* [RESEND v2 3/4] target: core: abort all preempted regs if requested
  2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 1/4] target: core: fix preempt and abort for allreg res Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 2/4] target: core: fix memory leak in preempt_and_abort Dmitry Bogdanov
@ 2022-12-02 10:33 ` Dmitry Bogdanov
  2022-12-02 10:33 ` [RESEND v2 4/4] target: core: new key must be used for moved PR Dmitry Bogdanov
  2022-12-02 10:37 ` [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:33 UTC (permalink / raw)
  To: Martin Petersen, target-devel
  Cc: linux-scsi, linux, Dmitry Bogdanov, Mike Christie

According to SPC the preempted commands shall be always aborted.

SPC-4: 5.12.11.2.6 Preempting and aborting
c) all commands from the I_T nexus(es) associated with the persistent
reservations or registrations being preempted (i.e., preempted commands)
except the PERSISTENT RESERVE OUT command itself shall be aborted as
defined in SAM-5;

Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
 drivers/target/target_core_pr.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index e3869576f254..6a5f9504a481 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -2960,9 +2960,23 @@ core_scsi3_pro_preempt(struct se_cmd *cmd, int type, int scope, u64 res_key,
 
 		spin_unlock(&dev->dev_reservation_lock);
 
-		if (preempt_type == PREEMPT_AND_ABORT)
+		/*
+		 * SPC-4 5.12.11.2.6 Preempting and aborting
+		 * The actions described in this subclause shall be performed
+		 * for all I_T nexuses that are registered with the non-zero
+		 * SERVICE ACTION RESERVATION KEY value, without regard for
+		 * whether the preempted I_T nexuses hold the persistent
+		 * reservation. If the SERVICE ACTION RESERVATION KEY field is
+		 * set to zero and an all registrants persistent reservation is
+		 * present, the device server shall abort all commands for all
+		 * registered I_T nexuses.
+		 */
+		if (preempt_type == PREEMPT_AND_ABORT) {
+			core_tmr_lun_reset(dev, NULL, &preempt_and_abort_list,
+					   cmd);
 			core_scsi3_release_preempt_and_abort(
 				&preempt_and_abort_list, pr_reg_n);
+		}
 
 		if (pr_tmpl->pr_aptpl_active)
 			core_scsi3_update_and_write_aptpl(cmd->se_dev, true);
-- 
2.25.1


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

* [RESEND v2 4/4] target: core: new key must be used for moved PR
  2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
                   ` (2 preceding siblings ...)
  2022-12-02 10:33 ` [RESEND v2 3/4] target: core: abort all preempted regs if requested Dmitry Bogdanov
@ 2022-12-02 10:33 ` Dmitry Bogdanov
  2022-12-02 10:37 ` [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:33 UTC (permalink / raw)
  To: Martin Petersen, target-devel
  Cc: linux-scsi, linux, Dmitry Bogdanov, Mike Christie

According to SPC4 5.12.8:
e) Retain the reservation key specified in the SERVICE ACTION
RESERVATION KEY field and associated information;

But currently sa_res_key is only used for the not existing I_T nexus.
The patch adds a changing of the key for the existing I_T nexus the PR
moved to.

Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
v2:
  fix indentation
---
 drivers/target/target_core_pr.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 6a5f9504a481..1493b1d01194 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -3440,8 +3440,6 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
 	 *       transport protocols where port names are not required;
 	 * d) Register the reservation key specified in the SERVICE ACTION
 	 *    RESERVATION KEY field;
-	 * e) Retain the reservation key specified in the SERVICE ACTION
-	 *    RESERVATION KEY field and associated information;
 	 *
 	 * Also, It is not an error for a REGISTER AND MOVE service action to
 	 * register an I_T nexus that is already registered with the same
@@ -3463,6 +3461,12 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
 		dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
 						iport_ptr);
 		new_reg = 1;
+	} else {
+		/*
+		 * e) Retain the reservation key specified in the SERVICE ACTION
+		 *    RESERVATION KEY field and associated information;
+		 */
+		dest_pr_reg->pr_res_key = sa_res_key;
 	}
 	/*
 	 * f) Release the persistent reservation for the persistent reservation
-- 
2.25.1


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

* Re: [RESEND v2 0/4] target: fix bugs in Persistent Reservations
  2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
                   ` (3 preceding siblings ...)
  2022-12-02 10:33 ` [RESEND v2 4/4] target: core: new key must be used for moved PR Dmitry Bogdanov
@ 2022-12-02 10:37 ` Dmitry Bogdanov
  4 siblings, 0 replies; 6+ messages in thread
From: Dmitry Bogdanov @ 2022-12-02 10:37 UTC (permalink / raw)
  To: Martin Petersen, target-devel; +Cc: linux-scsi, linux

On Fri, Dec 02, 2022 at 01:33:27PM +0300, Dmitry Bogdanov wrote:
> This patch set fixes few rare bugs and deviations from standard in
> PREEMPT AND ABORT and REGISTER AND MOVE operations.
> 
> v2:
>   remove superfluous parentheses
>   fix indentation
> 
> Dmitry Bogdanov (4):
>   target: core: fix preempt and abort for allreg res
>   target: core: fix memory leak in preempt_and_abort
>   target: core: abort all preempted regs if requested
>   target: core: new key must be used for moved PR
> 
>  drivers/target/target_core_pr.c | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)
> 
> -- 
> 2.25.1
> 


Sorry, found it in 6.1.
Thought it was not merged because I did not find it in 6.2/scsi-*
branches.

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

end of thread, other threads:[~2022-12-02 10:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-02 10:33 [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov
2022-12-02 10:33 ` [RESEND v2 1/4] target: core: fix preempt and abort for allreg res Dmitry Bogdanov
2022-12-02 10:33 ` [RESEND v2 2/4] target: core: fix memory leak in preempt_and_abort Dmitry Bogdanov
2022-12-02 10:33 ` [RESEND v2 3/4] target: core: abort all preempted regs if requested Dmitry Bogdanov
2022-12-02 10:33 ` [RESEND v2 4/4] target: core: new key must be used for moved PR Dmitry Bogdanov
2022-12-02 10:37 ` [RESEND v2 0/4] target: fix bugs in Persistent Reservations Dmitry Bogdanov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.