From patchwork Wed May 17 20:23:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13245648 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 50A8BC77B75 for ; Wed, 17 May 2023 20:24:25 +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:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=cc6AhLHylUhz/7eLBrUHsCh1TnCxFL66ZR068yefTAk=; b=pup39keETN/byB f16hf2LUpJO2mmPHMk5WCz8ryMDS31uJFj1log3iJrjpxp6bPSnJOeGYJ2DZrVxuwulCAfttWx59+ CnsWhp94M+r5ijqs8Gom5EXV/1XQyTn0aSSHL94ufU5bDMmKArbXTIwI/HmnClOK7gAw1rklBbugW o+D9MspwbHxJFOOv0UARMj//lkfWuTzWt5ICBwe+622HXMRI3bftuhG2qukgTEm4a84x4sGGFQqBX mYUZ6wkToFvAnfrYekbKpFdTA/FGFeLQQ2FOGXb8z2ONHnilm97oiJK52SzWP7RFuoZlRf6SPWwSn kufBDqSarO9pANdBoC5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzNgo-00Ayxg-0J; Wed, 17 May 2023 20:24:02 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzNgl-00Ayx9-2h for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2023 20:24:01 +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 695DA64B0C; Wed, 17 May 2023 20:23:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 958E6C433EF; Wed, 17 May 2023 20:23:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684355038; bh=M1muL6P9balayQTirNwNw7ozwMwB4GRF5EDrvyljyDw=; h=From:To:Cc:Subject:Date:From; b=RS/yL6l/vCWKXEPfvT+pPNWM5hgDu9e51+o6EU6T+haO2y02zgKBySeHRS9htKr2J 5XTwCb4gdfKu7wRPGdeIcbbg4Y0TfD47pzLPt0LnFVDte3Da0vw5/ejCm238U/VKnC l/HK9uVCjFTgzSiANETHWbM6F8aOjcGiIcwM1znLlMxqNqmqt5u2YhjF8E9tWFd8ur o6P4D5jD4R0xzQp3OLes5YqA3NMx/NRt4n+5SzaRtfqRKScGjSqvK1xCAKoblwYO5R aKZmlX4ZfNTPfsxMiqRzucpzLAh+EGQQDqn1+vqcZIMN9wDMvb2xYbfGIlPh2qOfHP H632CwXXX0iKQ== From: Arnd Bergmann To: Marc Zyngier , Oliver Upton , Catalin Marinas , Will Deacon , Shaoqin Huang , Ricardo Koller , Gavin Shan Cc: 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: [PATCH] arm64: kvm: avoid overflow in integer division Date: Wed, 17 May 2023 22:23:39 +0200 Message-Id: <20230517202352.793673-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230517_132359_916475_F449D3CD X-CRM114-Status: GOOD ( 13.40 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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; }