Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2980240rwo; Mon, 24 Jul 2023 04:37:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGKfNyXhqaHsBWpiCJzj6BdP8NqAFORKSUcm8PyOnUeQg4fVxGHUOkwOYDuE8hBwqRVPaQQ X-Received: by 2002:a17:907:1c26:b0:98d:4b97:acc8 with SMTP id nc38-20020a1709071c2600b0098d4b97acc8mr15936437ejc.25.1690198674850; Mon, 24 Jul 2023 04:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690198674; cv=none; d=google.com; s=arc-20160816; b=AbOyIuimNseZt57o11kUAW4Ou0beDX/Eqhd3mZcxn4oHyjTtT4qzoS/mj5d949kF9y 4gj4MX2erJU2xcYVSwI4tlF/x/M4asz7p2oFGLJ8Em4bir/8ESegnf6KUidPrjCnbDwh Fyo6peuExHm87s9X2w/hJQ7bttBJDYADkno6By5EPDkTsi45JYONDF3I5R+vSOJnELUd jqNpC4JjbuxGSeEIPLhndloNqz+gmWaPizKyLB0AE5yZ/qYfWOokXIVmB7l3/KljiGNc vtYpdEI+EdRDGrB6ZlD8n0ek/5Y/COd6jzU1uwv/wfULQQfUmTRiWfXGVWgI+vMNMxpK gSnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=EXJhrkLdNOLUHGZbbc+F0hjfqb3hPCsrY6WTn8MVyN8=; fh=X32eiQs63rYqXoA5F7iHQYUVFkpzLyr7MrIydsKSWqA=; b=LkqDJaRDrfziEtGpGZ58foCNNA+WkJ9IJDWgwhMN9kNcjUT4zk7rgaQjyaMqFjQ7+C HNWlZSgpu0JNapevj8cHshVahcMRuLKF9AJ1LQlRxbB4V52RscCMVehoVvYelOXeSh1S NteD+isaC1z2uin4vFD1H4+jcJNmz7dZyDSDhDQk2YOaKOOZg3EQnov/P4guK99diuGX ub5zA8iMIgoWH1f6eWcmwKaAWdTHTetFQOXnPoSrtnPpy9GiUbtSqUDDi5NNxAb5Gvko lr4VvjdX0QwdwGDNBVOiLeIps3v2IwuKOA4zmhmvKfFGdY/nOcaFzvtrV2kMQzGIwt9c f0rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IKMGMDoB; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bn4-20020a170906c0c400b00992bbbb019dsi6251144ejb.119.2023.07.24.04.37.30; Mon, 24 Jul 2023 04:37:54 -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=@redhat.com header.s=mimecast20190719 header.b=IKMGMDoB; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229650AbjGXLen (ORCPT + 99 others); Mon, 24 Jul 2023 07:34:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229909AbjGXLeY (ORCPT ); Mon, 24 Jul 2023 07:34:24 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 95F9D26A5 for ; Mon, 24 Jul 2023 04:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690198364; 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=EXJhrkLdNOLUHGZbbc+F0hjfqb3hPCsrY6WTn8MVyN8=; b=IKMGMDoBf5Q4TRF+J45GToUGxW8KJvD5bGgLyJeeLFh25nplZJDxAd3SInz6BrXVMcuVby hYYnA1MfyF7PRcydtsYPxyA9Zv0hniuCao8nXh20+jsSTaAkzAhJk2Wn0xOxzvlNoVm9B7 dKLPBtMs43iUq3LlMZkcsIFwzQ66bYY= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-169-ArKHm3Z2PmS6awbwkkKByg-1; Mon, 24 Jul 2023 07:32:43 -0400 X-MC-Unique: ArKHm3Z2PmS6awbwkkKByg-1 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-316f39e3e89so2536815f8f.1 for ; Mon, 24 Jul 2023 04:32:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690198362; x=1690803162; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EXJhrkLdNOLUHGZbbc+F0hjfqb3hPCsrY6WTn8MVyN8=; b=PdjBJqV8xcHhM9ZY2Ig8xH0sEEH19bQy0zpdv++3Rfz6vRbXF+rWTWHVkhk9WYWcIC NdMZz9CwOHgEl4ajMP50MBzntu0pOUTRyJN81o0Zed9A3qtqo/OmhtzjfC5efuaHM9Ld cIngVo+DLkTsJFWsfWGx/+nQz1eMH3bEo7kUnFJraOqC20mdsjZUUjI4pdktNqErHUDi t/VrbuGwaQkCT40tn2ac0g52JIKNAuacOXrK59c31+Yn5+SYyQwQMPAzGsErdTjr6KO4 AlE7hGNnJ1x+Y5+M8bfCrWMKWcqcgBnegT6/cLE1TfEOjXJkKBmD/Csa8XIpuYx3BAvO j5UA== X-Gm-Message-State: ABy/qLYY2TyIPDrdefblbAgYT8QFGwwr6vRHKHdByNJC8aSLdoOs3A94 Q9tW0WqW8EBfcQniRaO2+ogdfgf0annsNHiUiGwGoXtDiiO7FI6Qjs5U1dPTf6UQNTGD+YiB0qW +bGnx/BJ2T2mcFFxh3aG9NMDy X-Received: by 2002:a5d:4ec5:0:b0:314:98f:2495 with SMTP id s5-20020a5d4ec5000000b00314098f2495mr7489853wrv.12.1690198362015; Mon, 24 Jul 2023 04:32:42 -0700 (PDT) X-Received: by 2002:a5d:4ec5:0:b0:314:98f:2495 with SMTP id s5-20020a5d4ec5000000b00314098f2495mr7489803wrv.12.1690198361680; Mon, 24 Jul 2023 04:32:41 -0700 (PDT) Received: from vschneid.remote.csb ([149.12.7.81]) by smtp.gmail.com with ESMTPSA id w7-20020a5d4047000000b00313f61889ecsm12615302wrp.66.2023.07.24.04.32.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Jul 2023 04:32:41 -0700 (PDT) From: Valentin Schneider To: Nadav Amit Cc: Linux Kernel Mailing List , "linux-trace-kernel@vger.kernel.org" , "linux-doc@vger.kernel.org" , "kvm@vger.kernel.org" , linux-mm , bpf , the arch/x86 maintainers , "rcu@vger.kernel.org" , "linux-kselftest@vger.kernel.org" , Steven Rostedt , Masami Hiramatsu , Jonathan Corbet , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Paolo Bonzini , Wanpeng Li , Vitaly Kuznetsov , Andy Lutomirski , Peter Zijlstra , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Josh Poimboeuf , Jason Baron , Kees Cook , Sami Tolvanen , Ard Biesheuvel , Nicholas Piggin , Juerg Haefliger , Nicolas Saenz Julienne , "Kirill A. Shutemov" , Dan Carpenter , Chuang Wang , Yang Jihong , Petr Mladek , "Jason A. Donenfeld" , Song Liu , Julian Pidancet , Tom Lendacky , Dionna Glaze , Thomas =?utf-8?Q?Wei=C3=9Fschuh?= , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Yair Podemsky Subject: Re: [RFC PATCH v2 20/20] x86/mm, mm/vmalloc: Defer flush_tlb_kernel_range() targeting NOHZ_FULL CPUs In-Reply-To: <188AEA79-10E6-4DFF-86F4-FE624FD1880F@vmware.com> References: <20230720163056.2564824-1-vschneid@redhat.com> <20230720163056.2564824-21-vschneid@redhat.com> <188AEA79-10E6-4DFF-86F4-FE624FD1880F@vmware.com> Date: Mon, 24 Jul 2023 12:32:38 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE 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 On 21/07/23 18:15, Nadav Amit wrote: >> On Jul 20, 2023, at 9:30 AM, Valentin Schneider wr= ote: >> >> vunmap()'s issued from housekeeping CPUs are a relatively common source = of >> interference for isolated NOHZ_FULL CPUs, as they are hit by the >> flush_tlb_kernel_range() IPIs. >> >> Given that CPUs executing in userspace do not access data in the vmalloc >> range, these IPIs could be deferred until their next kernel entry. > > So I think there are a few assumptions here that it seems suitable to con= firm > and acknowledge the major one in the commit log (assuming they hold). > > There is an assumption that VMAP page-tables are not freed. I actually > never paid attention to that, but skimming the code it does seem so. To > clarify the issue: if page-tables were freed and their pages were reused, > there would be a problem that page-walk caches for instance would be used > and =E2=80=9Cjunk=E2=80=9D entries from the reused pages would be used. S= ee [1]. > Thanks for looking into this and sharing context. This is an area I don't have much experience with, so help is much appreciated! Indeed, accessing addresses that should be impacted by a TLB flush *before* executing the deferred flush is an issue. Deferring sync_core() for instruction patching is a similar problem - it's all in the shape of "access @addr impacted by @operation during kernel entry, before actually executing @operation". AFAICT the only reasonable way to go about the deferral is to prove that no such access happens before the deferred @operation is done. We got to prove that for sync_core() deferral, cf. PATCH 18. I'd like to reason about it for deferring vunmap TLB flushes: What addresses in VMAP range, other than the stack, can early entry code access? Yes, the ranges can be checked at runtime, but is there any chance of figuring this out e.g. at build-time? > I would also assume the memory-hot-unplug of some sorts is not an issue, > (i.e., you cannot have a stale TLB entry pointing to memory that was > unplugged). > > I also think that there might be speculative code execution using stale > TLB entries that would point to memory that has been reused and perhaps > controllable by the user. If somehow the CPU/OS is tricked to use the > stale executable TLB entries early enough on kernel entry that might be > an issue. I guess it is probably theoretical issue, but it would be helpf= ul > to confirm. > > In general, deferring TLB flushes can be done safely. This patch, I think, > takes it one step forward and allows the reuse of the memory before the T= LB > flush is actually done. This is more dangerous. > > [1] https://lore.kernel.org/lkml/tip-b956575bed91ecfb136a8300742ecbbf4514= 71ab@git.kernel.org/