From owner-freebsd-virtualization@FreeBSD.ORG Tue Nov 12 13:31:43 2013 Return-Path: Delivered-To: freebsd-virtualization@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B644EFC1; Tue, 12 Nov 2013 13:31:43 +0000 (UTC) Received: from mail-wg0-x236.google.com (mail-wg0-x236.google.com [IPv6:2a00:1450:400c:c00::236]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 296432C43; Tue, 12 Nov 2013 13:31:43 +0000 (UTC) Received: by mail-wg0-f54.google.com with SMTP id y10so2471848wgg.9 for ; Tue, 12 Nov 2013 05:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=AVabwv/D9+Cz7MIrjTlPiDfzBfCfrt+PMYx3Y0k4I0w=; b=SiZxouEdJZXQj/I5iLKOaDmaTNOeS+7XpBK8O9gsV/kRPN7frOMn9YjAj3ZdeM+oYg uS2Ur6Yb66zfLA3BFX4yoCDek/v3l9AoSz5uvJFuEyMywnI5VYAniL9mTmeX3OQu8p8G I7Lno2c8daz9kJjR/s1oiLhd9ef4Rn251hdLd8Xm6CKenMx9jgq+eaCEScHzkacub9ur Ir4hkYwVQTxt9ejwL13bhUL0AyTurR/QFjq75jvhRTg4VJYJf6sbNYzbA0BRgdjBsqoO kdWRLUvqE6jMHpwuLLvhrmEJdbCK/K/V1PdVES3AhBMz6qgQS0GsP6i2hFXA+Kfz7H4o CRyQ== X-Received: by 10.194.193.39 with SMTP id hl7mr11876wjc.91.1384263101625; Tue, 12 Nov 2013 05:31:41 -0800 (PST) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by mx.google.com with ESMTPSA id ey4sm44699996wic.11.2013.11.12.05.31.39 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 12 Nov 2013 05:31:40 -0800 (PST) Date: Tue, 12 Nov 2013 14:31:35 +0100 From: Mateusz Guzik To: Sergey Kandaurov Subject: Re: Running `sysctl -a` causes crash (Hyper-V) Message-ID: <20131112133135.GB29757@dft-labs.eu> References: <52814D25.1050603@freebsd.org> <20131112030154.GA29757@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 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 13:31:43 -0000 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); > > #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! -- Mateusz Guzik