From patchwork Sat Jul 9 04:15:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corneliu ZUZU X-Patchwork-Id: 9221979 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 886A860467 for ; Sat, 9 Jul 2016 04:18:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A786286A0 for ; Sat, 9 Jul 2016 04:18:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E791286A5; Sat, 9 Jul 2016 04:18:39 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0CE9F286A0 for ; Sat, 9 Jul 2016 04:18:38 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLjh0-0001iI-75; Sat, 09 Jul 2016 04:16:38 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bLjgy-0001hz-U3 for xen-devel@lists.xen.org; Sat, 09 Jul 2016 04:16:37 +0000 Received: from [85.158.137.68] by server-11.bemta-3.messagelabs.com id 10/CC-03403-4AA70875; Sat, 09 Jul 2016 04:16:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNIsWRWlGSWpSXmKPExsUSfTxjoe7iqoZ wgyM3lC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1ox9++4wFazkqrg/+RJzA+Nhji5GTg4hAXeJ +U+mM3YxcgHZaxglZr+awA7hnGSU2P5jGyNElZtE+9TNUPY6Rom3a6NAbDYBbYlzh+4xgdgiA tIS1z5fBpvELLAUaNKXl+wgCWEBb4mnk96DNbMIqEq0n7sJ1sAr4CJxq/8+UA0Hh4SAnMSCC+ kgYU4BV4lzb1+zQuxykbixbxJYuYRAjsTKZ7OgyqUk/rcqgaySEOhikVi27y07RI2MxKOJN9k mMAotYGRYxahRnFpUllqka2ygl1SUmZ5RkpuYmaNraGCsl5taXJyYnpqTmFSsl5yfu4kRGIj1 DAyMOxg7T/gdYpTkYFIS5b1g2xAuxJeUn1KZkVicEV9UmpNafIhRhoNDSYJXqRIoJ1iUmp5ak ZaZA4wJmLQEB4+SCO/hCqA0b3FBYm5xZjpE6hSjopQ4rwRInwBIIqM0D64NFoeXGGWlhHkZGR gYhHgKUotyM0tQ5V8xinMwKgnz/gcZz5OZVwI3/RXQYiagxQYB9SCLSxIRUlINjFErN98z9p6 Z9EpA+tIdDzmfmefEQqYu5zC+IbJT00zErHndxK7V/Keto+24gpL4r168Mc3q2cunvzb8Mz+o t272m9ZPc1wMb6Seu8PNf6v4cznfzQcy+jOi2Pb0lKxinbHHQKU58FmS9CPDB4dSPXT9/7Y8y ijkd7zC/27x6lVZ5yO4VIr6piuxFGckGmoxFxUnAgC1n92ovgIAAA== X-Env-Sender: czuzu@bitdefender.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1468037795!39935914!1 X-Originating-IP: [91.199.104.161] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.46; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10609 invoked from network); 9 Jul 2016 04:16:35 -0000 Received: from mx01.bbu.dsd.mx.bitdefender.com (HELO mx01.bbu.dsd.mx.bitdefender.com) (91.199.104.161) by server-4.tower-31.messagelabs.com with DHE-RSA-AES128-GCM-SHA256 encrypted SMTP; 9 Jul 2016 04:16:35 -0000 Received: (qmail 11907 invoked from network); 9 Jul 2016 07:16:34 +0300 Received: from unknown (HELO mx-sr.buh.bitdefender.com) (10.17.80.103) by mx01.bbu.dsd.mx.bitdefender.com with AES256-GCM-SHA384 encrypted SMTP; 9 Jul 2016 07:16:34 +0300 Received: from smtp03.buh.bitdefender.org (unknown [10.17.80.77]) by mx-sr.buh.bitdefender.com (Postfix) with ESMTP id 676227FBEA for ; Sat, 9 Jul 2016 07:16:34 +0300 (EEST) Received: (qmail 4434 invoked from network); 9 Jul 2016 07:16:34 +0300 Received: from 188-24-34-246.rdsnet.ro (HELO localhost.localdomain) (czuzu@bitdefender.com@188.24.34.246) by smtp03.buh.bitdefender.org with SMTP; 9 Jul 2016 07:16:34 +0300 From: Corneliu ZUZU To: xen-devel@lists.xen.org Date: Sat, 9 Jul 2016 07:15:57 +0300 Message-Id: <1468037757-6708-1-git-send-email-czuzu@bitdefender.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1468037509-6428-1-git-send-email-czuzu@bitdefender.com> References: <1468037509-6428-1-git-send-email-czuzu@bitdefender.com> X-BitDefender-Scanner: Clean, Agent: BitDefender qmail 3.1.6 on smtp03.buh.bitdefender.org, sigver: 7.66242 X-BitDefender-Spam: No (0) X-BitDefender-SpamStamp: Build: [Engines: 2.15.6.911, Dats: 425852, Stamp: 3], Multi: [Enabled, t: (0.000008, 0.001976)], BW: [Enabled, t: (0.000006,0.000001)], RBL DNSBL: [Disabled], APM: [Enabled, Score: 500, t: (0.002221), Flags: 85D2ED72; NN_NO_CONTENT_TYPE; NN_NO_LINK_NMD; NN_LEGIT_BITDEFENDER; NN_LEGIT_S_SQARE_BRACKETS; NN_LEGIT_MAILING_LIST_TO], SGN: [Enabled, t: (0.008290)], URL: [Enabled, t: (0.000005)], RTDA: [Enabled, t: (0.011210), Hit: No, Details: v2.3.10; Id: 2m1ghhc.1an6q9ac3.1ht], total: 0(775) X-BitDefender-CF-Stamp: none Cc: Andrew Cooper , Tamas K Lengyel , Jan Beulich , Razvan Cojocaru Subject: [Xen-devel] [PATCH 06/16] x86/monitor: fix: set msr_bitmap to NULL after xfree X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Fix: set d->arch.monitor.msr_bitmap to NULL after xfree, as the equivalence of it being NULL and xfreed is repeatedly presumed in the codebase. Along with this change, also properly reposition an 'if' targeting the aforementioned msr_bitmap when it is allocated and add likely/unlikely accordingly. Signed-off-by: Corneliu ZUZU --- xen/arch/x86/monitor.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/monitor.c b/xen/arch/x86/monitor.c index 29188e5..8f41f21 100644 --- a/xen/arch/x86/monitor.c +++ b/xen/arch/x86/monitor.c @@ -54,11 +54,12 @@ static inline void monitor_ctrlreg_disable_traps(struct domain *d) int monitor_init_domain(struct domain *d) { - if ( !d->arch.monitor.msr_bitmap ) + if ( likely(!d->arch.monitor.msr_bitmap) ) + { d->arch.monitor.msr_bitmap = xzalloc(struct monitor_msr_bitmap); - - if ( !d->arch.monitor.msr_bitmap ) - return -ENOMEM; + if ( unlikely(!d->arch.monitor.msr_bitmap) ) + return -ENOMEM; + } return 0; } @@ -66,6 +67,7 @@ int monitor_init_domain(struct domain *d) void monitor_cleanup_domain(struct domain *d) { xfree(d->arch.monitor.msr_bitmap); + d->arch.monitor.msr_bitmap = NULL; monitor_ctrlreg_disable_traps(d);