From nobody Sun May 19 07:11:57 2024 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=1585901846; cv=none; d=zohomail.com; s=zohoarc; b=GpQvk6esmGt4PDhjQbkDSwrwGua3fWNUCSqvcLywcpUk7XuTj8KruTPelw9AZ8Y2q0YWnabZLE6obVP77Ju0+P4YKB/qMpSQNY5m49Nw8Pzo8hhxonlhjONcNsGFPKFIMoGi4GlpyG6k4cfKRXI6U115dhm05b3Wh9PJs8VzpgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585901846; 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=ZYqxq9KR6NkWfqFxXwOrk0e3evu8rK7aJSoz1YqsRrM=; b=DbI9QFXzs14dSaol218YVd90GKWDAHmzzWE/CGzPsOBgiIjpexdBoyzm0qkXlFC2nDK5eNvsrl3g3f1wUmwb6k8sJ2LUnZebEA9brSIrSZKdOBuNocmMP2A75yUFCtlFoaxBEruSFelY5wKoeJZOVCqKlywPeUYONRAxG+QZ0DE= 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 1585901846052236.39970201154222; Fri, 3 Apr 2020 01:17:26 -0700 (PDT) Received: from localhost ([::1]:51914 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHW0-0003gh-Pz for importer@patchew.org; Fri, 03 Apr 2020 04:17:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43256) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHOB-0000Gh-CK for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKHOA-0005EE-8v for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:19 -0400 Received: from mga06.intel.com ([134.134.136.31]:40898) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKHOA-0005AA-1H for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:18 -0400 Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Apr 2020 01:09:16 -0700 Received: from dpdk-zhirun.sh.intel.com ([10.67.119.121]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2020 01:09:14 -0700 IronPort-SDR: 3c4DT0r95L3YtVbtrdTUS9ffbocSJSzGf7lqzPlmLEkIm0IVwcJjmMzEjJ7qXR6lY9L8UDOPF8 yiB+jyA6gT2Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: fIS0PF+hklhkYKwVjVhh7AJA5u68tJhTT7NTZjOzr8I3lE0WjxyaHPPYf+kpObmZdAdr/7Oy5T Rcg5gTSF10Sg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,339,1580803200"; d="scan'208";a="449943973" From: Yan Zhao To: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] memory: drop guest writes to read-only ram device regions Date: Fri, 3 Apr 2020 16:59:18 +0000 Message-Id: <20200403165918.20625-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: 134.134.136.31 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" for ram device regions, drop guest writes if the regions is read-only. Signed-off-by: Yan Zhao Signed-off-by: Xin Zeng --- memory.c | 6 +++++- trace-events | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/memory.c b/memory.c index 601b749906..a380b59980 100644 --- a/memory.c +++ b/memory.c @@ -1312,7 +1312,11 @@ static void memory_region_ram_device_write(void *opa= que, hwaddr addr, { MemoryRegion *mr =3D opaque; =20 - trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, = size); + trace_memory_region_ram_device_write(get_cpu_index(), mr, addr, data, + size, mr->readonly); + if (mr->readonly) { + return; + } =20 switch (size) { case 1: diff --git a/trace-events b/trace-events index 42107ebc69..e1de662973 100644 --- a/trace-events +++ b/trace-events @@ -61,7 +61,7 @@ memory_region_ops_write(int cpu_index, void *mr, uint64_t= addr, uint64_t value, memory_region_subpage_read(int cpu_index, void *mr, uint64_t offset, uint6= 4_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx64= " size %u" memory_region_subpage_write(int cpu_index, void *mr, uint64_t offset, uint= 64_t value, unsigned size) "cpu %d mr %p offset 0x%"PRIx64" value 0x%"PRIx6= 4" size %u" memory_region_ram_device_read(int cpu_index, void *mr, uint64_t addr, uint= 64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64"= size %u" -memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uin= t64_t value, unsigned size) "cpu %d mr %p addr 0x%"PRIx64" value 0x%"PRIx64= " size %u" +memory_region_ram_device_write(int cpu_index, void *mr, uint64_t addr, uin= t64_t value, unsigned size, bool readonly) "cpu %d mr %p addr 0x%"PRIx64" v= alue 0x%"PRIx64" size %u" " is_readonly_region=3D%d" flatview_new(void *view, void *root) "%p (root %p)" flatview_destroy(void *view, void *root) "%p (root %p)" flatview_destroy_rcu(void *view, void *root) "%p (root %p)" --=20 2.17.1 From nobody Sun May 19 07:11:57 2024 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=1585901520; cv=none; d=zohomail.com; s=zohoarc; b=RX7hd15TNwFHL2jgJHmBQDW8lcH4tTtxzOdowltsLDThMBRxHcY5LVox2NIpjkoiLBYSb3RjE1MoywoX3FkcdkbArUqiH6RVHGZQzBDdJh9AQ4vTlUtXVThqCea5bd7KJ1ZWGQqC4pEOYZUtvDcNynlPIjXvhX5jndnR+Bw9KfU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585901520; 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=ZFb6NV6v5Rku3UYnptoR3RFSqjdYIz4FEATJsDb5oXs=; b=nb792YbF+GjnJzFCg4JGeuKDxvxJY+amuqtOJtdHLIRIEqmk9HZWC6UnopaFzYlmIk6fcmvMFw3+ZRgOlmR/gafdwLOD0QkoTxvorAERCXneZxMZEvb4fCeOTbEzcvS/u1sE5qn3EgKDJi8RiH/gjkJ9j7Cj4kfo30AX77jPpps= 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 1585901520360214.59218239242193; Fri, 3 Apr 2020 01:12:00 -0700 (PDT) Received: from localhost ([::1]:51818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHQk-0004T1-VA for importer@patchew.org; Fri, 03 Apr 2020 04:11:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43289) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKHOU-0000ua-Ae for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKHOT-0005gH-8r for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:38 -0400 Received: from mga01.intel.com ([192.55.52.88]:21024) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKHOS-0005cT-VM for qemu-devel@nongnu.org; Fri, 03 Apr 2020 04:09:37 -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:33 -0700 Received: from dpdk-zhirun.sh.intel.com ([10.67.119.121]) by fmsmga005.fm.intel.com with ESMTP; 03 Apr 2020 01:09:31 -0700 IronPort-SDR: yXWWt1MUAmpDtNzNsr9MQX0fLpeJKx+gJ3cInbGzxfAaynhDi4LgPKRBmo0gcPmAQ25BP+LZkv 9thRbNpGL+jQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False IronPort-SDR: 5Zolj/Qeuu7/qv/+rfE4AznJe1L42UgCAFgeny6H3BNKCzCyFg8vQIEHmOCCQJ9vksaeAlZIpV A7L7le4ot2Ow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,339,1580803200"; d="scan'208";a="449944029" From: Yan Zhao To: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] hw/vfio: drop guest writes to ro regions Date: Fri, 3 Apr 2020 17:00:24 +0000 Message-Id: <20200403170024.20676-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" for vfio regions that are without write permission, drop guest writes to those regions. Signed-off-by: Yan Zhao Signed-off-by: Xin Zeng --- hw/vfio/common.c | 8 +++++++- hw/vfio/trace-events | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3593b3c0..fd6ee1fe3e 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -190,6 +190,11 @@ void vfio_region_write(void *opaque, hwaddr addr, uint64_t qword; } buf; =20 + if (!(region->flags & VFIO_REGION_INFO_FLAG_WRITE)) { + trace_vfio_region_write(vbasedev->name, region->nr, + addr, data, size, true); + return; + } switch (size) { case 1: buf.byte =3D data; @@ -215,7 +220,8 @@ void vfio_region_write(void *opaque, hwaddr addr, addr, data, size); } =20 - trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size); + trace_vfio_region_write(vbasedev->name, region->nr, addr, data, size, + false); =20 /* * A read or write to a BAR always signals an INTx EOI. This will diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index b1ef55a33f..fb9ff604e6 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -91,7 +91,7 @@ vfio_pci_nvlink2_setup_quirk_ssatgt(const char *name, uin= t64_t tgt, uint64_t siz vfio_pci_nvlink2_setup_quirk_lnkspd(const char *name, uint32_t link_speed)= "%s link_speed=3D0x%x" =20 # common.c -vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)" +vfio_region_write(const char *name, int index, uint64_t addr, uint64_t dat= a, unsigned size, bool readonly) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", = %d)" " is_readonly_region=3D%d." vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint= 64_t data) " (%s:region%d+0x%"PRIx64", %d) =3D 0x%"PRIx64 vfio_iommu_map_notify(const char *op, uint64_t iova_start, uint64_t iova_e= nd) "iommu %s @ 0x%"PRIx64" - 0x%"PRIx64 vfio_listener_region_add_skip(uint64_t start, uint64_t end) "SKIPPING regi= on_add 0x%"PRIx64" - 0x%"PRIx64 --=20 2.17.1 From nobody Sun May 19 07:11:57 2024 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