From patchwork Fri Jan 17 13:31:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11339027 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2D09214B7 for ; Fri, 17 Jan 2020 13:32:53 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F0EEF206B7 for ; Fri, 17 Jan 2020 13:32:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=bitdefender.onmicrosoft.com header.i=@bitdefender.onmicrosoft.com header.b="hAX2f4HB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F0EEF206B7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bitdefender.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isRiz-0004EE-Io; Fri, 17 Jan 2020 13:31:45 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1isRiy-0004Dw-Fn for xen-devel@lists.xenproject.org; Fri, 17 Jan 2020 13:31:44 +0000 X-Inumbo-ID: ae9b2016-392d-11ea-9fd7-bc764e2007e4 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe0e::712]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ae9b2016-392d-11ea-9fd7-bc764e2007e4; Fri, 17 Jan 2020 13:31:36 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nYkBgqnkyAVrS8voF+t5fm4s4XkmFdZGiVzSn4oRt1bUw8WHjdT2dk37K2cXvf/fs5Gtt/Ijl4jIpexEyRoc3gfvu+eG6MBRP+g9vzlEDmIcwtqRoPFrSIkNGQHBArJN0WgIZlGfRoSlEqhRw1TrcojwI9+rsbErRfeuR4AMhCnQCvZA8eGbNDkYu01XBuI9uKtjnYkvaTTy9FkR+p05K58dlCySgLr9czvr7uW1Zpk7JQIk+ayV8XSbjATkSjEGXpXS9GAUE9aRTHzOUI64RN1nDYwrpvrcwuvlsQiWW38mNnUSdoTmxaAz1ziQI791zZEdMtBimtqCvmBx/P04yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tKkiEIFep5Gag6ffzhkeq6WwkrhpReS6HP+mEeiQp3M=; b=DLFpVXqvq3uuRRoqhhKD2bsIqfeTc69EBVGxtftMi3vITvvaJHMZeVFCbd0XT+dkxFGJAyA4WllStlAGTl6ZXI0PEpmFr8z6OISx0zIILPPQafwRakwQP1ywzh3SyLaeUy8Xkb7HfsSM3o2jsmqaBocYGUy4FRVQ+cVE8slBi4/BN1S3XF5v6McJT+SeKuAmuQn7ZCpN15IS4yRE5FVnFx0/WhbQtNs9Q6vWdzTwkzzq6Tu5CZqRZ3s7DA1FpxElXyXyIWxw41b0JTdUcvZMpcIyP48BFBecjddQcWUJX8WX0ps6bYbZFWMYuwdJxYI+0sxdPfYmoAaDm6Mohog/VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bitdefender.com; dmarc=pass action=none header.from=bitdefender.com; dkim=pass header.d=bitdefender.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector2-bitdefender-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tKkiEIFep5Gag6ffzhkeq6WwkrhpReS6HP+mEeiQp3M=; b=hAX2f4HBV5tDbkEPupV+/uOfaM/ot0kDJ0y7JLRZtf2/QearRlAOw92UyAqI+e49hp3L0Vb02sxOBph3R0x7tybkrP4xOjKNVjfq2reuXIqOz7semeXo/apE+lIhxHaMZUbk6Ie+b/VLr8jFM08G13dbYSajmXZl6tddhhIVxPU= Received: from DB6PR02MB2999.eurprd02.prod.outlook.com (10.170.219.144) by DB6PR02MB3160.eurprd02.prod.outlook.com (10.170.220.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2623.12; Fri, 17 Jan 2020 13:31:34 +0000 Received: from DB6PR02MB2999.eurprd02.prod.outlook.com ([fe80::f1c2:7dd1:1131:1c1d]) by DB6PR02MB2999.eurprd02.prod.outlook.com ([fe80::f1c2:7dd1:1131:1c1d%7]) with mapi id 15.20.2644.023; Fri, 17 Jan 2020 13:31:34 +0000 Received: from aisaila-Latitude-E5570.dsd.bitdefender.biz (91.199.104.6) by AM0PR0402CA0004.eurprd04.prod.outlook.com (2603:10a6:208:15::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Fri, 17 Jan 2020 13:31:32 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V8 4/4] x86/mm: Make use of the default access param from xc_altp2m_create_view Thread-Index: AQHVzTpv5ZLQiQKNJUyjMfvbmY7/kg== Date: Fri, 17 Jan 2020 13:31:33 +0000 Message-ID: <20200117133059.14602-4-aisaila@bitdefender.com> References: <20200117133059.14602-1-aisaila@bitdefender.com> In-Reply-To: <20200117133059.14602-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR0402CA0004.eurprd04.prod.outlook.com (2603:10a6:208:15::17) To DB6PR02MB2999.eurprd02.prod.outlook.com (2603:10a6:6:17::16) 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: d35c0483-2b1d-4994-14f7-08d79b5191d6 x-ms-traffictypediagnostic: DB6PR02MB3160:|DB6PR02MB3160: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2958; x-forefront-prvs: 0285201563 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(39850400004)(396003)(346002)(136003)(366004)(189003)(199004)(186003)(2616005)(52116002)(956004)(26005)(6512007)(16526019)(6506007)(71200400001)(81156014)(36756003)(66946007)(8676002)(66476007)(66446008)(64756008)(66556008)(81166006)(86362001)(7416002)(6486002)(316002)(5660300002)(8936002)(54906003)(1076003)(478600001)(6916009)(2906002)(4326008); DIR:OUT; SFP:1102; SCL:1; SRVR:DB6PR02MB3160; H:DB6PR02MB2999.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: BCL:0; x-microsoft-antispam-message-info: 7heIFMuL8T/4DeVDcO7Uv2UanhlismWgRu0R3uySOfstkoZRmLu9cMfKKUg8pN8v2/2KB/wRkMV+CKsV1b/PgSPMbyK0nvJe7/d9kmAkjtIoXkz0iLkwAb99lJ9neO49xzRasJbYc9vB8U4fHThLEcCb//atyEUe+3Y7UU+hkPhlHJFARKuBy0+HPNaCNMpJZZ2AYzlZsuCPPmum0UDl9PPYr4Lfwh97eU784Lx4IXCW7CRCE/azBuZw5S+zUVFLCB3mXh9LEWm4NX/nIxZVF4zG4to7rVcpCEfp6pMunPO9z5yeHhIcQ8SE4ATT4zDoVCNr3/xYo1GFFjPuuWNrfV0/tZ5A+O7GrLmx6y3vn5roKDYg1A3H7/9mAZY5lTst10xI2qX3o9lcSQsS+a620Ou26CrR81HSQlHuEa9m2iikf2p9BUhK16um4C2L0xwC Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: d35c0483-2b1d-4994-14f7-08d79b5191d6 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2020 13:31:33.9136 (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: eArH0r09JiwaeYcQ+uyUFDzWD6W2+yIJGWVKN0u8hIi6Yv0On6uyLIvzFoh/t3Z+RYp/n9yYaM3HdVkoYucv/cUWB4cET8CodRclrEOElAI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR02MB3160 Subject: [Xen-devel] [PATCH V8 4/4] x86/mm: Make use of the default access param from xc_altp2m_create_view 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: Petre Ovidiu PIRCALABU , Stefano Stabellini , Julien Grall , Razvan COJOCARU , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tamas K Lengyel , Jan Beulich , Alexandru Stefan ISAILA , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At this moment the default_access param from xc_altp2m_create_view is not used. This patch assigns default_access to p2m->default_access at the time of initializing a new altp2m view. Signed-off-by: Alexandru Isaila Acked-by: Jan Beulich Acked-by: Tamas K Lengyel Reviewed-by: Petre Pircalabu Acked-by: George Dunlap --- CC: Jan Beulich CC: Andrew Cooper CC: Wei Liu CC: "Roger Pau Monné" CC: George Dunlap CC: Ian Jackson CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Razvan Cojocaru CC: Tamas K Lengyel CC: Petre Pircalabu CC: George Dunlap --- Changes since V6: - Remove the NULL check for p2m in xenmem_access_to_p2m_access() - Use hostp2m for default access in p2m_init_next_altp2m() - Remove the artifact line from p2m_init_next_altp2m(). --- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/mm/mem_access.c | 6 +++--- xen/arch/x86/mm/p2m.c | 20 +++++++++++++++----- xen/include/asm-x86/p2m.h | 3 ++- xen/include/public/hvm/hvm_op.h | 2 -- xen/include/xen/mem_access.h | 4 ++++ 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 4d79b4934e..b96fafed65 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4654,7 +4654,8 @@ static int do_altp2m_op( } case HVMOP_altp2m_create_p2m: - if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view)) ) + if ( !(rc = p2m_init_next_altp2m(d, &a.u.view.view, + a.u.view.hvmmem_default_access)) ) rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0; break; diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 31ff826393..d16540a9aa 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -314,9 +314,9 @@ static int set_mem_access(struct domain *d, struct p2m_domain *p2m, return rc; } -static bool xenmem_access_to_p2m_access(struct p2m_domain *p2m, - xenmem_access_t xaccess, - p2m_access_t *paccess) +bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess) { static const p2m_access_t memaccess[] = { #define ACCESS(ac) [XENMEM_access_##ac] = p2m_access_##ac diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 696946697a..4599a0bc24 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -25,6 +25,7 @@ #include /* copy_from_guest() */ #include +#include #include #include #include @@ -2536,7 +2537,8 @@ void p2m_flush_altp2m(struct domain *d) altp2m_list_unlock(d); } -static int p2m_activate_altp2m(struct domain *d, unsigned int idx) +static int p2m_activate_altp2m(struct domain *d, unsigned int idx, + p2m_access_t hvmmem_default_access) { struct p2m_domain *hostp2m, *p2m; int rc; @@ -2562,7 +2564,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) goto out; } - p2m->default_access = hostp2m->default_access; + p2m->default_access = hvmmem_default_access; p2m->domain = hostp2m->domain; p2m->global_logdirty = hostp2m->global_logdirty; p2m->min_remapped_gfn = gfn_x(INVALID_GFN); @@ -2579,6 +2581,7 @@ static int p2m_activate_altp2m(struct domain *d, unsigned int idx) int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) { int rc = -EINVAL; + struct p2m_domain *hostp2m = p2m_get_hostp2m(d); if ( idx >= min(ARRAY_SIZE(d->arch.altp2m_p2m), MAX_EPTP) ) return rc; @@ -2587,16 +2590,23 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) if ( d->arch.altp2m_eptp[array_index_nospec(idx, MAX_EPTP)] == mfn_x(INVALID_MFN) ) - rc = p2m_activate_altp2m(d, idx); + rc = p2m_activate_altp2m(d, idx, hostp2m->default_access); altp2m_list_unlock(d); return rc; } -int p2m_init_next_altp2m(struct domain *d, uint16_t *idx) +int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, + xenmem_access_t hvmmem_default_access) { int rc = -EINVAL; unsigned int i; + p2m_access_t a; + struct p2m_domain *hostp2m = p2m_get_hostp2m(d); + + if ( hvmmem_default_access > XENMEM_access_default || + !xenmem_access_to_p2m_access(hostp2m, hvmmem_default_access, &a) ) + return rc; altp2m_list_lock(d); @@ -2605,7 +2615,7 @@ int p2m_init_next_altp2m(struct domain *d, uint16_t *idx) if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) ) continue; - rc = p2m_activate_altp2m(d, i); + rc = p2m_activate_altp2m(d, i, a); if ( !rc ) *idx = i; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 94285db1b4..ac2d2787f4 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -884,7 +884,8 @@ bool p2m_altp2m_get_or_propagate(struct p2m_domain *ap2m, unsigned long gfn_l, int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx); /* Find an available alternate p2m and make it valid */ -int p2m_init_next_altp2m(struct domain *d, uint16_t *idx); +int p2m_init_next_altp2m(struct domain *d, uint16_t *idx, + xenmem_access_t hvmmem_default_access); /* Make a specific alternate p2m invalid */ int p2m_destroy_altp2m_by_id(struct domain *d, unsigned int idx); diff --git a/xen/include/public/hvm/hvm_op.h b/xen/include/public/hvm/hvm_op.h index d344606864..610e020a62 100644 --- a/xen/include/public/hvm/hvm_op.h +++ b/xen/include/public/hvm/hvm_op.h @@ -251,8 +251,6 @@ DEFINE_XEN_GUEST_HANDLE(xen_hvm_altp2m_vcpu_disable_notify_t); struct xen_hvm_altp2m_view { /* IN/OUT variable */ uint16_t view; - /* Create view only: default access type - * NOTE: currently ignored */ uint16_t hvmmem_default_access; /* xenmem_access_t */ }; typedef struct xen_hvm_altp2m_view xen_hvm_altp2m_view_t; diff --git a/xen/include/xen/mem_access.h b/xen/include/xen/mem_access.h index 00e594a0ad..5d53fb8ce4 100644 --- a/xen/include/xen/mem_access.h +++ b/xen/include/xen/mem_access.h @@ -58,6 +58,10 @@ typedef enum { /* NOTE: Assumed to be only 4 bits right now on x86. */ } p2m_access_t; +bool xenmem_access_to_p2m_access(const struct p2m_domain *p2m, + xenmem_access_t xaccess, + p2m_access_t *paccess); + /* * Set access type for a region of gfns. * If gfn == INVALID_GFN, sets the default access type.