From patchwork Fri Apr 5 13:25:37 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: 10887369 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 A9BA415AC for ; Fri, 5 Apr 2019 13:27:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93B32289F1 for ; Fri, 5 Apr 2019 13:27:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8784428B67; Fri, 5 Apr 2019 13:27:54 +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 67E41289F1 for ; Fri, 5 Apr 2019 13:27:53 +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 1hCOqm-0001gb-RD; Fri, 05 Apr 2019 13:25:44 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hCOql-0001gW-BV for xen-devel@lists.xenproject.org; Fri, 05 Apr 2019 13:25:43 +0000 X-Inumbo-ID: 4eae6474-57a6-11e9-92d7-bc764e045a96 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe06::721]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4eae6474-57a6-11e9-92d7-bc764e045a96; Fri, 05 Apr 2019 13:25:41 +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=McJ1GpuTh9bn9nG/Ub3LNjpgUWwMMB/nMCXvxcPtxww=; b=OY+ssKjDHLzbO3r8TrFfLmUAu1Co3zr0bvqXjrk5JzET5MF3gX2OH3E93Q2V1DbVXHWV90WWTptRltARUXM1Px84tsYQ13m/jK8FEYLEivVtXtxqPlbaMosMbCttL4x6RuzKVo/2X1zzHkc6+SS3TG3nyb01vyRb4wakbM0UuBs= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3280.eurprd02.prod.outlook.com (52.134.15.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.16; Fri, 5 Apr 2019 13:25:38 +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; Fri, 5 Apr 2019 13:25:38 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2 1/3] x86/mm: Introduce altp2m_get_gfn_type_access Thread-Index: AQHU67MOOt6j14oTzUCFLR1+mgEKCw== Date: Fri, 5 Apr 2019 13:25:37 +0000 Message-ID: <20190405132521.6630-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P194CA0023.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::36) 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: 83e7b6c1-68b0-4e7a-a87c-08d6b9ca30f1 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3280; x-ms-traffictypediagnostic: VI1PR0202MB3280:|VI1PR0202MB3280: x-microsoft-antispam-prvs: x-forefront-prvs: 0998671D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(366004)(396003)(376002)(346002)(39860400002)(189003)(199004)(68736007)(6486002)(316002)(71200400001)(71190400001)(4326008)(106356001)(105586002)(97736004)(2351001)(54906003)(478600001)(1076003)(81156014)(81166006)(53936002)(25786009)(5640700003)(86362001)(6916009)(8936002)(8676002)(2906002)(107886003)(3846002)(6116002)(6512007)(6436002)(14454004)(50226002)(5660300002)(7736002)(305945005)(476003)(14444005)(2616005)(386003)(6506007)(26005)(102836004)(2501003)(36756003)(256004)(66066001)(99286004)(52116002)(486006)(186003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3280; 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: Y5B4ZHQstgxj2knS/bxbQx8X8YhLdrgWfD5GjVT4u/0bZ+2G+DdZ+1PE/Yur/KqWnQ2whP/tht9OYHAYs3mbyCzhOPajGWrAlvNv9Uj8X1r3NGONX/4cpgYtrCMa8nhCqa52Hn5GfGtLYFJ7D2zQ/cwyrQq/V5lKhp/rXkp3wDfeoK3g8ZrSnbU4mARQ/MsEevi1vkEaoy/ACEU29J1BL0j9D0YSneMzqxG/DTo06o7BDyBiK23w1fwLJb5eBEYQfci+6K4D5Ohc8SyayeJj1/ovznbhYsMccvtvZ7d7CsNGjvXNnm/H/6g4+bryVkHlY4IAtk52EpkFc+lYvn4ZMmzscPHZNBSkrt+j8c3KreadbxJTRiEUKlG/ckVJfGwkubupwiK1bFFmLm5AUyrAu9aj/Nrh2Mv2uCZfuUEytNM= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83e7b6c1-68b0-4e7a-a87c-08d6b9ca30f1 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2019 13:25:37.8372 (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: VI1PR0202MB3280 Subject: [Xen-devel] [PATCH v2 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 --- xen/arch/x86/mm/mem_access.c | 30 +++++++++++------------------ xen/arch/x86/mm/p2m.c | 37 ++++++++++++++---------------------- xen/include/asm-x86/p2m.h | 23 ++++++++++++++++++++++ 3 files changed, 48 insertions(+), 42 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 56c06a4fc6..608f748a57 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -265,31 +265,23 @@ 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 found_in_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, &found_in_hostp2m); - /* Check host p2m if no valid entry in alternate */ if ( !mfn_valid(mfn) ) - { + return -ESRCH; - mfn = __get_gfn_type_access(hp2m, gfn_l, &t, &old_a, - P2M_ALLOC | P2M_UNSHARE, &page_order, 0); + /* If this is a superpage, copy that first */ + if ( page_order != PAGE_ORDER_4K && found_in_hostp2m ) + { + unsigned long mask = ~((1UL << page_order) - 1); + gfn_t gfn2 = _gfn(gfn_l & mask); + mfn_t mfn2 = _mfn(mfn_x(mfn) & mask); - 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..b2a5c0c42e 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 found_in_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, &found_in_hostp2m); if ( gfn_eq(new_gfn, INVALID_GFN) ) { @@ -2648,35 +2649,25 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, /* 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 ) - goto out; + 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 && found_in_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); + mfn = altp2m_get_gfn_type_access(ap2m, new_gfn, &t, &a, &page_order, &found_in_hostp2m); if ( !mfn_valid(mfn) ) - mfn = hp2m->get_entry(hp2m, new_gfn, &t, &a, 0, NULL, NULL); - - /* Note: currently it is not safe to remap to a shared entry */ - if ( !mfn_valid(mfn) || (t != p2m_ram_rw) ) 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..42068b4aed 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -448,6 +448,29 @@ 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 *found_in_hostp2m) +{ + mfn_t mfn = ap2m->get_entry(ap2m, gfn, t, a, 0, NULL, NULL); + + *found_in_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); + *found_in_hostp2m = true; + + /* Note: currently it is not safe to remap to a shared entry */ + if ( !mfn_valid(mfn) || *t != p2m_ram_rw ) + return INVALID_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 Fri Apr 5 13:25:40 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: 10887365 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 A949E1575 for ; Fri, 5 Apr 2019 13:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FFB3289F1 for ; Fri, 5 Apr 2019 13:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8237328B68; Fri, 5 Apr 2019 13:27: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 115D6289F1 for ; Fri, 5 Apr 2019 13:27: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 1hCOqp-0001hB-AO; Fri, 05 Apr 2019 13:25:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hCOqn-0001gr-ED for xen-devel@lists.xenproject.org; Fri, 05 Apr 2019 13:25:45 +0000 X-Inumbo-ID: 4fdf2cc2-57a6-11e9-92d7-bc764e045a96 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe06::712]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4fdf2cc2-57a6-11e9-92d7-bc764e045a96; Fri, 05 Apr 2019 13:25:43 +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=z8tI1W4r1pG/1D39xfwpMfTbT6SxUJSH5WdhZXluYwo=; b=H3MHYXD90D9cUiytATBkT/eJ5Vl0BVnEeoCWTvMK0JLQueBFk1vME+GAmrBwkb1NYahxk8/g+NevL/2S3vKeUtqODtZ6IyjwCoKgnAUAgsVeTrrEecH0h8kESxziKxvma1EJ+sTcUq1dplNUy6BCmPuKe2jC+QX1nw6x/AYRCYI= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3280.eurprd02.prod.outlook.com (52.134.15.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1771.16; Fri, 5 Apr 2019 13:25:41 +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; Fri, 5 Apr 2019 13:25:41 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2 2/3] x86/mm: Introduce altp2m_set_entry_by_page_order Thread-Index: AQHU67MQbz1qF5J0RU2Towq8lOMqBQ== Date: Fri, 5 Apr 2019 13:25:40 +0000 Message-ID: <20190405132521.6630-2-aisaila@bitdefender.com> References: <20190405132521.6630-1-aisaila@bitdefender.com> In-Reply-To: <20190405132521.6630-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P194CA0023.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::36) 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: 186d4c29-b3e3-47ec-26a2-08d6b9ca32d5 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3280; x-ms-traffictypediagnostic: VI1PR0202MB3280:|VI1PR0202MB3280: x-microsoft-antispam-prvs: x-forefront-prvs: 0998671D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(136003)(366004)(396003)(376002)(346002)(39860400002)(189003)(199004)(68736007)(6486002)(316002)(71200400001)(71190400001)(4326008)(106356001)(105586002)(97736004)(2351001)(54906003)(478600001)(1076003)(81156014)(81166006)(53936002)(25786009)(5640700003)(86362001)(6916009)(8936002)(8676002)(2906002)(107886003)(3846002)(6116002)(6512007)(6436002)(14454004)(50226002)(5660300002)(7736002)(305945005)(76176011)(446003)(476003)(11346002)(14444005)(2616005)(386003)(6506007)(26005)(102836004)(2501003)(36756003)(256004)(66066001)(99286004)(52116002)(486006)(186003); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3280; 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: nvm2XfgPmvIA35yYVv0eZhLkjyBAgHo+9PN0NprBao82Q+OHPORAvO9tgM88uZW+2wqRWgWnHT0oEXpmG2BmUGFnxqkZHjRbaGZIUYW4msALqPGMKKJX8KNrrDbvdvavmi2BdC9SAIdFNuAeB66Pxw59sr6fOC0+QcMrwSxx675Q4F2yZumCh6VKG8U+yRKyhex+C2ESwSpcgSgjIexu26PINbjqexb+QlJfqbK8hmxSvR2YKv9iSz37n/dFUTKuRS3eSMsZ/JegVlACfagfQn8f3Oz/bK6zc75yjsXKtrjBIyV3lDlJPUPFFlS7UP/rAx9O7h5h1LL/7FZMna31HFl/XLrKbdEFBmnlpw7o1eUFOjuZHC0qDwnVgoi74uhonH5RPWvbBc5Go+HtoTiSVJlUa0kDifERWewygf8Xe20= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 186d4c29-b3e3-47ec-26a2-08d6b9ca32d5 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2019 13:25:40.9638 (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: VI1PR0202MB3280 Subject: [Xen-devel] [PATCH v2 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 | 7 ++----- xen/arch/x86/mm/p2m.c | 12 ++---------- xen/include/asm-x86/p2m.h | 11 +++++++++++ 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/xen/arch/x86/mm/mem_access.c b/xen/arch/x86/mm/mem_access.c index 608f748a57..a26727dfee 100644 --- a/xen/arch/x86/mm/mem_access.c +++ b/xen/arch/x86/mm/mem_access.c @@ -275,11 +275,8 @@ int p2m_set_altp2m_mem_access(struct domain *d, struct p2m_domain *hp2m, /* If this is a superpage, copy that first */ if ( page_order != PAGE_ORDER_4K && found_in_hostp2m ) { - 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); + rc = altp2m_set_entry_by_page_order(ap2m, gfn_l, mfn, page_order, + t, old_a); if ( rc ) return rc; } diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index b2a5c0c42e..1f852694ff 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2653,17 +2653,9 @@ int p2m_change_altp2m_gfn(struct domain *d, unsigned int idx, /* If this is a superpage, copy that first */ if ( page_order != PAGE_ORDER_4K && found_in_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); - - if ( ap2m->set_entry(ap2m, gfn, mfn, page_order, t, a, 1) ) + if ( altp2m_set_entry_by_page_order(ap2m, gfn_x(old_gfn), mfn, + page_order, t, a) ) goto out; - } mfn = altp2m_get_gfn_type_access(ap2m, new_gfn, &t, &a, &page_order, &found_in_hostp2m); diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 42068b4aed..8ac9427743 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -471,6 +471,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 Fri Apr 5 13:25:42 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: 10887367 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 DAC8E15AC for ; Fri, 5 Apr 2019 13:27:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C320D289F1 for ; Fri, 5 Apr 2019 13:27:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B5F9C28B67; Fri, 5 Apr 2019 13:27: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 63A8028B65 for ; Fri, 5 Apr 2019 13:27: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 1hCOqp-0001hJ-LA; Fri, 05 Apr 2019 13:25:47 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hCOqp-0001h3-2l for xen-devel@lists.xenproject.org; Fri, 05 Apr 2019 13:25:47 +0000 X-Inumbo-ID: 513e703a-57a6-11e9-92d7-bc764e045a96 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe0c::700]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 513e703a-57a6-11e9-92d7-bc764e045a96; Fri, 05 Apr 2019 13:25:45 +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=jqnW9CjdNaE53AQr7SKN37fBX7Fitu0jmFudcf2eHkA=; b=WOAw6zWtsiy5zVNMHEJJNf7aXISEEbvpi0iCRp6bkmo4xLjO6FURvkVOtHMeczTk5tBHzXLdmis2F/+Dn87k0nKnyfLp4CcNnbsU3JgIF5opDjcn717joAaPnvpZ+BKlGTAcPTBgVdq6SndGjiAsbo9KBDVYKA9uopfj1yJ0748= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3551.eurprd02.prod.outlook.com (52.134.18.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1750.20; Fri, 5 Apr 2019 13:25:42 +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; Fri, 5 Apr 2019 13:25:42 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v2 3/3] x86/mm: Fix p2m_set_suppress_ve Thread-Index: AQHU67MRw6H5cMuNKk+McX+MnD77RQ== Date: Fri, 5 Apr 2019 13:25:42 +0000 Message-ID: <20190405132521.6630-3-aisaila@bitdefender.com> References: <20190405132521.6630-1-aisaila@bitdefender.com> In-Reply-To: <20190405132521.6630-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P194CA0023.EURP194.PROD.OUTLOOK.COM (2603:10a6:209:90::36) 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: 1a65e5b2-8637-4816-f2c5-08d6b9ca33f3 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600139)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3551; x-ms-traffictypediagnostic: VI1PR0202MB3551:|VI1PR0202MB3551: x-microsoft-antispam-prvs: x-forefront-prvs: 0998671D02 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(346002)(136003)(39860400002)(376002)(396003)(189003)(199004)(36756003)(68736007)(6512007)(4326008)(8936002)(81166006)(7736002)(53936002)(81156014)(5640700003)(50226002)(66066001)(6486002)(8676002)(256004)(14444005)(6436002)(99286004)(107886003)(305945005)(97736004)(316002)(6116002)(3846002)(54906003)(52116002)(102836004)(2616005)(6506007)(86362001)(2501003)(76176011)(476003)(6916009)(486006)(186003)(446003)(14454004)(11346002)(26005)(25786009)(478600001)(1076003)(105586002)(2351001)(386003)(5660300002)(4744005)(106356001)(71190400001)(2906002)(71200400001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3551; 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: vwadOkniOy0Xbfayq1CGwa4y0q7B9bLIj6vMdOK49if1QaHvmc7zfKMdwSv1Ig8m6jhDDmOhkpwwYKeSgSU1F2FNi2HGcUSsvFOnnpHN4AmKLCH5HWe2SrVztHtemFwgr2Nl6NhC7YOYtJSV9ethKgrVniR6O+ZfBtl2y7UefotPb/e8OlET1S8dEFEPXEffqonvNiQ5PLxI2xRMx+xdz6iSxOgUzka6DMHHbhLzmjElw9pMIiJTpzDQyLVIl47HkgilPKyaG6tgs5CJ98F7B1DudPZbtJFDQObDaKK7DYEDt505nTTEcptm2M+5TGjlUzq372/JuOQHBkoccnJuUrr/mtmUlNq5reX2N9trWakFAo2XODpEgJRaX3ouLcTwVh7+iGCUr+CXFQh02keiPHlW2aPvIRWW/hNOpWd2nsE= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1a65e5b2-8637-4816-f2c5-08d6b9ca33f3 X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Apr 2019 13:25:42.8604 (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: VI1PR0202MB3551 Subject: [Xen-devel] [PATCH v2 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 1f852694ff..6dee0052f8 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -2974,6 +2974,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 ) { @@ -2991,7 +2992,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;