From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 767C3C433E0 for ; Mon, 1 Mar 2021 13:41:42 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A26E464DAF for ; Mon, 1 Mar 2021 13:41:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A26E464DAF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dme.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lGins-0003uF-O1 for qemu-devel@archiver.kernel.org; Mon, 01 Mar 2021 08:41:40 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lGil6-0001eg-2U for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:38:48 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:36682) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lGil3-0002ao-Gg for qemu-devel@nongnu.org; Mon, 01 Mar 2021 08:38:47 -0500 Received: by mail-wm1-x334.google.com with SMTP id k66so14538520wmf.1 for ; Mon, 01 Mar 2021 05:38:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=to:cc:subject:in-reply-to:references:from:date:message-id :mime-version:content-transfer-encoding; bh=huoBhlCYFeDimNGtOjp/zuvqaBBR5G2/2Bg5LAsPTZU=; b=i5VBQiBTir6SvT7gzRZBSGrOqNnaZ5ZKCQ3g9NUXvdMRAc4jqnJZHq2V03aZwmhOc+ IOVZDvi0TMqy5bb69R1Q8MuFicdb9dKK5I1Ja6CnSBdApagTUldVbt2LKVsR3h8fwYju 4O77gDq7nif5NTbQbyBPACFeoqyE51j7eMZ4OiyrhuaDAoKA2VVI+lWHTSq++Gu/nIuj oTrZ7smhXR2l0iaQV5zto9/ZzNGk3eN/z02jkotI/yCo6RNKREmlG7uXpPHFT3WDeSJf gKAtS0nHLsVBuihIyCXr+MzVv8XPwn9J1sHNmdQHrUFAakFrdtbCEdgznF1QqxOyHJuc qflw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:subject:in-reply-to:references:from:date :message-id:mime-version:content-transfer-encoding; bh=huoBhlCYFeDimNGtOjp/zuvqaBBR5G2/2Bg5LAsPTZU=; b=MCqX2RYnce0IC5hnVlR5SzQlTuNSdiV6oU/ScDGqsQH6m+SUsyqGDvENAM+k60bVTG PItcgDGz8RjkcoqgDPLI8TJ5sY42VRTOv4UnSwLjmplx4RYTMYCNSX5Uyv6gPt6zZ0iN uxq/ZV3YqoxZJghfoCqOlrqY8Baye+8vNbpe34cGq4GNMEaNKEojnmg/dptFYS6rEOE4 btVT6/L0BVbwFKsUME6sQgCM5EC6HSvnz2EtpQRqM9e13NJ+53ZB7oAHt27D4UYeKuGf CUhEViZLEbp+BIZl3cylUAbzilXP2MCAE/7+2ltt0sJ1uHxhPLff9KNOX2Aw71SMnxII 5czQ== X-Gm-Message-State: AOAM533VAKL6AtsIqF5h9NjvAQxu4ZETM2sVbO2g1YLxyw4wBfffHufv DmMOZ5mSGoH1Ul8Nc7wx9ARnog== X-Google-Smtp-Source: ABdhPJywjofKW48a/2o0Z9SyUQ/2naF0yq4v+tm+T0ZW1tws/ii7PmEalz6q2aVYnytXcQ1wZIELWg== X-Received: by 2002:a1c:cc14:: with SMTP id h20mr15722936wmb.14.1614605923261; Mon, 01 Mar 2021 05:38:43 -0800 (PST) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [2001:8b0:bb71:7140:64::1]) by smtp.gmail.com with ESMTPSA id p6sm11200036wru.2.2021.03.01.05.38.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Mar 2021 05:38:42 -0800 (PST) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id fef18acf; Mon, 1 Mar 2021 13:38:41 +0000 (UTC) To: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Subject: Re: [RFC PATCH 3/3] hw/block/pflash: use memory_region_init_rom_device_from_file() In-Reply-To: References: <20210225230238.3719051-1-philmd@redhat.com> <20210225230238.3719051-4-philmd@redhat.com> X-HGTTG: heart-of-gold From: David Edmondson Date: Mon, 01 Mar 2021 13:38:41 +0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: neutral client-ip=2a00:1450:4864:20::334; envelope-from=dme@dme.org; helo=mail-wm1-x334.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NEUTRAL=0.779, UNPARSEABLE_RELAY=0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Xu Yandong , Markus Armbruster , Max Reitz , Zheng Xiang , haibinzhang , Stefan Hajnoczi , Paolo Bonzini , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On Monday, 2021-03-01 at 12:50:33 +01, Philippe Mathieu-Daud=C3=A9 wrote: > On 2/26/21 9:23 AM, David Edmondson wrote: >> On Friday, 2021-02-26 at 00:02:38 +01, Philippe Mathieu-Daud=C3=A9 wrote: >>=20 >>> If the block drive is read-only we will model a "protected" flash >>> device. We can thus use memory_region_init_rom_device_from_file() >>> which mmap the backing file when creating the MemoryRegion. >>> If the same backing file is used by multiple QEMU instances, this >>> reduces the memory footprint (this is often the case with the >>> CODE flash image from OVMF and AAVMF). >>> >>> Suggested-by: Stefan Hajnoczi >>> Signed-off-by: Philippe Mathieu-Daud=C3=A9 >>> --- >>> hw/block/pflash_cfi01.c | 20 ++++++++++++++------ >>> hw/block/pflash_cfi02.c | 18 ++++++++++++++---- >>> 2 files changed, 28 insertions(+), 10 deletions(-) >>> >>> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c >>> index a5fa8d8b74a..5757391df1c 100644 >>> --- a/hw/block/pflash_cfi01.c >>> +++ b/hw/block/pflash_cfi01.c >>> @@ -743,11 +743,19 @@ static void pflash_cfi01_realize(DeviceState *dev= , Error **errp) >>> pfl->ro =3D 0; >>> } >>>=20=20 >>> - memory_region_init_rom_device( >>> - &pfl->mem, OBJECT(dev), >>> - &pflash_cfi01_ops, >>> - pfl, >>> - pfl->name, total_len, errp); >>> + if (pfl->blk && pfl->ro) { >>> + memory_region_init_rom_device_from_file(&pfl->mem, OBJECT(dev), >>> + &pflash_cfi01_ops, pfl, >>> + pfl->name, total_len, >>> + qemu_real_host_page_si= ze, >>> + RAM_SHARED, >>> + blk_bs(pfl->blk)->file= name, >>=20 >> How will this behave if someone does: >>=20 >> -drive file=3DOVMF_CODE.fd.qcow2,index=3D0,if=3Dpflash,format=3Dqcow= 2,readonly=3Don >>=20 >> Honestly, I'm not sure why they would, but it works today. > > OK I can add a check for "raw" driver, but I don't know to check for > offset =3D=3D 0. This is pretty much where I got to when I tried using mmap() and gave up (mostly because I figured that adding layer violating checks to the pflash driver would not be well received, but also because we don't share the same underlying file between multiple VMs and I wasn't sure that it would eventually work well for writable devices). dme. --=20 Driving at 90 down those country lanes, singing to "Tiny Dancer".