From patchwork Fri Jun 7 09:37:57 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: 10981225 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 0B43D92A for ; Fri, 7 Jun 2019 09:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EABCE28A39 for ; Fri, 7 Jun 2019 09:40:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D9AB428877; Fri, 7 Jun 2019 09:40:11 +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 565CA28877 for ; Fri, 7 Jun 2019 09:40:11 +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 1hZBK0-0004pL-FI; Fri, 07 Jun 2019 09:38:04 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hZBJy-0004pG-7R for xen-devel@lists.xenproject.org; Fri, 07 Jun 2019 09:38:02 +0000 X-Inumbo-ID: f0425003-8907-11e9-8980-bc764e045a96 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe0e::72f]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f0425003-8907-11e9-8980-bc764e045a96; Fri, 07 Jun 2019 09:38:01 +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=Km8AtrdbY1ZidZdzjCLyzWXX908YboU+9DyeCIF4D64=; b=aT0bKNIIFVS9j1sMqp8NTSYcGKX3EGfPVlOV+/BkDbiEb8CoyAmWYXN9IiLdB1fjsgh4AZASK0PDwAKUXLoHTFIVEYY9qtLSbjuMwLVqdQQLQIX/PnT/YlKaFaJUxCgK8nXoPeTJ7CYXqIXihGYC6BZgFyJpnolAU8tMmXGahFw= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.106.11) by VI1PR0202MB3485.eurprd02.prod.outlook.com (52.134.17.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1965.14; Fri, 7 Jun 2019 09:37:57 +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 09:37:57 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2] x86/altp2m: Add xc_altp2m_get_vcpu_p2m_idx Thread-Index: AQHVHRSwfhPesTKM7U69gwFU2tlnGA== Date: Fri, 7 Jun 2019 09:37:57 +0000 Message-ID: <20190607093741.9976-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM4PR08CA0064.eurprd08.prod.outlook.com (2603:10a6:205:2::35) 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: 40e4b25e-3981-4c14-ebe9-08d6eb2bd2b4 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:VI1PR0202MB3485; x-ms-traffictypediagnostic: VI1PR0202MB3485:|VI1PR0202MB3485: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:580; x-forefront-prvs: 0061C35778 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(346002)(366004)(376002)(396003)(136003)(189003)(199004)(50226002)(478600001)(3846002)(2616005)(6116002)(102836004)(36756003)(14444005)(386003)(7736002)(256004)(86362001)(2501003)(2906002)(5640700003)(2351001)(6436002)(1076003)(6512007)(66066001)(5660300002)(14454004)(6486002)(186003)(54906003)(8936002)(53936002)(25786009)(316002)(68736007)(107886003)(26005)(81166006)(81156014)(6506007)(6916009)(52116002)(66476007)(4326008)(73956011)(476003)(7416002)(305945005)(71190400001)(8676002)(99286004)(486006)(66446008)(66946007)(64756008)(71200400001)(66556008)(70780200001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3485; 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: iNs76HAx5fkHgWGUJ3WwL0f/jKnFmfllU40ZsleoWKOqBFY8U22Ir0UbX51mYO/wZ9PJYqn/3WIeviK+0LyKreR+5uB/xul8SwCrnFgI4DMhyD+UObcfPJFmxH5r1rZ+B2BP8ReNNHszr3QA2P/z8EZrCCAyiKDa1SjxduouypypjqFBil6cODpTZTDp2ye9C2cAstVrRcJStoTHTj+GaUc8rbxVigxaWNz/XDf/H9cML/fxHhH/TLntjDMVfvj15CoEgdHQqzb+oPLMEvk8P+NlsOGks1zUclIM/OeYaMQkQcCQSCgSpmIUNVgbn09qxeJ2hfDDG/ljt/4LwROw7DaoKNQGPocBFY1WG6lVSzKZMaSb1ZqeH0xYrqn9rlQaZ77S9GFlmNAi/lnaH4plx8ZdJDRH081diVZfLZaR/jY= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 40e4b25e-3981-4c14-ebe9-08d6eb2bd2b4 X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Jun 2019 09:37:57.5481 (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: VI1PR0202MB3485 Subject: [Xen-devel] [PATCH v2] 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 vcpu. Signed-off-by: Alexandru Isaila --- Changes since V3: - Use domain_vcpu() - Drop xen_hvm_altp2m_get_vcpu_p2m_idx_t. --- 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 | 8 ++++++++ 4 files changed, 59 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..5d631c055e 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 = domain_vcpu(d, 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..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; };