From patchwork Thu Oct 9 07:04:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "pang.xunlei" X-Patchwork-Id: 38495 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B319B2032C for ; Thu, 9 Oct 2014 07:10:34 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf361918lab.3 for ; Thu, 09 Oct 2014 00:10:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=hkbR5U+CC8vzMn8CUctWV8990HmTPXj9o5wUaGDGxYM=; b=kMnH3gCyv8te10CT91hasEj6SBSBkq/Aff7eVjEbcAuKhn58EFOeQ7Prp8hC8o1Q8q XoT5ncaALZMfSMcz+Iz8WE5MlfjiT0FWUZ1ZvXDRRa65xUHyyQolk3mzBq/e/8EilFPl vT+wzIelYyB1eXZxTpmhwx/4eArURkqZ9eK+2fB4ZbqZSXuHukOi1gDI3Q3MwZgERBqO okMRLTtaASratmCBsgeCVYthvZz4ED3NHHqfras8tw8QgWib2I5YrY2laOqGlZYA/S9r SFDS19K01VHubuG6pZRA+XouNCWZtYU8Dy5Fut6/h8/d2oqmoPOmrPWbFr5MTbfSVfRJ XvkQ== X-Gm-Message-State: ALoCoQnulaSMXAnRr2QlQrVTSb5BjYWh2vQEVrebkgdaanbeKBKN1J/cxny1t66UUCGjol17bXvp X-Received: by 10.112.151.3 with SMTP id um3mr72090lbb.15.1412838633050; Thu, 09 Oct 2014 00:10:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.72 with SMTP id g8ls142314lab.23.gmail; Thu, 09 Oct 2014 00:10:32 -0700 (PDT) X-Received: by 10.152.26.226 with SMTP id o2mr1820698lag.44.1412838632878; Thu, 09 Oct 2014 00:10:32 -0700 (PDT) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com [209.85.215.45]) by mx.google.com with ESMTPS id d2si3114099lbv.18.2014.10.09.00.10.32 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Oct 2014 00:10:32 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id q1so567299lam.32 for ; Thu, 09 Oct 2014 00:10:32 -0700 (PDT) X-Received: by 10.112.134.229 with SMTP id pn5mr15567602lbb.22.1412838632732; Thu, 09 Oct 2014 00:10:32 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp193232lbz; Thu, 9 Oct 2014 00:10:31 -0700 (PDT) X-Received: by 10.182.18.101 with SMTP id v5mr19786127obd.64.1412838631201; Thu, 09 Oct 2014 00:10:31 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fi8si1792197obb.48.2014.10.09.00.10.30 for ; Thu, 09 Oct 2014 00:10:31 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751219AbaJIHKU (ORCPT + 27 others); Thu, 9 Oct 2014 03:10:20 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:64311 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750815AbaJIHKN (ORCPT ); Thu, 9 Oct 2014 03:10:13 -0400 Received: by mail-ig0-f169.google.com with SMTP id uq10so1937224igb.0 for ; Thu, 09 Oct 2014 00:10:12 -0700 (PDT) X-Received: by 10.50.78.70 with SMTP id z6mr51745839igw.23.1412838612308; Thu, 09 Oct 2014 00:10:12 -0700 (PDT) Received: from wangdeqiang.com.cn ([210.21.227.66]) by mx.google.com with ESMTPSA id gb12sm4564577igd.0.2014.10.09.00.10.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 09 Oct 2014 00:10:11 -0700 (PDT) From: "pang.xunlei" To: linux-kernel@vger.kernel.org Cc: John Stultz , Thomas Gleixner , "pang.xunlei" Subject: [PATCH 1/2] time: Fix NTP adjustment mult overflow. Date: Thu, 9 Oct 2014 15:04:30 +0800 Message-Id: <1412838271-11175-1-git-send-email-pang.xunlei@linaro.org> X-Mailer: git-send-email 1.7.10.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pang.xunlei@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The mult memember of struct clocksource should always be a large u32 number when calculated through __clocksource_updatefreq_scale(). The value of (cs->mult+cs->maxadj) may have a chance to reach very near 0xFFFFFFFF. For instance, 555MHz oscillator: cs->mult is 0xE6A17102, cs->maxadj is 0x195E8EFD, cs->mult+cs->maxadj is 0xFFFFFFFF. Such oscillators would probably exist on some processors like MIPS which use CP0 compare/count CPU clock as the clock source. Clocksource might encounter large frequency adjustment due to the hardware unstability, environment temperature, software deviation, NTP algorithm accuracy, etc. When NTP slewes the clock, kernel goes through update_wall_time()->...->timekeeping_apply_adjustment(): tk->tkr.mult += mult_adj; Unfortunately, tk->tkr.mult may overflow after this operation, though such cases are next to impossible to happen in practice. This patch avoids mult overflow by judging the overflow case before adding mult_adj to mult, also adds the WARNING message when capturing such case. Signed-off-by: pang.xunlei --- kernel/time/timekeeping.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index ec1791f..cad61b3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1332,6 +1332,12 @@ static __always_inline void timekeeping_apply_adjustment(struct timekeeper *tk, * * XXX - TODO: Doc ntp_error calculation. */ + if (tk->tkr.mult + mult_adj < mult_adj) { + /* NTP adjustment caused clocksource mult overflow */ + WARN_ON_ONCE(1); + return; + } + tk->tkr.mult += mult_adj; tk->xtime_interval += interval; tk->tkr.xtime_nsec -= offset;