From nobody Sat Dec 21 15:09:52 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=1706182545; cv=none; d=zohomail.com; s=zohoarc; b=XddVGUsz2w1D12dtAFvaqOm4FFhYcxxyJiW1tHKqrDWEWx+cRg90OEczlt/BG2BFV6eAe1hgfvmOsV8o+NGQA9aGwNLgmzAcSQwxDlNoOLRpy2KOKv2eQqBHwtepSCHIlMvPxFTVocQOSHAh8W8jIpTOBFJqyi8dzSOWuO+KYhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1706182545; 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=/k73oXcIz3WVqTNOrZrfIsDoxlUIJ1rH6UDqE9l/aMQ=; b=VM1JgSeJxGNMOEFuvJYnwscTHT2JSCKuHO9RCef5Ij8xRwYAu51eGZlP9YVqZ6eATD4Lu9K5/0emv903+fWpjf9hp5MkmQvJ0LESU9PNwNTOttEXkQEqgX+Hr78qn54od9k6e1a6nReYsvA3Klb7NgwCacI9oHFUEUlR0CU24vE= 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 1706182545313599.0252050760722; Thu, 25 Jan 2024 03:35:45 -0800 (PST) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTPA id EBDA421572; Thu, 25 Jan 2024 11:35:39 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by coreboot.org (Postfix) with ESMTP id 6EBB7217AA for ; Thu, 25 Jan 2024 11:35:22 +0000 (UTC) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by m0050096.ppops.net-00190b01. (8.17.1.24/8.17.1.24) with ESMTP id 40PArbc7014321; Thu, 25 Jan 2024 11:35:20 GMT Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by m0050096.ppops.net-00190b01. (PPS) with ESMTPS id 3vtmg806kj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 11:35:19 +0000 (GMT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint1.akamai.com (8.17.1.19/8.17.1.19) with ESMTP id 40P8frJH018435; Thu, 25 Jan 2024 06:35:18 -0500 Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by prod-mail-ppoint1.akamai.com (PPS) with ESMTPS id 3vrad2jqaw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 25 Jan 2024 06:35:18 -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; Thu, 25 Jan 2024 06:35:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=seabios.org; s=dkim; t=1706182541; 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=/k73oXcIz3WVqTNOrZrfIsDoxlUIJ1rH6UDqE9l/aMQ=; b=gklrsF5/4oyC0D9LHqV4Mr1lMS0PfbCjcMYHaiLJ2E3srSO7UBXKS/bN7FG6f8DNq3CChY HbeuXXnznnTUynLg7QT3P2i9lefabNq62B0LoYWNw2Yo+R6JpjKFeQbuV4x7TUyuWWzlRi YE1vDlAdZXx4xkWkaLSIMJCe5VvtCrI= 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=rTQzrOYkErmiZq2egoR57dETPgy8B8JMCOuOtRbNhVI=; b= P6RIt94Bo2lfpPVJI4lx/78hxKP2cZk3ITaFHV1s1ACx+NgQsirvZw9UFJMrbz2Y 3OPJpukSsjS2FTceRz6dw4q3kwBONelFdRnctrHYcUsPZlW4kpTcXTXTQqv/HUYV sJfWTcwFEiyA/A7tzJSBjhu6BlpWqA4QLjOprbAUvxt86I+LHmV5WQ+AOlcX4F47 ND9lM8YEr620gqn1aiV5C87qMdl+3U3ghSqOqOXodQJ6gvAih+LvRVmGKn6byMFT 8TfUeaknQHBtjoHIpZC8nCoFb5k98GENOeQA0g/Nwn5vOR9wNVDdKWjsJP6M1I9x cMgxCgk+ZSf1RKRhGJBOGQ== To: Date: Thu, 25 Jan 2024 06:35:01 -0500 Message-ID: <20240125113501.3739465-2-mtottenh@akamai.com> In-Reply-To: <20240125113501.3739465-1-mtottenh@akamai.com> References: <20240125113501.3739465-1-mtottenh@akamai.com> MIME-Version: 1.0 X-ClientProxiedBy: usma1ex-dag4mb7.msg.corp.akamai.com (172.27.91.26) 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_06,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401250080 X-Proofpoint-ORIG-GUID: 4Yt2NvtedQw7_fXFaefmys_nNH_VDfAp X-Proofpoint-GUID: 4Yt2NvtedQw7_fXFaefmys_nNH_VDfAp 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_06,2024-01-25_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 impostorscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 spamscore=0 suspectscore=0 phishscore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401190000 definitions=main-2401250080 X-Spam-Level: *** Message-ID-Hash: OCEVVRMM54IZMCR46XOJVBVT6IG6XQ3V X-Message-ID-Hash: OCEVVRMM54IZMCR46XOJVBVT6IG6XQ3V 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 X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [SeaBIOS] [RFC v2 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: 1706182546490100001 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). Signed-off-by: Max Tottenham --- src/hw/blockcmd.c | 61 +++++++++++++++++++++++++++++++++++------------ src/hw/blockcmd.h | 27 +++++++++++++++++++++ 2 files changed, 73 insertions(+), 15 deletions(-) diff --git a/src/hw/blockcmd.c b/src/hw/blockcmd.c index 6b6fea97..9b6a32bf 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,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(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); + 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=3D%llX\n", s, drive->blksize, driv= e->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