From nobody Sat May 10 05:37:17 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 C683A20D4E1 for <linux-kernel@vger.kernel.org>; Tue, 1 Apr 2025 15:57:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743523042; cv=none; b=Fr/GVNlv6HTrtLKNStf4L/hIJFPE8YyKnSOIFfokN+ldk5d9+8cG5TtGpj5zcW7kpbcmRtblKjNj/QEyGAm1Q8ZsXxuEa7F+b6ZeV8P3rVJL57cAoEYl0FhpJLWuPLDOil5UNYPqjdF1JCMEFJll4n0eH1wIPKIyEGChASD/B6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743523042; c=relaxed/simple; bh=0ZZQsy5iR/tBBwSV2RsNwEBEpyYjNX9rkaOvEJOwHEo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=IDtuMb38XO1jdf6Hkmfl+HEbxU1BEcVqKyMte1F8sE42fUGA5V316Lt9PwqD7cyk4Ku0pqE23o7FZ7DfGk7wRdlIHOhNMEc1tH6fTMv0KoekPnjeCCbqmY+ap896ZxbKLZPkNMjvuUagVAALVsStNP+Wsl6wUr9eLQc3ygZL7Xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=MR5rVmpw; arc=none smtp.client-ip=209.85.216.73 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--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="MR5rVmpw" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ff4b130bb2so10362275a91.0 for <linux-kernel@vger.kernel.org>; Tue, 01 Apr 2025 08:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1743523040; x=1744127840; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=qA3FLGTWw4iTy7QH63sW/7/WyR1uRH4cACOa/5NAWCI=; b=MR5rVmpwhfFU7Kk7zoQdF/DA7BYy8CS10sch71A0/6TPL43vYo0VWwoM/ZRTon0rci 2N1wOvqVAe/mVqt9s5HPj8UJ2QqPQc8jMCAJ3wifadS3C88mQ5Rw/xzcl3OC4g6tX805 Lx6ljp3SIYVYm/W0tH9ZyWdLtB6cimXdE86W5D0wGocMK8RTu4IXY3wEZ/94nb1yqaX7 I+7GBBjtrR4h69qKA9JIDRf7TYYxao1/46lpx05/qLW14/yz/Lbx1Q4UQ9lVp4m+2SEm XMfNoD7qfov2HFIBfb4NzVa3bXzUfmbGQV2tzutopo4YQPnmDlzkOnAPdN+f/MXPqlEU vbxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743523040; x=1744127840; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qA3FLGTWw4iTy7QH63sW/7/WyR1uRH4cACOa/5NAWCI=; b=wB/kOkbrXqAEf4qBq4EjbExRiqCNZJ7gQnhWqLQ+LRr6bY0+Rl9yW6f5Lf6dfAVxZA QQdcgUXZPrbnEx/bA01di/6oMhaFxFvH/Y/Y8xD31CubLl85G7EslUs3n5S9Kix+TlwB +4o5f3sNQs0T9/xOf/meN8nRy7krnASgmNpVSIHjikEu2XO78pusdSdGsT+nz50XFxzk ndDB+lF1qT3E33VGmrAWusepA9j5KAeh1UQRnmAOt74SWQemFpQbeohxqw8D69ymLCpu CnVjnrpnvmoHOJstTZLFe7He/aT2FxJDqnUwZ17UWaE8J9ySC4wzoCXLF+7ArnlgTPfV 3vnA== X-Forwarded-Encrypted: i=1; AJvYcCXdZRgptefRfC7KcbkgHUVGRdS7JROzgIbjK/CKQ8kdXOZEIbYTJwIlvmENw57fN4KlpFAEvwVuyzFyk1A=@vger.kernel.org X-Gm-Message-State: AOJu0Yyy1gbFyqEw2pdMcWGoLH8qZRgRn8ziZuz3mbLTlUd8NlaruSpf sVtUrGKKC1yMotsO0vY0CXsFZyJQMpn/Wy/RaUTEpTlm+4I3OO+wVV7f4upkhyVFLmFMjZU+Zfq VAQ== X-Google-Smtp-Source: AGHT+IFfRx5K6oY4RAb5pZkeJwowkj1BgVmibF8BfPMQekfaCGm2fIiGn7Kg30MfKpJzguRbFKy2Jg4G68k= X-Received: from pfbli7.prod.google.com ([2002:a05:6a00:7187:b0:736:a983:dc43]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c889:b0:1f5:6c94:2cc1 with SMTP id adf61e73a8af0-2009f640589mr24122182637.21.1743523040124; Tue, 01 Apr 2025 08:57:20 -0700 (PDT) Reply-To: Sean Christopherson <seanjc@google.com> Date: Tue, 1 Apr 2025 08:57:13 -0700 In-Reply-To: <20250401155714.838398-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> Mime-Version: 1.0 References: <20250401155714.838398-1-seanjc@google.com> X-Mailer: git-send-email 2.49.0.472.ge94155a9ec-goog Message-ID: <20250401155714.838398-3-seanjc@google.com> Subject: [PATCH v2 2/3] KVM: x86: Allocate kvm_vmx/kvm_svm structures using kzalloc() From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma <vipinsh@google.com> Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that the size of "struct kvm" is less than 2KiB, switch back to using kzalloc() to allocate the VM structures. Add compile-time assertions in vendor code to ensure the size is an order-0 allocation, i.e. to prevent unknowingly letting the size balloon in the future. Signed-off-by: Sean Christopherson <seanjc@google.com> --- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/svm/svm.c | 1 + arch/x86/kvm/vmx/vmx.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index e523d7d8a107..6c7fd7db6f11 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1940,7 +1940,7 @@ void kvm_x86_vendor_exit(void); #define __KVM_HAVE_ARCH_VM_ALLOC static inline struct kvm *kvm_arch_alloc_vm(void) { - return __vmalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT | __GFP_ZERO); + return kzalloc(kvm_x86_ops.vm_size, GFP_KERNEL_ACCOUNT); } =20 #define __KVM_HAVE_ARCH_VM_FREE diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 8abeab91d329..589adc5f92e0 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -5536,6 +5536,7 @@ static int __init svm_init(void) if (r) goto err_kvm_init; =20 + BUILD_BUG_ON(get_order(sizeof(struct kvm_svm) !=3D 0)); return 0; =20 err_kvm_init: diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index b70ed72c1783..01264842bf45 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -8755,6 +8755,7 @@ static int __init vmx_init(void) if (r) goto err_kvm_init; =20 + BUILD_BUG_ON(get_order(sizeof(struct kvm_vmx) !=3D 0)); return 0; =20 err_kvm_init: --=20 2.49.0.472.ge94155a9ec-goog