From nobody Mon Feb 9 20:34:51 2026 Delivered-To: importer@patchew.org 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; 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=1586760039; cv=none; d=zohomail.com; s=zohoarc; b=NI2XTHdMt/YzLUPDB8+hPdz4+t1YFzY/jhRxehSo9bKpm/Kex7dEOv/UCx21uC3+MoM7uYp1M+xU9NDzn2KvhOgyUaZkvH5OaD0Ko01zOQsS+FAjdAesl7OVF9TFBDn3pb1QH39Fdc+dsi4LdwTK9GV6amyG5YWOaL8ud3WxnHc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586760039; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=muE+GBHrD8IRysa6OXnA5AfaUojmatYCYigHasizPvk=; b=bYJbp5+vZJzDO1fCIQAl42pfEXaMurEKrtDd3PzsdQWLk54EGbWOg63942tv/Nw2r7XuWMBrPDpLRcs+i3xBUGSWyzCaBRYDkeMG1BsTEutkz/nlmqcOIOY+IcgZrGdUfBQpm9Icef7PgB6H4gifD63mp3eTpoXoOiYj99G/pAA= 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 1586760039856912.1902507958878; Sun, 12 Apr 2020 23:40:39 -0700 (PDT) Received: from localhost ([::1]:40884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNslq-0005zE-LZ for importer@patchew.org; Mon, 13 Apr 2020 02:40:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33215) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jNskG-0003tD-7j for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:39:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jNskF-0006oh-94 for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:39:00 -0400 Received: from mga02.intel.com ([134.134.136.20]:22314) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jNskF-0006oV-1l for qemu-devel@nongnu.org; Mon, 13 Apr 2020 02:38:59 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2020 23:38:58 -0700 Received: from dpdk-zhirun.sh.intel.com ([10.67.119.121]) by fmsmga005.fm.intel.com with ESMTP; 12 Apr 2020 23:38:56 -0700 IronPort-SDR: MUgPNdSCkMn8RcPtjgAvzonZSDxQTiY4xhJDT6aVlszQThC/hDarRAF+EVopL5Wt47UkFVPUc6 6Xda78/h9phA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: e0Egk4H0cnnSkK68El48wiEPxDbxl+nT5PgLWwkjr3HJ4VSD/UX6l4cpG5xonVa1qhdTfJs5pO QcJ93h7/N/bg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,377,1580803200"; d="scan'208";a="453062368" From: Yan Zhao To: qemu-devel@nongnu.org Subject: [PATCH v3 3/3] hw/vfio: let read-only flag take effect for mmap'd regions Date: Mon, 13 Apr 2020 06:37:47 +0000 Message-Id: <20200413063747.84753-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200413063627.84608-1-yan.y.zhao@intel.com> References: <20200413063627.84608-1-yan.y.zhao@intel.com> X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 134.134.136.20 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 , alex.williamson@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, philmd@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" along side setting host page table to be read-only, the memory regions are also required to be read-only, so that when guest writes to the read-only & mmap'd regions, vmexits would happen and region write handlers are called. Signed-off-by: Yan Zhao Signed-off-by: Xin Zeng Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- hw/vfio/common.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index fd6ee1fe3e..fc7618e041 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -977,6 +977,10 @@ int vfio_region_mmap(VFIORegion *region) name, region->mmaps[i].size, region->mmaps[i].mmap); g_free(name); + + if (!(region->flags & VFIO_REGION_INFO_FLAG_WRITE)) { + memory_region_set_readonly(®ion->mmaps[i].mem, true); + } memory_region_add_subregion(region->mem, region->mmaps[i].offset, ®ion->mmaps[i].mem); =20 --=20 2.17.1