From nobody@FreeBSD.org  Fri Jan 10 01:45:59 2014
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTPS id 6EFCF283
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 10 Jan 2014 01:45:59 +0000 (UTC)
Received: from oldred.freebsd.org (oldred.freebsd.org [IPv6:2001:1900:2254:206a::50:4])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 40F7A159B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 10 Jan 2014 01:45:59 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id s0A1jxB2056847
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 10 Jan 2014 01:45:59 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id s0A1jxdF056838;
	Fri, 10 Jan 2014 01:45:59 GMT
	(envelope-from nobody)
Message-Id: <201401100145.s0A1jxdF056838@oldred.freebsd.org>
Date: Fri, 10 Jan 2014 01:45:59 GMT
From: Venkatesh Srinivas <venkateshs@google.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: virtio-scsi driver incorrectly encodes LUNs for device
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         185626
>Category:       kern
>Synopsis:       virtio-scsi driver incorrectly encodes LUNs for device
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bryanv
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 10 01:50:00 UTC 2014
>Closed-Date:    Sun Jan 12 17:41:52 UTC 2014
>Last-Modified:  Sun Jan 12 17:50:00 UTC 2014
>Originator:     Venkatesh Srinivas
>Release:        9.2-RELEASE
>Organization:
Google, Inc
>Environment:
FreeBSD freefall 9.2-RELEASE FreeBSD 9.2-RELEASE #0: Thu Jan  9 16:14:41 PST 2014     root@freefall:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
The virtio-scsi driver in FreeBSD 9.2-RELEASE (and in -current) encodes CAM LUN identifiers into virtio-scsi identifiers in vtscsi_set_request_lun(). vtscsi_set_request_lun constructs the low byte (lun[3]) of the transport-layer LUN incorrectly, resulting in mapping LUNs [0-255] to LUN 0.

For hypervisors and SCSI targets which emulate REPORT LUNs, this is harmless. For ones that do not, this may result in multiple CAM targets for a single physical target.
>How-To-Repeat:

>Fix:
Patch attached with fix.

Fix is tested on qemu from git -master, with REPORT LUNs disabled. Fix is also tested on Google Compute Engine hypervisor.

Patch attached with submission follows:

From 847c465b06ffe0bb4a4f61c33bd0c76c45f62e33 Mon Sep 17 00:00:00 2001
From: Venkatesh Srinivas <venkateshs@google.com>
Date: Thu, 9 Jan 2014 16:13:44 -0800
Subject: [PATCH] virtio_scsi: Correct conversion of CAM-layer LUN to
 virtio-scsi LUN.

virtio_scsi was incorrectly shifting the CAM-layer LUN before
extracting the low byte. This would result in mapping LUNs [0-255]
to LUN 0.
---
 sys/dev/virtio/scsi/virtio_scsi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys/dev/virtio/scsi/virtio_scsi.c b/sys/dev/virtio/scsi/virtio_scsi.c
index e5f922be..ccee89a 100644
--- a/sys/dev/virtio/scsi/virtio_scsi.c
+++ b/sys/dev/virtio/scsi/virtio_scsi.c
@@ -1539,7 +1539,7 @@ vtscsi_set_request_lun(struct ccb_hdr *ccbh, uint8_t lun[])
 	lun[0] = 1;
 	lun[1] = ccbh->target_id;
 	lun[2] = 0x40 | ((ccbh->target_lun >> 8) & 0x3F);
-	lun[3] = (ccbh->target_lun >> 8) & 0xFF;
+	lun[3] = ccbh->target_lun & 0xFF;
 }
 
 static void
-- 
1.8.5.1



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->bryanv 
Responsible-Changed-By: bryanv 
Responsible-Changed-When: Fri Jan 10 23:00:10 UTC 2014 
Responsible-Changed-Why:  

http://www.freebsd.org/cgi/query-pr.cgi?pr=185626 
State-Changed-From-To: open->closed 
State-Changed-By: bryanv 
State-Changed-When: Sun Jan 12 17:41:51 UTC 2014 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=185626 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/185626: commit references a PR
Date: Sun, 12 Jan 2014 17:40:54 +0000 (UTC)

 Author: bryanv
 Date: Sun Jan 12 17:40:47 2014
 New Revision: 260566
 URL: http://svnweb.freebsd.org/changeset/base/260566
 
 Log:
   Remove incorrect bit shift when assigning the LUN request field
   
   This caused duplicate targets appearing on Google Compute Engine
   instances.
   
   PR:		kern/185626
   Submitted by:	Venkatesh Srinivas <venkateshs@google.com>
   MFC after:	3 days
 
 Modified:
   head/sys/dev/virtio/scsi/virtio_scsi.c
 
 Modified: head/sys/dev/virtio/scsi/virtio_scsi.c
 ==============================================================================
 --- head/sys/dev/virtio/scsi/virtio_scsi.c	Sun Jan 12 15:35:03 2014	(r260565)
 +++ head/sys/dev/virtio/scsi/virtio_scsi.c	Sun Jan 12 17:40:47 2014	(r260566)
 @@ -1539,7 +1539,7 @@ vtscsi_set_request_lun(struct ccb_hdr *c
  	lun[0] = 1;
  	lun[1] = ccbh->target_id;
  	lun[2] = 0x40 | ((ccbh->target_lun >> 8) & 0x3F);
 -	lun[3] = (ccbh->target_lun >> 8) & 0xFF;
 +	lun[3] = ccbh->target_lun & 0xFF;
  }
  
  static void
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
