From patchwork Thu Dec 19 09:43:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexandru Stefan ISAILA X-Patchwork-Id: 11302935 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 AC780921 for ; Thu, 19 Dec 2019 09:44:44 +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 7C4E2206B7 for ; Thu, 19 Dec 2019 09:44:44 +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="ayE6DD+o" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7C4E2206B7 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 1ihsKx-0003cU-Sy; Thu, 19 Dec 2019 09:43:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ihsKw-0003cC-8F for xen-devel@lists.xenproject.org; Thu, 19 Dec 2019 09:43:14 +0000 X-Inumbo-ID: f3a50e84-2243-11ea-88e7-bc764e2007e4 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (unknown [40.107.0.107]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f3a50e84-2243-11ea-88e7-bc764e2007e4; Thu, 19 Dec 2019 09:43:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JJDE8MRTwdOS516QybxSvpQlS5rH5nk1+Lc0Cdwn7k3KOmhYOi78R1knB1EFBPMyt+TZuj3WckgGQtWt2wO3TpV1JDjkvdOw5LP4Fp0O1rDe55UzKSUsXZKQ1gXLQlOYSSfLvUJBm5ZZfUfh9P+WDqar08Y1nF5bwx8J0CIL+6QkExOEsbtaYFDksyYE3QFS1su4OTiTlV1sqVQA7u8CX5jOSRgtQ/WI71jmnsHu/IEN9pS4jeFj0ZNCdmeRvUvwjf893UB6lb2vLPL7h8vnRRQb3+bIxT9Y+dSem0xMUNYKqUn+4NttGBLGmVwU2H5oFvZou6imSuppQWRfLx3Tcw== 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=h2rROfhrv+TLhpZWCedIDHiUfzzT/+Jn05q0sZpkCSM=; b=GsQHr1AExzw/+8xYI4iJ5l/ii2xZhH8G2DTWlxMkB9k8s0e5vjJAX9Eby8ybrihvt98gNZZotcThpypLZsnA52dDgoHks5cZBUDpMfaWLnxmdHXYArqrCc5cL5s+o3a5+6PQIiWv14RU+49VZBSDYYw7pV6h7yepctfLKjHRoKQrLdthcRUEZBx/URFPGFg5m/ns92bQpjEmk00T/iIJB80qpFQbq4Chwaf1Zt1QQoBoqJp3N4IEu7dJxr3iA7QRuRNGzaNdgdOJ3E4Y+kstlWjeaSdXsxsxudmvgb3vK7l7lwCi+qBK0tZuvPPaX4Xj+mKPeFABIiFtbzxUSSFkgA== 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=h2rROfhrv+TLhpZWCedIDHiUfzzT/+Jn05q0sZpkCSM=; b=ayE6DD+oiwvDaw82Na6id7ZbMDZABPDfutOz63EV6KnSqrFS7Iam5WQ94UGsEjAEw97va/vE3zc9oj/I9X8hSDAUXU7Gg4GcnIej/Qrmnnap0G6JewQ0/G8koDPHZ/mLqpjv6uMZaB6pWDtmQpo3Z08fp62y58bdCQf+vzOSsYk= Received: from AM0PR02MB5553.eurprd02.prod.outlook.com (10.255.30.78) by AM0PR02MB3604.eurprd02.prod.outlook.com (52.134.80.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2559.15; Thu, 19 Dec 2019 09:43:02 +0000 Received: from AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d]) by AM0PR02MB5553.eurprd02.prod.outlook.com ([fe80::8cec:7638:734c:89d%4]) with mapi id 15.20.2559.015; Thu, 19 Dec 2019 09:43:02 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH V5 4/4] x86/mm: Make use of the default access param from xc_altp2m_create_view Thread-Index: AQHVtlC0axyOFCcTm0GbblWfn3zm3Q== Date: Thu, 19 Dec 2019 09:43:02 +0000 Message-ID: <20191219094236.22002-4-aisaila@bitdefender.com> References: <20191219094236.22002-1-aisaila@bitdefender.com> In-Reply-To: <20191219094236.22002-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM0PR05CA0074.eurprd05.prod.outlook.com (2603:10a6:208:136::14) To AM0PR02MB5553.eurprd02.prod.outlook.com (2603:10a6:208:160::14) 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: c58f687d-222c-4904-102e-08d78467d70d x-ms-traffictypediagnostic: AM0PR02MB3604:|AM0PR02MB3604:|AM0PR02MB3604: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2582; x-forefront-prvs: 0256C18696 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(376002)(39860400002)(346002)(136003)(366004)(396003)(189003)(199004)(7416002)(36756003)(186003)(2906002)(71200400001)(1076003)(26005)(2616005)(4326008)(478600001)(6486002)(5660300002)(6916009)(81166006)(81156014)(8676002)(6506007)(8936002)(54906003)(66476007)(52116002)(316002)(6512007)(86362001)(66946007)(66446008)(64756008)(66556008); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR02MB3604; H:AM0PR02MB5553.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: wH/LiJLg3boGTswwDm49Q0z1FtSNXpXOFqodGpbBlx0HADr4n//qEoWJUWiMfJCQ/F7izOv/c2bRFuIGvn+/+83T1W2Awsxwy/fA+BpXZzJIRc2u5bz6J8LPRcm1x/b6I+9zFGmPillQu1S5oupsQB3G0AId1J6rTJWSyucqtzq6asktpuAUPcFaVgrftT83Z/KssGILrurULVoLlnQYDvQsqPeP8/Mz0xmohBjg9j9jqWbWb7hjghmEdZbQKzzFRH/nLz9fpQ2Xk57ty/eGk7fZrgjAUJlqFiIYsjQk24vwK5LM5yDz+wOQjh6Vs7XxwBsbr09Wxj2tfrLNA7sVuSd824wJkY82g3mqiJBNa1hpF0Y5YggcsH3gbXpkp0y1vSQ9yBlhz5JUCFVLMUWVAO98RvXjDcCUHEDP18dnz4LwIcMiKiPkHLW/x0V3t7lJ Content-ID: <9F535C933703CB4FB809FA795A69EE81@eurprd02.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: c58f687d-222c-4904-102e-08d78467d70d X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Dec 2019 09:43:02.2888 (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: HhOt577oCtuHs95w0Gd+52bYxryJp3eQHm5ei2S+HNYELYz2YiOQbn+4tshlqffu9Uk1BYEIKM2xEIF3jNNMTw3Sjoqw1uO605QvKjQ1rYI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR02MB3604 Subject: [Xen-devel] [PATCH V5 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 --- 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 V4: - Add const struct p2m_domain *p2m to xenmem_access_to_p2m_access() - Pull xenmem_access_to_p2m_access() out of the locked area - Add a check for NULL p2m in xenmem_access_to_p2m_access(). --- xen/arch/x86/hvm/hvm.c | 3 ++- xen/arch/x86/mm/mem_access.c | 11 +++++++---- xen/arch/x86/mm/p2m.c | 21 ++++++++++++++++----- 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, 31 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 98d1d9788b..d7a55568c9 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -4687,7 +4687,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 33e379db8f..5b74a6898b 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 @@ -340,7 +340,10 @@ static bool xenmem_access_to_p2m_access(struct p2m_domain *p2m, *paccess = memaccess[xaccess]; break; case XENMEM_access_default: - *paccess = p2m->default_access; + if ( !p2m ) + *paccess = p2m_access_rwx; + else + *paccess = p2m->default_access; break; default: return false; diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index cb5b8d67d1..2774811bb8 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 @@ -2533,7 +2534,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; @@ -2559,7 +2561,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); @@ -2576,6 +2578,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 >= MAX_ALTP2M ) return rc; @@ -2584,16 +2587,23 @@ int p2m_init_altp2m_by_id(struct domain *d, unsigned int idx) altp2m_list_lock(d); if ( d->arch.altp2m_eptp[idx] == 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 *p2m; + + if ( hvmmem_default_access > XENMEM_access_default || + !xenmem_access_to_p2m_access(NULL, hvmmem_default_access, &a) ) + return rc; altp2m_list_lock(d); @@ -2602,7 +2612,8 @@ 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); + p2m = d->arch.altp2m_p2m[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 5446d634d8..49816d9312 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.