Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3004140ybi; Mon, 17 Jun 2019 14:29:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4TcZjHtyXniv/UAlEvojBwcYiSdR1RjJEOMGBMIZb4/XcJpsxavcpBmtagvME48fU6RHx X-Received: by 2002:a17:902:1003:: with SMTP id b3mr111578963pla.172.1560806945860; Mon, 17 Jun 2019 14:29:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560806945; cv=none; d=google.com; s=arc-20160816; b=xvByFXzEALWqekWUPVry278+O3DXA7WYEwDrnYyOHaQEo2DzRdikW6v43H2YoGdZa+ nrbYEnuaZLDD3XpHwLrUm6KCqA0UMklrBXw8s/XUB0GQX4Pw2HTJLFFoqFgzTUPViPq0 N6jC6h2qoTI3kvdbR0f0iadpvOnvfu7MwACrSvV2xbuIJ7Hx2y5FIZ2tYSQn74wCsFF0 kSNy/xcT7pHih2DDnOGXy/+92dGzzrV4dy6aaeUHufRA3qEf52u/skT3o7j/Wn6R2yYt p3O0CYVYz7X3DcmwdIEykd3G4ElgqZuhdwX6RtWnvY60p5YYdhM/Hq+DRtvmggmbLUzt pVAQ== 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=ZIVslmaO2AnH4Agg6KM8TXKLmPHzt+pf/Z9P8vB5NVA=; b=eeVp6je1EhuXN3yXG57R6yKD0k8ijm+btXnko5HowdwP9lHpeGnVDBcfFNZyt9dWUS EoXTdJKpgd5/ia4XvHzv6yDIzRLUkltgkf2VP7W/0jNuxELKXKsrYloTwcpeL2N2f0oY 0x2FiheUHHHvnfW8t5V3Pq+wh+PqVb7OQlN1vjno+oU26YEODld7pHA/BdgvfKtLO5It j8Q15ldJWLB+Uq96XdOLXscx7ST7Eu1Ox4dgAYJUpiEimKS28IoiMhbnmUP2kjdna1W+ QJ4kg3PA3eCW9OZi0128oO9B4wAsFVOiCD90EIo+mhdoPPNQfu0+uKURO8ODmypmD78Q n4Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o83NuleD; 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 b18si11943481pgm.82.2019.06.17.14.28.50; Mon, 17 Jun 2019 14:29:05 -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=o83NuleD; 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 S1730335AbfFQV1E (ORCPT + 99 others); Mon, 17 Jun 2019 17:27:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:53858 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730332AbfFQV1D (ORCPT ); Mon, 17 Jun 2019 17:27:03 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 E279120673; Mon, 17 Jun 2019 21:27:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806822; bh=l2iPqIbRA3NdXoDeJJJLOAyo1gE2Xi1qHojbMW/AEHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o83NuleDa2JXeOlIOxiaF+ngC8SbgXYtGYJ8snrhbVK86xKSzLPiJj/ie3SW1/Z/W vG/A93wL10+uzNYbZnEDNoCaNOcuFS8lsYAabLxO+2H/FzWsJWP5jOJOSfODD+Zox3 LEeI0O9OeSO/VCfox8uru7/obDF1y12cXAcnezRA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Cong Wang , Borislav Petkov , Thomas Gleixner , Tony Luck , linux-edac Subject: [PATCH 4.19 67/75] RAS/CEC: Convert the timer callback to a workqueue Date: Mon, 17 Jun 2019 23:10:18 +0200 Message-Id: <20190617210755.733537007@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210752.799453599@linuxfoundation.org> References: <20190617210752.799453599@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Cong Wang commit 0ade0b6240c4853cf9725924c46c10f4251639d7 upstream. cec_timer_fn() is a timer callback which reads ce_arr.array[] and updates its decay values. However, it runs in interrupt context and the mutex protection the CEC uses for that array, is inadequate. Convert the used timer to a workqueue to keep the tasks the CEC performs preemptible and thus low-prio. [ bp: Rewrite commit message. s/timer/decay/gi to make it agnostic as to what facility is used. ] Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector") Signed-off-by: Cong Wang Signed-off-by: Borislav Petkov Cc: Thomas Gleixner Cc: Tony Luck Cc: linux-edac Cc: Link: https://lkml.kernel.org/r/20190416213351.28999-2-xiyou.wangcong@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/ras/cec.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) --- a/drivers/ras/cec.c +++ b/drivers/ras/cec.c @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -123,16 +124,12 @@ static u64 dfs_pfn; /* Amount of errors after which we offline */ static unsigned int count_threshold = COUNT_MASK; -/* - * The timer "decays" element count each timer_interval which is 24hrs by - * default. - */ - -#define CEC_TIMER_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */ -#define CEC_TIMER_MIN_INTERVAL 1 * 60 * 60 /* 1h */ -#define CEC_TIMER_MAX_INTERVAL 30 * 24 * 60 * 60 /* one month */ -static struct timer_list cec_timer; -static u64 timer_interval = CEC_TIMER_DEFAULT_INTERVAL; +/* Each element "decays" each decay_interval which is 24hrs by default. */ +#define CEC_DECAY_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */ +#define CEC_DECAY_MIN_INTERVAL 1 * 60 * 60 /* 1h */ +#define CEC_DECAY_MAX_INTERVAL 30 * 24 * 60 * 60 /* one month */ +static struct delayed_work cec_work; +static u64 decay_interval = CEC_DECAY_DEFAULT_INTERVAL; /* * Decrement decay value. We're using DECAY_BITS bits to denote decay of an @@ -160,20 +157,21 @@ static void do_spring_cleaning(struct ce /* * @interval in seconds */ -static void cec_mod_timer(struct timer_list *t, unsigned long interval) +static void cec_mod_work(unsigned long interval) { unsigned long iv; - iv = interval * HZ + jiffies; - - mod_timer(t, round_jiffies(iv)); + iv = interval * HZ; + mod_delayed_work(system_wq, &cec_work, round_jiffies(iv)); } -static void cec_timer_fn(struct timer_list *unused) +static void cec_work_fn(struct work_struct *work) { + mutex_lock(&ce_mutex); do_spring_cleaning(&ce_arr); + mutex_unlock(&ce_mutex); - cec_mod_timer(&cec_timer, timer_interval); + cec_mod_work(decay_interval); } /* @@ -374,15 +372,15 @@ static int decay_interval_set(void *data { *(u64 *)data = val; - if (val < CEC_TIMER_MIN_INTERVAL) + if (val < CEC_DECAY_MIN_INTERVAL) return -EINVAL; - if (val > CEC_TIMER_MAX_INTERVAL) + if (val > CEC_DECAY_MAX_INTERVAL) return -EINVAL; - timer_interval = val; + decay_interval = val; - cec_mod_timer(&cec_timer, timer_interval); + cec_mod_work(decay_interval); return 0; } DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n"); @@ -426,7 +424,7 @@ static int array_dump(struct seq_file *m seq_printf(m, "Flags: 0x%x\n", ca->flags); - seq_printf(m, "Timer interval: %lld seconds\n", timer_interval); + seq_printf(m, "Decay interval: %lld seconds\n", decay_interval); seq_printf(m, "Decays: %lld\n", ca->decays_done); seq_printf(m, "Action threshold: %d\n", count_threshold); @@ -472,7 +470,7 @@ static int __init create_debugfs_nodes(v } decay = debugfs_create_file("decay_interval", S_IRUSR | S_IWUSR, d, - &timer_interval, &decay_interval_ops); + &decay_interval, &decay_interval_ops); if (!decay) { pr_warn("Error creating decay_interval debugfs node!\n"); goto err; @@ -508,8 +506,8 @@ void __init cec_init(void) if (create_debugfs_nodes()) return; - timer_setup(&cec_timer, cec_timer_fn, 0); - cec_mod_timer(&cec_timer, CEC_TIMER_DEFAULT_INTERVAL); + INIT_DELAYED_WORK(&cec_work, cec_work_fn); + schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL); pr_info("Correctable Errors collector initialized.\n"); }