From patchwork Thu Oct 19 08:16:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Yi" X-Patchwork-Id: 10016233 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 286BB600CC for ; Thu, 19 Oct 2017 09:24:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A51C287B3 for ; Thu, 19 Oct 2017 09:24:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EBBB2880F; Thu, 19 Oct 2017 09:24:41 +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 887B8287B3 for ; Thu, 19 Oct 2017 09:24:38 +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 1e571x-0001wO-LQ; Thu, 19 Oct 2017 09:22:21 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e55zi-0004qa-2U for xen-devel@lists.xenproject.org; Thu, 19 Oct 2017 08:15:58 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id DD/88-21967-D3F58E95; Thu, 19 Oct 2017 08:15:57 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeJIrShJLcpLzFFi42I5YG5SrGsT/yL SYNoKfYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPuvQusBetUK7Z/fsPWwLhStouRi0NIYDqj xI+Nm5m6GDk5JAR4JY4sm8EKYftL/Jt3BCwuJFAk0bZtMwuEvZBR4miPA4jNJqAt0XzjPVhcR EBJ4t6qyUwgQ5kFepkkFtz4CpYQFrCTOPdtIhuIzSKgKvHuxVewobwCCRJL5n+CWiYncfNcJz OIzQlUf/fZFjaIZbYSz779ZJnAyLeAkWEVo0ZxalFZapGukYVeUlFmekZJbmJmjq6hgalebmp xcWJ6ak5iUrFecn7uJkZgoNQzMDDuYOxb5XeIUZKDSUmUVzbwRaQQX1J+SmVGYnFGfFFpTmrx IUYZDg4lCV7vOKCcYFFqempFWmYOMGRh0hIcPEoivDogad7igsTc4sx0iNQpRmOOY5su/2Hi6 Lh59w+TEEtefl6qlDjvt1igUgGQ0ozSPLhBsFi6xCgrJczLyMDAIMRTkFqUm1mCKv+KUZyDUU mYtwBkIU9mXgncvldApzABncJuD3ZKSSJCSqqBka/2xKW/rY11J0MTH66vnm9T83AbV4u842y xzjxl4bvlr0vsZynHT22f//9Cv3763rOzxU+ZWm3o+XU6+VJigHa1h3Tmlpk9yv/dQvKULlmv cXPOThQKlv5pZW6tdK/lXHxQ78bm3Cmsl4vOrdH88G+xafrzJ91PLmVJz2Ao+jRh5dQzjZqPl ViKMxINtZiLihMBTfDJY6ACAAA= X-Env-Sender: yi.z.zhang@linux.intel.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1508400954!107773668!1 X-Originating-IP: [192.55.52.115] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46442 invoked from network); 19 Oct 2017 08:15:56 -0000 Received: from mga14.intel.com (HELO mga14.intel.com) (192.55.52.115) by server-9.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Oct 2017 08:15:56 -0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2017 01:15:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,400,1503385200"; d="scan'208";a="911446337" Received: from linux.intel.com ([10.54.29.200]) by FMSMGA003.fm.intel.com with ESMTP; 19 Oct 2017 01:15:42 -0700 Received: from dazhang1-ssd.sh.intel.com (unknown [10.239.48.55]) by linux.intel.com (Postfix) with ESMTP id 3E96558027A; Thu, 19 Oct 2017 01:15:40 -0700 (PDT) From: Zhang Yi To: xen-devel@lists.xenproject.org Date: Thu, 19 Oct 2017 16:16:18 +0800 Message-Id: <90cbda6aa45b0de7e16b685af9b64e2973a139ba.1508397860.git.yi.z.zhang@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-Mailman-Approved-At: Thu, 19 Oct 2017 09:22:18 +0000 Cc: kevin.tian@intel.com, tamas@tklengyel.com, wei.liu2@citrix.com, jun.nakajima@intel.com, rcojocaru@bitdefender.com, george.dunlap@eu.citrix.com, andrew.cooper3@citrix.com, ian.jackson@eu.citrix.com, Zhang Yi Z , jbeulich@suse.com Subject: [Xen-devel] [PATCH RFC 14/14] xen: tools: Added xen-subpage tool. 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 From: Zhang Yi Z It is a tool could set a 4K page corresponding a 32 bit bitmap: xen-subpage -m [domid] set [gfn] [bitmap] Signed-off-by: Zhang Yi Z --- tools/tests/xen-subpage/Makefile | 30 ++++++++ tools/tests/xen-subpage/xen-subpage.c | 125 ++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 tools/tests/xen-subpage/Makefile create mode 100644 tools/tests/xen-subpage/xen-subpage.c diff --git a/tools/tests/xen-subpage/Makefile b/tools/tests/xen-subpage/Makefile new file mode 100644 index 0000000..89b58f2 --- /dev/null +++ b/tools/tests/xen-subpage/Makefile @@ -0,0 +1,30 @@ +XEN_ROOT=$(CURDIR)/../../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS += -Werror +CFLAGS += -DXC_WANT_COMPAT_DEVICEMODEL_API + +CFLAGS += $(CFLAGS_libxenctrl) +CFLAGS += $(CFLAGS_libxenguest) +CFLAGS += $(CFLAGS_xeninclude) + +TARGETS-y := xen-subpage +TARGETS := $(TARGETS-y) + +.PHONY: all +all: build + +.PHONY: build +build: $(TARGETS) + +.PHONY: clean +clean: + $(RM) *.o $(TARGETS) *~ $(DEPS) + +.PHONY: distclean +distclean: clean + +xen-subpage: xen-subpage.o Makefile + $(CC) -o $@ $< $(LDFLAGS) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenevtchn) + +-include $(DEPS) diff --git a/tools/tests/xen-subpage/xen-subpage.c b/tools/tests/xen-subpage/xen-subpage.c new file mode 100644 index 0000000..78e416c --- /dev/null +++ b/tools/tests/xen-subpage/xen-subpage.c @@ -0,0 +1,125 @@ +/* + * xen-subpage.c + * + * Exercises the basic per-page access mechanisms + * + * Copyright (c) 2011 Virtuata, Inc. + * Copyright (c) 2017 by Intel + * + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define DPRINTF(a, b...) fprintf(stderr, a, ## b) +#define ERROR(a, b...) fprintf(stderr, a "\n", ## b) +#define PERROR(a, b...) fprintf(stderr, a ": %s\n", ## b, strerror(errno)) + +void usage(char* progname) +{ + fprintf(stderr, "Usage: %s [-m] get|set [gfn] [bit_map]", progname); + + fprintf(stderr, + "\n" + "set - set gfn bitmap.\n" + "\n" + "-m requires this program to run\n"); +} + +int main(int argc, char *argv[]) +{ + domid_t domain_id; + xc_interface *xch; + xen_pfn_t gfn = 0; + uint32_t access = 0; + int required = 0; + int rc = 0; + + char* progname = argv[0]; + argv++; + argc--; + + if ( argc == 5 && argv[0][0] == '-' ) + { + if ( !strcmp(argv[0], "-m") ) + required = 1; + else + { + usage(progname); + return -1; + } + argv++; + argc--; + } + + if ( argc != 4 ) + { + usage(progname); + return -1; + } + + domain_id = atoi(argv[0]); + argv++; + argc--; + + if ( !strcmp(argv[0], "set") ) + { + gfn = strtoul(argv[1], 0, 0); + access = strtoul(argv[2], 0, 0); + DPRINTF("set subpage gfn:0x%lx -- map:0x%x\n", gfn, access); + xch = xc_interface_open(NULL, NULL, 0); + if ( !xch ) + { + ERROR("get interface error\n"); + return -1; + } + xc_mem_set_subpage(xch, domain_id, gfn, access); + xc_interface_close(xch); + } + else + { + usage(argv[0]); + return -1; + } + + return rc; +} + + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */