Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17193637ybl; Thu, 2 Jan 2020 00:16:11 -0800 (PST) X-Google-Smtp-Source: APXvYqw4LSfwySTOajTUvZvUVuLL7+7QaGImfnOoICb69NEKr5x0svc3k1kyQfE0u6DejiKRgnsq X-Received: by 2002:a9d:2de5:: with SMTP id g92mr73184763otb.217.1577952971778; Thu, 02 Jan 2020 00:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577952971; cv=none; d=google.com; s=arc-20160816; b=eNHMtud52+vU/wkHLCcp1dNHRVAQd3FdR95hIQaYJaQ0nN3OhPkp0AQIG18P+KF9Cl BYJ11+cSXnt/lAbaEGd1s9Kp3sONDYcnGOgQ6XOpezftRgxMIIRQdiqfg0BOcxfwGSVt ePLSn7mWNiSTYWAn39DjHnqlcZmJf/+ueDTcyFXTHve1kVSUfygyPKePJPnhZyqfmPyN NjK6blDSzDsNBE416V/RDf0An+3EPrNWfmWi04hb3J9cLIEFFDlvOAdbg4QQwQB0ttd6 cYnQPC6CVA3/Wd/Z/Kax0jc4QbvroRnFPwrfsH3ikvyVSuzJun8gAabLO1ZefZ58Ada6 JbxQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=9/ZQd8fykcwIHApOSTO18B3aej2Y/CTBHWK3Fc/qaWY=; b=t3QIufGUVzzF+48nJxHLiZiEbvS4KZzCy2PIjhdKNkB3b0ML2tmthd/NgwTpsl7f3s SGU6fwRlPKE7+LZlZqhdsPfDZTt8riBSEXZlAqWiMQEwv+tgm/SDt9Slmbn+6CngNXbp FSjYbahSGV4dLO+P/XQbhuq+LL3aNTQFj5qEPnIfB17bghelDNrkZQnD3pr40apFwvC6 K8oklNf2KTw6YoMJEMvKVZKnaajrqhmg32UMIDAN2/3tdUaXJ55nYYzJDYXzFzs3C8tv K6ZorYIWHFTUrdMk/RM8ouvzHsGzbwgEUHtED6Pw8PXc+hr9hiUqgGljB2DG8qFO4H24 Yg0g== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n85si25400833oig.191.2020.01.02.00.16.00; Thu, 02 Jan 2020 00:16:11 -0800 (PST) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727829AbgABIPR (ORCPT + 99 others); Thu, 2 Jan 2020 03:15:17 -0500 Received: from out30-133.freemail.mail.aliyun.com ([115.124.30.133]:55911 "EHLO out30-133.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbgABIPR (ORCPT ); Thu, 2 Jan 2020 03:15:17 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04394;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0TmanhCh_1577952902; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TmanhCh_1577952902) by smtp.aliyun-inc.com(127.0.0.1); Thu, 02 Jan 2020 16:15:14 +0800 From: Wen Yang To: Andrew Morton , Qian Cai Cc: xlpang@linux.alibaba.com, Wen Yang , Tejun Heo , Jens Axboe , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] mm/page-writeback.c: avoid potential division by zero in wb_min_max_ratio() Date: Thu, 2 Jan 2020 16:14:40 +0800 Message-Id: <20200102081442.8273-2-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20200102081442.8273-1-wenyang@linux.alibaba.com> References: <20200102081442.8273-1-wenyang@linux.alibaba.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The variables 'min' and 'max' are unsigned long and do_div truncates them to 32 bits, which means it can test non-zero and be truncated to zero for division. Fix this issue by using div64_ul() instead. Fixes: 693108a8a667 ("writeback: make bdi->min/max_ratio handling cgroup writeback aware") Signed-off-by: Wen Yang Cc: Andrew Morton Cc: Qian Cai Cc: Tejun Heo Cc: Jens Axboe Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/page-writeback.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/page-writeback.c b/mm/page-writeback.c index 50055d2..2d658b2 100644 --- a/mm/page-writeback.c +++ b/mm/page-writeback.c @@ -201,11 +201,11 @@ static void wb_min_max_ratio(struct bdi_writeback *wb, if (this_bw < tot_bw) { if (min) { min *= this_bw; - do_div(min, tot_bw); + min = div64_ul(min, tot_bw); } if (max < 100) { max *= this_bw; - do_div(max, tot_bw); + max = div64_ul(max, tot_bw); } } -- 1.8.3.1