From patchwork Thu Jun 6 12:16:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 10979445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D3206C5 for ; Thu, 6 Jun 2019 12:18:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E026288CE for ; Thu, 6 Jun 2019 12:18:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2281C288E1; Thu, 6 Jun 2019 12:18:52 +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=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 043E3288CE for ; Thu, 6 Jun 2019 12:18:50 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hYrJj-0003Lb-8O; Thu, 06 Jun 2019 12:16:27 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hYrJh-0003LU-4H for xen-devel@lists.xenproject.org; Thu, 06 Jun 2019 12:16:25 +0000 X-Inumbo-ID: e5b4f0ce-8854-11e9-8980-bc764e045a96 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe02::700]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e5b4f0ce-8854-11e9-8980-bc764e045a96; Thu, 06 Jun 2019 12:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector1-bitdefender-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IJ93Yf06jEVwHQTXFcGknz31EbXbJELG/3KSem3twwA=; b=QTN3K9SZezogJcq88H+vPRJdFBnoMN2+btd+UZHJSUPFF6Fb9pMyIcpD8ENQhxoo+aUY/dfTsjUgH5IT/QvVcjI0kImkvlqMAAG8+H/Hi6SDoylc3hMaC416uRySYKCJz4JNUiVhU3kRkot1599Rr+sC+nrEJKbsez6/3+It/+s= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.106.11) by VI1PR0202MB3327.eurprd02.prod.outlook.com (52.134.15.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1943.22; Thu, 6 Jun 2019 12:16:19 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::fdcf:4771:37b7:9830]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::fdcf:4771:37b7:9830%9]) with mapi id 15.20.1965.011; Thu, 6 Jun 2019 12:16:19 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v1] x86/altp2m: Add xc_altp2m_get_vcpu_p2m_idx Thread-Index: AQHVHGGlu0NbVCknh0ips2+nSWSJiQ== Date: Thu, 6 Jun 2019 12:16:19 +0000 Message-ID: <20190606121548.2075-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: VI1PR0202CA0021.eurprd02.prod.outlook.com (2603:10a6:803:14::34) To VI1PR0202MB2928.eurprd02.prod.outlook.com (2603:10a6:800:e3::11) authentication-results: spf=none (sender IP is ) smtp.mailfrom=aisaila@bitdefender.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-originating-ip: [91.199.104.6] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ed38a1b7-98d9-448e-f0ef-08d6ea78c7ce x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:VI1PR0202MB3327; x-ms-traffictypediagnostic: VI1PR0202MB3327:|VI1PR0202MB3327: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:580; x-forefront-prvs: 00603B7EEF x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(396003)(39860400002)(376002)(136003)(366004)(189003)(199004)(3846002)(186003)(53936002)(6506007)(386003)(7416002)(6116002)(2501003)(8676002)(26005)(486006)(8936002)(66066001)(102836004)(5660300002)(7736002)(478600001)(6512007)(6916009)(99286004)(14454004)(66946007)(52116002)(54906003)(107886003)(2616005)(73956011)(316002)(68736007)(6436002)(256004)(6486002)(50226002)(2906002)(36756003)(86362001)(2351001)(64756008)(305945005)(66446008)(66476007)(66556008)(25786009)(14444005)(81156014)(81166006)(1076003)(476003)(71200400001)(71190400001)(4326008)(5640700003)(70780200001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3327; H:VI1PR0202MB2928.eurprd02.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bitdefender.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: nB8FZYN+SVi281zN+tlERxwLdZn1vH0L61CVMA0eRb743LY/HO15yub17x7GNa8kKNmeclWRlGPXyq8QpXo+4uyH1w3/O8mP6mvyeGY7GNLzQsLO/ZWbCTYZ25rVTzplIhcsU3BbqwOEPHtNgqfcYEx/x+Up1uitON2MBktuiq2sCOXJe1kp6mvaXpLoDiCWjPu84DEXvGcDeCE1m4rKW326wE01hsFjfnmwL1C7Kz2A5yrDvrsn+DwbpuX5+KUC+Zu8A4Ylkd+R73p8HNcZHCOQ4szidGSryKKz1rM9oQpQckKvLHbYh+AVgkWnHaoHYWeiOIF8P1Pz1txi5I8dRNR3LPH0TN9aHbDeVc/qiEYcx2Hhg1UmxsAB+y1cM/ImrDhd9MO+2FJV5jTqwsu3ioXF5f5yn32wFagCAS1J2c4= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: ed38a1b7-98d9-448e-f0ef-08d6ea78c7ce X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jun 2019 12:16:19.1889 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 487baf29-f1da-469a-9221-243f830c36f3 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: aisaila@bbu.bitdefender.biz X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0202MB3327 Subject: [Xen-devel] [PATCH v1] x86/altp2m: Add xc_altp2m_get_vcpu_p2m_idx X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: "sstabellini@kernel.org" , "wl@xen.org" , "konrad.wilk@oracle.com" , "George.Dunlap@eu.citrix.com" , "andrew.cooper3@citrix.com" , "ian.jackson@eu.citrix.com" , "tim@xen.org" , "julien.grall@arm.com" , "jbeulich@suse.com" , Alexandru Stefan ISAILA , "roger.pau@citrix.com" Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This new function returns the active altp2m index form a given vcp. Signed-off-by: Alexandru Isaila --- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 25 +++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 24 ++++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 11 +++++++++++ 4 files changed, 62 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 538007a6dc..87526af4b4 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1942,6 +1942,8 @@ int xc_altp2m_get_mem_access(xc_interface *handle, uint32_t domid, int xc_altp2m_change_gfn(xc_interface *handle, uint32_t domid, uint16_t view_id, xen_pfn_t old_gfn, xen_pfn_t new_gfn); +int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid, + uint32_t vcpuid, uint16_t *p2midx); /** * Mem paging operations. diff --git a/tools/libxc/xc_altp2m.c b/tools/libxc/xc_altp2m.c index a86520c232..09dad0355e 100644 --- a/tools/libxc/xc_altp2m.c +++ b/tools/libxc/xc_altp2m.c @@ -352,3 +352,28 @@ int xc_altp2m_get_mem_access(xc_interface *handle, uint32_t domid, xc_hypercall_buffer_free(handle, arg); return rc; } + +int xc_altp2m_get_vcpu_p2m_idx(xc_interface *handle, uint32_t domid, + uint32_t vcpuid, uint16_t *altp2m_idx) +{ + int rc; + + DECLARE_HYPERCALL_BUFFER(xen_hvm_altp2m_op_t, arg); + + arg = xc_hypercall_buffer_alloc(handle, arg, sizeof(*arg)); + if ( arg == NULL ) + return -1; + + arg->version = HVMOP_ALTP2M_INTERFACE_VERSION; + arg->cmd = HVMOP_altp2m_get_p2m_idx; + arg->domain = domid; + arg->u.get_vcpu_p2m_idx.vcpu_id = vcpuid; + + rc = xencall2(handle->xcall, __HYPERVISOR_hvm_op, HVMOP_altp2m, + HYPERCALL_BUFFER_AS_ARG(arg)); + if ( !rc ) + *altp2m_idx = arg->u.get_vcpu_p2m_idx.altp2m_idx; + + xc_hypercall_buffer_free(handle, arg); + return rc; +} diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 029eea3b85..28ae23087c 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4500,6 +4500,7 @@ static int do_altp2m_op( case HVMOP_altp2m_set_mem_access_multi: case HVMOP_altp2m_get_mem_access: case HVMOP_altp2m_change_gfn: + case HVMOP_altp2m_get_p2m_idx: break; default: @@ -4735,6 +4736,29 @@ static int do_altp2m_op( _gfn(a.u.change_gfn.old_gfn), _gfn(a.u.change_gfn.new_gfn)); break; + + case HVMOP_altp2m_get_p2m_idx: + { + struct vcpu *v; + + if ( a.u.get_vcpu_p2m_idx.vcpu_id >= d->max_vcpus ) + { + rc = -EINVAL; + break; + } + + if ( !altp2m_active(d) ) + { + rc = -EOPNOTSUPP; + break; + } + + v = d->vcpu[a.u.get_vcpu_p2m_idx.vcpu_id]; + a.u.get_vcpu_p2m_idx.altp2m_idx = altp2m_vcpu_idx(v); + rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; + break; + } + default: ASSERT_UNREACHABLE(); } diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index c6cd12f596..26d5a580dc 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -304,6 +304,14 @@ struct xen_hvm_altp2m_change_gfn { typedef struct xen_hvm_altp2m_change_gfn xen_hvm_altp2m_change_gfn_t; DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_change_gfn_t); +struct xen_hvm_altp2m_get_vcpu_p2m_idx { + uint32_t vcpu_id; + uint16_t altp2m_idx; +}; +typedef struct xen_hvm_altp2m_get_vcpu_p2m_idx + xen_hvm_altp2m_get_vcpu_p2m_idx_t; +DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_get_vcpu_p2m_idx_t); + struct xen_hvm_altp2m_op { uint32_t version; /* HVMOP_ALTP2M_INTERFACE_VERSION */ uint32_t cmd; @@ -332,6 +340,8 @@ struct xen_hvm_altp2m_op { #define HVMOP_altp2m_get_mem_access 12 /* Disable altp2m event notifications for a given VCPU */ #define HVMOP_altp2m_vcpu_disable_notify 13 +/* Get the active vcpu p2m index */ +#define HVMOP_altp2m_get_p2m_idx 14 domid_t domain; uint16_t pad1; uint32_t pad2; @@ -347,6 +357,7 @@ struct xen_hvm_altp2m_op { struct xen_hvm_altp2m_set_mem_access_multi set_mem_access_multi; struct xen_hvm_altp2m_suppress_ve suppress_ve; struct xen_hvm_altp2m_vcpu_disable_notify disable_notify; + struct xen_hvm_altp2m_get_vcpu_p2m_idx get_vcpu_p2m_idx; uint8_t pad[64]; } u; };