Skip to contentSkip to conversation

scsifront: avoid aquiring same lock twice if ring is full

PATCH In review Juergen Gross 3 participants 4 messages Jan 13, 2015 – Jan 14, 2015 Xen hypervisor interface

lore
Share & tools
lore

Juergen Gross

author maintainer
#0 lore raw

PATCH 1/1 scsifront: avoid aquiring same lock twice if ring is full

The locking in scsifront_dev_reset_handler() is obviously wrong. In case of a full ring the host lock is aquired twice.

Fixing this issue enables to get rid of the endless fo loop with an explicit break statement.

---

drivers/xen/scsifront/scsifront.c +2 -4
diff -r 078f1bb69ea5 drivers/xen/scsifront/scsifront.c
@@ -447,12 +447,10 @@ static int scsifront_dev_reset_handler(s
 	uint16_t rqid;
 	int err = 0;
 
-	for (;;) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-		spin_lock_irq(host->host_lock);
+	spin_lock_irq(host->host_lock);
 #endif
-		if (!RING_FULL(&info->ring))
-			break;
+	while (RING_FULL(&info->ring)) {
 		if (err) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 			spin_unlock_irq(host->host_lock);
#1 lore raw

Hi,

Quoted 6 lines · Juergen Gross

The locking in scsifront_dev_reset_handler() is obviously wrong. In case of a full ring the host lock is aquired twice.

Fixing this issue enables to get rid of the endless fo loop with an explicit break statement.

Is this patch needed in upstream Linux kernel aswell, now that Xen PVSCSI drivers are in upstream Linux ?

Thanks,

-- Pasi

Quoted 26 lines

---

diff -r 078f1bb69ea5 drivers/xen/scsifront/scsifront.c

drivers/xen/scsifront/scsifront.c +2 -4
@@ -447,12 +447,10 @@ static int scsifront_dev_reset_handler(s
 	uint16_t rqid;
 	int err = 0;
 
-	for (;;) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-		spin_lock_irq(host->host_lock);
+	spin_lock_irq(host->host_lock);
 #endif
-		if (!RING_FULL(&info->ring))
-			break;
+	while (RING_FULL(&info->ring)) {
 		if (err) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 			spin_unlock_irq(host->host_lock);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author maintainer
#2 lore raw
Quoted 11 lines · Pasi Kärkkäinen

Hi,

Quoted 6 lines · Juergen Gross

The locking in scsifront_dev_reset_handler() is obviously wrong. In case of a full ring the host lock is aquired twice.

Fixing this issue enables to get rid of the endless fo loop with an explicit break statement.

Is this patch needed in upstream Linux kernel aswell, now that Xen PVSCSI drivers are in upstream Linux ?

No, especially this part of the code was reorganized and doesn't have that issue.

Juergen

Quoted 34 lines

Thanks,

-- Pasi

Quoted 26 lines

---

diff -r 078f1bb69ea5 drivers/xen/scsifront/scsifront.c

drivers/xen/scsifront/scsifront.c +2 -4
@@ -447,12 +447,10 @@ static int scsifront_dev_reset_handler(s
  	uint16_t rqid;
  	int err = 0;
 
-	for (;;) {
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-		spin_lock_irq(host->host_lock);
+	spin_lock_irq(host->host_lock);
  #endif
-		if (!RING_FULL(&info->ring))
-			break;
+	while (RING_FULL(&info->ring)) {
  		if (err) {
  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
  			spin_unlock_irq(host->host_lock);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#3 lore raw
In reply to Juergen Gross
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 13.01.15 at 17:22, <"[email protected]".non-mime.internet> wrote:

The locking in scsifront_dev_reset_handler() is obviously wrong. In case of a full ring the host lock is aquired twice.

Fixing this issue enables to get rid of the endless fo loop with an explicit break statement.

Perhaps worth noting that it was my c/s 1209:4d1471ca031e that screwed this up.

Jan

Quoted 21 lines

---

diff -r 078f1bb69ea5 drivers/xen/scsifront/scsifront.c

drivers/xen/scsifront/scsifront.c +2 -4
@@ -447,12 +447,10 @@ static int scsifront_dev_reset_handler(s
 	uint16_t rqid;
 	int err = 0;
 
-	for (;;) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
-		spin_lock_irq(host->host_lock);
+	spin_lock_irq(host->host_lock);
 #endif
-		if (!RING_FULL(&info->ring))
-			break;
+	while (RING_FULL(&info->ring)) {
 		if (err) {
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,12)
 			spin_unlock_irq(host->host_lock);