From patchwork Thu Mar 7 09:37:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 159814 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp7222872jad; Thu, 7 Mar 2019 01:40:29 -0800 (PST) X-Google-Smtp-Source: APXvYqz62AQcYlkOOVM6Egu8rsc7y5QLpIN7NRp5cMSwWuJ+eTb5gPiskf17uyC8tci92LjKlnos X-Received: by 2002:a0d:edc3:: with SMTP id w186mr9159086ywe.301.1551951629239; Thu, 07 Mar 2019 01:40:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551951629; cv=none; d=google.com; s=arc-20160816; b=zSlr9n8L/iJ9THYYs8/eeBMpVPUddOgCSKNeyXGK3TEqeijXRdV5SIVFadU9zhiBDs hbP1w+orLQv02YfepcI9W87v37zNnEZePaXtzcwIgm+gIaGYPaINEQDK7nWa7liwyNMi SpenUZIPgl+/VzkLMXryksOiZWgOnYwKCE6fBfQW0LLkfL0rfdMJ0c3llQKJAZNe5JSy 1OpMJ/TxsChOKEW3qzylKLlWaxt7KxGhflS5zxttdk/3pDEAFqPl/AhAuF1az+v7rVFS g1Z8+udITOFQdmmRQGQi5xOkKDM09wsrUYcO5FwP9mMjUo0fhAlEl7BPlueO9ipntc8k 7wkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from; bh=9w9GzomsHvCGpgvvsLhSMe56ctphm+IpZWhKsz+iSVI=; b=f5a12Q0oQgzRFosbBSti4n0+Dtbsg+2NAtvBnP2jtcCi0o7WN6z+BkhdWljWW+QXjg ZGSt+Yqna8cvwCrIGTQSFeukBO/GtSNP8BLTwcA6DFnUQuXnYTkuZE92hObpHnrNXXLG cMnneUDTVVAM13Q8LtEs0RyqCDsxpaOxt5T+g3ZklLvDk21NOB2Hh75uIHO9M2nYJ+ni +HUIMKyN/1vddVvhiF4i8HS1yKhP3W8JoVOJQKIdbOqJHv3EkNq64aiXA4MYmlUWg6qP hB3m0fIwhZkgIT4CSpBpmE9ks70xrxV4T0XqDTM9lmzJRu74Pa+Sq9q9X7IZ4bMAICl6 9s4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t11si2557627ywf.203.2019.03.07.01.40.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 07 Mar 2019 01:40:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([127.0.0.1]:48114 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pVs-0007YA-Ny for patch@linaro.org; Thu, 07 Mar 2019 04:40:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:54780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1pT4-0005Wg-Vm for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1pT4-0004yK-66 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 04:37:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1pT2-0004wh-1O; Thu, 07 Mar 2019 04:37:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 46C6380472; Thu, 7 Mar 2019 09:37:31 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5831BA4FB0; Thu, 7 Mar 2019 09:37:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id C411E1138661; Thu, 7 Mar 2019 10:37:23 +0100 (CET) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 10:37:20 +0100 Message-Id: <20190307093723.655-2-armbru@redhat.com> In-Reply-To: <20190307093723.655-1-armbru@redhat.com> References: <20190307093723.655-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 07 Mar 2019 09:37:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC PATCH v6 1/4] hw/block: better reporting on pflash backing file mismatch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, alex.bennee@linaro.org, philmd@redhat.com, mreitz@redhat.com, lersek@redhat.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée It looks like there was going to be code to check we had some sort of alignment so let's replace it with an actual check. Reject undersized images with "device needs N bytes, backing file provides only M bytes". This is a bit more useful than the enigmatic "failed to read the initial flash content" when we attempt to read the number of bytes the device should have. Continue to accept oversized images, but warn "device needs N bytes, rest ignored". Signed-off-by: Alex Bennée Reviewed-by: Laszlo Ersek Signed-off-by: Markus Armbruster --- hw/block/pflash_cfi01.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) -- 2.17.2 diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c index 9d1c356eb6..75ce8ef489 100644 --- a/hw/block/pflash_cfi01.c +++ b/hw/block/pflash_cfi01.c @@ -45,6 +45,7 @@ #include "qemu/bitops.h" #include "qemu/host-utils.h" #include "qemu/log.h" +#include "qemu/error-report.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "trace.h" @@ -730,13 +731,6 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) } device_len = sector_len_per_device * blocks_per_device; - /* XXX: to be fixed */ -#if 0 - if (total_len != (8 * 1024 * 1024) && total_len != (16 * 1024 * 1024) && - total_len != (32 * 1024 * 1024) && total_len != (64 * 1024 * 1024)) - return NULL; -#endif - memory_region_init_rom_device( &pfl->mem, OBJECT(dev), &pflash_cfi01_ops, @@ -763,6 +757,27 @@ static void pflash_cfi01_realize(DeviceState *dev, Error **errp) } if (pfl->blk) { + /* + * Validate the backing store is the right size for pflash + * devices. If the user supplies a larger file we ignore the + * tail. + */ + int64_t backing_len = blk_getlength(pfl->blk); + if (backing_len < 0) { + error_setg(errp, "unable to check size of backing file"); + return; + } + + if (backing_len < total_len) { + error_setg(errp, "device needs %" PRIu64 " bytes, " + "backing file provides only %" PRIu64 " bytes", + total_len, backing_len); + return; + } else if (backing_len > total_len) { + warn_report("device needs %" PRIu64 " bytes, rest ignored", + total_len); + } + /* read the initial flash content */ ret = blk_pread(pfl->blk, 0, pfl->storage, total_len);