From patchwork Fri Jun 7 10:55:02 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: 10981411 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 B779C14C0 for ; Fri, 7 Jun 2019 10:57:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A521F28B58 for ; Fri, 7 Jun 2019 10:57:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97D4528B5A; Fri, 7 Jun 2019 10:57:08 +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 A8F3828B58 for ; Fri, 7 Jun 2019 10:57:06 +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 1hZCWb-00039w-W4; Fri, 07 Jun 2019 10:55:09 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZCWb-00039r-1c for xen-devel@lists.xenproject.org; Fri, 07 Jun 2019 10:55:09 +0000 X-Inumbo-ID: b4c4648c-8912-11e9-a351-a7c6f19d0e43 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (unknown [40.107.1.101]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id b4c4648c-8912-11e9-a351-a7c6f19d0e43; Fri, 07 Jun 2019 10:55:05 +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=yOmDZVbbd1VkcYWVxPCrygTt0IMNXK0G5G9i4eDp2Uo=; b=i8axOcsFThHJ+j9/xXOzl5GMuEd3q5XZr9IaAzgh20xR8b6mug2jisRbqZhHdR8IemcEGHMWhBj2DBI9ejHBjA2hJL7v5yd92v8kl79RV4qV8qVlyI+45iyPRTbtD+k+5c4n2oI827VmctDKVWnwLli6aq9YMcocy6mU+vqVsOw= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.106.11) by VI1PR0202MB2525.eurprd02.prod.outlook.com (10.173.78.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1965.12; Fri, 7 Jun 2019 10:55:02 +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; Fri, 7 Jun 2019 10:55:02 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3] x86/altp2m: Add a new hypercall to get the active altp2m index Thread-Index: AQHVHR91gFCC2wnfik6rp2c4QxPTkg== Date: Fri, 7 Jun 2019 10:55:02 +0000 Message-ID: <20190607105449.28167-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P193CA0113.EURP193.PROD.OUTLOOK.COM (2603:10a6:209:85::18) 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: ac0992f7-c90e-477a-534d-08d6eb369779 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:VI1PR0202MB2525; x-ms-traffictypediagnostic: VI1PR0202MB2525:|VI1PR0202MB2525: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:949; x-forefront-prvs: 0061C35778 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(346002)(39860400002)(396003)(376002)(136003)(189003)(199004)(86362001)(6512007)(71200400001)(478600001)(53936002)(5660300002)(5640700003)(6486002)(66066001)(6436002)(64756008)(73956011)(2501003)(71190400001)(6916009)(7416002)(25786009)(54906003)(3846002)(6116002)(81166006)(316002)(81156014)(8936002)(8676002)(305945005)(14454004)(7736002)(107886003)(2906002)(476003)(2616005)(50226002)(14444005)(256004)(66946007)(66476007)(386003)(6506007)(36756003)(2351001)(66446008)(68736007)(186003)(66556008)(102836004)(26005)(99286004)(4326008)(486006)(1076003)(52116002)(15583001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB2525; 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: 7cme8tavcT/j9XuBTZ/YlerLHuYdy/KUPnkKK6M+IAp5BpOkn65xnXwMaqYA3mQcNcwI1i/egHd/5MmcXZtjhHTmtQ2DKfGicWaMRMtkR95QJMxjwI3/o+iPWOXRg5wpzRfI7uKRnDYB7G3pFDsxgx3KGCVqz7+auihAjNgV0LGQe4i4zp/IbKtShhhqQb6yDochQkwTvq/w/hCv7qr2S+wx0vUT/mw8x88szJ6KaMU5i4rOfVMGvlzXbl62iKLHd0tsgWMCW84BTZ8/pmnNcS8YfaXX/8kP9RMJb0WSsq4oywzHOunfB0MvxQIt6LkWV5yuIEMrBBEOe8CjMjARWOaDBl6H3/RLxXjQZEhnp1lSUWa/obnyZJzsrshAEA1bOh6PV1+b1+YuGV+Kuep/ojqBsKtCbdMjvO9COTiGqi4= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac0992f7-c90e-477a-534d-08d6eb369779 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jun 2019 10:55:02.4718 (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: VI1PR0202MB2525 Subject: [Xen-devel] [PATCH v3] x86/altp2m: Add a new hypercall to get the active altp2m index 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 The patch adds a new lib xc function (xc_altp2m_get_vcpu_p2m_idx) that uses a new hvmop (HVMOP_altp2m_get_p2m_idx) to get the active altp2m index from a given vcpu. Signed-off-by: Alexandru Isaila Reviewed-by: George Dunlap --- Changes since V2: - Update comment and title - Remove redundant max_vcpu check. --- tools/libxc/include/xenctrl.h | 2 ++ tools/libxc/xc_altp2m.c | 25 +++++++++++++++++++++++++ xen/arch/x86/hvm/hvm.c | 23 +++++++++++++++++++++++ xen/include/public/hvm/hvm_op.h | 8 ++++++++ 4 files changed, 58 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..4ee7e6ce47 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,28 @@ 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 ( !altp2m_active(d) ) + { + rc = -EOPNOTSUPP; + break; + } + + if ( (v = domain_vcpu(d, a.u.get_vcpu_p2m_idx.vcpu_id)) == NULL ) + { + rc = -EINVAL; + break; + } + + 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..353f8034d9 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -304,6 +304,11 @@ 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; +}; + struct xen_hvm_altp2m_op { uint32_t version; /* HVMOP_ALTP2M_INTERFACE_VERSION */ uint32_t cmd; @@ -332,6 +337,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 +354,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; };