Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2865561rwl; Mon, 27 Mar 2023 06:24:29 -0700 (PDT) X-Google-Smtp-Source: AKy350Z/kz6jP2teYxTskGTsHTuyxVc4B3Qv+LQj/hwn0r/pUZ0l1ZnpA29R85jZTrt4VuvXqlmz X-Received: by 2002:a17:906:ecf1:b0:932:c1e2:9983 with SMTP id qt17-20020a170906ecf100b00932c1e29983mr12330985ejb.15.1679923469403; Mon, 27 Mar 2023 06:24:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1679923469; cv=pass; d=google.com; s=arc-20160816; b=lhstNrMZd/+ExrtabTnGttCJfE72G/yaaZ3zRAs2UeGfTf01NMv1P9KsfPc2GXFN37 ozPa3e4FLvbCoI3mF2GsQ5GNT4d4MFyFlxpoTU/13LMYz8HwlOMdNyYitnFkosPKyFsw x/w31ZoupGVoP191BA3BASrDjcCKTGXzoaaTKtigVpGTXzLTuUlh5D2PaNRZDPtpnLZq rb5KUsQ7GdrUF7mQW32yJC0RRS8aulucHgLTVUDFwRf4xqNYK69yjdTZRAthKx3nT637 0KgWk/7mdB1BtndCaxhSpDcmHwc1U2OEzStSTFrVjrEn2TL9fBxBgFxieyNtF71N+UFY 2fJw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1wivdlfXRZHaFecrxciooBcchDqO+eaAuuDzZW4Ha+w=; b=Z3L3jWUclfRazK0Z7w4ZAqGqlpj7ibvp5vO+0fcIpGqdPaclWhM64cCJdlBrHs+UxH 5NBH3Y05VlMa6OrUpQU/ttJwEZne5/MyjBgfj+2oKsTR9NIxp0kTcVxRRZ64KSh9nfTG VsKtrqsrw4yvltSgCgrV4Q8UuHzW52hYBRPKu33azJluL0ijxMKDCivD9OHWTSOCeVvl 3KVklql4jgh/94GBDZG3L36sbdNHc7B0SIQJCOtdpMO+/RGHFAzAsl7xcGkGc/RmNsH2 oBSdpD++R9OBMupGZp3mfF5V1aH68e1GPRbVVC/9ZqDCGgTWAFCMyiW0IsltZVyCaoB8 GV9A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ESmlUFjb; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss24-20020a170907c01800b009334a8e8c07si22746282ejc.103.2023.03.27.06.24.01; Mon, 27 Mar 2023 06:24:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector2 header.b=ESmlUFjb; arc=pass (i=1 spf=pass spfdomain=microsoft.com dkim=pass dkdomain=microsoft.com dmarc=pass fromdomain=microsoft.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232452AbjC0NR2 (ORCPT + 99 others); Mon, 27 Mar 2023 09:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232435AbjC0NRW (ORCPT ); Mon, 27 Mar 2023 09:17:22 -0400 Received: from DM5PR00CU002.outbound.protection.outlook.com (mail-centralusazon11021022.outbound.protection.outlook.com [52.101.62.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 954C61723; Mon, 27 Mar 2023 06:17:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JbM1D/zetlQ6RNFDMqa/LrvX6DmkEpOAMlVA86TaRlRFwjFH6Vd7TZvZx0jSa4IX9UZ7RRuTAyNGU4nKBZr3jgfrxgrjuVyEcq4w4POpwlwTG05dg6woRj8YKuvoz4IdGK6CrS7N7Z7jj+kO/r1egiH1uZMqh4tk7KjHA1aQB93sdb0NRWCP0hieW55JVIenkJjUFBSgyeNiHImjRAgc2QrRDoKo9yVkibKITlgew+yXlL8WyOkBNTd7223B9Hbr124pnSsvPtjQ3+hGjZOkVjdfwITY0reD7zBD7GH/+Wdl0S+G+tRqJ2RPAMFwHcekj72dd51oQHaeOSGFapqyTQ== 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=1wivdlfXRZHaFecrxciooBcchDqO+eaAuuDzZW4Ha+w=; b=XHJqwkGEWHmNnoGIomgbKX9KUR/bQoUWm0F0MBCBoQsRstEXXsQ6cJSP5MI/r0H/zugDlrk3lLHwf9zQk3Yt/BBO35QcOsjovxJWfZu4iJlpZMJjjJ/a5i9yPk7nDbNXLfdBRRMXCGV3Af4+809gSdj//VmGZdofoS8PajXZIguTplMG2K9JjBSS/MBmdoM31TvIl6HVus1nwdeaFBBd0w2laVGEyHHAkPvr0wTsc6vt8eIC618UIjeFz47P35XgoJD3k4diFK2gDAEPgwOYJAlwsNP9jTjJ32+SrMOeOV6vUXjgbSughsbm9vrYyDAF+/5USvQDJ+qxJxBhYf/PUg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1wivdlfXRZHaFecrxciooBcchDqO+eaAuuDzZW4Ha+w=; b=ESmlUFjbxjsQhHnOrPPphPK17SYI7i7EOAL2hPILRT44TqJ6r7N9KZLGvJKnMxm6nGrwBSUoPiIhhkBsz7492boSNPSEaZepse116CR/EUsjwSduoNzXjfiQsj0AXs+C1regiwIVTK3X0cho+9EsGHhj+kkBA+xiMPXQZiiie3k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=microsoft.com; Received: from DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) by SA3PR21MB3960.namprd21.prod.outlook.com (2603:10b6:806:2fd::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6254.11; Mon, 27 Mar 2023 13:17:18 +0000 Received: from DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f]) by DM6PR21MB1370.namprd21.prod.outlook.com ([fe80::b7e9:4da1:3c23:35f%3]) with mapi id 15.20.6254.016; Mon, 27 Mar 2023 13:17:18 +0000 From: Michael Kelley To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, arnd@arndb.de, x86@kernel.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Cc: mikelley@microsoft.com Subject: [PATCH 2/2] x86/hyperv: Exclude lazy TLB mode CPUs from enlightened TLB flushes Date: Mon, 27 Mar 2023 06:16:07 -0700 Message-Id: <1679922967-26582-3-git-send-email-mikelley@microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679922967-26582-1-git-send-email-mikelley@microsoft.com> References: <1679922967-26582-1-git-send-email-mikelley@microsoft.com> Content-Type: text/plain X-ClientProxiedBy: MW3PR06CA0026.namprd06.prod.outlook.com (2603:10b6:303:2a::31) To DM6PR21MB1370.namprd21.prod.outlook.com (2603:10b6:5:16b::28) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM6PR21MB1370:EE_|SA3PR21MB3960:EE_ X-MS-Office365-Filtering-Correlation-Id: d2cec5f0-a4d9-44d8-7991-08db2ec595b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ch/bgHkZ1Ldh+zQrGBC+7iSfguH/lTpTupfkUuFYIhEdhbg84oVqqi23NftCs35ODo5X8kSeoAeuw38nUvUQ9VhMyu/Uc8UqUGUFFLrqNoARoKLYS/RSuL063ZRa/IP/UwesLltT11r4SX9g8+39sc03uc/1Ok3Bm21eRJg800WJPEHAljLK71vznkfErgap46IO7IiuoXNEK99Dsg/8a8gA7e+DvhkvLVUS3Ct450UxsJANeKTnZiVGaIAABZSUYdiRGXCqfexl73u30/+E3Qo48v1QfseIqgA+mKnp7I8kIfk9lyae1VMkBdvveJB2TG1ghQj23BeniiPl7Ap+oUBczwqcC02pN2JW2vBA+WRUB8bVwdruqCdxfi82BOh3oRb8Gf5Ltv6mdLli7LZfoAOY1ohNBq/heEUY47t4mKlDxt9DmyRc0cLI8CniGlHZwPaEatIp8188QVYrHXNFvGEl5KQv4uG9a5a/rEcoyHIvFyrXThbdEy3k5sNrMvypUrNOQ7qtvG2Ln61083/s7t2NdTfqJTUqX18ZmgtCyqevmC3mcLJe8ZVEKlzSbUURJ/njYGmt0Sfb08nlkQAaqXc6V93WOX6ad34BZu4ytf4YFsFFu/qfZUzeB25z0oJlE6JOEeNbln/LlEouVJNuy9GWaAaYNi2PYFc9V0AB97RazsKpNT4rWj7wQWICy+L5 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR21MB1370.namprd21.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(346002)(376002)(39860400002)(136003)(366004)(396003)(451199021)(41300700001)(4326008)(82950400001)(26005)(2616005)(921005)(6506007)(6486002)(82960400001)(8936002)(86362001)(66946007)(66556008)(5660300002)(66476007)(8676002)(6512007)(10290500003)(83380400001)(2906002)(38100700002)(38350700002)(107886003)(7416002)(36756003)(6666004)(316002)(52116002)(186003)(478600001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?YP9169tbuVsR/+nA9t9DPTwJhb7Trm/bj29oeeH4tok7O9a4UIJY01ponSNY?= =?us-ascii?Q?J/8QfjTGi7pX8fwgpORhnGEtBFMZi+DeOSAiYuNlU3bXV629HKfmYCKk3agm?= =?us-ascii?Q?3eO8Ia2xF6mcLqjOH0q/PtcYbNTpduOdDQzj0cUzIOz0XBwtfEaHWiiqe8cZ?= =?us-ascii?Q?qqaFtYO2uoX60G/+gziF19zDq95xdI4+9ZGFmy2cu7MUOerMJjf+3/gJVbNX?= =?us-ascii?Q?LT4PzVSpcCYieEJsohJa0IXyOhS7EwHjsOuFXqkj3PZJO1eTZdaAL7v/0V4s?= =?us-ascii?Q?J4m2BMJ8mpLRN2GgR04TqYzc68nmHuY2+xLthbPHjdULUO2sgTENi/cFebSA?= =?us-ascii?Q?M51vJFdZMnvG957h90VVWVKhmPXPHe6mNvziTuMvcgUJ81o98N9ulg1UMl1j?= =?us-ascii?Q?SqSdD3Ffx0wYGsmo6dYK5FEiMMmUBhME9jxt2loxgSlm33ijPgbHQu7Ot5Sm?= =?us-ascii?Q?ISrcOp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yOQwIMgeIvY3PU4xkUAfY?= =?us-ascii?Q?M4RCi9Dse1bzTqseMyL/CfnCCm81Xy0z+DWnvvdd10BwIVVi4sTyLMhCIjSS?= =?us-ascii?Q?A4fzngC3vVvSAAHaNrIV8StoU6+ekF/850sbYsRPC3yPCndZdP4ufM29jst6?= =?us-ascii?Q?MOiYkmIqVaerg1xLBBKa5xBwWB2dBMEXVEJJKvYM+OMzvNwK+bxatADc3vgt?= =?us-ascii?Q?/0B9gpNmMMjc+uSre/B+VzK/A9yy3s/Vkqn8N+xH?= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2cec5f0-a4d9-44d8-7991-08db2ec595b9 X-MS-Exchange-CrossTenant-AuthSource: DM6PR21MB1370.namprd21.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2023 13:17:15.9715 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7m6soiOALhqtLTR8otuiWmCLOlfQZHJ0UG6KBTG07trWupd66+LCuhW6AHMGPKmGrG4FXx/2vPieD9OLfXykQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR21MB3960 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the case where page tables are not freed, native_flush_tlb_multi() does not do a remote TLB flush on CPUs in lazy TLB mode because the CPU will flush itself at the next context switch. By comparison, the Hyper-V enlightened TLB flush does not exclude CPUs in lazy TLB mode and so performs unnecessary flushes. If we're not freeing page tables, add logic to test for lazy TLB mode when adding CPUs to the input argument to the Hyper-V TLB flush hypercall. Exclude lazy TLB mode CPUs so the behavior matches native_flush_tlb_multi() and the unnecessary flushes are avoided. Handle both the <=64 vCPU case and the _ex case for >64 vCPUs. Signed-off-by: Michael Kelley --- arch/x86/hyperv/mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/hyperv/mmu.c b/arch/x86/hyperv/mmu.c index 0ad2378..8460bd3 100644 --- a/arch/x86/hyperv/mmu.c +++ b/arch/x86/hyperv/mmu.c @@ -52,6 +52,11 @@ static inline int fill_gva_list(u64 gva_list[], int offset, return gva_n - offset; } +static bool cpu_is_lazy(int cpu) +{ + return per_cpu(cpu_tlbstate_shared.is_lazy, cpu); +} + static void hyperv_flush_tlb_multi(const struct cpumask *cpus, const struct flush_tlb_info *info) { @@ -60,6 +65,7 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus, struct hv_tlb_flush *flush; u64 status; unsigned long flags; + bool do_lazy = !info->freed_tables; trace_hyperv_mmu_flush_tlb_multi(cpus, info); @@ -112,6 +118,8 @@ static void hyperv_flush_tlb_multi(const struct cpumask *cpus, goto do_ex_hypercall; for_each_cpu(cpu, cpus) { + if (do_lazy && cpu_is_lazy(cpu)) + continue; vcpu = hv_cpu_number_to_vp_number(cpu); if (vcpu == VP_INVAL) { local_irq_restore(flags); @@ -198,7 +206,8 @@ static u64 hyperv_flush_tlb_others_ex(const struct cpumask *cpus, flush->hv_vp_set.valid_bank_mask = 0; flush->hv_vp_set.format = HV_GENERIC_SET_SPARSE_4K; - nr_bank = cpumask_to_vpset(&(flush->hv_vp_set), cpus); + nr_bank = cpumask_to_vpset_skip(&flush->hv_vp_set, cpus, + info->freed_tables ? NULL : cpu_is_lazy); if (nr_bank < 0) return HV_STATUS_INVALID_PARAMETER; -- 1.8.3.1