From patchwork Fri May 29 13:23:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 187314 Delivered-To: patch@linaro.org Received: by 2002:a92:5b0a:0:0:0:0:0 with SMTP id p10csp586513ilb; Fri, 29 May 2020 06:30:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJynNt24d1njgnmMDWxMfWHAHAEcDhHip0SnkvZJbhZb0C1nIH2aK4jAPU7+j1nu8roP4EFW X-Received: by 2002:a05:6214:186b:: with SMTP id eh11mr8093199qvb.35.1590759007909; Fri, 29 May 2020 06:30:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590759007; cv=none; d=google.com; s=arc-20160816; b=Z2gpKw4dxcYnRth3HI05wmRptAmbnTHHbfcmff6tiGYCJLSEu1aU2CwOsM9Rb15fL+ ns8h9a/VviqDpt8iMCdMyZNdJbLVvfohrSUgs/5Rasu2eNZs5t9DSjQdYCW6LpaLhlHl f7+AIxtvmU4iG4AgqvH6SZ1D8/QOu/K49Urwuku6B2WhD/OCbV1+HfMS0uya7sG09UuH vlErR8XznIyHM187ISRTM2HKlJHso1OBt5UxnaNHeSi/lKShp5cZaNzPUPiEUP+2/aoQ 9LIh0M1YWGZMPMngzQpDmlwREvrJ0MSTFTj27UsoeLUtROCy5kZKddVEIKH8Gi++P9Cr I/yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=ydcgl47Pm6W+gZBnliZbqxH7FmNLx2YcsU8HDYc4sUVt7KG+6OdxsM7+SJsfto9HxZ 3WYIyj3QElvc94HHloK8SIRgn5+GsXTwVRgnWjwrumoRiF9yvmzHKpuS87a8Yd3YvpL4 Q17iaV1BaRBkSVtOuGyO1fPV4Z8pU8pSDrbsTsCxiM9gpqCW0Cak8pCWmZ7VxhdeCc1N zS4ZiPmv7KfDQR6j6fhHbIdKmiwHq3B9PZdI8GG1T8+Ac3YskZ5y4hRD6xIVAPUm1RGc PVE9mkgLI6va70Bqksf2GKdKOJn3AwR78zobipYQwKAuckJT20SzqEQlgzz/5YEjzU6f BBjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xiceRRG+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x3si2209381qvn.6.2020.05.29.06.30.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 29 May 2020 06:30:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=xiceRRG+; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jef5L-0006WM-Aw for patch@linaro.org; Fri, 29 May 2020 09:30:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42908) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jeezO-0004tN-0r for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:58 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jeezM-0003he-VZ for qemu-devel@nongnu.org; Fri, 29 May 2020 09:23:57 -0400 Received: by mail-pl1-x644.google.com with SMTP id bg4so1164660plb.3 for ; Fri, 29 May 2020 06:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=xiceRRG+/TTDb0OXC244QM/ffSZIlCmPHW6oo5g7ITnFGVML6PJp1sWMy9VZpiC5zP UQDKOK/z9g6uFlzNmETiAA6Pl+OtMMtHoJHayDGMwgquXZAkuHqltVnPglKItiJ3Bl/G YMDdLs6xAot9CtGYtcJy34U9X2dkQDkJAM+QPs9/S/ElSksPV+F0WnGmIRfwUnZXHCxB n82hzUuFs0DUe/9a9rqRfWSItQ+xL1CQ9Uqm9r/J0u1WxtuCiGznSzlfl7kEUtlCapdk MFQKKiLplVS+zfIl/B12L5XMzsPhsxKoEHl2v48o9dYv+ULOkPDC5mTlV6B65uIr290v Gphg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AOzUAJyFNQB4L+phqsSsfzj9Z8OtZxOrajLi9NoXesk=; b=bqG7rHc+ncsBtHhwIAthTE2phr0OuayOfP9IoMimmRXdhpAy/ifcjbDTzU7dVcctap aqGFvrRkjRpSWwbJXpgnpS7l57kkp8wtpR/Zm4WkVYTOlp8AlSj5VdQm/3EjkAEsMsq/ tzPN99g6XL6XSOKgj4VyN/wvsalQ5O6uu95oXrquPC38mDntd1t3nuwf6OUaD4gwEiTe OV/n+SAklLC3W4VO6xW84AIahmYBqLYOzzU1MlaI6aSCyd8WuiFQ4oQWS2T55RyBP3v6 OOKvsisjvD/1twM7a55rw6M2OD3PrcBSQ3MEPyw9XYcuQykGh1dS/m9oG90xwfdNsL15 73iQ== X-Gm-Message-State: AOAM5327CeWQFpCPR3h295DWKSMs2EiAsoVyHgwtAUud4rEAkTCuxAnc df4nruFiqL51BnEy3Tenfbn3F/pialxXmg== X-Received: by 2002:a17:90a:6f26:: with SMTP id d35mr9414092pjk.210.1590758634877; Fri, 29 May 2020 06:23:54 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:75ac:d268:da04:dde4]) by smtp.gmail.com with ESMTPSA id e13sm1998686pfd.10.2020.05.29.06.23.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 May 2020 06:23:54 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v1 10/12] include/qemu: Added tsan.h for annotations. Date: Fri, 29 May 2020 09:23:40 -0400 Message-Id: <20200529132341.755-10-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200529132341.755-1-robert.foley@linaro.org> References: <20200529132341.755-1-robert.foley@linaro.org> Received-SPF: pass client-ip=2607:f8b0:4864:20::644; envelope-from=robert.foley@linaro.org; helo=mail-pl1-x644.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN 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: peter.puhov@linaro.org, cota@braap.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" These annotations will allow us to give tsan additional hints. For example, we can inform tsan about reads/writes to ignore to silence certain classes of warnings. We can also annotate threads so that the proper thread naming shows up in tsan warning results. Signed-off-by: Robert Foley Reviewed-by: Emilio G. Cota --- include/qemu/tsan.h | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 include/qemu/tsan.h -- 2.17.1 diff --git a/include/qemu/tsan.h b/include/qemu/tsan.h new file mode 100644 index 0000000000..09cc665f91 --- /dev/null +++ b/include/qemu/tsan.h @@ -0,0 +1,71 @@ +#ifndef QEMU_TSAN_H +#define QEMU_TSAN_H +/* + * tsan.h + * + * This file defines macros used to give ThreadSanitizer + * additional information to help suppress warnings. + * This is necessary since TSan does not provide a header file + * for these annotations. The standard way to include these + * is via the below macros. + * + * Annotation examples can be found here: + * https://github.com/llvm/llvm-project/tree/master/compiler-rt/test/tsan + * annotate_happens_before.cpp or ignore_race.cpp are good places to start. + * + * The full set of annotations can be found here in tsan_interface_ann.cpp. + * https://github.com/llvm/llvm-project/blob/master/compiler-rt/lib/tsan/rtl/ + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifdef CONFIG_TSAN +/* + * Informs TSan of a happens before/after relationship. + */ +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) \ + AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr)) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) \ + AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr)) +/* + * Gives TSan more information about thread names it can report the + * name of the thread in the warning report. + */ +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) \ + AnnotateThreadName(__FILE__, __LINE__, (void *)(name)) +/* + * Allows defining a region of code on which TSan will not record memory READS. + * This has the effect of disabling race detection for this section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() \ + AnnotateIgnoreReadsBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() \ + AnnotateIgnoreReadsEnd(__FILE__, __LINE__) +/* + * Allows defining a region of code on which TSan will not record memory + * WRITES. This has the effect of disabling race detection for this + * section of code. + */ +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() \ + AnnotateIgnoreWritesBegin(__FILE__, __LINE__) +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() \ + AnnotateIgnoreWritesEnd(__FILE__, __LINE__) +#else +#define QEMU_TSAN_ANNOTATE_HAPPENS_BEFORE(addr) +#define QEMU_TSAN_ANNOTATE_HAPPENS_AFTER(addr) +#define QEMU_TSAN_ANNOTATE_THREAD_NAME(name) +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_READS_END() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_BEGIN() +#define QEMU_TSAN_ANNOTATE_IGNORE_WRITES_END() +#endif + +void AnnotateHappensBefore(const char *f, int l, void *addr); +void AnnotateHappensAfter(const char *f, int l, void *addr); +void AnnotateThreadName(const char *f, int l, char *name); +void AnnotateIgnoreReadsBegin(const char *f, int l); +void AnnotateIgnoreReadsEnd(const char *f, int l); +void AnnotateIgnoreWritesBegin(const char *f, int l); +void AnnotateIgnoreWritesEnd(const char *f, int l); +#endif