From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: Re: [kvm-unit-tests PATCH 01/14] x86: vm: allow multiple init for vm setup Date: Thu, 20 Oct 2016 16:24:08 +0800 Message-ID: <20161020082408.GI15168@pxdev.xzpeter.org> References: <1476448852-30062-1-git-send-email-peterx@redhat.com> <1476448852-30062-2-git-send-email-peterx@redhat.com> <20161020081707.6ewyxtkaxuoslz6u@kamzik.brq.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: kvm@vger.kernel.org, jan.kiszka@web.de, agordeev@redhat.com, rkrcmar@redhat.com, pbonzini@redhat.com To: Andrew Jones Return-path: Received: from mx1.redhat.com ([209.132.183.28]:46988 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754597AbcJTIYN (ORCPT ); Thu, 20 Oct 2016 04:24:13 -0400 Content-Disposition: inline In-Reply-To: <20161020081707.6ewyxtkaxuoslz6u@kamzik.brq.redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Thu, Oct 20, 2016 at 10:17:07AM +0200, Andrew Jones wrote: > On Fri, Oct 14, 2016 at 08:40:39PM +0800, Peter Xu wrote: > > Signed-off-by: Peter Xu > > --- > > lib/x86/vm.c | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/lib/x86/vm.c b/lib/x86/vm.c > > index 906fbf2..9771bd7 100644 > > --- a/lib/x86/vm.c > > +++ b/lib/x86/vm.c > > @@ -151,9 +151,16 @@ static void setup_mmu(unsigned long len) > > > > void setup_vm() > > { > > + static bool vm_inited = false; > > + > > + if (vm_inited) { > > + return; > > + } > > + > > end_of_memory = fwcfg_get_u64(FW_CFG_RAM_SIZE); > > free_memory(&edata, end_of_memory - (unsigned long)&edata); > > setup_mmu(end_of_memory); > > + vm_inited = true; > > } > > > > void *vmalloc(unsigned long size) > > -- > > 2.7.4 > > > > My preference for kvm-unit-tests is that we avoid tolerating > unit tests that do things "wrong". This patch allows setup_vm > to be called multiple times, but why do that? Why not just > ensure it's only called once? If it looks like a mistake that's > easy to make and hard to debug, then maybe we need an assert > > assert(!end_of_memory); /* ensure we haven't already called setup_vm */ > > or something. Yeah, sure. The first two patches are just something good to have IMO, I did it since I see we have similar thing in setup_idt(), and I feel it good. I can replace it with an assertion. Thanks. -- peterx