Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp690173pxp; Wed, 9 Mar 2022 10:35:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxonv1+XsiIuGU5vnZfeGXZncFWX42Z31HY1bAakNqbqU4MeVHYFPudp6r5k3C8VnHB5hgX X-Received: by 2002:a17:907:6d9d:b0:6da:7d4c:287f with SMTP id sb29-20020a1709076d9d00b006da7d4c287fmr968713ejc.741.1646850923447; Wed, 09 Mar 2022 10:35:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646850923; cv=none; d=google.com; s=arc-20160816; b=cAEg/qwrZS5y1sR1dhpEGCG8+nDogYJ5aiyXuAJ5YuN6TEN6roZo45xGQJelTzyRGc EiHmYjFxvhWRDtn0TFNnm63NjqEwxbYwnfcinYIkQV4dvfpNQCJLjqY1FqxJggZ/nYa1 uTtOIK4hF5bCpZE9Lrk0M4F6QuoXN7nbuyg/Va+qGuAae5ByW31rZf4bhZ7q+0ncYGxB 5m6LQDz4tTb9N1xknVazvrGaeApD3DxQ0CqLZcxW4KoxKMaXER9BYUWQiVPzmUxqYCG0 x7RzANoEo1AAab6FH8PTRAVQfhA0uHa7GgXDEnB0s4a3YfG8drowfQbwkxsiKA5bwYsK K1PQ== 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 :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=syTwecBEygKuudfwQOVGf2DnhX/mY34+RgVI9pj30HY=; b=fHrFxH+iAW1UJGvLLWoV6p55vfZ29FGEI/CWPYyMWmu3e4QL+39m/r6VyVXXVnZ9L4 hH1nJiPRG3QRmEXWny9kiFFQ02QjoqzE9KR50ZhOZ+tPzgIvaXM9P8PO1puH7loxE724 +QW/kZb8sIEaOzG3YcVFTONyxB2xKIoUG1gYhVZqq3zc4u8eUDLZP/lGdPVtSjvTvGtX 2NQE2cYzAkW9m/hKq0Pg8qSEXxHhZBHvKqziAD8BzCfmn4+Q2WrJDvpfc9F/w336hTvR RKe+M+P8yYGZ3keBgeqA+iNbllgoHVP9+6u3ZMFbK8wF4cNgACuSR7VNmo79wyxUcYGZ 5rBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FmF5HKGD; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck5-20020a0564021c0500b0041614eca4e0si1663273edb.16.2022.03.09.10.34.55; Wed, 09 Mar 2022 10:35:23 -0800 (PST) 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=@kernel.org header.s=k20201202 header.b=FmF5HKGD; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236904AbiCIRTS (ORCPT + 99 others); Wed, 9 Mar 2022 12:19:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236943AbiCIRSw (ORCPT ); Wed, 9 Mar 2022 12:18:52 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFC52B16D7 for ; Wed, 9 Mar 2022 09:17:09 -0800 (PST) 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 8DFBC60BAF for ; Wed, 9 Mar 2022 17:17:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B04E6C340E8; Wed, 9 Mar 2022 17:17:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646846229; bh=9UoUCC1ls/L9HENnvFoU5WNKJ/fU0gxSo20kTRh/kRg=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=FmF5HKGDibvFxUWXY4N37EIGfNe8mbKNpXcqZPhgeApuR2/ua64JyIFltkVdzu+H6 DIKHFheeOvvRiYDHlbf/+POIDIN5HWsHi2HM/i5KAC2iPKjzbCoPqsLbkCRLycKy3D 7HgWKLj77eak/Ysb19QnW3YNfNxivUz24rJQoGEQL5rt/0mkf7E4/q0uTOABsV0T9s tsByc/5BPFcNQ+GCcXnn/Weq8xrT0Lkq5I9jcCx834bjsUfyGDvuvLpJtmA4tfwQoM n2fh+jMxjiTxKkUNA+FzjvxepoiC0qnJ336qFpeGbXOi+TIehFk5Bzs/lTVQr96aaP tddo2bKxTU7SQ== Message-ID: <23cbcd6a467c211f792ff54d50635cd6536c9dcc.camel@kernel.org> Subject: Re: [PATCH 16/19] context_tracking: Convert state to atomic_t From: nicolas saenz julienne To: Frederic Weisbecker , LKML Cc: 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 Date: Wed, 09 Mar 2022 18:17:02 +0100 In-Reply-To: <20220302154810.42308-17-frederic@kernel.org> References: <20220302154810.42308-1-frederic@kernel.org> <20220302154810.42308-17-frederic@kernel.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-1.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Wed, 2022-03-02 at 16:48 +0100, Frederic Weisbecker wrote: > Context tracking's state and dynticks counter are going to be merged > in a single field so that both updates can happen atomically and at the > same time. Prepare for that with converting the state into an atomic_t. > > 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 > --- > static __always_inline bool context_tracking_in_user(void) > { > - return __this_cpu_read(context_tracking.state) == CONTEXT_USER; > + return __ct_state() == CONTEXT_USER; > } I was wondering whether it'd make more sense to use ct_state() for extra safety vs preemption, but it turns out the function isn't being used at all. I figure it'd be better to remove it altogether and leave ct_state() as the goto function for this sort of checks. > #else > static inline bool context_tracking_in_user(void) { return false; } > diff --git a/kernel/context_tracking.c b/kernel/context_tracking.c > index de247e758767..69db43548768 100644 > --- a/kernel/context_tracking.c > +++ b/kernel/context_tracking.c > @@ -337,6 +337,7 @@ static __always_inline void context_tracking_recursion_exit(void) > */ > void noinstr __ct_user_enter(enum ctx_state state) > { > + struct context_tracking *ct = this_cpu_ptr(&context_tracking); I wonder if there is any value to having __ct_state() take 'struct context_tracking *ct' as an argument to avoid a redundant this_cpu_ptr()... > lockdep_assert_irqs_disabled(); > > /* Kernel threads aren't supposed to go to userspace */ > @@ -345,8 +346,8 @@ void noinstr __ct_user_enter(enum ctx_state state) > if (!context_tracking_recursion_enter()) > return; > > - if ( __this_cpu_read(context_tracking.state) != state) { > - if (__this_cpu_read(context_tracking.active)) { > + if (__ct_state() != state) { ...here (and in __ct_user_exit()). Regards, Nicolas