From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.1 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58620C4743C for ; Wed, 23 Jun 2021 10:07:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B4EF66112D for ; Wed, 23 Jun 2021 10:07:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B4EF66112D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lvznW-0004t3-Nt for qemu-devel@archiver.kernel.org; Wed, 23 Jun 2021 06:07:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvzmb-0003xP-Ro for qemu-devel@nongnu.org; Wed, 23 Jun 2021 06:06:57 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:49609) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lvzma-0004fj-9n for qemu-devel@nongnu.org; Wed, 23 Jun 2021 06:06:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624442815; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u75PBCL27AgZAuy42poL79leLYeBhCq8kNguc+faja8=; b=ifk6uHr9GtcOe2FgbeYxRT8oKi4sZhB4a5EZmEeEK9HyeH+sG1MT5aLA0XKIOhhMSLwF+A LOUtNnBczVR25trVxsYTM70qMnHdHafIn/sNKJT3KCEZ8yriqaeqO1EdkFk22K6K851Rgo aF/bQF2iu4aIRtYN862sgz5yAuROUYs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-58-JMJLreAFMNOCqyZqnMCeEg-1; Wed, 23 Jun 2021 06:06:52 -0400 X-MC-Unique: JMJLreAFMNOCqyZqnMCeEg-1 Received: by mail-wm1-f69.google.com with SMTP id v2-20020a7bcb420000b0290146b609814dso405880wmj.0 for ; Wed, 23 Jun 2021 03:06:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=u75PBCL27AgZAuy42poL79leLYeBhCq8kNguc+faja8=; b=r7UyRlaGbR7ajukb6d75xm3RQSBxn4fW2WVDhCMyAvfkdzDHNzJLMRrvo5i7Afr8Tp tls3UVjgo/sYfxeGQHi0SufVMQKOoA3SaCHFI3iWhjBQfsJA3U9EvrTiQ0kW7uuf6Hex J5dcAyqJFJkq5yVZj/2I16RcBuUtJQBK43FZmcQn3nNWFAFv13gV1jBaJ2I/i/bxpGOV K42i4PVUbt/Tzt5kXKLHe67KGEvA7Lw/swwkCDAaCUMDUR98qqzIbknmseniNbYIpXa4 Ykvibe4LQMCB4qy+AXE2BFHr5DBI7QlryNYw11Ki1AUvqzZsz25HaxsjzpW/zwNmTGTW 4h6A== X-Gm-Message-State: AOAM532+QIUaxWAQ4fETyzgCpXe1RgvG5i0fit6SI1Lf3tOXO9CEevDc le71DAgKVXCI35bP7CAib21xPtqcMiKFdaKHSbiwCRee5Jk8WntuuGbwoCxiB0GgROqfYAkVRIE fIvISoiWI/CIydzBQOKpz8omeDKjh2ed4ZWbpBLQX6ywXKpbv0IYvC3bRhSkrEW51AEQ= X-Received: by 2002:a05:600c:2141:: with SMTP id v1mr9886578wml.68.1624442810974; Wed, 23 Jun 2021 03:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXyORDhK2p/mwi09uzavmmm2nN1DMk9vchCacliUMFSlytojdtsBji5hBclW2k0xAu15aptw== X-Received: by 2002:a05:600c:2141:: with SMTP id v1mr9886555wml.68.1624442810777; Wed, 23 Jun 2021 03:06:50 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id s62sm5364307wms.13.2021.06.23.03.06.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Jun 2021 03:06:50 -0700 (PDT) Subject: Re: [PATCH v4 6/6] block-copy: atomic .cancelled and .finished fields in BlockCopyCallState To: Vladimir Sementsov-Ogievskiy , Emanuele Giuseppe Esposito , qemu-block@nongnu.org References: <20210614073350.17048-1-eesposit@redhat.com> <20210614073350.17048-7-eesposit@redhat.com> <28d4cd1c-2495-b30d-3c9f-2d8d0d3e897b@virtuozzo.com> <5e019d88-3551-4a08-6a67-e0699dd4f72e@virtuozzo.com> From: Paolo Bonzini Message-ID: <248f3bd9-df61-829c-8db9-6669490e5ae0@redhat.com> Date: Wed, 23 Jun 2021 12:06:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <5e019d88-3551-4a08-6a67-e0699dd4f72e@virtuozzo.com> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -29 X-Spam_score: -3.0 X-Spam_bar: --- X-Spam_report: (-3.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.223, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , John Snow , qemu-devel@nongnu.org, Stefan Hajnoczi , Max Reitz Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" On 22/06/21 12:39, Vladimir Sementsov-Ogievskiy wrote: > 22.06.2021 13:20, Paolo Bonzini wrote: >> On 22/06/21 11:36, Vladimir Sementsov-Ogievskiy wrote: >>> OK, I agree, let's keep it. >> >> You can also have a finished job, but get a stale value for >> error_is_read or ret.  The issue is not in getting the stale value per >> se, but in block_copy_call_status's caller not expecting it. > > Hmm. So, do you mean that we can read ret and error_is_read ONLY after > explicitly doing load_acquire(finished) and checking that it's true? > > That means that we must do it not in assertion (to not be compiled out): > > bool finished = load_acquire() > > assert(finished); > > ... read reat and error_is_read ... In reality you must have synchronized in some other way; that outside synchronization outside block-copy.c is what guarantees that the assertion does not fail. The simplest cases are: - a mutex: "unlock" counts as release, "lock" counts as acquire; - a bottom half: "schedule" counts as release, running counts as acquire. Therefore, removing the assertion would work just fine because the synchronization would be like this: write ret/error_is_read write finished trigger bottom half or something --> bottom half runs read ret/error_is_read So there is no need at all to read ->finished, much less to load it outside the assertion. At the same time there are two problems with "assert(qatomic_read(&call_state->finished))". Note that they are not logic issues, they are maintenance issues. First, if *there is a bug elsewhere* and the above synchronization doesn't happen, it may manifest sometimes as an assertion failure and sometimes as a memory reordering. This is what I was talking about in the previous message, and it is probably the last thing that you want when debugging; since we're adding asserts defensively, we might as well do it well. Second, if somebody later carelessly changes the function to if (qatomic_read(&call_state->finished)) { ... } else { error_setg(...); } that would be broken. Using qatomic_load_acquire makes the code more future-proof against a change like the one above. Paolo