Skip to contentSkip to conversation

IB/qib: fix test of unsigned variable

PATCH Superseded Mike Marciniszyn 4 participants 5 messages May 11, 2015 – May 12, 2015 3 messages not in the archive InfiniBand

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 IB/qib: fix test of unsigned variable

Commit d4988623cc60 ("IB/qib: use arch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.

Unfortunately, the new interface returns a signed value and the patch tested the unsigned wc_cookie.

Fix the issue by using 'ret' and only assigning
wc_cookie from ret when ret >= 0. Additionally, insure
ret is 0 on success.

---
 drivers/infiniband/hw/qib/qib_wc_x86_64.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5 -3
index 6d61ef9..85525be 100644
@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd)
 	}
 
 	if (!ret) {
-		dd->wc_cookie = arch_phys_wc_add(pioaddr, piolen);
-		if (dd->wc_cookie < 0)
-			ret = -EINVAL;
+		ret = arch_phys_wc_add(pioaddr, piolen);
+		if (ret >= 0) {
+			dd->wc_cookie = ret;
+			ret = 0;
+		}
 	}
 
 	return ret;

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20150511121315.21044.78464.stgit-K+u1se/DcYrLESAwzcoQNrvm/[email protected]

#2 lore raw

Hi,

Quoted 11 lines · Mike Marciniszyn

Commit d4988623cc60 ("IB/qib: use arch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.

Unfortunately, the new interface returns a signed value and the patch tested the unsigned wc_cookie.

Fix the issue by using 'ret' and only assigning
wc_cookie from ret when ret >= 0. Additionally, insure
ret is 0 on success.

Cc Luis R. Rodriguez <[email protected]>
Cc Luis R. Rodriguez <mcgrof-IBi9RG/[email protected]>
Quoted 14 lines
---
 drivers/infiniband/hw/qib/qib_wc_x86_64.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +0 -1
index 6d61ef9..85525be 100644
@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd)
 	}
 
 	if (!ret) {
-		dd->wc_cookie = arch_phys_wc_add(pioaddr, piolen);

drivers/infiniband/hw/qib/qib_wc_x86_64.c int qib_enable_wc(struct qib_devdata *dd) · line 126

Quoted 10 lines
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5 -2
-		if (dd->wc_cookie < 0)
-			ret = -EINVAL;
+		ret = arch_phys_wc_add(pioaddr, piolen);
+		if (ret >= 0) {
+			dd->wc_cookie = ret;
+			ret = 0;
+		}
 	}
 
 	return ret;

Regards.

Signature · 8 lines
Yann Droneaud
OPTEYA


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 1431348365.25060.31.camel-RlY5vtjFyJ3QT0dZR+AlfA@public.gmane.org

#4 lore raw
Quoted 29 lines · Yann Droneaud

Hi,

Quoted 11 lines · Mike Marciniszyn

Commit d4988623cc60 ("IB/qib: use arch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.

Unfortunately, the new interface returns a signed value and the patch tested the unsigned wc_cookie.

Fix the issue by using 'ret' and only assigning
wc_cookie from ret when ret >= 0. Additionally, insure
ret is 0 on success.

Cc Luis R. Rodriguez <[email protected]>
Cc Luis R. Rodriguez <mcgrof-IBi9RG/[email protected]>
Quoted 11 lines
---
 drivers/infiniband/hw/qib/qib_wc_x86_64.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/infiniband/hw/qib/qib_wc_x86_64.c +0 -0
index 6d61ef9..85525be 100644
@@ -116,9 +116,11 @@ int qib_enable_wc(struct qib_devdata *dd)
 	}
 
Quoted 9 lines

drivers/infiniband/hw/qib/qib_wc_x86_64.c int qib_enable_wc(struct qib_devdata *dd) · line 123

Quoted 9 lines
drivers/infiniband/hw/qib/qib_wc_x86_64.c +5 -3
 	if (!ret) {
-		dd->wc_cookie = arch_phys_wc_add(pioaddr, piolen);
-		if (dd->wc_cookie < 0)
-			ret = -EINVAL;
+		ret = arch_phys_wc_add(pioaddr, piolen);
+		if (ret >= 0) {
+			dd->wc_cookie = ret;
+			ret = 0;
+		}

This fix is broken. Luis and I discussed this at some length with his original patch. You're right that the code is broken because wc_cookie is unsigned and that needs fixed, but once qib_enable_wc returns an error, we don't fail the adapter init, we print out a warning about poor performance and move on. Later, we test wc_cookie != 0 in order to determine if we used PAT. It doesn't matter if our return was positive or negative, we only try to enable wc via arch_phys_wc_add() when we didn't use PAT, and so we need to capture the return value whether it's a valid cookie or an error return in order to make sure we don't attempt to use PAT later on.

So, the matrix of what the driver does now looks like this:

dd->wc_cookie == 0: PAT was used
dd->wc_cookie > 0: wc was used successfully
dd->wc_cookie < 0: neither PAT nor wc was used

I've fixed up the change to simply switch wc_cookie from unsigned long to plain long and left the original code as it was, and it is now staged for 4.1-rc.

Signature · 2 lines
Doug Ledford <[email protected]>
              GPG KeyID: 0E572FDD

A message that is not in the archive (sent off-list or not yet received): 1431447713.43876.44.camel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org

#6 lore raw

PiBTbywgdGhlIG1hdHJpeCBvZiB3aGF0IHRoZSBkcml2ZXIgZG9lcyBub3cgbG9va3MgbGlrZSB0 aGlzOg0KPiANCj4gZGQtPndjX2Nvb2tpZSA9PSAwOiBQQVQgd2FzIHVzZWQNCj4gZGQtPndjX2Nv b2tpZSA+IDA6IHdjIHdhcyB1c2VkIHN1Y2Nlc3NmdWxseSB3Y19jb29raWUgPCAwOiBuZWl0aGVy IFBBVA0KPiBkZC0+bm9yIHdjIHdhcyB1c2VkDQo+IA0KPiBJJ3ZlIGZpeGVkIHVwIHRoZSBjaGFu Z2UgdG8gc2ltcGx5IHN3aXRjaCB3Y19jb29raWUgZnJvbSB1bnNpZ25lZCBsb25nIHRvIHBsYWlu DQo+IGxvbmcgYW5kIGxlZnQgdGhlIG9yaWdpbmFsIGNvZGUgYXMgaXQgd2FzLCBhbmQgaXQgaXMg bm93IHN0YWdlZCBmb3IgNC4xLXJjLg0KPiANCg0KSSBoYXZlIGEgdjIgb2YgdGhpcyBwYXRjaCB0 aGF0IGNoYW5nZXMgdGhlIHR5cGUgb2YgdGhlIHdjX2Nvb2tpZS4NCg0KSXQgYWxzbyB1c2VzIGFu eSBuZWdhdGl2ZSBjb29raWUgYXMgdGhlIHJldC4gICBJdCBzZWVtcyBiZXR0ZXIgdG8gdXNlIGlu IGFjdHVhbCBlcnJvciBhcmNoX3BoeXNfd2NfYWRkKCkgZnJvbSAgdnMuIGEgY2FubmVkIG9uZS4N Cg0KTWlrZSANCg==
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#7 lore raw
In reply to a message not in the archive
Quoted 5 lines · Mike Marciniszyn

Commit d4988623cc60 ("IB/qib: use arch_phys_wc_add()") adjusted mtrr inititialization to use the new interface.

Unfortunately, the new interface returns a signed value and the patch tested the unsigned wc_cookie.

Looks like wc_cookie is only used with arch_phys_wc_add/del, so it should become an int, not casted..

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html