Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30376557rwd; Thu, 6 Jul 2023 05:11:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlFxUepn55eNeQqU6P71CClKTBMjlhg06sXJ7KKDD1sBzu9QSNPTvaAKROKpZgYJWkwT22VM X-Received: by 2002:a05:6870:390e:b0:1b3:862f:a88 with SMTP id b14-20020a056870390e00b001b3862f0a88mr1977511oap.42.1688645495927; Thu, 06 Jul 2023 05:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688645495; cv=none; d=google.com; s=arc-20160816; b=RBRlYy9ffIB77l2Oyi+0xk5R+l7bQ0OzCnmiftOEMKpsAxnTKHkwbEY8MxhXd9F8yh 65HGKl/bcxIVLn/RGxXf4SFfrrGnNl1p7/prAuDGfOJEXmr6rZe8d1lT4DyT9UV+LB2G elgKzSinN64+EJP9bcyKNSctEqoEz3L56RiM3zblC1y+SRIvh+GLyGy6nMYx/z9WY/QJ 0E8Oykd9GJDSYgqoQLp1N2HTlqrs6Of4rRoQXTKWW3c4f4/PUZF3V7uAcw6M9BYhS4T5 UCMmYNLa0HguRCfXKOUSZCW3Q2JLq59kXz5vyyRtdVFYk0RtLdWfrkQWfiG2p+lF8oDd sZ1Q== 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=RinQDlUt4K38HkHxLwhOYs8pH7N2WJkW7Jmb1TL6X3c=; fh=uB6QRJGC0r0aM8goVOXH3pVN/cldAQUSXdUWIIMFuJA=; b=qT95o0/m/pGsquvUH3j5B9tkIM2W4qhpPEXsICHOr66sNZYge6a9zO45YvdZ0MD5M0 kuwj8+Ca+obqMJ6NUy7qafQ/GShR+HKJqS57I+ZhBmq9g1Y9NuCvutFZCyq6FPb8mlaS SycHLsST1To/Nj0GADpck1ZFcAolI/LJxteXTWdehYqbIi3ECyv/e6T171cGgShUIz0l hrV2yWsR6yMi7f0PP50plbwhF2J+v6cbw3ChYKFF4eaKTe3ID+d2PPRoBo5WHVZXJMND boLkRZlRx3b5gYEA9CbHBGcK75DZNrBqC10StEZyDcap+Lk1IEb9q3FK0N9pPzCCvYeZ gpow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=daTvktUa; 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 kk13-20020a17090b4a0d00b002636b31935asi1554049pjb.120.2023.07.06.05.11.23; Thu, 06 Jul 2023 05:11:35 -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=daTvktUa; 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 S232350AbjGFLbn (ORCPT + 99 others); Thu, 6 Jul 2023 07:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232307AbjGFLbk (ORCPT ); Thu, 6 Jul 2023 07:31:40 -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 58A451727 for ; Thu, 6 Jul 2023 04:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688643054; 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=RinQDlUt4K38HkHxLwhOYs8pH7N2WJkW7Jmb1TL6X3c=; b=daTvktUaUzkWhbkD74TdmxfhS7MLdiT1fLQebvHYuPuzjzWasKJY3Bgpv3lQ9vaW1xw99N gaaLdnmaEtr/f2W2kDch6azmuS0d+OMR4z+BKiC4sb2bDykScGImi2Z/FdFNGCuq/N9WiT pSriEbyW5C8dZ/lrqdlntiEPogvcgIk= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-649-fLz_LYVrNB-GMIF0tX_uKA-1; Thu, 06 Jul 2023 07:30:53 -0400 X-MC-Unique: fLz_LYVrNB-GMIF0tX_uKA-1 Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-635e0889cc5so8318196d6.2 for ; Thu, 06 Jul 2023 04:30:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688643053; x=1691235053; 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=RinQDlUt4K38HkHxLwhOYs8pH7N2WJkW7Jmb1TL6X3c=; b=Zk28a1SMTQsbVU4/jTdpMps5Qva/xftjD5WsdxGgiFfgli1i5iGwCtvRCGqJPFR+cs iZ8aUl3BkbXRC4jrlyEwLHedQiw1dFgxoo0kVE3uIrHx1OXNM5EEehF2PBNQRsU9ayMO P1pq+N2vw+j8q1fgsoDD2h16YQf+A83NzCjFFiaACtD1fLxdEX3D8sB1fNZHmHky6/mF AeNXnckVpmgZeCmm7N7wQsDwVuLD01Dd39Hc9+4C8jKrn76tjZBYFjfro5Jtfxqjn4sh 0b+KGQQZteE8FVXPzb3bEe/65aqCeaqxI7oeXK5mdiGwiggYQy0ACPwP1NMAH9uuEtVt 1zeg== X-Gm-Message-State: ABy/qLZmxJqEwbp49aW6qc1Ab/sTBDohv2o6rwh6w/A1olibfDaHF6lg 7W1cxA3Or4spi11LzAC6GlkpiFmyFUZymFMeDHR5KhrovogBVcMesxdg8mFrQHoPoGS4cIS8yeU rcOM9QYmEiJUj8Rvlzgjxzc6P X-Received: by 2002:a0c:f549:0:b0:62f:effe:3dca with SMTP id p9-20020a0cf549000000b0062feffe3dcamr1420108qvm.2.1688643053024; Thu, 06 Jul 2023 04:30:53 -0700 (PDT) X-Received: by 2002:a0c:f549:0:b0:62f:effe:3dca with SMTP id p9-20020a0cf549000000b0062feffe3dcamr1420051qvm.2.1688643052762; Thu, 06 Jul 2023 04:30:52 -0700 (PDT) Received: from vschneid.remote.csb ([154.57.232.159]) by smtp.gmail.com with ESMTPSA id a12-20020a0ce38c000000b0062de6537febsm769879qvl.58.2023.07.06.04.30.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jul 2023 04:30:52 -0700 (PDT) From: Valentin Schneider To: Frederic Weisbecker 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, 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 , Peter Zijlstra , "Paul E. McKenney" , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Josh Poimboeuf , 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 11/14] context-tracking: Introduce work deferral infrastructure In-Reply-To: References: <20230705181256.3539027-1-vschneid@redhat.com> <20230705181256.3539027-12-vschneid@redhat.com> Date: Thu, 06 Jul 2023 12:30:46 +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 06/07/23 00:23, Frederic Weisbecker wrote: > Le Wed, Jul 05, 2023 at 07:12:53PM +0100, Valentin Schneider a =C3=A9crit= : >> +bool ct_set_cpu_work(unsigned int cpu, unsigned int work) >> +{ >> + struct context_tracking *ct =3D per_cpu_ptr(&context_tracking, cpu); >> + unsigned int old_work; >> + bool ret =3D false; >> + >> + preempt_disable(); >> + >> + old_work =3D atomic_read(&ct->work); >> + /* >> + * Try setting the work until either >> + * - the target CPU no longer accepts any more deferred work >> + * - the work has been set >> + */ >> + while (!(old_work & CONTEXT_WORK_DISABLED) && !ret) > > Isn't there a race here where you may have missed a CPU that just entered= in > user and you eventually disturb it? > Yes, unfortunately. >> + ret =3D atomic_try_cmpxchg(&ct->work, &old_work, old_work | work); >> + >> + preempt_enable(); >> + return ret; >> +} > [...] >> @@ -100,14 +158,19 @@ static noinstr void ct_kernel_exit_state(int offse= t) >> */ >> static noinstr void ct_kernel_enter_state(int offset) >> { >> + struct context_tracking *ct =3D this_cpu_ptr(&context_tracking); >> int seq; >> + unsigned int work; >> >> + work =3D ct_work_fetch(ct); > > So this adds another fully ordered operation on user <-> kernel transitio= n. > How many such IPIs can we expect? > Despite having spent quite a lot of time on that question, I think I still only have a hunch. Poking around RHEL systems, I'd say 99% of the problematic IPIs are instruction patching and TLB flushes. Staring at the code, there's quite a lot of smp_calls for which it's hard to say whether the target CPUs can actually be isolated or not (e.g. the CPU comes from a cpumask shoved in a struct that was built using data from another struct of uncertain origins), but then again some of them don't need to hook into context_tracking. Long story short: I /think/ we can consider that number to be fairly small, but there could be more lurking in the shadows. > If this is just about a dozen, can we stuff them in the state like in the > following? We can potentially add more of them especially on 64 bits we c= ould > afford 30 different works, this is just shrinking the RCU extended quiesc= ent > state counter space. Worst case that can happen is that RCU misses 65535 > idle/user <-> kernel transitions and delays a grace period... > I'm trying to grok how this impacts RCU, IIUC most of RCU mostly cares abou= t the even/odd-ness of the thing, and rcu_gp_fqs() cares about the actual value but only to check if it has changed over time (rcu_dynticks_in_eqs_since() only does a !=3D). I'm rephrasing here to make sure I get it - is it then that the worst case here is 2^(dynticks_counter_size) transitions happen between saving the dynticks snapshot and checking it again, so RCU waits some more?