From nobody Tue May 14 08:23:22 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=1705692888; cv=none; d=zohomail.com; s=zohoarc; b=AEfgN+L5Ix/BzqG0sM56BKACe9d7AaADbZTDPl+V9889xGGIaNj80UmFMfCx4jswsSVM+S8e7Ex9mku12M73O/Ipmze8xpM3SghNqTiJWjTWRTmmpthRxbHzPoliA+9HYmjClCqHx8SPx5WHuBG7h4JvEfTU55k/zBd02Ho+X04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1705692888; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:Subject:Subject:To:To:Message-Id; bh=TT2bQaTrlgtLmEEAmrxptLp6bLYGqZ9XzOvYq3gU9aA=; b=K70ofFSGoMQQKPqVrLdbZL1xxJAAjg1IffwPKJqlysxvlL32e5tzcX6FZAnNvMrQzpBLo16lbwCLpGUpsINsQEENamYmE9M6LnmPZlJw8oJHyo7QzU3rm4YehctN/srD0lDT+4wsnoGDRIewnLtH2EdjgxriZ6fR52M/Z13GQHs= 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 1705692888763195.12891231976425; Fri, 19 Jan 2024 11:34:48 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id 9C36F22BE8; Fri, 19 Jan 2024 19:34:43 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 16FCD22A5D for ; Fri, 19 Jan 2024 19:34:24 +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 40JI5pfn030750 for ; Fri, 19 Jan 2024 19:34:22 GMT Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by mx0b-00190b01.pphosted.com (PPS) with ESMTPS id 3vq5fvbawb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 19:34:22 +0000 (GMT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint2.akamai.com (8.17.1.19/8.17.1.19) with ESMTP id 40JI7UIF030874 for ; Fri, 19 Jan 2024 14:34:21 -0500 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint2.akamai.com (PPS) with ESMTPS id 3vkpr31xjx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 19 Jan 2024 14:34:21 -0500 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; Fri, 19 Jan 2024 14:34:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seabios.org; s=dkim; t=1705692885; 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: references:list-id:list-owner:list-unsubscribe:list-subscribe:list-post; bh=TT2bQaTrlgtLmEEAmrxptLp6bLYGqZ9XzOvYq3gU9aA=; b=Ss1qP45woftWXeSzPQ7vO0BCAH0fpCp0iNFrMnqoowrO9ojpovGwfONH6N69DusFP2k+up k8nufvi1eQSouADdA7RHa4J4RUQJYVn6KSh3hdWdvHX4xqA2nsg1ipYeSu6GgH9JOm30Od 5Zs3UCpBcSFp2XzQuRK8g8V8u3KbUKY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=jan2016.eng; bh=lzHc1 t5hW2uYrj+dZljhwy0eyNU0UHZJ1jdE4G7Luxg=; b=ntAoJGUzTBTJcEeKr7yzZ swJuL7tQHlysXrzq5m6riwGHM/gzRcTvyv9wrHyN8t/Iviwr7LlfaKGN9WW2kbtS Cbqom6VM22m0SOWsI6D5Hp8Yy/SVfiaY3PKPet/6cT9c22gjpM7Ds6qV88+ltWy6 suoTbA4swJJfgoZ03a89SzNEtpiFJ9WAyBTM4YvaLykRbyap1bo9XfrAyjGmMxh8 BGf/IrBjzjmUvpm+a4kwFT/uUJru8vSv/Quc2RKGbRpY5dJXjjMlRdc9XbwEPNGQ cPghcjB29Zl4PovuyXZvx9TAtCEhBWHQznxjf+SB3QK1ay9Giemb+q1L4mjSLtE9 A== To: Date: Fri, 19 Jan 2024 14:33:53 -0500 Message-ID: <20240119193353.2340707-1-mtottenh@akamai.com> MIME-Version: 1.0 X-ClientProxiedBy: ustx2ex-dag4mb5.msg.corp.akamai.com (172.27.50.204) 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.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_12,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxscore=0 mlxlogscore=971 malwarescore=0 spamscore=0 phishscore=0 adultscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401190116 X-Proofpoint-GUID: WZ5UQ5AHg2k3TxnwsBAuwjyV98y_tf7U X-Proofpoint-ORIG-GUID: WZ5UQ5AHg2k3TxnwsBAuwjyV98y_tf7U X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-19_12,2024-01-19_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=953 clxscore=1011 spamscore=0 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401190116 X-Spam-Level: *** Message-ID-Hash: CX6HNFXIBX53IAKDFDWX4J46RXRH2C47 X-Message-ID-Hash: CX6HNFXIBX53IAKDFDWX4J46RXRH2C47 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 X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [RFC] 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: 1705692890034100001 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 issues 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). --- src/hw/blockcmd.c | 75 +++++++++++++++++++++++++++++++++++------------ src/hw/blockcmd.h | 27 +++++++++++++++++ 2 files changed, 84 insertions(+), 18 deletions(-) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 6b6fea97..4f5dc2d7 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,13 +128,23 @@ 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); - return GET_FLATPTR(op->drive_fl->blksize); + 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); + return GET_FLATPTR(op->drive_fl->blksize); + } 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) return -1; @@ -331,18 +358,30 @@ 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 (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); + if (be32_to_cpu(capdata.sectors) =3D=3D 0xFFFFFFFFUL) { + dprintf(1, "%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); + if (drive->blksize !=3D DISK_SECTOR_SIZE) { + dprintf(1, "%s: unsupported block size %d\n", s, drive->blksiz= e); + return -1; + } =20 + drive->sectors =3D be64_to_cpu(capdata16.sectors); + dprintf(1, "READCAP(16) %s blksize=3D%d sectors=3D%llX\n" + , s, drive->blksize, drive->sectors); + } else { + drive->blksize =3D be32_to_cpu(capdata.blksize); + if (drive->blksize !=3D DISK_SECTOR_SIZE) { + dprintf(1, "%s: unsupported block size %d\n", s, drive->blksiz= e); + 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); + } // 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