Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3009483ybi; Mon, 17 Jun 2019 14:35:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxM3AAN6nNhqs08q55Fzw4WX5LgHXcW2OzfTS4swlgu+hJ4fiwRyGbwxZyVuH8Hq5M4FRNf X-Received: by 2002:a62:5c84:: with SMTP id q126mr1101309pfb.247.1560807356376; Mon, 17 Jun 2019 14:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560807356; cv=none; d=google.com; s=arc-20160816; b=ssFd/VCCcygZu4OUrclOfX5KPJoBoCg1gUG1c5ltAaj+Qvft3U16JkIdO2xrZD5ZQX VPUzDD6gBdk7p8/A3rH8XG1yl8QobCD6h7XTzKF2fMI9MqZ4ekElrOVvKSTksze9qnOQ e04XdNaRcjKBf4ShdBCA7fKQsaZiQ3vmR6l9prvvGyShpacVXomOStOphMwXB2fJWp+2 gle2YbZVcAywqKah13SPR8VLujO91Ij/wDFMSXFxlvEQhvOfw6jAr2CSMchXvwnqcw+Y fLb6FTk8rhI817brshuF/T9EGvYHftW2i00HuRwlfWYMcxRuqdKcrwSKqz230CJIHSRT 3pvg== 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=rYmoLQmGCbNht4PT6Aiws4XVJLgp6HW8jzLxteJImA5mx0Ah3LAv5bkIHtkc3FUHI6 Q8+YQ6sGNEgLERjl//XdQ1DpInP+SAW/XaBqAYL1vyBR0Nh9/roAVGCEYjXsdGLp8r89 xLgK9WgHmDHbbPbhs/xa6Du1RD9qWhGJCWwggs05JN+FYHSDZJCZu7o/uysmnL0O/nzB c6UdLXL0LUvIwbjoyD5sJoEU1sN3Fw/wNm5StOwWtU5G/9nQJz62bk36gIweatmzOfD5 YfLFlCtAsrHcoCRIfaxz8bWDR4B1GuwJN/Ri+mE2eyObKAByP01Y7UsiIGQLRjAFFWio 0kPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fqTVGU/R"; 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 d126si11522686pgc.46.2019.06.17.14.35.41; Mon, 17 Jun 2019 14:35:56 -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="fqTVGU/R"; 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 S1729682AbfFQVXP (ORCPT + 99 others); Mon, 17 Jun 2019 17:23:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:48186 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729675AbfFQVXM (ORCPT ); Mon, 17 Jun 2019 17:23:12 -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 4B3ED206B7; Mon, 17 Jun 2019 21:23:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560806591; bh=l2iPqIbRA3NdXoDeJJJLOAyo1gE2Xi1qHojbMW/AEHw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fqTVGU/RHh/pqfQDiBFFKdCSwQtBQb567c35bU9xhhFHxn5QQ5E5LMhihi2njcmRG 09SZQUfQmmn+f9gPBz3+4jHyNXIJ8lr+Bm26NLOqMZDzI7zF8Vb131qRpDDu7VsRlV yWqaNV2xSbXh32dSwPDhOKgBmeLK0jMEL18kOpxI= 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 5.1 106/115] RAS/CEC: Convert the timer callback to a workqueue Date: Mon, 17 Jun 2019 23:10:06 +0200 Message-Id: <20190617210805.397818808@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190617210759.929316339@linuxfoundation.org> References: <20190617210759.929316339@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"); }