Skip to contentSkip to conversation

vhost/scsi: Adjustments for five function implementations

PATCH In review SF Markus Elfring 3 participants 18 messages May 20, 2017 – May 22, 2017

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

cover vhost/scsi: Adjustments for five function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 16:25:04 +0200

A few update suggestions were taken into account
from static source code analysis.

Markus Elfring (2):
Improve a size determination in four functions
Delete error messages for failed memory allocations in five functions

 drivers/vhost/scsi.c | 33 +++++++++++----------------------
 1 file changed, 11 insertions(+), 22 deletions(-)
Signature · 1 line
2.13.0
#1 lore raw

PATCH 1/2 vhost/scsi: Improve a size determination in four functions

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 13:48:44 +0200

Replace the specification of four data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/vhost/scsi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/vhost/scsi.c +4 -5
index fd6c8b66f06f..650533916c19 100644
@@ -597,8 +597,7 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
 	sg = cmd->tvc_sgl;
 	prot_sg = cmd->tvc_prot_sgl;
 	pages = cmd->tvc_upages;
-	memset(cmd, 0, sizeof(struct vhost_scsi_cmd));
-
+	memset(cmd, 0, sizeof(*cmd));
 	cmd->tvc_sgl = sg;
 	cmd->tvc_prot_sgl = prot_sg;
 	cmd->tvc_upages = pages;
@@ -1757,5 +1756,5 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 		return -EEXIST;
 	}
 
-	tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
+	tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL);
 	if (!tv_nexus) {
@@ -1958,5 +1957,5 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
 	if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET)
 		return ERR_PTR(-EINVAL);
 
-	tpg = kzalloc(sizeof(struct vhost_scsi_tpg), GFP_KERNEL);
+	tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
 	if (!tpg) {
@@ -2012,5 +2011,5 @@ vhost_scsi_make_tport(struct target_fabric_configfs *tf,
 	/* if (vhost_scsi_parse_wwn(name, &wwpn, 1) < 0)
 		return ERR_PTR(-EINVAL); */
 
-	tport = kzalloc(sizeof(struct vhost_scsi_tport), GFP_KERNEL);
+	tport = kzalloc(sizeof(*tport), GFP_KERNEL);
 	if (!tport) {
Signature · 1 line
2.13.0
Reviewed-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] vhost/scsi: Improve a size determination in four functions

Quoted 11 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 13:48:44 +0200

Replace the specification of four data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/vhost/scsi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
#3 lore raw

PATCH 1/2 vhost/scsi: Improve a size determination in four functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 13:48:44 +0200

Replace the specification of four data structures by pointer dereferences as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.

---
 drivers/vhost/scsi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/vhost/scsi.c +4 -5
index fd6c8b66f06f..650533916c19 100644
@@ -597,8 +597,7 @@ vhost_scsi_get_tag(struct vhost_virtqueue *vq, struct vhost_scsi_tpg *tpg,
 	sg = cmd->tvc_sgl;
 	prot_sg = cmd->tvc_prot_sgl;
 	pages = cmd->tvc_upages;
-	memset(cmd, 0, sizeof(struct vhost_scsi_cmd));
-
+	memset(cmd, 0, sizeof(*cmd));
 	cmd->tvc_sgl = sg;
 	cmd->tvc_prot_sgl = prot_sg;
 	cmd->tvc_upages = pages;
@@ -1757,5 +1756,5 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 		return -EEXIST;
 	}
 
-	tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
+	tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL);
 	if (!tv_nexus) {
@@ -1958,5 +1957,5 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
 	if (kstrtou16(name + 5, 10, &tpgt) || tpgt >= VHOST_SCSI_MAX_TARGET)
 		return ERR_PTR(-EINVAL);
 
-	tpg = kzalloc(sizeof(struct vhost_scsi_tpg), GFP_KERNEL);
+	tpg = kzalloc(sizeof(*tpg), GFP_KERNEL);
 	if (!tpg) {
@@ -2012,5 +2011,5 @@ vhost_scsi_make_tport(struct target_fabric_configfs *tf,
 	/* if (vhost_scsi_parse_wwn(name, &wwpn, 1) < 0)
 		return ERR_PTR(-EINVAL); */
 
-	tport = kzalloc(sizeof(struct vhost_scsi_tport), GFP_KERNEL);
+	tport = kzalloc(sizeof(*tport), GFP_KERNEL);
 	if (!tport) {
Signature · 1 line
2.13.0
#4 lore raw

PATCH 2/2 vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 15:50:30 +0200

Omit seven extra messages for memory allocation failures in these functions.

This issue was detected by using the Coccinelle software.

---
 drivers/vhost/scsi.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/vhost/scsi.c +7 -17
index 650533916c19..49d07950e2e5 100644
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
 		vs->vs_events_missed = true;
 		return NULL;
 	}
@@ -1722,21 +1721,15 @@ static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
-		if (!tv_cmd->tvc_sgl) {
-			pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
+		if (!tv_cmd->tvc_sgl)
 			goto out;
-		}
 
 		tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) *
 				VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
-		if (!tv_cmd->tvc_upages) {
-			pr_err("Unable to allocate tv_cmd->tvc_upages\n");
+		if (!tv_cmd->tvc_upages)
 			goto out;
-		}
 
 		tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) *
 				VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
-		if (!tv_cmd->tvc_prot_sgl) {
-			pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
+		if (!tv_cmd->tvc_prot_sgl)
 			goto out;
-		}
 	}
 	return 0;
 out:
@@ -1760,6 +1753,5 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 	if (!tv_nexus) {
 		mutex_unlock(&tpg->tv_tpg_mutex);
-		pr_err("Unable to allocate struct vhost_scsi_nexus\n");
 		return -ENOMEM;
 	}
 	/*
@@ -1961,7 +1953,6 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
-	if (!tpg) {
-		pr_err("Unable to allocate struct vhost_scsi_tpg");
+	if (!tpg)
 		return ERR_PTR(-ENOMEM);
-	}
+
 	mutex_init(&tpg->tv_tpg_mutex);
 	INIT_LIST_HEAD(&tpg->tv_tpg_list);
 	tpg->tport = tport;
@@ -2015,7 +2006,6 @@ vhost_scsi_make_tport(struct target_fabric_configfs *tf,
-	if (!tport) {
-		pr_err("Unable to allocate struct vhost_scsi_tport");
+	if (!tport)
 		return ERR_PTR(-ENOMEM);
-	}
+
 	tport->tport_wwpn = wwpn;
 	/*
 	 * Determine the emulated Protocol Identifier and Target Port Name
Signature · 1 line
2.13.0
#5 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 8 lines · SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 15:50:30 +0200

Omit seven extra messages for memory allocation failures in these functions.

This issue was detected by using the Coccinelle software.

Please include an actual explanation for this change instead of linking to slides. Why are you trying to get rid of memory allocation failure messages?

drivers/vhost/scsi.c vhost_scsi_allocate_evt(struct vhost_scsi *vs, · line 418

Quoted 12 lines
---
 drivers/vhost/scsi.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/vhost/scsi.c +0 -1
index 650533916c19..49d07950e2e5 100644
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
#define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
                if ((vq)->error_ctx)                               \
                                eventfd_signal((vq)->error_ctx, 1);\
        } while (0)

You silently dropped the eventfd_signal() call. Please explain.

#6 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 4 lines
Quoted 1 line

Please include an actual explanation for this change instead of linking to slides.

Do you care for a bit of code size reduction by removal of questionable error messages?

Quoted 1 line

Why are you trying to get rid of memory allocation failure messages?

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

Quoted 11 lines

drivers/vhost/scsi.c vhost_scsi_allocate_evt(struct vhost_scsi *vs, · line 418

Quoted 4 lines

+++ b/drivers/vhost/scsi.c

drivers/vhost/scsi.c +0 -1
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
#define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
                if ((vq)->error_ctx)                               \
                                eventfd_signal((vq)->error_ctx, 1);\
        } while (0)
Quoted 1 line

You silently dropped the eventfd_signal() call.

Do you prefer to preserve this special error handling then?

Regards,
Markus

#7 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Why are you trying to get rid of memory allocation failure messages?

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

Quoted 11 lines
Quoted 11 lines

drivers/vhost/scsi.c vhost_scsi_allocate_evt(struct vhost_scsi *vs, · line 418

Quoted 4 lines

+++ b/drivers/vhost/scsi.c

drivers/vhost/scsi.c +0 -1
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
#define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
                if ((vq)->error_ctx)                               \
                                eventfd_signal((vq)->error_ctx, 1);\
        } while (0)
Quoted 3 lines
Quoted 1 line

You silently dropped the eventfd_signal() call.

Do you prefer to preserve this special error handling then?

Yes, please leave vq_err() calls.

Stefan

#8 lore raw

Re: vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 10 lines
Quoted 2 lines

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

I am also looking for a more complete and easier accessible documentation for this aspect of the desired exception handling.
How would we like to resolve any remaining open issues there?

Regards,
Markus

#9 lore raw

Re: vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 7 lines · SF Markus Elfring
Quoted 7 lines
Quoted 2 lines

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

Quoted 7 lines
Quoted 3 lines

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

I am also looking for a more complete and easier accessible documentation for this aspect of the desired exception handling.
How would we like to resolve any remaining open issues there?

No objection from me but please make sure to keep vq_err().

Stefan

#10 lore raw

Re: vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 1 line

No objection from me but please make sure to keep vq_err().

How long should I wait before I may dare to send another variant for the discussed update suggestion?

Which commit message would be acceptable then for this update step?

Regards,
Markus

#11 lore raw

Re: vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to SF Markus Elfring
Quoted 7 lines · SF Markus Elfring
Quoted 7 lines
Quoted 2 lines

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

Quoted 7 lines
Quoted 3 lines

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

I am also looking for a more complete and easier accessible documentation for this aspect of the desired exception handling.
How would we like to resolve any remaining open issues there?

No objection from me but please make sure to keep vq_err().

Stefan

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#12 lore raw

Re: vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to Stefan Hajnoczi
Quoted 10 lines
Quoted 2 lines

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

I am also looking for a more complete and easier accessible documentation for this aspect of the desired exception handling.
How would we like to resolve any remaining open issues there?

Regards,
Markus

#13 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to Stefan Hajnoczi
Quoted 3 lines · Stefan Hajnoczi

I'm not sure if kmalloc() and friends guarantee to show
a message (not just the first time, but for every failed allocation)?

It prints multiple times, but it's ratelimited. It can also be disabled using a config option.

See slab_out_of_memory().

regards,
dan carpenter

#14 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

Quoted 9 lines · Dan Carpenter
Quoted 3 lines · Stefan Hajnoczi

I'm not sure if kmalloc() and friends guarantee to show
a message (not just the first time, but for every failed allocation)?

It prints multiple times, but it's ratelimited. It can also be disabled using a config option.

See slab_out_of_memory().

Thanks!

Stefan

#15 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to SF Markus Elfring
Quoted 4 lines · SF Markus Elfring
Quoted 1 line

Why are you trying to get rid of memory allocation failure messages?

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

If kmalloc() and friends guarantee to print a warning and backtrace on every allocation failure, then there's no need for error messages in callers.

That seems like good justification that can go in the commit description, but I'm not sure if kmalloc() and friends guarantee to show a message (not just the first time, but for every failed allocation)?

Quoted 11 lines
Quoted 11 lines

drivers/vhost/scsi.c vhost_scsi_allocate_evt(struct vhost_scsi *vs, · line 418

Quoted 4 lines

+++ b/drivers/vhost/scsi.c

drivers/vhost/scsi.c +0 -1
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
#define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
                if ((vq)->error_ctx)                               \
                                eventfd_signal((vq)->error_ctx, 1);\
        } while (0)
Quoted 3 lines
Quoted 1 line

You silently dropped the eventfd_signal() call.

Do you prefer to preserve this special error handling then?

Yes, please leave vq_err() calls.

Stefan

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#16 lore raw

Re: [PATCH 2/2] vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to Stefan Hajnoczi
Quoted 4 lines
Quoted 1 line

Please include an actual explanation for this change instead of linking to slides.

Do you care for a bit of code size reduction by removal of questionable error messages?

Quoted 1 line

Why are you trying to get rid of memory allocation failure messages?

Do you find information from a Linux allocation failure report sufficient for any function implementations here?

Quoted 11 lines

drivers/vhost/scsi.c vhost_scsi_allocate_evt(struct vhost_scsi *vs, · line 418

Quoted 4 lines

+++ b/drivers/vhost/scsi.c

drivers/vhost/scsi.c +0 -1
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
#define vq_err(vq, fmt, ...) do {                                  \
                pr_debug(pr_fmt(fmt), ##__VA_ARGS__);       \
                if ((vq)->error_ctx)                               \
                                eventfd_signal((vq)->error_ctx, 1);\
        } while (0)
Quoted 1 line

You silently dropped the eventfd_signal() call.

Do you prefer to preserve this special error handling then?

Regards,
Markus

#17 lore raw

PATCH 2/2 vhost/scsi: Delete error messages for failed memory allocations in five functions

In reply to SF Markus Elfring

From: Markus Elfring <[email protected]>
Date: Sat, 20 May 2017 15:50:30 +0200

Omit seven extra messages for memory allocation failures in these functions.

This issue was detected by using the Coccinelle software.

---
 drivers/vhost/scsi.c | 24 +++++++-----------------
 1 file changed, 7 insertions(+), 17 deletions(-)
drivers/vhost/scsi.c +7 -17
index 650533916c19..49d07950e2e5 100644
@@ -417,5 +417,4 @@ vhost_scsi_allocate_evt(struct vhost_scsi *vs,
 	if (!evt) {
-		vq_err(vq, "Failed to allocate vhost_scsi_evt\n");
 		vs->vs_events_missed = true;
 		return NULL;
 	}
@@ -1722,21 +1721,15 @@ static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
-		if (!tv_cmd->tvc_sgl) {
-			pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
+		if (!tv_cmd->tvc_sgl)
 			goto out;
-		}
 
 		tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) *
 				VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
-		if (!tv_cmd->tvc_upages) {
-			pr_err("Unable to allocate tv_cmd->tvc_upages\n");
+		if (!tv_cmd->tvc_upages)
 			goto out;
-		}
 
 		tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) *
 				VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
-		if (!tv_cmd->tvc_prot_sgl) {
-			pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
+		if (!tv_cmd->tvc_prot_sgl)
 			goto out;
-		}
 	}
 	return 0;
 out:
@@ -1760,6 +1753,5 @@ static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
 	if (!tv_nexus) {
 		mutex_unlock(&tpg->tv_tpg_mutex);
-		pr_err("Unable to allocate struct vhost_scsi_nexus\n");
 		return -ENOMEM;
 	}
 	/*
@@ -1961,7 +1953,6 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
-	if (!tpg) {
-		pr_err("Unable to allocate struct vhost_scsi_tpg");
+	if (!tpg)
 		return ERR_PTR(-ENOMEM);
-	}
+
 	mutex_init(&tpg->tv_tpg_mutex);
 	INIT_LIST_HEAD(&tpg->tv_tpg_list);
 	tpg->tport = tport;
@@ -2015,7 +2006,6 @@ vhost_scsi_make_tport(struct target_fabric_configfs *tf,
-	if (!tport) {
-		pr_err("Unable to allocate struct vhost_scsi_tport");
+	if (!tport)
 		return ERR_PTR(-ENOMEM);
-	}
+
 	tport->tport_wwpn = wwpn;
 	/*
 	 * Determine the emulated Protocol Identifier and Target Port Name
Signature · 1 line
2.13.0