From patchwork Thu Sep 30 12:35:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12528209 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13FA5C433F5 for ; Thu, 30 Sep 2021 12:35:38 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C0F2461381 for ; Thu, 30 Sep 2021 12:35:37 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C0F2461381 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.199867.354176 (Exim 4.92) (envelope-from ) id 1mVvHe-0002mq-0A; Thu, 30 Sep 2021 12:35:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 199867.354176; Thu, 30 Sep 2021 12:35:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVvHd-0002mj-TK; Thu, 30 Sep 2021 12:35:29 +0000 Received: by outflank-mailman (input) for mailman id 199867; Thu, 30 Sep 2021 12:35:29 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mVvHc-0002kX-VO for xen-devel@lists.xenproject.org; Thu, 30 Sep 2021 12:35:28 +0000 Received: from de-smtp-delivery-102.mimecast.com (unknown [194.104.111.102]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7087557a-fe7b-48c5-8378-b1e43e0c7094; Thu, 30 Sep 2021 12:35:27 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05lp2113.outbound.protection.outlook.com [104.47.17.113]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-20-aoc0CG_oOqS0JfWrqru6WQ-1; Thu, 30 Sep 2021 14:35:25 +0200 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com (2603:10a6:803:e7::16) by VE1PR04MB6383.eurprd04.prod.outlook.com (2603:10a6:803:11b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.13; Thu, 30 Sep 2021 12:35:24 +0000 Received: from VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b]) by VI1PR04MB5600.eurprd04.prod.outlook.com ([fe80::4d37:ec64:4e90:b16b%7]) with mapi id 15.20.4566.014; Thu, 30 Sep 2021 12:35:24 +0000 Received: from [10.156.60.236] (37.24.206.209) by AS9PR06CA0219.eurprd06.prod.outlook.com (2603:10a6:20b:45e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4566.15 via Frontend Transport; Thu, 30 Sep 2021 12:35:24 +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: 7087557a-fe7b-48c5-8378-b1e43e0c7094 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1633005327; 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=eWRvbp7ta3owYpcdKj7PO7T0r2HXZ7zs9WVfAD35Uvw=; b=UXXlauToOjHhrRu8X3wJHT8P7ehbax9MC1OeZ3RsHo86vGKJB0it7YUxco6xoxXbkgaw3S ztAjrHLkaA1JeyHZxaaQ5wHEoNMwZX1QGNvQN1IEDv9/H0rHnt0ku5QsTmpa9foc2KLImI MA1BJaalnudb+f5VWlA01VsvQSia5Sg= X-MC-Unique: aoc0CG_oOqS0JfWrqru6WQ-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHkFibb5LYshIVpl0Jp9XnQZEGUsmW7OWVWVt0BujZRFHmCG+Bc50cgQqtzeRjcbiYLLLyPp0v7NQqVfrtBiNOqdMjnNKS6XkdwG0hx0DPY9PKuUk97H+nWKvlabCeMYG0nO6Cv3dX40QvfHKH3weYlGrh0gofHGLkrCYCtRRdQpVpZyWSlxBSEjB/JHVZyboqadYFIGEYsDJIR/N9YdBetu/2osTnEew84x+VfLMq3lcMVRoDoEK+7uwwI/2+I3z7XD5GHGfSHJTOznViGOtsnJKSWNmsn7GF/fhTZiPrN19YwZsuiqmddGoZr/i4zUXs4sWaQ8xhoRPc6WEvFh8w== 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; bh=eWRvbp7ta3owYpcdKj7PO7T0r2HXZ7zs9WVfAD35Uvw=; b=YsImSKohjx7Tx5XUvZCvBF0KUB/FrYqV17rGkQVV+9k75XwtAkVl8oe8qcsDUAD0lvstAt1+cYkDhiTXIoYMHE0DnpWyPbXLceIXXlEi0QICl3TcgypmmsBapKE59xmxL/anh/vyg+M0BjWzHKOrgvll6/aMGFQLIyEYnl7dw5tt0y/rd8xPZQI/GwpYH6WK2E7BLRFMCOnsMvRps7GY0/EMEmflRe7xvtpwfqbUb0Vc9MeFe+lAtlwTkSwR/4uxHmbgoZvgRIZjhb3tYtq9STA4tIjUjf9s+SJCOsrclV63PQ48ZXwH/Myqx2KVt1iZhJ0XmcF0nv6BARaYO4wCbA== 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: lists.xenproject.org; dkim=none (message not signed) header.d=none;lists.xenproject.org; dmarc=none action=none header.from=suse.com; Subject: [PATCH 2/6] xen/x86: restore (fix) xen_set_pte_init() behavior From: Jan Beulich To: Juergen Gross , Boris Ostrovsky Cc: Stefano Stabellini , lkml , "xen-devel@lists.xenproject.org" References: <022b1a5e-4121-6bae-f07c-4ad5eac12481@suse.com> Message-ID: <57ce1289-0297-e96e-79e1-cedafb5d9bf6@suse.com> Date: Thu, 30 Sep 2021 14:35:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 In-Reply-To: <022b1a5e-4121-6bae-f07c-4ad5eac12481@suse.com> Content-Language: en-US X-ClientProxiedBy: AS9PR06CA0219.eurprd06.prod.outlook.com (2603:10a6:20b:45e::10) 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: 74700795-3594-4d3b-fd63-08d9840ec687 X-MS-TrafficTypeDiagnostic: VE1PR04MB6383: X-LD-Processed: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba,ExtFwd X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: w3I5bU96eYptQzelHHw9QkIo2SbqWLNurMYmpBlW2DK5UVBHPgPgtxQg9tSYuQ1lObrEXgzpRgOfhMx4S2WELbT6wKE1zE0/fE66OBbI4c2JDgnoAcsWUMN3f6Qlo4hAJ382EcUf2prMHo5u6YCXoNDZyv9NBzCZyZewBA1AdH29qlEZaez7fVEfR7Hu+p9HEs1+C9AWlDjsfCIJz9KVgIII8PNMR6pLwAcL7Ie5bUqxWgYza07SitTUTdY/P1Ca2ATtd/A6dyk7aCQ1LHPGL9SS56Iv4bL0ZiY2K+5TW59ElCM4kaHi+9Rf+JALzQebeV5WYeid90F9gDrQVdjMihv239FLVaMqfYu6/2G4S8oDfpoIZZVDLCiD24m7SR6/in71fd22+YeL7VfC30TPdEiuQGCkeUZNMmHHcirbqkqsWSI12lfu7wI1ycT0RpeXdwnRiMLpNmspBYyfzAkLOsMTdBLYjVqHKV8Uq6NdiuTeqHzTAcLP8OC0Fxy5JU1uz58MH6FBWGQfqln/WjRoidjfFoFigOVwXBjbzqPFKrgXm0zChU4PaZZ7qP3BwbKSoIj6/9UJAhAwj0p30VywGdGiiUNUzd8tn1+EO3lehmpuFrKu3PpmH+shMcfWeE8a1yz+7N7F/iF8YXYmIEqtS+wgayvOWBFLZbFq+LZJW2OSEZECzQ2FjhlKRORfS4JHGLxI/x95rUKr2pK36L+m69sRDzxNdXDqPgBH7L+dstoBoQzCJZEYIQLtmU+xnYIh 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)(4326008)(2616005)(186003)(956004)(508600001)(31686004)(66946007)(83380400001)(8936002)(86362001)(2906002)(31696002)(16576012)(316002)(38100700002)(110136005)(8676002)(36756003)(6486002)(66556008)(66476007)(54906003)(26005)(5660300002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?xTgVkak16NvHu3cEimEsqTTCl7H7?= =?utf-8?q?1WZS/PUzC1HDPD7k+tQL98Ol6jvJmSQFZI/Q78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EJgtx2wQp+IJFczDqQM8S?= =?utf-8?q?dieA/oeLfJVCd6VTmi7AnR5cuTNRcj8nZqv4Y/NJ8vEjcBQw7UlTexlu2AOYOXntY?= =?utf-8?q?aM7oqXZ6tJX7X1Adsvbw99cFB2Op+cNnGGArEa5iWeFBvhNVgidmlVaCn9yDH+ioX?= =?utf-8?q?jnXWfZmhI9B+XSzach7pgzkIpeV10Hp1IF3ZXiKsXRn2bb1SLx+GzhttscqSuCjhy?= =?utf-8?q?oRAb0YJIcPkINShQsE+tKvTwyUkbo0z54ySWYQtMCLH1af70dDftqKn35qDS0r108?= =?utf-8?q?JMkhk3YycISxEO739jeiROP4vBEAG3Sd+6xqqSHHH6dlV7EnSH3Vo+EakO3a/jG/F?= =?utf-8?q?hhROjRzqBJAxvm2V?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74700795-3594-4d3b-fd63-08d9840ec687 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5600.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Sep 2021 12:35:24.5804 (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: Z+QpJ6hdD1dvtUjfh20b2SeBFtCK/5mrepLbPm7M8obAJPEYT8rkLVValbSZp1jWDTxr/UUqZCjnonlfRIpSDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6383 Commit f7c90c2aa400 ("x86/xen: don't write ptes directly in 32-bit PV guests") needlessly (and heavily) penalized 64-bit guests here: The majority of the early page table updates is to writable pages (which get converted to r/o only after all the writes are done), in particular those involved in building the direct map (which consists of all 4k mappings in PV). On my test system this accounts for almost 16 million hypercalls when each could simply have been a plain memory write. Switch back to using native_set_pte(), except for updates of early ioremap tables (where a suitable accessor exists to recognize them). With 32-bit PV support gone, this doesn't need to be further conditionalized (albeit backports thereof may need adjustment). To avoid a fair number (almost 256k on my test system) of trap-and- emulate cases appearing as a result, switch the hook in xen_pagetable_init(). Finally commit d6b186c1e2d8 ("x86/xen: avoid m2p lookup when setting early page table entries") inserted a function ahead of xen_set_pte_init(), separating it from its comment (which may have been part of the reason why the performance regression wasn't anticipated / recognized while codeing / reviewing the change mentioned further up). Move the function up and adjust that comment to describe the new behavior. Signed-off-by: Jan Beulich --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -1194,6 +1194,13 @@ static void __init xen_pagetable_p2m_set static void __init xen_pagetable_init(void) { + /* + * The majority of further PTE writes is to pagetables already + * announced as such to Xen. Hence it is more efficient to use + * hypercalls for these updates. + */ + pv_ops.mmu.set_pte = __xen_set_pte; + paging_init(); xen_post_allocator_init(); @@ -1422,10 +1429,18 @@ static void xen_pgd_free(struct mm_struc * * Many of these PTE updates are done on unpinned and writable pages * and doing a hypercall for these is unnecessary and expensive. At - * this point it is not possible to tell if a page is pinned or not, - * so always write the PTE directly and rely on Xen trapping and + * this point it is rarely possible to tell if a page is pinned, so + * mostly write the PTE directly and rely on Xen trapping and * emulating any updates as necessary. */ +static void __init xen_set_pte_init(pte_t *ptep, pte_t pte) +{ + if (unlikely(is_early_ioremap_ptep(ptep))) + __xen_set_pte(ptep, pte); + else + native_set_pte(ptep, pte); +} + __visible pte_t xen_make_pte_init(pteval_t pte) { unsigned long pfn; @@ -1447,11 +1462,6 @@ __visible pte_t xen_make_pte_init(pteval } PV_CALLEE_SAVE_REGS_THUNK(xen_make_pte_init); -static void __init xen_set_pte_init(pte_t *ptep, pte_t pte) -{ - __xen_set_pte(ptep, pte); -} - /* Early in boot, while setting up the initial pagetable, assume everything is pinned. */ static void __init xen_alloc_pte_init(struct mm_struct *mm, unsigned long pfn)