From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ingo Molnar Subject: Re: [PATCH 1/3 V2] kvm tools: Add memory gap for larger RAM sizes Date: Wed, 11 May 2011 09:39:00 +0200 Message-ID: <20110511073900.GA26020@elte.hu> References: <1305099257-7187-1-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: penberg@kernel.org, asias.hejun@gmail.com, prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com, kvm@vger.kernel.org To: Sasha Levin Return-path: Received: from fallback.mail.elte.hu ([157.181.151.13]:37360 "EHLO fallback.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756128Ab1EKP44 (ORCPT ); Wed, 11 May 2011 11:56:56 -0400 Received: from mx2.mail.elte.hu ([157.181.151.9]) by fallback.mail.elte.hu with esmtp (Exim) id 1QK49u-00060Y-8O from for ; Wed, 11 May 2011 09:48:38 +0200 Content-Disposition: inline In-Reply-To: <1305099257-7187-1-git-send-email-levinsasha928@gmail.com> Sender: kvm-owner@vger.kernel.org List-ID: * Sasha Levin wrote: > +void kvm__init_ram(struct kvm *self) > +{ > + if (self->ram_size < KVM_32BIT_GAP_START) { > + kvm_register_mem_slot(self, 0, 0, self->ram_size, (u64)self->ram_start); > + } else { > + kvm_register_mem_slot(self, 0, 0, KVM_32BIT_GAP_START, (u64)self->ram_start); > + kvm_register_mem_slot(self, 1, 0x100000000ULL, self->ram_size - KVM_32BIT_GAP_START, (u64)self->ram_start + 0x100000000ULL); Why not change kvm_register_mem_slot() to have a void * parameter for the start address? This has two advantages: - the ugly and fragile (u64) casts above disappear, as ->ram_start is already void * - we get type checking protection: if someone accidentally calls this function with (start, size) instead of (size, start) we'll get a compiler warning Basically every type you are forced to write a C type cast you should think hard to avoid it. They are almost always the wrong thing to do and are canaries of some other structural problem. Thanks, Ingo