From patchwork Wed Dec 1 11:20:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12649765 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 49985C433EF for ; Wed, 1 Dec 2021 11:20:50 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.235918.409217 (Exim 4.92) (envelope-from ) id 1msNf9-0002lb-Qt; Wed, 01 Dec 2021 11:20:35 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 235918.409217; Wed, 01 Dec 2021 11:20:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msNf9-0002lU-Nl; Wed, 01 Dec 2021 11:20:35 +0000 Received: by outflank-mailman (input) for mailman id 235918; Wed, 01 Dec 2021 11:20:35 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msNf8-0002lJ-VB for xen-devel@lists.xenproject.org; Wed, 01 Dec 2021 11:20:35 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b3294761-5298-11ec-976b-d102b41d0961; Wed, 01 Dec 2021 12:20:33 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2059.outbound.protection.outlook.com [104.47.14.59]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-18-noYV7RiEPEKp4BGql6JYqA-1; Wed, 01 Dec 2021 12:20:32 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR0402MB3936.eurprd04.prod.outlook.com (2603:10a6:803:23::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Wed, 1 Dec 2021 11:20:31 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe%5]) with mapi id 15.20.4734.024; Wed, 1 Dec 2021 11:20:31 +0000 Received: from [10.156.60.236] (37.24.206.209) by AM7PR02CA0010.eurprd02.prod.outlook.com (2603:10a6:20b:100::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Wed, 1 Dec 2021 11:20:30 +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: b3294761-5298-11ec-976b-d102b41d0961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1638357633; 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=uVzkRXmNhEFLnejBb+/P0JNRxNOczXHfjbrfmo5RiEM=; b=E2AZEDKGHYI/hYHOVgiz8hJmGESv+Yolo0MN8cfUiOz5kTPAPKxRfLPqMBobJV9swrmNcx XIZGE7e3PTQHxBWJ9YQFqbGvoPxZP1hY+WgIVRjEgr3V03nQ227i6WQltOYWXnxHDeUSS7 GWV6lp3Bb0wTkgSLG48UuU7XRKJqAuc= X-MC-Unique: noYV7RiEPEKp4BGql6JYqA-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Bgte0DhyRDGnwNBt/cVkzSoKG2OJWsBnFmHS4zKCYfPu5jpcljMx+F4svgWONsfkJpL9fcStYhdOVRFR8XpPFBbEYFoPrvNIUA887Gna5yyItzE98ha4PwhrUiEkWEYmECShSufjZJO9RMkFUzDjB4Gh4QTO/7T18KryIKaF4D7GIpeISZ9OkQvkLpMDMJzfkVCbahOVOQ9Ab53g6CurY6YW1Q0v0/ICrEk7LNPLqD/cXinmbc5h0+zEND5qxmXPVAvJly18FqKOJcGZgLnE8DEBGrQGlR5QhTOKbOFueIBwRDDOj2vckGJhnRHi2oEb5A07Sd7atLAqufvYIB0rTg== 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=uVzkRXmNhEFLnejBb+/P0JNRxNOczXHfjbrfmo5RiEM=; b=N5HnvmbqDrUGJeXS3SrBm2tSzr5BGa4jT7e8EbI+C3GAV8K3ifLMpxnBDdyP5hgJnkxhOsvpmHbGFcUwzJ/1EMir+pbg1pirYb+6XwC54ETtcymzCCtEwVlLlYpLtlloXjhDse+5ryqkmf2cNtkzNYGD2CuN6apjp9DAbihpLeCMtjXmcUvI5BLp9weFyfXf9RC7KlaOmJwaqxMKhuv7LKT4oNGbhIdHXg5Fzl4v+OWXi2InICjm+xMpj2iHllACb/0wf6hOFReJpW5/RJY7TRXcfsJkPkx0r9viCmea9K9dfpkNf3LVT/a3/OwBdtjyaQQMxTga1d8Yx/YaEk71Wg== 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: <81a27b5a-99f7-d929-987a-1dcf2433144b@suse.com> Date: Wed, 1 Dec 2021 12:20:28 +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] IOMMU/x86: disallow device assignment to PoD guests 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 , Paul Durrant , Tamas K Lengyel , Petre Pircalabu , Alexandru Isaila References: <8bb92e3f-38b4-16a1-0a45-5f393081f230@suse.com> In-Reply-To: <8bb92e3f-38b4-16a1-0a45-5f393081f230@suse.com> X-ClientProxiedBy: AM7PR02CA0010.eurprd02.prod.outlook.com (2603:10a6:20b:100::20) 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: 15f64a15-07c7-43b9-6a27-08d9b4bc95fc X-MS-TrafficTypeDiagnostic: VI1PR0402MB3936: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: L+iW7oNWzbaCAtNL9/PU83c2pofWk3Geqm6xcjzpd+JxYwXa7sIsqxNEJE4G6hxZK5VRsGUXmkpve+nZujQzEl5/6qGH8S4aqHBElNzStdyNQV7MJh/eqcCG4fpeSjqP644pfKauc/v0JdVWil/ayjjXCl5DgNjiu3GOyukWGe35Q9i2TtTHW0lFMxMaeDklV9SoR7wxXw8sa4V8HZugRJxncFf6f3YkEv6yudDKJD50RFGxF3WRRhT+92om5nRGoPOzi5L0JONy3F1ct8rp0bQ02JPxydtqgE63iIsehzC69gEiGgrP5i1Vyt5E62UQ8we1M8hWQ94BUJ2keGsBwcE23EfrfU709P3TFkHmzhuuY3e9b0UUIfOAnkeFPRkjfNCKyBp2Lmp1i6x+9bxN+j0kkubov4nc/9bpYPjxI0c624T66nIES2nfgCvYBAb/eQ7PFqP6muu30b2qKbVUmP9LZhNeLfSJ77uyJqUWU6k0ah7aFUbZODucFMIpyi53nsWva3kCdPMG+Dxw8sJ8WIFIeidEOIWNtKRLJLPRxkkl5jd6Jd8+dNud8UnyF8my0ezwHqlualiv909HyMzbVg8qwR7J3KjDbS7QSSXSfGaSCsw0QOPsxN6VaUQowphTgdbcI1c1XIWTeOEk83yX4ZH+0nbRMoB4HrnY7zrOJjQveRqB47ngd9yQW88PCwuQgL2JiKxzDpHCwOzDet6WDuPsO/rBlSy2TlZc4GRD6Wc= 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)(8936002)(2616005)(36756003)(6486002)(4326008)(86362001)(5660300002)(6916009)(508600001)(16576012)(54906003)(66556008)(66476007)(31696002)(83380400001)(26005)(66946007)(31686004)(2906002)(956004)(186003)(38100700002)(8676002)(316002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?yFPo7idB7KxuUoACYmSSC9mLbLuQ?= =?utf-8?q?x8R79mhCa+KBI1f2NzBjuGrFY8Fs9xKGXaJHtKENgIQGMy2myzvjsL2glaBOYkx+y?= =?utf-8?q?ZxOxWiT/b1iy4PCmAPjJhzXKwmYMQj1hdkOsZIyA4mpWZLKphGfzLTkg3S+zHq5ce?= =?utf-8?q?zYT1/MICI1MIiRz7R41V2t8np1D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qxVsSe2XDlL1XmqKD3bZjoujUbPNNa8Ih?= =?utf-8?q?/4/D96RQcxvn40QJALzPTzoJ2lPKRQ9Yyi7CC8aWWPcjQ2091odBRg41NGzMRkFEL?= =?utf-8?q?RQKP/0zHpcvuLonkcfaOCdoBlFJH1GLzqJYPLtMw8zFsGTrStc7rK8cE6/UlAKaj5?= =?utf-8?q?5hMfwfBl4QmzVU6jSjalBdsjtAzUgcEU6M3AtO/WWhkUiV55PLgRyzasZ4jrfHfcI?= =?utf-8?q?26t3hqsbYo390AEGYH/FtMhqGsQQ/oIwA/GAf0qSi+VrjzfkHKoRzYXxxAm42SDN2?= =?utf-8?q?xS2VBZ1vBAD+kgUfQFucD5spKqPVivCuxBtlkkrNji+VlJROJ03dJ8kgsU1mrEUZt?= =?utf-8?q?XiDA8ku5gbsys9IDUzpkb93HSeIEOVnqoFmBt6wfG0UWQVWzZ7vdOsRycqsGdIcSD?= =?utf-8?q?lV3BEbaKAyISJUjcTvq85tYPfOvYAgufS2WAVDafckAr38EOmRyj74sMVCkcnCV0C?= =?utf-8?q?tvwJYeC6HzvW4qHYSCUUo1TsI9yjZVi5fYhpZAi8SwVrG+BOn1YaVCo=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 15f64a15-07c7-43b9-6a27-08d9b4bc95fc X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2021 11:20:31.4403 (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: cxTrwQZgy3EEZs5z4bq6SKVRXpSGaWDxp3ZMmz4vOytLvUkO9ChykBP/Aht6HfelsToJsGHD2uCDHZQt7JnhbQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3936 While it is okay for IOMMU page tables to get set up for guests starting in PoD mode, actual device assignment may only occur once all PoD entries have been removed from the P2M. So far this was enforced only for boot-time assignment, and only in the tool stack. Also use the new function to replace p2m_pod_entry_count(): Its unlocked access to p2m->pod.entry_count wasn't really okay (irrespective of the result being stale by the time the caller gets to see it). To allow the tool stack to see a consistent snapshot of PoD state, move the tail of XENMEM_{get,set}_pod_target handling into a function, adding proper locking there. At the same time fail such requests for PV guests. In libxl take the liberty to use the new local variable r also for a pre-existing call into libxc. Signed-off-by: Jan Beulich --- If p2m->pod.entry_count == p2m->pod.count it is in principle possible to permit device assignment by actively resolving all remaining PoD entries. Initially I thought this was introduced by f89f555827a6 ("remove late (on-demand) construction of IOMMU page tables"), but without arch_iommu_use_permitted() checking for PoD I think the issue has been there before that. --- v2: New. --- a/tools/libs/light/libxl_pci.c +++ b/tools/libs/light/libxl_pci.c @@ -1619,8 +1619,13 @@ void libxl__device_pci_add(libxl__egc *e pas->callback = device_pci_add_stubdom_done; if (libxl__domain_type(gc, domid) == LIBXL_DOMAIN_TYPE_HVM) { - rc = xc_test_assign_device(ctx->xch, domid, pci_encode_bdf(pci)); - if (rc) { + int r; + uint64_t cache, ents; + + rc = ERROR_FAIL; + + r = xc_test_assign_device(ctx->xch, domid, pci_encode_bdf(pci)); + if (r) { LOGD(ERROR, domid, "PCI device %04x:%02x:%02x.%u %s?", pci->domain, pci->bus, pci->dev, pci->func, @@ -1628,6 +1633,22 @@ void libxl__device_pci_add(libxl__egc *e : "already assigned to a different guest"); goto out; } + + r = xc_domain_get_pod_target(ctx->xch, domid, NULL, &cache, &ents); + if (r) { + LOGED(ERROR, domid, "Cannot determine PoD status"); + goto out; + } + /* + * In principle it is sufficient for the domain to have ballooned down + * enough such that ents <= cache. But any remaining entries would + * need resolving first. Until such time when this gets effected, + * refuse assignment as long as any entries are left. + */ + if (ents /* > cache */) { + LOGD(ERROR, domid, "Cannot assign device with PoD still active"); + goto out; + } } rc = libxl__device_pci_setdefault(gc, domid, pci, !starting); --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -20,6 +20,7 @@ */ #include +#include #include #include #include @@ -333,6 +334,9 @@ p2m_pod_set_mem_target(struct domain *d, int ret = 0; unsigned long populated, pod_target; + if ( has_arch_pdevs(d) || cache_flush_permitted(d) ) + return -ENOTEMPTY; + pod_lock(p2m); /* P == B: Nothing to do (unless the guest is being created). */ @@ -370,6 +374,23 @@ out: return ret; } +void p2m_pod_get_mem_target(const struct domain *d, xen_pod_target_t *target) +{ + struct p2m_domain *p2m = p2m_get_hostp2m(d); + + ASSERT(is_hvm_domain(d)); + + pod_lock(p2m); + lock_page_alloc(p2m); + + target->tot_pages = domain_tot_pages(d); + target->pod_cache_pages = p2m->pod.count; + target->pod_entries = p2m->pod.entry_count; + + unlock_page_alloc(p2m); + pod_unlock(p2m); +} + int p2m_pod_empty_cache(struct domain *d) { struct p2m_domain *p2m = p2m_get_hostp2m(d); @@ -1387,6 +1408,9 @@ guest_physmap_mark_populate_on_demand(st if ( !paging_mode_translate(d) ) return -EINVAL; + if ( has_arch_pdevs(d) || cache_flush_permitted(d) ) + return -ENOTEMPTY; + do { rc = mark_populate_on_demand(d, gfn, chunk_order); @@ -1408,3 +1432,20 @@ void p2m_pod_init(struct p2m_domain *p2m for ( i = 0; i < ARRAY_SIZE(p2m->pod.mrp.list); ++i ) p2m->pod.mrp.list[i] = gfn_x(INVALID_GFN); } + +bool p2m_pod_active(const struct domain *d) +{ + struct p2m_domain *p2m; + bool res; + + if ( !is_hvm_domain(d) ) + return false; + + p2m = p2m_get_hostp2m(d); + + pod_lock(p2m); + res = p2m->pod.entry_count | p2m->pod.count; + pod_unlock(p2m); + + return res; +} --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4777,7 +4777,6 @@ long arch_memory_op(unsigned long cmd, X { xen_pod_target_t target; struct domain *d; - struct p2m_domain *p2m; if ( copy_from_guest(&target, arg, 1) ) return -EFAULT; @@ -4786,7 +4785,9 @@ long arch_memory_op(unsigned long cmd, X if ( d == NULL ) return -ESRCH; - if ( cmd == XENMEM_set_pod_target ) + if ( !is_hvm_domain(d) ) + rc = -EINVAL; + else if ( cmd == XENMEM_set_pod_target ) rc = xsm_set_pod_target(XSM_PRIV, d); else rc = xsm_get_pod_target(XSM_PRIV, d); @@ -4812,10 +4813,7 @@ long arch_memory_op(unsigned long cmd, X } else if ( rc >= 0 ) { - p2m = p2m_get_hostp2m(d); - target.tot_pages = domain_tot_pages(d); - target.pod_cache_pages = p2m->pod.count; - target.pod_entries = p2m->pod.entry_count; + p2m_pod_get_mem_target(d, &target); if ( __copy_to_guest(arg, &target, 1) ) { --- a/xen/common/vm_event.c +++ b/xen/common/vm_event.c @@ -639,7 +639,7 @@ int vm_event_domctl(struct domain *d, st rc = -EXDEV; /* Disallow paging in a PoD guest */ - if ( p2m_pod_entry_count(p2m_get_hostp2m(d)) ) + if ( p2m_pod_active(d) ) break; /* domain_pause() not required here, see XSA-99 */ --- a/xen/drivers/passthrough/x86/iommu.c +++ b/xen/drivers/passthrough/x86/iommu.c @@ -451,11 +451,12 @@ bool arch_iommu_use_permitted(const stru { /* * Prevent device assign if mem paging, mem sharing or log-dirty - * have been enabled for this domain. + * have been enabled for this domain, or if PoD is still in active use. */ return d == dom_io || (likely(!mem_sharing_enabled(d)) && likely(!mem_paging_enabled(d)) && + likely(!p2m_pod_active(d)) && likely(!p2m_get_hostp2m(d)->global_logdirty)); } --- a/xen/include/asm-x86/p2m.h +++ b/xen/include/asm-x86/p2m.h @@ -661,6 +661,12 @@ int p2m_pod_empty_cache(struct domain *d * domain matches target */ int p2m_pod_set_mem_target(struct domain *d, unsigned long target); +/* Obtain a consistent snapshot of PoD related domain state. */ +void p2m_pod_get_mem_target(const struct domain *d, xen_pod_target_t *target); + +/* Check whether PoD is (still) active in a domain. */ +bool p2m_pod_active(const struct domain *d); + /* Scan pod cache when offline/broken page triggered */ int p2m_pod_offline_or_broken_hit(struct page_info *p); @@ -669,11 +675,6 @@ p2m_pod_offline_or_broken_hit(struct pag void p2m_pod_offline_or_broken_replace(struct page_info *p); -static inline long p2m_pod_entry_count(const struct p2m_domain *p2m) -{ - return p2m->pod.entry_count; -} - void p2m_pod_init(struct p2m_domain *p2m); #else @@ -689,6 +690,11 @@ static inline int p2m_pod_empty_cache(st return 0; } +static inline bool p2m_pod_active(const struct domain *d) +{ + return false; +} + static inline int p2m_pod_offline_or_broken_hit(struct page_info *p) { return 0; @@ -699,11 +705,6 @@ static inline void p2m_pod_offline_or_br ASSERT_UNREACHABLE(); } -static inline long p2m_pod_entry_count(const struct p2m_domain *p2m) -{ - return 0; -} - static inline void p2m_pod_init(struct p2m_domain *p2m) {} #endif From patchwork Wed Dec 1 11:21:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12649767 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 D00A2C433F5 for ; Wed, 1 Dec 2021 11:21:19 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.235924.409227 (Exim 4.92) (envelope-from ) id 1msNfj-0003Nq-6e; Wed, 01 Dec 2021 11:21:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 235924.409227; Wed, 01 Dec 2021 11:21:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msNfj-0003Nj-3j; Wed, 01 Dec 2021 11:21:11 +0000 Received: by outflank-mailman (input) for mailman id 235924; Wed, 01 Dec 2021 11:21:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1msNfh-0002lJ-79 for xen-devel@lists.xenproject.org; Wed, 01 Dec 2021 11:21:09 +0000 Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.111.102]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id c5d0028a-5298-11ec-976b-d102b41d0961; Wed, 01 Dec 2021 12:21:05 +0100 (CET) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04lp2052.outbound.protection.outlook.com [104.47.14.52]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-14-uTpvIZzHMGSgBT8luWXX7g-1; Wed, 01 Dec 2021 12:21:03 +0100 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VI1PR0402MB3936.eurprd04.prod.outlook.com (2603:10a6:803:23::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Wed, 1 Dec 2021 11:21:03 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::5951:a489:1cf0:19fe%5]) with mapi id 15.20.4734.024; Wed, 1 Dec 2021 11:21:03 +0000 Received: from [10.156.60.236] (37.24.206.209) by AM7PR02CA0023.eurprd02.prod.outlook.com (2603:10a6:20b:100::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4755.11 via Frontend Transport; Wed, 1 Dec 2021 11:21:02 +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: c5d0028a-5298-11ec-976b-d102b41d0961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1638357664; 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=2biUIJpAqJ0eyN1ne/XaQldxN2vM6fcaq9kRJNDcVj8=; b=kmRqSOmosVJCu0w3PILVULsYzkUymgNDjkVHiXQx74/jAB6VZUzvxsCITb3kPqZyEL7iM5 VMeGBU6/orXqwnBzcDDZfJHxliLtJIYJFn5G3TWyhBTiiLLonwckX1jQIWTHSOTm6R7iKc OJ1uqs95yvfOHO4oJCq1QiGXHfrv/II= X-MC-Unique: uTpvIZzHMGSgBT8luWXX7g-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZgPRG/PTYx512xwVOnUvSJSr1jOQV9oFPtG0qyF3LcDp6+rhSEXmHSRSCxuELW+JBZIKu2NNJLbzKXDB31tklRpFErxJYbKrc5yqBP9smDQ5T8F+zIZskN7QPTDVhej35dYhDzpRVNJKVEbpyJjUnSg1TBe+mfKmqFiMt3TWiH1bMRmNe9UxHhKuaHJ74bkU+RI3qE6Jh/ZChpOr8zrh4hdDYnNUAAZHoPIVnzhljqg4aCGKuHDwR1tKBIDD76NYRRx7zxEhWLwCpPPxiVzrFw7PAxUHiAsQi0h8V42f2ZytpF/fIwjcy/LOzUCpSJe1EaP8WTz6SrWGlrh7q9xMCQ== 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=2biUIJpAqJ0eyN1ne/XaQldxN2vM6fcaq9kRJNDcVj8=; b=S/fM81DCcv4tL6hY2UdVbXqxB4sWhiX/kn6fwUCypjJWF93Zix5iL05DECDZUXKTBYjUYqZu+pWZ6LXvvrUbBMc9HBy/3JzNy005EJN6Siv4GBvT/wjoEWNZDYqCRdPfyisO/Rp3tS3/Rk/DzaqbB/DNnqHrKyEeXJiyJRcrBbZY3x/KO0PNJlV6D9b0N1a3+dEu/3VPSDkvLEAi/5mHgXEQ1/mRhdL+3ezUVVEWfbXP1+VN+WzKuOVLB5pN0nnHS/rq7wRdjhc7JHPO8UGYIxTPCRZ7NeY/NJ9yLnh+1g+SugqQTAjHurDM4P7H60nguAadbHrOGCiObqz35pJooA== 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: <33b3a7a2-3b1e-d24d-5359-c5fd3294d847@suse.com> Date: Wed, 1 Dec 2021 12:21:01 +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] x86/mm: tidy XENMEM_{get,set}_pod_target handling 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: <8bb92e3f-38b4-16a1-0a45-5f393081f230@suse.com> In-Reply-To: <8bb92e3f-38b4-16a1-0a45-5f393081f230@suse.com> X-ClientProxiedBy: AM7PR02CA0023.eurprd02.prod.outlook.com (2603:10a6:20b:100::33) 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: ac7186f9-94fa-498e-6175-08d9b4bca8d9 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3936: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:419; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +ayEi9LNnXfpkJFBOvfQSPsk7YXTgl+Ykfj3OI7aIG1RmYlTuiC96imhYoV/6/DnMc3rsifJmeTMDB0iDs/I4sdkBasE8nncUUMhVJr4EWTInBJniGXvzulxTgzRRwVsscx6TDfyPbB+y3PLTvMY0bi6Do9E5pSin0EVnTW1xnkYryfg2N9L27Cgx/MAfi4zA6qlHzPu3oXklGWOZNiJak//SgQelZthvwj31lNrFn/GPsxC05MW0GzXyeiZIyrirUlUT/GG01JSpkBaxI5AV85F8FfRlumSo5WisW0LguW3FucLk+90R0Ey9NtUN2GaD0/UhJKcHFLz9PwAxzi2sFxsXeebVf7jteD9itvl8HbxA+zuloPsWotQbQ/xQNmyTydXozn12yQmCBpdakWPQmMGKbmD6VDaeB05VtKk73JgSA08PdnGs3R7ZTNwIhTIOAkFA5roeYIs7wb+3MJ/SmgHO2cd7aHB3MUkN5GCpFY3RMdOoAy8U3rM9wXzeELIXV6dax+gEEtvY+cCSSrz2g3JbYTjowEflDcI/CiQmWbCBbL9NKygJNjlSUs/vP0eorh+sz6QnK59PNHYX2n+/u1h1qxMWH3R3NovU+wzfFR7LYMhG6p4876ugPGs33nD5nkgEfVytJEbXavJSBw1oQkUluHWGa7F7i6X7G0P58b+BU/FZXoT1ifYt+5qT0GG/+bQ7HBcz5zUkbBdF7lYwYTY7JD3PeQMQ5ahsh8cuuw= 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)(8936002)(2616005)(36756003)(6486002)(4326008)(86362001)(5660300002)(6916009)(508600001)(16576012)(54906003)(66556008)(66476007)(31696002)(83380400001)(26005)(66946007)(31686004)(2906002)(956004)(186003)(38100700002)(8676002)(316002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?m+3DCHVUs2PJ1QW3J13Pg+Ulsf7X?= =?utf-8?q?WhUX44LaU+WumeCqGd9txHBcUHnNzDeYo5Qb5Js2y3ZivsoyDEtkabXBmrGb480ZU?= =?utf-8?q?ZLQtJ4QtAZ8T9cGy9pdjA4lV5C4y9fmvjLioYqU/nZErkaBYRKNOVX/WTnQ0g0Qgw?= =?utf-8?q?9nYDoMNz469WSw8pVJjiIiMnyORJz0sJK39VceyJCShBW8rYuAbEkX8eMMrmVtiEQ?= =?utf-8?q?vQB5OHlE5DTZ4/tnnBZnO2GufNVUz0bmd9cI14mrdcSyNtg5xZ2nS3XVAvuOnc5Bj?= =?utf-8?q?dMUNJIn/6Ov+KCX7OZdjT7yyOcDk93ofMy5gHW8p7xHBNzPHHgqUCyr7wuY7dyLLH?= =?utf-8?q?hB34WSTy9lRXdiOs0wyVKw1+0mvCK6PXuR7OAnsQ82XSC7FUupeyBcrSpol8vN/KS?= =?utf-8?q?eu8wxKwJ3J0WBpAcEZF+eR6b/Z3ECcl8dOSU3B2eH81XJOHvhH7eblu8HRE6edI4/?= =?utf-8?q?wam9Ph+18TDnwwvF1BDAL67N2UZYVYxXpqVLUouQ+45k1FVltYEaK2t1Wsf69xKOZ?= =?utf-8?q?gLfX9OFbDRFaq5OAYZ0xSnWy5qOQGAb43/0W9mPAlLl5/OSZKKMCRpyUgHKCFCVNT?= =?utf-8?q?TN9kPsRG/fNu0Jaoy+sR9OyuSKb2iZzJ0i/wrOyx8STfdgBUB22M0vXXT+rL57AY8?= =?utf-8?q?s41gyeIncQsou/FLlw3IYmQeN5yA8SsllAomxMJXk+Mu2OJG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c/E8=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac7186f9-94fa-498e-6175-08d9b4bca8d9 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Dec 2021 11:21:03.0285 (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: OgavDlWeah3ipLxGls/UuPGkx1OXN95D01P6AT4ltpJXxIw+hG9NA3CsDEvlkRqnLPygcHM2JrbyoN4f2vfYcg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3936 Do away with the "pod_target_out_unlock" label. In particular by folding if()-s, the logic can be expressed with less code (and no goto-s) this way. Limit scope of "p2m", constifying it at the same time. Signed-off-by: Jan Beulich --- v2: Re-base over new earlier patch. --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4788,23 +4788,17 @@ long arch_memory_op(unsigned long cmd, X if ( !is_hvm_domain(d) ) rc = -EINVAL; else if ( cmd == XENMEM_set_pod_target ) - rc = xsm_set_pod_target(XSM_PRIV, d); - else - rc = xsm_get_pod_target(XSM_PRIV, d); - - if ( rc != 0 ) - goto pod_target_out_unlock; - - if ( cmd == XENMEM_set_pod_target ) { - if ( target.target_pages > d->max_pages ) - { + rc = xsm_set_pod_target(XSM_PRIV, d); + if ( rc ) + ASSERT(rc < 0); + else if ( target.target_pages > d->max_pages ) rc = -EINVAL; - goto pod_target_out_unlock; - } - - rc = p2m_pod_set_mem_target(d, target.target_pages); + else + rc = p2m_pod_set_mem_target(d, target.target_pages); } + else + rc = xsm_get_pod_target(XSM_PRIV, d); if ( rc == -ERESTART ) { @@ -4816,13 +4810,9 @@ long arch_memory_op(unsigned long cmd, X p2m_pod_get_mem_target(d, &target); if ( __copy_to_guest(arg, &target, 1) ) - { - rc= -EFAULT; - goto pod_target_out_unlock; - } + rc = -EFAULT; } - pod_target_out_unlock: rcu_unlock_domain(d); return rc; }