From patchwork Fri Mar 22 12:09:07 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: 10865563 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 36039922 for ; Fri, 22 Mar 2019 12:11:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 166D82A6DE for ; Fri, 22 Mar 2019 12:11:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 091342A6DF; Fri, 22 Mar 2019 12:11:19 +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 821452A6DC for ; Fri, 22 Mar 2019 12:11:18 +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 1h7Iz3-0001Gp-M7; Fri, 22 Mar 2019 12:09:13 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1h7Iz2-0001Gk-KC for xen-devel@lists.xenproject.org; Fri, 22 Mar 2019 12:09:12 +0000 X-Inumbo-ID: 4c8150be-4c9b-11e9-bc90-bc764e045a96 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (unknown [2a01:111:f400:fe1e::714]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 4c8150be-4c9b-11e9-bc90-bc764e045a96; Fri, 22 Mar 2019 12:09:11 +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=vc/JQ2n9dm5jWTccvrNjWPZT30Lr7zuhQZK5bQIKBb8=; b=Z+e9+urHGxekf9n204It/4v9owtjIg1bwels4RU/8SzfpDKF+IPTWUse5HIMHnrdXN8eBAwYSM9Z3oOBBiM/cmI2fX2EixxB2VtZ39MxvS30mVgghkydyWa8o0W2hPCI74LMtAVhWdq+V9Tn8JGshfWQHrhXYjG9CbNhbc821fY= Received: from VI1PR0202MB2928.eurprd02.prod.outlook.com (10.171.103.139) by VI1PR0202MB2654.eurprd02.prod.outlook.com (10.173.80.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1709.13; Fri, 22 Mar 2019 12:09:07 +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.1730.013; Fri, 22 Mar 2019 12:09:07 +0000 From: Alexandru Stefan ISAILA To: "xen-devel@lists.xenproject.org" Thread-Topic: [PATCH v3] x86/mm: Clean up p2m_finish_type_change return value Thread-Index: AQHU4KgMUsVbo/lfhEGYknKOa8T9MQ== Date: Fri, 22 Mar 2019 12:09:07 +0000 Message-ID: <20190322120848.31528-1-aisaila@bitdefender.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: AM5P194CA0003.EURP194.PROD.OUTLOOK.COM (2603:10a6:203:8f::13) 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: 198b9ba8-1f8c-4fe0-8203-08d6aebf2ed9 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600127)(711020)(4605104)(2017052603328)(7153060)(7193020); SRVR:VI1PR0202MB2654; x-ms-traffictypediagnostic: VI1PR0202MB2654:|VI1PR0202MB2654: x-microsoft-antispam-prvs: x-forefront-prvs: 09840A4839 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(366004)(136003)(396003)(39860400002)(346002)(376002)(189003)(199004)(8936002)(3846002)(6116002)(71190400001)(71200400001)(52116002)(6916009)(6506007)(2616005)(36756003)(97736004)(476003)(66066001)(26005)(4326008)(316002)(386003)(486006)(186003)(54906003)(14444005)(86362001)(1076003)(305945005)(2351001)(7736002)(6486002)(6436002)(81156014)(102836004)(478600001)(53936002)(2906002)(256004)(6512007)(81166006)(25786009)(14454004)(99286004)(50226002)(5660300002)(68736007)(107886003)(2501003)(105586002)(106356001)(5640700003)(8676002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0202MB2654; 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: X7Pt0mhFRq6aTKsn0KQ2pFS/4q7RlTT+YcjOEFwObeKPfdI9CZr/qGarSNql0imQFF0s3hyWbFfZMTnrFiN2cMD0QyWrLUqdBRfOGMCNYW/kQdj3bjRwXprwFvfEzlUUOJtA7Z/KndDyj8nnxD5hRthkHSGWj5F3AblffGn56eF8fJFXIRb94CNJDR25GOJ3KtPgLGFJ6WYJ/mZqgtgLyA7fB1TAkTdNlFKLv56ENOQYp2lO89+vKU2e95ErdeOUIOoA1Du7qvNKb1kQmzfJngb/wsiRQj1zUvKwzP+jL6L7IOcdTuUxahIbVezJwKRcW3zkZeNmD+uXprSKxxVbH8iWPVW+zrBXvcJauQdbJjEAmA51zIN+nuOUU6To9lZC1WVCO1BxMVQ6FABFq3kogP2GM2q/aO/M61TnYUExDZo= MIME-Version: 1.0 X-OriginatorOrg: bitdefender.com X-MS-Exchange-CrossTenant-Network-Message-Id: 198b9ba8-1f8c-4fe0-8203-08d6aebf2ed9 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 Mar 2019 12:09:07.1250 (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: VI1PR0202MB2654 Subject: [Xen-devel] [PATCH v3] 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" , "andrew.cooper3@citrix.com" , "george.dunlap@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 --- Changes since V2: - Update commit msg. --- xen/arch/x86/mm/p2m.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c index b9bbb8f485..bcf8cad423 100644 --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -1213,22 +1213,17 @@ 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 + rc = 0; out: p2m_unlock(hostp2m);