From patchwork Wed Oct 4 15:57:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 9985121 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 D68FF605B2 for ; Wed, 4 Oct 2017 16:09:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C90952876F for ; Wed, 4 Oct 2017 16:09:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDF91287F8; Wed, 4 Oct 2017 16:09:37 +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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED 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 50EB228B44 for ; Wed, 4 Oct 2017 16:09:37 +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 1dzmD4-0003mP-Dj; Wed, 04 Oct 2017 16:07:46 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzmD2-0003ga-9L for xen-devel@lists.xensource.com; Wed, 04 Oct 2017 16:07:44 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 87/41-01916-F4705D95; Wed, 04 Oct 2017 16:07:43 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrMIsWRWlGSWpSXmKPExsXitHSDva4f+9V Ig7ff9C3uTXnP7sDosb1vF3sAYxRrZl5SfkUCa8bWzu9MBYfUKp4sPMXawPhLoYuRk0NCwF/i yfXJbBC2h8T1syeYQGw2AV2Jpi1/weIiAsoSx5u+sHYxcnEwC5xjlGidsoG5i5GDQ1ggSOLbJ neQGhYBFYlzdz8zgti8Al4S+zccYoKYKSdx/vhPZhCbEyj+dGcHWKuQgKfEsbWmEKaaxNz18R CdghInZz5hAbGZBSQkDr54wQwxxVLi2/qnzBMY+WchKZuFpGwBI9MqRo3i1KKy1CJdYwO9pKL M9IyS3MTMHF1DA2O93NTi4sT01JzEpGK95PzcTYzAQKtnYGDcwdh5wu8QoyQHk5Io76+fVyKF +JLyUyozEosz4otKc1KLDzHKcHAoSfBuYLsaKSRYlJqeWpGWmQMMeZi0BAePkghvO0iat7ggM bc4Mx0idYrRkuPYpst/mDiabt4Fkh0gUoglLz8vVUqcdwJIgwBIQ0ZpHtw4WFxeYpSVEuZlZG BgEOIpSC3KzSxBlX/FKM7BqCTMewFkCk9mXgnc1ldABzEBHTSn6QrIQSWJCCmpBkaHA1MkFJd x35vg/216icHsayF/Hz+JE46PP/f2DHvV0bDMIB3rhK9ME657CH4QnRDXvyfruI7Xmto56l4f i2NYGHYe0qmc87Zw7fJLRa4b7tjPu3xk2rR3D2Ynax8oWrLY71FDXtO2mZOVkvZdrLp5Xa2h1 WNXY/X6ujKbjx4rI4OENn2Mmm6mxFKckWioxVxUnAgAprcuwMYCAAA= X-Env-Sender: prvs=4438c69fc=Ian.Jackson@citrix.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1507133258!59823793!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 39209 invoked from network); 4 Oct 2017 16:07:42 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-4.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 4 Oct 2017 16:07:42 -0000 X-IronPort-AV: E=Sophos;i="5.42,477,1500940800"; d="scan'208";a="450475325" X-CrossPremisesHeadersFilteredBySendConnector: FTLPEX02AMS01.citrite.net From: Ian Jackson To: Date: Wed, 4 Oct 2017 16:57:18 +0100 Message-ID: <1507132650-25376-13-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1507132650-25376-1-git-send-email-ian.jackson@eu.citrix.com> References: <1507132650-25376-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 X-OrganizationHeadersPreserved: FTLPEX02AMS01.citrite.net Cc: Ross Lagerwall , Stefano Stabellini , Wei Liu , Ian Jackson Subject: [Xen-devel] [PATCH 12/24] xentoolcore_restrict_all: Implement for libxenforeignmemory 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Ian Jackson Acked-by: Wei Liu --- tools/Rules.mk | 2 +- tools/libs/foreignmemory/Makefile | 4 ++-- tools/libs/foreignmemory/core.c | 15 +++++++++++++++ tools/libs/foreignmemory/private.h | 3 +++ tools/libs/foreignmemory/xenforeignmemory.pc.in | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/tools/Rules.mk b/tools/Rules.mk index 71037a1..7dd126a 100644 --- a/tools/Rules.mk +++ b/tools/Rules.mk @@ -124,7 +124,7 @@ LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_LIBXENCALL)/libxencall$(libextens SHLIB_libxencall = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_LIBXENCALL) CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude) -SHDEPS_libxenforeignmemory = +SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore) LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension) SHLIB_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY) diff --git a/tools/libs/foreignmemory/Makefile b/tools/libs/foreignmemory/Makefile index ab7f873..cbe815f 100644 --- a/tools/libs/foreignmemory/Makefile +++ b/tools/libs/foreignmemory/Makefile @@ -7,7 +7,7 @@ SHLIB_LDFLAGS += -Wl,--version-script=libxenforeignmemory.map CFLAGS += -Werror -Wmissing-prototypes CFLAGS += -I./include $(CFLAGS_xeninclude) -CFLAGS += $(CFLAGS_libxentoollog) +CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore) SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.c @@ -62,7 +62,7 @@ libxenforeignmemory.so.$(MAJOR): libxenforeignmemory.so.$(MAJOR).$(MINOR) $(SYMLINK_SHLIB) $< $@ libxenforeignmemory.so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxenforeignmemory.map - $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenforeignmemory.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenforeignmemory.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) .PHONY: install install: build diff --git a/tools/libs/foreignmemory/core.c b/tools/libs/foreignmemory/core.c index a6897dc..b48ecba 100644 --- a/tools/libs/foreignmemory/core.c +++ b/tools/libs/foreignmemory/core.c @@ -19,6 +19,16 @@ #include "private.h" +static int all_restrict_cb(Xentoolcore__Active_Handle *ah, uint32_t domid) { + xenforeignmemory_handle *fmem = CONTAINER_OF(ah, *fmem, tc_ah); + + if (fmem->fd < 0) + /* just in case */ + return 0; + + return xenforeignmemory_restrict(fmem, domid); +} + xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, unsigned open_flags) { @@ -31,6 +41,9 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, fmem->logger = logger; fmem->logger_tofree = NULL; + fmem->tc_ah.restrict_callback = all_restrict_cb; + xentoolcore__register_active_handle(&fmem->tc_ah); + if (!fmem->logger) { fmem->logger = fmem->logger_tofree = (xentoollog_logger*) @@ -45,6 +58,7 @@ xenforeignmemory_handle *xenforeignmemory_open(xentoollog_logger *logger, err: osdep_xenforeignmemory_close(fmem); + xentoolcore__deregister_active_handle(&fmem->tc_ah); xtl_logger_destroy(fmem->logger_tofree); free(fmem); return NULL; @@ -58,6 +72,7 @@ int xenforeignmemory_close(xenforeignmemory_handle *fmem) return 0; rc = osdep_xenforeignmemory_close(fmem); + xentoolcore__deregister_active_handle(&fmem->tc_ah); xtl_logger_destroy(fmem->logger_tofree); free(fmem); return rc; diff --git a/tools/libs/foreignmemory/private.h b/tools/libs/foreignmemory/private.h index c5c07cc..2470f3c 100644 --- a/tools/libs/foreignmemory/private.h +++ b/tools/libs/foreignmemory/private.h @@ -5,6 +5,8 @@ #include +#include + #include #include @@ -20,6 +22,7 @@ struct xenforeignmemory_handle { xentoollog_logger *logger, *logger_tofree; unsigned flags; int fd; + Xentoolcore__Active_Handle tc_ah; }; int osdep_xenforeignmemory_open(xenforeignmemory_handle *fmem); diff --git a/tools/libs/foreignmemory/xenforeignmemory.pc.in b/tools/libs/foreignmemory/xenforeignmemory.pc.in index 63432dc..61c9def 100644 --- a/tools/libs/foreignmemory/xenforeignmemory.pc.in +++ b/tools/libs/foreignmemory/xenforeignmemory.pc.in @@ -7,4 +7,4 @@ Description: The Xenforeignmemory library for Xen hypervisor Version: @@version@@ Cflags: -I${includedir} @@cflagslocal@@ Libs: @@libsflag@@${libdir} -lxenforeignmemory -Requires.private: xentoollog +Requires.private: xentoollog,xentoolcore