From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abNzY-0002yw-7r for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:48:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abNzT-0001kM-3v for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:48:12 -0500 Received: from e06smtp05.uk.ibm.com ([195.75.94.101]:56601) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abNzS-0001jw-PN for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:48:07 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 3 Mar 2016 07:48:04 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 19BB01B0804B for ; Thu, 3 Mar 2016 07:48:25 +0000 (GMT) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u237m1d52228574 for ; Thu, 3 Mar 2016 07:48:01 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u237m1lr027942 for ; Thu, 3 Mar 2016 02:48:01 -0500 Date: Thu, 3 Mar 2016 08:47:59 +0100 From: David Hildenbrand Message-ID: <20160303084759.16aa52dc@thinkpad-w530> In-Reply-To: <56D74400.5020308@linux.vnet.ibm.com> References: <1456866806-31466-1-git-send-email-mjrosato@linux.vnet.ibm.com> <1456866806-31466-6-git-send-email-mjrosato@linux.vnet.ibm.com> <20160302085716.7874dd8d@thinkpad-w530> <56D74400.5020308@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v7 5/6] s390x/cpu: Add error handling to cpu creation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Matthew Rosato Cc: imammedo@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, borntraeger@de.ibm.com, bharata@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, pbonzini@redhat.com, afaerber@suse.de, rth@twiddle.net > >> +static void s390_cpu_get_id(Object *obj, Visitor *v, const char *name, > >> + void *opaque, Error **errp) > >> +{ > >> + S390CPU *cpu = S390_CPU(obj); > >> + int64_t value = cpu->id; > >> + > >> + visit_type_int(v, name, &value, errp); > >> +} > >> + > >> +static void s390_cpu_set_id(Object *obj, Visitor *v, const char *name, > >> + void *opaque, Error **errp) > >> +{ > >> + S390CPU *cpu = S390_CPU(obj); > >> + DeviceState *dev = DEVICE(obj); > >> + const int64_t min = 0; > >> + const int64_t max = UINT32_MAX; > >> + Error *local_err = NULL; > >> + int64_t value; > >> + > >> + if (dev->realized) { > >> + error_setg(errp, "Attempt to set property '%s' on '%s' after " > >> + "it was realized", name, object_get_typename(obj)); > >> + return; > >> + } > >> + > >> + visit_type_int(v, name, &value, &local_err); > >> + if (local_err) { > >> + error_propagate(errp, local_err); > >> + return; > >> + } > >> + if (value < min || value > max) { > >> + error_setg(errp, "Property %s.%s doesn't take value %" PRId64 > >> + " (minimum: %" PRId64 ", maximum: %" PRId64 ")" , > >> + object_get_typename(obj), name, value, min, max); > >> + return; > >> + } > >> + if ((value != cpu->id) && cpu_exists(value)) { > >> + error_setg(errp, "CPU with ID %" PRIi64 " exists", value); > >> + return; > >> + } > >> + cpu->id = value; > >> +} > > > > Just curious, what about using a simple > > > > object_property_set_int() and doing all the checks in realize() ? > > > > Then we could live without manual getter/setter (and without the realize check). > > > > I think we still need at least a manual setter, even if you want to move > the checks to realize. > > See something like object_property_add_uint64_ptr() -- It sets a > boilerplate get routine, and no set routine -- I think this presumes you > set your property upfront (at add time), never change it for the life of > the object, but want to read it later. > By comparison, S390CPU.id is set sometime after instance_init, based on > input. > > So, we call object_property_set_int() to update it -- This just passes > the provided int value to the setter routine associated with the > property. If one doesn't exist, you get: > qemu: Insufficient permission to perform this operation > > I think this is also why we want to check for dev->realized in the > setter routine, to make sure the property is not being changed "too > late" -- Once the cpu is realized, the ID is baked and can't be changed. > > Or did I misunderstand your idea here? If we care about malicious users, wanting to set id's after realize that is true. But I am no QOM expert and don't know if that is a scenarios that has to be taken care of. But as I see similar code for other properties, I assume we are better off doing it also that way. David