From patchwork Fri Dec 10 09:39:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12669119 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2FE25C433F5 for ; Fri, 10 Dec 2021 09:40:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.243666.421556 (Exim 4.92) (envelope-from ) id 1mvcNn-0000C9-Ak; Fri, 10 Dec 2021 09:40:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 243666.421556; Fri, 10 Dec 2021 09:40:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mvcNn-0000C0-6h; Fri, 10 Dec 2021 09:40:03 +0000 Received: by outflank-mailman (input) for mailman id 243666; Fri, 10 Dec 2021 09:40:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mvcNm-0008SI-Fc for xen-devel@lists.xenproject.org; Fri, 10 Dec 2021 09:40:02 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 2551e253-599d-11ec-a831-37629979565c; Fri, 10 Dec 2021 10:40:01 +0100 (CET) Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01lp2057.outbound.protection.outlook.com [104.47.0.57]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-40-GYnaKQCEO5uwIFwvOui8Qw-1; Fri, 10 Dec 2021 10:40:00 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR04MB5325.eurprd04.prod.outlook.com (2603:10a6:803:60::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Fri, 10 Dec 2021 09:39:57 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe%6]) with mapi id 15.20.4755.024; Fri, 10 Dec 2021 09:39:57 +0000 Received: from [10.156.60.236] (37.24.206.209) by AS8PR04CA0008.eurprd04.prod.outlook.com (2603:10a6:20b:310::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.17 via Frontend Transport; Fri, 10 Dec 2021 09:39:56 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 2551e253-599d-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1639129201; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nQbHxo+SG7zXc0WpjqfjCW7hun4rktAxwnnAypfq9w8=; b=dMWyyVtgdncU1XGXXLA7fHm+RdVecL/Hs2gWc0ahwlRJ310/bf6gxlhziH+XRJKinMvrvX b5JD/jl+GyU0+8Jy8U5u0Rdag0UIZCkF1N5L88Pu/oU9IDu+GyBxma9ReefhMkARHTJKzo 5PnN3/GwR1ZAn5aSniBVa8zOmkkuv7E= X-MC-Unique: GYnaKQCEO5uwIFwvOui8Qw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jvb9SjtqNm+73m7UPu624dGUJHV7WA7/IaB303mWKvUOi30Umc7B1kmqOk+PiBwLLiZCEHCWU+uinj7YCXlpomw0LgJ7VQ6Tw02NIISYJreJxEjH09xhByWgITZB3NLl2b/RiZKHIXIbohs9OaGlj4I9YjB/82qHGcIByvLUrGRztN25jY92bntC5y9Vq/SCt3z10EpQfqy7qoHsK5WkkiDRgGAM598YO60mH7er71WH3hMvb+KwDP5rcXmf0IZ2UWjJMovclui9u008q2JBIvuM3s1Q6pB3Xo10tkt8QWMwVOBnFR75s9rkABVJHcL94xhI5m9pl3pQTdwou7mLKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=nQbHxo+SG7zXc0WpjqfjCW7hun4rktAxwnnAypfq9w8=; b=kW1zSbcpjDlW4j9XfeKz6MqmJ48wMeFNz//z5i0qs1ZG9/0DGE8q/XYYgB900CNxoFXEpr6dpY+FG6efjvIduORArLcQLMo/4xzcX82np3AiV3sUAa1RIWztxfqwriCbPGT79wgDausvy5v/bICQgKhkTeZHSb7yM/e7l+W/Z8h78G/Q6s++QgxtWEQD/U2dPeG7G3wrHUBTtkK2xXZZidKgu5xzTMKGhQoflJRSXG7hLHlMFpE43nixnLWti5wzz5xzP8CvJ9AvijbBc92QngaSWb3StTlmRoNvl9T0+zwGuGgcTuM7a/ju5NH9ScXfLA+buH8/wqE9n5oIoB/CwQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <6d2d29ca-0495-5029-afc8-7248f462db06@suse.com> Date: Fri, 10 Dec 2021 10:39:55 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH v2 1/2] mm: introduce INVALID_{G,M}FN_RAW Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu References: <9725c93e-c227-f29f-07a4-65e383bb7858@suse.com> In-Reply-To: <9725c93e-c227-f29f-07a4-65e383bb7858@suse.com> X-ClientProxiedBy: AS8PR04CA0008.eurprd04.prod.outlook.com (2603:10a6:20b:310::13) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a661d899-186b-46ff-1ac1-08d9bbc10759 X-MS-TrafficTypeDiagnostic: VI1PR04MB5325:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tWeAP6AIzSDp16yRsvHgDyp4CZTcacv/7OFE3BrIUggRgeLEg/aXrktR+d1tg0sCbYmGayrsQmSdIBTz/OS0u7pYxe5ICR6vigUn2WWEkhU1A/NuVbtdrJW5B/fWDLpno1Shzu12Z7XmOEr/HHHhqzIVwNzf+QZ6zo8xvjMaaaeRkz022fnday1l3CW0vAUbHP9hG7mCnpv8ni59buST1FuTPWRbPUGvWhfynIkSdz0KqfBRQ2wN8C2mRx6weXEzx2W8Tn5//oHVcYaCWhjvhAIy96bDp14qU9sIe9PvRKosxlaXRibyJ9Zc0GMcDU1Kn3e/tIRZK9tRxgfhs1Y1CwNhLVQMxltwyM47GnRTBeQdfZzQtX8HJ4ENhWNzPSf73jAO+YfrpSoJLsC04gL5JhkU48ATSeGlbmhr7kpgKCL0dXJX3gCY/hyUhuO427q2riOXlJRXtcTDhxfrIAuqiRSUYUDHHD4LByNZ2bEQcgTZe10pBgE0c7b7vmtIyrdT48r8Ggo8m4lD/HLke4VSStPAvnTdFQkHbaGZbElu4Cw1FFtlq6ft1mrYYuo5M/uelagCjVsIorOEJkqvtEyHT+VQndc6Pt2XMExPFvCIdIlcbAjRn1hR1w5jbnonZ4kcvCPxF/f/+UX6BdeBWPwOFPbegJrJVcArnW7+l//L7dpCR91RHooVIXkp/ZGpuwuxpzliHwFxXWYaOT7iqd6o78avtk6YTPvnx/PzBkU0Ffn79K6tgqfNbDqkcubIPNMeHtYX1k5WZNrV51f6vP9BeGWihM52WrR7QURSnLrCH/2gqhx0NxoyUUmvzLbbrSeHWLUtOqZiRYFGrM+6J2pq0A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(6486002)(8676002)(8936002)(2616005)(956004)(66556008)(66476007)(31696002)(66946007)(966005)(26005)(508600001)(86362001)(2906002)(186003)(38100700002)(54906003)(6916009)(5660300002)(36756003)(16576012)(316002)(4326008)(31686004)(43740500002)(45980500001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?CGF+l6c6qH2OHpeP4SQOwr/J43mT?= =?utf-8?q?Oir1PCz1NQFpZt5K9WqyVz3jSg5w2aGqfNLgh0lgFL4acfLzARzmtQ30MWzKIWJXK?= =?utf-8?q?9Fhm9VPBg4/igZ3YVW715hLFGQC7LtBEKqQ88kLCAjydeH4RDaTJGxA5FPXnJBA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8?q?A6gdzGwBh2ZWQRmUf5A8vQOhgQ5GJUS8C1KBEuFZxLx5seZPAJfhCVUaV/xqO4n7y?= =?utf-8?q?jd562wdKTW7Nhg/ZELDxJ09X0TqbVBDBxohVJGKPdJEP+oZsSJgJes3UmRXG1TqwI?= =?utf-8?q?YcAPxzqaTOgwPKbZ1GEfl/BZeGFNrkku/KsTLKKnHv2qQYBO8TPjVrdHKF4tuXaYt?= =?utf-8?q?XLxgWhbzbXGnrLNYgYYJQoGPOj9cVmu2SQg3NfWIy1FloPQKvz07I7lZpZmL6sz9U?= =?utf-8?q?DISPfp9IWoiw9fopGn6AEql/8kUd5Mk9ScqSvtF+HW89K5TgdkZatQd4QbdQmBCJ+?= =?utf-8?q?Ez+b+BCL4PYTBNxQwhp94BPj5W0Y5beF0aQIeXYUqVS+KDX9U/uzQeexsjiZoUote?= =?utf-8?q?i1yQQrHbCwFH4f8Bs3+fglnV3cnRiG7fdttSMplDB62DR8if3I+oc7e43ZtnMfl/S?= =?utf-8?q?RhA96DeznHpuP8rochayg/hjaVTiSWwikqkCL8qdzmKLSL/bNGrolVNGwU3W9W5Me?= =?utf-8?q?H1r+HBHGpbsv+nUMqUiqy1CnBP2hBuJSrTftEKnTSAIdkIyIiR7l8Fg=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a661d899-186b-46ff-1ac1-08d9bbc10759 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2021 09:39:57.6867 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IhuZy7DoPlcfAh9YyfluNT/2Lr6SlHMfDMEpgOLtFMrqXrZUN+Rj7lrr1JUbFX4r9nqAXVzd2yAeVA0wQ8K+MQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5325 This allows properly tying together INVALID_{G,M}FN and INVALID_{G,M}FN_INITIALIZER as well as using the actual values in compile time constant expressions (or even preprocessor dirctives). Since INVALID_PFN is unused, and with x86'es paging_mark_pfn_dirty() being the only user of pfn_t it also doesn't seem likely that new uses would appear, remove that one at this same occasion. Signed-off-by: Jan Beulich Reviewed-by: Oleksandr Andrushchenko Reviewed-by: Julien Grall --- v2: New. --- a/xen/include/xen/mm-frame.h +++ b/xen/include/xen/mm-frame.h @@ -6,12 +6,13 @@ TYPE_SAFE(unsigned long, mfn); #define PRI_mfn "05lx" -#define INVALID_MFN _mfn(~0UL) +#define INVALID_MFN_RAW (~0UL) +#define INVALID_MFN _mfn(INVALID_MFN_RAW) /* * To be used for global variable initialization. This workaround a bug * in GCC < 5.0. */ -#define INVALID_MFN_INITIALIZER { ~0UL } +#define INVALID_MFN_INITIALIZER { INVALID_MFN_RAW } #ifndef mfn_t #define mfn_t /* Grep fodder: mfn_t, _mfn() and mfn_x() are defined above */ @@ -44,12 +45,13 @@ static inline bool_t mfn_eq(mfn_t x, mfn TYPE_SAFE(unsigned long, gfn); #define PRI_gfn "05lx" -#define INVALID_GFN _gfn(~0UL) +#define INVALID_GFN_RAW (~0UL) +#define INVALID_GFN _gfn(INVALID_GFN_RAW) /* * To be used for global variable initialization. This workaround a bug * in GCC < 5.0 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64856 */ -#define INVALID_GFN_INITIALIZER { ~0UL } +#define INVALID_GFN_INITIALIZER { INVALID_GFN_RAW } #ifndef gfn_t #define gfn_t /* Grep fodder: gfn_t, _gfn() and gfn_x() are defined above */ @@ -82,7 +84,6 @@ static inline bool_t gfn_eq(gfn_t x, gfn TYPE_SAFE(unsigned long, pfn); #define PRI_pfn "05lx" -#define INVALID_PFN (~0UL) #ifndef pfn_t #define pfn_t /* Grep fodder: pfn_t, _pfn() and pfn_x() are defined above */ From patchwork Fri Dec 10 09:40:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12669121 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE88DC433F5 for ; Fri, 10 Dec 2021 09:40:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.243669.421567 (Exim 4.92) (envelope-from ) id 1mvcOS-0001F6-IT; Fri, 10 Dec 2021 09:40:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 243669.421567; Fri, 10 Dec 2021 09:40:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mvcOS-0001Ez-FH; Fri, 10 Dec 2021 09:40:44 +0000 Received: by outflank-mailman (input) for mailman id 243669; Fri, 10 Dec 2021 09:40:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mvcOR-0001En-BN for xen-devel@lists.xenproject.org; Fri, 10 Dec 2021 09:40:43 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 3dbb2004-599d-11ec-a831-37629979565c; Fri, 10 Dec 2021 10:40:42 +0100 (CET) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04lp2055.outbound.protection.outlook.com [104.47.13.55]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-15-PlJ-ZA4CPXOzpmKLfSxNUQ-1; Fri, 10 Dec 2021 10:40:41 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VE1PR04MB6670.eurprd04.prod.outlook.com (2603:10a6:803:120::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.21; Fri, 10 Dec 2021 09:40:39 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe%6]) with mapi id 15.20.4755.024; Fri, 10 Dec 2021 09:40:39 +0000 Received: from [10.156.60.236] (37.24.206.209) by AS8PR04CA0012.eurprd04.prod.outlook.com (2603:10a6:20b:310::17) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Fri, 10 Dec 2021 09:40:39 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 3dbb2004-599d-11ec-a831-37629979565c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1639129242; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ea6giwOa1Pf9wAAzmwlZGs6GybWSd+Ba6eO/po1jxw=; b=SgaH0Y0PmO/r7jp2WU9vPIbdILHgv7Tl3d9Q6MG9x/Q7GAEJZODklLZN0MKlMw7v6RdWMy v2VTUnzMoBxj554j9XOKMNMygXjYq3dY5hkOKdB8el1YRVu3P8o4y59YiW3VXQDcNeEfK2 sbGlhLDXhMaSQ0nuMqOuFEpSUNFIuFE= X-MC-Unique: PlJ-ZA4CPXOzpmKLfSxNUQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lfDvS4fYyVHJkG/cFhUOlN/AYsyXcZcoMpCEmszGEOHjtWXe/ukgoU0aFcRLrcheRC69nuEHuL3mL20GxZDF63PyYld9yIYRANWZ1hceuyIo+nko7IPfigwTskO2+nVVsWb7QvQo1RglEKywjiC4Dgv8Hng7jib4SGo10RQRK1iMEmg0HC6cb9vpjezvl4BW3M5ctceoqMjczbhS6p9N/Fk0/rc5dF3+sL/fEsnYkXyjAGsQBiEYxqJAGcWA5S3ZoBRznwPIfWVk08YjgYt34pVgFn+kCxM/dmnERBLZFfjP8xyULjIuDyA5MtB92pOSQlSfAGluFt83ok9GnbEnSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=/ea6giwOa1Pf9wAAzmwlZGs6GybWSd+Ba6eO/po1jxw=; b=Bu2GzTWjo4y9TvZg5/rvkVT9NY7M9phaNVfRu/TdQP5jA0kCOiKGvK4I2CyEqySSZ97NYIqQ1CAls5g6R00YxF+N/z5yYdyx/SRq0T7sPFSu2xPRveZ9A4Fqt4AENfphVofZBAAfC6XLvkqWx+2MtiYbuUEC3ucB9UdmbA5VdW2UyeUXxXIMGGhz3BhgxD8rk1jLnNfhCFxXNTiX6JC2CSxLtaO4Pb+YKrHvqofXEPNCcjaXSFRDITMM1xUsSpt6v0mWNeqDOUWOUOOx8DkCnmHLy9nI04bQrUgeapTIjksX63U82+GrfzynJ/XaLuweCaJ+6MaABVt17fw1ckp4cA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Message-ID: <0b68ff3a-3c82-f800-4d20-17eded13163a@suse.com> Date: Fri, 10 Dec 2021 10:40:38 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Subject: [PATCH v2 2/2] memory: XENMEM_add_to_physmap (almost) wrapping checks Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Julien Grall , Stefano Stabellini , Wei Liu References: <9725c93e-c227-f29f-07a4-65e383bb7858@suse.com> In-Reply-To: <9725c93e-c227-f29f-07a4-65e383bb7858@suse.com> X-ClientProxiedBy: AS8PR04CA0012.eurprd04.prod.outlook.com (2603:10a6:20b:310::17) To VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 89b85327-3fd4-4e29-42d7-08d9bbc1205d X-MS-TrafficTypeDiagnostic: VE1PR04MB6670:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6108; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1E+N7cW7yLgAvHI2Ekh3YUXY0BzgZo8wt1ivCYQL8JRrHFcBrypjO/0Ac+jgZ6O0KZV+bCJ6S37TcqsBKEDgUX8xZawXUkbqpiQskIvg2c6BD9w6AMFMVTOKs3j2IjMY179eo85OtMBdur32nq3hkB7lFf+htv0s8PA0TwoxXHIYZbASKtMDHVZYkFFkWYhZe6Z8XmdtzMu2G9O0i2StKUbJiJYqXTAGma46oKeHAWovexUTtw2TZe93KzMfl8FF5SdOfF3r4xu+zH7CeN1FeXqcCXF+W1yEkZG2DqOcmLIHP5nMiYaIxEcJx0OjHDqPTs8nbc2QpZBqHS1yJ4WthxLQyx1d/m80gfVfawHa6HL+wUpnu+zHwowfyu9dDOb5qy6x9Iy6iEYty8YzPG/rtaTLCE4wasCwJyv7UOfQ63mAwDS6PROgmcTffYX7vKr819wKaBzzucXf/2+VNE4RuAQ17OIRcGfGqfXy7J00CT79GCvYYNU04PHMMbDZcb9TWPGYivacQaqni+cY+07O/XazF5klR+8RvdIdADewmO1cO6l0IuGUS2cYR9lHqMko8dbvuP0ext4BiOC9yrnuzB39J/+Ts6tMdFNYIyfUHkOmDhEjx7Gt/pCBriGu+BIm+492HEiRUtK2au4IOZsRIJMN2SbXNX9M7MQNFzuXp+uDum3+ePj7+0ADvz/L4hdan+CREWftpSXb17ErLH0w92mfleTS7zn7qTw4BE9yvtsRdSNfD0kvKVETx3Q4vCgv X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5600.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(16576012)(31686004)(83380400001)(38100700002)(54906003)(956004)(6486002)(31696002)(6916009)(8936002)(66556008)(2906002)(66476007)(66946007)(86362001)(316002)(4326008)(508600001)(36756003)(5660300002)(8676002)(26005)(2616005)(186003)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?1oCPkudhr/JlwwzL9sN3eDjrWljo?= =?utf-8?q?m3ml44pXC0BYLqGRAJ88KLWRwqvnpYSZ/NIjmRi1N4iFFCpYd0c6ZWE5z9Vwk2qzM?= =?utf-8?q?CyAV10mtiZi5OoU7ATw9YdttmYwkMJkwA/gs3Mnyo0oHAxhRLe3q+qEHj8IULN0Wt?= =?utf-8?q?qY4BIT5mrQ4P45PyYkN6M1V1DqQcPxehqPIoXvTemeS5xGYLdmjsS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fUduvl2hMGJL4fH6hN9?= =?utf-8?q?7waXa79WeLKDFCqgKCYvn4+CKC/elzlkINU6VXnvt313cfeuuLWvyeVPmozFlN3mb?= =?utf-8?q?c7vTJ850Bc4XqEQpKZpyyypuYE1qqknG3HQpSQpwEvHgbCsML6ic9kFjZpmAvzyfd?= =?utf-8?q?gQ9ooHF+XZm9Sh102Bx7bKhppa0aBQYoYsmK/Tkhb6YjA+DgH7ZbuPVJW7w9UMd/+?= =?utf-8?q?vNk3a3rno8OCzvRyqykQm5csVXGvH/UaWxXOHeIEklXwY4GGJbGF1KErAJ7Z6WSJJ?= =?utf-8?q?0w5qY/s17MSr3NUrdAqmTwYJSMgLpsqCCmc5iNTbAJg67JAKSIZw2+ros9qw9RbpG?= =?utf-8?q?NwlfXDtE1DuaLrVitKgMnWrSTqyungwWJYPmoNcFM54dsjmsxBtbaq/AM9D14UvbP?= =?utf-8?q?fZKZvN9Nz5p2A78ykfkb3EcA8e1FBfUp1G/2DkrmyAadK7k6uS5W3GAsWIbx4b0ii?= =?utf-8?q?x0+S5uo6wqWeOD/g2s9vrIuTzpOZR7Y75so9el1oKx2arbyJnj7rcAM=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 89b85327-3fd4-4e29-42d7-08d9bbc1205d X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Dec 2021 09:40:39.6600 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: R2Tn/V4T8uEhYbl9GThh3loAnRBPP6zN2uacdche2V6jd1bBp9QxDGEtlmhQ3tCdDhzOhVbaS5AfUTJh55rvOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6670 Determining that behavior is correct (i.e. results in failure) for a passed in GFN equaling INVALID_GFN is non-trivial. Make this quite a bit more obvious by checking input in generic code - both for singular requests to not match the value and for range ones to not pass / wrap through it. For Arm similarly make more obvious that no wrapping of MFNs passed for XENMAPSPACE_dev_mmio and thus to map_dev_mmio_region() can occur: Drop the "nr" parameter of the function to avoid future callers appearing which might not themselves check for wrapping. Otherwise the respective ASSERT() in rangeset_contains_range() could trigger. Signed-off-by: Jan Beulich --- v2: Add comment to BUILD_BUG_ON(). Avoid transiently #define-ing _gfn() (by way of new prereq patch). --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1479,7 +1479,7 @@ int xenmem_add_to_physmap_one( break; } case XENMAPSPACE_dev_mmio: - rc = map_dev_mmio_region(d, gfn, 1, _mfn(idx)); + rc = map_dev_mmio_region(d, gfn, _mfn(idx)); return rc; default: --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1357,19 +1357,18 @@ int unmap_mmio_regions(struct domain *d, int map_dev_mmio_region(struct domain *d, gfn_t gfn, - unsigned long nr, mfn_t mfn) { int res; - if ( !(nr && iomem_access_permitted(d, mfn_x(mfn), mfn_x(mfn) + nr - 1)) ) + if ( !iomem_access_permitted(d, mfn_x(mfn), mfn_x(mfn)) ) return 0; - res = p2m_insert_mapping(d, gfn, nr, mfn, p2m_mmio_direct_c); + res = p2m_insert_mapping(d, gfn, 1, mfn, p2m_mmio_direct_c); if ( res < 0 ) { - printk(XENLOG_G_ERR "Unable to map MFNs [%#"PRI_mfn" - %#"PRI_mfn" in Dom%d\n", - mfn_x(mfn), mfn_x(mfn) + nr - 1, d->domain_id); + printk(XENLOG_G_ERR "Unable to map MFN %#"PRI_mfn" in %pd\n", + mfn_x(mfn), d); return res; } --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -4150,7 +4150,10 @@ int gnttab_map_frame(struct domain *d, u bool status = false; if ( gfn_eq(gfn, INVALID_GFN) ) + { + ASSERT_UNREACHABLE(); return -EINVAL; + } grant_write_lock(gt); --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -832,6 +832,9 @@ int xenmem_add_to_physmap(struct domain return -EACCES; } + if ( gfn_eq(_gfn(xatp->gpfn), INVALID_GFN) ) + return -EINVAL; + if ( xatp->space == XENMAPSPACE_gmfn_foreign ) extra.foreign_domid = DOMID_INVALID; @@ -842,6 +845,18 @@ int xenmem_add_to_physmap(struct domain if ( xatp->size < start ) return -EILSEQ; + if ( xatp->gpfn + xatp->size < xatp->gpfn || + xatp->idx + xatp->size < xatp->idx ) + { + /* + * Make sure INVALID_GFN is the highest representable value, i.e. + * guaranteeing that it won't fall in the middle of the + * [xatp->gpfn, xatp->gpfn + xatp->size) range checked above. + */ + BUILD_BUG_ON(INVALID_GFN_RAW + 1); + return -EOVERFLOW; + } + xatp->idx += start; xatp->gpfn += start; xatp->size -= start; @@ -962,6 +977,9 @@ static int xenmem_add_to_physmap_batch(s extent, 1)) ) return -EFAULT; + if ( gfn_eq(_gfn(gpfn), INVALID_GFN) ) + return -EINVAL; + rc = xenmem_add_to_physmap_one(d, xatpb->space, extra, idx, _gfn(gpfn)); --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -297,7 +297,6 @@ int unmap_regions_p2mt(struct domain *d, int map_dev_mmio_region(struct domain *d, gfn_t gfn, - unsigned long nr, mfn_t mfn); int p2m_insert_mapping(struct domain *d, gfn_t start_gfn, unsigned long nr,