Re: [Xen-devel] [PATCH 3/4] tools: xencall, xengnttab, xengntshr: Provide access to internal fds
Andrew Cooper writes ("Re: [Xen-devel] [PATCH 3/4] tools: xencall, xengnttab, xengntshr: Provide access to internal fds"): > These are ABI breakages. Thanks for the review and sorry to miss that. You are right. I have another question, RFC: I have a test C program which links against Xen libraries and does the actual descriptor auditing. Current WIP version attached to give you an idea. Should I submit this for inclusion in xen.git#tools/tests/ ? Or should I put it in osstest and have osstest build it ? I think the former is probably better because then it can be used more widely. This thing is surrounded by two perl scripts, which grobble around in /proc. They contain pathname regexps, some of which are osstest-specific. They also have to grobble around in xenstore to find pids and things. I'm currently unsure as to whether these scripts should be in xen.git or osstest. If they go into xen.git then they will have to take arguments for the osstest-specific supplementary regexps, or something, which seems awkward. So I'm currently thinking I will put them in osstest. Opinions welcome. Ian. /* */ #include #include #include #include #include #include #include #include #include #include #include #include #include /* * Every class needs setup. setup is called once per class at program * startup. * * Then it can have * open test getfd close * In which case the core code will for every fd * open test getfd dup2 test close * And test should call blocked or succeeded and then immediately * return, or error out * * Or it can have * check * which should call report, or error out * * Errors: use trouble for simple syscall errors. Or use err or errx * and maybe print fd_desc and test_which, according to the comments * in struct classinfo. */ static xentoollog_logger *logger; static int object_fd; static const char *classname; static const char *fd_desc; static const char *test_which; static const char *test_wh_unrest = "test (unrestricted)"; static const char *test_wh_rest = "test (restricted)"; static void trouble(const char *what) __attribute__((noreturn)); static void trouble(const char *what) { fprintf(stderr, "trouble: %s %s %d (%s) %s: %s\n", classname, test_which, object_fd, fd_desc, what, strerror(errno)); exit(-1); } static void report(const char *pass_or_fail, const char *what, const char *notes) { printf("%s %s %d %s (%s) %s\n", classname, pass_or_fail, object_fd, what, notes, fd_desc); if (ferror(stdout) || fflush(stdout)) err(16,"stdout"); } static void succeeded(const char *what) { if (test_which == test_wh_unrest) { /* ok */ test_which = 0; } else if (test_which == test_wh_rest) { report("fail",what,"unexpectedly succeeded"); test_which = 0; } else { abort(); } } static void blocked(const char *what) { if (test_which == test_wh_rest) { /* yay */ report("pass", what,"blocked"); test_which = 0; } else if (test_which == test_wh_unrest) { err(4,"test blocked on unrestricted fd: %s {%s}",what,test_which); } else { abort(); } } /* privcmd */ static xc_interface *xch; static void setup_privcmd(void) { } static void open_privcmd(void) { xch = xc_interface_open(logger,0,0); if (!xch) trouble("xc_interface_open"); } static void test_privcmd(void) { int r = xc_get_online_cpus(xch); if (r>0) succeeded("xc_get_online_cpus"); else if (r==0) errx(-1,"xc_get_online_cpus{%s, %s}=0", test_which, fd_desc); else if (errno==EPERM) blocked("xc_get_online_cpus"); else trouble("xc_get_online_cpus"); } static int getfd_privcmd(void) { return xencall_fd(xc_interface_xcall_handle(xch)); } static void close_privcmd(void) { xc_interface_close(xch); } /* gntdev */ static xengntshr_handle *xgs; static uint32_t gntshr_gref; static xengnttab_handle *xgt; static void setup_gntdev(void) { void *r; xgs = xengntshr_open(logger,0); if (!xgs) trouble("xengntshr_open"); r = xengntshr_share_pages(xgs, 0, 1, _gref, 1); if (!r || r==(void*)-1) trouble("xengntshr_share_pages"); memset(r, 0x55, XC_PAGE_SIZE); } static void open_gntdev(void) { xgt = xengnttab_open(logger,0); if (!xgt) trouble("xengnttab_open"); } static void test_gntdev(void) { char mybuf[XC_PAGE_SIZE]; memset(mybuf, 0xaa, XC_PAGE_SIZE); xengnttab_grant_copy_segment_t seg; seg.source.foreign.ref = gntshr_gref; seg.source.foreign.offset = 0; seg.source.foreign.domid = 0; seg.dest.virt = mybuf; seg.len = 1; seg.flags = GNTCOPY_source_gref; for (;;) { seg.status = 0;
Re: [Xen-devel] [PATCH 3/4] tools: xencall, xengnttab, xengntshr: Provide access to internal fds
On 14/05/18 18:08, Ian Jackson wrote: > diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map > index 2f96144..299ca38 100644 > --- a/tools/libs/call/libxencall.map > +++ b/tools/libs/call/libxencall.map > @@ -2,6 +2,7 @@ VERS_1.0 { > global: > xencall_open; > xencall_close; > + xencall_fd; > > xencall0; > xencall1; > diff --git a/tools/libs/gnttab/libxengnttab.map > b/tools/libs/gnttab/libxengnttab.map > index f78da22..ce59ec9 100644 > --- a/tools/libs/gnttab/libxengnttab.map > +++ b/tools/libs/gnttab/libxengnttab.map > @@ -2,6 +2,7 @@ VERS_1.0 { > global: > xengnttab_open; > xengnttab_close; > + xengnttab_fd; > > xengnttab_set_max_grants; > > @@ -14,6 +15,7 @@ VERS_1.0 { > > xengntshr_open; > xengntshr_close; > + xengntshr_fd; > > xengntshr_share_page_notify; > xengntshr_share_pages; These are ABI breakages. The only modification you can make to the map files is to define a new minor SOversion and introduce the new functions there (although we can accumulate multiple additions to the not-yet-release SOversion in master). ~Andrew ___ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel
[Xen-devel] [PATCH 3/4] tools: xencall, xengnttab, xengntshr: Provide access to internal fds
I want this to support my qemu depriv descriptor audit tool. Signed-off-by: Ian Jackson--- tools/libs/call/core.c| 5 + tools/libs/call/include/xencall.h | 8 tools/libs/call/libxencall.map| 1 + tools/libs/gnttab/gntshr_core.c | 6 ++ tools/libs/gnttab/gnttab_core.c | 5 + tools/libs/gnttab/include/xengnttab.h | 17 + tools/libs/gnttab/libxengnttab.map| 2 ++ 7 files changed, 44 insertions(+) diff --git a/tools/libs/call/core.c b/tools/libs/call/core.c index f3a3400..c155bd4 100644 --- a/tools/libs/call/core.c +++ b/tools/libs/call/core.c @@ -81,6 +81,11 @@ int xencall_close(xencall_handle *xcall) return rc; } +int xencall_fd(xencall_handle *xcall) +{ +return xcall->fd; +} + int xencall0(xencall_handle *xcall, unsigned int op) { privcmd_hypercall_t call = { diff --git a/tools/libs/call/include/xencall.h b/tools/libs/call/include/xencall.h index bafacdd..24bcafb 100644 --- a/tools/libs/call/include/xencall.h +++ b/tools/libs/call/include/xencall.h @@ -74,6 +74,14 @@ xencall_handle *xencall_open(struct xentoollog_logger *logger, int xencall_close(xencall_handle *xcall); /* + * Return the fd used internally by xencall. selecting on it is not + * useful. But it could be useful for unusual use cases; perhaps, + * passing to other programs, calling ioctls on directly, or maybe + * calling fcntl. + */ +int xencall_fd(xencall_handle *xcall); + +/* * Call hypercalls with varying numbers of arguments. * * On success the return value of the hypercall is the return value of diff --git a/tools/libs/call/libxencall.map b/tools/libs/call/libxencall.map index 2f96144..299ca38 100644 --- a/tools/libs/call/libxencall.map +++ b/tools/libs/call/libxencall.map @@ -2,6 +2,7 @@ VERS_1.0 { global: xencall_open; xencall_close; + xencall_fd; xencall0; xencall1; diff --git a/tools/libs/gnttab/gntshr_core.c b/tools/libs/gnttab/gntshr_core.c index 7f6bf9d..1117e29 100644 --- a/tools/libs/gnttab/gntshr_core.c +++ b/tools/libs/gnttab/gntshr_core.c @@ -64,6 +64,12 @@ int xengntshr_close(xengntshr_handle *xgs) free(xgs); return rc; } + +int xengntshr_fd(xengntshr_handle *xgs) +{ +return xgs->fd; +} + void *xengntshr_share_pages(xengntshr_handle *xcg, uint32_t domid, int count, uint32_t *refs, int writable) { diff --git a/tools/libs/gnttab/gnttab_core.c b/tools/libs/gnttab/gnttab_core.c index 98f1591..bd075f8 100644 --- a/tools/libs/gnttab/gnttab_core.c +++ b/tools/libs/gnttab/gnttab_core.c @@ -75,6 +75,11 @@ int xengnttab_close(xengnttab_handle *xgt) return rc; } +int xengnttab_fd(xengnttab_handle *xgt) +{ +return xgt->fd; +} + int xengnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count) { return osdep_gnttab_set_max_grants(xgt, count); diff --git a/tools/libs/gnttab/include/xengnttab.h b/tools/libs/gnttab/include/xengnttab.h index 35be6c1..91d4cd5 100644 --- a/tools/libs/gnttab/include/xengnttab.h +++ b/tools/libs/gnttab/include/xengnttab.h @@ -149,6 +149,15 @@ xengnttab_handle *xengnttab_open(struct xentoollog_logger *logger, */ int xengnttab_close(xengnttab_handle *xgt); + +/* + * Return the fd used internally by xengnttab. selecting on it is not + * useful. But it could be useful for unusual use cases; perhaps, + * passing to other programs, calling ioctls on directly, or maybe + * calling fcntl. + */ +int xengnttab_fd(xengnttab_handle *xgt); + /** * Memory maps a grant reference from one domain to a local address range. * Mappings should be unmapped with xengnttab_unmap. Logs errors. @@ -334,6 +343,14 @@ xengntshr_handle *xengntshr_open(struct xentoollog_logger *logger, */ int xengntshr_close(xengntshr_handle *xgs); +/* + * Return the fd used internally by xengntshr. selecting on it is not + * useful. But it could be useful for unusual use cases; perhaps, + * passing to other programs, calling ioctls on directly, or maybe + * calling fcntl. + */ +int xengntshr_fd(xengntshr_handle *xgs); + /** * Allocates and shares pages with another domain. * diff --git a/tools/libs/gnttab/libxengnttab.map b/tools/libs/gnttab/libxengnttab.map index f78da22..ce59ec9 100644 --- a/tools/libs/gnttab/libxengnttab.map +++ b/tools/libs/gnttab/libxengnttab.map @@ -2,6 +2,7 @@ VERS_1.0 { global: xengnttab_open; xengnttab_close; + xengnttab_fd; xengnttab_set_max_grants; @@ -14,6 +15,7 @@ VERS_1.0 { xengntshr_open; xengntshr_close; + xengntshr_fd; xengntshr_share_page_notify; xengntshr_share_pages; -- 2.1.4 ___ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel