From nobody Sat Nov 2 08:06:17 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) client-ip=78.46.105.101; envelope-from=seabios-bounces@seabios.org; helo=coreboot.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=pass(p=reject dis=none) header.from=seabios.org ARC-Seal: i=1; a=rsa-sha256; t=1706194920; cv=none; d=zohomail.com; s=zohoarc; b=QiAymTy1nijd2AfkgBWq6AU8Nao1NwMSOCQk/9tZe/CII9NkDhyhy5xBhXiRk72FnvIxmmkg7v0Db0MWv8Za+OBjWDs/yR71UrR3vMbFS1cwSIqVzVKCxfbNSOBG27Pj+3lCaqlHv31waeoDpImU+DugTls7nHvuRNC7ebp6Ir0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706194920; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id; bh=he92l4L2XprJECJMbH18j1M7PVSR9w2bj37A5og9Dew=; b=EweZPuQ0/FeuyB/ZQNBhppTjR3lF2hI1+6dgKrtLFN7v/M3wHIktZfBNAv1sK7ArurhvwtMGSGfYMYF1+TyZ1JskNKNwlwrxLFvkgs2IM41Rk+dxWs1v42q8jzOLKsbftFQyX0THcvcd2ld1KOuP32f+r2HUpjW66tnpOjKvpio= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of seabios.org designates 78.46.105.101 as permitted sender) smtp.mailfrom=seabios-bounces@seabios.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from coreboot.org (coreboot.org [78.46.105.101]) by mx.zohomail.com with SMTPS id 1706194920574170.95882344369102; Thu, 25 Jan 2024 07:02:00 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id A672E21B7B; Thu, 25 Jan 2024 15:01:55 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 6FD4721BA5 for ; Thu, 25 Jan 2024 15:01:26 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mx0b-00190b01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40PArjK9026502; Thu, 25 Jan 2024 15:01:10 GMT Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mx0b-00190b01.pphosted.com (PPS) with ESMTPS id 3vtmg7vcxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 15:01:08 +0000 (GMT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint5.akamai.com (8.17.1.19/8.17.1.19) with ESMTP id 40PDaUxw030485; Thu, 25 Jan 2024 07:01:07 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint5.akamai.com (PPS) with ESMTPS id 3vrd1eu06p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 07:01:07 -0800 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) usma1ex-dag4mb5.msg.corp.akamai.com (172.27.91.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Thu, 25 Jan 2024 10:01:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seabios.org; s=dkim; t=1706194916; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-owner: list-unsubscribe:list-subscribe:list-post; bh=he92l4L2XprJECJMbH18j1M7PVSR9w2bj37A5og9Dew=; b=C7SGv6wodGlansInfj3AGhG2TP1IKrispqpUyCXHTgwbOwNZbbGX98F8EX2zkSYNlDO3f4 eqiZHRqPVY5UZbu1pnno1jFgbC8IGpXjYIu0TCYwg9pwpzj7hprKyrJXoGgWXhOIGU8HR4 zO0vFFlfX1UlWdvRvAQhAGKMtIQbnbA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= jan2016.eng; bh=tLSa/yLMV64YcXZzXHm6h9rd6I+wW1NCE8oiZKIQu3g=; b= WpGQhbHvZ0Uz4Eel/y4CegBeA5CG7sxMqYYnNsOsiXsrPTlY2QuAc8kMuBfcpASl 78elAPFNOidtUo6CEjos5SloTfizUDAj20YsNPY3GCbcVspLdnACUadCm9aKJQpY Ui0q1055cSe4ovu2YAm2vUwNlVZDRAYjeI4g3AZowtBUuvHA1vKCltKEn5AUEoys dRv+Yr6aHpVs5S4E2JY/q5p8hmHcIr4FBc4IhSNbL0cOeowOs6rIapvr1OyY9O9L mck05uqPIb7NCJP5csSlOIgg5l0BXURBwsFKNv6pUXKwa2+D9/qqCnx+DATPJJ1L xy4o2GKYss4on8C5LB0pJw== To: Date: Thu, 25 Jan 2024 10:00:50 -0500 Message-ID: <20240125150050.3775834-2-mtottenh@akamai.com> In-Reply-To: <20240125150050.3775834-1-mtottenh@akamai.com> References: <20240125150050.3775834-1-mtottenh@akamai.com> MIME-Version: 1.0 X-ClientProxiedBy: usma1ex-dag4mb1.msg.corp.akamai.com (172.27.91.20) To usma1ex-dag4mb5.msg.corp.akamai.com (172.27.91.24) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_08,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 malwarescore=0 adultscore=0 suspectscore=0 bulkscore=0 spamscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401250104 X-Proofpoint-ORIG-GUID: WkKxm9do-A5O-Kknt0e9UChaDqvuqX6k X-Proofpoint-GUID: WkKxm9do-A5O-Kknt0e9UChaDqvuqX6k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-25_08,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 bulkscore=0 impostorscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401190000 definitions=main-2401250106 X-Spam-Level: ** Message-ID-Hash: LM5I4DUD3R7IIHRGP4WWPIJVHXWZOBVX X-Message-ID-Hash: LM5I4DUD3R7IIHRGP4WWPIJVHXWZOBVX X-MailFrom: mtottenh@akamai.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-seabios.seabios.org-0; header-match-seabios.seabios.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: johunt@akamai.com, mtottenh@akamai.com, Gerd Hoffmann , Paul Menzel X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [RFC v3 1/1] Add LBA 64bit support for reads beyond 2TB. List-Id: SeaBIOS mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Max Tottenham via SeaBIOS Reply-To: Max Tottenham Content-Transfer-Encoding: quoted-printable Authentication-Results: coreboot.org; auth=pass smtp.auth=mailman@coreboot.org smtp.mailfrom=seabios-bounces@seabios.org X-Spamd-Bar: ---- X-ZohoMail-DKIM: pass (identity @seabios.org) X-ZM-MESSAGEID: 1706194925094100001 Content-Type: text/plain; charset="utf-8" When booting from a >2TB drive/filesystem, it's possible what the kernel/bootloader may be updated and written out at an LBA address beyond what is normally accessible by the READ(10) SCSI commands. If this happens to the kernel grub will fail to boot the kernel as it will call into the BIOS with an LBA address >2TB, and the BIOS will return an error. Per the SCSI spec, >2TB drives should return 0XFFFFFFFF, and a READ CAPACITY(16) command should be issued to determine the full size of the drive, READ(16) commands can then be used in order to read data at LBA addresses beyond 2TB (64 bit LBA addresses) Signed-off-by: Max Tottenham --- src/hw/blockcmd.c | 58 +++++++++++++++++++++++++++++++++++------------ src/hw/blockcmd.h | 27 ++++++++++++++++++++++ 2 files changed, 71 insertions(+), 14 deletions(-) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 6b6fea97..f59b2ef0 100644 --- a/src/hw/blockcmd.c +++ b/src/hw/blockcmd.c @@ -66,6 +66,23 @@ cdb_test_unit_ready(struct disk_op_s *op) return process_op(op); } =20 +static int +cdb_read_capacity16(struct disk_op_s *op, struct cdbres_read_capacity_16 *= data) +{ + struct cdb_sai_read_capacity_16 cmd; + memset(&cmd, 0, sizeof(cmd)); + cmd.command =3D CDB_CMD_SERVICE_ACTION_IN; + cmd.flags =3D CDB_CMD_SAI_READ_CAPACITY_16; + cmd.len =3D cpu_to_be32(sizeof(struct cdbres_read_capacity_16)); + op->command =3D CMD_SCSI; + op->count =3D 1; + op->buf_fl =3D data; + op->cdbcmd =3D &cmd; + op->blocksize =3D sizeof(*data); + return process_op(op); +} + + // Request capacity static int cdb_read_capacity(struct disk_op_s *op, struct cdbres_read_capacity *data) @@ -111,12 +128,21 @@ scsi_fill_cmd(struct disk_op_s *op, void *cdbcmd, int= maxcdb) switch (op->command) { case CMD_READ: case CMD_WRITE: ; - struct cdb_rwdata_10 *cmd =3D cdbcmd; - memset(cmd, 0, maxcdb); - cmd->command =3D (op->command =3D=3D CMD_READ ? CDB_CMD_READ_10 - : CDB_CMD_WRITE_10); - cmd->lba =3D cpu_to_be32(op->lba); - cmd->count =3D cpu_to_be16(op->count); + if (op->lba < 0xFFFFFFFFULL) { + struct cdb_rwdata_10 *cmd =3D cdbcmd; + memset(cmd, 0, maxcdb); + cmd->command =3D (op->command =3D=3D CMD_READ ? CDB_CMD_READ_10 + : CDB_CMD_WRITE_10); + cmd->lba =3D cpu_to_be32(op->lba); + cmd->count =3D cpu_to_be16(op->count); + } else { + struct cdb_rwdata_16 *cmd =3D cdbcmd; + memset(cmd, 0, maxcdb); + cmd->command =3D (op->command =3D=3D CMD_READ ? CDB_CMD_READ_16 + : CDB_CMD_WRITE_16); + cmd->lba =3D cpu_to_be64(op->lba); + cmd->count =3D cpu_to_be32(op->count); + } return GET_FLATPTR(op->drive_fl->blksize); case CMD_SCSI: if (MODESEGMENT) @@ -331,18 +357,22 @@ scsi_drive_setup(struct drive_s *drive, const char *s= , int prio) if (ret) return ret; =20 - // READ CAPACITY returns the address of the last block. - // We do not bother with READ CAPACITY(16) because BIOS does not suppo= rt - // 64-bit LBA anyway. - drive->blksize =3D be32_to_cpu(capdata.blksize); + if (be32_to_cpu(capdata.sectors) =3D=3D 0xFFFFFFFFUL) { + dprintf(3, "%s: >2TB Detected trying READCAP(16)\n", s); + struct cdbres_read_capacity_16 capdata16; + ret =3D cdb_read_capacity16(&dop, &capdata16); + drive->blksize =3D be32_to_cpu(capdata16.blksize); + drive->sectors =3D be64_to_cpu(capdata16.sectors) + 1; + } else { + drive->blksize =3D be32_to_cpu(capdata.blksize); + drive->sectors =3D (u64)be32_to_cpu(capdata.sectors) + 1; + } + if (drive->blksize !=3D DISK_SECTOR_SIZE) { dprintf(1, "%s: unsupported block size %d\n", s, drive->blksize); return -1; } - drive->sectors =3D (u64)be32_to_cpu(capdata.sectors) + 1; - dprintf(1, "%s blksize=3D%d sectors=3D%u\n" - , s, drive->blksize, (unsigned)drive->sectors); - + dprintf(1, "%s blksize=3D%d sectors=3D0x%llx\n", s, drive->blksize, dr= ive->sectors); // We do not recover from USB stalls, so try to be safe and avoid // sending the command if the (obsolete, but still provided by QEMU) // fixed disk geometry page may not be supported. diff --git a/src/hw/blockcmd.h b/src/hw/blockcmd.h index f18543ed..2683186c 100644 --- a/src/hw/blockcmd.h +++ b/src/hw/blockcmd.h @@ -18,6 +18,16 @@ struct cdb_rwdata_10 { u8 pad[6]; } PACKED; =20 +#define CDB_CMD_READ_16 0x88 +#define CDB_CMD_WRITE_16 0x8A +struct cdb_rwdata_16 { + u8 command; + u8 flags; + u64 lba; + u32 count; + u16 reserved_14; +} PACKED; + #define CDB_CMD_READ_CAPACITY 0x25 =20 struct cdb_read_capacity { @@ -32,6 +42,23 @@ struct cdbres_read_capacity { u32 blksize; } PACKED; =20 + +#define CDB_CMD_SERVICE_ACTION_IN 0x9E +#define CDB_CMD_SAI_READ_CAPACITY_16 0x10 +struct cdb_sai_read_capacity_16 { + u8 command; + u8 flags; + u64 lba; //marked as obsolete? + u32 len; + u16 reserved_14; +} PACKED; + +struct cdbres_read_capacity_16 { + u64 sectors; + u32 blksize; + u8 reserved_12[20]; +} PACKED; + #define CDB_CMD_TEST_UNIT_READY 0x00 #define CDB_CMD_INQUIRY 0x12 #define CDB_CMD_REQUEST_SENSE 0x03 --=20 2.34.1 _______________________________________________ SeaBIOS mailing list -- seabios@seabios.org To unsubscribe send an email to seabios-leave@seabios.org