From patchwork Tue Jul 18 16:59:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wan-Teh Chang X-Patchwork-Id: 4358 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.1.76 with SMTP id 73csp1831869vsb; Tue, 18 Jul 2017 10:08:14 -0700 (PDT) X-Received: by 10.223.139.205 with SMTP id w13mr1910560wra.146.1500397693955; Tue, 18 Jul 2017 10:08:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500397693; cv=none; d=google.com; s=arc-20160816; b=a5I11VtueQGg+1M8/mQU81QdkHeFI9GUbY47YmArxsDT3vegY0BP3ucUd/ztt8kSTn 2z3DIQbKmEIVLx7wNnwyyQtsgAqyCkO7DGEYom8EH3sq64EBflQYOsbyfv9d1JqcOqRm PpswHqKYn0DbGJPaMdv9eIeRsMoCgAEpx4qbvNEbmOl9jBPRYRBjnficulEZqMpAAJKr YCwe0y7qxqkQnBU+vCPWilqyo1bbkveSzEKa7oxTtLopKavhLU8u9cVd13h331tSL+bM IVAG0VmE6NlKpF/Jf0SU4xl/iXgYu/6nT+yjCE7gfSuucQ1N98Ra3BCmgwR/h4ukB5tc GY5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:to:message-id:date:from:mime-version :dkim-signature:delivered-to:arc-authentication-results; bh=P2l5DbPRJanp5/wkj1WZuJPPxUqHUmTBCjC3xLCuzUs=; b=LS/avFvH1EzzRWGAmCgS+irBmopWkB2oXmHVZ7Hshw6AMeZw/4Hf2ugKeI5F9fNcHG m55xh7AV9Q3UpiDLNJhJfaW8wXhDEWRPC3/LfRHhMKQQgQfBF25+CFzK6DOoWgUJqJHO Mt2RKIBmqCJV70qbYJBpFdhml/1HAYmKyW8XzXZmFsDXypy6aJJGgwyQtg9uiXMbVs6r KUu2c5a79EyYNwsQm8c31ND6qMgs1mS5CoJKZBGtp65fxxjJpjQZmY7FsK4IY6rdId9B XlDwYTokV+58iuCPUDzc6AmmnGmPQ1GcmhgGJXgXgG0veQvwMvtL061WwHYYUDfXbwCg ir6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.b=m4v6Y3OQ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 37si2206349wrt.64.2017.07.18.10.08.13; Tue, 18 Jul 2017 10:08:13 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com header.b=m4v6Y3OQ; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 99387689992; Tue, 18 Jul 2017 20:08:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BA5346898A9 for ; Tue, 18 Jul 2017 20:07:57 +0300 (EEST) Received: by mail-wr0-f169.google.com with SMTP id v105so7927353wrb.0 for ; Tue, 18 Jul 2017 10:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rHHgZUGoBEvQwy2xdD5UDJEAT13EvAMC3c+38B4evxQ=; b=m4v6Y3OQUdoShJuIP+tCWjoSmqcj0YtgG2GLsM3LFBFkb183/olKfytkEjBiEK2Ogk K3pDhFfnDGgvJz2ClqwQs08bVelly6NnGmjrZiX0fK5QT2bZ/iNRz/pjmEYWMppptjGG wjYtJE8sGgMqOmzUIZmDwgRvQ2HJ6kcsmDldknqANtIqTOLf+3CF+qBpX2+S8SjT7ioq CqSDieeS9BbeAGfucgAzS2R6m04OTYSWO/fvaTd7K0tzGYl8OdftU47FOWGYxM007MNR RqKaLbcNJNuHrBv038N/ONxyRba9rmNN59qa2PMCovAOTJmumUgGx/U6QGzjumqWznjv qQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rHHgZUGoBEvQwy2xdD5UDJEAT13EvAMC3c+38B4evxQ=; b=VM8MBZUbOUIWAh6kGXMzih/cmaiPlVRa66Z3LlBD+4Xt2qNCOv/obT3ThjpaLFBCLZ anQ8lPYR20EwPasY02kcwB27ZLcZ5xEOWSzPrCxCaAmcdAIEqstg6eXrYQoaWhZm5S6K x1dA/ZZTbIhDo2D/K8RgsWgfobnoIEoVuJI1/UdqWHGtYkdwnSXOHqNhSr5Eplwv4PZM lyL89HUDBvm9dYslFZzwhAWbT7RG5z/gnqoAdNjXt3YBAM4AKqFiNVP9RjxB/o9kBypj mmeUeVONKQRdG5lPYCPCwjSszlzDuPGMTT4rC4zKkFuuQpdVTQ+AddiNcNKogCp+b7dJ Z64g== X-Gm-Message-State: AIVw110r0ng82BkdjZ13WU8YT55z1jVt4viTH/7QN7gUBDzsvmt/X3ot CQJJtIxsiL+cOzQ8vkdVO62YRgq2KaxySXjd8Q== X-Received: by 10.223.149.99 with SMTP id 90mr1936640wrs.46.1500397190813; Tue, 18 Jul 2017 09:59:50 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.23.140 with HTTP; Tue, 18 Jul 2017 09:59:49 -0700 (PDT) From: Wan-Teh Chang Date: Tue, 18 Jul 2017 09:59:49 -0700 Message-ID: To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] tsan warning about data race in h264 decoder X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, I'd like to report a tsan warning about a data race in the h264 decoder. 1. Steps to reproduce: ./configure --samples=~/fate-suite/ --toolchain=clang-tsan --disable-stripping make fate-h264 THREADS=4 2. Here is an excerpt of the tsan warning in tests/data/fate/h264-conformance-ba1_ft_c.err: WARNING: ThreadSanitizer: data race (pid=31070) Write of size 8 at 0x7bbc000082a8 by thread T1 (mutexes: write M1628): #0 memcpy /work/release-test/final/llvm.src/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_common_interceptors.inc:655:5 (ffmpeg+0x10de9d) #1 h264_initialise_ref_list home/wtc/tmp/ffmpeg/libavcodec/h264_refs.c:214:29 (ffmpeg+0x1186b3f) #2 ff_h264_build_ref_list home/wtc/tmp/ffmpeg/libavcodec/h264_refs.c:306 (ffmpeg+0x1186b3f) #3 h264_slice_init home/wtc/tmp/ffmpeg/libavcodec/h264_slice.c:1900:11 (ffmpeg+0x1191149) #4 ff_h264_queue_decode_slice home/wtc/tmp/ffmpeg/libavcodec/h264_slice.c:2129 (ffmpeg+0x1191149) #5 decode_nal_units home/wtc/tmp/ffmpeg/libavcodec/h264dec.c:675:24 (ffmpeg+0x7924ec) #6 h264_decode_frame home/wtc/tmp/ffmpeg/libavcodec/h264dec.c:1006 (ffmpeg+0x7924ec) #7 frame_worker_thread home/wtc/tmp/ffmpeg/libavcodec/pthread_frame.c:201:21 (ffmpeg+0xae56dc) Previous read of size 8 at 0x7bbc000082a8 by main thread (mutexes: write M1630): #0 memcpy /work/release-test/final/llvm.src/projects/compiler-rt/lib/tsan/../sanitizer_common/sanitizer_common_interceptors.inc:655:5 (ffmpeg+0x10de9d) #1 ff_h264_update_thread_context home/wtc/tmp/ffmpeg/libavcodec/h264_slice.c:411:5 (ffmpeg+0x118b7dc) #2 update_context_from_thread home/wtc/tmp/ffmpeg/libavcodec/pthread_frame.c:315:19 (ffmpeg+0xae4302) #3 submit_packet home/wtc/tmp/ffmpeg/libavcodec/pthread_frame.c:418:15 (ffmpeg+0xae3783) #4 ff_thread_decode_frame home/wtc/tmp/ffmpeg/libavcodec/pthread_frame.c:495 (ffmpeg+0xae3783) #5 decode_simple_internal home/wtc/tmp/ffmpeg/libavcodec/decode.c:415:15 (ffmpeg+0x665ae4) #6 decode_simple_receive_frame home/wtc/tmp/ffmpeg/libavcodec/decode.c:620 (ffmpeg+0x665ae4) #7 decode_receive_frame_internal home/wtc/tmp/ffmpeg/libavcodec/decode.c:638 (ffmpeg+0x665ae4) #8 avcodec_send_packet home/wtc/tmp/ffmpeg/libavcodec/decode.c:678:15 (ffmpeg+0x665017) #9 decode home/wtc/tmp/ffmpeg/ffmpeg.c:2265:15 (ffmpeg+0x1a748e) #10 decode_video home/wtc/tmp/ffmpeg/ffmpeg.c:2409 (ffmpeg+0x1a748e) #11 process_input_packet home/wtc/tmp/ffmpeg/ffmpeg.c:2644 (ffmpeg+0x1a748e) #12 process_input home/wtc/tmp/ffmpeg/ffmpeg.c:4432:5 (ffmpeg+0x1a2e69) #13 transcode_step home/wtc/tmp/ffmpeg/ffmpeg.c:4543 (ffmpeg+0x1a2e69) #14 transcode home/wtc/tmp/ffmpeg/ffmpeg.c:4597 (ffmpeg+0x1a2e69) #15 main home/wtc/tmp/ffmpeg/ffmpeg.c:4803:9 (ffmpeg+0x19daef) 3. The relevant source code is: libavcodec/h264_refs.c: 135 static void h264_initialise_ref_list(H264Context *h, H264SliceContext *sl) 136 { ... 213 for (i = 0; i < sl->list_count; i++) 214 h->default_ref[i] = sl->ref_list[i][0]; 215 } libavcodec/h264_slice.c: 288 int ff_h264_update_thread_context(AVCodecContext *dst, 289 const AVCodecContext *src) 290 { ... 409 memcpy(&h->poc, &h1->poc, sizeof(h->poc)); 410 411 memcpy(h->default_ref, h1->default_ref, sizeof(h->default_ref)); 412 memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref)); 413 memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref)); 414 memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic)); 415 memcpy(h->last_pocs, h1->last_pocs, sizeof(h->last_pocs)); 4. I can eliminate the tsan warning by deleting line 411 in libavcodec/h264_slice.c, but I don't know if that is the correct fix. Wan-Teh Chang diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 6deb08fe6d..2fb89b189d 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -408,7 +408,6 @@ int ff_h264_update_thread_context(AVCodecContext *dst, memcpy(&h->poc, &h1->poc, sizeof(h->poc)); - memcpy(h->default_ref, h1->default_ref, sizeof(h->default_ref)); memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref)); memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref)); memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic));