From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E845B1DF989 for ; Mon, 20 Jan 2025 16:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737389383; cv=none; b=YTcHPIsllDKl4Uqt0rxO3WWCvD3UxIep1o/2ww9JCcb0drFsstHfzdq4cMvCBjZg0kzO6Vt+CVDIHKHFWPZR9VVFaY5x22G6jqBKBGRsk6qLmA50+RZTCf4sc+ET9VrPRMaS2ioVgwxJEDWyYbMaoJE9WB9L6AoA8eBMHunhYh4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737389383; c=relaxed/simple; bh=uPYF3/ytKmNcBW6xY8UN6OXUapKiaxgyBXzq3dB0L9c=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=g5fPA9DJxYg1kpjhZnh9k0jrmW5ccOaILjvMPEoKmhDGcceObbNz79Bgr/+zjmsCTZFFEqpm1hFrLnoJ/ARaj+HEsfDyshbRHuq63+FVfvvjpaZ/P6/yh0bsZGGO9tBPmb0cbx+fzJloZeTp3OgameEwdtchbY3uROETV4cHHFw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HstRS4Sd; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HstRS4Sd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737389381; 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=uPYF3/ytKmNcBW6xY8UN6OXUapKiaxgyBXzq3dB0L9c=; b=HstRS4SdHmeIjSH5U/eUEw2AJHZh9YwaKlG9B4qZWAR4B4GUnDKvKYsoGevwW28NQfg2h6 JL9aH3JFmtnBjYVWnCwv+rQ49T+GIX/2LVV5P60tIeSQ7Q6STReYZ0g5Vg4NhPo5cThxyi YK86tq+1QcuwVBot2cQ9hD/PxSrYX6U= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-638-hWlfj-gqOZGD31mM1iEuXw-1; Mon, 20 Jan 2025 11:09:39 -0500 X-MC-Unique: hWlfj-gqOZGD31mM1iEuXw-1 X-Mimecast-MFC-AGG-ID: hWlfj-gqOZGD31mM1iEuXw Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-385e3cbf308so2001048f8f.2 for ; Mon, 20 Jan 2025 08:09:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737389378; x=1737994178; 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=uPYF3/ytKmNcBW6xY8UN6OXUapKiaxgyBXzq3dB0L9c=; b=ENDiTp8dphlMxvSDGEIVi8NfLdhM/0PkSRiAWB1kMsIQdARso0k8614624E+Ji0g2l 8Fi7C7lC+mCCoh0GNgYcMRsG0YnmZ4GAN75ZY/Lk0dQIdt9RmKvenQEjcUJk9luLVjGj isIi8EYh9sneCMjbWHImmh6Hx/FSrD0EfB23slkRTyY+et0iUqO4JqnuymtT9afGzxdU zBe3m3Nw5Ramaxg8GxFsbJiTvO746WTly8BqkJz79NEJwKZrzTfykCasYycd//eQlNBM zRy7a0/oAFHjyjogTZxohf+dNzxESgMZIGBh+3m+iOOKN94HWDvBV2Rq3ygXcM2s0NdP vijQ== X-Forwarded-Encrypted: i=1; AJvYcCUXTnM3OCa28XK6jvi6lHiIr3r8MKqyZpIlKsk1p+lnQ6UfHVbBQxrf6QvHQpQ64TfgdRUJgBqIGfXeKb8=@vger.kernel.org X-Gm-Message-State: AOJu0YzhabJHWgJR0dtnyuvJ2K1oK+/1LaJw8aQKfe+0YFxZfj+DKEPG CzSzcj/jsr8kxAYsmsZV4GPrvtIZZFN3LdVfbsOVhrHHk82bLhW3TRio21EkSzIeN/BexbQIaPl sPdvoLXUWLwEXUnnbqtEFAt4CZ5+8EOmiba7QwM3DdGYBwWFRxwr6CY8zvpK4WA== X-Gm-Gg: ASbGncuCsBgo5XhS29WF7iprwv8YdvW91BnNCFiu78xooB7hN5m+t8qWQ46jQgpbQw2 rcebMbzfAubz+z8Ly8KzZI+4SAISUivd1xdURm+MG2lV3xYcEucJKpBiE2Ub9hXXaFUlqhhybNp 5fPfes7UmBA2X9w8VCYHStY1HwNQP7ZlNnP0IrW6uA+NgEaZRGN5mUpSbqC29DQ4ZnPaYHVVhnf artQQ55CXlsbPhPknwZXwyJmcJmPIlWlQEd3/apAsgVwaq1siYfATtxvzBFATycUQtKEri8LzJ0 a1PdOLOzaCU2fzNrey/4ewel90S6yWvn0BH+qudpkP4w6AAOlRUSHVw= X-Received: by 2002:adf:f682:0:b0:38b:e26d:ea0b with SMTP id ffacd0b85a97d-38bf566c314mr10592138f8f.25.1737389378238; Mon, 20 Jan 2025 08:09:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IE7jMmKmijGDhYJpj3v2AzDeWwh7lxfHaye7x+JEw9SklvyOVZq+Wb4Niy5wxwqRIeZEeA2rg== X-Received: by 2002:adf:f682:0:b0:38b:e26d:ea0b with SMTP id ffacd0b85a97d-38bf566c314mr10592030f8f.25.1737389377661; Mon, 20 Jan 2025 08:09:37 -0800 (PST) Received: from vschneid-thinkpadt14sgen2i.remote.csb (213-44-141-166.abo.bbox.fr. [213.44.141.166]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38bf3221b70sm10695813f8f.26.2025.01.20.08.09.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jan 2025 08:09:37 -0800 (PST) From: Valentin Schneider To: Uladzislau Rezki Cc: Uladzislau Rezki , Jann Horn , linux-kernel@vger.kernel.org, x86@kernel.org, virtualization@lists.linux.dev, linux-arm-kernel@lists.infradead.org, loongarch@lists.linux.dev, linux-riscv@lists.infradead.org, linux-perf-users@vger.kernel.org, xen-devel@lists.xenproject.org, kvm@vger.kernel.org, linux-arch@vger.kernel.org, rcu@vger.kernel.org, linux-hardening@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, bpf@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Juergen Gross , Ajay Kaher , Alexey Makhalov , Russell King , Catalin Marinas , Will Deacon , Huacai Chen , WANG Xuerui , Paul Walmsley , Palmer Dabbelt , Albert Ou , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , "Liang, Kan" , Boris Ostrovsky , Josh Poimboeuf , Pawan Gupta , Sean Christopherson , Paolo Bonzini , Andy Lutomirski , Arnd Bergmann , Frederic Weisbecker , "Paul E. McKenney" , Jason Baron , Steven Rostedt , Ard Biesheuvel , Neeraj Upadhyay , Joel Fernandes , Josh Triplett , Boqun Feng , Mathieu Desnoyers , Lai Jiangshan , Zqiang , Juri Lelli , Clark Williams , Yair Podemsky , Tomas Glozar , Vincent Guittot , Dietmar Eggemann , Ben Segall , Mel Gorman , Kees Cook , Andrew Morton , Christoph Hellwig , Shuah Khan , Sami Tolvanen , Miguel Ojeda , Alice Ryhl , "Mike Rapoport (Microsoft)" , Samuel Holland , Rong Xu , Nicolas Saenz Julienne , Geert Uytterhoeven , Yosry Ahmed , "Kirill A. Shutemov" , "Masami Hiramatsu (Google)" , Jinghao Jia , Luis Chamberlain , Randy Dunlap , Tiezhu Yang Subject: Re: [PATCH v4 29/30] x86/mm, mm/vmalloc: Defer flush_tlb_kernel_range() targeting NOHZ_FULL CPUs In-Reply-To: References: <20250114175143.81438-1-vschneid@redhat.com> <20250114175143.81438-30-vschneid@redhat.com> Date: Mon, 20 Jan 2025 17:09:34 +0100 Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 20/01/25 12:15, Uladzislau Rezki wrote: > On Fri, Jan 17, 2025 at 06:00:30PM +0100, Valentin Schneider wrote: >> On 17/01/25 17:11, Uladzislau Rezki wrote: >> > On Fri, Jan 17, 2025 at 04:25:45PM +0100, Valentin Schneider wrote: >> >> On 14/01/25 19:16, Jann Horn wrote: >> >> > On Tue, Jan 14, 2025 at 6:51=E2=80=AFPM Valentin Schneider wrote: >> >> >> vunmap()'s issued from housekeeping CPUs are a relatively common s= ource 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 v= malloc >> >> >> range, these IPIs could be deferred until their next kernel entry. >> >> >> >> >> >> Deferral vs early entry danger zone >> >> >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> >> >> >> >> >> This requires a guarantee that nothing in the vmalloc range can be= vunmap'd >> >> >> and then accessed in early entry code. >> >> > >> >> > In other words, it needs a guarantee that no vmalloc allocations th= at >> >> > have been created in the vmalloc region while the CPU was idle can >> >> > then be accessed during early entry, right? >> >> >> >> I'm not sure if that would be a problem (not an mm expert, please do >> >> correct me) - looking at vmap_pages_range(), flush_cache_vmap() isn't >> >> deferred anyway. >> >> >> >> So after vmapping something, I wouldn't expect isolated CPUs to have >> >> invalid TLB entries for the newly vmapped page. >> >> >> >> However, upon vunmap'ing something, the TLB flush is deferred, and th= us >> >> stale TLB entries can and will remain on isolated CPUs, up until they >> >> execute the deferred flush themselves (IOW for the entire duration of= the >> >> "danger zone"). >> >> >> >> Does that make sense? >> >> >> > Probably i am missing something and need to have a look at your patche= s, >> > but how do you guarantee that no-one map same are that you defer for T= LB >> > flushing? >> > >> >> That's the cool part: I don't :') >> > Indeed, sounds unsafe :) Then we just do not need to free areas. > >> For deferring instruction patching IPIs, I (well Josh really) managed to >> get instrumentation to back me up and catch any problematic area. >> >> I looked into getting something similar for vmalloc region access in >> .noinstr code, but I didn't get anywhere. I even tried using emulated >> watchpoints on QEMU to watch the whole vmalloc range, but that went about >> as well as you could expect. >> >> That left me with staring at code. AFAICT the only vmap'd thing that is >> accessed during early entry is the task stack (CONFIG_VMAP_STACK), which >> itself cannot be freed until the task exits - thus can't be subject to >> invalidation when a task is entering kernelspace. >> >> If you have any tracing/instrumentation suggestions, I'm all ears (eyes?= ). >> > As noted before, we defer flushing for vmalloc. We have a lazy-threshold > which can be exposed(if you need it) over sysfs for tuning. So, we can ad= d it. > In a CPU isolation / NOHZ_FULL context, isolated CPUs will be running a single userspace application that will never enter the kernel, unless forced to by some interference (e.g. IPI sent from a housekeeping CPU). Increasing the lazy threshold would unfortunately only delay the interference - housekeeping CPUs are free to run whatever, and so they will eventually cause the lazy threshold to be hit and IPI all the CPUs, including the isolated/NOHZ_FULL ones. I was thinking maybe we could subdivide the vmap space into two regions with their own thresholds, but a task may allocate/vmap stuff while on a HK CPU and be moved to an isolated CPU afterwards, and also I still don't have any strong guarantee about what accesses an isolated CPU can do in its early entry code :( > -- > Uladzislau Rezki