Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1242450lfc; Wed, 1 Jun 2022 12:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJznU0yVXLHBreqsyluoMv2l6lmNrgj82/4N+zxB5EsMR1Ppxy2GeK/bQNfeEXZxHitxgrOd X-Received: by 2002:a62:c5c3:0:b0:51b:a11c:201f with SMTP id j186-20020a62c5c3000000b0051ba11c201fmr1147815pfg.71.1654113071071; Wed, 01 Jun 2022 12:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654113071; cv=none; d=google.com; s=arc-20160816; b=jiO0xn+Q0UGlEOpABVQC7X9zdQYoT7dT/avqrDj4OS160sSetWHbGRGFg5Db25kZOD +e74BMVq1fa6eeA5+8VlJYxKJsLhzbh2Az/Ko5Byf9FLKJ4Oiak7UEgDAol0uOGN2kRN N6w73/0DEK1MpPJOc3cOvXhdwC+EEAWKCidVy5jA15ZnfQQfkI42hyUl+doYOEw9lxXN Q+5y1Q2t6yt0veDKyEdwVWtEkRS05Rz1rqp1o3728l22ApRzFHETMyeRjh/wOzgrwmpn fZ6HNTBxhNgke+zibRUz+/ZcklNTQMetEC8tXl0KtM2dtCNQfAEmAljAIsgoMk5z/W9a 6q3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=FhsHeS2sasXxgthG1EVyqOnKYpRF9QRdFVG7EiWgSPc=; b=pMg+wJazgM5oE/zbZYNd7pgOhtOitNqTktmoY9+XXlrGI8YahEefZ484OPsawyqgHK YzlIo5VDDsO5og0x4voeNkQGrbgzZOSF+AZQBLgxHY3iTg9c90hWbkbzr7NCElyNVl1X Vxu1jV7tweC1EUy9TygOGN1HfXLrmhIdbfiRTuNJCxeCBdq6+rLwm66XsLuTR4pgDCKU zoBl/cnvS7ocfAHLevVxSVwvElU4ffk4AffNn4jGc1TdcXkZEblzVt+ZoUqvplaFNT9G UjYVYO6XUFanxv3WbK43BsGnOMOU+jqLxLYWuVC1ZESFEX5iU3wFrJ0ohxdFnz0KSpne zJXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vP8RRYZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x82-20020a633155000000b003995a4f48c4si3453861pgx.377.2022.06.01.12.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:51:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vP8RRYZ3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A03141F6B63; Wed, 1 Jun 2022 12:13:30 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345230AbiEaOXp (ORCPT + 99 others); Tue, 31 May 2022 10:23:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345218AbiEaOXl (ORCPT ); Tue, 31 May 2022 10:23:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F8F7C174 for ; Tue, 31 May 2022 07:23:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5CEB9612FB for ; Tue, 31 May 2022 14:23:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 622ADC3411D; Tue, 31 May 2022 14:23:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1654007018; bh=3uDJRMnzzkW1jtjk1n7EQ8ObZJ85Vi7lUATGso0uNF4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=vP8RRYZ3y30ALTNdCEkm+3VDVsur8xxSUZ/6Pn5NadYKSgyZD98jwvQeU3yHdCikI eBuTt1Fr5FwqoWMuS2d0Ib+dT382cv3Xzuc9LC61T2isr3EKlsQOwKRXEIznLQyLDo UK6l3E+79kAQ5J6TWeWKQ4nVvVxkR6tzRJKw4n/NXDa6f0Pq6S5xJVRtqhGHgT0WMD 742UOnfk8s0rR0vPcepuHXvS+BUoXmwJm1rvYoQSKRhvkJRNjTLDMSXGTofGZ30gu8 sGVzxgkZxYYKrNywTr5zhzZfHuxKVCNGJpEXhOze9/SoJeJn2aq+sPM6Rp8xhfatUm QZrMPs+a8OAdg== Date: Tue, 31 May 2022 16:23:35 +0200 From: Frederic Weisbecker To: nicolas saenz julienne Cc: LKML , Peter Zijlstra , Phil Auld , Alex Belits , Xiongfeng Wang , Neeraj Upadhyay , Thomas Gleixner , Yu Liao , Boqun Feng , "Paul E . McKenney" , Marcelo Tosatti , Paul Gortmaker , Uladzislau Rezki , Joel Fernandes , Mark Rutland Subject: Re: [PATCH 20/21] rcu/context_tracking: Merge dynticks counter and context tracking states Message-ID: <20220531142335.GA1272449@lothringen> References: <20220519145823.618983-1-frederic@kernel.org> <20220519145823.618983-21-frederic@kernel.org> <315b0b80f7f541b99a49a9fecb743874f31d95ba.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <315b0b80f7f541b99a49a9fecb743874f31d95ba.camel@kernel.org> X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_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 Mon, May 30, 2022 at 08:02:57PM +0200, nicolas saenz julienne wrote: > Hi Frederic, > > On Thu, 2022-05-19 at 16:58 +0200, Frederic Weisbecker wrote: > > Updating the context tracking state and the RCU dynticks counter > > atomically in a single operation is a first step towards improving CPU > > isolation. This makes the context tracking state updates fully ordered > > and therefore allow for later enhancements such as postponing some work > > while a task is running isolated in userspace until it ever comes back > > to the kernel. > > > > The state field becomes divided in two parts: > > > > 1) Two Lower bits for context tracking state: > > > > CONTEXT_KERNEL = 0 > > CONTEXT_IDLE = 1, > > CONTEXT_USER = 2, > > CONTEXT_GUEST = 3, > > > > 2) Higher bits for RCU eqs dynticks counting: > > > > RCU_DYNTICKS_IDX = 4 > > > > The dynticks counting is always incremented by this value. > > (state & RCU_DYNTICKS_IDX) means we are NOT in an extended quiescent > > state. This makes the chance for a collision more likely between two > > RCU dynticks snapshots but wrapping up 28 bits of eqs dynticks > > increments still takes some bad luck (also rdp.dynticks_snap could be > > converted from int to long?) > > > > Some RCU eqs functions have been renamed to better reflect their broader > > scope that now include context tracking state. > > > > Signed-off-by: Frederic Weisbecker > > Cc: Paul E. McKenney > > Cc: Peter Zijlstra > > Cc: Thomas Gleixner > > Cc: Neeraj Upadhyay > > Cc: Uladzislau Rezki > > Cc: Joel Fernandes > > Cc: Boqun Feng > > Cc: Nicolas Saenz Julienne > > Cc: Marcelo Tosatti > > Cc: Xiongfeng Wang > > Cc: Yu Liao > > Cc: Phil Auld > > Cc: Paul Gortmaker > > Cc: Alex Belits > > --- > > While working on a feature on top of this series (IPI deferral stuff) I believe > I've found a discrepancy on how context state is being updated: > > - When servicing an IRQ from user-space, we increment dynticks, and clear the > ct state to show we're in-kernel. > > - When servicing an IRQ from idle/guest or an NMI from any context we only > increment the dynticks counter. The ct state remains unchanged. Hmm, an IRQ from userspace does: ct_user_enter() //run in user //-----IRQ ct_user_exit() ct_irq_enter() ct_irq_exit() ct_user_enter() //run in user An IRQ from guest does: for (;;) { context_tracking_guest_enter() //vmrun //IRQ pending #VMEXIT context_tracking_guest_exit() local_irq_enable() ct_irq_enter() ct_irq_exit() local_irq_disable() } (although I see there is an "sti" right before "vmrun" so it looks possible to have ct_irq_enter() after context_tracking_guest_enter() if a host IRQ fires between the sti and the vmrun though I might be missing some kvm subtelty). An IRQ from idle does just: ct_idle_enter() //IRQ ct_irq_enter() ct_irq_exit() ct_idle_exit() So guest looks mostly ok to me (except for the little sti before vmrun for which I have a doubt). But idle at least is an exception and CONTEXT_IDLE will remain during the interrupt handling. It's not that trivial to handle the idle case because ct_irq_exit() needs to know that it is called between ct_idle_enter() and ct_idle_exit(). Thanks.