Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2678076imj; Mon, 11 Feb 2019 06:55:01 -0800 (PST) X-Google-Smtp-Source: AHgI3IaWri1aD4JFDo5/FBoGxX9rO/pFXiaNK8WjidXOaOK3koweYMI07knXsp8Xf5SNBz1mNJjY X-Received: by 2002:a17:902:bc89:: with SMTP id bb9mr16554379plb.212.1549896901131; Mon, 11 Feb 2019 06:55:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549896901; cv=none; d=google.com; s=arc-20160816; b=nwWLLp5E6pP/4XCCra4rpCYvVxqfejnwgTMS+HnSrxtJykW2KooyyRgoPr66NXzGvp QTfHcCqT/b22O7v4gK9rg2WLw8nAB1cW7JREAA7tFSa6qEUSFB+1wFFr7lu1kyCEhFss WDFJUQ7Cl9H6wCIV24+z+q5p6WGwtqsq5PfPS5RbY5VBrbeOwhQVnzB0ZGNwO4yfO4EX /sQr63QyjaeyuN6lFXgulPzCjgyIK8RsZ5CQSuesAs6Z9s4L/eoVgQ60QIW6Hu94J54H CLmerNGnyo1taK/5yapZlH7ySFbzOSclW3iN23OMfroLL0H+UIqoOsNyc/9sm00m+VGb FNsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yenh1AJnZvaXbifJWHYThD/RWLI0ceDp7ze4/wNnGwQ=; b=Q8TUq+7I+4+Az4fBAuEkIU9b0NRHyN9Nqf4jcbmvTT7DsHEOqdRN3gdOm71iI+5FLB wsyodN8C8SGHkmMx+xHxIlwonCtxMkqser9kXrlUt+Uy46lktRZYoVv222LOLzvLnd2f 3BJiqVQzsNd7GaHhJV6PYx4oIQpuRFisBGGhuLfalmM9w4aYPCnXNCOnDUXpMKM4GlZg pxe6jx1NzAPHEh3qDJIwBefwDsNeAuL6iwxi6vrFo5z6KUKEcGDz4qUdoDacODUWE77s H3LpQPwfB5g/WeWLd7dQvUvzk4Rlj43xKhtfAl9VHsrFZ375jK+5vNGto+7Jejok9LYF cbBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MgZEXKh7; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h4si4232239pgl.409.2019.02.11.06.54.44; Mon, 11 Feb 2019 06:55:01 -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=@kernel.org header.s=default header.b=MgZEXKh7; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388741AbfBKOxu (ORCPT + 99 others); Mon, 11 Feb 2019 09:53:50 -0500 Received: from mail.kernel.org ([198.145.29.99]:40288 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387780AbfBKOxq (ORCPT ); Mon, 11 Feb 2019 09:53:46 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 07D5520700; Mon, 11 Feb 2019 14:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549896825; bh=RvbQBeaXP2ONzvtX0a2mxmLz7hSu2O566CDDmrjhRxk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MgZEXKh7uQNRvbOXZqcpNTdTjqJO40hOWILad1YgSElgPRI/wwD5jx3tJcyI/Jci2 N5NNego9DXpC85HrHNCPd5FMNTeg9k5VoDaa83iL7rj9k4/63pAG5+OrhTLfR0viuW caCA+zmVH1W0wfPG7Gui9fXKtzvZADwVOlo6vHjU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, He Zhe , Sebastian Andrzej Siewior , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , acme@kernel.org, bp@alien8.de, hpa@zytor.com, jolsa@kernel.org, kan.liang@linux.intel.com, namhyung@kernel.org, Ingo Molnar Subject: [PATCH 4.19 313/313] perf/x86/intel: Delay memory deallocation until x86_pmu_dead_cpu() Date: Mon, 11 Feb 2019 15:19:53 +0100 Message-Id: <20190211141913.704871356@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141852.749630980@linuxfoundation.org> References: <20190211141852.749630980@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Peter Zijlstra commit 602cae04c4864bb3487dfe4c2126c8d9e7e1614a upstream. intel_pmu_cpu_prepare() allocated memory for ->shared_regs among other members of struct cpu_hw_events. This memory is released in intel_pmu_cpu_dying() which is wrong. The counterpart of the intel_pmu_cpu_prepare() callback is x86_pmu_dead_cpu(). Otherwise if the CPU fails on the UP path between CPUHP_PERF_X86_PREPARE and CPUHP_AP_PERF_X86_STARTING then it won't release the memory but allocate new memory on the next attempt to online the CPU (leaking the old memory). Also, if the CPU down path fails between CPUHP_AP_PERF_X86_STARTING and CPUHP_PERF_X86_PREPARE then the CPU will go back online but never allocate the memory that was released in x86_pmu_dying_cpu(). Make the memory allocation/free symmetrical in regard to the CPU hotplug notifier by moving the deallocation to intel_pmu_cpu_dead(). This started in commit: a7e3ed1e47011 ("perf: Add support for supplementary event registers"). In principle the bug was introduced in v2.6.39 (!), but it will almost certainly not backport cleanly across the big CPU hotplug rewrite between v4.7-v4.15... [ bigeasy: Added patch description. ] [ mingo: Added backporting guidance. ] Reported-by: He Zhe Signed-off-by: Peter Zijlstra (Intel) # With developer hat on Signed-off-by: Sebastian Andrzej Siewior Signed-off-by: Peter Zijlstra (Intel) # With maintainer hat on Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: acme@kernel.org Cc: bp@alien8.de Cc: hpa@zytor.com Cc: jolsa@kernel.org Cc: kan.liang@linux.intel.com Cc: namhyung@kernel.org Cc: Fixes: a7e3ed1e47011 ("perf: Add support for supplementary event registers"). Link: https://lkml.kernel.org/r/20181219165350.6s3jvyxbibpvlhtq@linutronix.de Signed-off-by: Ingo Molnar [ He Zhe: Fixes conflict caused by missing disable_counter_freeze which is introduced since v4.20 af3bdb991a5cb. ] Signed-off-by: He Zhe Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/intel/core.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/arch/x86/events/intel/core.c +++ b/arch/x86/events/intel/core.c @@ -3440,6 +3440,11 @@ static void free_excl_cntrs(int cpu) static void intel_pmu_cpu_dying(int cpu) { + fini_debug_store_on_cpu(cpu); +} + +static void intel_pmu_cpu_dead(int cpu) +{ struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu); struct intel_shared_regs *pc; @@ -3451,8 +3456,6 @@ static void intel_pmu_cpu_dying(int cpu) } free_excl_cntrs(cpu); - - fini_debug_store_on_cpu(cpu); } static void intel_pmu_sched_task(struct perf_event_context *ctx, @@ -3541,6 +3544,7 @@ static __initconst const struct x86_pmu .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting, .cpu_dying = intel_pmu_cpu_dying, + .cpu_dead = intel_pmu_cpu_dead, }; static struct attribute *intel_pmu_attrs[]; @@ -3581,6 +3585,8 @@ static __initconst const struct x86_pmu .cpu_prepare = intel_pmu_cpu_prepare, .cpu_starting = intel_pmu_cpu_starting, .cpu_dying = intel_pmu_cpu_dying, + .cpu_dead = intel_pmu_cpu_dead, + .guest_get_msrs = intel_guest_get_msrs, .sched_task = intel_pmu_sched_task, };