From patchwork Tue Apr 9 12:03:55 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: 10891159 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 1E6C117EF for ; Tue, 9 Apr 2019 12:05:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B81B28880 for ; Tue, 9 Apr 2019 12:05:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F408A28898; Tue, 9 Apr 2019 12:05: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 6323928880 for ; Tue, 9 Apr 2019 12:05:52 +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 1hDpTu-0005qQ-QF; Tue, 09 Apr 2019 12:04:02 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hDpTt-0005q6-23 for xen-devel@lists.xenproject.org; Tue, 09 Apr 2019 12:04:01 +0000 X-Inumbo-ID: 8e2676e5-5abf-11e9-92d7-bc764e045a96 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe05::718]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 8e2676e5-5abf-11e9-92d7-bc764e045a96; Tue, 09 Apr 2019 12:03:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector1-bitdefender-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fa0WiHB7fefqxY4WR8gXgfCa01jxg6OzS0oP3+40lmM=; b=EomrqKe4n2uvKBv1UcUUb3e8ASyepZSYgXCkXkGzCwj+6fWD7Pb1G4yMU872cg+taiquDJx1qzOsGkNtIJ64y9nlOYXNuqaqnpgAoC/xbZWEKDbS3PppYI7JBcNDk0a19PG9M4eXNNaAbAOcm/eknFb/SkmzwByHVmKwmH037CQ= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3328.eurprd02.prod.outlook.com (52.134.15.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.21; Tue, 9 Apr 2019 12:03:55 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1%9]) with mapi id 15.20.1771.016; Tue, 9 Apr 2019 12:03:55 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3 1/3] x86/mm: Introduce altp2m_get_gfn_type_access Thread-Index: AQHU7sxOthwR4rIdkUC4dpiYJsWlRg== Date: Tue, 9 Apr 2019 12:03:55 +0000 Message-ID: <20190409120324.13940-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR05CA0013.eurprd05.prod.outlook.com (2603:10a6:20b:2e::26) To VI1PR0202MB2928.eurprd02.prod.outlook.com (2603:10a6:800:de::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: 83dadeb8-fec6-4bd5-c80b-08d6bce3707e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3328; x-ms-traffictypediagnostic: VI1PR0202MB3328:|VI1PR0202MB3328: x-microsoft-antispam-prvs: x-forefront-prvs: 000227DA0C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(39860400002)(376002)(366004)(346002)(189003)(199004)(6916009)(66066001)(6436002)(54906003)(3846002)(6512007)(8676002)(52116002)(6116002)(53936002)(102836004)(1076003)(486006)(97736004)(86362001)(316002)(81156014)(6486002)(81166006)(5660300002)(71200400001)(71190400001)(4326008)(5640700003)(26005)(2906002)(386003)(107886003)(2351001)(8936002)(478600001)(6506007)(14444005)(25786009)(186003)(106356001)(256004)(305945005)(105586002)(68736007)(14454004)(50226002)(476003)(99286004)(7736002)(2501003)(2616005)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3328; 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: WkVCUQMPNe7RuDR8ijXoBpx/6V01o1WiOVsu2uOqbcZT9n3WKTsHBTC/SVdt5+8uaH1clR9tMz0yqxp0pOYlqE+WNCthoyBOP7e9BO28XesX+FLAhUTYwGMuAYKzni3O/WMmJtAt+IWSBBpqpyq08Obya/ucfgI5Y4bpchrD7EcKqCxemPT5Y8CsKboIkLSb+Jhtba3N7J0ehgOdifcc6HM+fQN7/HeNc0Nxue0ICnFEPeQnousxY1B6YgS8Q4xPLrer8Fdj0sGh8E5w+vQmSqpuv2KI0NE3MP60BGeujzwXSyp5dKixi7dlCVnmtESKPG5ev5CedRSdrJrVMA21r86TF8mOmHL7btbd59lYYXie3AQV2TgOLJQ/V1cTng1AOIwj8KomNwtGppU4CTwQn0teI8BNjtmmzFJTGv/5Xv8= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83dadeb8-fec6-4bd5-c80b-08d6bce3707e X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2019 12:03:55.3791 (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-Transport-CrossTenantHeadersStamped: VI1PR0202MB3328 Subject: [Xen-devel] [PATCH v3 1/3] x86/mm: Introduce altp2m_get_gfn_type_access 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: "tamas@tklengyel.com" , "wei.liu2@citrix.com" , "rcojocaru@bitdefender.com" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.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 patch moves common code from p2m_set_altp2m_mem_access() and p2m_change_altp2m_gfn() into one function Signed-off-by: Alexandru Isaila Signed-off-by: George Dunlap Signed-off-by: Alexandru Isaila --- Changes since V2: - Change var name from found_in_hostp2m to copied_from_hostp2m - Move the type check from altp2m_get_gfn_type_access() to the callers. --- xen/arch/x86/mm/mem_access.c | 32 ++++++++++++---------------- xen/arch/x86/mm/p2m.c | 41 ++++++++++++++---------------------- xen/include/asm-x86/p2m.h | 19 +++++++++++++++++ 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 56c06a4fc6..bf67ddb15a 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -265,31 +265,27 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, unsigned int page_order; unsigned long gfn_l = gfn_x(gfn); int rc; + bool copied_from_hostp2m; - mfn = ap2m->get_entry(ap2m, gfn, &t, &old_a, 0, NULL, NULL); + mfn = altp2m_get_gfn_type_access(ap2m, gfn, &t, &old_a, &page_order, &copied_from_hostp2m); - /* Check host p2m if no valid entry in alternate */ if ( !mfn_valid(mfn) ) + return -ESRCH; + + /* If this is a superpage, copy that first */ + if ( page_order != PAGE_ORDER_4K && copied_from_hostp2m ) { + unsigned long mask = ~((1UL << page_order) - 1); + gfn_t gfn2 = _gfn(gfn_l & mask); + mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); - mfn = __get_gfn_type_access(hp2m, gfn_l, &t, &old_a, - P2M_ALLOC | P2M_UNSHARE, &page_order, 0); + /* Note: currently it is not safe to remap to a shared entry */ + if ( t != p2m_ram_rw ) + return -ESRCH; - rc = -ESRCH; - if ( !mfn_valid(mfn) || t != p2m_ram_rw ) + rc = ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, old_a, 1); + if ( rc ) return rc; - - /* If this is a superpage, copy that first */ - if ( page_order != PAGE_ORDER_4K ) - { - unsigned long mask = ~((1UL << page_order) - 1); - gfn_t gfn2 = _gfn(gfn_l & mask); - mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); - - rc = ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, old_a, 1); - if ( rc ) - return rc; - } } /* diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index b9bbb8f485..d38d7c29ca 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2626,6 +2626,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, mfn_t mfn; unsigned int page_order; int rc = -EINVAL; + bool copied_from_hostp2m; if ( idx >= MAX_ALTP2M || d->arch.altp2m_eptp[idx] == mfn_x(INVALID_MFN) ) return rc; @@ -2636,7 +2637,7 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, p2m_lock(hp2m); p2m_lock(ap2m); - mfn = ap2m->get_entry(ap2m, old_gfn, &t, &a, 0, NULL, NULL); + mfn = altp2m_get_gfn_type_access(ap2m, old_gfn, &t, &a, &page_order, &copied_from_hostp2m); if ( gfn_eq(new_gfn, INVALID_GFN) ) { @@ -2646,37 +2647,27 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, goto out; } - /* Check host p2m if no valid entry in alternate */ - if ( !mfn_valid(mfn) ) - { - mfn = __get_gfn_type_access(hp2m, gfn_x(old_gfn), &t, &a, - P2M_ALLOC, &page_order, 0); + if ( !mfn_valid(mfn) || (t != p2m_ram_rw && copied_from_hostp2m) ) + goto out; - if ( !mfn_valid(mfn) || t != p2m_ram_rw ) - goto out; - - /* If this is a superpage, copy that first */ - if ( page_order != PAGE_ORDER_4K ) - { - gfn_t gfn; - unsigned long mask; + /* If this is a superpage, copy that first */ + if ( page_order != PAGE_ORDER_4K && copied_from_hostp2m ) + { + gfn_t gfn; + unsigned long mask; - mask = ~((1UL << page_order) - 1); - gfn = _gfn(gfn_x(old_gfn) & mask); - mfn = _mfn(mfn_x(mfn) & mask); + mask = ~((1UL << page_order) - 1); + gfn = _gfn(gfn_x(old_gfn) & mask); + mfn = _mfn(mfn_x(mfn) & mask); - if ( ap2m->set_entry(ap2m, gfn, mfn, page_order, t, a, 1) ) - goto out; - } + if ( ap2m->set_entry(ap2m, gfn, mfn, page_order, t, a, 1) ) + goto out; } - mfn = ap2m->get_entry(ap2m, new_gfn, &t, &a, 0, NULL, NULL); - - if ( !mfn_valid(mfn) ) - mfn = hp2m->get_entry(hp2m, new_gfn, &t, &a, 0, NULL, NULL); + mfn = altp2m_get_gfn_type_access(ap2m, new_gfn, &t, &a, &page_order, &copied_from_hostp2m); /* Note: currently it is not safe to remap to a shared entry */ - if ( !mfn_valid(mfn) || (t != p2m_ram_rw) ) + if ( !mfn_valid(mfn) || (t != p2m_ram_rw && copied_from_hostp2m) ) goto out; if ( !ap2m->set_entry(ap2m, old_gfn, mfn, PAGE_ORDER_4K, t, a, diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 2801a8ccca..6de1546d76 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -448,6 +448,25 @@ static inline mfn_t __nonnull(3) get_gfn_type( return get_gfn_type_access(p2m_get_hostp2m(d), gfn, t, &a, q, NULL); } +static inline mfn_t altp2m_get_gfn_type_access( + struct p2m_domain *ap2m, gfn_t gfn, p2m_type_t *t, p2m_access_t *a, + unsigned int *page_order, bool *copied_from_hostp2m) +{ + mfn_t mfn = ap2m->get_entry(ap2m, gfn, t, a, 0, NULL, NULL); + + *copied_from_hostp2m = false; + + /* Check host p2m if no valid entry in alternate */ + if ( !mfn_valid(mfn) ) + { + mfn = __get_gfn_type_access(p2m_get_hostp2m(ap2m->domain), gfn_x(gfn), t, a, + P2M_ALLOC | P2M_UNSHARE, page_order, false); + *copied_from_hostp2m = mfn_valid(mfn); + } + + return mfn; +} + /* Syntactic sugar: most callers will use one of these. */ #define get_gfn(d, g, t) get_gfn_type((d), (g), (t), P2M_ALLOC) #define get_gfn_query(d, g, t) get_gfn_type((d), (g), (t), 0) From patchwork Tue Apr 9 12:03:58 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: 10891155 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 C18C51515 for ; Tue, 9 Apr 2019 12:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AE2E428824 for ; Tue, 9 Apr 2019 12:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1FC82888D; Tue, 9 Apr 2019 12:05:49 +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 425E428824 for ; Tue, 9 Apr 2019 12:05:49 +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 1hDpTw-0005ql-39; Tue, 09 Apr 2019 12:04: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 1hDpTu-0005qE-AS for xen-devel@lists.xenproject.org; Tue, 09 Apr 2019 12:04:02 +0000 X-Inumbo-ID: 8f8c61fb-5abf-11e9-92d7-bc764e045a96 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe05::718]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 8f8c61fb-5abf-11e9-92d7-bc764e045a96; Tue, 09 Apr 2019 12:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector1-bitdefender-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=owta9WrNUe0kPuZmGRjF2IO/FGMqGR2j75nhjLn8wSM=; b=btCXUyMJwn4KrRyAQm2qfIHCTFt7Bbf6/HEIt+I1lxD+nEMr7Ph060uKsp7UrXmC8bBw10YQPMSVkRYOS9c42NkGfcq+sDmQnqxXSN3jOIl+MjYv5yFGqOaJcuzjdZjPwJtb/kNE7ZdjdH4PrBccXUyiXt1MxwrcNrxjaosZAE8= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3328.eurprd02.prod.outlook.com (52.134.15.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.21; Tue, 9 Apr 2019 12:03:58 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1%9]) with mapi id 15.20.1771.016; Tue, 9 Apr 2019 12:03:58 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3 2/3] x86/mm: Introduce altp2m_set_entry_by_page_order Thread-Index: AQHU7sxQ+KX9XNKHYECIICmH90QLYA== Date: Tue, 9 Apr 2019 12:03:58 +0000 Message-ID: <20190409120324.13940-2-aisaila@bitdefender.com> References: <20190409120324.13940-1-aisaila@bitdefender.com> In-Reply-To: <20190409120324.13940-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR05CA0013.eurprd05.prod.outlook.com (2603:10a6:20b:2e::26) To VI1PR0202MB2928.eurprd02.prod.outlook.com (2603:10a6:800:de::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: c95226dc-aa99-4513-7e0f-08d6bce3724f x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3328; x-ms-traffictypediagnostic: VI1PR0202MB3328:|VI1PR0202MB3328: x-microsoft-antispam-prvs: x-forefront-prvs: 000227DA0C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(39860400002)(376002)(366004)(346002)(189003)(199004)(6916009)(66066001)(6436002)(54906003)(3846002)(6512007)(8676002)(52116002)(6116002)(53936002)(102836004)(1076003)(486006)(97736004)(86362001)(316002)(81156014)(6486002)(81166006)(5660300002)(71200400001)(71190400001)(4326008)(5640700003)(26005)(2906002)(386003)(107886003)(2351001)(8936002)(478600001)(6506007)(14444005)(25786009)(186003)(106356001)(256004)(305945005)(11346002)(105586002)(68736007)(14454004)(76176011)(50226002)(476003)(99286004)(7736002)(2501003)(2616005)(446003)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3328; 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: eUHoPNC+0z2gUe37MdHARAbD6Q7HpPfMTGLNv2VqlR7Qkf5Al+GgadFYLg+BDmP/wKnFRWWkpNXKmYRg2HiY9VVk05beFzwQuBjZ+fFMIfxWVUAE0L4DgMQZ7+RIz+QCebdT6KnGrVbmzlcnLlc/xCYEccIpMAgu1KvgPYa98d5VzQ+RN92UcCtImJlKQz90RDClcaEDR8+aYUL9GxH/EhjOXb+jGBSr4U+cdz+z2Vj7t8WzOjFMxxUfcypK4Vp+uNiJKCt9BKPWHHF+pPWxsoTJdoW6HL1W5Urny/Wpm8CdCgCN84tFMo9Sktt+zUHSw4TlJfqJCuLzf6Osy12jXOfwvzxA80jIRBcn+v+8LVwcFfkEOyQ0N2yJJGnmr3/Ukxeb6lfLbit8tcwfVO8IEAIKXZ7sILtvt/v9/YQSPrE= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: c95226dc-aa99-4513-7e0f-08d6bce3724f X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2019 12:03:58.3646 (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-Transport-CrossTenantHeadersStamped: VI1PR0202MB3328 Subject: [Xen-devel] [PATCH v3 2/3] x86/mm: Introduce altp2m_set_entry_by_page_order 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: "tamas@tklengyel.com" , "wei.liu2@citrix.com" , "rcojocaru@bitdefender.com" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.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 patch moves common code from p2m_set_altp2m_mem_access() and p2m_change_altp2m_gfn() into one function Signed-off-by: Alexandru Isaila --- xen/arch/x86/mm/mem_access.c | 2 +- xen/include/asm-x86/p2m.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index bf67ddb15a..6a22512555 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -279,7 +279,7 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, gfn_t gfn2 = _gfn(gfn_l & mask); mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); - /* Note: currently it is not safe to remap to a shared entry */ + /* Note: currently it is not safe to remap to a shared entry */ if ( t != p2m_ram_rw ) return -ESRCH; diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 6de1546d76..90a6c135a7 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -467,6 +467,17 @@ static inline mfn_t altp2m_get_gfn_type_access( return mfn; } +static inline int altp2m_set_entry_by_page_order( + struct p2m_domain *ap2m, unsigned long gfn, mfn_t mfn, + unsigned int page_order, p2m_type_t t, p2m_access_t a) +{ + unsigned long mask = ~((1UL << page_order) - 1); + gfn_t gfn2 = _gfn(gfn & mask); + mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); + + return ap2m->set_entry(ap2m, gfn2, mfn2, page_order, t, a, 1); +} + /* Syntactic sugar: most callers will use one of these. */ #define get_gfn(d, g, t) get_gfn_type((d), (g), (t), P2M_ALLOC) #define get_gfn_query(d, g, t) get_gfn_type((d), (g), (t), 0) From patchwork Tue Apr 9 12:04:00 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: 10891157 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 BB88417EF for ; Tue, 9 Apr 2019 12:05:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A889128880 for ; Tue, 9 Apr 2019 12:05:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9C96F2888D; Tue, 9 Apr 2019 12:05:51 +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 506F128824 for ; Tue, 9 Apr 2019 12:05:51 +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 1hDpTw-0005r7-DL; Tue, 09 Apr 2019 12:04: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 1hDpTu-0005qF-B5 for xen-devel@lists.xenproject.org; Tue, 09 Apr 2019 12:04:02 +0000 X-Inumbo-ID: 9015082d-5abf-11e9-92d7-bc764e045a96 Received: from EUR02-HE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe05::718]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 9015082d-5abf-11e9-92d7-bc764e045a96; Tue, 09 Apr 2019 12:04:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bitdefender.onmicrosoft.com; s=selector1-bitdefender-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NDKhZAoi1Ql3FNdnpucSDMHqWk+uaYPCr+59SLfRSIA=; b=OSC1HMZcxlrMTSWLKy3XO2Cx7/eMr2sU6piET10qnM/cjpDHqAKHWiy5YRgdQLfzbUf/iRfqgsWMns6daaBN/7p6QI6B+05r0cuEbS9bzXUK2NsYUWgUt1tvqNUoLDbdHqN/4ee6oYafprmbJX4aUDZJkBeGysDuOTOhaaGwnNc= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3328.eurprd02.prod.outlook.com (52.134.15.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.21; Tue, 9 Apr 2019 12:04:00 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::dcda:38be:3bd6:14f1%9]) with mapi id 15.20.1771.016; Tue, 9 Apr 2019 12:04:00 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3 3/3] x86/mm: Fix p2m_set_suppress_ve Thread-Index: AQHU7sxQFaeXQ0Sbd0+5R1BM40gWCw== Date: Tue, 9 Apr 2019 12:04:00 +0000 Message-ID: <20190409120324.13940-3-aisaila@bitdefender.com> References: <20190409120324.13940-1-aisaila@bitdefender.com> In-Reply-To: <20190409120324.13940-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR05CA0013.eurprd05.prod.outlook.com (2603:10a6:20b:2e::26) To VI1PR0202MB2928.eurprd02.prod.outlook.com (2603:10a6:800:de::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: a390dd93-0f59-4041-7882-08d6bce3734b x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3328; x-ms-traffictypediagnostic: VI1PR0202MB3328:|VI1PR0202MB3328: x-microsoft-antispam-prvs: x-forefront-prvs: 000227DA0C x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(396003)(39860400002)(376002)(366004)(346002)(189003)(199004)(6916009)(66066001)(6436002)(54906003)(3846002)(6512007)(8676002)(52116002)(6116002)(53936002)(102836004)(1076003)(486006)(97736004)(86362001)(316002)(81156014)(6486002)(81166006)(5660300002)(71200400001)(71190400001)(4326008)(5640700003)(26005)(2906002)(386003)(107886003)(2351001)(8936002)(4744005)(478600001)(6506007)(14444005)(25786009)(186003)(106356001)(256004)(305945005)(11346002)(105586002)(68736007)(14454004)(76176011)(50226002)(476003)(99286004)(7736002)(2501003)(2616005)(446003)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3328; 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: Y64mP2DoaOkPoBb6HeEfVLtbkEbav/clyk1XX77IfJzu9zqRhq8EdUGa8L5r2F/V2uQA6lkA5uP5Ccpj0RuqRFAENnUGzmLmzFo+2Yjj6hsiZnhus8+WDsNyhC26KWKHK9YnLX5ZhRswKc1xsXKkLcQT37C1RpvsTr8qxAkuiS9PR+kehacGLPW7M39wmmUxTNx8RwbKp/pL0PlEnUWj/NMHbK4H6bygeo9PN7+XLnf0jd29ic9vKfBSbZ8o044NSGj/M6d1UXkTG7578zunvJtjXFT2iFop6sTO2g0+UXoAaowo75toq62VjHJWz7QQJQmyA6egSxLApN0pgj0cqSZ/IHZ9OhuJ2EyBVEl6t1lCIavR11HKsI0RVOpSpNOw6IIdjB9bZ3b4Z21r+bS3zB8BZUiFuT/9xFI6vVCossg= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: a390dd93-0f59-4041-7882-08d6bce3734b X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2019 12:04:00.0180 (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-Transport-CrossTenantHeadersStamped: VI1PR0202MB3328 Subject: [Xen-devel] [PATCH v3 3/3] x86/mm: Fix p2m_set_suppress_ve 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: "tamas@tklengyel.com" , "wei.liu2@citrix.com" , "rcojocaru@bitdefender.com" , "george.dunlap@eu.citrix.com" , "andrew.cooper3@citrix.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 On a new altp2m view the p2m_set_suppress_ve() func will fail with invalid mfn from p2m->get_entry() if p2m->set_entry() was not called before. This patch solves the problem by getting the mfn from hostp2m. Signed-off-by: Alexandru Isaila --- xen/arch/x86/mm/p2m.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index d38d7c29ca..aee82f814d 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2982,6 +2982,7 @@ int p2m_set_suppress_ve(struct domain *d, gfn_t gfn, bool suppress_ve, p2m_access_t a; p2m_type_t t; int rc; + bool found_in_hostp2m; if ( altp2m_idx > 0 ) { @@ -2999,7 +3000,7 @@ int p2m_set_suppress_ve(struct domain *d, gfn_t gfn, bool suppress_ve, if ( ap2m ) p2m_lock(ap2m); - mfn = p2m->get_entry(p2m, gfn, &t, &a, 0, NULL, NULL); + mfn = altp2m_get_gfn_type_access(p2m, gfn, &t, &a, NULL, &found_in_hostp2m); if ( !mfn_valid(mfn) ) { rc = -ESRCH;