From nobody Sun Feb 8 15:10:34 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.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=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1588224605; cv=none; d=zohomail.com; s=zohoarc; b=NdAEUINyF/qWk7x62rY8uEwFzpmj06VGHfhEPiQ+0g7MgrG/iDP65p8UfW3G6MUAr/9vXxVwMcfSgMKH0kWHs2zdSAgU1cnqliPF98V2mt0HHPtZS3suJikWT0Ap3HwoPEowVYhe2qC6Lki91AxpVbRbPsMVhYNMkMFt9gGYZ4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588224605; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=UucWAPVfDh41I7Du6Zo0Qz+ylcDABbcWIjSQuvfK8tU=; b=kwWmt1OM5RqsRPwOAjGFSl3NhJq8MdOunxwtHBTrAGETpprIxwb/fnUfuvSXkxg2Yp7jIoKfny57ujpMpsYY9lcwS+cyYUy0nYTUTVYOzyOlsdYFIhJb8L5NvwPMWPdbdHfK8MO6FkeeNjoYaNsnjUtGltVw0sQOVc3emaPDmYo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1588224605105497.1359885916264; Wed, 29 Apr 2020 22:30:05 -0700 (PDT) Received: from localhost ([::1]:37780 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU1lr-0003yW-G0 for importer@patchew.org; Thu, 30 Apr 2020 01:30:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53216) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jU1lH-0003Ti-OD for qemu-devel@nongnu.org; Thu, 30 Apr 2020 01:29:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jU1lH-00028I-9u for qemu-devel@nongnu.org; Thu, 30 Apr 2020 01:29:27 -0400 Received: from mga18.intel.com ([134.134.136.126]:48100) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jU1lG-00028B-PT for qemu-devel@nongnu.org; Thu, 30 Apr 2020 01:29:26 -0400 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Apr 2020 22:29:25 -0700 Received: from joy-optiplex-7040.sh.intel.com ([10.239.13.16]) by fmsmga008.fm.intel.com with ESMTP; 29 Apr 2020 22:29:23 -0700 IronPort-SDR: hcZrCMAzQxXz8+EcMmr0ME/9uKYeKGoRAh/uVbwLT4EokG63aN2YXWcq8cMqyLQ22s4MTxmY3y RL1w79+q+ZIA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: Xv52D3rETX74P8CJw1CHMA0xPGqIKq4I/9uPlXTE/k97zSSoAykr/vkXWGiytgLtjGLJdz7qi9 xlW0sg2AAo8w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,334,1583222400"; d="scan'208";a="249649344" From: Yan Zhao To: pbonzini@redhat.com, alex.williamson@redhat.com Subject: [PATCH v5 1/3] memory: drop guest writes to read-only ram device regions Date: Thu, 30 Apr 2020 01:19:23 -0400 Message-Id: <20200430051923.29159-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200430051558.28991-1-yan.y.zhao@intel.com> References: <20200430051558.28991-1-yan.y.zhao@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=134.134.136.126; envelope-from=yan.y.zhao@intel.com; helo=mga18.intel.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/29 23:42:54 X-ACL-Warn: Detected OS = FreeBSD 9.x or newer [fuzzy] X-Received-From: 134.134.136.126 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: Yan Zhao , xin.zeng@intel.com, philmd@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" for ram device regions, drop guest writes if the regions is read-only. Cc: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Yan Zhao Signed-off-by: Xin Zeng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- memory.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/memory.c b/memory.c index 601b749906..90a748912f 100644 --- a/memory.c +++ b/memory.c @@ -34,6 +34,7 @@ #include "sysemu/accel.h" #include "hw/boards.h" #include "migration/vmstate.h" +#include "qemu/log.h" =20 //#define DEBUG_UNASSIGNED =20 @@ -1307,12 +1308,19 @@ static uint64_t memory_region_ram_device_read(void = *opaque, return data; } =20 -static void memory_region_ram_device_write(void *opaque, hwaddr addr, - uint64_t data, unsigned size) +static MemTxResult memory_region_ram_device_write(void *opaque, hwaddr add= r, + uint64_t data, unsigned size, + MemTxAttrs attrs) { MemoryRegion *mr =3D opaque; =20 trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, = size); + if (mr->readonly) { + qemu_log_mask(LOG_GUEST_ERROR, + "Invalid write to read only ram device region addr 0= x%" + HWADDR_PRIx" size %u\n", addr, size); + return MEMTX_ERROR; + } =20 switch (size) { case 1: @@ -1328,11 +1336,12 @@ static void memory_region_ram_device_write(void *op= aque, hwaddr addr, *(uint64_t *)(mr->ram_block->host + addr) =3D data; break; } + return MEMTX_OK; } =20 static const MemoryRegionOps ram_device_mem_ops =3D { .read =3D memory_region_ram_device_read, - .write =3D memory_region_ram_device_write, + .write_with_attrs =3D memory_region_ram_device_write, .endianness =3D DEVICE_HOST_ENDIAN, .valid =3D { .min_access_size =3D 1, --=20 2.17.1