NetBSD Problem Report #54389

From gson@gson.org  Sat Jul 20 13:36:04 2019
Return-Path: <gson@gson.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id BE6A27A173
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 20 Jul 2019 13:36:04 +0000 (UTC)
Message-Id: <20190720133559.40AFF9896BA@guava.gson.org>
Date: Sat, 20 Jul 2019 16:35:59 +0300 (EEST)
From: gson@gson.org (Andreas Gustafsson)
Reply-To: gson@gson.org (Andreas Gustafsson)
To: gnats-bugs@NetBSD.org
Subject: NetBSD fails to interoperate with qemu virtual SATA CDROM
X-Send-Pr-Version: 3.95

>Number:         54389
>Category:       kern
>Synopsis:       NetBSD fails to interoperate with qemu virtual SATA CDROM
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 20 13:40:00 +0000 2019
>Closed-Date:    Mon Sep 09 19:04:23 +0000 2019
>Last-Modified:  Mon Sep 09 19:04:23 +0000 2019
>Originator:     Andreas Gustafsson
>Release:        NetBSD 8.1; also -current, source date 2019.07.20.03.54.50
>Organization:
>Environment:
System: NetBSD
Architecture: i386
Machine: i386
>Description:

By default, qemu-system-i386 emulates a 1996 vintage PC ("pc-i440fx-4.0"),
with an IDE CDROM.  NetBSD works fine on this, including the CDROM.

Qemu can also emulate newer PCs.  For example, by specifying "-machine
q35" on the qemu command line, it will emulate a 2009 vintage PC with
AHCI and a SATA CDROM.  However, if you try to install NetBSD on this,
the installation fails with errors from the cd0 device, such as:

  cd0(ahcisata0:1:0): Sense Error Code 0x50

>How-To-Repeat:

Run:

  anita install --vmm-args="-machine q35" http://ftp.netbsd.org/pub/NetBSD/NetBSD-8.1/i386/ | tee log

This will fail with a "loop detected" error as opening the CDROM
repeatedly fails and sysinst prompts for it the device name again.
Inspect the log for the "cd0(ahcisata0:5:0): Sense Error Code 0x50"
errors.

>Fix:

I believe I have found the cause of the errors: Qemu is insisting that
for ATAPI commands that return data, such as the "GET CONFIGURATION"
command (0x46), the ATAPI "BYTE COUNT LIMIT" field must contain a
nonzero value, but NetBSD is setting this field to zero when sending
the command over SATA.

The failing check in qemu happens in the function validate_bcl(), called
from ide_atapi_cmd().

The following patch to NetBSD makes installation work, by effectively
doing for SATA what the line

            xfer->c_bcount <= 0xffff ? xfer->c_bcount : 0xffff,

in sys/dev/scsipi/atapi_wdc.c does for ATA.  But since I'm not an
expert in this area, I'm not sure if this is the correct fix.
Could someone familiar with ATAPI and SATA please review?

Index: src/sys/dev/ata/satafis_subr.c
===================================================================
RCS file: /cvsroot/src/sys/dev/ata/satafis_subr.c,v
retrieving revision 1.7
diff -u -r1.7 satafis_subr.c
--- src/sys/dev/ata/satafis_subr.c	22 Jul 2012 17:57:57 -0000	1.7
+++ src/sys/dev/ata/satafis_subr.c	20 Jul 2019 10:12:28 -0000
@@ -140,12 +140,16 @@
 void
 satafis_rhd_construct_atapi(struct ata_xfer *xfer, uint8_t *fis)
 {
+	int bcount16;

 	memset(fis, 0, RHD_FISLEN);

 	fis[fis_type] = RHD_FISTYPE;
 	fis[rhd_c] = RHD_C;
 	fis[rhd_command] = ATAPI_PKT_CMD;
+	bcount16 = xfer->c_bcount <= 0xffff ? xfer->c_bcount : 0xffff;
+	fis[rhd_lba1] = (bcount16 >> 0) & 0xff;
+	fis[rhd_lba2] = (bcount16 >> 8) & 0xff;
 	fis[rhd_features0] = (xfer->c_flags & C_DMA) ?
 	    ATAPI_PKT_CMD_FTRE_DMA : 0;
 }

>Release-Note:

>Audit-Trail:
From: "Andreas Gustafsson" <gson@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54389 CVS commit: src/sys/dev/ata
Date: Thu, 15 Aug 2019 09:00:23 +0000

 Module Name:	src
 Committed By:	gson
 Date:		Thu Aug 15 09:00:23 UTC 2019

 Modified Files:
 	src/sys/dev/ata: satafis_subr.c

 Log Message:
 Set the ATAPI "BYTE COUNT LIMIT" field in the SATA case like we
 already do in the ATA case, to make NetBSD work with the virtual
 SATA CD-ROM of "qemu-system-i386 -machine q35".  Fixes PR kern/54389.
 OK mlelstv.


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.9 src/sys/dev/ata/satafis_subr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->needs-pullups
State-Changed-By: gson@NetBSD.org
State-Changed-When: Thu, 15 Aug 2019 09:06:56 +0000
State-Changed-Why:
Patch committed.


State-Changed-From-To: needs-pullups->pending-pullups
State-Changed-By: gson@NetBSD.org
State-Changed-When: Wed, 04 Sep 2019 18:35:25 +0000
State-Changed-Why:
Pullup requested.


From: "Martin Husemann" <martin@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54389 CVS commit: [netbsd-9] src/sys/dev/ata
Date: Thu, 5 Sep 2019 09:02:48 +0000

 Module Name:	src
 Committed By:	martin
 Date:		Thu Sep  5 09:02:48 UTC 2019

 Modified Files:
 	src/sys/dev/ata [netbsd-9]: satafis_subr.c

 Log Message:
 Pull up following revision(s) (requested by gson in ticket #179):

 	sys/dev/ata/satafis_subr.c: revision 1.9

 Set the ATAPI "BYTE COUNT LIMIT" field in the SATA case like we
 already do in the ATA case, to make NetBSD work with the virtual
 SATA CD-ROM of "qemu-system-i386 -machine q35".  Fixes PR kern/54389.

 OK mlelstv.


 To generate a diff of this commit:
 cvs rdiff -u -r1.8 -r1.8.10.1 src/sys/dev/ata/satafis_subr.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: pending-pullups->closed
State-Changed-By: gson@NetBSD.org
State-Changed-When: Mon, 09 Sep 2019 19:04:23 +0000
State-Changed-Why:
Pulled up.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.