Received: by 10.223.185.116 with SMTP id b49csp1924869wrg; Mon, 12 Feb 2018 00:54:34 -0800 (PST) X-Google-Smtp-Source: AH8x224tdXTvafPVyYJxwEZAgS8T+J2B7zFSKrkGVWClBGjxrDKAf4jKiiEcTtK+aGoqbu+wvPvT X-Received: by 10.98.196.204 with SMTP id h73mr11182337pfk.143.1518425674230; Mon, 12 Feb 2018 00:54:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518425674; cv=none; d=google.com; s=arc-20160816; b=GC+cvFXc9yLHoP3UWsikT9P3AFPYEs+FFtVHrNtUE5PjUMp+OqSFiIJPjd50G3I0D5 Rh40TYHp660oOkKfD+kF8HOZi5KPOr9eOp5OOBqKbClN54XUOzW0NJPcEVM8h0Ht29S5 +VlZncdzxMrC7uTBSB9imGbWYMXqo4m3j9oH2jHccEv9unghO/RHeeVWSK5djr5EkjJq semFBLAQ2+gv2xvIqK07URQEOQX7PTsJgUN5+ccnoC387zdNI2ZPqeLnuhQhD7bQf1Dt wFLju9Uf0mXQLiesF/vs3L6Ojzean35/PFfud543ASwEXhvhQJlxIKCw/Y6wE3Kad6EG td/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Cva+kIWUu97UOgGY6NKCRgY3n0lPGNN6RAKOYGtwcd0=; b=omA7KnuR9+Sds3uZpDNhU3jkPQHrazr3F118K4YeQkZRpzsqJtshVJ+eaxRdbG2/yA /5+7R5HycqNAia3SnfBspSFjM9RSDYr59u4fxHbXv3/ub/sZo4Ose15xRBmo3kIgsvZ2 ho3m0MYVIT0SohNVqzr+x1QotK+D7QTJdLKpUoZq6vwEroK/q2+iVAM42klcVJcdMumZ OlPN+W+CxAfrTgcA8CR1OjTlzmAALxR53zUQsbsefhtSXBbsWzdMEFu5203ClkB44B+6 Gz5t6sYBa3yR9mvLGvvyfeftjeYSrsibnJ679rzg4OgYhP/8WGHrSFkqDfzeMyOe1RAb wlfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ssADkrGS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i77si6105184pfd.15.2018.02.12.00.54.19; Mon, 12 Feb 2018 00:54:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2017-10-26 header.b=ssADkrGS; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932798AbeBLInn (ORCPT + 99 others); Mon, 12 Feb 2018 03:43:43 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:36236 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932504AbeBLInm (ORCPT ); Mon, 12 Feb 2018 03:43:42 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1C8hJlN117681; Mon, 12 Feb 2018 08:43:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2017-10-26; bh=Cva+kIWUu97UOgGY6NKCRgY3n0lPGNN6RAKOYGtwcd0=; b=ssADkrGSsuueKdBwhFQjlnhictODbPU7l7KDUWkK5MNJqlU29i8kfwXwx4cmpy+ZhtSw qrf4qohl+moCfPILOugOQYoPQbitzC0kn4Gy9vhjTLUDuXEXl2mshMPvR5H0Vo6+qeGp XZ7e9LYrQa98H8a/fqv5WQuKP4ylRudgDM+V3PemUIeE/uMQBqONKui33QYPZC+pBhCJ xkdYe3nrNL8BW9hVt0JlDoeyvfdLsnevqsV87zC2xknvo4KaN69xlLR6fNU2CIqjb9/H oAucMRMnZ449slY3S8hy1Z4bfiwgoXskphItCcEv5t1gmLp5yfjhWUceiHO8qU+Ieyaw 5g== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2g371h04dj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 12 Feb 2018 08:43:29 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w1C8gJLG004841 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 12 Feb 2018 08:42:19 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1C8gHkd008310; Mon, 12 Feb 2018 08:42:18 GMT Received: from mwanda (/197.254.35.146) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 12 Feb 2018 00:42:17 -0800 Date: Mon, 12 Feb 2018 11:42:05 +0300 From: Dan Carpenter To: kys@microsoft.com, Stephen Hemminger Cc: gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, devel@linuxdriverproject.org, olaf@aepfle.de, apw@canonical.com, vkuznets@redhat.com, jasowang@redhat.com, leann.ogasawara@canonical.com, marcelo.cerri@canonical.com, sthemmin@microsoft.com, Michael Kelley Subject: Re: [PATCH 08/12] Drivers: hv: vmbus: Implement Direct Mode for stimer0 Message-ID: <20180212084205.idjf2lwrdn2nprw7@mwanda> References: <20180212002958.6679-1-kys@exchange.microsoft.com> <20180212003320.6748-1-kys@exchange.microsoft.com> <20180212003320.6748-8-kys@exchange.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180212003320.6748-8-kys@exchange.microsoft.com> User-Agent: NeoMutt/20170609 (1.8.3) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8802 signatures=668668 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802120113 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Feb 11, 2018 at 05:33:16PM -0700, kys@exchange.microsoft.com wrote: > @@ -116,9 +146,29 @@ static int hv_ce_set_oneshot(struct clock_event_device *evt) > { > union hv_timer_config timer_cfg; > > + timer_cfg.as_uint64 = 0; > timer_cfg.enable = 1; > timer_cfg.auto_enable = 1; > - timer_cfg.sintx = VMBUS_MESSAGE_SINT; > + if (direct_mode_enabled) > + /* > + * When it expires, the timer will directly interrupt > + * on the specified hardware vector/IRQ. > + */ > + { > + timer_cfg.direct_mode = 1; > + timer_cfg.apic_vector = stimer0_vector; > + hv_enable_stimer0_percpu_irq(stimer0_irq); > + } > + else > + /* > + * When it expires, the timer will generate a VMbus message, > + * to be handled by the normal VMbus interrupt handler. > + */ > + { > + timer_cfg.direct_mode = 0; > + timer_cfg.sintx = VMBUS_MESSAGE_SINT; > + } > + This indenting isn't right. We should probably zero out .apic_vector if .direct_mode is zero. Or maybe it's fine. I don't know if any static analysis tools will complain... > hv_init_timer_config(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64); > > return 0; > @@ -191,6 +241,10 @@ int hv_synic_alloc(void) > INIT_LIST_HEAD(&hv_cpu->chan_list); > } > > + if (direct_mode_enabled && hv_setup_stimer0_irq( > + &stimer0_irq, &stimer0_vector, hv_stimer0_isr)) > + goto err; Can you indent it like this: if (direct_mode_enabled && hv_setup_stimer0_irq(&stimer0_irq, &stimer0_vector, hv_stimer0_isr)) goto err; [ What follows is a long rant not directed at you ] It's annoying because as soon as I see the "goto err;", I know the error handling for this function is going to be buggy... Some rules of error handling are: 1) Each function should clean up after itself instead returning partially allocated structures. 2) Each allocation function should have a matching free function. 3) Give meaningful label names based on what the label location so that we can tell what the goto does just by looking at it, such as, "goto free_some_variable". This way we can just keep a mental tally of the most recently allocated resource and verify based on the "goto free_resource;" statemetn that it frees the correct thing. We don't need to scroll to the bottom of the function. Using good names means that we should avoid do-nothing gotos because, by definition, the label name for a do-nothing goto is going to be vague. In this case the label looks like this: > + > return 0; > err: > return -ENOMEM; We allocate a bunch of stuff in this function so at first glance this looks like we leak everything but, actually, the cleanup is done in vmbus_bus_init(). This is a layering violation. Later on, we changed hv_synic_alloc() in 37cdd991fac8 ("vmbus: put related per-cpu variable together") and we started allocating: hv_cpu->clk_evt = kzalloc(... but we forgot to update the error handling because it was in the wrong place. It's a very predictable, avoidable bug if we just use proper error handling style. Anyway... Sorry for the long rant. Summary: Always distrust vague label names. regards, dan carpenter