From patchwork Tue Jul 7 07:08:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 234915 Delivered-To: patch@linaro.org Received: by 2002:a92:d244:0:0:0:0:0 with SMTP id v4csp653094ilg; Tue, 7 Jul 2020 00:11:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVtk5tABvcY68gGXzpO88k63UvB4pbXNzMdGKjJUAYx7EpeXp2gqGIDYdWFiYJsojmFyu/ X-Received: by 2002:a25:56c3:: with SMTP id k186mr57480718ybb.183.1594105892322; Tue, 07 Jul 2020 00:11:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594105892; cv=none; d=google.com; s=arc-20160816; b=UTWVPKxwSxRWklM2Pw/MMrR2KAv2PD/977JLIlVWesDp/Lzb0JE0qx2J8mwQ0nYiAs X75C/EgLVdcSCzq7JShH+tUePOLZUArgFUQyjAgV6jgHTp3VpqepKHSwOgLBtwxEIM+A cZWox/NopSCkjqyPoeWy0UzjGGUpEZQGsdLqABxGGMgQkH6t/TQaN/UKam+IbZSGk6Ds KHqH+IWjMkv+MoD7nOuRS5sYToFcgidT+FIP5ZP1HsIy9TH/kZNHSdwWDILi43Gl+ZBH THj1wCf2ti5xhNYTnAOycJyptkdPeUnS/hEnFxLSOcc5Lj+DldYAKfNC4hnifHTihl5T Rhyg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=0qqS4w4mRnCRDCTfWQqRgg26scMxtoAIPpRe2SvN8Gk=; b=Yqr1lXV468s06YRNUS/0TB4+4OZ3RcD+XNvKPJtLSvZqMnqvtwDM9hkqh/cEoZCdri uLxzGP5YVYm2SGf6C1UQOujIx76T9Su1f2lEw9Swk1xQbeL2aYwkBcNahfhy3icrXrSi YmUi2+Ip4Ev/KBtit5AHus1gT8/qpM7E7nXCStpeVIdHpykqr6Wg46DLuZwyGKPzhEEP NgxoPY4Y34Mze/DQjk0/R99i0UIYEqJ0Tj8iG+kUXJV1rcEUQoQQPnnImuE9zl9Vj+pR BaeTFmvskRRPhuUuUcnI4yPKzJvOppkeEiLqKLSbgufPh7TdScrZPu32sWQANmMn+TMF Y2Aw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="RQeNH/EW"; 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 t45si22693966ybi.478.2020.07.07.00.11.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 07 Jul 2020 00:11:32 -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="RQeNH/EW"; 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]:43102 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jshlK-0007tP-Vk for patch@linaro.org; Tue, 07 Jul 2020 03:11:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42462) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jshj2-0004PW-QW for qemu-devel@nongnu.org; Tue, 07 Jul 2020 03:09:09 -0400 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:34549) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jshj0-00043W-W3 for qemu-devel@nongnu.org; Tue, 07 Jul 2020 03:09:08 -0400 Received: by mail-wr1-x42c.google.com with SMTP id f7so40959475wrw.1 for ; Tue, 07 Jul 2020 00:09:06 -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 :mime-version:content-transfer-encoding; bh=0qqS4w4mRnCRDCTfWQqRgg26scMxtoAIPpRe2SvN8Gk=; b=RQeNH/EWZqgdFsCUzh4H97+zKDBdI28lkG6B4qicotvqO80bI/hyKfy1nMuWVrCy25 vA7ijNBi00ddkc1DzKSKhvapsBJBXXHWj/6as2U5/WQsPfJCp+S5dN0nkUarUR+Y4V2w r/5Ml5kiS2ZH/STPZnDNEkT8ZmRwR5+lMxB8W65RMsXxwPQQ1zL1ex/SUHHug+t818n1 19mnHstgArAs5Wpsp9XABoKreF1DdPRN1zp2gULPCBbYNCvQLJ+mR2P8p8RdXxBPlokP 3WUOlSntttjtd275XDqcM6iwby9i4Jn6kj00X+nmqHSKf0DmjzbYRwn1ncPrWaBy1ofi aPIw== 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:mime-version:content-transfer-encoding; bh=0qqS4w4mRnCRDCTfWQqRgg26scMxtoAIPpRe2SvN8Gk=; b=leolTC7Zdcjp8jUYrJNKeTMLi4DRAe4PLqLlwix3kB9/T7YuYikH50/tiHeEeAmFKP 0JiKlYHzsjnkBZwZ1S9FBo5J9QDZjBEyMh4evIE6M/1mvTgg5fEhsH6L9VDAUo9qrj8q uHBehSE+WnwDP+8I40hLpRMxeazXzTRyqzGijhFDi6iOAfsspTGDG1zZ9sFT4uA6p1c8 hgkmzxcJ09kAxasZPf59jGRelZt/1JwVMgS5bP/U40DSGqCTiZIxvtcrOkjeYTz0Jia1 Q4JFZBQwneE5JZmLOzXLvvi7rjlmQACvq6Vo68iqs7wSqT9NnpmrJojwg3TjUs1rrFl7 8fLQ== X-Gm-Message-State: AOAM530ol0msfAa/D/+1gsDn9nSQXd2NykucXYQXs8VJWAkixjBQHWXr tgeY3Ebl8PC0tp5t6+vi8dzSXw== X-Received: by 2002:a05:6000:1c8:: with SMTP id t8mr56219990wrx.73.1594105745480; Tue, 07 Jul 2020 00:09:05 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o9sm26892564wrs.1.2020.07.07.00.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 00:09:02 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A638F1FF8C; Tue, 7 Jul 2020 08:08:58 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 02/41] util/coroutine: Cleanup start_switch_fiber_ for TSAN. Date: Tue, 7 Jul 2020 08:08:19 +0100 Message-Id: <20200707070858.6622-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200707070858.6622-1-alex.bennee@linaro.org> References: <20200707070858.6622-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42c.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_HELO_NONE=0.001, SPF_PASS=-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: Kevin Wolf , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Stefan Hajnoczi , Robert Foley Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Robert Foley This is a cleanup patch to follow-up the patch which introduced TSAN. This patch makes separate start_switch_fiber_ functions for TSAN and ASAN. This does two things: 1. Unrelated ASAN and TSAN code is separate and each function only has arguments that are actually needed. 2. The co->tsan_caller_fiber and co->tsan_co_fiber fields are only access from within #ifdef CONFIG_TSAN. Signed-off-by: Robert Foley Reviewed-by: Stefan Hajnoczi Signed-off-by: Alex Bennée Message-Id: <20200626170001.27017-1-robert.foley@linaro.org> Message-Id: <20200701135652.1366-5-alex.bennee@linaro.org> -- 2.20.1 diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index f0b66320e102..fff20aad80a4 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -52,8 +52,10 @@ typedef struct { #endif sigjmp_buf env; +#ifdef CONFIG_TSAN void *tsan_co_fiber; void *tsan_caller_fiber; +#endif #ifdef CONFIG_VALGRIND_H unsigned int valgrind_stack_id; @@ -77,7 +79,10 @@ union cc_arg { int i[2]; }; -/* QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. */ +/* + * QEMU_ALWAYS_INLINE only does so if __OPTIMIZE__, so we cannot use it. + * always_inline is required to avoid TSan runtime fatal errors. + */ static inline __attribute__((always_inline)) void on_new_fiber(CoroutineUContext *co) { @@ -87,6 +92,7 @@ void on_new_fiber(CoroutineUContext *co) #endif } +/* always_inline is required to avoid TSan runtime fatal errors. */ static inline __attribute__((always_inline)) void finish_switch_fiber(void *fake_stack_save) { @@ -109,18 +115,29 @@ void finish_switch_fiber(void *fake_stack_save) #endif } -static inline __attribute__((always_inline)) void start_switch_fiber( - CoroutineAction action, void **fake_stack_save, - const void *bottom, size_t size, void *new_fiber) +/* always_inline is required to avoid TSan runtime fatal errors. */ +static inline __attribute__((always_inline)) +void start_switch_fiber_asan(CoroutineAction action, void **fake_stack_save, + const void *bottom, size_t size) { #ifdef CONFIG_ASAN __sanitizer_start_switch_fiber( action == COROUTINE_TERMINATE ? NULL : fake_stack_save, bottom, size); #endif +} + +/* always_inline is required to avoid TSan runtime fatal errors. */ +static inline __attribute__((always_inline)) +void start_switch_fiber_tsan(void **fake_stack_save, + CoroutineUContext *co, + bool caller) +{ #ifdef CONFIG_TSAN - void *curr_fiber = - __tsan_get_current_fiber(); + void *new_fiber = caller ? + co->tsan_caller_fiber : + co->tsan_co_fiber; + void *curr_fiber = __tsan_get_current_fiber(); __tsan_acquire(curr_fiber); *fake_stack_save = curr_fiber; @@ -144,12 +161,9 @@ static void coroutine_trampoline(int i0, int i1) /* Initialize longjmp environment and switch back the caller */ if (!sigsetjmp(self->env, 0)) { - start_switch_fiber( - COROUTINE_YIELD, - &fake_stack_save, - leader.stack, - leader.stack_size, - self->tsan_caller_fiber); + start_switch_fiber_asan(COROUTINE_YIELD, &fake_stack_save, leader.stack, + leader.stack_size); + start_switch_fiber_tsan(&fake_stack_save, self, true); /* true=caller */ siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } @@ -208,10 +222,10 @@ Coroutine *qemu_coroutine_new(void) /* swapcontext() in, siglongjmp() back out */ if (!sigsetjmp(old_env, 0)) { - start_switch_fiber( - COROUTINE_YIELD, - &fake_stack_save, - co->stack, co->stack_size, co->tsan_co_fiber); + start_switch_fiber_asan(COROUTINE_YIELD, &fake_stack_save, co->stack, + co->stack_size); + start_switch_fiber_tsan(&fake_stack_save, + co, false); /* false=not caller */ #ifdef CONFIG_SAFESTACK /* @@ -287,8 +301,10 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, ret = sigsetjmp(from->env, 0); if (ret == 0) { - start_switch_fiber(action, &fake_stack_save, - to->stack, to->stack_size, to->tsan_co_fiber); + start_switch_fiber_asan(action, &fake_stack_save, to->stack, + to->stack_size); + start_switch_fiber_tsan(&fake_stack_save, + to, false); /* false=not caller */ siglongjmp(to->env, action); }