From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 64C85C0015E for ; Thu, 6 Jul 2023 11:30:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE5F08D0005; Thu, 6 Jul 2023 07:30:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EBD238D0001; Thu, 6 Jul 2023 07:30:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D85108D0005; Thu, 6 Jul 2023 07:30:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C9F148D0001 for ; Thu, 6 Jul 2023 07:30:57 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 9193AA052F for ; Thu, 6 Jul 2023 11:30:57 +0000 (UTC) X-FDA: 80980970154.14.04438D3 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 36E2A20013 for ; Thu, 6 Jul 2023 11:30:55 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KCQpclfj; spf=pass (imf03.hostedemail.com: domain of vschneid@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1688643055; h=from:from:sender: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:dkim-signature; bh=GGfRdlkJ3HdO+/y60WijuGvRZhKQFtZj0a8vHJ3Z9W0=; b=r9uf6cqzj6MZWejwX8zWV+2eF+T0zSI68V1T3sYt/ZyUCNuZFqKGVPYBoK24/FJzkL9UQL oceC2LSE2OHGRv8erdzzCzeKx/3uNTt7wAC0Mn6KXHcSWB+grt5wrm+iHHmqBeNwv+rft5 3HIVXefzGRcc57CYKp7pO+pLKsvtKSg= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KCQpclfj; spf=pass (imf03.hostedemail.com: domain of vschneid@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=vschneid@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1688643055; a=rsa-sha256; cv=none; b=NDct9bKCH97n9WBml9reFpNS6W4aPTeyyse4fUrdqePKNUJY877+Lh1czkIwuz5az82Oz3 FPmY3wybIH8Wegg/34nJv4uHZEPGLzorZQjLTF7sX/eckfxnGoAg78vAPFT0sCwmGtpfIr 6OeshHCFgevA0NGwZKfxxjyCTd7TgjA= 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=GGfRdlkJ3HdO+/y60WijuGvRZhKQFtZj0a8vHJ3Z9W0=; b=KCQpclfjjjkkgCLNbV2iEID1Om1+KeX3KSmSnzxVscaxUsxHZf6v9uZT95+3uL0ShkzcqP IboNIQ69plnlNfFJbjFiXm/NbKM08JtkSQolZ7iYV8kVHnZHzjr9nZ8A8qEQg1u/2Xsn78 xnAJOVC1I2kOdE3Hc8gQUKmi/vTwmwU= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-179-daJLdgoFMA2uxi02Vc9nSQ-1; Thu, 06 Jul 2023 07:30:53 -0400 X-MC-Unique: daJLdgoFMA2uxi02Vc9nSQ-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-635d9e482f1so8380436d6.1 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=SRTCfdFQZv/ZhpmJfRzcLx7tqgpIUD+GLYOLw2EhnY3n/GyeoCq5GpNrG9AsJZ91oC YdVXzTVf45KUe4MiPS5EmZ5+Nl2ZlhxlWEjPEkGKirMumzguFvAJnivF48knEliSrVh6 qyPCXsa93X3rjO6Z4Zmx1WGxoHaJhuGMKTlBoCLHnsV65UzA0WnhvmFRlmY+bswuLYe4 xciDpr4c6ZPbYsPoP/UK9dyJfullmVLFd7tvMSPmNRz5Py2xYJI+vMNLRcIbgm8wgQ4b uqUJEIPv/1SaaSp2bAvDDkypPH4APUrqS5K16tpm7IPwCH5Fgrn/YAFPpLEFrgNg+3/I HMkg== X-Gm-Message-State: ABy/qLZouXtyEHDpqnH60jV0/xpq+8OEqYq2XboDh0cdasGnEuT12V+a TMLoMC3VA1rFtYxQ77EXZRDWuCl4ZDnaR9FAb6JLFQil8uL5DWOfgaeBBSDECU6eI2puuKzyCVz xA8lnAjc2da8= X-Received: by 2002:a0c:f549:0:b0:62f:effe:3dca with SMTP id p9-20020a0cf549000000b0062feffe3dcamr1420111qvm.2.1688643053026; Thu, 06 Jul 2023 04:30:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlEbUYOJppwMgQvsEvMakiRmaJatTD8CbvHxxx1dIrR+0X5zWXHf8RNpRxDwVdgtv2CCKKsXFA== 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 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 36E2A20013 X-Rspam-User: X-Stat-Signature: ubh8nkbase7qskwk8txytnef76cfnmwp X-Rspamd-Server: rspam01 X-HE-Tag: 1688643055-339020 X-HE-Meta: U2FsdGVkX1978AkIecKyE01VgLv4wN7gsGLHCQeTtJq7efVjDr26+Xc9hxjB4dz4jjeRN4Ae+eIyosO2WvuS4fDeoPtoxawwfn5E0z9NWsJwLPZAzu+Kbgu8iLB0uFpKOFcz03sf3fK02stq6wMnbeHNKiheGk7xACLkHSytR1xOA5BrVeO4kW1eXZhb2h4mXBJosqBCdwLhbVuWWaLPbvlwiiJF6wTI4rnVdv6BBTkWpdW8lJTRpZRHaSwoMpgf+1X+HLtEf0bhxGRJgJ1Xx2D7C2QYcPtoUuAyWddZlyAFZtWDctGciLtIKx8W47hbQ+3aGBa5g8vbExbzxA9+eOO2j4Xh+g2Tk0MQuQWWFXmkyyuXWwhXKXSkI4I/GXOh0e02OLUyIfUX/+/rDNVGRsOQPV7roY++k1DDIn8vytYOzzqENX6ZnxAvw+3VKSt1Nfkcx+0G8aEKk4da3XbZFAu/g7ydlT937bMGDVrQDji5jte8TBEJPwPuV+0kGiRMPVA4Oa1a3ybFnhwOHwstyUiZYtQYKfrWVKDtztCQmYTTLz3blnXmgKO8bdCcw8PdpMVeE5yR9aSNuNDa0uDEoXiz/4jE//uhF6zM0GsLDmQPR0EoMBsMByafikvOsqwAcpLUOE79g0gIz0K570p8gcNSyX0Ayc5ixB+DMndp7gdc01ZEb5vxg/WaLkG7n47LXZ4UFUOmNSP0eYv1NiWMAk8yQYkzrNUZy2hhb5/nKTiqrHU1x/phLFU14V2PfmZXCmSLHCoHmgHSu+QpxGOHWcjwpUyPhFTHX7CuF0dKOlw26HXQIADexm8GcN59GPMWtlt4/g5uy/Fdx86uNQ9RmQYT3eXlKhnBo43pHegMUAGrbL0N1H4mFcBJTTyjkz7TdHN2HG2uyIx05QCpjgft6kBdXQDVNJr15g+Kx1UxWsqO0xbb+aLuaKdTfcN2jaUAq7FiOYMzNH2ZkgiZ7Ig lQlnOoz0 rG5jSN4KGIfuAwriS/Y2BQWZKiVcDIh1/aBsWBeGd0h6myKyky69tMNrc2MHZRJceHhojTihYwiHPibm8MRlPQinFPuwGABdIbENq3nHX+sQIUZEe2y3ShXyegaDQv+Dng1C30bx+sydyP+hjDiHIQF5t+3CoZSlk9oigdUVbYXyeM9K4FaqJY87wfYQpobARsnldcuwUTsRNmmH0J+JT9g1BlJ8l4xO+7ppyJNjbRZ5PE6c7U1Ea7berA6atRhBHSOCAPckYHZlVYuFfj6gvrIkt92xmqXqx7PAYGHadnyehOSiiVX4llzYrW6x1kLLTJc+y7rtI0pZuzx0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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) >> +{ >> +=09struct context_tracking *ct =3D per_cpu_ptr(&context_tracking, cpu); >> +=09unsigned int old_work; >> +=09bool ret =3D false; >> + >> +=09preempt_disable(); >> + >> +=09old_work =3D atomic_read(&ct->work); >> +=09/* >> +=09 * Try setting the work until either >> +=09 * - the target CPU no longer accepts any more deferred work >> +=09 * - the work has been set >> +=09 */ >> +=09while (!(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. >> +=09=09ret =3D atomic_try_cmpxchg(&ct->work, &old_work, old_work | work)= ; >> + >> +=09preempt_enable(); >> +=09return ret; >> +} > [...] >> @@ -100,14 +158,19 @@ static noinstr void ct_kernel_exit_state(int offse= t) >> */ >> static noinstr void ct_kernel_enter_state(int offset) >> { >> +=09struct context_tracking *ct =3D this_cpu_ptr(&context_tracking); >> int seq; >> +=09unsigned int work; >> >> +=09work =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?