Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754916AbdCWKgB (ORCPT ); Thu, 23 Mar 2017 06:36:01 -0400 Received: from LGEAMRELO11.lge.com ([156.147.23.51]:38410 "EHLO lgeamrelo11.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932920AbdCWKdW (ORCPT ); Thu, 23 Mar 2017 06:33:22 -0400 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 165.244.249.25 X-Original-MAILFROM: byungchul.park@lge.com X-Original-SENDERIP: 10.177.222.33 X-Original-MAILFROM: byungchul.park@lge.com From: Byungchul Park To: , CC: , , , Subject: [PATCH 5/8] sched/deadline: Protect read of cpudl heap with a lock Date: Thu, 23 Mar 2017 19:32:40 +0900 Message-ID: <1490265163-29981-6-git-send-email-byungchul.park@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490265163-29981-1-git-send-email-byungchul.park@lge.com> References: <1490265163-29981-1-git-send-email-byungchul.park@lge.com> X-MIMETrack: Itemize by SMTP Server on LGEKRMHUB05/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/03/23 19:33:18, Serialize by Router on LGEKRMHUB05/LGE/LG Group(Release 8.5.3FP6|November 21, 2013) at 2017/03/23 19:33:18, Serialize complete at 2017/03/23 19:33:18 MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1747 Lines: 52 Current code reads cp->elements[0].cpu and cp->elements[0].dl without acquiring cpudl's lock. There are two problems on it: 1. When we read elements[0].dl, the value can be broken on 32 bit machine because elements[0].dl is 64 bit data. We should guarantee it to be done atomically. 2. Obsolete data can be read unless syncronizing with updaters: updater1 updater2 reader -------- -------- ------ lock A set maxcpu = cpu1 unlock A lock A set maxcpu = cpu2 unlock A read maxcpu, it might be -1 where maxcpu was -1 initially. When reading maxcpu, the value might be -1, we expect that should be cpu2 though. So force readers also to be protected using the lock. Signed-off-by: Byungchul Park --- kernel/sched/cpudeadline.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kernel/sched/cpudeadline.c b/kernel/sched/cpudeadline.c index f03479c..37bbb66 100644 --- a/kernel/sched/cpudeadline.c +++ b/kernel/sched/cpudeadline.c @@ -118,8 +118,14 @@ static inline u64 cpudl_maximum_dl(struct cpudl *cp) static int cpudl_fast_find(struct cpudl *cp, struct task_struct *p) { const struct sched_dl_entity *dl_se = &p->dl; - int max_cpu = cpudl_maximum_cpu(cp); - u64 max_dl = cpudl_maximum_dl(cp); + unsigned long flags; + int max_cpu; + u64 max_dl; + + raw_spin_lock_irqsave(&cp->lock, flags); + max_cpu = cpudl_maximum_cpu(cp); + max_dl = cpudl_maximum_dl(cp); + raw_spin_unlock_irqrestore(&cp->lock, flags); if (cpumask_test_cpu(max_cpu, &p->cpus_allowed) && dl_time_before(dl_se->deadline, max_dl)) -- 1.9.1