From patchwork Fri Mar 29 12:50:06 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: 10877005 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 9795F15AC for ; Fri, 29 Mar 2019 12:52:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8101329074 for ; Fri, 29 Mar 2019 12:52:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7508028EC6; Fri, 29 Mar 2019 12:52:03 +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 ED75F28EC6 for ; Fri, 29 Mar 2019 12:52:02 +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 1h9qxY-0007EF-KS; Fri, 29 Mar 2019 12:50:12 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h9qxX-0007E7-Tm for xen-devel@lists.xenproject.org; Fri, 29 Mar 2019 12:50:12 +0000 X-Inumbo-ID: 2f2860bd-5221-11e9-bc90-bc764e045a96 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (unknown [40.107.4.94]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 2f2860bd-5221-11e9-bc90-bc764e045a96; Fri, 29 Mar 2019 12:50:09 +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=EMXHh6eBkTDxW77vecxg+B8rO5Y8ZfePZG5RHwxIguE=; b=ZBAIP3MDiv4afiLXrdRlf3+BIHErEE5JTjKzBse0XdMk/MskN6xkGsyuZjH9Vd6cQn4oEGYvFytyA1z//K4ID9djOO5LlFBRuENw9ek4d3rfdcUXcYv0hoJXGtcEJl2BV6qPky4t7AiiiX4j+PTsVFawUvYq/CwMxGN5ZpL/nUA= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB2559.eurprd02.prod.outlook.com (10.173.79.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1730.18; Fri, 29 Mar 2019 12:50:06 +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.1750.014; Fri, 29 Mar 2019 12:50:06 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v5] x86/mm: Clean up p2m_finish_type_change return value Thread-Index: AQHU5i3vDniTb5BnO0Gz8DdTvSv4Qw== Date: Fri, 29 Mar 2019 12:50:06 +0000 Message-ID: <20190329124940.24091-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM6P192CA0005.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:83::18) 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: c22b46ac-0a5f-472e-6c2a-08d6b445117d x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(5600127)(711020)(4605104)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020); SRVR:VI1PR0202MB2559; x-ms-traffictypediagnostic: VI1PR0202MB2559:|VI1PR0202MB2559: x-microsoft-antispam-prvs: x-forefront-prvs: 0991CAB7B3 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(346002)(366004)(39860400002)(136003)(376002)(396003)(189003)(199004)(2906002)(25786009)(4326008)(305945005)(68736007)(99286004)(186003)(7736002)(86362001)(36756003)(102836004)(316002)(26005)(5660300002)(54906003)(486006)(386003)(71200400001)(71190400001)(6916009)(6506007)(66066001)(97736004)(6486002)(6512007)(6436002)(106356001)(2501003)(81166006)(476003)(14444005)(2616005)(52116002)(8676002)(3846002)(6116002)(5640700003)(2351001)(105586002)(1076003)(81156014)(14454004)(8936002)(53936002)(50226002)(256004)(107886003)(478600001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB2559; 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: l8Pug6xVTbgmgxDp13EDP+odw/wGtrKzoIbAV2sru/D1n0ifhL1z2j5PGsO+Ylw/jocgP6Bjglp5w5evHFegkWN4ZJaYNhs04RktqilWQNjr3fYD6/40p8OYah8tfbJnL5rDOAST+bUSVa3KhukbmD/iS1XqriMxEAPRU7B+sN/klEzoXZUKyIlTohCkuC28KRL483TSWRTszjvJGR7ht2j4DyqhvIXozI3uXpj+Cyw8+bc9LELr7MaEAclQ2G5nlHmq4/LaDTMoXpAZ0SpfFXopLGqPiLb5tVNWBRppNX0M/4VN3FpLU7cJHDixcasV0SMGoG92N5nHPKSh5773hjVSEVYPB+ae/6kmg7xIC2bdM+LTVdNC4VXnpcklWlqrwNhxVNJnylxCVrd5ZFa63gi7CM1bkHOZh71lDncNncc= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: c22b46ac-0a5f-472e-6c2a-08d6b445117d X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Mar 2019 12:50:06.1771 (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: VI1PR0202MB2559 Subject: [Xen-devel] [PATCH v5] x86/mm: Clean up p2m_finish_type_change return value 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" , "Paul.Durrant@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 In the case of any errors, finish_type_change() passes values returned from p2m->recalc() up the stack (with some exceptions in the case where an error is expected); this eventually ends up being returned to the XEN_DOMOP_map_mem_type_to_ioreq_server hypercall. However, on Intel processors (but not on AMD processor), p2m->recalc() can also return '1' as well as '0'. This case is handled very inconsistently: finish_type_change() will return the value of the final entry it attempts, discarding results for other entries; p2m_finish_type_change() will attempt to accumulate '1's, so that it returns '1' if any of the calls to finish_type_change() returns '1'; and dm_op() will again return '1' only if the very last call to p2m_finish_type_change() returns '1'. The result is that the XEN_DMOP_map_mem_type_to_ioreq_server() hypercall will sometimes return 0 and sometimes return 1 on success, in an unpredictable manner. The hypercall documentation doesn't mention return values; but it's not clear what the caller could do with the information about whether entries had been changed or not. At the moment it's always 0 on AMD boxes, and *usually* 1 on Intel boxes; so nothing can be relying on a '1' return value for correctness (or if it is, it's broken). Make the return value on success consistently '0' by only returning 0/-ERROR from finish_type_change(). Also remove the accumulation code from p2m_finish_type_change(). Suggested-by: George Dunlap Signed-off-by: Alexandru Isaila Reviewed-by: Jan Beulich Reviewed-by: George Dunlap --- Changes since V4: - Undo changes in p2m->recalc() and have 1 turn into 0 in finish_type_change(). --- xen/arch/x86/mm/p2m.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index b9bbb8f485..5508cedc55 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1158,7 +1158,7 @@ void p2m_change_type_range(struct domain *d, * Finish p2m type change for gfns which are marked as need_recalc in a range. * Uses the current p2m's max_mapped_pfn to further clip the invalidation * range for alternate p2ms. - * Returns: 0/1 for success, negative for failure + * Returns: 0 for success, negative for failure */ static int finish_type_change(struct p2m_domain *p2m, gfn_t first_gfn, unsigned long max_nr) @@ -1174,9 +1174,9 @@ static int finish_type_change(struct p2m_domain *p2m, /* * ept->recalc could return 0/1/-ENOMEM. pt->recalc could return * 0/-ENOMEM/-ENOENT, -ENOENT isn't an error as we are looping - * gfn here. + * gfn here. If rc is 1 we need to have it 0 for success. */ - if ( rc == -ENOENT ) + if ( rc == -ENOENT || rc == 1 ) rc = 0; else if ( rc < 0 ) { @@ -1213,19 +1213,13 @@ int p2m_finish_type_change(struct domain *d, if ( d->arch.altp2m_eptp[i] != mfn_x(INVALID_MFN) ) { struct p2m_domain *altp2m = d->arch.altp2m_p2m[i]; - int rc1; p2m_lock(altp2m); - rc1 = finish_type_change(altp2m, first_gfn, max_nr); + rc = finish_type_change(altp2m, first_gfn, max_nr); p2m_unlock(altp2m); - if ( rc1 < 0 ) - { - rc = rc1; + if ( rc < 0 ) goto out; - } - - rc |= rc1; } } #endif