Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4638301rdh; Wed, 29 Nov 2023 06:58:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IHMNiDXnbiq3ZsUFfeXXqcxrKkipp32jV/5oouVEEUbKhMPqjXiptxNRGpWYWmoz0q2SGdS X-Received: by 2002:a17:902:9883:b0:1c1:dbd6:9bf6 with SMTP id s3-20020a170902988300b001c1dbd69bf6mr18385341plp.41.1701269898265; Wed, 29 Nov 2023 06:58:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701269898; cv=none; d=google.com; s=arc-20160816; b=N6ms9OZSF20dhAZUVMoKP9jNSnpm8sjFtELHgMGPY6ihYAy4nLdSmZs/n/UVzzXvcC dtysyPG47oUK0BqCO+6w5j31yd9wB7mPyeGG24N/PAZ2A9TcUpSnK7QQtZHAW3vB/yq7 O8eFIEIvRCTb1Id6gfEfRe19BC9zmPCLLZ9O8JjrEEwynsjmmZaB1fJGbSPjB8tLdHnd pIK3Av186h0TEPSwUiFVphJpcESCIMuebK0lLBAl1Y5D+P8EVMyhVrU/e2WulvMcYMKo SLSpDrWN17+o9P4nKx24iVkN16dORA/QtV8BFTwwQm1WwCyZBPFfpwI2N9NzskHCj/iU H2ig== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=XHA3RS4nCnrfEARQ9/T6MGTNrQC0ZFgxywPOzPevpNM=; fh=Y3gvkCYGIKm1p3xKiYKKjdPJzz3c7vS/1kHLUuaMIOs=; b=L5roteTBi/JNsqX9EmB8MroMcMJY2NLw28Vm7GUTzOzFibaVA8z3EZm3Kwfx/KTzab QvWv4YYsYwWIWIwucvpLgMYuGn5wyM3DaXeQ6Hq1HfE4JJOoOJcr3MrvRi5SzHtTN7O2 qpIqhNM7AdBHia498t6zb8bGpwaFvIgBmW70JKqQ5MNEGvlGBy7UmyhcKqi04Wjsc1PR /2/+47O+5atTxm0XcFDJ3LUK0SNwXJhFHutHoiOu9m51QYXd7DLQHDNvawAefs/IhGLF ZsOG+2B8rkz/NEoUoOVvZi03jmowM9yaRG9jwjPKynMWYfAD43LCaxkVF9o9ypeA62wC 5myA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id 6-20020a170902ee4600b001b86ddfd49bsi13761534plo.6.2023.11.29.06.58.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 06:58:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 91E1E8043059; Wed, 29 Nov 2023 06:58:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234733AbjK2O57 (ORCPT + 99 others); Wed, 29 Nov 2023 09:57:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231488AbjK2O56 (ORCPT ); Wed, 29 Nov 2023 09:57:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3907EA3 for ; Wed, 29 Nov 2023 06:58:05 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30A6BC433C8; Wed, 29 Nov 2023 14:58:04 +0000 (UTC) Date: Wed, 29 Nov 2023 09:58:26 -0500 From: Steven Rostedt To: Petr Pavlu Cc: mhiramat@kernel.org, mathieu.desnoyers@efficios.com, zhengyejian1@huawei.com, linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] tracing: Simplify and fix "buffered event" synchronization Message-ID: <20231129095826.1aec6381@gandalf.local.home> In-Reply-To: References: <20231127151248.7232-1-petr.pavlu@suse.com> <20231127151248.7232-2-petr.pavlu@suse.com> <20231127124130.1041ffd4@gandalf.local.home> <77037ca1-8116-4bc6-b286-67059db0848e@suse.com> <20231128102748.23328618@gandalf.local.home> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,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 fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Wed, 29 Nov 2023 06:58:15 -0800 (PST) On Wed, 29 Nov 2023 10:22:23 +0100 Petr Pavlu wrote: > Yes, I believe this should address this potential race condition. > > An alternative would be instead to update > trace_event_buffer_lock_reserve() as follows: > > if (this_cpu_inc_return(trace_buffered_event_cnt) == 1) { > smp_rmb(); This is the problem I have with your approach. That smp_rmb() is in the highly critical path. On some architectures, this has a significant impact on the overhead of this code. This path is called during code execution and increases the overhead of the tracing infrastructure. If I'm given two solutions where one adds a smp_rmb() to the critical path and the other just slows down the non-critical path more, I'll take the slow down of non-critical path every time. > if ((entry = __this_cpu_read(trace_buffered_event))) { > [...] > > That saves the synchronize_rcu() call but additionally modifies > trace_buffered_event_cnt even if trace_buffered_event is currently NULL. > > Another alternative is the approach taken by my patch which avoids more > RCU work and unnecessary memory modifications. > > I'd be interested if you could have a look again at what I'm proposing > in my patch. I think it simplifies the code while addressing these > problems as well. However, if you have reservations about that approach > then it is ok, I can fix the found problems individually as discussed. Fix this without adding any memory barriers to the critical path, then I'll take another look. FYI, this code was designed in the first place to avoid adding memory barriers in the critical path. Thanks! -- Steve