Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4785651rwo; Tue, 25 Jul 2023 10:52:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlFxxH1SNj4Jr11mSAyxOKqngGgrbynVZMsev5irdeIuCe32pQ1abPo/9F9/A6O30GeVurlN X-Received: by 2002:a17:90b:84:b0:268:1795:8700 with SMTP id bb4-20020a17090b008400b0026817958700mr4481975pjb.32.1690307565263; Tue, 25 Jul 2023 10:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690307565; cv=none; d=google.com; s=arc-20160816; b=WaCX2g+eaizU1NZlcmNSvvNJCA27Ij2cth690zsT/lzcXNbtlqTF8VHOphoFxziq6t 91WCpZfjMG9rsOjenKzGPR5kbQB0jNFcpVvaT7gxDlCxu0kkmw7GU3B9U0Bo9IidfmGh bmy3+I3+kW5BQjvdQF8t356dNfDOzgz+GnipRBetr9dGp62qxF0K0mqIVZks5HQK3hkU lMCKhVKk9B82rQssFNnBIHV0USwfHJLnMGDrCFzGAd8ffKFjwcUbTWazOpcx42dPT8YW wX9i1F6TIFhaA2RmUPylH6bZNRmRpX0wiIahvuP7KDC8f/puj24rzxqZEp1QRvWIacc2 6Mlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=tjxGQ97jdZy+msttaE6/InGye12w/eRXu8aDXNaXRhA=; fh=BfNlnzR0q2uqOaNCMEJTXX7AUTrRDBF8ytd57g3kpPE=; b=j8blcP363xYZUTJUm4+qKf69Z63YwBmx36jnBvbAbpyBvh585fwqgG6Qcwarvx6GTl iGy/fA8viaEqNJdSq9CkskPTrYZZWy0j2qimJ2lfvIgTMM/+sdu4TYT5a9YjRF8VgRJ3 TP0pdqCejZPJaRtbBJRe6v5xl/nQRiiaL96WGGjUxnb/iIfJzOsvCKyTKIBad4kH715h ef/nhKePdjrO/f+JUJTNK+t1X5xBZ6zZCopLDY6oScXki/1UX1gARhMt2SnKf0X18aeM FHMB9bCoIj2JpTEalV03/2KN8AjII5N/tkwld8yiFQ1UoCLuBkz0QGc4EqSsi5DDJFLl R3iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=mJItfjJo; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k186-20020a6384c3000000b00563deb65f94si194219pgd.192.2023.07.25.10.52.08; Tue, 25 Jul 2023 10:52:45 -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=@joelfernandes.org header.s=google header.b=mJItfjJo; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231273AbjGYRrT (ORCPT + 99 others); Tue, 25 Jul 2023 13:47:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjGYRrP (ORCPT ); Tue, 25 Jul 2023 13:47:15 -0400 Received: from mail-ua1-x92d.google.com (mail-ua1-x92d.google.com [IPv6:2607:f8b0:4864:20::92d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA3701FDA for ; Tue, 25 Jul 2023 10:47:12 -0700 (PDT) Received: by mail-ua1-x92d.google.com with SMTP id a1e0cc1a2514c-79a2216a22fso775864241.0 for ; Tue, 25 Jul 2023 10:47:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; t=1690307232; x=1690912032; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=tjxGQ97jdZy+msttaE6/InGye12w/eRXu8aDXNaXRhA=; b=mJItfjJo0J8vq8ZI7eQRqgBugJTE/Qjls8F9j5zJT4/6drjQg4QRDl54H4s/m4+/B6 OdBZ9Wq1QAC//eamW92We5bVMlBhbiRysXzmrEde6b6WilxsOOxfPGb41E5gLvLxIRQd mG8WW9RKwkhn1rvhmTvmgDcKKzEniO9bQreDA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690307232; x=1690912032; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tjxGQ97jdZy+msttaE6/InGye12w/eRXu8aDXNaXRhA=; b=LpLGfWD5esN8uBUIBcXNWvU0jsX4HWFK6YOlcMgjKn4kCfxodlTheFPxSDIvKmlqwc rvSCTIKRnlgAYdnQpBX87HYyybx3mBCKdZj3SQUVZBnsL/mHDG/L8bmjmUSLVdY54Ezn t84H/NBrCup00JqOOG+K10xceXxQgCgkTkEoMZEpbDK3vzZoAuqrG4ogetdu+FFJYEAc FT6bDBB1QQhEEzOtkdXfDSc5/lHVq6Ku8s9wFzlpcg5B5ZVM+puUDaXWxlDLr9EZvZni 84MwZZfChPbG+phQ0KrO9mV/VDrevLfgS72fFOLMw9vQ1BDx0UHK40sltvprJ4+bCkH/ 9Plw== X-Gm-Message-State: ABy/qLYNYkkV6ebF9eTeJIR4h5nZPGKiGthuA3yNwjE17JF2UrphAenR VcGq0vDD4kn7rWxTYIaDJgXouA== X-Received: by 2002:a67:b106:0:b0:443:60d7:3925 with SMTP id w6-20020a67b106000000b0044360d73925mr5444114vsl.20.1690307231746; Tue, 25 Jul 2023 10:47:11 -0700 (PDT) Received: from [192.168.0.198] (c-98-249-43-138.hsd1.va.comcast.net. [98.249.43.138]) by smtp.gmail.com with ESMTPSA id c11-20020a0cf2cb000000b0063d1f967268sm404045qvm.111.2023.07.25.10.47.09 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Jul 2023 10:47:11 -0700 (PDT) Message-ID: Date: Tue, 25 Jul 2023 13:47:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: [RFC PATCH v2 18/20] context_tracking,x86: Defer kernel text patching IPIs Content-Language: en-US To: Peter Zijlstra Cc: Valentin Schneider , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-mm@kvack.org, bpf@vger.kernel.org, x86@kernel.org, rcu@vger.kernel.org, linux-kselftest@vger.kernel.org, Nicolas Saenz Julienne , 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 , Frederic Weisbecker , "Paul E. McKenney" , Neeraj Upadhyay , 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" , Nadav Amit , Dan Carpenter , Chuang Wang , Yang Jihong , Petr Mladek , "Jason A. Donenfeld" , Song Liu , Julian Pidancet , Tom Lendacky , Dionna Glaze , =?UTF-8?Q?Thomas_Wei=c3=9fschuh?= , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Yair Podemsky References: <20230720163056.2564824-19-vschneid@redhat.com> <6EBAEEED-6F38-472D-BA31-9C61179EFA2F@joelfernandes.org> <20230725133936.GM3765278@hirez.programming.kicks-ass.net> From: Joel Fernandes In-Reply-To: <20230725133936.GM3765278@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 7/25/23 09:39, Peter Zijlstra wrote: > On Tue, Jul 25, 2023 at 06:49:45AM -0400, Joel Fernandes wrote: >> Interesting series Valentin. Some high-level question/comments on this one: >> >>> On Jul 20, 2023, at 12:34 PM, Valentin Schneider wrote: >>> >>> text_poke_bp_batch() sends IPIs to all online CPUs to synchronize >>> them vs the newly patched instruction. CPUs that are executing in userspace >>> do not need this synchronization to happen immediately, and this is >>> actually harmful interference for NOHZ_FULL CPUs. >> >> Does the amount of harm not correspond to practical frequency of text_poke? >> How often does instruction patching really happen? If it is very infrequent >> then I am not sure if it is that harmful. > > Well, it can happen quite a bit, also from things people would not > typically 'expect' it. > > For instance, the moment you create the first per-task perf event we > frob some jump-labels (and again some second after the last one goes > away). > > The same for a bunch of runtime network configurations. Ok cool. I guess I still have memories of that old ARM device I had where modifications to kernel text was forbidden by hardware (was a security feature). That was making kprobes unusable... >>> As the synchronization IPIs are sent using a blocking call, returning from >>> text_poke_bp_batch() implies all CPUs will observe the patched >>> instruction(s), and this should be preserved even if the IPI is deferred. >>> In other words, to safely defer this synchronization, any kernel >>> instruction leading to the execution of the deferred instruction >>> sync (ct_work_flush()) must *not* be mutable (patchable) at runtime. >> >> If it is not infrequent, then are you handling the case where userland >> spends multiple seconds before entering the kernel, and all this while >> the blocking call waits? Perhaps in such situation you want the real IPI >> to be sent out instead of the deferred one? > > Please re-read what Valentin wrote -- nobody is waiting on anything. Makes sense. To be fair I received his email 3 minutes before yours ;-). But thank you both for clarifying! - Joel