From patchwork Wed Apr 24 14:27:32 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: 10914927 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 5B28B1708 for ; Wed, 24 Apr 2019 14:29:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 474EA287B7 for ; Wed, 24 Apr 2019 14:29:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B775289C6; Wed, 24 Apr 2019 14:29:39 +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 5FC2E288D1 for ; Wed, 24 Apr 2019 14:29:37 +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 1hJIs6-0002Gf-IN; Wed, 24 Apr 2019 14:27:38 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hJIs5-0002Ga-6t for xen-devel@lists.xenproject.org; Wed, 24 Apr 2019 14:27:37 +0000 X-Inumbo-ID: 1a337d6d-669d-11e9-92d7-bc764e045a96 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe1f::70e]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1a337d6d-669d-11e9-92d7-bc764e045a96; Wed, 24 Apr 2019 14:27:35 +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=WrRqfKKrbZoYLciP80Q3T0MVoqxcJoVteJlfVcPVl7M=; b=SfowaB6Ua6/lezQUssnL8llaRmQ0XHj/7hb7cdJBjJy8Kb1VHIhM/rG1x5vyRCLIvD4vSzoujrQgY82ifvjE0GskZTxxgY7FrG/CTKiKcC5YdIH5CJ+sxsRLvohWt3P9/PfojAXjDunmGo+1ixId6Uy1GTUeZ18BQ+V1daL4J8A= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB3327.eurprd02.prod.outlook.com (52.134.15.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.17; Wed, 24 Apr 2019 14:27:32 +0000 Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::89a9:54d2:cf14:66a7]) by VI1PR0202MB2928.eurprd02.prod.outlook.com ([fe80::89a9:54d2:cf14:66a7%9]) with mapi id 15.20.1835.010; Wed, 24 Apr 2019 14:27:32 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v1] x86/mm: Make change_type_range return error Thread-Index: AQHU+qnahqk7Qfv5gU6tW7kXrs6RHg== Date: Wed, 24 Apr 2019 14:27:32 +0000 Message-ID: <20190424142718.14721-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6PR0102CA0003.eurprd01.prod.exchangelabs.com (2603:10a6:209:14::16) 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: 4ca20a73-4e47-4d18-7d99-08d6c8c0fcb0 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(2017052603328)(7193020); SRVR:VI1PR0202MB3327; x-ms-traffictypediagnostic: VI1PR0202MB3327:|VI1PR0202MB3327: x-microsoft-antispam-prvs: x-forefront-prvs: 00179089FD x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(346002)(396003)(376002)(136003)(39860400002)(189003)(199004)(6486002)(71190400001)(36756003)(256004)(6116002)(14444005)(3846002)(71200400001)(5640700003)(2616005)(14454004)(476003)(68736007)(486006)(107886003)(305945005)(7736002)(2501003)(478600001)(8936002)(4326008)(6512007)(53936002)(97736004)(8676002)(2351001)(6436002)(102836004)(81166006)(50226002)(6916009)(25786009)(52116002)(99286004)(86362001)(26005)(64756008)(6506007)(66476007)(5660300002)(186003)(2906002)(316002)(1076003)(66556008)(66066001)(386003)(66446008)(66946007)(73956011)(54906003)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB3327; 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: lxKFRiIQLq5iIlHFLFiIeZND4J6fmrZ3GijWpIoR5DPXUqAXzdSadzj3CrnmUhCX5nMCIJKJB8RwoN1yurt2KiTjzOkudvz9a8LXmw6Ejoi6HqcuguHnnqY8N1Drjj+AzLBn61S9lOSaPY8E7tK9wm5a5YSsinmCiam223mJVVs5FZHBInOr1dfQfg0YtbG4ioxsH6eFdoNIXrJA5Ioqq5xnzg75lPt8Huq/64TY6BjRNmjO7YaQNk3/hkTKz8nN7edgB+HJI5uqXYQ6l5egZu7aUL07pTTy1h2iXMlsY9IEAMZFfA/WfR7UlOTSND/3KjX4z0GRSXNsoqKy/1vNBu5D0VvIlw0u6n/hTZSrN3e2uaECRoCYfVQ3UXpZCd53Url2TNYKjVv/l9q3dZtrnP38gGuBqjXaBFhkyEz3hTU= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ca20a73-4e47-4d18-7d99-08d6c8c0fcb0 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Apr 2019 14:27:32.1637 (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: VI1PR0202MB3327 Subject: [Xen-devel] [PATCH v1] x86/mm: Make change_type_range return error 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: "wei.liu2@citrix.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 At this moment change_type_range() prints a warning in case end > host_max_pfn. While this is unlikely to happen the function should return a error and propagate it to the caller, hap_track_dirty_vram() This patch makes change_type_range() return -EINVAL or 0 if all is ok. Signed-off-by: Alexandru Isaila --- xen/arch/x86/mm/hap/hap.c | 12 ++++++++---- xen/arch/x86/mm/p2m.c | 32 ++++++++++++++++++++------------ xen/include/asm-x86/p2m.h | 6 +++--- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/xen/arch/x86/mm/hap/hap.c b/xen/arch/x86/mm/hap/hap.c index 412a442b6a..b113c3154b 100644 --- a/xen/arch/x86/mm/hap/hap.c +++ b/xen/arch/x86/mm/hap/hap.c @@ -108,15 +108,19 @@ int hap_track_dirty_vram(struct domain *d, paging_unlock(d); if ( oend > ostart ) - p2m_change_type_range(d, ostart, oend, - p2m_ram_logdirty, p2m_ram_rw); + rc = p2m_change_type_range(d, ostart, oend, + p2m_ram_logdirty, p2m_ram_rw); + if ( rc ) + goto out; /* * Switch vram to log dirty mode, either by setting l1e entries of * P2M table to be read-only, or via hardware-assisted log-dirty. */ - p2m_change_type_range(d, begin_pfn, begin_pfn + nr, - p2m_ram_rw, p2m_ram_logdirty); + rc = p2m_change_type_range(d, begin_pfn, begin_pfn + nr, + p2m_ram_rw, p2m_ram_logdirty); + if ( rc ) + goto out; flush_tlb_mask(d->dirty_cpumask); diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index 9e81a30cc4..27697d5a77 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1028,7 +1028,7 @@ int p2m_change_type_one(struct domain *d, unsigned long gfn_l, } /* Modify the p2m type of [start, end_exclusive) from ot to nt. */ -static void change_type_range(struct p2m_domain *p2m, +static int change_type_range(struct p2m_domain *p2m, unsigned long start, unsigned long end_exclusive, p2m_type_t ot, p2m_type_t nt) { @@ -1053,15 +1053,11 @@ static void change_type_range(struct p2m_domain *p2m, * This should be revisited later, but for now post a warning. */ if ( unlikely(end > host_max_pfn) ) - { - printk(XENLOG_G_WARNING "Dom%d logdirty rangeset clipped to max_mapped_pfn\n", - d->domain_id); - end = invalidate_end = host_max_pfn; - } + return -EINVAL; /* If the requested range is out of scope, return doing nothing. */ if ( start > end ) - return; + return 0; if ( p2m_is_altp2m(p2m) ) invalidate_end = min(invalidate_end, max_pfn); @@ -1115,13 +1111,16 @@ static void change_type_range(struct p2m_domain *p2m, rc, d->domain_id); domain_crash(d); } + + return 0; } -void p2m_change_type_range(struct domain *d, - unsigned long start, unsigned long end, - p2m_type_t ot, p2m_type_t nt) +int p2m_change_type_range(struct domain *d, + unsigned long start, unsigned long end, + p2m_type_t ot, p2m_type_t nt) { struct p2m_domain *hostp2m = p2m_get_hostp2m(d); + int rc = 0; ASSERT(ot != nt); ASSERT(p2m_is_changeable(ot) && p2m_is_changeable(nt)); @@ -1129,7 +1128,10 @@ void p2m_change_type_range(struct domain *d, p2m_lock(hostp2m); hostp2m->defer_nested_flush = 1; - change_type_range(hostp2m, start, end, ot, nt); + rc = change_type_range(hostp2m, start, end, ot, nt); + + if ( rc ) + goto out; #ifdef CONFIG_HVM if ( unlikely(altp2m_active(d)) ) @@ -1142,8 +1144,11 @@ void p2m_change_type_range(struct domain *d, struct p2m_domain *altp2m = d->arch.altp2m_p2m[i]; p2m_lock(altp2m); - change_type_range(altp2m, start, end, ot, nt); + rc = change_type_range(altp2m, start, end, ot, nt); p2m_unlock(altp2m); + + if ( rc ) + goto out; } } #endif @@ -1151,7 +1156,10 @@ void p2m_change_type_range(struct domain *d, if ( nestedhvm_enabled(d) ) p2m_flush_nestedp2m(d); +out: p2m_unlock(hostp2m); + + return rc; } /* diff --git a/xen/include/asm-x86/p2m.h b/xen/include/asm-x86/p2m.h index 2801a8ccca..a118812025 100644 --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -613,9 +613,9 @@ void p2m_change_entry_type_global(struct domain *d, p2m_type_t ot, p2m_type_t nt); /* Change types across a range of p2m entries (start ... end-1) */ -void p2m_change_type_range(struct domain *d, - unsigned long start, unsigned long end, - p2m_type_t ot, p2m_type_t nt); +int p2m_change_type_range(struct domain *d, + unsigned long start, unsigned long end, + p2m_type_t ot, p2m_type_t nt); /* Compare-exchange the type of a single p2m entry */ int p2m_change_type_one(struct domain *d, unsigned long gfn,