Received: from eggs.gnu.org ([2001:4830:134:3::10]:54417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWQt2-0001BJ-0Z for qemu-devel@nongnu.org; Mon, 31 Aug 2015 11:20:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZWQsu-0004V4-Pn for qemu-devel@nongnu.org; Mon, 31 Aug 2015 11:20:44 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:48033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZWQsu-0004UV-2u for qemu-devel@nongnu.org; Mon, 31 Aug 2015 11:20:36 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 31 Aug 2015 16:20:34 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id A93ED219004D for ; Mon, 31 Aug 2015 16:20:04 +0100 (BST) Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t7VFKS4v16908452 for ; Mon, 31 Aug 2015 15:20:31 GMT Received: from d06av02.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t7VFKJFR009071 for ; Mon, 31 Aug 2015 09:20:19 -0600 Date: Mon, 31 Aug 2015 17:20:08 +0200 From: Cornelia Huck Message-ID: <20150831172008.0a695bb2.cornelia.huck@de.ibm.com> In-Reply-To: <55E46923.4030304@redhat.com> References: <1441018834-8993-1-git-send-email-cornelia.huck@de.ibm.com> <1441018834-8993-5-git-send-email-cornelia.huck@de.ibm.com> <55E46923.4030304@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v3 4/8] s390x: Dump storage keys qmp command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, qemu-devel@nongnu.org, jjherne@linux.vnet.ibm.com, agraf@suse.de On Mon, 31 Aug 2015 08:48:03 -0600 Eric Blake wrote: > On 08/31/2015 05:00 AM, Cornelia Huck wrote: > > From: "Jason J. Herne" > > > > Provide a dump-skeys qmp command to allow the end user to dump storage > > keys. This is useful for debugging problems with guest storage key support > > within Qemu and for guest operating system developers. > > > > Reviewed-by: Thomas Huth > > Reviewed-by: David Hildenbrand > > Signed-off-by: Jason J. Herne > > Signed-off-by: Cornelia Huck > > --- > > hw/s390x/s390-skeys.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++-- > > monitor.c | 7 ++++ > > qapi-schema.json | 14 ++++++++ > > qmp-commands.hx | 25 ++++++++++++++ > > 4 files changed, 134 insertions(+), 2 deletions(-) > > > > > +static void write_keys(QEMUFile *f, uint8_t *keys, uint64_t startgfn, > > + uint64_t count, Error **errp) > > +{ > > + uint64_t curpage = startgfn; > > + uint64_t maxpage = curpage + count - 1; > > + const char *fmt = "page=%03" PRIx64 ": key(%d) => ACC=%X, FP=%d, REF=%d," > > + " ch=%d, reserved=%d\n"; > > + char buf[128]; > > + int len; > > + > > + for (; curpage <= maxpage; curpage++) { > > + uint8_t acc = (*keys & 0xF0) >> 4; > > + int fp = (*keys & 0x08); > > + int ref = (*keys & 0x04); > > + int ch = (*keys & 0x02); > > + int res = (*keys & 0x01); > > + > > + len = snprintf(buf, sizeof(buf), fmt, curpage, > > + *keys, acc, fp, ref, ch, res); > > + qemu_put_buffer(f, (uint8_t *)buf, len); > > While I can overlook the use of snprintf(), I still think you ought to > at least have assert(len < sizeof(buf)) here before the > qemu_put_buffer(), to ensure that future changes to fmt don't attempt to > print beyond the end of the fixed-width buffer. I'll just merge that in when sending the pull request. > > With an assert added, > Reviewed-by: Eric Blake > Thanks!