From nobody Sat Jun 29 04:57:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548700658147913.1063441202662; Mon, 28 Jan 2019 10:37:38 -0800 (PST) Received: from localhost ([127.0.0.1]:36751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBmm-0007DL-4L for importer@patchew.org; Mon, 28 Jan 2019 13:37:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1goBNA-0002gd-Oo for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1goBN9-0008Rf-RI for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:04 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:44063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1goBN9-0008Pf-JS for qemu-devel@nongnu.org; Mon, 28 Jan 2019 13:11:03 -0500 Received: by mail-wr1-x436.google.com with SMTP id z5so19119239wrt.11 for ; Mon, 28 Jan 2019 10:11:03 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id b18sm97910681wrw.83.2019.01.28.10.11.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 10:11:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=07yrPBcrxdQgo8XLbgpxSvssxeoja/CdPeRpQD42bkw=; b=dglg2Cd9MKsrBaLqgl8plzNMQddPMEJhKwOrVJD5iHUia8bfBszLaVH8o1zrHdQHhF sPSi6BS1HO+RuDmXHlzJspfRoFrUqOTgvx9hWgJA7FdithkKyNxtMcctNH1a2S/yIh1F +qIhT47sMMPgPFoLsTVTR4OBNMWM4dvJsTFmY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=07yrPBcrxdQgo8XLbgpxSvssxeoja/CdPeRpQD42bkw=; b=B07/n74sBcbsZoNjUJWWX9SIRiVFZKiyuYzwyPrX3+pO5DtXUk+SCi6PiTwXTxtBDL QNVwt9xV8QIDD8cWsdvUVRSZpLoOtRNyu9Q1vkhMgqwSTT60GsWCDjEk26r9k/06hAHp /fF+RXNYWF9SbU6FI5q8XRF8uyhN6tSGPRtDFxHjzuLuN89BTTdS77/Hnbz23fzwbFrS sygfQrjsxbISx1homasja+tFIqV5rmcyXf+NPaA8Fvy05+gi59sjcXIKPGoME8xu7fTX vsBDvouhE9ZOBt87TPEg1ROn9TWywzx80F/hBPnB5NkVh4Vsf6lsLCZsSgYpqLZxSPZ5 qVOg== X-Gm-Message-State: AJcUukcDFuMwTT/XoXcEkRZflIqCA1urGFnqYcHRVY6d6UdeBCBgR2Wm 6hvYBLJnyd5lGLyCYFaslJ7MZ5Ek4e5L9g== X-Google-Smtp-Source: ALg8bN7wZZu2mTSjHMMoTbPIEn9w6SkxowDKKH4ziyQ/tWFZbOWD45NowwoqnYRxZuwsg1Fh9ctbWg== X-Received: by 2002:adf:891a:: with SMTP id s26mr22571309wrs.44.1548699062245; Mon, 28 Jan 2019 10:11:02 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 28 Jan 2019 18:10:31 +0000 Message-Id: <20190128181047.20781-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190128181047.20781-1-peter.maydell@linaro.org> References: <20190128181047.20781-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PULL 10/26] memory: add memory_region_flush_rom_device() 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi ROM devices go via MemoryRegionOps->write() callbacks for write operations and do not dirty/invalidate that memory. Device emulation must be able to mark memory ranges that have been modified internally (e.g. using memory_region_get_ram_ptr()). Introduce the memory_region_flush_rom_device() API for this purpose. Signed-off-by: Stefan Hajnoczi Message-id: 20190123212234.32068-2-stefanha@redhat.com Reviewed-by: Peter Maydell [PMM: fix block comment style] Signed-off-by: Peter Maydell --- include/exec/memory.h | 18 ++++++++++++++++++ exec.c | 13 +++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index cd2f209b64e..abe9cc79c0d 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -1344,6 +1344,24 @@ bool memory_region_snapshot_get_dirty(MemoryRegion *= mr, void memory_region_reset_dirty(MemoryRegion *mr, hwaddr addr, hwaddr size, unsigned client); =20 +/** + * memory_region_flush_rom_device: Mark a range of pages dirty and invalid= ate + * TBs (for self-modifying code). + * + * The MemoryRegionOps->write() callback of a ROM device must use this fun= ction + * to mark byte ranges that have been modified internally, such as by dire= ctly + * accessing the memory returned by memory_region_get_ram_ptr(). + * + * This function marks the range dirty and invalidates TBs so that TCG can + * detect self-modifying code. + * + * @mr: the region being flushed. + * @addr: the start, relative to the start of the region, of the range bei= ng + * flushed. + * @size: the size, in bytes, of the range being flushed. + */ +void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr = size); + /** * memory_region_set_readonly: Turn a memory region read-only (or read-wri= te) * diff --git a/exec.c b/exec.c index 9557a4e523c..da3e635f91b 100644 --- a/exec.c +++ b/exec.c @@ -3162,6 +3162,19 @@ static void invalidate_and_set_dirty(MemoryRegion *m= r, hwaddr addr, cpu_physical_memory_set_dirty_range(addr, length, dirty_log_mask); } =20 +void memory_region_flush_rom_device(MemoryRegion *mr, hwaddr addr, hwaddr = size) +{ + /* + * In principle this function would work on other memory region types = too, + * but the ROM device use case is the only one where this operation is + * necessary. Other memory regions should use the + * address_space_read/write() APIs. + */ + assert(memory_region_is_romd(mr)); + + invalidate_and_set_dirty(mr, addr, size); +} + static int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr) { unsigned access_size_max =3D mr->ops->valid.max_access_size; --=20 2.20.1