Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp30378936rwd; Thu, 6 Jul 2023 05:13:30 -0700 (PDT) X-Google-Smtp-Source: APBJJlH9iwJ2Qgqd1it5mzH9gHEUAXHbCgrODBdoXNy6xFSxQywlL6ehl5y5a7zB/ijI7Y0gqWhZ X-Received: by 2002:a05:6a20:12c3:b0:129:b68b:92d4 with SMTP id v3-20020a056a2012c300b00129b68b92d4mr7317363pzg.2.1688645610126; Thu, 06 Jul 2023 05:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688645610; cv=none; d=google.com; s=arc-20160816; b=SFibhSBbXryMuQEbgMCeAV9pbOUTRwNnbxis9xEFiVM7Z3ez3S85UjM29T3IobT7FP hB1PxwvVsPwer/v4nNVEsNVvixIJNlU9bYNFFPPXscQWdNmPMcCNIGEu+S52Kk5uiGva bHjVpKwHvsuGLTmv2gZRpKlrZQMydY+I1mNtBvgSbGw42FCu9rpwSVvbPSbjk7ZNMQg2 Jx+duuyW3OaNggdLOxhKgQsv7jwZVXFKk6GEgRTHh25/PyWObOH5VjrW3bWIniWYjIrx ybFxn9bCgxIw9rfOFozT1I9qosORgqxy0vniTwJGrcL4o3NwYGb23hE8UObF/8OtO2f3 XYMQ== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LB0WZdjf38++GLTF73yrl8/5yf6d9s8lwOayuLhr5Wg=; fh=Zo1Fq1MWukl9d7OK8SXRYod2ZOvK3zlh63QCm5GXtBI=; b=eFaWwWCVcZvDRHnjDdKVE6ApXmmIMLwSzH7bVIxtoR/dGMq7OmFtEqa5yajN1c6sih k6FrcmWx8u+I6zfCh7U2uNvxDg79bVrL/GEKspnOovw5+LPFXA2IXCQ9HjkN8VHicxr3 aCGXd3n6jrDmV83AoGBXGW0+g1Lut+ZkmjnF+tBYpw0ZznMGUr2iFilcGd9LBpT2klcp 8lQ0rQ8OnJxMiU9hMyA4kvcGvOcjuszqxMON/HXTZnyzCsEGKchO4qTO001Gw8gGrx4e Jv8ZjTUe41fkiLcaaTu6Xj3nyVkrqOSXXUgPTU9wRtkHOkFQJyadudWqx8bJoulJEP3D uyCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aeK1eaSy; 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 x14-20020a63170e000000b0053ef469281bsi1291555pgl.474.2023.07.06.05.13.17; Thu, 06 Jul 2023 05:13:30 -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=@kernel.org header.s=k20201202 header.b=aeK1eaSy; 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 S232373AbjGFLzp (ORCPT + 99 others); Thu, 6 Jul 2023 07:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjGFLzo (ORCPT ); Thu, 6 Jul 2023 07:55:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0288EE54; Thu, 6 Jul 2023 04:55:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D09606191D; Thu, 6 Jul 2023 11:55:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4006C433C7; Thu, 6 Jul 2023 11:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1688644542; bh=ZVX2FMUo6DUhnVIuypz+Mg6dxvARnYElPp//q0SE0qU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aeK1eaSynsCDDKxSD1F3WceQUwfJ0lwG8w7w2wvYdL8l4k+X4A4MkxqN9Y//Vwo8K zduOA5Y4ba9Bt1DoD1eAV69H46QcjEHXBNfhl1fJo16ly2PKYxhvJgBqjZtCkuG45e iegT1G25Wd2n64fjlSfxpmNd3wCSK3EaJU2BOyB8Gf/YNy8MkkgFxfBJMdPagVp6rj 8t9HxLcCMvfjFm8rSm46+m8ErvaSrux1gc0n1lYSeP9c+6z444zhcf+koQiZBP3dEF hl8/yImExn67ElaNHSXK8bcXcY912fUYoh+gN9G2pSP32K7DEUstz7jhEa9uKKrWyh xqF79eKz9qH/w== Date: Thu, 6 Jul 2023 13:55:39 +0200 From: Frederic Weisbecker To: Valentin Schneider 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 =?iso-8859-1?Q?Wei=DFschuh?= , Juri Lelli , Daniel Bristot de Oliveira , Marcelo Tosatti , Yair Podemsky Subject: Re: [RFC PATCH 11/14] context-tracking: Introduce work deferral infrastructure Message-ID: References: <20230705181256.3539027-1-vschneid@redhat.com> <20230705181256.3539027-12-vschneid@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-7.1 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 Thu, Jul 06, 2023 at 12:23:57AM +0200, Frederic Weisbecker wrote: > Le Wed, Jul 05, 2023 at 07:12:53PM +0100, Valentin Schneider a ?crit : > +bool ct_set_cpu_work(unsigned int cpu, unsigned int work) > +{ > + struct context_tracking *ct = per_cpu_ptr(&context_tracking, cpu); > + unsigned int old, new, state; > + bool ret = false; > + > + preempt_disable(); > + > + work <<= CONTEXT_WORK; > + state = atomic_read(&ct->state); > + /* > + * Try setting the work until either > + * - the target CPU is on the kernel > + * - the work has been set > + */ > + for (;;) { > + /* Only set if running in user/guest */ > + old = state; > + old &= ~CONTEXT_MASK; > + old |= CONTEXT_USER; > + > + new = old | work; > + > + state = atomic_cmpxchg(&ct->state, old, new); > + if (state & work) { And this should be "if (state == old)", otherwise there is a risk that someone else had set the work but atomic_cmpxchg() failed due to other modifications is the meantime. It's then dangerous in that case to defer the work because atomic_cmpxchg() failures don't imply full ordering. So there is a risk that the target executes the work but doesn't see the most recent data. Thanks.