From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oa1-x2d.google.com (mail-oa1-x2d.google.com [IPv6:2001:4860:4864:20::2d]) by sourceware.org (Postfix) with ESMTPS id A11F03850232 for ; Wed, 8 Jun 2022 16:53:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A11F03850232 Received: by mail-oa1-x2d.google.com with SMTP id 586e51a60fabf-e93bbb54f9so27887156fac.12 for ; Wed, 08 Jun 2022 09:53:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=W/Eru+PL6YPaTg9s481Jfv8GGukIhsjr5t+5cN1dWYk=; b=KXCq7r/4tqemLMNapE/3FTOA4RlQXJRoDMCENXvCW65RDggP31s6E4aBRDHedv6N/g 6waiknO30o5QJm+klGKVyPFeFR38PG758WNNQOLKg4DSMyCDC20eWx5VBGJpNFca6YGL wiGO+7mgByoKKd9bckFLvuXr6nTv9ZUUcAZaDyX9ik611n8spXZWWtRNbj/6IKhUXxtl rGQt68ROlb+C+HaSDaHAYxZE3tbDS5MUZY8pmSBYVrnWJxV9hZYij2a+QVLZ1BtbxjTr q58xYrVqoF8m57jmgSPmoNPTOXHtgpnDS+ySYkZ/zCvYwCPX6SmEX1lslJbXnAu+efDZ 1vsg== X-Gm-Message-State: AOAM531Dsm+jFak80SYkVxECRhKI+uc98XWUBIAO19kf1Q/r+NuDFjb6 2Tw9CtwuwybjtTCI+LBY1muog5/aZX+nKw== X-Google-Smtp-Source: ABdhPJz7ILytjHCpQiUGNiXNAkIPirYYkdzdF/2lY6yZ0xdVgVN1vK1YudYYljAHFsuj1oeR5RHNRg== X-Received: by 2002:a05:6870:4787:b0:f2:bfdf:5c8e with SMTP id c7-20020a056870478700b000f2bfdf5c8emr2794578oaq.291.1654707186909; Wed, 08 Jun 2022 09:53:06 -0700 (PDT) Received: from ?IPV6:2804:431:c7cb:a613:9260:25f7:781e:1ec9? ([2804:431:c7cb:a613:9260:25f7:781e:1ec9]) by smtp.gmail.com with ESMTPSA id o9-20020a9d6d09000000b0060bf6213084sm5403545otp.27.2022.06.08.09.53.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jun 2022 09:53:06 -0700 (PDT) Message-ID: <8b4ddbb9-683c-0002-4c60-59ada0a45c70@linaro.org> Date: Wed, 8 Jun 2022 13:53:04 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v2] Avoid RMW of flags2 outside lock (BZ #27842) Content-Language: en-US To: Wilco Dijkstra , 'GNU C Library' References: From: Adhemerval Zanella In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, 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 server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Jun 2022 16:53:10 -0000 On 23/05/2022 12:47, Wilco Dijkstra wrote: > v2: remove flags2 update altogether since it isn't needed. > > Remove an unconditional RMW on flags2 in flockfile - we don't need to change > _IO_FLAGS2_NEED_LOCK since it isn't used in flockfile or funlockfile. > This fixes BZ #27842. I think it should be ok, although POSIX states that: "All functions that reference (FILE *) objects, except those with names ending in _unlocked, shall behave as if they use flockfile() and funlockfile() internally to obtain ownership of these (FILE *) objects." Skipping the locks on single-thread case should not issue any visible side-effects (since flockfile does take the lock regardless). Reviewed-by: Adhemerval Zanella > > --- > > diff --git a/stdio-common/flockfile.c b/stdio-common/flockfile.c > index a5decb450f8d477e3105d02661282afeab58f88b..49f72c69ab7a4ccca6f21d443c6fc3a0eca76376 100644 > --- a/stdio-common/flockfile.c > +++ b/stdio-common/flockfile.c > @@ -22,7 +22,6 @@ > void > __flockfile (FILE *stream) > { > - stream->_flags2 |= _IO_FLAGS2_NEED_LOCK; > _IO_lock_lock (*stream->_lock); > } > weak_alias (__flockfile, flockfile);