From patchwork Tue Aug 30 11:37:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 9305229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 08ABB607F0 for ; Tue, 30 Aug 2016 11:38:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E904A28B49 for ; Tue, 30 Aug 2016 11:38:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB30128B60; Tue, 30 Aug 2016 11:38:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A36428B49 for ; Tue, 30 Aug 2016 11:38:13 +0000 (UTC) Received: from localhost ([::1]:48430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1behMq-0007Wm-B7 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Aug 2016 07:38:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1behMY-0007Vt-Hs for qemu-devel@nongnu.org; Tue, 30 Aug 2016 07:37:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1behMT-0006tr-IM for qemu-devel@nongnu.org; Tue, 30 Aug 2016 07:37:53 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1behMT-0006tk-7Y for qemu-devel@nongnu.org; Tue, 30 Aug 2016 07:37:49 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.11/8.16.0.11) with SMTP id u7UBXvKB042136 for ; Tue, 30 Aug 2016 07:37:48 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2558r4stuu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 30 Aug 2016 07:37:47 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 30 Aug 2016 12:37:45 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 30 Aug 2016 12:37:43 +0100 X-IBM-Helo: d06dlp01.portsmouth.uk.ibm.com X-IBM-MailFrom: cornelia.huck@de.ibm.com X-IBM-RcptTo: qemu-block@nongnu.org;qemu-devel@nongnu.org Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 0543717D805F; Tue, 30 Aug 2016 12:39:32 +0100 (BST) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u7UBbhA122282486; Tue, 30 Aug 2016 11:37:43 GMT Received: from d06av08.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u7UBbhT4030375; Tue, 30 Aug 2016 05:37:43 -0600 Received: from gondolin (dyn-9-152-224-137.boeblingen.de.ibm.com [9.152.224.137]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id u7UBbgi3030354; Tue, 30 Aug 2016 05:37:42 -0600 Date: Tue, 30 Aug 2016 13:37:41 +0200 From: Cornelia Huck To: "Michael S. Tsirkin" In-Reply-To: <20160830141341-mutt-send-email-mst@kernel.org> References: <1472526419-5900-1-git-send-email-jasowang@redhat.com> <1472526419-5900-3-git-send-email-jasowang@redhat.com> <20160830093127.49463d9d.cornelia.huck@de.ibm.com> <20160830130128-mutt-send-email-mst@kernel.org> <20160830130926-mutt-send-email-mst@kernel.org> <20160830131105.74f78a45.cornelia.huck@de.ibm.com> <20160830141341-mutt-send-email-mst@kernel.org> Organization: IBM Deutschland Research & Development GmbH Vorsitzende des Aufsichtsrats: Martina Koederitz =?UTF-8?B?R2VzY2jDpGZ0c2bDvGhydW5nOg==?= Dirk Wittkopp Sitz der Gesellschaft: =?UTF-8?B?QsO2Ymxpbmdlbg==?= Registergericht: Amtsgericht Stuttgart, HRB 243294 X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16083011-0008-0000-0000-000002BA72DD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16083011-0009-0000-0000-0000199EB83E Message-Id: <20160830133741.776e8ff0.cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-08-30_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1604210000 definitions=main-1608300113 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 148.163.156.1 Subject: Re: [Qemu-devel] qom and debug X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Jason Wang , qemu-devel@nongnu.org, peterx@redhat.com, Amit Shah , wexu@redhat.com, Stefan Hajnoczi , vkaplans@redhat.com, pbonzini@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Tue, 30 Aug 2016 14:15:14 +0300 "Michael S. Tsirkin" wrote: > On Tue, Aug 30, 2016 at 01:11:05PM +0200, Cornelia Huck wrote: > > On Tue, 30 Aug 2016 13:21:23 +0300 > > "Michael S. Tsirkin" wrote: > > > > > BTW downstreams are building with --disable-qom-cast-debug which drops > > > all QOM casts on data path - one way is to say we just make this the > > > default upstream as well. Another to say that we want to distinguish > > > fast path calls from slow path, this way we will be able to bring back > > > some of the checks. > > > > I find CONFIG_QOM_CAST_DEBUG a bit inconsistent, btw: > > > > - for object casts, we optimize away all checks and just return the > > object for !debug > > - for class casts, we optimize away only the caching and still keep the > > checking (why would we drop the caching if this can speed up things?) > > > > We certainly want to have debug turned on during development to avoid > > nasty surprises later (otherwise, why even bother?), but it makes sense > > to turn it off for a release. (Is there an easy way to turn it off for > > the release, normal or stable, and keep it during the development > > cycle?) > > I think the assumption was class casts are not on data path. > Ideally we'd keep it on for release too for non-datapath things, > to help improve security. This would probably need some more fine-grained configuration. For now, what about this completely untested patch that at least adds caching for the class->interfaces case if debug is off? diff --git a/qom/object.c b/qom/object.c index 8166b7d..05f1fe4 100644 --- a/qom/object.c +++ b/qom/object.c @@ -696,12 +696,16 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, const char *func) { ObjectClass *ret; + int i; trace_object_class_dynamic_cast_assert(class ? class->type->name : "(null)", typename, file, line, func); -#ifdef CONFIG_QOM_CAST_DEBUG - int i; +#ifndef CONFIG_QOM_CAST_DEBUG + if (!class || !class->interfaces) { + return class; + } +#endif for (i = 0; class && i < OBJECT_CLASS_CAST_CACHE; i++) { if (class->class_cast_cache[i] == typename) { @@ -709,11 +713,6 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, goto out; } } -#else - if (!class || !class->interfaces) { - return class; - } -#endif ret = object_class_dynamic_cast(class, typename); if (!ret && class) { @@ -722,7 +721,6 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, abort(); } -#ifdef CONFIG_QOM_CAST_DEBUG if (class && ret == class) { for (i = 1; i < OBJECT_CLASS_CAST_CACHE; i++) { class->class_cast_cache[i - 1] = class->class_cast_cache[i]; @@ -730,7 +728,6 @@ ObjectClass *object_class_dynamic_cast_assert(ObjectClass *class, class->class_cast_cache[i - 1] = typename; } out: -#endif return ret; }