Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2713996imj; Mon, 11 Feb 2019 07:23:27 -0800 (PST) X-Google-Smtp-Source: AHgI3IZrAZt5eMEwIVDnJQMJDbbh6EBdNZcpAlHEstV0OcHeZeUZEVLRQdK1yDEwXZx4uIBzywL1 X-Received: by 2002:a63:451a:: with SMTP id s26mr34566269pga.150.1549898607189; Mon, 11 Feb 2019 07:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549898607; cv=none; d=google.com; s=arc-20160816; b=r/eZvQVGoLTBbkrYFoOlX/kJnVmclUmjCM+rojR+cGyclT49c46d6A0gzoQthd4k77 IA6JzYDDNGKfn0Xfm2oXgATvemSJuXx/xsEiTmxdaxUMl6jCu2rCddZNvsODdtKzEff+ TIyS/PwXra+W36liM3MmsOStCOZGG4scLlNlnaKYlxdEFnT2o1znRy5i8O39oxjeJJ5c B4sAn6fx34oe3ZSKJu6di6hF0zs15FNj4b5NkKjaz2k+CHyOauZmwFHKNk6nk6YqHQhx vA9aqkEYpLTIoZPkcqhY8K59x4g0XHAuVjiMjzKuviQWHsLv7E82yaLUW7Z1yE8qzQMS xkUg== 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=Lag1uyEcagrJ6ZfbLy24o5wU87AVV6BV+D+fCSubTK0=; b=v5CczRLxG/ho6DNlVakRdGICogxydcr/j3EZuw3s+3A1ys5Do+iqOHml1xb04RgecP FFby4XuCUK8bsJdzHjjAMuhAXoWX1rIV6/nkEsWqXad0pkoN1c25foFCDG6LxEsBsIKW NoC7puJEBgbyl+egq0o0lWA6Tp6NYxGQey7uiXw+4FyDkGK08LZZoYbObE+Je6gug1Gk VcuKZq6UjciI920Hb4fU19ToFBK9MvysyZNaeRf0Bbixpz6bgQlc0sOIRCK9dCZxV4dy KawX2nB+mmL50satfi/rP4CFc/jvu5rsJ2zF8wP7hTFfFuAVKfMYeFKTFFCAsV7UuqR/ FGUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HxZV8vzj; 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 o8si10104603pll.365.2019.02.11.07.23.05; Mon, 11 Feb 2019 07:23:27 -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=HxZV8vzj; 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 S2391663AbfBKPWO (ORCPT + 99 others); Mon, 11 Feb 2019 10:22:14 -0500 Received: from mail.kernel.org ([198.145.29.99]:52930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389916AbfBKPEE (ORCPT ); Mon, 11 Feb 2019 10:04:04 -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 42427222B0; Mon, 11 Feb 2019 15:04:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549897443; bh=PPOGv8G5XmnASdHNzEbiXmlHqaJsV4lXACNu2bsn5tI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HxZV8vzjRMOBd7AOzr4SXVr6oul11rZmVbxh9tD/knuwpoUBxVTeATLoKVW5jBAXO 1ISJTRXmF/a5dkiOPg0OYLCLDuZ8oxOeolgvM1QNk4JHdfeiGCmLDBz9an5GzX5dHE YmPpixx95gMXOTvWSCB7FYqAoV7fgIHZGQ3Fz2WI= 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.14 205/205] perf/x86/intel: Delay memory deallocation until x86_pmu_dead_cpu() Date: Mon, 11 Feb 2019 15:20:03 +0100 Message-Id: <20190211141841.970354596@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211141827.214852402@linuxfoundation.org> References: <20190211141827.214852402@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.14-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 @@ -3420,6 +3420,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; @@ -3431,8 +3436,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, @@ -3521,6 +3524,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[]; @@ -3560,6 +3564,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, };