From patchwork Thu Sep 14 14:26:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 9953191 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4A7FF6024A for ; Thu, 14 Sep 2017 14:26:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33A0E29100 for ; Thu, 14 Sep 2017 14:26:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 283DE2910F; Thu, 14 Sep 2017 14:26:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC03029100 for ; Thu, 14 Sep 2017 14:26:51 +0000 (UTC) Received: from localhost ([::1]:48111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsV6R-0006EQ-4b for patchwork-qemu-devel@patchwork.kernel.org; Thu, 14 Sep 2017 10:26:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dsV5p-0006CL-9N for qemu-devel@nongnu.org; Thu, 14 Sep 2017 10:26:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dsV5m-0007fo-2g for qemu-devel@nongnu.org; Thu, 14 Sep 2017 10:26:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38216) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dsV5l-0007fA-QX for qemu-devel@nongnu.org; Thu, 14 Sep 2017 10:26:10 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C8CC783F40; Thu, 14 Sep 2017 14:26:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C8CC783F40 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=cohuck@redhat.com Received: from gondolin (ovpn-204-195.brq.redhat.com [10.40.204.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FAB7617A8; Thu, 14 Sep 2017 14:26:07 +0000 (UTC) Date: Thu, 14 Sep 2017 16:26:03 +0200 From: Cornelia Huck To: Halil Pasic Message-ID: <20170914162603.1cdabd09.cohuck@redhat.com> In-Reply-To: <20170913132752.8484-2-pasic@linux.vnet.ibm.com> References: <20170913132752.8484-1-pasic@linux.vnet.ibm.com> <20170913132752.8484-2-pasic@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 14 Sep 2017 14:26:08 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: Re: [Qemu-devel] [PATCH 1/2] s390x/ccs: add ccw-tester emulated device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Dong Jia Shi , Pierre Morel , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Wed, 13 Sep 2017 15:27:51 +0200 Halil Pasic wrote: > Add a fake device meant for testing the correctness of our css emulation. > > What we currently have is writing a Fibonacci sequence of uint32_t to the > device via ccw write. The write is going to fail if it ain't a Fibonacci > and indicate a device exception in scsw together with the proper residual > count. > > Of course lot's of invalid inputs (besides basic data processing) can be > tested with that as well. > > Usage: > 1) fire up a qemu with something like -device ccw-tester,devno=fe.0.0001 > on the command line > 2) exercise the device from the guest > > Signed-off-by: Halil Pasic > --- > > Depends on the series 'add CCW indirect data access support' > > --- > hw/s390x/Makefile.objs | 1 + > hw/s390x/ccw-tester.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 180 insertions(+) > create mode 100644 hw/s390x/ccw-tester.c > > +static int ccw_tester_write_fib(SubchDev *sch, CCW1 ccw) > +{ > + CcwTesterDevice *d = sch->driver_data; > + bool is_fib = true; > + uint32_t sum; > + int ret = 0; > + > + ccw_dstream_init(&sch->cds, &ccw, &sch->orb); > + d->fib.next = 0; > + while (ccw_dstream_avail(&sch->cds) > 0) { > + ret = ccw_dstream_read(&sch->cds, > + d->fib.ring[abs_to_ring(d->fib.next)]); > + if (ret) { > + error(0, -ret, "fib"); > + break; > + } > + if (d->fib.next > 2) { > + sum = (d->fib.ring[abs_to_ring(d->fib.next - 1)] > + + d->fib.ring[abs_to_ring(d->fib.next - 2)]); > + is_fib = sum == d->fib.ring[abs_to_ring(d->fib.next)]; This is not endian-safe (noticed while testing on my laptop). Trivial to fix: > + if (!is_fib) { > + break; > + } > + } > + ++(d->fib.next); > + } > + if (!is_fib) { > + sch->curr_status.scsw.ctrl &= ~SCSW_ACTL_START_PEND; > + sch->curr_status.scsw.ctrl |= SCSW_STCTL_PRIMARY | > + SCSW_STCTL_SECONDARY | > + SCSW_STCTL_ALERT | > + SCSW_STCTL_STATUS_PEND; > + sch->curr_status.scsw.count = ccw_dstream_residual_count(&sch->cds); > + sch->curr_status.scsw.cpa = sch->channel_prog + 8; > + sch->curr_status.scsw.dstat = SCSW_DSTAT_UNIT_EXCEP; > + return -EIO; > + } > + return ret; > +} > + (...) > +static Property ccw_tester_properties[] = { > + DEFINE_PROP_UINT16("cu_type", CcwTesterDevice, cu_type, > + 0x3831), 0x4711 would be nice :) If we want to follow up on that testdev idea (and I think we should), it might make sense to have a proper type reserve to prevent accidental clashes. (Or is there already something reserved for "hypervisor use" or whatever?) > + DEFINE_PROP_UINT8("chpid_type", CcwTesterDevice, chpid_type, > + 0x98), > + DEFINE_PROP_END_OF_LIST(), > +}; IIUC, pci-testdev provides some unit tests to testers (like kvm-tests) itself. This might be an idea to follow up on for ccw as well. There's quite some potential in this. We may want to make this a permanent addition. diff --git a/hw/s390x/ccw-tester.c b/hw/s390x/ccw-tester.c index c8017818c4..a425daaa34 100644 --- a/hw/s390x/ccw-tester.c +++ b/hw/s390x/ccw-tester.c @@ -58,9 +58,9 @@ static int ccw_tester_write_fib(SubchDev *sch, CCW1 ccw) break; } if (d->fib.next > 2) { - sum = (d->fib.ring[abs_to_ring(d->fib.next - 1)] - + d->fib.ring[abs_to_ring(d->fib.next - 2)]); - is_fib = sum == d->fib.ring[abs_to_ring(d->fib.next)]; + sum = be32_to_cpu(d->fib.ring[abs_to_ring(d->fib.next - 1)]) + + be32_to_cpu(d->fib.ring[abs_to_ring(d->fib.next - 2)]); + is_fib = sum == be32_to_cpu(d->fib.ring[abs_to_ring(d->fib.next)]); if (!is_fib) { break; }