Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6737067rwi; Mon, 24 Oct 2022 05:36:19 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6Hz7pBVP+gUknEgbAlYIEmg6n22RlQuvdKVyTllqNTy184DenXNIv4GRKholz5fETTUYTz X-Received: by 2002:a17:907:3da2:b0:78d:45df:b4f with SMTP id he34-20020a1709073da200b0078d45df0b4fmr26752030ejc.651.1666614979341; Mon, 24 Oct 2022 05:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614979; cv=none; d=google.com; s=arc-20160816; b=tXuzHCRMbN/S5m7MCSXroKhL9mJN7J/3vD9mPg+PkVVTT+sFFZZy4BI4U1HJ0T+tg7 owQpHMPMMwbd9zmLiM50P9Su44XtlcN72rX2ylxQ8uGtTEcsDwWuHXXoZJhAHBSps6gg 0eHde1sWj45OjrloCkYyT2N1yrS+74hep3sCEfS7pkLRY9y7dsheAkgFP/QQz/kCAIBy n5FLj+d9+QHMi1Zx1w7dOo9iVrmeZuomHR10aq9/PrS91coC+I02Dter2x1He4w1OlB1 2vdTePPir2NcTujyjCFsC7xe6YKL2RpKZchD/x8RoopIArRdEFSR65f54wpmsWnNtu/y euhw== 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=dNup1E96i7/VCnyTb4Lw6Ce8tncoNz2vFRmlgUeZZaw=; b=JMVSKeiPr2E7P1jztJthbo4kECy0ROLQjn1Ew6VyDOKIdOCWMobqxN+MiTrKvV3VU3 tA0MNQ9gPDvw35jJ9CxnLkChfhdq/5yQq+Y23tkXYJKfuel4Ei+30STWtzPfLwyoY7oh stLEZS3lgC88CmCF7Su82yGMHJSheq+jNq9rZ6ctBk7D1b9mHuVFt9OHSOeoBgYvO84c m9/MTRQmIEKaNAAtUXZyLJeMeIv792MLjirPfvvzSylzYNob6hUrwA5vNLsfVs8eJSwS 0QxMQxfmP6f8EipF9oBmKtz75kRNRnpinD5hebcqR8rGd5FSSXyi05zk+QpF0FBVVnSI fwBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YAmtNEIK; 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 a21-20020a1709066d5500b007835897050asi22155950ejt.83.2022.10.24.05.35.51; Mon, 24 Oct 2022 05:36:19 -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=YAmtNEIK; 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 S230230AbiJXLaW (ORCPT + 99 others); Mon, 24 Oct 2022 07:30:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbiJXLaU (ORCPT ); Mon, 24 Oct 2022 07:30:20 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BB6413F84; Mon, 24 Oct 2022 04:30:18 -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 ams.source.kernel.org (Postfix) with ESMTPS id 357FDB81132; Mon, 24 Oct 2022 11:30:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0539C433D6; Mon, 24 Oct 2022 11:30:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1666611015; bh=wc7q89o37lUAS6YZchaEYz4ZHRKRvZLgc1XU7PqIFLw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YAmtNEIKG7at+1aB+aMH5nNezIMRI82+4TaMv8rLeiYCxPhGxUHkzZbRoCdCk+2Cc sAw4CRqVlluM9fO/8GOWHZm3YLrlPw8Bdcm1Wf8d0FnamerKgpzlGYBNNOYUE1W8zJ zOGrGWBo9oTu4zUvrQCj9I4OqEqwUhX0wEouIjI4Eu00D8qyvLQ3c6kX1l29BpOKQi n4c4Qb1fIpEvVKrzfLpGTUkakil3waOyYq3NDNn16OHJcSpBSrjtwWlL/Y+Otb6F8s tcsQCtAQ0XBjC0UreuL79XQMzu6Gt9V0MNhrjS0kvIoHSMTATDRSt0iPxv+WBCHkPS qUB7jt6JVKDmg== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id 59658404BE; Mon, 24 Oct 2022 08:30:13 -0300 (-03) Date: Mon, 24 Oct 2022 08:30:13 -0300 From: Arnaldo Carvalho de Melo To: Leo Yan Cc: Ian Rogers , Greg Thelen , Anand K Mistry , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Stephane Eranian Subject: Re: [PATCH v1] perf record: Fix event fd races Message-ID: References: <20221024011024.462518-1-irogers@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Url: http://acmel.wordpress.com X-Spam-Status: No, score=-5.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,URI_DOTEDU 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 Em Mon, Oct 24, 2022 at 05:16:56PM +0800, Leo Yan escreveu: > On Sun, Oct 23, 2022 at 10:33:30PM -0700, Ian Rogers wrote: > > [...] > > > > > +static volatile int done_fd = -1; > > > > > > Here is a bit suspecious for adding volatile qualifier. See the > > > document: process/volatile-considered-harmful.rst. > > > > > > I know the document is mainly for kernel programming, but seems to me > > > it's also valid for C programming in userspace. > > > > > > I not sure what's the purpose for adding volatile for done_fd, if we > > > really have concern for reading any stale value for done_fd, should we > > > use WRITE_ONCE/READ_ONCE? > > > > We could just switch to C11 and stdatomic. The volatile is consistent > > with the code above and more consistent with the expectation of > > writing to a variable that is read in a signal handler. > > Thanks for the info for C11 and stdatomic.h. The documentation [1] says > the safe way is for accessing shared data in signal handler is: > > static volatile sig_atomic_t done_fd = -1; > > It's fine if you want to use another patch to address this issue, this > patch for fixing errno is fine for me: > > Reviewed-by: Leo Yan Thanks, applied. - Arnaldo > [1] https://wiki.sei.cmu.edu/confluence/display/c/SIG31-C.+Do+not+access+shared+objects+in+signal+handlers -- - Arnaldo