From nobody Thu May 2 22:50:36 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1593191437; cv=none; d=zohomail.com; s=zohoarc; b=KPa42INUd4dQEyePPUQI7fNIRMYFsmv4KqIQYwbhmM9Y3r5qIaECb5cfqwvmTV4GpdVI+yxt4PySWOUfcnz5b/JlBJkTH6R1aAdkvNlJmUqehfgqmN9fbNojm1pMAbE9wdB+7sveYH7AirR+Yqv55qZoNShdCo8xNwu1aua2mFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593191437; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=EvAUDqwpoFqGrtryxitUaLeigBIhi7ip9x0IrHUD61Y=; b=Kso8sL5D+ypWYlKkizL+712WD70JdYDfMsqRRhcH78zy/pEkTD84Uc63zI0OqvHnP8kdrS5FCAnJMh7KraFhUBjD8HQgVFHnjH+OK0NPvYGjXKapeGbNHUrh4xYr7Y1lRHgxuv4xi41laOajeDwiyfpDXdSnnFN9f+8qGd5w31I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1593191437246143.5288361706721; Fri, 26 Jun 2020 10:10:37 -0700 (PDT) Received: from localhost ([::1]:54808 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jors3-0001iu-Rq for importer@patchew.org; Fri, 26 Jun 2020 13:10:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37560) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jorrQ-0001IW-74 for qemu-devel@nongnu.org; Fri, 26 Jun 2020 13:09:56 -0400 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:40453) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jorrN-00084s-Sw for qemu-devel@nongnu.org; Fri, 26 Jun 2020 13:09:55 -0400 Received: by mail-pf1-x443.google.com with SMTP id u5so4904380pfn.7 for ; Fri, 26 Jun 2020 10:09:52 -0700 (PDT) Received: from Rfoley-MA01.hsd1.ma.comcast.net ([2601:199:4480:60c0:78b5:2b0a:b9c6:c392]) by smtp.gmail.com with ESMTPSA id f18sm9941430pgv.84.2020.06.26.10.09.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2020 10:09:50 -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; bh=EvAUDqwpoFqGrtryxitUaLeigBIhi7ip9x0IrHUD61Y=; b=zDJHILnwduDcH6RBmJa8r6fjAIUIfHZDu47c5dmFEBPaHEL7sYlAYCdK5d0fbtFL35 yKDKdzkgrk8r677LgeSTmJdkgfD2QHTaPyFEBWJpQIOhFlLcNkxrSBbY6Fzjxg1vTWFb rX0HnsJkuK4XoFvovdSobkY1HifiBWgvX6CCeOrU4GHjmZYOGQATeLEfgWm6db2dg0zT oA3TbevuYEvyeUp8Hef0/52zp4sdMg1rwgnRduz9fVc89j4lb+p5TmXTbqVUzUoUnKO8 esskhyGpHTCu2weNjKnE3dSYztRk2HWRnfSLhHe8HjR7ntA3cVGIn1s/2acXcSHhJZuI vLLw== 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; bh=EvAUDqwpoFqGrtryxitUaLeigBIhi7ip9x0IrHUD61Y=; b=c9MMShb30Z5eeEBFwk6ScGKrfyIA9I9jc94GU0AHI01WHGH5EZeV7ywRJdLhgr+U3T v+9v6GVx9/19u0I6s8QD/nTogob6ucuE7fvr7i+xGcNbbRYs+difR4aOdKab7agDANrS 9PEt4KFUBeHIknLZ+84llFESnfmzVNBuZbC6yXWMm/qp1w88d2WK/h7wp+3+/5z5zyP1 JevqzkR4x+AVdERdWSIlirm8q1kQuxY0TZcYdUaB8bvWMppF5A4w3yPQ9OZRLqSKlmPO Aoi4edZPgKCfUqvI7PUh+rhiQ/g68CUo/APibHaU2b6MxxO1w8JyAol/gwq8y1ZnUuiY yW/A== X-Gm-Message-State: AOAM530k2EDPcGpRlpTVqYj8dZbmH/m3hMI0FW/VSWeRTgIiD4lGhIKO 8WcIt30P4ZFkS6wyMgYL4BjLmXQ0V+lNAw== X-Google-Smtp-Source: ABdhPJx1lNkqHIt0Ors+/xf4eTr5kY2vEClMLQ5YEZN6ovjGLI9owQOfPGwKNEgFU1OpCK+YVCHmWA== X-Received: by 2002:a62:3814:: with SMTP id f20mr3706179pfa.278.1593191391031; Fri, 26 Jun 2020 10:09:51 -0700 (PDT) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH] util/coroutine: Cleanup start_switch_fiber_ for TSAN. Date: Fri, 26 Jun 2020 13:00:01 -0400 Message-Id: <20200626170001.27017-1-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::443; envelope-from=robert.foley@linaro.org; helo=mail-pf1-x443.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 , robert.foley@linaro.org, cota@braap.org, Stefan Hajnoczi , peter.puhov@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- util/coroutine-ucontext.c | 52 +++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/util/coroutine-ucontext.c b/util/coroutine-ucontext.c index 613f4c118e..bac164d1f1 100644 --- a/util/coroutine-ucontext.c +++ b/util/coroutine-ucontext.c @@ -47,8 +47,10 @@ typedef struct { size_t stack_size; sigjmp_buf env; =20 +#ifdef CONFIG_TSAN void *tsan_co_fiber; void *tsan_caller_fiber; +#endif =20 #ifdef CONFIG_VALGRIND_H unsigned int valgrind_stack_id; @@ -72,7 +74,10 @@ union cc_arg { int i[2]; }; =20 -/* 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) { @@ -82,6 +87,7 @@ void on_new_fiber(CoroutineUContext *co) #endif } =20 +/* always_inline is required to avoid TSan runtime fatal errors. */ static inline __attribute__((always_inline)) void finish_switch_fiber(void *fake_stack_save) { @@ -104,18 +110,29 @@ void finish_switch_fiber(void *fake_stack_save) #endif } =20 -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_sav= e, + const void *bottom, size_t size) { #ifdef CONFIG_ASAN __sanitizer_start_switch_fiber( action =3D=3D 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 =3D - __tsan_get_current_fiber(); + void *new_fiber =3D caller ? + co->tsan_caller_fiber : + co->tsan_co_fiber; + void *curr_fiber =3D __tsan_get_current_fiber(); __tsan_acquire(curr_fiber); =20 *fake_stack_save =3D curr_fiber; @@ -139,12 +156,9 @@ static void coroutine_trampoline(int i0, int i1) =20 /* 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=3Dc= aller */ siglongjmp(*(sigjmp_buf *)co->entry_arg, 1); } =20 @@ -199,10 +213,10 @@ Coroutine *qemu_coroutine_new(void) =20 /* 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->sta= ck, + co->stack_size); + start_switch_fiber_tsan(&fake_stack_save, + co, false); /* false=3Dnot caller */ swapcontext(&old_uc, &uc); } =20 @@ -259,8 +273,10 @@ qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, =20 ret =3D sigsetjmp(from->env, 0); if (ret =3D=3D 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=3Dnot caller */ siglongjmp(to->env, action); } =20 --=20 2.17.1