From patchwork Tue Apr 26 01:06:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julius Werner X-Patchwork-Id: 8933841 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8736DBF29F for ; Tue, 26 Apr 2016 01:07:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 83FF720145 for ; Tue, 26 Apr 2016 01:07:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8EF752011B for ; Tue, 26 Apr 2016 01:07:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750963AbcDZBHG (ORCPT ); Mon, 25 Apr 2016 21:07:06 -0400 Received: from mail-pf0-f178.google.com ([209.85.192.178]:35717 "EHLO mail-pf0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbcDZBHE (ORCPT ); Mon, 25 Apr 2016 21:07:04 -0400 Received: by mail-pf0-f178.google.com with SMTP id n1so75901160pfn.2 for ; Mon, 25 Apr 2016 18:07:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=iFo5TcBF9XvZAjFi9fkOeggpRGViBFMp996DGaRvRYs=; b=BQocwCD59C9tqGZKm8D6zQwymI/UOnDAlNDNpddw2Lzh0wmnzK8ENDMLEPDU/kA4F+ TZnL5S3MVZvwNqL5zsQQr3PfhgZpRyhX1NNkGDIOGTeJ26cXsoSIKozQTvNWW6XDRCAQ 600bXWJvOy2pR+MoRS4RHwtuS96rti104zOGI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iFo5TcBF9XvZAjFi9fkOeggpRGViBFMp996DGaRvRYs=; b=ZlOQ65uxKVurBdaE0ywb1Pumx7ZCRH0ZO8Ksp/H6ro5/H+Dj58FuVV/hdL98fUmMzZ sqF6qCdi2UEQLHBZoTyI4dpP5WXCwTDIL4k2doX648myK8Bh9hToHYRvIY7ABp5Oaxjb 93ES9a83bolC07AgTPJFbjbIKfTfKLsKTEQKdDLSlyX7FBKGyUGTWCUTrRI5+QzeYIQK QrB906c9khlbgK8z4A6jWgnBEz5sSg/vzXlbnEr69m9AzDneQOkIqGrUhWmOKLXd0J8e N0rOZRRdcP1m+qAU1e7kADYOzK/xKAK66eR+PLLei+D252l4e80j1qKUyW0ko7qNWt4+ m6wA== X-Gm-Message-State: AOPr4FXrhlcvyyOC9d036pdFYo2pyicL9ug2VBXb6gqldW8q48M8VqaZuPTbzqTKWQCs4w== X-Received: by 10.98.44.70 with SMTP id s67mr1067449pfs.59.1461632822910; Mon, 25 Apr 2016 18:07:02 -0700 (PDT) Received: from jwerner-linux.mtv.corp.google.com ([172.22.64.164]) by smtp.gmail.com with ESMTPSA id v189sm31710858pfb.85.2016.04.25.18.07.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 25 Apr 2016 18:07:02 -0700 (PDT) From: Julius Werner To: Davidlohr Bueso Cc: linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Gwendal Grignou , Doug Anderson , Julius Werner Subject: [PATCH] block: partitions: efi: Always check for alternative GPT at end of drive Date: Mon, 25 Apr 2016 18:06:46 -0700 Message-Id: <1461632806-5946-1-git-send-email-jwerner@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-7.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The GUID Partiton Table layout maintains two synonymous partition tables on a block device, one starting in sector 1 and one in the very last sectors of the block device. This is useful if one of the tables gets accidentally corrupted (e.g. through a partial write because of an unexpected power loss). Linux normally only boots if the primary GPT is valid. It will not even try to find the alternative GPT to an invalid primary one unless the "gpt" command line option forces more aggressive detection. This doesn't really make any sense... if the "gpt" option is not set, the code validates the protective or hybrid MBR in sector 0 anyway before it even starts looking for the actual GPTs. If we get to the point where a valid proctective or hybrid MBR was found but the primary GPT was not found (valid), checking the alternative GPT is our best bet: we know that this block device is meant to use GPT (because any other partitioning system would've presumably overwritten sector 0), and we know that if the alternative GPT is valid it should contain more accurate information than parsing the protective/hybrid MBR with msdos_partition() would yield (which would otherwise be what happens next). Signed-off-by: Julius Werner --- block/partitions/efi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index 26cb624..0d4ca8e 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -625,7 +625,7 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, good_agpt = is_gpt_valid(state, le64_to_cpu(pgpt->alternate_lba), &agpt, &aptes); - if (!good_agpt && force_gpt) + if (!good_agpt) good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes); /* The obviously unsuccessful case */