From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcph6-0007pH-Pn for mharc-grub-devel@gnu.org; Sun, 24 May 2020 08:25:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcpgz-0007ij-5d for grub-devel@gnu.org; Sun, 24 May 2020 08:25:25 -0400 Received: from ionic.de ([87.98.244.45]:51557 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcpgx-0004jw-TE for grub-devel@gnu.org; Sun, 24 May 2020 08:25:24 -0400 Received: from apgunner.local.home.ionic.de (home.ionic.de [217.92.117.31]) by mail.ionic.de (Postfix) with ESMTPSA id 3E2494F0BA14 for ; Sun, 24 May 2020 12:25:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ionic.de; s=default; t=1590323122; bh=weigtzVoec6HUJmaUh0NOF3o/X3f31zLejvuUVBLn68=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tsr/J6P8N9dH4xoin50LZcRtzOrdOHBQo/bbMTfGpN2DcmkfEV5d4WLYIhlmrVScj qTT0kS11DGGSM2NOTTe4E9oXWB428P+n9eIyFKT4k2CHJhD9MSKMykcHnH7XSO0B/F LOtFqUSXwOiKB5iaq4gVtGOSrPkgx9wjSm5pliig= From: Mihai Moldovan To: The development of GNU GRUB Subject: [PATCH v2 2/7] biosdisk: restore LBA mode after read/write failures Date: Sun, 24 May 2020 14:25:12 +0200 Message-Id: <20200524122517.5010-3-ionic@ionic.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200524122517.5010-1-ionic@ionic.de> References: <20200524122517.5010-1-ionic@ionic.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=87.98.244.45; envelope-from=ionic@ionic.de; helo=mail.ionic.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/24 07:43:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 May 2020 12:25:25 -0000 Falling back to the old-style CHS mode after read failures is a valid error recovery technique, but read failures can just happen. One prominent example of that is trying to read the (somewhat) inaccessible end sectors on newer disks with old, buggy system firmware. Restore LBA access mode after an old-style CHS mode read/write try again. This might lead to additional read/write operations (in case they fail again), but also fixes issues like the biosdisk constantly being unable to read data off sectors that are located behind the (shy of) 8-GB-mark. --- grub-core/disk/i386/pc/biosdisk.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/grub-core/disk/i386/pc/biosdisk.c b/grub-core/disk/i386/pc/biosdisk.c index 044bc48f3..3d55e68f8 100644 --- a/grub-core/disk/i386/pc/biosdisk.c +++ b/grub-core/disk/i386/pc/biosdisk.c @@ -990,11 +990,27 @@ grub_biosdisk_rw (int cmd, grub_disk_t disk, * sectors, fall back to the CHS mode ... */ grub_err_t chs_read = GRUB_ERR_NONE; + + /* Save old data first. */ + grub_uint64_t old_total_sectors = disk->total_sectors; + + /* + * Switch into CHS mode and call the old-style reading code path. + */ data->flags &= ~GRUB_BIOSDISK_FLAG_LBA; disk->total_sectors = data->cylinders * data->heads * data->sectors; - chs_read = grub_biosdisk_rw (cmd, disk, sector, size, segment); + /* + * Whatever happened, restore LBA access. + * + * We don't want the biosdisk instance to permanently degrade into + * an old-style CHS access mode after a read failure. Read failures + * can happen, especially for the end sectors. + */ + data->flags |= GRUB_BIOSDISK_FLAG_LBA; + disk->total_sectors = old_total_sectors; + /* Pass CHS operation result through. */ return chs_read; } -- 2.25.1