From nobody Thu Dec 18 14:12:57 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1656762454; cv=none; d=zohomail.com; s=zohoarc; b=KeSAMhG9jkphvM97mlRDGYKjAqFKXEu0TF5mueE9HL1NeiEbIJIvYiI58S+Jlwoz4l1HVPofd6hccrIsSIgnEfxRpwuD8IOQQ1JZWCschHGxa13iCwrn4rk3BJBT3eqc/17jRqT9osXiujdPxusH8Y+HYsMEIDF1Hu6wbawIdNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1656762454; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qgAvujYqizfhFzEg/64loORf7tkDYZhXuaubHSCsHLM=; b=IgwEiyirNiavdQOh187Iz5BPRDf839PrYEZigw46VyFDWBgLPVgTkhmiKjaqWkWSORbioudj+y9c7JWIvrrn4ABIlLb957W2FTcJYUjSmtbbay5ozRClURDY+i7cY27c/xHYsoIfvxUN/AkXTxivLr2IkCZIQ1z2iLc/BoAL3C4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1656762454040530.8109911077709; Sat, 2 Jul 2022 04:47:34 -0700 (PDT) Received: from localhost ([::1]:51896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7bb2-00015G-6R for importer@patchew.org; Sat, 02 Jul 2022 07:47:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7bO3-0003RD-OI for qemu-devel@nongnu.org; Sat, 02 Jul 2022 07:34:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:26839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7bO1-0007zm-Ut for qemu-devel@nongnu.org; Sat, 02 Jul 2022 07:34:07 -0400 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-53-I_GKM4V1NfeADn2PeqoCzQ-1; Sat, 02 Jul 2022 07:34:02 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BDE991C068E2; Sat, 2 Jul 2022 11:34:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.39.194.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 853A1492C3B; Sat, 2 Jul 2022 11:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1656761645; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qgAvujYqizfhFzEg/64loORf7tkDYZhXuaubHSCsHLM=; b=FH2x2UesCPQfh1wY/XuraaxZiJQ/A2G7MR3Za0gg49c0cbVcpAS0PmQRrJTTvQzjOrLuKh 6Ot5Wq26T+KVZ9YIgIbI0LJPQBk5gLu3w6m9bemey9uiCf/5p0ZVF/aBJv7ZHTmA0qvYQn iXLJe5yzKG5nQtleTZj1i7KMwCUkoWc= X-MC-Unique: I_GKM4V1NfeADn2PeqoCzQ-1 From: Alberto Faria To: qemu-devel@nongnu.org Cc: Paolo Bonzini , qemu-block@nongnu.org, "Denis V. Lunev" , Emanuele Giuseppe Esposito , Stefan Hajnoczi , Ronnie Sahlberg , Hanna Reitz , Stefano Garzarella , Kevin Wolf , Peter Xu , Alberto Garcia , John Snow , Eric Blake , Fam Zheng , Markus Armbruster , Vladimir Sementsov-Ogievskiy , Peter Lieven , Alberto Faria Subject: [RFC 7/8] block: Add no_coroutine_fn marker Date: Sat, 2 Jul 2022 12:33:30 +0100 Message-Id: <20220702113331.2003820-8-afaria@redhat.com> In-Reply-To: <20220702113331.2003820-1-afaria@redhat.com> References: <20220702113331.2003820-1-afaria@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 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=170.10.129.124; envelope-from=afaria@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1656762454883100001 Content-Type: text/plain; charset="utf-8" When applied to a function, it advertises that it should not be called from coroutine_fn functions. Make generated_co_wrapper evaluate to no_coroutine_fn, as coroutine_fn functions should instead directly call the coroutine_fn that backs the generated_co_wrapper. Extend static-analyzer.py's "coroutine-annotation-validity" and "coroutine-calls" checks to enforce no_coroutine_fn rules. Signed-off-by: Alberto Faria --- include/block/block-common.h | 2 +- include/qemu/coroutine.h | 12 ++++++++++++ static-analyzer.py | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/include/block/block-common.h b/include/block/block-common.h index fdb7306e78..4b60c8c6f2 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -42,7 +42,7 @@ * * Read more in docs/devel/block-coroutine-wrapper.rst */ -#define generated_co_wrapper +#define generated_co_wrapper no_coroutine_fn =20 /* block.c */ typedef struct BlockDriver BlockDriver; diff --git a/include/qemu/coroutine.h b/include/qemu/coroutine.h index 40a4037525..11eea8cc79 100644 --- a/include/qemu/coroutine.h +++ b/include/qemu/coroutine.h @@ -48,6 +48,18 @@ #define coroutine_fn #endif =20 +/** + * Mark a function that should never be called from a coroutine context + * + * This typically means that there is an analogous, coroutine_fn function = that + * should be used instead. + */ +#ifdef __clang__ +#define no_coroutine_fn __attribute__((__annotate__("no_coroutine_fn"))) +#else +#define no_coroutine_fn +#endif + /** * This can wrap a call to a coroutine_fn from a non-coroutine_fn function= and * suppress the static analyzer's complaints. diff --git a/static-analyzer.py b/static-analyzer.py index 485d054052..ad7ee1ccf5 100755 --- a/static-analyzer.py +++ b/static-analyzer.py @@ -459,6 +459,12 @@ def check_coroutine_annotation_validity( ): log(node, "invalid coroutine_fn usage") =20 + if is_annotation(node, "no_coroutine_fn") and ( + ancestors[-1] is None + or not is_valid_no_coroutine_fn_usage(ancestors[-1]) + ): + log(node, "invalid no_coroutine_fn usage") + if is_comma_wrapper( node, "__allow_coroutine_fn_call" ) and not is_valid_allow_coroutine_fn_call_usage(node): @@ -478,6 +484,9 @@ def log_annotation_disagreement(annotation: str) -> Non= e: if is_coroutine_fn(node) !=3D is_coroutine_fn(node.canonical): log_annotation_disagreement("coroutine_fn") =20 + if is_no_coroutine_fn(node) !=3D is_no_coroutine_fn(node.canon= ical): + log_annotation_disagreement("no_coroutine_fn") + =20 @check("coroutine-calls") def check_coroutine_calls( @@ -516,6 +525,11 @@ def check_coroutine_calls( ): log(call, "non-coroutine_fn function calls coroutine_fn") =20 + # reject calls from coroutine_fn to no_coroutine_fn + + if caller_is_coroutine and is_no_coroutine_fn(callee): + log(call, f"coroutine_fn calls no_coroutine_fn function") + =20 @check("coroutine-pointers") def check_coroutine_pointers( @@ -704,6 +718,16 @@ def parent_type_is_function_pointer() -> bool: return False =20 =20 +def is_valid_no_coroutine_fn_usage(parent: Cursor) -> bool: + """ + Checks if an occurrence of `no_coroutine_fn` represented by a node with + parent `parent` appears at a valid point in the AST. This is the case = if the + parent is a function declaration/definition. + """ + + return parent.kind =3D=3D CursorKind.FUNCTION_DECL + + def is_valid_allow_coroutine_fn_call_usage(node: Cursor) -> bool: """ Check if an occurrence of `__allow_coroutine_fn_call()` represented by= node @@ -771,6 +795,17 @@ def is_coroutine_fn(node: Cursor) -> bool: return False =20 =20 +def is_no_coroutine_fn(node: Cursor) -> bool: + """ + Checks whether the given `node` should be considered to be + `no_coroutine_fn`. + + This assumes valid usage of `no_coroutine_fn`. + """ + + return is_annotated_with(node, "no_coroutine_fn") + + def is_annotated_with(node: Cursor, annotation: str) -> bool: return any(is_annotation(c, annotation) for c in node.get_children()) =20 --=20 2.36.1