From nobody Mon Feb 9 19:08:06 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=1585901905; cv=none; d=zohomail.com; s=zohoarc; b=dTSoYyL8jR/ZYl+rdftiXS9meC9vD9HUASbFUfLx6VonYAic9flTC3uGI4CpE74q13n5jrug1Jw7Y/EvXKNqJcwc2sGeOP8Ul4QCM3imiAGjNVfve4klQhY2ZPdecg5f2eo2nCgSutQEgpI2HZUrLwdSt1kXIM2iCslUPda43KY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585901905; 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=kcCaanDA+sYqKw6i/tVPWSRHteOJAjnBPGQ7lsdPUsBNoeXw7UD6zCSRUNTnVjsu1fLgO9tBIL/YGPbi5uu/YeqqyPyO9HonTIntqGz/EcQm6Nr3AT1rIGgZf1vqodnHtMCmW5k+AEAUPrRGSNO5d9Gu2bYvx+S1dUudUKeJUsM= 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 1585901905885969.6889192287182; Fri, 3 Apr 2020 01:18:25 -0700 (PDT) Received: from localhost ([::1]:51920 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHWy-0004eR-Ny for importer@patchew.org; Fri, 03 Apr 2020 04:18:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43356) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHOl-0001Oh-Bx for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKHOk-0006Pv-D8 for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:55 -0400 Received: from mga01.intel.com ([192.55.52.88]:21036) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKHOk-0006M1-4h for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:54 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 01:09:52 -0700 Received: from dpdk-zhirun.sh.intel.com ([10.67.119.121]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2020 01:09:50 -0700 IronPort-SDR: J67euxDIgooOdVQMpjT2vjyhGfaX5kG+Z1DShFymZooq2PR/nrYIsJq+ujtV+myiZrl4VRIGLl SOqk/EGk3jJw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: 3HiTK+8pMLAJobZVQMYY/9qchoDW482vsxwJIG69EvW9CDvFwKtCBKhFhuHccKKbOMDOJM63Qr +LI1KKreJf+Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,339,1580803200"; d="scan'208";a="449944103" From: Yan Zhao To: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] hw/vfio: let read-only flag take effect for mmap'd regions Date: Fri, 3 Apr 2020 17:00:42 +0000 Message-Id: <20200403170042.20723-1-yan.y.zhao@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200403165657.20566-1-yan.y.zhao@intel.com> References: <20200403165657.20566-1-yan.y.zhao@intel.com> X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 192.55.52.88 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 , pbonzini@redhat.com, alex.williamson@redhat.com, philmd@redhat.com, xin.zeng@intel.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 --- 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