Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp4486294rwo; Tue, 25 Jul 2023 06:53:45 -0700 (PDT) X-Google-Smtp-Source: APBJJlHG3dzP4Bwwq9d/D+EKwpROLAv5e3ezp1ZhpDKP6d0kMlCaJXO8Sr53c44+QNQB4+fRVk7l X-Received: by 2002:a17:906:db:b0:99b:8c6f:f3af with SMTP id 27-20020a17090600db00b0099b8c6ff3afmr6668757eji.12.1690293225525; Tue, 25 Jul 2023 06:53:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690293225; cv=none; d=google.com; s=arc-20160816; b=QlSITJLufxziKiulwIFGRt8BBhex/Nn9VvRsHhVo7QRN/BSCsxIL8Zcb2mMDC7I9C7 6ChnqhvItxJxIB3xNxjTVZEpt1MIho4/nBREfuYPnNptDA5tulHwAYiFxspk2abViRTD gIH3vBbLmITZ6Ps4mr5ENEwteGjr71lDXGIc+Z97G3+CzFrw4HpBPto6YMo+IpW68GyZ L2hgba2IxSrmN0jkNFflS3g30XX7n0iiaVZj4Z28x6nVuBVtaTDKh6IGKZA1TLeeCOHP CvIx3JRd9EQYUmywWj8kOmZOlAN5TOxiiI9cNScsa25SyEOrmYipoX7oPJBr96qnrSx/ gZ2A== 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=YuHDDSh+hqntXfEBDTeZy9lkclJmyfPYzRYLt1ff+f8=; fh=U85wl6l7otKgk0T234HGgttG+3H1tNi6T98zmskZTJU=; b=E//fXZyONlt70kDwwHru24ngX3X6uMerD8ztRoYkuWbIZ9+pUsU2NQSmvHCyVU8T3B l69/XgoTWQCDMvLLoOge5PmGtu2j9VUu2y+BkcwDN9PgBVkQbYvL/C1C6Zs7crip7K5w NxUQPE9/mIEnvtumPCS07pHdpRMlw9biSm8wEwn03obEesVS8ALdTn4xGJohtEes+A9V QkdmL6/Sr9f2TeuRQpCtq7HMsEJGMkz9sgYQyrtKTl9x+CkYnNIYQEGYd4yL3p8ZiYIz tptty9WnoJT1jOnS6FNc0kwzZsV/z//luyi6R17AoDgmnWCFCYyH8mB/jSs6fSdlfKHH P6Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=D+Py+Dz7; 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 kt20-20020a170906aad400b00992f45c9341si8146421ejb.1016.2023.07.25.06.53.19; Tue, 25 Jul 2023 06:53: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=@redhat.com header.s=mimecast20190719 header.b=D+Py+Dz7; 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 S231217AbjGYNiO (ORCPT + 99 others); Tue, 25 Jul 2023 09:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231183AbjGYNiL (ORCPT ); Tue, 25 Jul 2023 09:38:11 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF2761FE6 for ; Tue, 25 Jul 2023 06:37:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1690292233; 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=YuHDDSh+hqntXfEBDTeZy9lkclJmyfPYzRYLt1ff+f8=; b=D+Py+Dz7QtVFbXp+d+7w+d4ly9UsAicqh8rLFTGaF2dMyGXOYCp0CcCF0WAg7PDCdy1afF +DbHSQtnNscCM6BczQZKFD+YXh7CWzjd7Fy9OoFCVprNCJgqb3oA2cRkBqtWpkOrPbC+tO 4vFw5xBJ5SDaHYNfo8sSACNMhmLSnoU= 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-146-_NnqUJvLOrCOcSRG-kBFWA-1; Tue, 25 Jul 2023 09:37:08 -0400 X-MC-Unique: _NnqUJvLOrCOcSRG-kBFWA-1 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-3142665f122so3270144f8f.0 for ; Tue, 25 Jul 2023 06:37:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292223; x=1690897023; 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=YuHDDSh+hqntXfEBDTeZy9lkclJmyfPYzRYLt1ff+f8=; b=Gwlh4stVXGYJj2oK3J2z6c+o9pDlGpt8MZ9+8MYRQpCrXVibIfmPQ+QpyiNyYUS6vI c3XACwlHsQKFTBsrtc652OYzJiIWXrHbkB8HbFS+T66/+B1PHiLEtAF+Qgh5XkI+Eoys 8A8emZUFSvDbOFfxFYp/Grgqc/Qvps3u1f0/LMIdVVaVgDYTpHGKJgd+c0NO84YGb5Co 1QnLL4fQPPY60xKMgJIcPtTg2GYaO3hWa8la0ccUaIybNrTAdRJr75BraGZFTS/6zuwi 1VqZI/yhgVEUp++XxaWu5iH31q1cJ5FVUTQt/f+hxrHsoBfYO/k6sD/0Dc93rlHM2Hnm Qy3g== X-Gm-Message-State: ABy/qLbP2rFHaRQWMzm5Fbvh8KMBHPtjYsze4yhKNhrwcgFAFYKOoKYU LOOSGlJask26m0YRPff0yYJ/XTG0HBm1aRzbHRwO0rNQzGHIorii8CeOx6FOqvm5i7Ux030GUTc wC8z1h+yCPboIlTpKoDjBy543 X-Received: by 2002:adf:edd1:0:b0:313:df09:ad04 with SMTP id v17-20020adfedd1000000b00313df09ad04mr11718257wro.57.1690292223005; Tue, 25 Jul 2023 06:37:03 -0700 (PDT) X-Received: by 2002:adf:edd1:0:b0:313:df09:ad04 with SMTP id v17-20020adfedd1000000b00313df09ad04mr11718201wro.57.1690292222669; Tue, 25 Jul 2023 06:37:02 -0700 (PDT) Received: from vschneid.remote.csb ([149.12.7.81]) by smtp.gmail.com with ESMTPSA id h3-20020a5d4fc3000000b00314329f7d8asm16390715wrw.29.2023.07.25.06.36.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:37:01 -0700 (PDT) From: Valentin Schneider To: Joel Fernandes Cc: 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, Peter Zijlstra , 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 , Thomas =?utf-8?Q?Wei=C3=9Fschuh?= , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Yair Podemsky Subject: Re: [RFC PATCH v2 18/20] context_tracking,x86: Defer kernel text patching IPIs In-Reply-To: <6EBAEEED-6F38-472D-BA31-9C61179EFA2F@joelfernandes.org> References: <20230720163056.2564824-19-vschneid@redhat.com> <6EBAEEED-6F38-472D-BA31-9C61179EFA2F@joelfernandes.org> Date: Tue, 25 Jul 2023 14:36:59 +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 25/07/23 06:49, Joel Fernandes wrote: > Interesting series Valentin. Some high-level question/comments on this on= e: > >> On Jul 20, 2023, at 12:34 PM, Valentin Schneider w= rote: >> >> =EF=BB=BFtext_poke_bp_batch() sends IPIs to all online CPUs to synchroni= ze >> them vs the newly patched instruction. CPUs that are executing in usersp= ace >> 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_pok= e? > How often does instruction patching really happen? If it is very infreque= nt > then I am not sure if it is that harmful. > Being pushed over a latency threshold *once* is enough to impact the latency evaluation of your given system/application. It's mainly about shielding the isolated, NOHZ_FULL CPUs from whatever the housekeeping CPUs may be up to (flipping static keys, loading kprobes, using ftrace...) - frequency of the interference isn't such a big part of the reasoning. >> >> As the synchronization IPIs are sent using a blocking call, returning fr= om >> 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? > The blocking call only waits for CPUs for which it queued a CSD. Deferred calls do not queue a CSD thus do not impact the waiting at all. See smp_call_function_many_cond().