From patchwork Wed Feb 23 15:58:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12757137 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 6481CC433EF for ; Wed, 23 Feb 2022 15:59:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.277470.473982 (Exim 4.92) (envelope-from ) id 1nMu2Y-0001Fw-I1; Wed, 23 Feb 2022 15:58:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 277470.473982; Wed, 23 Feb 2022 15:58:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nMu2Y-0001Fp-EE; Wed, 23 Feb 2022 15:58:54 +0000 Received: by outflank-mailman (input) for mailman id 277470; Wed, 23 Feb 2022 15:58:52 +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 1nMu2W-000083-JD for xen-devel@lists.xenproject.org; Wed, 23 Feb 2022 15:58:52 +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 7e8ea6a3-94c1-11ec-8539-5f4723681683; Wed, 23 Feb 2022 16:58:51 +0100 (CET) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2111.outbound.protection.outlook.com [104.47.17.111]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-29-zU7gkAc4PgqNKoLYXq-eyA-1; Wed, 23 Feb 2022 16:58:50 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR0401MB2479.eurprd04.prod.outlook.com (2603:10a6:800:53::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22; Wed, 23 Feb 2022 15:58:45 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::d479:b728:345c:bd65%6]) with mapi id 15.20.5017.022; Wed, 23 Feb 2022 15:58:45 +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: 7e8ea6a3-94c1-11ec-8539-5f4723681683 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1645631931; 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=Absf33xo61iOtxqb/+8Eu6L66vlBNlW2G4hE8J6Sq7o=; b=PqAPjUGtAceYdQRviw961lJiU11Jf6C59vrit+3rMXZCvtHHLDh+N5VYTeQ/epH2RBrAGX JbOn1+u/US+iLSXP/7k+9ANySfeu5S+YVu5u8QPumfkXqCGof0WkmP3l/Z/OKGqoNls7ax Gky+QAtvV47fFQHOVrA7U35x6SbxsGk= X-MC-Unique: zU7gkAc4PgqNKoLYXq-eyA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WGvqI8lY7T3PBBTL5P2rrn9cyf77+7GvTxPiIbgNQMErHX/MCsgB0+dFKhzvdwzRy+03eQs7zGlyTgwKHKAMAak8bAUVimKA/EZGEDz+8IZTC9vqkbmdjFgPslcR6e27Ms+j0uzo8J+HuYV+9qqb9QtGJ+PlwtIdXl1tObNpTKz3BvuzN+CbrVsYWcPG0um6efkIIJjcNVfw9SK42ilWE6OcbetAeAdAMHO+ex63PAjzFQ98+Cj+l80pgQbCHjSjaVcRunk5zAGAwqJq7cUCW+x0+livy+jowYYoBhm0VFBosu68sZErUCuw+hrXFSmWHDodJ+qhEK5A8+9P65ETPw== 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=Absf33xo61iOtxqb/+8Eu6L66vlBNlW2G4hE8J6Sq7o=; b=I8D7EbBgxBaBfszSBub3/rkec2CUJV9chcxyvXDV9FynTk0ZHj2zFsLipI0kBG3PHVQI67GmObZ74aAMvaneMbMDTqsa3q1PmQN61cwltyCT3dukz98deSmZnnSc28H51QbUMxglHgaKDiqJtUlZ8Tx6hBUZ92wmBdEoJ3AlzS1veQ8ibGzUC4+E9PtW9Vj0Zlmy8JD5/E0a+s6LUWDloYbgKoJ2k7WVVD/CyNp+RXZnwOKBTnQGF8XjkfAiUpZtA17ZEfK0d9j7mNksIbgaGqwWNrVjnU0owYQrVq36xjQAdbL0Z2ikGPfoq4laNhS/QuOxdWEUNa0F/a0OHT2w4g== 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: Date: Wed, 23 Feb 2022 16:58:44 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: [PATCH v2 03/14] x86/mm: move guest_physmap_{add,remove}_page() Content-Language: en-US From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , George Dunlap References: In-Reply-To: X-ClientProxiedBy: AS9PR06CA0355.eurprd06.prod.outlook.com (2603:10a6:20b:466::22) 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: e5795b0e-57da-4f2b-a191-08d9f6e55f41 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2479:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WABS4NcpsqIOvX/u/RMoLxxGAwmzGlIny8Vn/d0YWRwPz9fcFZKcvOquP7EeXByTDwIuK7rqGVb/UXmDyZkw5cws7p59BikH8Jdrl3hNASQAZstsGRj1bz8r0ypkhmlmwqdDWrZoaHo2s7C58K7O5WCJUyIcBNeksZCiwOw2cEF8D6WFpfEkAQyxCBocLuXhqSWgf9YViTduPpB5x3uqXvt5chlgeBkWdxSXfO6ymqoT+TCAzxJv3ZOn0Xa7RaSvF4QTntz8WfAzmdVMG7oXxjeQKylAkROX53kF7hq7q7BEHW/8iAX7MGpKVyvUUatmuUfGCXtcQAiSp7+fyOXRMWf3v1y5xGHWFr7qx/zVAcHaP9Q4yUJpropajWY7es5doa6X89IRZRji1ILVKTeFrbW4nXWHSkpaQ73X5n06lt85ZtjKaG79+Td9+1yTVd3Fz+8aeI4I2JEsRekhs9BFC86IVz1AwOuCKtdqi4FGt4zWRwzgxKDX8xDfQFOaSbihkgBJe5C2ATF/Bg+Xu5JGqcgNZl2bgyqaMEoleJmuBmPgfqB8m3n2VsLQdNEYPz/4EZUXTNBE9JVvwWEkqGgXSMuvXGuTrCyBJA9dImSrsQHSz7Qkm00LIQdnL63VO1Z2arhpq7h3Q8F8/bz/0tIVXngQhTm8K58+wZUMJIAM/BaQFd50+uzzq7l2BvR1TEUBpe+vlcbxa2b4iX3F+2+JlsUCgsY6p55wzk9C2ww9/bCmCTnTo9nQg8CJEnPnrN1+XllIDU6j2tq3zOF1wMxScsFKmonlpIHUSZ+OFbmsTVPAGcPaeSEnf5tdUfiM762oieo/HnvNr0rgc7x2sXeXwA== 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:(13230001)(366004)(66476007)(66556008)(8676002)(4326008)(26005)(66946007)(186003)(6512007)(2616005)(2906002)(6486002)(508600001)(6506007)(31686004)(316002)(8936002)(6916009)(31696002)(86362001)(38100700002)(5660300002)(83380400001)(54906003)(36756003)(2004002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?UbbbIwSURfMC/D0yoWndBPI+CCnf?= =?utf-8?q?IsaE4EGXe3Ggr1D4MZa7SxkfAsY8Y5lPMrz9AjnhV3v0NI5K00bmFn1oZU/GQI/I4?= =?utf-8?q?0BEjzrI2KDXeGg4GRgM6YekfiR9TFTyWLBAuocSMlkir+loEQlegpd2nUAQeu5g7r?= =?utf-8?q?JzOOmmg8YxDYu9eybAgMqAbnGhDkO/wIImxqiCRIhB3LFrqVA+b12En9SL0pPDwZB?= =?utf-8?q?Mv8CbLlWjX2yGfJpufhr9D5KfSG9trxbTbfe/1MIOzcC2rzEe5VaL1Bs9DmHXLfuy?= =?utf-8?q?Y2DUFHExKiM2qKaqt59m3rI17IYY83pEn26VZ5kpDtIeWzQRmKqizCHDDVK5t5LS4?= =?utf-8?q?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8l6wMHiwZLij7K?= =?utf-8?q?GdVXhbzLwbaiK6x3y4Cm4+r6mg2td/G8A6oGpjegaNA9FyljJ4P55lbeI0fn30nT+?= =?utf-8?q?CIOF8pIqhE9qeZNRrFU7sj3phqWqesJ7jOTk0ZbdgAPWci4626XL7NwS5XZG6fk5c?= =?utf-8?q?967KYfmiCtGxMXMYuJmIz79K2+/DSfTwFC2jyQhH5WnMa77qGmq+dYdXEVbWcODOG?= =?utf-8?q?GlbyMkzVFcENz9Mb3Ku7ffxxT/Uv3xmwctJHRsdZmN7l8shKUMVvcvxHn1BUtNrds?= =?utf-8?q?Ji7jzSLMNH8aLoIZYlVxNVrWcgDIKg3G3qsCLrkPelz1b1pIUumyUObPcXHugZw9Z?= =?utf-8?q?NQUCM48Zq7wbJumLRAFEKhseqlsyROszds6oL/oMsFh+53nuota1DVg=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5795b0e-57da-4f2b-a191-08d9f6e55f41 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Feb 2022 15:58:45.7278 (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: CvyFsYc8ownQ1/EGeS4qc3C+pgthdYbarHFA0wTgKjdSk3AqKqDNzyheg+KHEyVbjy1Z4C9THSAyFZVHFwz8EA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2479 ... to a new file, separating the functions from their HVM-specific backing ones, themselves only dealing with the non-translated case. To avoid having a new CONFIG_HVM conditional in there, do away with the inline placeholder. Signed-off-by: Jan Beulich Reviewed-by: George Dunlap --- v2: Re-base. --- a/xen/arch/x86/mm/Makefile +++ b/xen/arch/x86/mm/Makefile @@ -10,3 +10,4 @@ obj-$(CONFIG_MEM_SHARING) += mem_sharing obj-y += p2m.o obj-$(CONFIG_HVM) += p2m-ept.o p2m-pod.o p2m-pt.o obj-y += paging.o +obj-y += physmap.o --- a/xen/arch/x86/mm/p2m.c +++ b/xen/arch/x86/mm/p2m.c @@ -870,60 +870,6 @@ p2m_remove_page(struct domain *d, gfn_t } int -guest_physmap_remove_page(struct domain *d, gfn_t gfn, - mfn_t mfn, unsigned int page_order) -{ - /* IOMMU for PV guests is handled in get_page_type() and put_page(). */ - if ( !paging_mode_translate(d) ) - return 0; - - return p2m_remove_page(d, gfn, mfn, page_order); -} - -#endif /* CONFIG_HVM */ - -int -guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, - unsigned int page_order) -{ - /* IOMMU for PV guests is handled in get_page_type() and put_page(). */ - if ( !paging_mode_translate(d) ) - { - struct page_info *page = mfn_to_page(mfn); - unsigned long i; - - /* - * Our interface for PV guests wrt IOMMU entries hasn't been very - * clear; but historically, pages have started out with IOMMU mappings, - * and only lose them when changed to a different page type. - * - * Retain this property by grabbing a writable type ref and then - * dropping it immediately. The result will be pages that have a - * writable type (and an IOMMU entry), but a count of 0 (such that - * any guest-requested type changes succeed and remove the IOMMU - * entry). - */ - for ( i = 0; i < (1UL << page_order); ++i, ++page ) - { - if ( !need_iommu_pt_sync(d) ) - /* nothing */; - else if ( get_page_and_type(page, d, PGT_writable_page) ) - put_page_and_type(page); - else - return -EINVAL; - - set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn) + i); - } - - return 0; - } - - return p2m_add_page(d, gfn, mfn, page_order, p2m_ram_rw); -} - -#ifdef CONFIG_HVM - -int p2m_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned int page_order, p2m_type_t t) { --- /dev/null +++ b/xen/arch/x86/mm/physmap.c @@ -0,0 +1,85 @@ +/****************************************************************************** + * arch/x86/mm/physmap.c + * + * Parts of this code are Copyright (c) 2009 by Citrix Systems, Inc. (Patrick Colp) + * Parts of this code are Copyright (c) 2007 by Advanced Micro Devices. + * Parts of this code are Copyright (c) 2006-2007 by XenSource Inc. + * Parts of this code are Copyright (c) 2006 by Michael A Fetterman + * Parts based on earlier work by Michael A Fetterman, Ian Pratt et al. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + */ + +#include + +#include "mm-locks.h" + +int +guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn, + unsigned int page_order) +{ + /* IOMMU for PV guests is handled in get_page_type() and put_page(). */ + if ( !paging_mode_translate(d) ) + { + struct page_info *page = mfn_to_page(mfn); + unsigned long i; + + /* + * Our interface for PV guests wrt IOMMU entries hasn't been very + * clear; but historically, pages have started out with IOMMU mappings, + * and only lose them when changed to a different page type. + * + * Retain this property by grabbing a writable type ref and then + * dropping it immediately. The result will be pages that have a + * writable type (and an IOMMU entry), but a count of 0 (such that + * any guest-requested type changes succeed and remove the IOMMU + * entry). + */ + for ( i = 0; i < (1UL << page_order); ++i, ++page ) + { + if ( !need_iommu_pt_sync(d) ) + /* nothing */; + else if ( get_page_and_type(page, d, PGT_writable_page) ) + put_page_and_type(page); + else + return -EINVAL; + + set_gpfn_from_mfn(mfn_x(mfn) + i, gfn_x(gfn) + i); + } + + return 0; + } + + return p2m_add_page(d, gfn, mfn, page_order, p2m_ram_rw); +} + +int +guest_physmap_remove_page(struct domain *d, gfn_t gfn, + mfn_t mfn, unsigned int page_order) +{ + /* IOMMU for PV guests is handled in get_page_type() and put_page(). */ + if ( !paging_mode_translate(d) ) + return 0; + + return p2m_remove_page(d, gfn, mfn, page_order); +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + */ --- a/xen/include/xen/p2m-common.h +++ b/xen/include/xen/p2m-common.h @@ -8,18 +8,9 @@ int set_foreign_p2m_entry(struct domain unsigned long gfn, mfn_t mfn); /* Remove a page from a domain's p2m table */ -#ifdef CONFIG_HVM int __must_check guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn, unsigned int page_order); -#else -static inline int -guest_physmap_remove_page(struct domain *d, gfn_t gfn, mfn_t mfn, - unsigned int page_order) -{ - return 0; -} -#endif /* Map MMIO regions in the p2m: start_gfn and nr describe the range in * * the guest physical address space to map, starting from the machine