From owner-freebsd-virtualization@FreeBSD.ORG Tue Nov 12 21:48:48 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 41ED72D8 for ; Tue, 12 Nov 2013 21:48:48 +0000 (UTC) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 0A16429ED for ; Tue, 12 Nov 2013 21:48:47 +0000 (UTC) Received: from julian-mbp3.pixel8networks.com (50-196-156-133-static.hfc.comcastbusiness.net [50.196.156.133]) (authenticated bits=0) by vps1.elischer.org (8.14.7/8.14.7) with ESMTP id rACLmed9075464 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Tue, 12 Nov 2013 13:48:41 -0800 (PST) (envelope-from julian@freebsd.org) Message-ID: <5282A233.9090401@freebsd.org> Date: Tue, 12 Nov 2013 13:48:35 -0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Mateusz Guzik , Sergey Kandaurov Subject: Re: Running `sysctl -a` causes crash (Hyper-V) References: <52814D25.1050603@freebsd.org> <20131112030154.GA29757@dft-labs.eu> <20131112133135.GB29757@dft-labs.eu> In-Reply-To: <20131112133135.GB29757@dft-labs.eu> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: "freebsd-virtualization@freebsd.org" X-BeenThere: freebsd-virtualization@freebsd.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "Discussion of various virtualization techniques FreeBSD supports." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Nov 2013 21:48:48 -0000 On 11/12/13, 5:31 AM, Mateusz Guzik wrote: > On Tue, Nov 12, 2013 at 03:33:45PM +0400, Sergey Kandaurov wrote: >> On 12 November 2013 07:01, Mateusz Guzik wrote: >>> On Mon, Nov 11, 2013 at 01:33:25PM -0800, Julian Elischer wrote: >>>> On 11/11/13, 7:49 AM, Pavel Timofeev wrote: >>>>> Great, it helped! Thanks a lot! >>>> the suggested change suggests fragile code. It should be able to >>>> handle unexpected input.. >>> Indeed, I already suggested Sergey placing a compile time assertion to >>> make sure vm_guest range is covered. >> I have the following change for this. >> Btw, the last element in vm_guest_sysctl_names is NULL, is it really needed >> for something? Unlike vm_bnames/vm_pnames, it seems not. >> > No idea, I would leave it be. > >> Add CTASSERT to handle enum VM_GUEST and vm_guest_sysctl_names cooperation. >> >> Index: sys/sys/systm.h >> =================================================================== >> --- sys/sys/systm.h (revision 258036) >> +++ sys/sys/systm.h (working copy) >> @@ -72,7 +72,8 @@ extern int vm_guest; /* Running as virtual machin >> * ever implemented (e.g. vendor-specific paravirtualization features). >> * Keep in sync with vm_guest_sysctl_names[]. >> */ >> -enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV }; >> +enum VM_GUEST { VM_GUEST_NO = 0, VM_GUEST_VM, VM_GUEST_XEN, VM_GUEST_HV, >> + VM_LAST }; >> >> #if defined(WITNESS) || defined(INVARIANTS) >> void kassert_panic(const char *fmt, ...) __printflike(1, 2); >> Index: sys/kern/subr_param.c >> =================================================================== >> --- sys/kern/subr_param.c (revision 258036) >> +++ sys/kern/subr_param.c (working copy) >> @@ -156,6 +156,7 @@ static const char *const vm_guest_sysctl_names[] = >> "hv", >> NULL >> }; >> +CTASSERT(nitems(vm_guest_sysctl_names) - 1 == VM_LAST); hmm. one learns something every day. nitems() is new to me.. yes assuming nitems is supported on all platforms then this adds a safety belt and is a good idea. >> >> #ifndef XEN >> static const char *const vm_bnames[] = { >> > I can't test it right now, I presume it works :) > > With that in mind looks good to me, thanks! >