From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752182AbcGAImJ (ORCPT ); Fri, 1 Jul 2016 04:42:09 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:33374 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751036AbcGAImG (ORCPT ); Fri, 1 Jul 2016 04:42:06 -0400 Subject: Re: [PATCH v1 03/11] KVM: x86: dynamic kvm_apic_map To: Andrew Honig , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= References: <20160630205429.16480-1-rkrcmar@redhat.com> <20160630205429.16480-4-rkrcmar@redhat.com> Cc: linux-kernel@vger.kernel.org, kvm , "Lan, Tianyu" , Igor Mammedov , Jan Kiszka , Peter Xu From: Paolo Bonzini Message-ID: Date: Fri, 1 Jul 2016 10:42:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.1.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/07/2016 00:15, Andrew Honig wrote: >> > + /* kvm_apic_map_get_logical_dest() expects multiples of 16 */ >> > + size = round_up(max_id + 1, 16); > Now that you're using the full range of apic_id values, could this > calculation overflow? Perhaps max_id could be u64? Good point, but I wonder if it's a good idea to let userspace allocate 32 GB of memory. :) Let's put a limit on the maximum supported APIC ID, and report it through KVM_CHECK_EXTENSION on the new KVM_CAP_X2APIC_API capability. If 767 is enough for Knights Landing, the allocation below fits in two pages. If you need to make it higher, please change the allocation to use kvm_kvzalloc and kvfree. Last but not least... >> > + new = kzalloc(sizeof(struct kvm_apic_map) + >> > + sizeof(struct kvm_lapic) * size, GFP_KERNEL); ^^^^^^^^^^^^^^^^^^^^^^^^ ... the sizeof here must be sizeof(struct kvm_lapic *). Thanks, Paolo