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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 12103C433FE for ; Thu, 6 Oct 2022 18:13:56 +0000 (UTC) Received: from localhost ([::1]:53818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogVNa-0001n1-RW for qemu-devel@archiver.kernel.org; Thu, 06 Oct 2022 14:13:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59890) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogU35-0008SS-0y for qemu-devel@nongnu.org; Thu, 06 Oct 2022 12:48:53 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21071) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogU31-0003Gn-Vh for qemu-devel@nongnu.org; Thu, 06 Oct 2022 12:48:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665074914; 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: in-reply-to:in-reply-to:references:references; bh=H1YLOn9YsDkJAyu1vVMhYfu/xRZL5Z3HBp+QNbLPgJc=; b=fs+y+qqPgGUnAy9QyYK0vCBfkwL9niGRhsrD79dcUq4YS0NVOsiT9fvLPuOWxiAkR5qMy0 mX/hTQBZr5aeI0Z5RN4c9f2ZOP6UgRLvf10pKfwSQaVmp61SW2qo5rOuv0CkRPLD6JkNOa VLCq5YBfsgzG/0ySSOpEeVXmty6M/AU= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-3-tdMsfMP0NdSyO-qGY1wMGw-1; Thu, 06 Oct 2022 12:48:30 -0400 X-MC-Unique: tdMsfMP0NdSyO-qGY1wMGw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 06A0E3817A62; Thu, 6 Oct 2022 16:48:30 +0000 (UTC) Received: from redhat.com (unknown [10.39.192.224]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A8D1B145BA44; Thu, 6 Oct 2022 16:48:27 +0000 (UTC) Date: Thu, 6 Oct 2022 18:48:26 +0200 From: Kevin Wolf To: Emanuele Giuseppe Esposito Cc: qemu-block@nongnu.org, Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Wen Congyang , Xie Changlong , Markus Armbruster , Stefan Hajnoczi , Fam Zheng , qemu-devel@nongnu.org, Vladimir Sementsov-Ogievskiy Subject: Re: [PATCH v12 16/21] blockjob: protect iostatus field in BlockJob struct Message-ID: References: <20220926093214.506243-1-eesposit@redhat.com> <20220926093214.506243-17-eesposit@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220926093214.506243-17-eesposit@redhat.com> X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Am 26.09.2022 um 11:32 hat Emanuele Giuseppe Esposito geschrieben: > iostatus is the only field (together with .job) that needs > protection using the job mutex. > > It is set in the main loop (GLOBAL_STATE functions) but read > in I/O code (block_job_error_action). > > In order to protect it, change block_job_iostatus_set_err > to block_job_iostatus_set_err_locked(), always called under > job lock. > > Signed-off-by: Emanuele Giuseppe Esposito > Reviewed-by: Kevin Wolf > Reviewed-by: Vladimir Sementsov-Ogievskiy > --- > block/mirror.c | 7 +++++-- > blockjob.c | 5 +++-- > 2 files changed, 8 insertions(+), 4 deletions(-) > > diff --git a/block/mirror.c b/block/mirror.c > index c6bf7f40ce..7e32ee1d31 100644 > --- a/block/mirror.c > +++ b/block/mirror.c > @@ -893,7 +893,7 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) > MirrorBlockJob *s = container_of(job, MirrorBlockJob, common.job); > BlockDriverState *bs = s->mirror_top_bs->backing->bs; > BlockDriverState *target_bs = blk_bs(s->target); > - bool need_drain = true; > + bool need_drain = true, iostatus; iostatus isn't really a bool, it's BlockDeviceIoStatus. > int64_t length; > int64_t target_length; > BlockDriverInfo bdi; > @@ -1016,8 +1016,11 @@ static int coroutine_fn mirror_run(Job *job, Error **errp) > * We do so every BLKOCK_JOB_SLICE_TIME nanoseconds, or when there is > * an error, or when the source is clean, whichever comes first. */ > delta = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - s->last_pause_ns; > + WITH_JOB_LOCK_GUARD() { > + iostatus = s->common.iostatus; > + } > if (delta < BLOCK_JOB_SLICE_TIME && > - s->common.iostatus == BLOCK_DEVICE_IO_STATUS_OK) { > + iostatus == BLOCK_DEVICE_IO_STATUS_OK) { Your code actually happens to work because the one value that you compare it against is BLOCK_DEVICE_IO_STATUS_OK, which is 0, so it maps to false and everything else to true, but... it's still not right. :-) > if (s->in_flight >= MAX_IN_FLIGHT || s->buf_free_count == 0 || > (cnt == 0 && s->in_flight > 0)) { > trace_mirror_yield(s, cnt, s->buf_free_count, s->in_flight); Kevin