From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6A6C4779A8 for ; Wed, 15 Jul 2026 15:01:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784127693; cv=none; b=pX/h+1iJCH6yjdAu2PMC07svHgplHYoLfx18mAenS+EqQAyIWvFCNjqgm6ohb5FjWl29BzAHzoAMk7d4zQAIsSibmJa/2lCwkpUdZvHkb01BWL/dBcFjqzutOpzBmytwAFYSzqkqBSQG2XKux25/hOu5hwoBA1hAdmvrJwxJz0g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784127693; c=relaxed/simple; bh=8+jGNB5irA8u1mmyluWOv/fGSc4MZVL9ROhTZSbY5us=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=FFXLxCiTWxKeFF+t+fWh1VcIDem2oRxqcZ1krb9v+YOLrd+2DUcZbAk+AQ2YiG+B3eAjcw0zBekjwtJ5pv5bq9V/kZcgnMG+vKAHp6muGn2BvDdixHRA212CYTk83yQiVC4FxGTJsSsGxtkpnAqIJPKhdpkDegcW0FgGJqUUHfA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Xwnd52Dp; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--smostafa.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Xwnd52Dp" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-47bbe3b9705so5082643f8f.0 for ; Wed, 15 Jul 2026 08:01:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1784127690; x=1784732490; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=j8UdcPrCWpOwvzYn0GBOE+Kb77J6h4WrSrgHpYB821s=; b=Xwnd52DpkP2Mw4fQI1nLIwMmMFu7DicxrtUF3ID8KJ0PaOSVSqlEBhhKZLZyz7ww62 Patn4e5MH/D4wkIOT7Scc2razaVG921Loi0NLO89mYgQb/1G1cE6j0cy+P+dZi8U+Oqq GzD79Q+5pHVTU7wSxXK203068e/sGlWnn5fRDiaUWbIU9/R4HVrFILjtq654IY7g7MVs kUxrRiAG7YUm17i4XnrNqgou8YBQ/knppU+X25vZ2nIkQOMuHdW91vHfMx63VcOwYL2T dJBqqeCzBi860fBRnBuXkjdxiXc1IBPwh/jKv5YXW6V1X6cvQI3pZwdBqnw5Muw9KM3J FgtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784127690; x=1784732490; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j8UdcPrCWpOwvzYn0GBOE+Kb77J6h4WrSrgHpYB821s=; b=W/lx/VVmUedvE81LP3M4ThLC6ithvyHcg9cnSScMHgbMdwkR0ZW6AW3QAATAJ3UmCb qmSpezp3UYhLaFrTO4kdLwJyPo5f67M3wDd6N0sWKF6JwGb6r+ZYkGUdPfJarSUEf3Tf c5pwC0hF/ycrIxQ3T4rHd1wSdOVz28se1mmdTv9dKP5vJOOwHaZb/IeU7lTlz5T3MkHU UFSIW7x0ly44NyB4fWx998oY0gUefKAkmzumIgVpXbCwAzKcWdu9rcHLIh9CodaJrwCm PdY+DaUeule5ouU/Q0h8EM+bltQPe29E5F4IK+GrBkqZimlXPerg0dcvqa6MQ/zRUZ4m kjtQ== X-Gm-Message-State: AOJu0YwJgr/TFtVdAbNi0U58CE8UWc9va0gkvAVxafADpURM52VvZMPX 2C3u3HhedQmczRbCXSX0YIscmpCWcBqH7kfXCHZYXeKV65lULjoJSIgtNCiMUBtl55Rxfzkuke1 W+evDnGTEWzmNHW2v/IXWEawuD+hQ+jTFS3BVR72BoR0oBar6PG0w//OynXR9yQ4KrlVZsq0OM3 vMxP70XYFC/f/igRzVr+znwSK1TbkAR2h2u1wrzmEqfO0eUR5SDnBi0o4= X-Received: from wrwq6.prod.google.com ([2002:a5d:5746:0:b0:47a:6462:7fbe]) (user=smostafa job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6000:2c0a:b0:474:4525:eb55 with SMTP id ffacd0b85a97d-47f4fd1fc60mr3529438f8f.47.1784127689429; Wed, 15 Jul 2026 08:01:29 -0700 (PDT) Date: Wed, 15 Jul 2026 15:01:25 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog Message-ID: <20260715150125.2798116-1-smostafa@google.com> Subject: [PATCH] KVM: arm64: Use consistent type for pool size From: Mostafa Saleh To: linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org Cc: maz@kernel.org, oupton@kernel.org, seiden@linux.ibm.com, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, vdonnefort@google.com, tabba@google.com, Mostafa Saleh Content-Type: text/plain; charset="UTF-8" All the pool sizes in the hypervisor are "unsigned long" but when they get passed to hyp_early_alloc_contig() or hyp_pool_init() they get truncated to 32-bits. That is not a big problem at the moment as to overflow this we need 4G bytes of carveout (2 TB of host or guest system memory). However when new users are added (as IOMMU) it is hard to reason about the carveout size anymore. Signed-off-by: Mostafa Saleh --- For example in the SMMUv3 to avoid this overflow, I add a cap for the pools size to UINT_MAX to work around this: https://lore.kernel.org/linux-iommu/20260715115906.2664882-9-smostafa@google.com/ --- arch/arm64/kvm/hyp/include/nvhe/early_alloc.h | 2 +- arch/arm64/kvm/hyp/include/nvhe/gfp.h | 4 ++-- arch/arm64/kvm/hyp/nvhe/early_alloc.c | 2 +- arch/arm64/kvm/hyp/nvhe/page_alloc.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/include/nvhe/early_alloc.h b/arch/arm64/kvm/hyp/include/nvhe/early_alloc.h index dc61aaa56f31..462883c4e325 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/early_alloc.h +++ b/arch/arm64/kvm/hyp/include/nvhe/early_alloc.h @@ -7,7 +7,7 @@ void hyp_early_alloc_init(void *virt, unsigned long size); unsigned long hyp_early_alloc_nr_used_pages(void); void *hyp_early_alloc_page(void *arg); -void *hyp_early_alloc_contig(unsigned int nr_pages); +void *hyp_early_alloc_contig(unsigned long nr_pages); extern struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops; diff --git a/arch/arm64/kvm/hyp/include/nvhe/gfp.h b/arch/arm64/kvm/hyp/include/nvhe/gfp.h index 3766333bace9..3a428dc40b14 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/gfp.h +++ b/arch/arm64/kvm/hyp/include/nvhe/gfp.h @@ -29,6 +29,6 @@ void hyp_get_page(struct hyp_pool *pool, void *addr); void hyp_put_page(struct hyp_pool *pool, void *addr); /* Used pages cannot be freed */ -int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, - unsigned int reserved_pages); +int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned long nr_pages, + unsigned long reserved_pages); #endif /* __KVM_HYP_GFP_H */ diff --git a/arch/arm64/kvm/hyp/nvhe/early_alloc.c b/arch/arm64/kvm/hyp/nvhe/early_alloc.c index 00de04153cc6..9fef0c7d2185 100644 --- a/arch/arm64/kvm/hyp/nvhe/early_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/early_alloc.c @@ -21,7 +21,7 @@ unsigned long hyp_early_alloc_nr_used_pages(void) return (cur - base) >> PAGE_SHIFT; } -void *hyp_early_alloc_contig(unsigned int nr_pages) +void *hyp_early_alloc_contig(unsigned long nr_pages) { unsigned long size = (nr_pages << PAGE_SHIFT); void *ret = (void *)cur; diff --git a/arch/arm64/kvm/hyp/nvhe/page_alloc.c b/arch/arm64/kvm/hyp/nvhe/page_alloc.c index 57f86aa0f82f..51460d420c94 100644 --- a/arch/arm64/kvm/hyp/nvhe/page_alloc.c +++ b/arch/arm64/kvm/hyp/nvhe/page_alloc.c @@ -229,12 +229,12 @@ void *hyp_alloc_pages(struct hyp_pool *pool, u8 order) return hyp_page_to_virt(p); } -int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, - unsigned int reserved_pages) +int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned long nr_pages, + unsigned long reserved_pages) { phys_addr_t phys = hyp_pfn_to_phys(pfn); struct hyp_page *p; - int i; + unsigned long i; hyp_spin_lock_init(&pool->lock); pool->max_order = min(MAX_PAGE_ORDER, -- 2.55.0.141.g00534a21ce-goog