From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527014946519605.6717853602629; Tue, 22 May 2018 11:49:06 -0700 (PDT) Received: from localhost ([::1]:57340 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCLJ-0002mj-HT for importer@patchew.org; Tue, 22 May 2018 14:49:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50643) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ3-0001cB-IB for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ2-0007PK-PG for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:43466) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ2-0007P3-Ia for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:44 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5AEA320853; Tue, 22 May 2018 18:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014803; bh=YB2xo8vHcGc0E18k1A9vX6DC7vcYpVBmtk5QHxxrK6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nqSXebjxkyvHhuHanmCkbXc/X9/xLeLAXxd766hKfXnPiXIh282HlSqLAQ2RGnVa1 SOS1Y26s62PB5cxXtur+CsExuJoD2pzE8U+U6TGRF6l5mWGzUMWAK9NaCHwa97O8TF c9lMzMhS1hxDtFr8fk/10eGjPdmXykcp8KpSlPBs= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:28 -0700 Message-Id: <1527014802-11289-1-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 01/15] xen-pvdevice: Introduce a simplistic xen-pvdevice save state X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Igor Druzhinin This should help to avoid problems with accessing the device after migration/resume without PV drivers by migrating its PCI configuration space state. Without an explicitly defined state record it resets every time a VM migrates which confuses the OS and makes every access to xen-pvdevice MMIO region to fail. PV tools enable some logic to save and restore PCI configuration state from within the VM every time it migrates which basically hides the issue. Older systems will acquire the new record when migrated which should not change their state for worse. Signed-off-by: Igor Druzhinin Reviewed-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/i386/xen/xen_pvdevice.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hw/i386/xen/xen_pvdevice.c b/hw/i386/xen/xen_pvdevice.c index f748823..a146f18 100644 --- a/hw/i386/xen/xen_pvdevice.c +++ b/hw/i386/xen/xen_pvdevice.c @@ -71,6 +71,16 @@ static const MemoryRegionOps xen_pv_mmio_ops =3D { .endianness =3D DEVICE_LITTLE_ENDIAN, }; =20 +static const VMStateDescription vmstate_xen_pvdevice =3D { + .name =3D "xen-pvdevice", + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_PCI_DEVICE(parent_obj, XenPVDevice), + VMSTATE_END_OF_LIST() + } +}; + static void xen_pv_realize(PCIDevice *pci_dev, Error **errp) { XenPVDevice *d =3D XEN_PV_DEVICE(pci_dev); @@ -120,6 +130,7 @@ static void xen_pv_class_init(ObjectClass *klass, void = *data) k->class_id =3D PCI_CLASS_SYSTEM_OTHER; dc->desc =3D "Xen PV Device"; dc->props =3D xen_pv_props; + dc->vmsd =3D &vmstate_xen_pvdevice; } =20 static const TypeInfo xen_pv_type_info =3D { --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527014954260848.3994903266854; Tue, 22 May 2018 11:49:14 -0700 (PDT) Received: from localhost ([::1]:57341 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCLR-0002rP-Dm for importer@patchew.org; Tue, 22 May 2018 14:49:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50652) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ3-0001cC-UV for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ3-0007PV-5R for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43482) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ2-0007PC-Rt for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:45 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B76AD20877; Tue, 22 May 2018 18:46:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014803; bh=tvSsNV6460Ks3ytomtQ+nElWnvsRYBQAfjHMVlOQ+bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VE+agr7NyT/mMJEerAMMRv8xHFtY5yjj8mJHsQacUccPfDeH7C3cnG6PQtl8NB5IT vakGW0cYa+PqaVtbiID8+TqI7Q8D2zeAdQAs/7rHL412QiT9icI/zZg57FEOufXWT9 RryZBP2271/tcXVRi7OtNGf0zotynparAKUNxIj0= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:29 -0700 Message-Id: <1527014802-11289-2-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 02/15] xen/pt: use address_space_memory object for memory region hooks X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Igor Druzhinin , sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Igor Druzhinin Commit 99605175c (xen-pt: Fix PCI devices re-attach failed) introduced a subtle bug. As soon as the guest switches off Bus Mastering on the device it immediately causes all the BARs be unmapped due to the DMA address space of the device being changed. This is undesired behavior because the guest may try to communicate with the device after that which triggers the following errors in the logs: [00:05.0] xen_pt_bar_read: Error: Should not read BAR through QEMU. @0x0000= 000000000200 [00:05.0] xen_pt_bar_write: Error: Should not write BAR through QEMU. @0x00= 00000000000200 The issue that the original patch tried to workaround (uneven number of region_add/del calls on device attach/detach) was fixed in d25836cafd (memory: do explicit cleanup when remove listeners). Signed-off-by: Igor Druzhinin Reported-by: Ross Lagerwall Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/xen/xen_pt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 9b7a960..e5a6eff 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -907,7 +907,7 @@ out: } } =20 - memory_listener_register(&s->memory_listener, &s->dev.bus_master_as); + memory_listener_register(&s->memory_listener, &address_space_memory); memory_listener_register(&s->io_listener, &address_space_io); s->listener_set =3D true; XEN_PT_LOG(d, --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015117513783.9398839644849; Tue, 22 May 2018 11:51:57 -0700 (PDT) Received: from localhost ([::1]:57357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCO4-000543-Kx for importer@patchew.org; Tue, 22 May 2018 14:51:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ4-0001cD-2i for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ3-0007Pf-GO for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ3-0007PE-An for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:45 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1990920878; Tue, 22 May 2018 18:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014804; bh=/A9QtItFP0SbLQF54MIhQgS1gF4my0qJl4hYIoWw8IM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bZzzJVdN7q+pzB9Ce7Aafr3m9nPpTI0MxjKcEniGp7GqYFCrf3B3TVEc/TrDZat+p aiuRa9vcYRNvvllo97sd/wvlHCucfap41ETnu79NjtkH51HBrBDEtr32oadqZVatyU Lo9oFyn/sdFRAMQYzYrZGCW4Ab+jbnHcAsallI5Q= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:30 -0700 Message-Id: <1527014802-11289-3-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 03/15] configure: Add explanation for --enable-xen-pci-passthrough X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: anthony.perard@citrix.com, xen-devel@lists.xenproject.org, sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Anthony PERARD Signed-off-by: Anthony PERARD Reviewed-by: Markus Armbruster Signed-off-by: Stefano Stabellini --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 59f91ab..a8498ab 100755 --- a/configure +++ b/configure @@ -1588,7 +1588,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: virtfs VirtFS mpath Multipath persistent reservation passthrough xen xen backend driver support - xen-pci-passthrough + xen-pci-passthrough PCI passthrough support for Xen brlapi BrlAPI (Braile) curl curl connectivity membarrier membarrier system call (for Linux 4.14+ or Windows) --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 152701528513361.9605221326691; Tue, 22 May 2018 11:54:45 -0700 (PDT) Received: from localhost ([::1]:57369 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCQg-0007K5-FN for importer@patchew.org; Tue, 22 May 2018 14:54:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ4-0001cF-Jl for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ3-0007Pw-Ok for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:43518) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ3-0007PP-JP for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:45 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6C8A520879; Tue, 22 May 2018 18:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014804; bh=+W8v3gBGrc/kRije4LYyHDcMDjAEk0ozR3iAS++0jRc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TknDxtj+KWScP80rlVj1diQlkXBSvDDz12KfRjT/B0wY5BVC4w+bzPdOMeL8aqPe7 qexY8wqVfRF9g17+Ei4R6JwiIp7DcVs26E2emMZubX/oUHO08lW+mVspGjCyiMhBOD bBnLo/QPzaq3OyezjZ4CHtqZx42IUm5v4H6/jOEI= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:31 -0700 Message-Id: <1527014802-11289-4-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 04/15] xen_pt: Present the size of 64 bit BARs correctly X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Ross Lagerwall , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ross Lagerwall The full size of the BAR is stored in the lower PCIIORegion.size. The upper PCIIORegion.size is 0. Calculate the size of the upper half correctly from the lower half otherwise the size read by the guest will be incorrect. Signed-off-by: Ross Lagerwall Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/xen/xen_pt_config_init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/xen/xen_pt_config_init.c b/hw/xen/xen_pt_config_init.c index a3ce33e..aee31c6 100644 --- a/hw/xen/xen_pt_config_init.c +++ b/hw/xen/xen_pt_config_init.c @@ -504,6 +504,8 @@ static int xen_pt_bar_reg_write(XenPCIPassthroughState = *s, XenPTReg *cfg_entry, bar_ro_mask =3D XEN_PT_BAR_IO_RO_MASK | (r_size - 1); break; case XEN_PT_BAR_FLAG_UPPER: + assert(index > 0); + r_size =3D d->io_regions[index - 1].size >> 32; bar_emu_mask =3D XEN_PT_BAR_ALLF; bar_ro_mask =3D r_size ? r_size - 1 : 0; break; --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015293316798.0508924956873; Tue, 22 May 2018 11:54:53 -0700 (PDT) Received: from localhost ([::1]:57372 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCQu-0007Uy-Ht for importer@patchew.org; Tue, 22 May 2018 14:54:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50745) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fB-1l for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ4-0007QG-4I for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43526) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ3-0007Pa-Sm for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C3F0D2087A; Tue, 22 May 2018 18:46:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014805; bh=IU0WlyPP3F1/98iiHEzAhgipc4jvJBwBB1LgwntFpKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e/v5oQo8nZuFFWq6WlQmo76wf4szyhswl6MMRPg7LjMEs5m3hwVjd00lE4E3x3PmZ Ol8qz2pn24ulnXqKiEdnp+Fxk1+V1CVvIPKmgFYVk55Btnz/kIeI069daTUi3MoyDu x85kmgbpVYGY7OiyXAXnRDjs3SQGTbtgZ3DXobDA= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:32 -0700 Message-Id: <1527014802-11289-5-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 05/15] xen-hvm: create separate function for ioreq server initialization X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant The code is sufficiently substantial that it improves code readability to put it in a new function called by xen_hvm_init() rather than having it inline. Signed-off-by: Paul Durrant Reviewed-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/i386/xen/xen-hvm.c | 76 +++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/hw/i386/xen/xen-hvm.c b/hw/i386/xen/xen-hvm.c index caa563b..6ffa3c2 100644 --- a/hw/i386/xen/xen-hvm.c +++ b/hw/i386/xen/xen-hvm.c @@ -95,7 +95,8 @@ typedef struct XenIOState { CPUState **cpu_by_vcpu_id; /* the evtchn port for polling the notification, */ evtchn_port_t *ioreq_local_port; - /* evtchn local port for buffered io */ + /* evtchn remote and local ports for buffered io */ + evtchn_port_t bufioreq_remote_port; evtchn_port_t bufioreq_local_port; /* the evtchn fd for polling */ xenevtchn_handle *xce_handle; @@ -1236,12 +1237,52 @@ static void xen_wakeup_notifier(Notifier *notifier,= void *data) xc_set_hvm_param(xen_xc, xen_domid, HVM_PARAM_ACPI_S_STATE, 0); } =20 -void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) +static int xen_map_ioreq_server(XenIOState *state) { - int i, rc; xen_pfn_t ioreq_pfn; xen_pfn_t bufioreq_pfn; evtchn_port_t bufioreq_evtchn; + int rc; + + rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, + &ioreq_pfn, &bufioreq_pfn, + &bufioreq_evtchn); + if (rc < 0) { + error_report("failed to get ioreq server info: error %d handle=3D%= p", + errno, xen_xc); + return rc; + } + + DPRINTF("shared page at pfn %lx\n", ioreq_pfn); + DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); + DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); + + state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &ioreq_pfn, NULL); + if (state->shared_page =3D=3D NULL) { + error_report("map shared IO page returned error %d handle=3D%p", + errno, xen_xc); + return -1; + } + + state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_domid, + PROT_READ | PROT_WRITE, + 1, &bufioreq_pfn, NULL); + if (state->buffered_io_page =3D=3D NULL) { + error_report("map buffered IO page returned error %d", errno); + return -1; + } + + state->bufioreq_remote_port =3D bufioreq_evtchn; + + return 0; +} + +void xen_hvm_init(PCMachineState *pcms, MemoryRegion **ram_memory) +{ + int i, rc; + xen_pfn_t ioreq_pfn; XenIOState *state; =20 state =3D g_malloc0(sizeof (XenIOState)); @@ -1269,25 +1310,8 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) state->wakeup.notify =3D xen_wakeup_notifier; qemu_register_wakeup_notifier(&state->wakeup); =20 - rc =3D xen_get_ioreq_server_info(xen_domid, state->ioservid, - &ioreq_pfn, &bufioreq_pfn, - &bufioreq_evtchn); + rc =3D xen_map_ioreq_server(state); if (rc < 0) { - error_report("failed to get ioreq server info: error %d handle=3D%= p", - errno, xen_xc); - goto err; - } - - DPRINTF("shared page at pfn %lx\n", ioreq_pfn); - DPRINTF("buffered io page at pfn %lx\n", bufioreq_pfn); - DPRINTF("buffered io evtchn is %x\n", bufioreq_evtchn); - - state->shared_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ|PROT_WRITE, - 1, &ioreq_pfn, NULL); - if (state->shared_page =3D=3D NULL) { - error_report("map shared IO page returned error %d handle=3D%p", - errno, xen_xc); goto err; } =20 @@ -1308,14 +1332,6 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion= **ram_memory) goto err; } =20 - state->buffered_io_page =3D xenforeignmemory_map(xen_fmem, xen_domid, - PROT_READ|PROT_WRITE, - 1, &bufioreq_pfn, NULL); - if (state->buffered_io_page =3D=3D NULL) { - error_report("map buffered IO page returned error %d", errno); - goto err; - } - /* Note: cpus is empty at this point in init */ state->cpu_by_vcpu_id =3D g_malloc0(max_cpus * sizeof(CPUState *)); =20 @@ -1340,7 +1356,7 @@ void xen_hvm_init(PCMachineState *pcms, MemoryRegion = **ram_memory) } =20 rc =3D xenevtchn_bind_interdomain(state->xce_handle, xen_domid, - bufioreq_evtchn); + state->bufioreq_remote_port); if (rc =3D=3D -1) { error_report("buffered evtchn bind error %d", errno); goto err; --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015285237652.402993157984; Tue, 22 May 2018 11:54:45 -0700 (PDT) Received: from localhost ([::1]:57371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCQk-0007O9-N4 for importer@patchew.org; Tue, 22 May 2018 14:54:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fH-3u for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ4-0007QU-BY for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43546) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ4-0007Pn-5r for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 243D82087B; Tue, 22 May 2018 18:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014805; bh=nPsPVsTdrewqt5Ubuzz6BTPrmPzJzlU5C9GEiqdDW3E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Lg54SEDXEcOxEeVNBwDPCyFsPjOPFeJrQGPkvt8Wx1VJ54L9H5qwGHIqtzfL+zcbw GgzKdU/qTMXo1+hgKr1LokojvqWHrXehWj9Dgf3Du4zSOEhHwLOZgY9W14Kzmo6ACU Q2ZW7c0A8RI9RCv4em4lewfOA1B2GGAKd4IBf9Q8= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:33 -0700 Message-Id: <1527014802-11289-6-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 06/15] checkpatch: generalize xen handle matching in the list of types X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant All the xen stable APIs define handle types of the form: xen_handle and some define additional handle types of the form: xen__handle Examples of these are xenforeignmemory_handle and xenforeignmemory_resource_handle. Both of these types will be misparsed by checkpatch if they appear as the first token in a line since, as types defined by an external library, they do not conform to the QEMU CODING_STYLE, which suggests CamelCase. A previous patch (5ac067a24a8) added xendevicemodel_handle to the list of types. This patch changes that to xen\w+_handle such that it will match all Xen stable API handles of the forms detailed above. Signed-off-by: Paul Durrant Reviewed-by: Eric Blake Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- scripts/checkpatch.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index cb1b652..e3d8c2c 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -271,7 +271,7 @@ our @typeList =3D ( qr{hwaddr}, # external libraries qr{xml${Ident}}, - qr{xendevicemodel_handle}, + qr{xen\w+_handle}, # Glib definitions qr{gchar}, qr{gshort}, --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015129666490.85347525255656; Tue, 22 May 2018 11:52:09 -0700 (PDT) Received: from localhost ([::1]:57360 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCOG-0005Gr-PI for importer@patchew.org; Tue, 22 May 2018 14:52:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fF-2u for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ4-0007Qt-PY for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43558) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ4-0007Q6-K0 for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:46 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7A2E520877; Tue, 22 May 2018 18:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014805; bh=x1x3KuRo0iLwnvoX04jmiazPzUD4LoJTWvSkHgzsMAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jv302mlNvf0+/bb0ura9k4pegS2jC0HPJEznmJfD+daSkVaIv8WDoqhRekmoefvaf vSl/PThsTQNHMnWP9cOAy6XCCBDaohQTTVbAthQFxEk1qMiu2RKiMOJw2zQvoAsrci MhJK7rJTsoMPpo0CsR/xUfJCfIHoaEBgKvVRo3PY= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:34 -0700 Message-Id: <1527014802-11289-7-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 07/15] xen: add a meaningful declaration of grant_copy_segment into xen_common.h X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Currently the xen_disk source has to carry #ifdef exclusions to compile against Xen older then 4.8. This is a bit messy so this patch lifts the definition of struct xengnttab_grant_copy_segment and adds it into the pre-4.8 compat area in xen_common.h, which allows xen_disk to be cleaned up. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/block/xen_disk.c | 18 ------------------ include/hw/xen/xen_common.h | 17 +++++++++++++++-- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index f74fcd4..78bfb41 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -496,8 +496,6 @@ static int ioreq_map(struct ioreq *ioreq) return 0; } =20 -#if CONFIG_XEN_CTRL_INTERFACE_VERSION >=3D 40800 - static void ioreq_free_copy_buffers(struct ioreq *ioreq) { int i; @@ -579,22 +577,6 @@ static int ioreq_grant_copy(struct ioreq *ioreq) =20 return rc; } -#else -static void ioreq_free_copy_buffers(struct ioreq *ioreq) -{ - abort(); -} - -static int ioreq_init_copy_buffers(struct ioreq *ioreq) -{ - abort(); -} - -static int ioreq_grant_copy(struct ioreq *ioreq) -{ - abort(); -} -#endif =20 static int ioreq_runio_qemu_aio(struct ioreq *ioreq); =20 diff --git a/include/hw/xen/xen_common.h b/include/hw/xen/xen_common.h index 5f1402b..bbf207d 100644 --- a/include/hw/xen/xen_common.h +++ b/include/hw/xen/xen_common.h @@ -667,8 +667,21 @@ static inline int xen_domain_create(xc_interface *xc, = uint32_t ssidref, =20 #if CONFIG_XEN_CTRL_INTERFACE_VERSION < 40800 =20 - -typedef void *xengnttab_grant_copy_segment_t; +struct xengnttab_grant_copy_segment { + union xengnttab_copy_ptr { + void *virt; + struct { + uint32_t ref; + uint16_t offset; + uint16_t domid; + } foreign; + } source, dest; + uint16_t len; + uint16_t flags; + int16_t status; +}; + +typedef struct xengnttab_grant_copy_segment xengnttab_grant_copy_segment_t; =20 static inline int xengnttab_grant_copy(xengnttab_handle *xgt, uint32_t cou= nt, xengnttab_grant_copy_segment_t *seg= s) --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015494526555.7206395557388; Tue, 22 May 2018 11:58:14 -0700 (PDT) Received: from localhost ([::1]:57391 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCU9-0001Xs-Qo for importer@patchew.org; Tue, 22 May 2018 14:58:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50744) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001f7-19 for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ5-0007RA-7r for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43574) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ4-0007QY-VT for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:47 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D16E32087C; Tue, 22 May 2018 18:46:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014806; bh=CLB5ZB1kVTHLFZJxut+VGN+OAXp3mWKI7d0Cj532x9Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TJTqjcKH25EpLXWRmLvUAvrrdLntnBaY1W48zd72K8pz9p9X98vv5CK4lJRUszWBY KsU7jedYabGBmozzV4i2Yb2tsPMV567z2nWvw7xC3kYNMorxmkoLLUGFqyPhoUAePg XH079fSC/yIg6f6uIVyLIrxtKDkfWObk9244h28k= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:35 -0700 Message-Id: <1527014802-11289-8-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 08/15] xen_backend: add grant table helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant This patch adds grant table helper functions to the xen_backend code to localize error reporting and use of xen_domid. The patch also defers the call to xengnttab_open() until just before the initialise method in XenDevOps is invoked. This method is responsible for mapping the shared ring. No prior method requires access to the grant table. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/xen/xen_backend.c | 123 ++++++++++++++++++++++++++++++++++++++-= ---- include/hw/xen/xen_backend.h | 33 ++++++++++++ 2 files changed, 144 insertions(+), 12 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 7445b50..50412d6 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -106,6 +106,103 @@ int xen_be_set_state(struct XenDevice *xendev, enum x= enbus_state state) return 0; } =20 +void xen_be_set_max_grant_refs(struct XenDevice *xendev, + unsigned int nr_refs) +{ + assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV); + + if (xengnttab_set_max_grants(xendev->gnttabdev, nr_refs)) { + xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n", + strerror(errno)); + } +} + +void *xen_be_map_grant_refs(struct XenDevice *xendev, uint32_t *refs, + unsigned int nr_refs, int prot) +{ + void *ptr; + + assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV); + + ptr =3D xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_refs, + xen_domid, refs, prot); + if (!ptr) { + xen_pv_printf(xendev, 0, + "xengnttab_map_domain_grant_refs failed: %s\n", + strerror(errno)); + } + + return ptr; +} + +void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr, + unsigned int nr_refs) +{ + assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV); + + if (xengnttab_unmap(xendev->gnttabdev, ptr, nr_refs)) { + xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n", + strerror(errno)); + } +} + +int xen_be_copy_grant_refs(struct XenDevice *xendev, + bool to_domain, + XenGrantCopySegment segs[], + unsigned int nr_segs) +{ + xengnttab_grant_copy_segment_t *xengnttab_segs; + unsigned int i; + int rc; + + assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV); + + xengnttab_segs =3D g_new0(xengnttab_grant_copy_segment_t, nr_segs); + + for (i =3D 0; i < nr_segs; i++) { + XenGrantCopySegment *seg =3D &segs[i]; + xengnttab_grant_copy_segment_t *xengnttab_seg =3D &xengnttab_segs[= i]; + + if (to_domain) { + xengnttab_seg->flags =3D GNTCOPY_dest_gref; + xengnttab_seg->dest.foreign.domid =3D xen_domid; + xengnttab_seg->dest.foreign.ref =3D seg->dest.foreign.ref; + xengnttab_seg->dest.foreign.offset =3D seg->dest.foreign.offse= t; + xengnttab_seg->source.virt =3D seg->source.virt; + } else { + xengnttab_seg->flags =3D GNTCOPY_source_gref; + xengnttab_seg->source.foreign.domid =3D xen_domid; + xengnttab_seg->source.foreign.ref =3D seg->source.foreign.ref; + xengnttab_seg->source.foreign.offset =3D + seg->source.foreign.offset; + xengnttab_seg->dest.virt =3D seg->dest.virt; + } + + xengnttab_seg->len =3D seg->len; + } + + rc =3D xengnttab_grant_copy(xendev->gnttabdev, nr_segs, xengnttab_segs= ); + + if (rc) { + xen_pv_printf(xendev, 0, "xengnttab_copy failed: %s\n", + strerror(errno)); + } + + for (i =3D 0; i < nr_segs; i++) { + xengnttab_grant_copy_segment_t *xengnttab_seg =3D + &xengnttab_segs[i]; + + if (xengnttab_seg->status !=3D GNTST_okay) { + xen_pv_printf(xendev, 0, "segment[%u] status: %d\n", i, + xengnttab_seg->status); + rc =3D -1; + } + } + + g_free(xengnttab_segs); + return rc; +} + /* * get xen backend device, allocate a new one if it doesn't exist. */ @@ -149,18 +246,6 @@ static struct XenDevice *xen_be_get_xendev(const char = *type, int dom, int dev, } qemu_set_cloexec(xenevtchn_fd(xendev->evtchndev)); =20 - if (ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { - xendev->gnttabdev =3D xengnttab_open(NULL, 0); - if (xendev->gnttabdev =3D=3D NULL) { - xen_pv_printf(NULL, 0, "can't open gnttab device\n"); - xenevtchn_close(xendev->evtchndev); - qdev_unplug(DEVICE(xendev), NULL); - return NULL; - } - } else { - xendev->gnttabdev =3D NULL; - } - xen_pv_insert_xendev(xendev); =20 if (xendev->ops->alloc) { @@ -322,6 +407,16 @@ static int xen_be_try_initialise(struct XenDevice *xen= dev) } } =20 + if (xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV) { + xendev->gnttabdev =3D xengnttab_open(NULL, 0); + if (xendev->gnttabdev =3D=3D NULL) { + xen_pv_printf(NULL, 0, "can't open gnttab device\n"); + return -1; + } + } else { + xendev->gnttabdev =3D NULL; + } + if (xendev->ops->initialise) { rc =3D xendev->ops->initialise(xendev); } @@ -369,6 +464,10 @@ static void xen_be_disconnect(struct XenDevice *xendev= , enum xenbus_state state) xendev->ops->disconnect) { xendev->ops->disconnect(xendev); } + if (xendev->gnttabdev) { + xengnttab_close(xendev->gnttabdev); + xendev->gnttabdev =3D NULL; + } if (xendev->be_state !=3D state) { xen_be_set_state(xendev, state); } diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 3a27692..29bf1c3 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -42,6 +42,39 @@ void xen_be_register_common(void); int xen_be_register(const char *type, struct XenDevOps *ops); int xen_be_set_state(struct XenDevice *xendev, enum xenbus_state state); int xen_be_bind_evtchn(struct XenDevice *xendev); +void xen_be_set_max_grant_refs(struct XenDevice *xendev, + unsigned int nr_refs); +void *xen_be_map_grant_refs(struct XenDevice *xendev, uint32_t *refs, + unsigned int nr_refs, int prot); +void xen_be_unmap_grant_refs(struct XenDevice *xendev, void *ptr, + unsigned int nr_refs); + +typedef struct XenGrantCopySegment { + union { + void *virt; + struct { + uint32_t ref; + off_t offset; + } foreign; + } source, dest; + size_t len; +} XenGrantCopySegment; + +int xen_be_copy_grant_refs(struct XenDevice *xendev, + bool to_domain, XenGrantCopySegment segs[], + unsigned int nr_segs); + +static inline void *xen_be_map_grant_ref(struct XenDevice *xendev, + uint32_t ref, int prot) +{ + return xen_be_map_grant_refs(xendev, &ref, 1, prot); +} + +static inline void xen_be_unmap_grant_ref(struct XenDevice *xendev, + void *ptr) +{ + return xen_be_unmap_grant_refs(xendev, ptr, 1); +} =20 /* actual backend drivers */ extern struct XenDevOps xen_console_ops; /* xen_console.c */ --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527014958771765.0338844118423; Tue, 22 May 2018 11:49:18 -0700 (PDT) Received: from localhost ([::1]:57342 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCLV-0002uS-Sn for importer@patchew.org; Tue, 22 May 2018 14:49:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50743) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001f2-1P for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ5-0007RM-Js for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43588) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ5-0007Qn-BD for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:47 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34F8620876; Tue, 22 May 2018 18:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014806; bh=MG7J8H20KyM3cnHxpfpOaxLmgFfEavq9oYqgJsdlEUE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SDHHx+amVnk/mjaBBakEF+PDy0fzADzHmDQcA2/chv8BSAOL1FnNICqVopDWiq6GP jzgC34gX0BwT7vJR2bZKi5z6ntxAExNoCOsNzoT6JIo41o9G3ojDyNjsWhoxZgBe6/ M7TDR8kj1yS772cX5i83LgLnZ9dSGQwBIopvfkig= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:36 -0700 Message-Id: <1527014802-11289-9-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 09/15] xen_disk: remove open-coded use of libxengnttab X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Now that helpers are present in xen_backend, this patch removes open-coded calls to libxengnttab from the xen_disk code. This patch also fixes one whitspace error in the assignment of the XenDevOps initialise method. Signed-off-by: Paul Durrant Acked-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/block/xen_disk.c | 122 ++++++++++++++----------------------------------= ---- 1 file changed, 32 insertions(+), 90 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 78bfb41..d3be45a 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -68,7 +68,6 @@ struct ioreq { uint8_t mapped; =20 /* grant mapping */ - uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST]; uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int prot; void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; @@ -142,7 +141,6 @@ static void ioreq_reset(struct ioreq *ioreq) ioreq->presync =3D 0; ioreq->mapped =3D 0; =20 - memset(ioreq->domids, 0, sizeof(ioreq->domids)); memset(ioreq->refs, 0, sizeof(ioreq->refs)); ioreq->prot =3D 0; memset(ioreq->page, 0, sizeof(ioreq->page)); @@ -168,16 +166,12 @@ static gint int_cmp(gconstpointer a, gconstpointer b,= gpointer user_data) static void destroy_grant(gpointer pgnt) { PersistentGrant *grant =3D pgnt; - xengnttab_handle *gnt =3D grant->blkdev->xendev.gnttabdev; + struct XenBlkDev *blkdev =3D grant->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; =20 - if (xengnttab_unmap(gnt, grant->page, 1) !=3D 0) { - xen_pv_printf(&grant->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_ref(xendev, grant->page); grant->blkdev->persistent_gnt_count--; - xen_pv_printf(&grant->blkdev->xendev, 3, - "unmapped grant %p\n", grant->page); + xen_pv_printf(xendev, 3, "unmapped grant %p\n", grant->page); g_free(grant); } =20 @@ -185,15 +179,10 @@ static void remove_persistent_region(gpointer data, g= pointer dev) { PersistentRegion *region =3D data; struct XenBlkDev *blkdev =3D dev; - xengnttab_handle *gnt =3D blkdev->xendev.gnttabdev; + struct XenDevice *xendev =3D &blkdev->xendev; =20 - if (xengnttab_unmap(gnt, region->addr, region->num) !=3D 0) { - xen_pv_printf(&blkdev->xendev, 0, - "xengnttab_unmap region %p failed: %s\n", - region->addr, strerror(errno)); - } - xen_pv_printf(&blkdev->xendev, 3, - "unmapped grant region %p with %d pages\n", + xen_be_unmap_grant_refs(xendev, region->addr, region->num); + xen_pv_printf(xendev, 3, "unmapped grant region %p with %d pages\n", region->addr, region->num); g_free(region); } @@ -304,7 +293,6 @@ static int ioreq_parse(struct ioreq *ioreq) goto err; } =20 - ioreq->domids[i] =3D blkdev->xendev.dom; ioreq->refs[i] =3D ioreq->req.seg[i].gref; =20 mem =3D ioreq->req.seg[i].first_sect * blkdev->file_blk; @@ -324,7 +312,8 @@ err: =20 static void ioreq_unmap(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; int i; =20 if (ioreq->num_unmap =3D=3D 0 || ioreq->mapped =3D=3D 0) { @@ -334,11 +323,7 @@ static void ioreq_unmap(struct ioreq *ioreq) if (!ioreq->pages) { return; } - if (xengnttab_unmap(gnt, ioreq->pages, ioreq->num_unmap) !=3D 0) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_refs(xendev, ioreq->pages, ioreq->num_unmap); ioreq->blkdev->cnt_map -=3D ioreq->num_unmap; ioreq->pages =3D NULL; } else { @@ -346,11 +331,7 @@ static void ioreq_unmap(struct ioreq *ioreq) if (!ioreq->page[i]) { continue; } - if (xengnttab_unmap(gnt, ioreq->page[i], 1) !=3D 0) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "xengnttab_unmap failed: %s\n", - strerror(errno)); - } + xen_be_unmap_grant_ref(xendev, ioreq->page[i]); ioreq->blkdev->cnt_map--; ioreq->page[i] =3D NULL; } @@ -360,14 +341,14 @@ static void ioreq_unmap(struct ioreq *ioreq) =20 static int ioreq_map(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; - uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, j, new_maps =3D 0; PersistentGrant *grant; PersistentRegion *region; - /* domids and refs variables will contain the information necessary + /* refs variable will contain the information necessary * to map the grants that are needed to fulfill this request. * * After mapping the needed grants, the page array will contain the @@ -392,7 +373,6 @@ static int ioreq_map(struct ioreq *ioreq) /* Add the grant to the list of grants that * should be mapped */ - domids[new_maps] =3D ioreq->domids[i]; refs[new_maps] =3D ioreq->refs[i]; page[i] =3D NULL; new_maps++; @@ -405,14 +385,13 @@ static int ioreq_map(struct ioreq *ioreq) } else { /* All grants in the request should be mapped */ memcpy(refs, ioreq->refs, sizeof(refs)); - memcpy(domids, ioreq->domids, sizeof(domids)); memset(page, 0, sizeof(page)); new_maps =3D ioreq->v.niov; } =20 if (batch_maps && new_maps) { - ioreq->pages =3D xengnttab_map_grant_refs - (gnt, new_maps, domids, refs, ioreq->prot); + ioreq->pages =3D xen_be_map_grant_refs(xendev, refs, new_maps, + ioreq->prot); if (ioreq->pages =3D=3D NULL) { xen_pv_printf(&ioreq->blkdev->xendev, 0, "can't map %d grant refs (%s, %d maps)\n", @@ -427,8 +406,8 @@ static int ioreq_map(struct ioreq *ioreq) ioreq->blkdev->cnt_map +=3D new_maps; } else if (new_maps) { for (i =3D 0; i < new_maps; i++) { - ioreq->page[i] =3D xengnttab_map_grant_ref - (gnt, domids[i], refs[i], ioreq->prot); + ioreq->page[i] =3D xen_be_map_grant_ref(xendev, refs[i], + ioreq->prot); if (ioreq->page[i] =3D=3D NULL) { xen_pv_printf(&ioreq->blkdev->xendev, 0, "can't map grant ref %d (%s, %d maps)\n", @@ -527,10 +506,12 @@ static int ioreq_init_copy_buffers(struct ioreq *iore= q) =20 static int ioreq_grant_copy(struct ioreq *ioreq) { - xengnttab_handle *gnt =3D ioreq->blkdev->xendev.gnttabdev; - xengnttab_grant_copy_segment_t segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; + struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; + XenGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, count, rc; int64_t file_blk =3D ioreq->blkdev->file_blk; + bool to_domain =3D (ioreq->req.operation =3D=3D BLKIF_OP_READ); =20 if (ioreq->v.niov =3D=3D 0) { return 0; @@ -539,16 +520,12 @@ static int ioreq_grant_copy(struct ioreq *ioreq) count =3D ioreq->v.niov; =20 for (i =3D 0; i < count; i++) { - if (ioreq->req.operation =3D=3D BLKIF_OP_READ) { - segs[i].flags =3D GNTCOPY_dest_gref; + if (to_domain) { segs[i].dest.foreign.ref =3D ioreq->refs[i]; - segs[i].dest.foreign.domid =3D ioreq->domids[i]; segs[i].dest.foreign.offset =3D ioreq->req.seg[i].first_sect *= file_blk; segs[i].source.virt =3D ioreq->v.iov[i].iov_base; } else { - segs[i].flags =3D GNTCOPY_source_gref; segs[i].source.foreign.ref =3D ioreq->refs[i]; - segs[i].source.foreign.domid =3D ioreq->domids[i]; segs[i].source.foreign.offset =3D ioreq->req.seg[i].first_sect= * file_blk; segs[i].dest.virt =3D ioreq->v.iov[i].iov_base; } @@ -556,7 +533,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq) - ioreq->req.seg[i].first_sect + 1) * file_blk; } =20 - rc =3D xengnttab_grant_copy(gnt, count, segs); + rc =3D xen_be_copy_grant_refs(xendev, to_domain, segs, count); =20 if (rc) { xen_pv_printf(&ioreq->blkdev->xendev, 0, @@ -565,16 +542,6 @@ static int ioreq_grant_copy(struct ioreq *ioreq) return -1; } =20 - for (i =3D 0; i < count; i++) { - if (segs[i].status !=3D GNTST_okay) { - xen_pv_printf(&ioreq->blkdev->xendev, 3, - "failed to copy data %d for gref %d, domid %d\n", - segs[i].status, ioreq->refs[i], ioreq->domids[i]= ); - ioreq->aio_errors++; - rc =3D -1; - } - } - return rc; } =20 @@ -1067,7 +1034,6 @@ static int blk_connect(struct XenDevice *xendev) int order, ring_ref; unsigned int ring_size, max_grants; unsigned int i; - uint32_t *domids; =20 trace_xen_disk_connect(xendev->name); =20 @@ -1229,31 +1195,11 @@ static int blk_connect(struct XenDevice *xendev) /* Add on the number needed for the ring pages */ max_grants +=3D blkdev->nr_ring_ref; =20 - blkdev->xendev.gnttabdev =3D xengnttab_open(NULL, 0); - if (blkdev->xendev.gnttabdev =3D=3D NULL) { - xen_pv_printf(xendev, 0, "xengnttab_open failed: %s\n", - strerror(errno)); - return -1; - } - if (xengnttab_set_max_grants(blkdev->xendev.gnttabdev, max_grants)) { - xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n", - strerror(errno)); - return -1; - } - - domids =3D g_new0(uint32_t, blkdev->nr_ring_ref); - for (i =3D 0; i < blkdev->nr_ring_ref; i++) { - domids[i] =3D blkdev->xendev.dom; - } - - blkdev->sring =3D xengnttab_map_grant_refs(blkdev->xendev.gnttabdev, - blkdev->nr_ring_ref, - domids, - blkdev->ring_ref, - PROT_READ | PROT_WRITE); - - g_free(domids); + xen_be_set_max_grant_refs(xendev, max_grants); =20 + blkdev->sring =3D xen_be_map_grant_refs(xendev, blkdev->ring_ref, + blkdev->nr_ring_ref, + PROT_READ | PROT_WRITE); if (!blkdev->sring) { return -1; } @@ -1326,8 +1272,8 @@ static void blk_disconnect(struct XenDevice *xendev) aio_context_release(blkdev->ctx); =20 if (blkdev->sring) { - xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring, - blkdev->nr_ring_ref); + xen_be_unmap_grant_refs(xendev, blkdev->sring, + blkdev->nr_ring_ref); blkdev->cnt_map--; blkdev->sring =3D NULL; } @@ -1351,11 +1297,6 @@ static void blk_disconnect(struct XenDevice *xendev) } blkdev->feature_persistent =3D false; } - - if (blkdev->xendev.gnttabdev) { - xengnttab_close(blkdev->xendev.gnttabdev); - blkdev->xendev.gnttabdev =3D NULL; - } } =20 static int blk_free(struct XenDevice *xendev) @@ -1392,10 +1333,11 @@ static void blk_event(struct XenDevice *xendev) } =20 struct XenDevOps xen_blkdev_ops =3D { + .flags =3D DEVOPS_FLAG_NEED_GNTDEV, .size =3D sizeof(struct XenBlkDev), .alloc =3D blk_alloc, .init =3D blk_init, - .initialise =3D blk_connect, + .initialise =3D blk_connect, .disconnect =3D blk_disconnect, .event =3D blk_event, .free =3D blk_free, --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152701556301034.506729718173915; Tue, 22 May 2018 11:59:23 -0700 (PDT) Received: from localhost ([::1]:57394 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCVG-00029Q-9b for importer@patchew.org; Tue, 22 May 2018 14:59:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50757) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fK-3k for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ5-0007Re-Vi for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43606) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ5-0007R4-Lg for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:47 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8CFAA20879; Tue, 22 May 2018 18:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014806; bh=pnEPxraoMfbxgx9Bs+SAdh0vNKcwjmfsh1TTy84kFmM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wN7iIwWp13oMRUCCDFU7+exe+v7VQ4rCQ26weG6xs8evOnCzyqEcK86k9t6WtXjDk YfT7kqF2rAVvPYAMosXV6BVzJq/ghNTfKeLItm9S7aRcVkEkIulZDOIudZqRA7GoXK d7CcfM+Xlp5izXcCq6Y3H/kiqUYNdF+1XsGlRSpk= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:37 -0700 Message-Id: <1527014802-11289-10-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 10/15] xen: remove other open-coded use of libxengnttab X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Now that helpers are available in xen_backend, use them throughout all Xen PV backends. Signed-off-by: Paul Durrant Acked-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/9pfs/xen-9p-backend.c | 32 +++++++++++++++----------------- hw/char/xen_console.c | 9 ++++----- hw/net/xen_nic.c | 33 ++++++++++++++------------------- hw/usb/xen-usb.c | 37 +++++++++++++++++-------------------- 4 files changed, 50 insertions(+), 61 deletions(-) diff --git a/hw/9pfs/xen-9p-backend.c b/hw/9pfs/xen-9p-backend.c index 95e50c4..6026780 100644 --- a/hw/9pfs/xen-9p-backend.c +++ b/hw/9pfs/xen-9p-backend.c @@ -331,14 +331,14 @@ static int xen_9pfs_free(struct XenDevice *xendev) =20 for (i =3D 0; i < xen_9pdev->num_rings; i++) { if (xen_9pdev->rings[i].data !=3D NULL) { - xengnttab_unmap(xen_9pdev->xendev.gnttabdev, - xen_9pdev->rings[i].data, - (1 << xen_9pdev->rings[i].ring_order)); + xen_be_unmap_grant_refs(&xen_9pdev->xendev, + xen_9pdev->rings[i].data, + (1 << xen_9pdev->rings[i].ring_order)); } if (xen_9pdev->rings[i].intf !=3D NULL) { - xengnttab_unmap(xen_9pdev->xendev.gnttabdev, - xen_9pdev->rings[i].intf, - 1); + xen_be_unmap_grant_refs(&xen_9pdev->xendev, + xen_9pdev->rings[i].intf, + 1); } if (xen_9pdev->rings[i].bh !=3D NULL) { qemu_bh_delete(xen_9pdev->rings[i].bh); @@ -390,11 +390,10 @@ static int xen_9pfs_connect(struct XenDevice *xendev) } g_free(str); =20 - xen_9pdev->rings[i].intf =3D xengnttab_map_grant_ref( - xen_9pdev->xendev.gnttabdev, - xen_9pdev->xendev.dom, - xen_9pdev->rings[i].ref, - PROT_READ | PROT_WRITE); + xen_9pdev->rings[i].intf =3D + xen_be_map_grant_ref(&xen_9pdev->xendev, + xen_9pdev->rings[i].ref, + PROT_READ | PROT_WRITE); if (!xen_9pdev->rings[i].intf) { goto out; } @@ -403,12 +402,11 @@ static int xen_9pfs_connect(struct XenDevice *xendev) goto out; } xen_9pdev->rings[i].ring_order =3D ring_order; - xen_9pdev->rings[i].data =3D xengnttab_map_domain_grant_refs( - xen_9pdev->xendev.gnttabdev, - (1 << ring_order), - xen_9pdev->xendev.dom, - xen_9pdev->rings[i].intf->ref, - PROT_READ | PROT_WRITE); + xen_9pdev->rings[i].data =3D + xen_be_map_grant_refs(&xen_9pdev->xendev, + xen_9pdev->rings[i].intf->ref, + (1 << ring_order), + PROT_READ | PROT_WRITE); if (!xen_9pdev->rings[i].data) { goto out; } diff --git a/hw/char/xen_console.c b/hw/char/xen_console.c index bdfaa40..8b4b4bf 100644 --- a/hw/char/xen_console.c +++ b/hw/char/xen_console.c @@ -233,12 +233,11 @@ static int con_initialise(struct XenDevice *xendev) if (!xendev->dev) { xen_pfn_t mfn =3D con->ring_ref; con->sring =3D xenforeignmemory_map(xen_fmem, con->xendev.dom, - PROT_READ|PROT_WRITE, + PROT_READ | PROT_WRITE, 1, &mfn, NULL); } else { - con->sring =3D xengnttab_map_grant_ref(xendev->gnttabdev, con->xen= dev.dom, - con->ring_ref, - PROT_READ|PROT_WRITE); + con->sring =3D xen_be_map_grant_ref(xendev, con->ring_ref, + PROT_READ | PROT_WRITE); } if (!con->sring) return -1; @@ -267,7 +266,7 @@ static void con_disconnect(struct XenDevice *xendev) if (!xendev->dev) { xenforeignmemory_unmap(xen_fmem, con->sring, 1); } else { - xengnttab_unmap(xendev->gnttabdev, con->sring, 1); + xen_be_unmap_grant_ref(xendev, con->sring); } con->sring =3D NULL; } diff --git a/hw/net/xen_nic.c b/hw/net/xen_nic.c index 20c43a6..46a8dbf 100644 --- a/hw/net/xen_nic.c +++ b/hw/net/xen_nic.c @@ -160,9 +160,8 @@ static void net_tx_packets(struct XenNetDev *netdev) (txreq.flags & NETTXF_more_data) ? " more_d= ata" : "", (txreq.flags & NETTXF_extra_info) ? " extra_= info" : ""); =20 - page =3D xengnttab_map_grant_ref(netdev->xendev.gnttabdev, - netdev->xendev.dom, - txreq.gref, PROT_READ); + page =3D xen_be_map_grant_ref(&netdev->xendev, txreq.gref, + PROT_READ); if (page =3D=3D NULL) { xen_pv_printf(&netdev->xendev, 0, "error: tx gref dereference failed (%d)\n", @@ -183,7 +182,7 @@ static void net_tx_packets(struct XenNetDev *netdev) qemu_send_packet(qemu_get_queue(netdev->nic), page + txreq.offset, txreq.size); } - xengnttab_unmap(netdev->xendev.gnttabdev, page, 1); + xen_be_unmap_grant_ref(&netdev->xendev, page); net_tx_response(netdev, &txreq, NETIF_RSP_OKAY); } if (!netdev->tx_work) { @@ -254,9 +253,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const = uint8_t *buf, size_t size memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); netdev->rx_ring.req_cons =3D ++rc; =20 - page =3D xengnttab_map_grant_ref(netdev->xendev.gnttabdev, - netdev->xendev.dom, - rxreq.gref, PROT_WRITE); + page =3D xen_be_map_grant_ref(&netdev->xendev, rxreq.gref, PROT_WRITE); if (page =3D=3D NULL) { xen_pv_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", @@ -265,7 +262,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const = uint8_t *buf, size_t size return -1; } memcpy(page + NET_IP_ALIGN, buf, size); - xengnttab_unmap(netdev->xendev.gnttabdev, page, 1); + xen_be_unmap_grant_ref(&netdev->xendev, page); net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); =20 return size; @@ -338,19 +335,17 @@ static int net_connect(struct XenDevice *xendev) return -1; } =20 - netdev->txs =3D xengnttab_map_grant_ref(netdev->xendev.gnttabdev, - netdev->xendev.dom, - netdev->tx_ring_ref, - PROT_READ | PROT_WRITE); + netdev->txs =3D xen_be_map_grant_ref(&netdev->xendev, + netdev->tx_ring_ref, + PROT_READ | PROT_WRITE); if (!netdev->txs) { return -1; } - netdev->rxs =3D xengnttab_map_grant_ref(netdev->xendev.gnttabdev, - netdev->xendev.dom, - netdev->rx_ring_ref, - PROT_READ | PROT_WRITE); + netdev->rxs =3D xen_be_map_grant_ref(&netdev->xendev, + netdev->rx_ring_ref, + PROT_READ | PROT_WRITE); if (!netdev->rxs) { - xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); + xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs); netdev->txs =3D NULL; return -1; } @@ -375,11 +370,11 @@ static void net_disconnect(struct XenDevice *xendev) xen_pv_unbind_evtchn(&netdev->xendev); =20 if (netdev->txs) { - xengnttab_unmap(netdev->xendev.gnttabdev, netdev->txs, 1); + xen_be_unmap_grant_ref(&netdev->xendev, netdev->txs); netdev->txs =3D NULL; } if (netdev->rxs) { - xengnttab_unmap(netdev->xendev.gnttabdev, netdev->rxs, 1); + xen_be_unmap_grant_ref(&netdev->xendev, netdev->rxs); netdev->rxs =3D NULL; } } diff --git a/hw/usb/xen-usb.c b/hw/usb/xen-usb.c index b3a90c0..5b2e21e 100644 --- a/hw/usb/xen-usb.c +++ b/hw/usb/xen-usb.c @@ -173,8 +173,9 @@ static int usbback_gnttab_map(struct usbback_req *usbba= ck_req) for (i =3D 0; i < usbback_req->nr_buffer_segs; i++) { ref[i] =3D usbback_req->req.seg[i].gref; } - usbback_req->buffer =3D xengnttab_map_domain_grant_refs(xendev->gn= ttabdev, - usbback_req->nr_buffer_segs, xendev->dom, ref, prot); + usbback_req->buffer =3D + xen_be_map_grant_refs(xendev, ref, usbback_req->nr_buffer_segs, + prot); =20 if (!usbback_req->buffer) { return -ENOMEM; @@ -206,8 +207,9 @@ static int usbback_gnttab_map(struct usbback_req *usbba= ck_req) for (i =3D 0; i < usbback_req->nr_extra_segs; i++) { ref[i] =3D usbback_req->req.seg[i + usbback_req->req.nr_buffer_seg= s].gref; } - usbback_req->isoc_buffer =3D xengnttab_map_domain_grant_refs( - xendev->gnttabdev, usbback_req->nr_extra_segs, xendev->dom, ref, = prot); + usbback_req->isoc_buffer =3D + xen_be_map_grant_refs(xendev, ref, usbback_req->nr_extra_segs, + prot); =20 if (!usbback_req->isoc_buffer) { return -ENOMEM; @@ -291,14 +293,14 @@ static void usbback_do_response(struct usbback_req *u= sbback_req, int32_t status, } =20 if (usbback_req->buffer) { - xengnttab_unmap(xendev->gnttabdev, usbback_req->buffer, - usbback_req->nr_buffer_segs); + xen_be_unmap_grant_refs(xendev, usbback_req->buffer, + usbback_req->nr_buffer_segs); usbback_req->buffer =3D NULL; } =20 if (usbback_req->isoc_buffer) { - xengnttab_unmap(xendev->gnttabdev, usbback_req->isoc_buffer, - usbback_req->nr_extra_segs); + xen_be_unmap_grant_refs(xendev, usbback_req->isoc_buffer, + usbback_req->nr_extra_segs); usbback_req->isoc_buffer =3D NULL; } =20 @@ -834,11 +836,11 @@ static void usbback_disconnect(struct XenDevice *xend= ev) xen_pv_unbind_evtchn(xendev); =20 if (usbif->urb_sring) { - xengnttab_unmap(xendev->gnttabdev, usbif->urb_sring, 1); + xen_be_unmap_grant_ref(xendev, usbif->urb_sring); usbif->urb_sring =3D NULL; } if (usbif->conn_sring) { - xengnttab_unmap(xendev->gnttabdev, usbif->conn_sring, 1); + xen_be_unmap_grant_ref(xendev, usbif->conn_sring); usbif->conn_sring =3D NULL; } =20 @@ -877,12 +879,10 @@ static int usbback_connect(struct XenDevice *xendev) return -1; } =20 - usbif->urb_sring =3D xengnttab_map_grant_ref(xendev->gnttabdev, xendev= ->dom, - urb_ring_ref, - PROT_READ | PROT_WRITE); - usbif->conn_sring =3D xengnttab_map_grant_ref(xendev->gnttabdev, xende= v->dom, - conn_ring_ref, - PROT_READ | PROT_WRITE); + usbif->urb_sring =3D xen_be_map_grant_ref(xendev, urb_ring_ref, + PROT_READ | PROT_WRITE); + usbif->conn_sring =3D xen_be_map_grant_ref(xendev, conn_ring_ref, + PROT_READ | PROT_WRITE); if (!usbif->urb_sring || !usbif->conn_sring) { xen_pv_printf(xendev, 0, "error mapping rings\n"); usbback_disconnect(xendev); @@ -1024,10 +1024,7 @@ static void usbback_alloc(struct XenDevice *xendev) =20 /* max_grants: for each request and for the rings (request and connect= ). */ max_grants =3D USBIF_MAX_SEGMENTS_PER_REQUEST * USB_URB_RING_SIZE + 2; - if (xengnttab_set_max_grants(xendev->gnttabdev, max_grants) < 0) { - xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n", - strerror(errno)); - } + xen_be_set_max_grant_refs(xendev, max_grants); } =20 static int usbback_free(struct XenDevice *xendev) --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015122524135.5141740283093; Tue, 22 May 2018 11:52:02 -0700 (PDT) Received: from localhost ([::1]:57359 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCO9-0005Br-LD for importer@patchew.org; Tue, 22 May 2018 14:52:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50747) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fD-1v for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ6-0007Rn-8b for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43618) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ5-0007RF-WE for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:48 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E33362087B; Tue, 22 May 2018 18:46:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014807; bh=bgAD0hHlztPXWtZZJwLpY9OhXzf2Hp8xmt6waTOjqF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c8KEb30QXs4P4KmCb9CzzvsR0hAdbmGvz6Xc68kBLx+bPg1apuyH5ZV1thMzlABp/ zGfY7jXicR8cjIMafeOabrj9lFS7ggcp5qk4TCwDeZNpYp2r6E1Cd4bB3Q7MxCZXPT /ZF7EDov6/x6R0cbYb5mnEos5cVVTcT5JGBLQpD0= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:38 -0700 Message-Id: <1527014802-11289-11-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 11/15] xen_backend: add an emulation of grant copy X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Not all Xen environments support the xengnttab_grant_copy() operation. E.g. where the OS is FreeBSD or Xen is older than 4.8.0. This patch introduces an emulation of that operation using xengnttab_map_domain_grant_refs() and memcpy() for those environments. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/xen/xen_backend.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 53 insertions(+) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 50412d6..3c3fc2c 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -146,6 +146,55 @@ void xen_be_unmap_grant_refs(struct XenDevice *xendev,= void *ptr, } } =20 +static int compat_copy_grant_refs(struct XenDevice *xendev, + bool to_domain, + XenGrantCopySegment segs[], + unsigned int nr_segs) +{ + uint32_t *refs =3D g_new(uint32_t, nr_segs); + int prot =3D to_domain ? PROT_WRITE : PROT_READ; + void *pages; + unsigned int i; + + for (i =3D 0; i < nr_segs; i++) { + XenGrantCopySegment *seg =3D &segs[i]; + + refs[i] =3D to_domain ? + seg->dest.foreign.ref : seg->source.foreign.ref; + } + + pages =3D xengnttab_map_domain_grant_refs(xendev->gnttabdev, nr_segs, + xen_domid, refs, prot); + if (!pages) { + xen_pv_printf(xendev, 0, + "xengnttab_map_domain_grant_refs failed: %s\n", + strerror(errno)); + g_free(refs); + return -1; + } + + for (i =3D 0; i < nr_segs; i++) { + XenGrantCopySegment *seg =3D &segs[i]; + void *page =3D pages + (i * XC_PAGE_SIZE); + + if (to_domain) { + memcpy(page + seg->dest.foreign.offset, seg->source.virt, + seg->len); + } else { + memcpy(seg->dest.virt, page + seg->source.foreign.offset, + seg->len); + } + } + + if (xengnttab_unmap(xendev->gnttabdev, pages, nr_segs)) { + xen_pv_printf(xendev, 0, "xengnttab_unmap failed: %s\n", + strerror(errno)); + } + + g_free(refs); + return 0; +} + int xen_be_copy_grant_refs(struct XenDevice *xendev, bool to_domain, XenGrantCopySegment segs[], @@ -157,6 +206,10 @@ int xen_be_copy_grant_refs(struct XenDevice *xendev, =20 assert(xendev->ops->flags & DEVOPS_FLAG_NEED_GNTDEV); =20 + if (!xen_feature_grant_copy) { + return compat_copy_grant_refs(xendev, to_domain, segs, nr_segs); + } + xengnttab_segs =3D g_new0(xengnttab_grant_copy_segment_t, nr_segs); =20 for (i =3D 0; i < nr_segs; i++) { --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015713863703.9329218001909; Tue, 22 May 2018 12:01:53 -0700 (PDT) Received: from localhost ([::1]:57412 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCXh-0003aI-3M for importer@patchew.org; Tue, 22 May 2018 15:01:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fC-24 for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ6-0007S4-M4 for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ6-0007RS-CA for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:48 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4769320878; Tue, 22 May 2018 18:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014807; bh=FF9ENIth57duLx0iW5OOP4SGGcvtirinGLtLwnHJpLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RtE0Mt3RwyfhKeIQNutdnUI8qJw1Y4a4I9ROgh4/rzyL6lUNzTeCfPSqXotjw5QY0 BYnIIxWb67Kor6lcZD7ek5TkC4m3iEl9mVthvQDe/+5BHgjFe3QuqvHLhoibIbusW2 iM5xCUmmO9xBre/ljvpYSbpQSXv90eAvcsw37W0o= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:39 -0700 Message-Id: <1527014802-11289-12-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 12/15] xen_disk: remove use of grant map/unmap X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Now that the (native or emulated) xen_be_copy_grant_refs() helper is always available, the xen_disk code can be significantly simplified by removing direct use of grant map and unmap operations. Signed-off-by: Paul Durrant Acked-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/block/xen_disk.c | 352 ++++--------------------------------------------= ---- 1 file changed, 25 insertions(+), 327 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index d3be45a..28be8b6 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -36,27 +36,9 @@ =20 /* ------------------------------------------------------------- */ =20 -static int batch_maps =3D 0; - -/* ------------------------------------------------------------- */ - #define BLOCK_SIZE 512 #define IOCB_COUNT (BLKIF_MAX_SEGMENTS_PER_REQUEST + 2) =20 -struct PersistentGrant { - void *page; - struct XenBlkDev *blkdev; -}; - -typedef struct PersistentGrant PersistentGrant; - -struct PersistentRegion { - void *addr; - int num; -}; - -typedef struct PersistentRegion PersistentRegion; - struct ioreq { blkif_request_t req; int16_t status; @@ -65,14 +47,11 @@ struct ioreq { off_t start; QEMUIOVector v; int presync; - uint8_t mapped; =20 /* grant mapping */ uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - int prot; void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; void *pages; - int num_unmap; =20 /* aio status */ int aio_inflight; @@ -103,7 +82,6 @@ struct XenBlkDev { int protocol; blkif_back_rings_t rings; int more_work; - int cnt_map; =20 /* request lists */ QLIST_HEAD(inflight_head, ioreq) inflight; @@ -114,13 +92,7 @@ struct XenBlkDev { int requests_finished; unsigned int max_requests; =20 - /* Persistent grants extension */ gboolean feature_discard; - gboolean feature_persistent; - GTree *persistent_gnts; - GSList *persistent_regions; - unsigned int persistent_gnt_count; - unsigned int max_grants; =20 /* qemu block driver */ DriveInfo *dinfo; @@ -139,10 +111,8 @@ static void ioreq_reset(struct ioreq *ioreq) ioreq->status =3D 0; ioreq->start =3D 0; ioreq->presync =3D 0; - ioreq->mapped =3D 0; =20 memset(ioreq->refs, 0, sizeof(ioreq->refs)); - ioreq->prot =3D 0; memset(ioreq->page, 0, sizeof(ioreq->page)); ioreq->pages =3D NULL; =20 @@ -156,37 +126,6 @@ static void ioreq_reset(struct ioreq *ioreq) qemu_iovec_reset(&ioreq->v); } =20 -static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data) -{ - uint ua =3D GPOINTER_TO_UINT(a); - uint ub =3D GPOINTER_TO_UINT(b); - return (ua > ub) - (ua < ub); -} - -static void destroy_grant(gpointer pgnt) -{ - PersistentGrant *grant =3D pgnt; - struct XenBlkDev *blkdev =3D grant->blkdev; - struct XenDevice *xendev =3D &blkdev->xendev; - - xen_be_unmap_grant_ref(xendev, grant->page); - grant->blkdev->persistent_gnt_count--; - xen_pv_printf(xendev, 3, "unmapped grant %p\n", grant->page); - g_free(grant); -} - -static void remove_persistent_region(gpointer data, gpointer dev) -{ - PersistentRegion *region =3D data; - struct XenBlkDev *blkdev =3D dev; - struct XenDevice *xendev =3D &blkdev->xendev; - - xen_be_unmap_grant_refs(xendev, region->addr, region->num); - xen_pv_printf(xendev, 3, "unmapped grant region %p with %d pages\n", - region->addr, region->num); - g_free(region); -} - static struct ioreq *ioreq_start(struct XenBlkDev *blkdev) { struct ioreq *ioreq =3D NULL; @@ -254,7 +193,6 @@ static int ioreq_parse(struct ioreq *ioreq) ioreq->req.handle, ioreq->req.id, ioreq->req.sector_numb= er); switch (ioreq->req.operation) { case BLKIF_OP_READ: - ioreq->prot =3D PROT_WRITE; /* to memory */ break; case BLKIF_OP_FLUSH_DISKCACHE: ioreq->presync =3D 1; @@ -263,7 +201,6 @@ static int ioreq_parse(struct ioreq *ioreq) } /* fall through */ case BLKIF_OP_WRITE: - ioreq->prot =3D PROT_READ; /* from memory */ break; case BLKIF_OP_DISCARD: return 0; @@ -310,171 +247,6 @@ err: return -1; } =20 -static void ioreq_unmap(struct ioreq *ioreq) -{ - struct XenBlkDev *blkdev =3D ioreq->blkdev; - struct XenDevice *xendev =3D &blkdev->xendev; - int i; - - if (ioreq->num_unmap =3D=3D 0 || ioreq->mapped =3D=3D 0) { - return; - } - if (batch_maps) { - if (!ioreq->pages) { - return; - } - xen_be_unmap_grant_refs(xendev, ioreq->pages, ioreq->num_unmap); - ioreq->blkdev->cnt_map -=3D ioreq->num_unmap; - ioreq->pages =3D NULL; - } else { - for (i =3D 0; i < ioreq->num_unmap; i++) { - if (!ioreq->page[i]) { - continue; - } - xen_be_unmap_grant_ref(xendev, ioreq->page[i]); - ioreq->blkdev->cnt_map--; - ioreq->page[i] =3D NULL; - } - } - ioreq->mapped =3D 0; -} - -static int ioreq_map(struct ioreq *ioreq) -{ - struct XenBlkDev *blkdev =3D ioreq->blkdev; - struct XenDevice *xendev =3D &blkdev->xendev; - uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - int i, j, new_maps =3D 0; - PersistentGrant *grant; - PersistentRegion *region; - /* refs variable will contain the information necessary - * to map the grants that are needed to fulfill this request. - * - * After mapping the needed grants, the page array will contain the - * memory address of each granted page in the order specified in ioreq - * (disregarding if it's a persistent grant or not). - */ - - if (ioreq->v.niov =3D=3D 0 || ioreq->mapped =3D=3D 1) { - return 0; - } - if (ioreq->blkdev->feature_persistent) { - for (i =3D 0; i < ioreq->v.niov; i++) { - grant =3D g_tree_lookup(ioreq->blkdev->persistent_gnts, - GUINT_TO_POINTER(ioreq->refs[i])); - - if (grant !=3D NULL) { - page[i] =3D grant->page; - xen_pv_printf(&ioreq->blkdev->xendev, 3, - "using persistent-grant %" PRIu32 "\n", - ioreq->refs[i]); - } else { - /* Add the grant to the list of grants that - * should be mapped - */ - refs[new_maps] =3D ioreq->refs[i]; - page[i] =3D NULL; - new_maps++; - } - } - /* Set the protection to RW, since grants may be reused later - * with a different protection than the one needed for this request - */ - ioreq->prot =3D PROT_WRITE | PROT_READ; - } else { - /* All grants in the request should be mapped */ - memcpy(refs, ioreq->refs, sizeof(refs)); - memset(page, 0, sizeof(page)); - new_maps =3D ioreq->v.niov; - } - - if (batch_maps && new_maps) { - ioreq->pages =3D xen_be_map_grant_refs(xendev, refs, new_maps, - ioreq->prot); - if (ioreq->pages =3D=3D NULL) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "can't map %d grant refs (%s, %d maps)\n", - new_maps, strerror(errno), ioreq->blkdev->cnt_ma= p); - return -1; - } - for (i =3D 0, j =3D 0; i < ioreq->v.niov; i++) { - if (page[i] =3D=3D NULL) { - page[i] =3D ioreq->pages + (j++) * XC_PAGE_SIZE; - } - } - ioreq->blkdev->cnt_map +=3D new_maps; - } else if (new_maps) { - for (i =3D 0; i < new_maps; i++) { - ioreq->page[i] =3D xen_be_map_grant_ref(xendev, refs[i], - ioreq->prot); - if (ioreq->page[i] =3D=3D NULL) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, - "can't map grant ref %d (%s, %d maps)\n", - refs[i], strerror(errno), ioreq->blkdev->cnt= _map); - ioreq->mapped =3D 1; - ioreq_unmap(ioreq); - return -1; - } - ioreq->blkdev->cnt_map++; - } - for (i =3D 0, j =3D 0; i < ioreq->v.niov; i++) { - if (page[i] =3D=3D NULL) { - page[i] =3D ioreq->page[j++]; - } - } - } - if (ioreq->blkdev->feature_persistent && new_maps !=3D 0 && - (!batch_maps || (ioreq->blkdev->persistent_gnt_count + new_maps <= =3D - ioreq->blkdev->max_grants))) { - /* - * If we are using persistent grants and batch mappings only - * add the new maps to the list of persistent grants if the whole - * area can be persistently mapped. - */ - if (batch_maps) { - region =3D g_malloc0(sizeof(*region)); - region->addr =3D ioreq->pages; - region->num =3D new_maps; - ioreq->blkdev->persistent_regions =3D g_slist_append( - ioreq->blkdev->persistent_regi= ons, - region); - } - while ((ioreq->blkdev->persistent_gnt_count < ioreq->blkdev->max_g= rants) - && new_maps) { - /* Go through the list of newly mapped grants and add as many - * as possible to the list of persistently mapped grants. - * - * Since we start at the end of ioreq->page(s), we only need - * to decrease new_maps to prevent this granted pages from - * being unmapped in ioreq_unmap. - */ - grant =3D g_malloc0(sizeof(*grant)); - new_maps--; - if (batch_maps) { - grant->page =3D ioreq->pages + (new_maps) * XC_PAGE_SIZE; - } else { - grant->page =3D ioreq->page[new_maps]; - } - grant->blkdev =3D ioreq->blkdev; - xen_pv_printf(&ioreq->blkdev->xendev, 3, - "adding grant %" PRIu32 " page: %p\n", - refs[new_maps], grant->page); - g_tree_insert(ioreq->blkdev->persistent_gnts, - GUINT_TO_POINTER(refs[new_maps]), - grant); - ioreq->blkdev->persistent_gnt_count++; - } - assert(!batch_maps || new_maps =3D=3D 0); - } - for (i =3D 0; i < ioreq->v.niov; i++) { - ioreq->v.iov[i].iov_base +=3D (uintptr_t)page[i]; - } - ioreq->mapped =3D 1; - ioreq->num_unmap =3D new_maps; - return 0; -} - static void ioreq_free_copy_buffers(struct ioreq *ioreq) { int i; @@ -570,32 +342,28 @@ static void qemu_aio_complete(void *opaque, int ret) goto done; } =20 - if (xen_feature_grant_copy) { - switch (ioreq->req.operation) { - case BLKIF_OP_READ: - /* in case of failure ioreq->aio_errors is increased */ - if (ret =3D=3D 0) { - ioreq_grant_copy(ioreq); - } - ioreq_free_copy_buffers(ioreq); - break; - case BLKIF_OP_WRITE: - case BLKIF_OP_FLUSH_DISKCACHE: - if (!ioreq->req.nr_segments) { - break; - } - ioreq_free_copy_buffers(ioreq); - break; - default: + switch (ioreq->req.operation) { + case BLKIF_OP_READ: + /* in case of failure ioreq->aio_errors is increased */ + if (ret =3D=3D 0) { + ioreq_grant_copy(ioreq); + } + ioreq_free_copy_buffers(ioreq); + break; + case BLKIF_OP_WRITE: + case BLKIF_OP_FLUSH_DISKCACHE: + if (!ioreq->req.nr_segments) { break; } + ioreq_free_copy_buffers(ioreq); + break; + default: + break; } =20 ioreq->status =3D ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY; - if (!xen_feature_grant_copy) { - ioreq_unmap(ioreq); - } ioreq_finish(ioreq); + switch (ioreq->req.operation) { case BLKIF_OP_WRITE: case BLKIF_OP_FLUSH_DISKCACHE: @@ -655,18 +423,13 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; =20 - if (xen_feature_grant_copy) { - ioreq_init_copy_buffers(ioreq); - if (ioreq->req.nr_segments && (ioreq->req.operation =3D=3D BLKIF_O= P_WRITE || - ioreq->req.operation =3D=3D BLKIF_OP_FLUSH_DISKCACHE) && - ioreq_grant_copy(ioreq)) { - ioreq_free_copy_buffers(ioreq); - goto err; - } - } else { - if (ioreq->req.nr_segments && ioreq_map(ioreq)) { - goto err; - } + ioreq_init_copy_buffers(ioreq); + if (ioreq->req.nr_segments && + (ioreq->req.operation =3D=3D BLKIF_OP_WRITE || + ioreq->req.operation =3D=3D BLKIF_OP_FLUSH_DISKCACHE) && + ioreq_grant_copy(ioreq)) { + ioreq_free_copy_buffers(ioreq); + goto err; } =20 ioreq->aio_inflight++; @@ -707,9 +470,6 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) } default: /* unknown operation (shouldn't happen -- parse catches this) */ - if (!xen_feature_grant_copy) { - ioreq_unmap(ioreq); - } goto err; } =20 @@ -895,10 +655,6 @@ static void blk_alloc(struct XenDevice *xendev) =20 blkdev->ctx =3D iothread_get_aio_context(blkdev->iothread); blkdev->bh =3D aio_bh_new(blkdev->ctx, blk_bh, blkdev); - - if (xen_mode !=3D XEN_EMULATE) { - batch_maps =3D 1; - } } =20 static void blk_parse_discard(struct XenBlkDev *blkdev) @@ -981,15 +737,10 @@ static int blk_init(struct XenDevice *xendev) =20 blkdev->file_blk =3D BLOCK_SIZE; =20 - xen_pv_printf(&blkdev->xendev, 3, "grant copy operation %s\n", - xen_feature_grant_copy ? "enabled" : "disabled"); - /* fill info * blk_connect supplies sector-size and sectors */ xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1); - xenstore_write_be_int(&blkdev->xendev, "feature-persistent", - !xen_feature_grant_copy); xenstore_write_be_int(&blkdev->xendev, "info", info); =20 xenstore_write_be_int(&blkdev->xendev, "max-ring-page-order", @@ -1016,19 +767,10 @@ out_error: return -1; } =20 -/* - * We need to account for the grant allocations requiring contiguous - * chunks; the worst case number would be - * max_req * max_seg + (max_req - 1) * (max_seg - 1) + 1, - * but in order to keep things simple just use - * 2 * max_req * max_seg. - */ -#define MAX_GRANTS(max_req, max_seg) (2 * (max_req) * (max_seg)) - static int blk_connect(struct XenDevice *xendev) { struct XenBlkDev *blkdev =3D container_of(xendev, struct XenBlkDev, xe= ndev); - int pers, index, qflags; + int index, qflags; bool readonly =3D true; bool writethrough =3D true; int order, ring_ref; @@ -1150,11 +892,6 @@ static int blk_connect(struct XenDevice *xendev) &blkdev->xendev.remote_port) =3D=3D -1) { return -1; } - if (xenstore_read_fe_int(&blkdev->xendev, "feature-persistent", &pers)= ) { - blkdev->feature_persistent =3D FALSE; - } else { - blkdev->feature_persistent =3D !!pers; - } =20 if (!blkdev->xendev.protocol) { blkdev->protocol =3D BLKIF_PROTOCOL_NATIVE; @@ -1189,11 +926,8 @@ static int blk_connect(struct XenDevice *xendev) return -1; } =20 - /* Calculate the maximum number of grants needed by ioreqs */ - max_grants =3D MAX_GRANTS(blkdev->max_requests, - BLKIF_MAX_SEGMENTS_PER_REQUEST); /* Add on the number needed for the ring pages */ - max_grants +=3D blkdev->nr_ring_ref; + max_grants =3D blkdev->nr_ring_ref; =20 xen_be_set_max_grant_refs(xendev, max_grants); =20 @@ -1204,8 +938,6 @@ static int blk_connect(struct XenDevice *xendev) return -1; } =20 - blkdev->cnt_map++; - switch (blkdev->protocol) { case BLKIF_PROTOCOL_NATIVE: { @@ -1229,19 +961,6 @@ static int blk_connect(struct XenDevice *xendev) } } =20 - if (blkdev->feature_persistent) { - /* Init persistent grants */ - blkdev->max_grants =3D blkdev->max_requests * - BLKIF_MAX_SEGMENTS_PER_REQUEST; - blkdev->persistent_gnts =3D g_tree_new_full((GCompareDataFunc)int_= cmp, - NULL, NULL, - batch_maps ? - (GDestroyNotify)g_free : - (GDestroyNotify)destroy_grant= ); - blkdev->persistent_regions =3D NULL; - blkdev->persistent_gnt_count =3D 0; - } - blk_set_aio_context(blkdev->blk, blkdev->ctx); =20 xen_be_bind_evtchn(&blkdev->xendev); @@ -1274,29 +993,8 @@ static void blk_disconnect(struct XenDevice *xendev) if (blkdev->sring) { xen_be_unmap_grant_refs(xendev, blkdev->sring, blkdev->nr_ring_ref); - blkdev->cnt_map--; blkdev->sring =3D NULL; } - - /* - * Unmap persistent grants before switching to the closed state - * so the frontend can free them. - * - * In the !batch_maps case g_tree_destroy will take care of unmapping - * the grant, but in the batch_maps case we need to iterate over every - * region in persistent_regions and unmap it. - */ - if (blkdev->feature_persistent) { - g_tree_destroy(blkdev->persistent_gnts); - assert(batch_maps || blkdev->persistent_gnt_count =3D=3D 0); - if (batch_maps) { - blkdev->persistent_gnt_count =3D 0; - g_slist_foreach(blkdev->persistent_regions, - (GFunc)remove_persistent_region, blkdev); - g_slist_free(blkdev->persistent_regions); - } - blkdev->feature_persistent =3D false; - } } =20 static int blk_free(struct XenDevice *xendev) --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015403398598.9826451290818; Tue, 22 May 2018 11:56:43 -0700 (PDT) Received: from localhost ([::1]:57385 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCSg-0000UR-Jy for importer@patchew.org; Tue, 22 May 2018 14:56:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50749) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fE-2I for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ6-0007SE-VR for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43654) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ6-0007Rj-Pk for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:48 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9DAEE2087D; Tue, 22 May 2018 18:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014807; bh=/M7cDh9P7Iit1R94SGjkcfcE0OslIVrIIvU+4WUwJr0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UYpIbdUTViF4wv5J8HHwuFvhHaC6Zb3s5jQonqmDOtv8I8kcx5SDwpdlkLGRpUzv/ 0GcBy6qYXr39kgg1uFzsRHxUwbG8exyzW9H85UvaWvHuHBUmV1zKDmfXCaI+jWrioK +TYHARS6BxS8+zI9QLMoAvV1him2bmWf+kwAntKI= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:40 -0700 Message-Id: <1527014802-11289-13-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 13/15] xen_backend: make the xen_feature_grant_copy flag private X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant There is no longer any use of this flag outside of the xen_backend code. Signed-off-by: Paul Durrant Acked-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/xen/xen_backend.c | 2 +- include/hw/xen/xen_backend.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 3c3fc2c..9a8e877 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -44,9 +44,9 @@ BusState *xen_sysbus; /* public */ struct xs_handle *xenstore =3D NULL; const char *xen_protocol; -bool xen_feature_grant_copy; =20 /* private */ +static bool xen_feature_grant_copy; static int debug; =20 int xenstore_write_be_str(struct XenDevice *xendev, const char *node, cons= t char *val) diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 29bf1c3..9c17fdd 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -16,7 +16,6 @@ /* variables */ extern struct xs_handle *xenstore; extern const char *xen_protocol; -extern bool xen_feature_grant_copy; extern DeviceState *xen_sysdev; extern BusState *xen_sysbus; =20 --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015407625188.70943908084394; Tue, 22 May 2018 11:56:47 -0700 (PDT) Received: from localhost ([::1]:57386 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCSk-0000Yu-Pb for importer@patchew.org; Tue, 22 May 2018 14:56:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJ9-0001fN-5D for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ7-0007SP-9o for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:51 -0400 Received: from mail.kernel.org ([198.145.29.99]:43668) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ7-0007Rz-2Q for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:49 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3DCA2087A; Tue, 22 May 2018 18:46:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014808; bh=44XX7DTHyN+3CrOh92I4rhmTr6fnDeOkZl4/zQbpoYk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NI4eWYxsVK99vypKDFVGVU8O0GmiX9lbu1sP4fa0ZQDrm/6qZ3R0+WfLI4T+rxRgo KfUGi7v7pf0vJmaop6egRbeNoIS9STNtT1TjBMH5WxKbJRhPIdTp+wuEoGWd86IQCT uKR4JUNOXBPMrPnESCc7F/FsVOK/OadOVzGZDBZU= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:41 -0700 Message-Id: <1527014802-11289-14-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 14/15] xen_disk: use a single entry iovec X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Since xen_disk now always copies data to and from a guest there is no need to maintain a vector entry corresponding to every page of a request. This means there is less per-request state to maintain so the ioreq structure can shrink significantly. Signed-off-by: Paul Durrant Acked-by: Anthony Perard Signed-off-by: Stefano Stabellini --- hw/block/xen_disk.c | 76 +++++++++++++++----------------------------------= ---- 1 file changed, 21 insertions(+), 55 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 28be8b6..28651c5 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -46,13 +46,10 @@ struct ioreq { /* parsed request */ off_t start; QEMUIOVector v; + void *buf; + size_t size; int presync; =20 - /* grant mapping */ - uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST]; - void *pages; - /* aio status */ int aio_inflight; int aio_errors; @@ -110,12 +107,10 @@ static void ioreq_reset(struct ioreq *ioreq) memset(&ioreq->req, 0, sizeof(ioreq->req)); ioreq->status =3D 0; ioreq->start =3D 0; + ioreq->buf =3D NULL; + ioreq->size =3D 0; ioreq->presync =3D 0; =20 - memset(ioreq->refs, 0, sizeof(ioreq->refs)); - memset(ioreq->page, 0, sizeof(ioreq->page)); - ioreq->pages =3D NULL; - ioreq->aio_inflight =3D 0; ioreq->aio_errors =3D 0; =20 @@ -138,7 +133,7 @@ static struct ioreq *ioreq_start(struct XenBlkDev *blkd= ev) ioreq =3D g_malloc0(sizeof(*ioreq)); ioreq->blkdev =3D blkdev; blkdev->requests_total++; - qemu_iovec_init(&ioreq->v, BLKIF_MAX_SEGMENTS_PER_REQUEST); + qemu_iovec_init(&ioreq->v, 1); } else { /* get one from freelist */ ioreq =3D QLIST_FIRST(&blkdev->freelist); @@ -183,7 +178,6 @@ static void ioreq_release(struct ioreq *ioreq, bool fin= ish) static int ioreq_parse(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; - uintptr_t mem; size_t len; int i; =20 @@ -230,13 +224,10 @@ static int ioreq_parse(struct ioreq *ioreq) goto err; } =20 - ioreq->refs[i] =3D ioreq->req.seg[i].gref; - - mem =3D ioreq->req.seg[i].first_sect * blkdev->file_blk; len =3D (ioreq->req.seg[i].last_sect - ioreq->req.seg[i].first_sec= t + 1) * blkdev->file_blk; - qemu_iovec_add(&ioreq->v, (void*)mem, len); + ioreq->size +=3D len; } - if (ioreq->start + ioreq->v.size > blkdev->file_size) { + if (ioreq->start + ioreq->size > blkdev->file_size) { xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of fil= e\n"); goto err; } @@ -247,35 +238,6 @@ err: return -1; } =20 -static void ioreq_free_copy_buffers(struct ioreq *ioreq) -{ - int i; - - for (i =3D 0; i < ioreq->v.niov; i++) { - ioreq->page[i] =3D NULL; - } - - qemu_vfree(ioreq->pages); -} - -static int ioreq_init_copy_buffers(struct ioreq *ioreq) -{ - int i; - - if (ioreq->v.niov =3D=3D 0) { - return 0; - } - - ioreq->pages =3D qemu_memalign(XC_PAGE_SIZE, ioreq->v.niov * XC_PAGE_S= IZE); - - for (i =3D 0; i < ioreq->v.niov; i++) { - ioreq->page[i] =3D ioreq->pages + i * XC_PAGE_SIZE; - ioreq->v.iov[i].iov_base =3D ioreq->page[i]; - } - - return 0; -} - static int ioreq_grant_copy(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; @@ -284,25 +246,27 @@ static int ioreq_grant_copy(struct ioreq *ioreq) int i, count, rc; int64_t file_blk =3D ioreq->blkdev->file_blk; bool to_domain =3D (ioreq->req.operation =3D=3D BLKIF_OP_READ); + void *virt =3D ioreq->buf; =20 - if (ioreq->v.niov =3D=3D 0) { + if (ioreq->req.nr_segments =3D=3D 0) { return 0; } =20 - count =3D ioreq->v.niov; + count =3D ioreq->req.nr_segments; =20 for (i =3D 0; i < count; i++) { if (to_domain) { - segs[i].dest.foreign.ref =3D ioreq->refs[i]; + segs[i].dest.foreign.ref =3D ioreq->req.seg[i].gref; segs[i].dest.foreign.offset =3D ioreq->req.seg[i].first_sect *= file_blk; - segs[i].source.virt =3D ioreq->v.iov[i].iov_base; + segs[i].source.virt =3D virt; } else { - segs[i].source.foreign.ref =3D ioreq->refs[i]; + segs[i].source.foreign.ref =3D ioreq->req.seg[i].gref; segs[i].source.foreign.offset =3D ioreq->req.seg[i].first_sect= * file_blk; - segs[i].dest.virt =3D ioreq->v.iov[i].iov_base; + segs[i].dest.virt =3D virt; } segs[i].len =3D (ioreq->req.seg[i].last_sect - ioreq->req.seg[i].first_sect + 1) * file_blk; + virt +=3D segs[i].len; } =20 rc =3D xen_be_copy_grant_refs(xendev, to_domain, segs, count); @@ -348,14 +312,14 @@ static void qemu_aio_complete(void *opaque, int ret) if (ret =3D=3D 0) { ioreq_grant_copy(ioreq); } - ioreq_free_copy_buffers(ioreq); + qemu_vfree(ioreq->buf); break; case BLKIF_OP_WRITE: case BLKIF_OP_FLUSH_DISKCACHE: if (!ioreq->req.nr_segments) { break; } - ioreq_free_copy_buffers(ioreq); + qemu_vfree(ioreq->buf); break; default: break; @@ -423,12 +387,12 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; =20 - ioreq_init_copy_buffers(ioreq); + ioreq->buf =3D qemu_memalign(XC_PAGE_SIZE, ioreq->size); if (ioreq->req.nr_segments && (ioreq->req.operation =3D=3D BLKIF_OP_WRITE || ioreq->req.operation =3D=3D BLKIF_OP_FLUSH_DISKCACHE) && ioreq_grant_copy(ioreq)) { - ioreq_free_copy_buffers(ioreq); + qemu_vfree(ioreq->buf); goto err; } =20 @@ -440,6 +404,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) =20 switch (ioreq->req.operation) { case BLKIF_OP_READ: + qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size); block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct, ioreq->v.size, BLOCK_ACCT_READ); ioreq->aio_inflight++; @@ -452,6 +417,7 @@ static int ioreq_runio_qemu_aio(struct ioreq *ioreq) break; } =20 + qemu_iovec_add(&ioreq->v, ioreq->buf, ioreq->size); block_acct_start(blk_get_stats(blkdev->blk), &ioreq->acct, ioreq->v.size, ioreq->req.operation =3D=3D BLKIF_OP_WRITE ? --=20 1.9.1 From nobody Sun Apr 28 23:47:58 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=kernel.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1527015639204349.91873809810045; Tue, 22 May 2018 12:00:39 -0700 (PDT) Received: from localhost ([::1]:57400 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCWM-0002rS-Ra for importer@patchew.org; Tue, 22 May 2018 15:00:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fLCJA-0001gK-B3 for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fLCJ7-0007Sf-Mr for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:43682) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fLCJ7-0007S9-Di for qemu-devel@nongnu.org; Tue, 22 May 2018 14:46:49 -0400 Received: from sstabellini-ThinkPad-X260.xilinx.com (unknown [149.199.62.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5699920876; Tue, 22 May 2018 18:46:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527014808; bh=vCfHCQcBP1Bo1W4g5wmovNCK78G9UbcsZ3qFQwKHt04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMEqipCIOBd8eMnf5VbxkFBI4MLSJ3bI2nEn4fOtxsGWv6RKljcqTtfKSrvsevG8f ixXUnxmeLo44j5+E2c3MFIeJ5b16Zdq7OfByGqOKHUkFcXOG9ZeIDLihBYqJnvvjda J84cXBXxLZI1pDrbil/J0M1Z8966ULPC9duhjLS8= From: Stefano Stabellini To: peter.maydell@linaro.org, stefanha@gmail.com Date: Tue, 22 May 2018 11:46:42 -0700 Message-Id: <1527014802-11289-15-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 198.145.29.99 Subject: [Qemu-devel] [PULL v2 15/15] xen_disk: be consistent with use of xendev and blkdev->xendev X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sstabellini@kernel.org, qemu-devel@nongnu.org, Paul Durrant , stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Certain functions in xen_disk are called with a pointer to xendev (struct XenDevice *). They then use container_of() to acces the surrounding blkdev (struct XenBlkDev) but then in various places use &blkdev->xendev when use of the original xendev pointer is shorter to express and clearly equivalent. This patch is a purely cosmetic patch which makes sure there is a xendev pointer on stack for any function where the pointer is need on multiple occasions modified those functions to use it consistently. Signed-off-by: Paul Durrant Acked-by: Anthony PERARD Signed-off-by: Stefano Stabellini --- hw/block/xen_disk.c | 90 +++++++++++++++++++++++++++----------------------= ---- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c index 28651c5..9fbc0cd 100644 --- a/hw/block/xen_disk.c +++ b/hw/block/xen_disk.c @@ -178,10 +178,11 @@ static void ioreq_release(struct ioreq *ioreq, bool f= inish) static int ioreq_parse(struct ioreq *ioreq) { struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; size_t len; int i; =20 - xen_pv_printf(&blkdev->xendev, 3, + xen_pv_printf(xendev, 3, "op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId= 64 "\n", ioreq->req.operation, ioreq->req.nr_segments, ioreq->req.handle, ioreq->req.id, ioreq->req.sector_numb= er); @@ -199,28 +200,28 @@ static int ioreq_parse(struct ioreq *ioreq) case BLKIF_OP_DISCARD: return 0; default: - xen_pv_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n= ", + xen_pv_printf(xendev, 0, "error: unknown operation (%d)\n", ioreq->req.operation); goto err; }; =20 if (ioreq->req.operation !=3D BLKIF_OP_READ && blkdev->mode[0] !=3D 'w= ') { - xen_pv_printf(&blkdev->xendev, 0, "error: write req for ro device\= n"); + xen_pv_printf(xendev, 0, "error: write req for ro device\n"); goto err; } =20 ioreq->start =3D ioreq->req.sector_number * blkdev->file_blk; for (i =3D 0; i < ioreq->req.nr_segments; i++) { if (i =3D=3D BLKIF_MAX_SEGMENTS_PER_REQUEST) { - xen_pv_printf(&blkdev->xendev, 0, "error: nr_segments too big\= n"); + xen_pv_printf(xendev, 0, "error: nr_segments too big\n"); goto err; } if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) { - xen_pv_printf(&blkdev->xendev, 0, "error: first > last sector\= n"); + xen_pv_printf(xendev, 0, "error: first > last sector\n"); goto err; } if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >=3D XC_PAGE_SIZE) { - xen_pv_printf(&blkdev->xendev, 0, "error: page crossing\n"); + xen_pv_printf(xendev, 0, "error: page crossing\n"); goto err; } =20 @@ -228,7 +229,7 @@ static int ioreq_parse(struct ioreq *ioreq) ioreq->size +=3D len; } if (ioreq->start + ioreq->size > blkdev->file_size) { - xen_pv_printf(&blkdev->xendev, 0, "error: access beyond end of fil= e\n"); + xen_pv_printf(xendev, 0, "error: access beyond end of file\n"); goto err; } return 0; @@ -244,7 +245,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq) struct XenDevice *xendev =3D &blkdev->xendev; XenGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST]; int i, count, rc; - int64_t file_blk =3D ioreq->blkdev->file_blk; + int64_t file_blk =3D blkdev->file_blk; bool to_domain =3D (ioreq->req.operation =3D=3D BLKIF_OP_READ); void *virt =3D ioreq->buf; =20 @@ -272,7 +273,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq) rc =3D xen_be_copy_grant_refs(xendev, to_domain, segs, count); =20 if (rc) { - xen_pv_printf(&ioreq->blkdev->xendev, 0, + xen_pv_printf(xendev, 0, "failed to copy data %d\n", rc); ioreq->aio_errors++; return -1; @@ -287,11 +288,12 @@ static void qemu_aio_complete(void *opaque, int ret) { struct ioreq *ioreq =3D opaque; struct XenBlkDev *blkdev =3D ioreq->blkdev; + struct XenDevice *xendev =3D &blkdev->xendev; =20 aio_context_acquire(blkdev->ctx); =20 if (ret !=3D 0) { - xen_pv_printf(&blkdev->xendev, 0, "%s I/O error\n", + xen_pv_printf(xendev, 0, "%s I/O error\n", ioreq->req.operation =3D=3D BLKIF_OP_READ ? "read" := "write"); ioreq->aio_errors++; } @@ -625,16 +627,17 @@ static void blk_alloc(struct XenDevice *xendev) =20 static void blk_parse_discard(struct XenBlkDev *blkdev) { + struct XenDevice *xendev =3D &blkdev->xendev; int enable; =20 blkdev->feature_discard =3D true; =20 - if (xenstore_read_be_int(&blkdev->xendev, "discard-enable", &enable) = =3D=3D 0) { + if (xenstore_read_be_int(xendev, "discard-enable", &enable) =3D=3D 0) { blkdev->feature_discard =3D !!enable; } =20 if (blkdev->feature_discard) { - xenstore_write_be_int(&blkdev->xendev, "feature-discard", 1); + xenstore_write_be_int(xendev, "feature-discard", 1); } } =20 @@ -649,7 +652,7 @@ static int blk_init(struct XenDevice *xendev) /* read xenstore entries */ if (blkdev->params =3D=3D NULL) { char *h =3D NULL; - blkdev->params =3D xenstore_read_be_str(&blkdev->xendev, "params"); + blkdev->params =3D xenstore_read_be_str(xendev, "params"); if (blkdev->params !=3D NULL) { h =3D strchr(blkdev->params, ':'); } @@ -669,18 +672,18 @@ static int blk_init(struct XenDevice *xendev) blkdev->fileproto =3D "vpc"; } if (blkdev->mode =3D=3D NULL) { - blkdev->mode =3D xenstore_read_be_str(&blkdev->xendev, "mode"); + blkdev->mode =3D xenstore_read_be_str(xendev, "mode"); } if (blkdev->type =3D=3D NULL) { - blkdev->type =3D xenstore_read_be_str(&blkdev->xendev, "type"); + blkdev->type =3D xenstore_read_be_str(xendev, "type"); } if (blkdev->dev =3D=3D NULL) { - blkdev->dev =3D xenstore_read_be_str(&blkdev->xendev, "dev"); + blkdev->dev =3D xenstore_read_be_str(xendev, "dev"); } if (blkdev->devtype =3D=3D NULL) { - blkdev->devtype =3D xenstore_read_be_str(&blkdev->xendev, "device-= type"); + blkdev->devtype =3D xenstore_read_be_str(xendev, "device-type"); } - directiosafe =3D xenstore_read_be_str(&blkdev->xendev, "direct-io-safe= "); + directiosafe =3D xenstore_read_be_str(xendev, "direct-io-safe"); blkdev->directiosafe =3D (directiosafe && atoi(directiosafe)); =20 /* do we have all we need? */ @@ -706,10 +709,10 @@ static int blk_init(struct XenDevice *xendev) /* fill info * blk_connect supplies sector-size and sectors */ - xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1); - xenstore_write_be_int(&blkdev->xendev, "info", info); + xenstore_write_be_int(xendev, "feature-flush-cache", 1); + xenstore_write_be_int(xendev, "info", info); =20 - xenstore_write_be_int(&blkdev->xendev, "max-ring-page-order", + xenstore_write_be_int(xendev, "max-ring-page-order", MAX_RING_PAGE_ORDER); =20 blk_parse_discard(blkdev); @@ -761,7 +764,7 @@ static int blk_connect(struct XenDevice *xendev) } =20 /* init qemu block driver */ - index =3D (blkdev->xendev.dev - 202 * 256) / 16; + index =3D (xendev->dev - 202 * 256) / 16; blkdev->dinfo =3D drive_get(IF_XEN, 0, index); if (!blkdev->dinfo) { Error *local_err =3D NULL; @@ -773,11 +776,11 @@ static int blk_connect(struct XenDevice *xendev) } =20 /* setup via xenbus -> create new block driver instance */ - xen_pv_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\= n"); + xen_pv_printf(xendev, 2, "create new bdrv (xenbus setup)\n"); blkdev->blk =3D blk_new_open(blkdev->filename, NULL, options, qflags, &local_err); if (!blkdev->blk) { - xen_pv_printf(&blkdev->xendev, 0, "error: %s\n", + xen_pv_printf(xendev, 0, "error: %s\n", error_get_pretty(local_err)); error_free(local_err); return -1; @@ -785,11 +788,11 @@ static int blk_connect(struct XenDevice *xendev) blk_set_enable_write_cache(blkdev->blk, !writethrough); } else { /* setup via qemu cmdline -> already setup for us */ - xen_pv_printf(&blkdev->xendev, 2, + xen_pv_printf(xendev, 2, "get configured bdrv (cmdline setup)\n"); blkdev->blk =3D blk_by_legacy_dinfo(blkdev->dinfo); if (blk_is_read_only(blkdev->blk) && !readonly) { - xen_pv_printf(&blkdev->xendev, 0, "Unexpected read-only drive"= ); + xen_pv_printf(xendev, 0, "Unexpected read-only drive"); blkdev->blk =3D NULL; return -1; } @@ -802,7 +805,7 @@ static int blk_connect(struct XenDevice *xendev) if (blkdev->file_size < 0) { BlockDriverState *bs =3D blk_bs(blkdev->blk); const char *drv_name =3D bs ? bdrv_get_format_name(bs) : NULL; - xen_pv_printf(&blkdev->xendev, 1, "blk_getlength: %d (%s) | drv %s= \n", + xen_pv_printf(xendev, 1, "blk_getlength: %d (%s) | drv %s\n", (int)blkdev->file_size, strerror(-blkdev->file_size), drv_name ?: "-"); blkdev->file_size =3D 0; @@ -814,15 +817,15 @@ static int blk_connect(struct XenDevice *xendev) blkdev->file_size, blkdev->file_size >> 20); =20 /* Fill in number of sector size and number of sectors */ - xenstore_write_be_int(&blkdev->xendev, "sector-size", blkdev->file_blk= ); - xenstore_write_be_int64(&blkdev->xendev, "sectors", + xenstore_write_be_int(xendev, "sector-size", blkdev->file_blk); + xenstore_write_be_int64(xendev, "sectors", blkdev->file_size / blkdev->file_blk); =20 - if (xenstore_read_fe_int(&blkdev->xendev, "ring-page-order", + if (xenstore_read_fe_int(xendev, "ring-page-order", &order) =3D=3D -1) { blkdev->nr_ring_ref =3D 1; =20 - if (xenstore_read_fe_int(&blkdev->xendev, "ring-ref", + if (xenstore_read_fe_int(xendev, "ring-ref", &ring_ref) =3D=3D -1) { return -1; } @@ -839,7 +842,7 @@ static int blk_connect(struct XenDevice *xendev) return -1; } =20 - if (xenstore_read_fe_int(&blkdev->xendev, key, + if (xenstore_read_fe_int(xendev, key, &ring_ref) =3D=3D -1) { g_free(key); return -1; @@ -854,18 +857,18 @@ static int blk_connect(struct XenDevice *xendev) return -1; } =20 - if (xenstore_read_fe_int(&blkdev->xendev, "event-channel", - &blkdev->xendev.remote_port) =3D=3D -1) { + if (xenstore_read_fe_int(xendev, "event-channel", + &xendev->remote_port) =3D=3D -1) { return -1; } =20 - if (!blkdev->xendev.protocol) { + if (!xendev->protocol) { blkdev->protocol =3D BLKIF_PROTOCOL_NATIVE; - } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_NATIVE) = =3D=3D 0) { + } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_NATIVE) =3D=3D 0)= { blkdev->protocol =3D BLKIF_PROTOCOL_NATIVE; - } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_32) = =3D=3D 0) { + } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_X86_32) =3D=3D 0)= { blkdev->protocol =3D BLKIF_PROTOCOL_X86_32; - } else if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_64) = =3D=3D 0) { + } else if (strcmp(xendev->protocol, XEN_IO_PROTO_ABI_X86_64) =3D=3D 0)= { blkdev->protocol =3D BLKIF_PROTOCOL_X86_64; } else { blkdev->protocol =3D BLKIF_PROTOCOL_NATIVE; @@ -896,7 +899,6 @@ static int blk_connect(struct XenDevice *xendev) max_grants =3D blkdev->nr_ring_ref; =20 xen_be_set_max_grant_refs(xendev, max_grants); - blkdev->sring =3D xen_be_map_grant_refs(xendev, blkdev->ring_ref, blkdev->nr_ring_ref, PROT_READ | PROT_WRITE); @@ -929,12 +931,12 @@ static int blk_connect(struct XenDevice *xendev) =20 blk_set_aio_context(blkdev->blk, blkdev->ctx); =20 - xen_be_bind_evtchn(&blkdev->xendev); + xen_be_bind_evtchn(xendev); =20 - xen_pv_printf(&blkdev->xendev, 1, "ok: proto %s, nr-ring-ref %u, " + xen_pv_printf(xendev, 1, "ok: proto %s, nr-ring-ref %u, " "remote port %d, local port %d\n", - blkdev->xendev.protocol, blkdev->nr_ring_ref, - blkdev->xendev.remote_port, blkdev->xendev.local_port); + xendev->protocol, blkdev->nr_ring_ref, + xendev->remote_port, xendev->local_port); return 0; } =20 @@ -952,7 +954,7 @@ static void blk_disconnect(struct XenDevice *xendev) blk_unref(blkdev->blk); blkdev->blk =3D NULL; } - xen_pv_unbind_evtchn(&blkdev->xendev); + xen_pv_unbind_evtchn(xendev); =20 aio_context_release(blkdev->ctx); =20 --=20 1.9.1