Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp2457807imd; Fri, 2 Nov 2018 11:44:39 -0700 (PDT) X-Google-Smtp-Source: AJdET5eHqaUCtyHfH+X2OqCV75cO4ANaNv3FctywFFLyEmBeZL0rLs3DevL7YsxjbQvKlPmYqRXE X-Received: by 2002:a63:b5b:: with SMTP id a27-v6mr11093490pgl.97.1541184279347; Fri, 02 Nov 2018 11:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541184279; cv=none; d=google.com; s=arc-20160816; b=KZpx0opucwsl9B4rYaRx9tVQZvGn2vQmZVdFS1NxjxKD9RPwuYT84maDEoezrHBAeo JjMciXJRj7BcpOK7Ue1Bm/8pyVO0kmOAoJYlalgbue2fc0NGLygwdQ/ymKlTL2RXEyNt 1lf126/hY7CyrrdlXeRPgoprGRmsncGKPHCi3e/eU7lxU+iO0pepT19FzUjZOLn+bNwQ hcOi2LAs8IRLb4iPiCUrMp8MtY0iBXROLlLoiMR1RaQjMMVQ/sFEJFOWYOENZGISu2PT L/RW4NE3jf299/5zNkY7tyUKCjw+gTPz04oZajym/wcKqdL/E5Lq6vIaXcfeXmS+XP3p jgSQ== 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=44eTR1/NO0WomDpcp1r4tYSfJbqpjZux+ccepHmZA4g=; b=vTUUadIL6Vt7SyQReiGZ9AqZwXy+5fZaBTANBsOOXKJKBWWIK7gZZTEAXagFWjdGu1 aFSPfwif/EhDXep2eJp518uf9WBvWK0aJpxKe5WDrMcjirgSQLD2HIz4l/uGWW2VdvWb BFr/oDxlBa9nXU868nswYHtH/DPBWaIST5Cpb/2Lo0ScaCxofyAzq9kS4LmFG6F5C9sj /nLmGbdOUHp7+Y08WcFH0br9BBgg+Mp4ThT+AGHfk+zKqrrZmLX0Eh7TnwSM175ulNfY iLNuHH3jjxYUeehsQfYaEZNoFK6CUeekh0iPa4wlww0cO14NUwXs0ZaJWUrRETLFkkTz e/fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=x6hlUqhO; 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 p23si1469088pgk.312.2018.11.02.11.44.24; Fri, 02 Nov 2018 11:44:39 -0700 (PDT) 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=x6hlUqhO; 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 S1729751AbeKCDuV (ORCPT + 99 others); Fri, 2 Nov 2018 23:50:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:45340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728835AbeKCDuU (ORCPT ); Fri, 2 Nov 2018 23:50:20 -0400 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 8F7352084D; Fri, 2 Nov 2018 18:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541184128; bh=3HMSJrgDuMBsxUugyZ2QBn7P7qidDA5OH69WhBI6iW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=x6hlUqhOFEfgbI4K3IaGEW8Z721gV+K75Az9XBj5nRqOj4NxhuuczDvSyyB4AYws5 3Uh9y4euhBSlno8hp/6haautTH22yKEXeExsxGv42D9U8qXxhArthwX0rsm0t7ooO/ wMvQWZ0yxnjx4sM2uIhWqFiN6zPKx+QY2JWBXbHA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , Ingo Molnar , Sasha Levin Subject: [PATCH 4.18 053/150] perf/core: Fix perf_pmu_unregister() locking Date: Fri, 2 Nov 2018 19:33:35 +0100 Message-Id: <20181102182907.207786004@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181102182902.250560510@linuxfoundation.org> References: <20181102182902.250560510@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit a9f9772114c8b07ae75bcb3654bd017461248095 ] When we unregister a PMU, we fail to serialize the @pmu_idr properly. Fix that by doing the entire thing under pmu_lock. Signed-off-by: Peter Zijlstra (Intel) Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Fixes: 2e80a82a49c4 ("perf: Dynamic pmu types") Signed-off-by: Ingo Molnar Signed-off-by: Sasha Levin --- kernel/events/core.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index ae22d93701db..b1ed5e99d9c6 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -9436,9 +9436,7 @@ static void free_pmu_context(struct pmu *pmu) if (pmu->task_ctx_nr > perf_invalid_context) return; - mutex_lock(&pmus_lock); free_percpu(pmu->pmu_cpu_context); - mutex_unlock(&pmus_lock); } /* @@ -9694,12 +9692,8 @@ EXPORT_SYMBOL_GPL(perf_pmu_register); void perf_pmu_unregister(struct pmu *pmu) { - int remove_device; - mutex_lock(&pmus_lock); - remove_device = pmu_bus_running; list_del_rcu(&pmu->entry); - mutex_unlock(&pmus_lock); /* * We dereference the pmu list under both SRCU and regular RCU, so @@ -9711,13 +9705,14 @@ void perf_pmu_unregister(struct pmu *pmu) free_percpu(pmu->pmu_disable_count); if (pmu->type >= PERF_TYPE_MAX) idr_remove(&pmu_idr, pmu->type); - if (remove_device) { + if (pmu_bus_running) { if (pmu->nr_addr_filters) device_remove_file(pmu->dev, &dev_attr_nr_addr_filters); device_del(pmu->dev); put_device(pmu->dev); } free_pmu_context(pmu); + mutex_unlock(&pmus_lock); } EXPORT_SYMBOL_GPL(perf_pmu_unregister); -- 2.17.1