From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92530C7EE23 for ; Thu, 18 May 2023 07:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Bt4bUbzUFkSt7kuX7WgLjXU26ufc4ikfAXE0iWVmRSs=; b=2D6NroWzm7Nh3m S5IJytUCZFmyUQEpX8/AcPzbTQfBrNCRb8oiqLUzeGjritLsk2llfUwS7N7bSn4DOJ3EvwwHew7+K LG6S7GUmQc0jZCxf+UB1dfir/Wr9JXOyABcinP1YQCzIuPIoG0hM6/2JfyEfHiES+F5IT0LL3m8jr 7eFxuNTJGxccnAN/sei7e/yiwWgHkpwouqPDmx9YAUMgV5U0/IkW5uU0WqlOito7Eh7RaDGaw1C7S MYWuwpQR1o82Z4bTTkToUXSPf8NCoCg5+HCSuWPWdGrX16wHSqjWtuJnZa/scwhd9n0453v2bbFO8 u5ipql7Z3ZsFzhhMu0lA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzY68-00CDNF-2o; Thu, 18 May 2023 07:30:52 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzY65-00CDMX-1T for linux-arm-kernel@lists.infradead.org; Thu, 18 May 2023 07:30:51 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A7F26190E; Thu, 18 May 2023 07:30:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DE9C433D2; Thu, 18 May 2023 07:30:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684395045; bh=hTlEdPj67IrmcUHD6iCX3p6gyeN8z+Z5BNTRRu7a0U0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=mB1glrViRgEAI3XP1lsGftyAXtqMgmXl/QjJXm68RlPf0vk0F1/xCHwyU3HSRFVFy wFQkFoVpx6m5H/mUqyuFje3HbF1iYUzdKxiGj/vDEXGbELdnMV4VNl3F031Gta2p+g 1QpU5q++n5pZG77X3lp70qYmet2+mHLXXRQ6kRsVyTZd/zQhgUKLjMVQMJ9Yr2TAg6 VJj+4k6UG9rcteFrK0wMgpqrAob3h4BG+ttcwP6R5kNkAKMfgZsIVN8fM7WmFLG6jw oFfFeSM+1xiQ/XvSj93gkqong39d6TD/3g0XZkPnHRNmJqEaCSkRYmVSn2VwYbNsyc Vr7EK1ZggB09w== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pzY5z-00G4a4-9X; Thu, 18 May 2023 08:30:43 +0100 Date: Thu, 18 May 2023 08:30:42 +0100 Message-ID: <86lehmksf1.wl-maz@kernel.org> From: Marc Zyngier To: Arnd Bergmann Cc: Oliver Upton , Catalin Marinas , Will Deacon , Shaoqin Huang , Ricardo Koller , Gavin Shan , Arnd Bergmann , James Morse , Suzuki K Poulose , Zenghui Yu , Cornelia Huck , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH] arm64: kvm: avoid overflow in integer division In-Reply-To: <20230517202352.793673-1-arnd@kernel.org> References: <20230517202352.793673-1-arnd@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: arnd@kernel.org, oliver.upton@linux.dev, catalin.marinas@arm.com, will@kernel.org, shahuang@redhat.com, ricarkol@google.com, gshan@redhat.com, arnd@arndb.de, james.morse@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, cohuck@redhat.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_003049_576187_E7C6E066 X-CRM114-Status: GOOD ( 25.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, 17 May 2023 21:23:39 +0100, Arnd Bergmann wrote: > > From: Arnd Bergmann > > The newly added kvm_mmu_split_nr_page_tables() function uses DIV_ROUND_DOWN_ULL() > to divide 64-bit addresses, but this requires a 32-bit divisior, and PUD_SIZE > may exceed that when 64KB pages are used: > > arch/arm64/kvm/mmu.c: In function 'kvm_mmu_split_nr_page_tables': > include/linux/math.h:42:64: error: conversion from 'long unsigned int' to 'u32' {aka 'unsigned int'} changes value from '68719476736' to '0' [-Werror=overflow] > 42 | DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d)) > | ^~~ > include/linux/math.h:39:47: note: in definition of macro 'DIV_ROUND_DOWN_ULL' > 39 | #define DIV_ROUND_DOWN_ULL(ll, d) div_u64(ll, d) > | ^ > arch/arm64/kvm/mmu.c:95:22: note: in expansion of macro 'DIV_ROUND_UP_ULL' > 95 | n += DIV_ROUND_UP_ULL(range, PUD_SIZE); > | ^~~~~~~~~~~~~~~~ > > Since this code is only used on 64-bit targets, DIV_ROUND_UP() can deal with this > more easily, as it already takes 64-bit arguments. > > Fixes: e7bf7a490c68 ("KVM: arm64: Split huge pages when dirty logging is enabled") > Signed-off-by: Arnd Bergmann > --- > arch/arm64/kvm/mmu.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 3386bd28d267..6db9ef288ec3 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -92,8 +92,8 @@ static int kvm_mmu_split_nr_page_tables(u64 range) > int n = 0; > > if (KVM_PGTABLE_MIN_BLOCK_LEVEL < 2) > - n += DIV_ROUND_UP_ULL(range, PUD_SIZE); > - n += DIV_ROUND_UP_ULL(range, PMD_SIZE); > + n += DIV_ROUND_UP(range, PUD_SIZE); > + n += DIV_ROUND_UP(range, PMD_SIZE); > return n; > } This is against -next, right? Oliver, I assume you'll take this as a fix for Ricardo's series? Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel