Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp17193593ybl; Thu, 2 Jan 2020 00:16:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxyZ2QW8hwmSbQj9mGUUQif2Nuh7UhYoxSSYQjzW6UC9NZ4Sky7nBg4f2JW5n0hP/6jI5Od X-Received: by 2002:a9d:588c:: with SMTP id x12mr87795650otg.2.1577952967385; Thu, 02 Jan 2020 00:16:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577952967; cv=none; d=google.com; s=arc-20160816; b=rAC5fy+07ofOZarNcep1mxZloBy5ghWr+HRQNJjo0g/v+4BUw4m/f0OpV5a8ht2qNj Vod663/k139V+Y4q5aat0/6EuODrYkstQrM0Syu7F3kk4lR5q6MSWIl7KIRDvNvd8c3+ O5ehgsIWD1U5mXmmyIzaaHQAKGoqPJeXieQ3HpzdrpTK4TCV4vhVCGDAtaqdTCXOlTtW HuHs8cMvpOztUUXYvoAdTfKNkZpziQ9UnmSfYsrnwwE32mpU2NO9+rOh8ywG3vMPf1+9 wz2+pacm7cWqHYWIv1g4GKc1EzxkUI0B2FuCtU7UX2fG43nfnjCFwovnWRU187K1lZPv 4BBA== 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 :message-id:date:subject:cc:to:from; bh=QIjs2fzaKhkcrawBdklytIXHh2PIipoPoJds7r62wd8=; b=mHblqD7iAcPt3YepUgF75A0jRnS4Wmk0z8ZF8WZczk4YW8YK7BreGOCCYA6NoosUut dIvj/KSnt3RoCWr7xo8AHVQqaRSVIWvMM1b1COWX/+rtY0DCj10Xa14RHzbPqYNEQzXU s+jVPkweouwaFLh2kvA6UR7ntGpNXflPVpXf7MrN7JViC1ZllaPEaGeZtcwVm0YGuWun wDazOk+s22bkgb8NWrlcaXF1rWmAVeRfKOxaNp31dE+8jgZRsZPjfffSs+S72rbvE8lY 0hzSy9Ueqvx/+yQ/a/IIEqqhDbQvnaEurcc7ZouSUHvYzCVrpK8HYHMOycmZxNfqGBAb e8+Q== 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 g5si29434794otn.232.2020.01.02.00.15.54; Thu, 02 Jan 2020 00:16:07 -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 S1727771AbgABIPF (ORCPT + 99 others); Thu, 2 Jan 2020 03:15:05 -0500 Received: from out30-132.freemail.mail.aliyun.com ([115.124.30.132]:50424 "EHLO out30-132.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727714AbgABIPF (ORCPT ); Thu, 2 Jan 2020 03:15:05 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R141e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=wenyang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0TmarSI6_1577952893; Received: from localhost(mailfrom:wenyang@linux.alibaba.com fp:SMTPD_---0TmarSI6_1577952893) by smtp.aliyun-inc.com(127.0.0.1); Thu, 02 Jan 2020 16:15:02 +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 0/3] use div64_ul() instead of div_u64() if the divisor is unsigned long Date: Thu, 2 Jan 2020 16:14:39 +0800 Message-Id: <20200102081442.8273-1-wenyang@linux.alibaba.com> X-Mailer: git-send-email 2.23.0 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 We were first inspired by commit b0ab99e7736a ("sched: Fix possible divide by zero in avg_atom () calculation"), then refer to the recently analyzed mm code, we found this suspicious place. 201 if (min) { 202 min *= this_bw; 203 do_div(min, tot_bw); 204 } And we also disassembled and confirmed it: /usr/src/debug/kernel-4.9.168-016.ali3000/linux-4.9.168-016.ali3000.alios7.x86_64/mm/page-writeback.c: 201 0xffffffff811c37da <__wb_calc_thresh+234>: xor %r10d,%r10d 0xffffffff811c37dd <__wb_calc_thresh+237>: test %rax,%rax 0xffffffff811c37e0 <__wb_calc_thresh+240>: je 0xffffffff811c3800 <__wb_calc_thresh+272> /usr/src/debug/kernel-4.9.168-016.ali3000/linux-4.9.168-016.ali3000.alios7.x86_64/mm/page-writeback.c: 202 0xffffffff811c37e2 <__wb_calc_thresh+242>: imul %r8,%rax /usr/src/debug/kernel-4.9.168-016.ali3000/linux-4.9.168-016.ali3000.alios7.x86_64/mm/page-writeback.c: 203 0xffffffff811c37e6 <__wb_calc_thresh+246>: mov %r9d,%r10d ---> truncates it to 32 bits here 0xffffffff811c37e9 <__wb_calc_thresh+249>: xor %edx,%edx 0xffffffff811c37eb <__wb_calc_thresh+251>: div %r10 0xffffffff811c37ee <__wb_calc_thresh+254>: imul %rbx,%rax 0xffffffff811c37f2 <__wb_calc_thresh+258>: shr $0x2,%rax 0xffffffff811c37f6 <__wb_calc_thresh+262>: mul %rcx 0xffffffff811c37f9 <__wb_calc_thresh+265>: shr $0x2,%rdx 0xffffffff811c37fd <__wb_calc_thresh+269>: mov %rdx,%r10 This series use div64_ul() instead of div_u64() if the divisor is unsigned long, to avoid truncation to 32-bit on 64-bit platforms. Cc: Andrew Morton Cc: Qian Cai Cc: Tejun Heo Cc: Jens Axboe Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org Wen Yang (3): mm/page-writeback.c: avoid potential division by zero in wb_min_max_ratio() mm/page-writeback.c: use div64_ul() for u64-by-unsigned-long divide mm/page-writeback.c: improve arithmetic divisions mm/page-writeback.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) -- 1.8.3.1