From patchwork Fri Jan 26 09:40:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Ofitserov X-Patchwork-Id: 192505 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp565119dyb; Fri, 26 Jan 2024 02:24:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IFIPpC9xjmBLWcCcN3G+0F7B46rQ95NXGsKymQ1BCO/nb0Uy/6ksyBF+ktRW7H8PQ1Iyfgu X-Received: by 2002:ae9:e712:0:b0:783:836e:9176 with SMTP id m18-20020ae9e712000000b00783836e9176mr1156642qka.146.1706264643908; Fri, 26 Jan 2024 02:24:03 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706264643; cv=pass; d=google.com; s=arc-20160816; b=KHojpCnYYs0+BSrPUtmxp+b1T+pNhEY09GPCs+/w5iy7gd3z7bj+KrMuP4Lf7Okufc s2lHUYV2QEqp4C/pa5hCBYttaUPK5EoYjWxNQWAkIHUoXWWfc8+1zvrBK+lLC7aQdROd R9HBWq5E7hcC2Igps+19pq0qxXszcMcq846Iyq1N4go2OvIzwItkYJu/WZXNPQbHTaQE K5DbYx9FpQIMh54Kmum/TEkvqDD3KWfuHJeUQEDWzUPbtq9oWOimszhwRX8OpnQ4S1oK Qh9KkLOVGj8VRJVJPO/Jf1jUzUMpZGfm/Gm3eFouyfTwkLHFnXPbyH+o+JsPa0QrHYzI qc4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=GMjElLtYvXdGvqjSGNHZDC2fvS57v0bg4d80yF8clsI=; fh=10drZrV4RvU/HdzZ5olGYr65ukKIXS5J6sTo3dhHKmg=; b=LYjw+7HDsQoPWjN63xOL6RREbme1fNDQcCgLqoeXTgSjd598jJPbaQGi9A4QlKUR+/ Aizs96BXVI8+vshh9dMxOuX1bpkhmIm6tPQLbuI5mknwpzOOPlgTx+K4MbDs7lxH2h2n DX2WwIcEK9gUe8/3bzhM8cU1O6XvZfKQdBPfEa7NuDJmihJ5IOj0fw4CNlf8z9PL4tv0 6EMERj9Q0v/AWAaV82hqQUsuVAO+QeJVpUBXfiWeqVV/OoJD2VFUyMwKTkaMk/rYnSC2 e5lkopAR6SlZ6Waqx9tEIDrdZTHNS2zkiYKnEdFfRGrKpwV4qmhDDMK92bPDcW8Izj3k IsTg== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-kernel+bounces-39950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39950-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a9-20020a05620a066900b0078321fc9bd9si968287qkh.367.2024.01.26.02.24.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 02:24:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=altlinux.org); spf=pass (google.com: domain of linux-kernel+bounces-39950-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39950-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 14D021C242FB for ; Fri, 26 Jan 2024 10:18:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 80C03745DB; Fri, 26 Jan 2024 09:41:03 +0000 (UTC) Received: from air.basealt.ru (air.basealt.ru [194.107.17.39]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB94C1B7F9; Fri, 26 Jan 2024 09:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=194.107.17.39 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706262062; cv=none; b=pXG5EWwSlt4cQADIXWQkqjvbWJJXc3S8Mj7tF19WjwHQk3pdmnjpEpdUn+aSGraRYFvFztoOcV3tFNRCmCg5gIfpbumCRLvklpToQW0U/SwnbjZVmfXfttjMGoLdUiUClOtOcX4GTG9/32dHjbxs0azcsKw0AQRcBAkDX5XkeUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706262062; c=relaxed/simple; bh=TXRpBSVjCJUcc+Ou62Ur6MM+Di8M71iBf31d0N8EyxU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bCZ7edqunJ7PQ7NVv5rtxMJaXCLZCw1XX59qbHWdFQC/FoqjGO52QU87TQdIJEGiDUNgpp6oFTlTi7Xv5crzmp0URBa4yjT3t4R/jONTyQLBIDvp4cVkbK2Pz9n2ENRdeuSNZyes8X+cCpTv5xBYd1V8R4RZCn+Ky5yhg4xjfZI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org; spf=pass smtp.mailfrom=altlinux.org; arc=none smtp.client-ip=194.107.17.39 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=altlinux.org Received: by air.basealt.ru (Postfix, from userid 490) id DA8152F2023B; Fri, 26 Jan 2024 09:40:50 +0000 (UTC) X-Spam-Level: Received: from shell.ipa.basealt.ru (unknown [176.12.98.74]) by air.basealt.ru (Postfix) with ESMTPSA id 17CBB2F2024B; Fri, 26 Jan 2024 09:40:25 +0000 (UTC) From: oficerovas@altlinux.org To: oficerovas@altlinux.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: kovalev@altlinux.org Subject: [PATCH 2/2] KVM: use __vcalloc for very large allocations Date: Fri, 26 Jan 2024 12:40:23 +0300 Message-ID: <20240126094023.2677376-3-oficerovas@altlinux.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20240126094023.2677376-1-oficerovas@altlinux.org> References: <20240126094023.2677376-1-oficerovas@altlinux.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789148155292577900 X-GMAIL-MSGID: 1789148155292577900 From: Alexander Ofitserov From: Paolo Bonzini commit 37b2a6510a48 ("KVM: use __vcalloc for very large allocations") Allocations whose size is related to the memslot size can be arbitrarily large. Do not use kvzalloc/kvcalloc, as those are limited to "not crazy" sizes that fit in 32 bits. URL: https://lore.kernel.org/lkml/20220711090606.962822924@linuxfoundation.org/ Reviewed-by: David Hildenbrand Signed-off-by: Paolo Bonzini Signed-off-by: Alexander Ofitserov --- arch/powerpc/kvm/book3s_hv_uvmem.c | 2 +- arch/x86/kvm/mmu/page_track.c | 2 +- arch/x86/kvm/x86.c | 4 ++-- virt/kvm/kvm_main.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kvm/book3s_hv_uvmem.c b/arch/powerpc/kvm/book3s_hv_uvmem.c index 3dd58b4ee33e5..5f6b3f80023de 100644 --- a/arch/powerpc/kvm/book3s_hv_uvmem.c +++ b/arch/powerpc/kvm/book3s_hv_uvmem.c @@ -250,7 +250,7 @@ int kvmppc_uvmem_slot_init(struct kvm *kvm, const struct kvm_memory_slot *slot) p = kzalloc(sizeof(*p), GFP_KERNEL); if (!p) return -ENOMEM; - p->pfns = vzalloc(array_size(slot->npages, sizeof(*p->pfns))); + p->pfns = vcalloc(slot->npages, sizeof(*p->pfns)); if (!p->pfns) { kfree(p); return -ENOMEM; diff --git a/arch/x86/kvm/mmu/page_track.c b/arch/x86/kvm/mmu/page_track.c index 81cf4babbd0b4..3c379335ea477 100644 --- a/arch/x86/kvm/mmu/page_track.c +++ b/arch/x86/kvm/mmu/page_track.c @@ -35,7 +35,7 @@ int kvm_page_track_create_memslot(struct kvm_memory_slot *slot, for (i = 0; i < KVM_PAGE_TRACK_MAX; i++) { slot->arch.gfn_track[i] = - kvcalloc(npages, sizeof(*slot->arch.gfn_track[i]), + __vcalloc(npages, sizeof(*slot->arch.gfn_track[i]), GFP_KERNEL_ACCOUNT); if (!slot->arch.gfn_track[i]) goto track_free; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 13e4699a0744f..6c2bf7cd7aec6 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10826,14 +10826,14 @@ static int kvm_alloc_memslot_metadata(struct kvm_memory_slot *slot, slot->base_gfn, level) + 1; slot->arch.rmap[i] = - kvcalloc(lpages, sizeof(*slot->arch.rmap[i]), + __vcalloc(lpages, sizeof(*slot->arch.rmap[i]), GFP_KERNEL_ACCOUNT); if (!slot->arch.rmap[i]) goto out_free; if (i == 0) continue; - linfo = kvcalloc(lpages, sizeof(*linfo), GFP_KERNEL_ACCOUNT); + linfo = __vcalloc(lpages, sizeof(*linfo), GFP_KERNEL_ACCOUNT); if (!linfo) goto out_free; diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 356fd5d1a4285..b7638c3c9eb7d 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -1008,9 +1008,9 @@ static int kvm_vm_release(struct inode *inode, struct file *filp) */ static int kvm_alloc_dirty_bitmap(struct kvm_memory_slot *memslot) { - unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot); + unsigned long dirty_bytes = kvm_dirty_bitmap_bytes(memslot); - memslot->dirty_bitmap = kvzalloc(dirty_bytes, GFP_KERNEL_ACCOUNT); + memslot->dirty_bitmap = __vcalloc(2, dirty_bytes, GFP_KERNEL_ACCOUNT); if (!memslot->dirty_bitmap) return -ENOMEM;