From nobody Sat May 18 07:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1620651453; cv=none; d=zohomail.com; s=zohoarc; b=A1zoEu9EFvtx/KvGO2cmPORZCvsz6NQE2hRvH++BvAGK2bkClQ+pro6KxZUzr0QH3u4UVF3VX33+UALC6iRUszRTWEnqpELOReZEOmHPxetTvJoNuhPiflGtC6hvssZJ4HWfcwBgn99lOAuDWCcC66JqtJs34lVjdygBhlHZ3IU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620651453; 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:Reply-To:References:Sender:Subject:To; bh=/whb4UHFFBAbmqCHSx4o6gBfaso5mDsE75tGnWGlfhU=; b=mAdIVCR/P/HWgfES9NLBO88kJTry4E+kog2Jy90h31eld9EmgrsBZ5P1ajRneABcQr/upBeM0Dge0eqdvDYhKrxcD2wjq5QoNymRHOxDILFWMywa3OJ6XpR2hI+CNb0wbgBRknRg9axTi1AoLaqImZH23f/J9Vh5P/6tqGyAMjo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass 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 1620651453520460.77490924160213; Mon, 10 May 2021 05:57:33 -0700 (PDT) Received: from localhost ([::1]:40656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg5TY-00028n-4a for importer@patchew.org; Mon, 10 May 2021 08:57:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Q2-00058h-El for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:54 -0400 Received: from esa2.hc3370-68.iphmx.com ([216.71.145.153]:29307) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Q0-0002LF-Ik for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620651232; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qxnni0A9eL6zKhHtldQizgIwzPgiDEvjSI22O1dRui0=; b=YqUGlJXCjXoh0tFVy1aUSqTzWypJSJC7F/WZFFE3fXy7Wd0EMwJG1pdv kGd3RR6LrbJkyLlq2YLfjY/X4ctRoZLsPXuhDes/sFnbYsq0+zuRYpkHp 6O5izd5+mZfrLPciWjxOy6Ne9yYVN6d52dyNxHD9X79txM+hRDi4sURcO 0=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: PkKXSDtAjaDFOOQRbZn0k9IaLjO3BMQWCnzZ85V1fHRFwePEEdABWzUO+LbkP83ZVQg6tJ8lJs +Q7DZ5yE1JttZ72LgzK2SehRl30S+hCwMW5tWLM/Fklrr989sIkeb3MYw8K7jv+HgzcvDdMTdV fTg7YbsCP42ww1HzOxFW4XZlDRl3YKI0uXLvU+0dGSFzD19slg7IC4Z1FY3sC7WESG3M6xd+Jq NVUE0eAhZ6GT1UNo2A/R/tfQNrLV/dxvgdskWzAne2r3kqUFXWo42h9wHlTvE6xBQHGC83b0+l gN8= X-SBRS: 5.1 X-MesageID: 43429923 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:vHHm6aCSYganiFLlHemq55DYdb4zR+YMi2TC1yhKJiC9Ffbo8P xG/c5rrCMc5wxxZJhNo7290ey7MBHhHP1OkO0s1NWZPDUO0VHAROoJ0WKh+UyEJ8SXzJ866U 4KScZD4bPLYWSS9fyKgzWFLw== X-IronPort-AV: E=Sophos;i="5.82,287,1613451600"; d="scan'208";a="43429923" To: CC: Peter Maydell , Igor Druzhinin , Anthony PERARD Subject: [PULL 1/3] xen-mapcache: avoid a race on memory map while using MAP_FIXED Date: Mon, 10 May 2021 13:53:38 +0100 Message-ID: <20210510125340.903323-2-anthony.perard@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125340.903323-1-anthony.perard@citrix.com> References: <20210510125340.903323-1-anthony.perard@citrix.com> MIME-Version: 1.0 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=216.71.145.153; envelope-from=anthony.perard@citrix.com; helo=esa2.hc3370-68.iphmx.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Anthony PERARD From: Anthony PERARD via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Igor Druzhinin When we're replacing the existing mapping there is possibility of a race on memory map with other threads doing mmap operations - the address being unmapped/re-mapped could be occupied by another thread in between. Linux mmap man page recommends keeping the existing mappings in place to reserve the place and instead utilize the fact that the next mmap operation with MAP_FIXED flag passed will implicitly destroy the existing mappings behind the chosen address. This behavior is guaranteed by POSIX / BSD and therefore is portable. Note that it wouldn't make the replacement atomic for parallel accesses to the replaced region - those might still fail with SIGBUS due to xenforeignmemory_map not being atomic. So we're still not expecting those. Tested-by: Anthony PERARD Signed-off-by: Igor Druzhinin Reviewed-by: Paul Durrant Message-Id: <1618889702-13104-1-git-send-email-igor.druzhinin@citrix.com> Signed-off-by: Anthony PERARD --- hw/i386/xen/xen-mapcache.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/hw/i386/xen/xen-mapcache.c b/hw/i386/xen/xen-mapcache.c index 5b120ed44b..e82b7dcdd2 100644 --- a/hw/i386/xen/xen-mapcache.c +++ b/hw/i386/xen/xen-mapcache.c @@ -171,7 +171,20 @@ static void xen_remap_bucket(MapCacheEntry *entry, if (!(entry->flags & XEN_MAPCACHE_ENTRY_DUMMY)) { ram_block_notify_remove(entry->vaddr_base, entry->size); } - if (munmap(entry->vaddr_base, entry->size) !=3D 0) { + + /* + * If an entry is being replaced by another mapping and we're using + * MAP_FIXED flag for it - there is possibility of a race for vaddr + * address with another thread doing an mmap call itself + * (see man 2 mmap). To avoid that we skip explicit unmapping here + * and allow the kernel to destroy the previous mappings by replac= ing + * them in mmap call later. + * + * Non-identical replacements are not allowed therefore. + */ + assert(!vaddr || (entry->vaddr_base =3D=3D vaddr && entry->size = =3D=3D size)); + + if (!vaddr && munmap(entry->vaddr_base, entry->size) !=3D 0) { perror("unmap fails"); exit(-1); } --=20 Anthony PERARD From nobody Sat May 18 07:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1620651346; cv=none; d=zohomail.com; s=zohoarc; b=Pt3SQ5yO7BPdz0r4ClUD/hRKAfEY0M4ByD3dx+AMwJzBHi0PLJyuqUCfBA5f7sgbDEuXm33w/4Eal3GBXTR0RAm+l8nCr39WVIx3cZV+G1KPyjywspVe2Hp5uckXSmMc4Js6XxIT1iuE0jEKJElOIIKOB/i5Vi0y2pquYcmOMXM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620651346; 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:Reply-To:References:Sender:Subject:To; bh=clRhRaSi5biwnPn5WZ+o0YvNXpE6o1CNp26Y7O+CBAo=; b=BNajvv+CuV6fiVpbnvhteK+lBAUrL4NSO+jgBQ/mBmHZfhUk0/cL63VI5qdvFLIsU/R/aQZnEXgj8YWwh/1TDLXUFUy174oCRHnHgCYN/fw1DRPE5GB4dd5pX6GxrGAJuY3FgEqqD41/5sflzmlXqzUehcpJMR+xths9geItziE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass 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 1620651346558231.39655889197184; Mon, 10 May 2021 05:55:46 -0700 (PDT) Received: from localhost ([::1]:36108 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg5Rp-0007Rj-A2 for importer@patchew.org; Mon, 10 May 2021 08:55:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Q0-00054H-NO for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:52 -0400 Received: from esa5.hc3370-68.iphmx.com ([216.71.155.168]:62940) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Py-0002LK-T6 for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620651230; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=luRpTb3ZsBRtDzz5jNYYhXTNfJ+3+seFm54k7RxAH0M=; b=IorLLTvDXUpbF0Ql5u29kswnjtPYSnQBFgLMYFyLHMtjvZhMBQ1jNKFw +mLWefwN4VaaOR2SdpQqNatDivPdzptwNnvwQq//UuNdHZqzYSd1XBed3 Ds6zBsYMbL5huZbA4cF2JWYa0X+ypovyOFTD6v+0/zIsn42xs98rAp9Xc E=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: OZiHAEwjijUrvENaT0OVXNjp8reLCAPLGcQq2ThmZQ9HvuA17R+pyRpzvMPLLSpz8eh57ScLAN bqgJ97t6/2vcQmFdLB+eNFw98/a0u2iCnUOsb2En0X0fW368MjXM3+t28Bhclxq4WZ4nMSK2df jkFCyj5hrILAX2+mk09a4ldk0RelqiHTSFgNw9WxlEt4yLuY3h73XYBtBIycOizkHGyle6ilfB bttJjX3ooVdfodNJPeTnFyKF3bOPBEi+NC4yOviQSR3hIjt7ITTDyjbU5VoD7WqKKgF8XGXMPE CEM= X-SBRS: 5.1 X-MesageID: 43235992 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:jfQ64ao9RTgVVkZ3T51Q2FMaV5oteYIsimQD101hICG8cqSj+P xG+85rsiMc6QxhIU3I9urgBEDtex7hHNtOkOss1NSZLW3bUQmTTL2KhLGKq1aLJ8S9zJ856U 4JSdkZNDSaNzZHZKjBjDVQa+xQo+W6zA== X-IronPort-AV: E=Sophos;i="5.82,287,1613451600"; d="scan'208";a="43235992" To: CC: Peter Maydell , Anthony PERARD Subject: [PULL 2/3] xen: Free xenforeignmemory_resource at exit Date: Mon, 10 May 2021 13:53:39 +0100 Message-ID: <20210510125340.903323-3-anthony.perard@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125340.903323-1-anthony.perard@citrix.com> References: <20210510125340.903323-1-anthony.perard@citrix.com> MIME-Version: 1.0 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=216.71.155.168; envelope-from=anthony.perard@citrix.com; helo=esa5.hc3370-68.iphmx.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Anthony PERARD From: Anthony PERARD via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Because Coverity complains about it and this is one leak that Valgrind reports. Signed-off-by: Anthony PERARD Acked-by: Paul Durrant Message-Id: <20210430163742.469739-1-anthony.perard@citrix.com> Signed-off-by: Anthony PERARD --- hw/i386/xen/xen-hvm.c | 9 ++++++--- include/hw/xen/xen_common.h | 6 ++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index c53fa17c50..9b432773f0 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -108,6 +108,7 @@ typedef struct XenIOState { shared_iopage_t *shared_page; shared_vmport_iopage_t *shared_vmport_page; buffered_iopage_t *buffered_io_page; + xenforeignmemory_resource_handle *fres; QEMUTimer *buffered_io_timer; CPUState **cpu_by_vcpu_id; /* the evtchn port for polling the notification, */ @@ -1253,6 +1254,9 @@ static void xen_exit_notifier(Notifier *n, void *data) XenIOState *state =3D container_of(n, XenIOState, exit); =20 xen_destroy_ioreq_server(xen_domid, state->ioservid); + if (state->fres !=3D NULL) { + xenforeignmemory_unmap_resource(xen_fmem, state->fres); + } =20 xenevtchn_close(state->xce_handle); xs_daemon_close(state->xenstore); @@ -1320,7 +1324,6 @@ static void xen_wakeup_notifier(Notifier *notifier, v= oid *data) static int xen_map_ioreq_server(XenIOState *state) { void *addr =3D NULL; - xenforeignmemory_resource_handle *fres; xen_pfn_t ioreq_pfn; xen_pfn_t bufioreq_pfn; evtchn_port_t bufioreq_evtchn; @@ -1332,12 +1335,12 @@ static int xen_map_ioreq_server(XenIOState *state) */ QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_bufioreq !=3D 0); QEMU_BUILD_BUG_ON(XENMEM_resource_ioreq_server_frame_ioreq(0) !=3D 1); - fres =3D xenforeignmemory_map_resource(xen_fmem, xen_domid, + state->fres =3D xenforeignmemory_map_resource(xen_fmem, xen_domid, XENMEM_resource_ioreq_server, state->ioservid, 0, 2, &addr, PROT_READ | PROT_WRITE, 0); - if (fres !=3D NULL) { + if (state->fres !=3D NULL) { trace_xen_map_resource_ioreq(state->ioservid, addr); state->buffered_io_page =3D addr; state->shared_page =3D addr + TARGET_PAGE_SIZE; diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 82e56339dd..a8118b41ac 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -134,6 +134,12 @@ static inline xenforeignmemory_resource_handle *xenfor= eignmemory_map_resource( return NULL; } =20 +static inline int xenforeignmemory_unmap_resource( + xenforeignmemory_handle *fmem, xenforeignmemory_resource_handle *fres) +{ + return 0; +} + #endif /* CONFIG_XEN_CTRL_INTERFACE_VERSION < 41100 */ =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 41000 --=20 Anthony PERARD From nobody Sat May 18 07:48:42 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1620651350; cv=none; d=zohomail.com; s=zohoarc; b=VSmvdQ2USZocAnsW2ugvCqHU2Jpio3xFf/5mIhkSP+hr+Jjsb+smIeV55dkcRUnqpoFrp2qlSnmkzFRjb3xoTvQykUMXZISM1hPYcTUQvo+kxp4khbkm0VaAvPLR6ZH5GBdZMKYrSuvE3iXHskMpoaKhsr90nBE8Z8lhYMwEA1E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620651350; 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:Reply-To:References:Sender:Subject:To; bh=GN/kNbjLSrMq1sfzet41HvG4noBsA+KXJ2GsHC0IYa0=; b=YdCaCwQlmtHJNMdi6R1AVekEJF/sE0svoWTkypqAsohiiRvy8aaRrjTlk8JuKNx8OCemYkx5568h8MO/18rd6XNCDk81Fe4deK0W7hs1xSQCwytTsLd3znMXsepne/ak7G+yiZylvIYkHV75/p8fxvJnwDSqG6BiwyOK7CkRoJw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass 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 1620651350261510.2779843798065; Mon, 10 May 2021 05:55:50 -0700 (PDT) Received: from localhost ([::1]:36380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lg5Rt-0007cj-5r for importer@patchew.org; Mon, 10 May 2021 08:55:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Q3-0005DG-Vi for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:56 -0400 Received: from esa6.hc3370-68.iphmx.com ([216.71.155.175]:9497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lg5Q2-0002OX-6Y for qemu-devel@nongnu.org; Mon, 10 May 2021 08:53:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1620651233; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u4QGM8/JFq+CXqBDhAUitCiWNGljacYz2VCNiGxaiPY=; b=I5mUOPRpSOHnEMmAmbCIzzlFLUpMqHENaXtaDhpggJzKd2RGToQJZXKT NWjJATCpdIq6iWj93xU2UdWi5kSeOGgwSgErJE30vQE/i1KarPZsB5fSN 8HzeK6HhlRGaibyFTyeWXDHdbOpUaejlr+FkCuOXCw0Xh+kp5OXxdx/zS k=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 7Z7gFGls+YTIeR9dHAOqE4/5OSsDGOG0IlwKFfX8QrI346t3wTpVuo0vXGmaWOIO8u0fDtaj6C yRk2urRe3DrKpumAyPYRMogiFUujHezMkQFD1hVpxFRl9KyqGl5IUnTacPZ7C2dqeJ1Z9S0Gxm D/7M6zlH5CpYW8xWExaRXKXgY6qRxN7/AMKQO9TrVbghfR+hrbw/RfYleW9jCvaWCFNKg0UOWR 7XJS8QDlNeQsHgHYADlI2IsmYLMQxPy9x3jKRPFHIIqYm7LD+oV2/LnyHZ6TTVh5GYdt0EH+er MUQ= X-SBRS: 5.1 X-MesageID: 43545480 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:+cRTKK3RqBeITaDSvZmXgQqjBIokLtp133Aq2lEZdPRUGvb3qy nIpoV86faUskdoZJhOo7C90cW7LU80sKQFhLX5Xo3SOzUO2lHYT72KhLGKq1aLdhEWtNQtsZ uIG5IOceEYZmIasS+V2maF+q4bsbu6zJw= X-IronPort-AV: E=Sophos;i="5.82,287,1613451600"; d="scan'208";a="43545480" To: CC: Peter Maydell , Anthony PERARD Subject: [PULL 3/3] xen-block: Use specific blockdev driver Date: Mon, 10 May 2021 13:53:40 +0100 Message-ID: <20210510125340.903323-4-anthony.perard@citrix.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510125340.903323-1-anthony.perard@citrix.com> References: <20210510125340.903323-1-anthony.perard@citrix.com> MIME-Version: 1.0 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=216.71.155.175; envelope-from=anthony.perard@citrix.com; helo=esa6.hc3370-68.iphmx.com X-Spam_score_int: -50 X-Spam_score: -5.1 X-Spam_bar: ----- X-Spam_report: (-5.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.698, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Anthony PERARD From: Anthony PERARD via X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" ... when a xen-block backend instance is created via xenstore. Following 8d17adf34f50 ("block: remove support for using "file" driver with block/char devices"), using the "file" blockdev driver for everything doesn't work anymore, we need to use the "host_device" driver when the disk image is a block device and "file" driver when it is a regular file. Signed-off-by: Anthony PERARD Acked-by: Paul Durrant Message-Id: <20210430163432.468894-1-anthony.perard@citrix.com> Signed-off-by: Anthony PERARD --- hw/block/xen-block.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/hw/block/xen-block.c b/hw/block/xen-block.c index 83754a4344..674953f1ad 100644 --- a/hw/block/xen-block.c +++ b/hw/block/xen-block.c @@ -728,6 +728,8 @@ static XenBlockDrive *xen_block_drive_create(const char= *id, XenBlockDrive *drive =3D NULL; QDict *file_layer; QDict *driver_layer; + struct stat st; + int rc; =20 if (params) { char **v =3D g_strsplit(params, ":", 2); @@ -761,7 +763,17 @@ static XenBlockDrive *xen_block_drive_create(const cha= r *id, file_layer =3D qdict_new(); driver_layer =3D qdict_new(); =20 - qdict_put_str(file_layer, "driver", "file"); + rc =3D stat(filename, &st); + if (rc) { + error_setg_errno(errp, errno, "Could not stat file '%s'", filename= ); + goto done; + } + if (S_ISBLK(st.st_mode)) { + qdict_put_str(file_layer, "driver", "host_device"); + } else { + qdict_put_str(file_layer, "driver", "file"); + } + qdict_put_str(file_layer, "filename", filename); g_free(filename); =20 --=20 Anthony PERARD