From owner-freebsd-bugs@FreeBSD.ORG Fri Jan 10 01:50:00 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id A84392EF for ; Fri, 10 Jan 2014 01:50:00 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 835B815B7 for ; Fri, 10 Jan 2014 01:50:00 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.7/8.14.7) with ESMTP id s0A1o0PC003713 for ; Fri, 10 Jan 2014 01:50:00 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.7/8.14.7/Submit) id s0A1o09i003710; Fri, 10 Jan 2014 01:50:00 GMT (envelope-from gnats) Resent-Date: Fri, 10 Jan 2014 01:50:00 GMT Resent-Message-Id: <201401100150.s0A1o09i003710@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Venkatesh Srinivas 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 ; 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 ; 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 ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Subject: kern/185626: virtio-scsi driver incorrectly encodes LUNs for device X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Jan 2014 01:50:00 -0000 >Number: 185626 >Category: kern >Synopsis: virtio-scsi driver incorrectly encodes LUNs for device >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Fri Jan 10 01:50:00 UTC 2014 >Closed-Date: >Last-Modified: >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 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: >Unformatted: