From patchwork Tue Aug 2 14:06:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paulina Szubarczyk X-Patchwork-Id: 9257565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E93F860865 for ; Tue, 2 Aug 2016 14:09:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D872B276AE for ; Tue, 2 Aug 2016 14:09:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD18D28536; Tue, 2 Aug 2016 14:09:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 20199276AE for ; Tue, 2 Aug 2016 14:09:33 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUaLS-0001bI-Rz; Tue, 02 Aug 2016 14:06:58 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bUaLR-0001ai-7O for xen-devel@lists.xenproject.org; Tue, 02 Aug 2016 14:06:57 +0000 Received: from [193.109.254.147] by server-10.bemta-14.messagelabs.com id 7C/40-03469-009A0A75; Tue, 02 Aug 2016 14:06:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrEIsWRWlGSWpSXmKPExsVyMfS6o+7/FQv CDSauU7X4vmUykwOjx+EPV1gCGKNYM/OS8isSWDMabj5kLvgZWtF9uIOpgXGdfRcjF4eQwHRG iTtf3zGCOCwCL1kkJvScZQVxJAT6WSWOfFgE5HACOTESu1+vZ4ewSyRe7lnHCGILCWhJXFq5g gVi1CYmib9zLjGDJNgEzCRmTv7JAmKLCChJ3Fs1mQnEZhZ4wijxdo1LFyMHh7CAs8SOE94gYR YBVYkT0y6CzeQV8JI42DGPCWKXnMTJY5PBbuAU8JaY/nYdM8ReL4mvbTtZJzAKLGBkWMWoUZx aVJZapGtorpdUlJmeUZKbmJmja2hoopebWlycmJ6ak5hUrJecn7uJERha9QwMjDsYf572PMQo ycGkJMrr8mV+uBBfUn5KZUZicUZ8UWlOavEhRg0ODoG+NasvMEqx5OXnpSpJ8HYvXxAuJFiUm p5akZaZAwx+mFIJDh4lEV5hkDRvcUFibnFmOkTqFKMxx5bf19YycWybem8tkxDYJClx3k6QUg GQ0ozSPLhBsKi8xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUUmYtxpkCk9mXgncvldApzABnXL CAOyUkkSElFQDY0fbunORy2Y/s+10yG68r/V/os7KJtmJL5dvfNB24FffITOr+yEfBA6u2sEV U/0pq+2X8F/JKXf+mJ8OiNW1niIYviXh6h9BrTWTnn/Ludl8wLqe/VZQE0NZ14uk8s0C/ukfr hqm/d3AzPjIbGe53XrWP5E3Tl7jbjFiZfv0Lixi6uRVf9oz+JVYijMSDbWYi4oTARFdJtbFAg AA X-Env-Sender: paulinaszubarczyk@gmail.com X-Msg-Ref: server-9.tower-27.messagelabs.com!1470146814!57340531!1 X-Originating-IP: [209.85.215.65] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2043 invoked from network); 2 Aug 2016 14:06:55 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-9.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 2 Aug 2016 14:06:55 -0000 Received: by mail-lf0-f65.google.com with SMTP id 33so10133624lfw.3 for ; Tue, 02 Aug 2016 07:06:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6Euy48FNKSKxjmChdulwXrjkRie5AOUAHfbC16dAk3o=; b=sfWieIj6f3k0BNLULsbNzglFaVC2xgSi72icTxmRC3VJzzPtd1kHic7YDXlEo7km/X ZkEy10AtAcOo2P4BV5lE6a2vfId03pKzbs2vJSz0bfsuSXS2Szuyu3dP1TUkVBElrKA9 nqwhsUjNIQ8LD4IXtZWNpN/8FLd/A9ph4QDXurHU9Qd0V1UlSUo3fkbuzs1LEVV4sl1I vtFsy+nWbKXuhiOPKfqER0rrP2rRKjk5ubBi1+5q4HlGFuDOmZNU+x5sy7nir0mDkHDv 2hDZM7CpG6bCRROKHHFAODJZm6pvUB6mHdC4tJxHMr8RVgdGuDXcUk7MT7luFSV1S+uf RnZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6Euy48FNKSKxjmChdulwXrjkRie5AOUAHfbC16dAk3o=; b=KtGnvh0ToMxl38zs4GBlLEaiFOSZgcbkRBVbBiID8G9tkhMlH3BL23768V9Pyc5OdZ +v/TOERkKEqWlUbPFu6nKaWHckrkanEymFxMOGrCTeiOh+d4YeeWPPhznInoXpknY1w7 IDveQxvYTUE8xj+sI6/pmapXT6Y5iLWNGIs7eUP0oGs8Luxn6lwiLaoj98XAF+nyEapE w3kcgvAJJoP/+F1CzqpCUWN9hus/9HjM64HwNE78IKzG/GVaT/C4UWqdmSIlwiGIjYJS sJKkBetCqc3/h+glvfzlhtQdvvXkyD/o91S2N5Qtc1vPFKRjL2HNYumTQh6O4bC9s/+n 9Fyw== X-Gm-Message-State: AEkoouvxxGr6sB6J5PAijPQITiWANpetg8hfNF4CtA/CZO64hN7RqG1cmuh1SPJ2hnjxNw== X-Received: by 10.46.0.5 with SMTP id 5mr19144044lja.59.1470146814301; Tue, 02 Aug 2016 07:06:54 -0700 (PDT) Received: from paulina.NAT.bialapodlaska.vectranet.pl (088156138244.dynamic-ra-01.vectranet.pl. [88.156.138.244]) by smtp.gmail.com with ESMTPSA id u11sm524634lja.12.2016.08.02.07.06.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Aug 2016 07:06:53 -0700 (PDT) From: Paulina Szubarczyk To: xen-devel@lists.xenproject.org Date: Tue, 2 Aug 2016 16:06:29 +0200 Message-Id: <1470146790-6168-2-git-send-email-paulinaszubarczyk@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1470146790-6168-1-git-send-email-paulinaszubarczyk@gmail.com> References: <1470146790-6168-1-git-send-email-paulinaszubarczyk@gmail.com> Cc: sstabellini@kernel.org, wei.liu2@citrix.com, Paulina Szubarczyk , ian.jackson@eu.citrix.com, qemu-devel@nongnu.org, david.vrabel@citrix.com, anthony.perard@citrix.com, roger.pau@citrix.com Subject: [Xen-devel] [PATCH v4 1/2] Interface for grant copy operation in libs. X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP In a linux part an ioctl(gntdev, IOCTL_GNTDEV_GRANT_COPY, ..) system call is invoked. In mini-os the operation is yet not implemented. For the OSs that does not implement gnttab the call of the grant copy operation causes abort. Signed-off-by: Paulina Szubarczyk Reviewed-by: David Vrabel --- Changes since v3: - revert to cast from xengnttab_grant_copy_segment_t to ioctl_gntdev_grant_copy. - added compile-time check to compare the libs xengnttab_grant_copy_segment_t with the ioctl structure. The patch relies on Wei patch introducing XENGNTTAB_BUILD_BUG_ON in libs/gnttab. --- tools/include/xen-sys/Linux/gntdev.h | 21 ++++++++++ tools/libs/gnttab/Makefile | 2 +- tools/libs/gnttab/gnttab_core.c | 6 +++ tools/libs/gnttab/gnttab_unimp.c | 6 +++ tools/libs/gnttab/include/xengnttab.h | 28 +++++++++++++ tools/libs/gnttab/libxengnttab.map | 5 +++ tools/libs/gnttab/linux.c | 79 +++++++++++++++++++++++++++++++++++ tools/libs/gnttab/minios.c | 6 +++ tools/libs/gnttab/private.h | 4 ++ 9 files changed, 156 insertions(+), 1 deletion(-) diff --git a/tools/include/xen-sys/Linux/gntdev.h b/tools/include/xen-sys/Linux/gntdev.h index caf6fb4..0ca07c9 100644 --- a/tools/include/xen-sys/Linux/gntdev.h +++ b/tools/include/xen-sys/Linux/gntdev.h @@ -147,4 +147,25 @@ struct ioctl_gntdev_unmap_notify { /* Send an interrupt on the indicated event channel */ #define UNMAP_NOTIFY_SEND_EVENT 0x2 +struct ioctl_gntdev_grant_copy_segment { + union { + void *virt; + struct { + uint32_t ref; + uint16_t offset; + uint16_t domid; + } foreign; + } source, dest; + uint16_t len; + uint16_t flags; + int16_t status; +}; + +#define IOCTL_GNTDEV_GRANT_COPY \ +_IOC(_IOC_NONE, 'G', 8, sizeof(struct ioctl_gntdev_grant_copy)) +struct ioctl_gntdev_grant_copy { + unsigned int count; + struct ioctl_gntdev_grant_copy_segment *segments; +}; + #endif /* __LINUX_PUBLIC_GNTDEV_H__ */ diff --git a/tools/libs/gnttab/Makefile b/tools/libs/gnttab/Makefile index af64542..95c2cd8 100644 --- a/tools/libs/gnttab/Makefile +++ b/tools/libs/gnttab/Makefile @@ -2,7 +2,7 @@ XEN_ROOT = $(CURDIR)/../../.. include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 -MINOR = 0 +MINOR = 1 SHLIB_LDFLAGS += -Wl,--version-script=libxengnttab.map CFLAGS += -Werror -Wmissing-prototypes diff --git a/tools/libs/gnttab/gnttab_core.c b/tools/libs/gnttab/gnttab_core.c index 5d0474d..968c833 100644 --- a/tools/libs/gnttab/gnttab_core.c +++ b/tools/libs/gnttab/gnttab_core.c @@ -113,6 +113,12 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count) return osdep_gnttab_unmap(xgt, start_address, count); } +int xengnttab_grant_copy(xengnttab_handle *xgt, + uint32_t count, + xengnttab_grant_copy_segment_t *segs) +{ + return osdep_gnttab_grant_copy(xgt, count, segs); +} /* * Local variables: * mode: C diff --git a/tools/libs/gnttab/gnttab_unimp.c b/tools/libs/gnttab/gnttab_unimp.c index b3a4a20..829eced 100644 --- a/tools/libs/gnttab/gnttab_unimp.c +++ b/tools/libs/gnttab/gnttab_unimp.c @@ -78,6 +78,12 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count) abort(); } +int xengnttab_copy_grant(xengnttab_handle *xgt, + uint32_t count, + xengnttab_copy_grant_segment_t *segs) +{ + abort(); +} /* * Local variables: * mode: C diff --git a/tools/libs/gnttab/include/xengnttab.h b/tools/libs/gnttab/include/xengnttab.h index 0431dcf..949fd9e 100644 --- a/tools/libs/gnttab/include/xengnttab.h +++ b/tools/libs/gnttab/include/xengnttab.h @@ -258,6 +258,34 @@ int xengnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count); int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t nr_grants); +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; + +/** + * Copy memory from or to grant references. The information of each operations + * are contained in 'xengnttab_grant_copy_segment_t'. The @flag value indicate + * the direction of an operation (GNTCOPY_source_gref\GNTCOPY_dest_gref). + * + * The sum of fields @offset[i] and @len[i] of 'xengnttab_grant_copy_segment_t' + * should not exceed XEN_PAGE_SIZE + */ +int xengnttab_grant_copy(xengnttab_handle *xgt, + uint32_t count, + xengnttab_grant_copy_segment_t *segs); + /* * Grant Sharing Interface (allocating and granting pages to others) */ diff --git a/tools/libs/gnttab/libxengnttab.map b/tools/libs/gnttab/libxengnttab.map index dc737ac..f78da22 100644 --- a/tools/libs/gnttab/libxengnttab.map +++ b/tools/libs/gnttab/libxengnttab.map @@ -21,3 +21,8 @@ VERS_1.0 { xengntshr_unshare; local: *; /* Do not expose anything by default */ }; + +VERS_1.1 { + global: + xengnttab_grant_copy; +} VERS_1.0; diff --git a/tools/libs/gnttab/linux.c b/tools/libs/gnttab/linux.c index 7b0fba4..56dff57 100644 --- a/tools/libs/gnttab/linux.c +++ b/tools/libs/gnttab/linux.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -235,6 +236,84 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, return 0; } +int osdep_gnttab_grant_copy(xengnttab_handle *xgt, + uint32_t count, + xengnttab_grant_copy_segment_t *segs) +{ + int rc; + int fd = xgt->fd; + struct ioctl_gntdev_grant_copy copy; + + XENGNTTAB_BUILD_BUG_ON(sizeof(struct ioctl_gntdev_grant_copy_segment) != + sizeof(xengnttab_grant_copy_segment_t)); + + XENGNTTAB_BUILD_BUG_ON(__alignof__(struct ioctl_gntdev_grant_copy_segment) != + __alignof__(xengnttab_grant_copy_segment_t)); + + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + source.virt) != + offsetof(xengnttab_grant_copy_segment_t, + source.virt)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + source.foreign) != + offsetof(xengnttab_grant_copy_segment_t, + source.foreign)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + source.foreign.ref) != + offsetof(xengnttab_grant_copy_segment_t, + source.foreign)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + source.foreign.offset) != + offsetof(xengnttab_grant_copy_segment_t, + source.foreign.offset)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + source.foreign.domid) != + offsetof(xengnttab_grant_copy_segment_t, + source.foreign.domid)); + + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + dest.virt) != + offsetof(xengnttab_grant_copy_segment_t, + dest.virt)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + dest.foreign) != + offsetof(xengnttab_grant_copy_segment_t, + dest.foreign)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + dest.foreign.ref) != + offsetof(xengnttab_grant_copy_segment_t, + dest.foreign)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + dest.foreign.offset) != + offsetof(xengnttab_grant_copy_segment_t, + dest.foreign.offset)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + dest.foreign.domid) != + offsetof(xengnttab_grant_copy_segment_t, + dest.foreign.domid)); + + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + len) != + offsetof(xengnttab_grant_copy_segment_t, len)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + flags) != + offsetof(xengnttab_grant_copy_segment_t, flags)); + XENGNTTAB_BUILD_BUG_ON(offsetof(struct ioctl_gntdev_grant_copy_segment, + status) != + offsetof(xengnttab_grant_copy_segment_t, status)); + + copy.segments = (struct ioctl_gntdev_grant_copy_segment *)segs; + copy.count = count; + + rc = ioctl(fd, IOCTL_GNTDEV_GRANT_COPY, ©); + if (rc) + { + GTERROR(xgt->logger, "ioctl GRANT COPY failed %d ", errno); + } + + return rc; +} + int osdep_gntshr_open(xengntshr_handle *xgs) { int fd = open(DEVXEN "gntalloc", O_RDWR); diff --git a/tools/libs/gnttab/minios.c b/tools/libs/gnttab/minios.c index 7e04174..0951bc9 100644 --- a/tools/libs/gnttab/minios.c +++ b/tools/libs/gnttab/minios.c @@ -106,6 +106,12 @@ int osdep_gnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count) return ret; } +int osdep_gnttab_grant_copy(xengnttab_handle *xgt, + uint32_t count, + xengnttab_grant_copy_segment_t *segs) +{ + return -1; +} /* * Local variables: * mode: C diff --git a/tools/libs/gnttab/private.h b/tools/libs/gnttab/private.h index 2bdc0f2..f8d234a 100644 --- a/tools/libs/gnttab/private.h +++ b/tools/libs/gnttab/private.h @@ -30,6 +30,10 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, int osdep_gnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count); +int osdep_gnttab_grant_copy(xengnttab_handle *xgt, + uint32_t count, + xengnttab_grant_copy_segment_t *segs); + int osdep_gntshr_open(xengntshr_handle *xgs); int osdep_gntshr_close(xengntshr_handle *xgs);