From patchwork Wed Oct 11 13:39:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Jason J. Herne" X-Patchwork-Id: 9999647 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 9C71C60244 for ; Wed, 11 Oct 2017 13:41:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DE2828A42 for ; Wed, 11 Oct 2017 13:41:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8223428A44; Wed, 11 Oct 2017 13:41:44 +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 0BE7728A40 for ; Wed, 11 Oct 2017 13:41:43 +0000 (UTC) Received: from localhost ([::1]:41126 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2HGZ-0007Do-5U for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Oct 2017 09:41:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33168) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e2HFh-0007Bz-DI for qemu-devel@nongnu.org; Wed, 11 Oct 2017 09:40:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e2HFd-00053F-D0 for qemu-devel@nongnu.org; Wed, 11 Oct 2017 09:40:49 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38956) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e2HFd-00052C-4H for qemu-devel@nongnu.org; Wed, 11 Oct 2017 09:40:45 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v9BDeZ1N140853 for ; Wed, 11 Oct 2017 09:40:37 -0400 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0a-001b2d01.pphosted.com with ESMTP id 2dhh9wn9qg-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 11 Oct 2017 09:40:35 -0400 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 11 Oct 2017 07:39:57 -0600 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 11 Oct 2017 07:39:55 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v9BDds121573360; Wed, 11 Oct 2017 06:39:54 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 068CB78041; Wed, 11 Oct 2017 07:39:54 -0600 (MDT) Received: from jason-laptop.endicott.ibm.com (unknown [9.60.75.184]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id A1E2D78037; Wed, 11 Oct 2017 07:39:53 -0600 (MDT) From: "Jason J. Herne" To: qemu-devel@nongnu.org, cohuck@redhat.com, borntraeger@de.ibm.com Date: Wed, 11 Oct 2017 09:39:53 -0400 X-Mailer: git-send-email 2.7.4 X-TM-AS-GCONF: 00 x-cbid: 17101113-0016-0000-0000-000007A47578 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00007878; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000235; SDB=6.00929603; UDB=6.00467888; IPR=6.00709873; BA=6.00005634; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00017490; XFM=3.00000015; UTC=2017-10-11 13:39:57 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17101113-0017-0000-0000-00003BD05FDA Message-Id: <1507729193-9747-1-git-send-email-jjherne@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-10-11_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1710110189 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH] s390x/event-facility: variable-length event masks 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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Cornelia Huck The architecture supports masks of variable length for sclp write event mask. We currently only support 4 byte event masks, as that is what Linux uses. Let's extend this to the maximum mask length supported by the architecture and return 0 to the guest for the mask bits we don't support in core. Initial patch by: Cornelia Huck Signed-off-by: Cornelia Huck Signed-off-by: Jason J. Herne Acked-by: Christian Borntraeger --- hw/s390x/event-facility.c | 35 +++++++++++++++++++++++++++++------ include/hw/s390x/event-facility.h | 20 ++++++++++++++++---- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/hw/s390x/event-facility.c b/hw/s390x/event-facility.c index 34b2faf..b0f71f4 100644 --- a/hw/s390x/event-facility.c +++ b/hw/s390x/event-facility.c @@ -259,23 +259,46 @@ out: return; } +/* copy up to dst_len bytes and fill the rest of dst with zeroes */ +static void copy_mask(uint8_t *dst, uint8_t *src, uint16_t dst_len, + uint16_t src_len) +{ + int i; + + for (i = 0; i < dst_len; i++) { + dst[i] = i < src_len ? src[i] : 0; + } +} + static void write_event_mask(SCLPEventFacility *ef, SCCB *sccb) { WriteEventMask *we_mask = (WriteEventMask *) sccb; + uint16_t mask_length = be16_to_cpu(we_mask->mask_length); + uint32_t tmp_mask; - /* Attention: We assume that Linux uses 4-byte masks, what it actually - does. Architecture allows for masks of variable size, though */ - if (be16_to_cpu(we_mask->mask_length) != 4) { + if (!mask_length || (mask_length > SCLP_EVENT_MASK_LEN_MAX)) { sccb->h.response_code = cpu_to_be16(SCLP_RC_INVALID_MASK_LENGTH); goto out; } + /* + * Note: We currently only support masks up to 4 byte length; + * the remainder is filled up with zeroes. Linux uses + * a 4 byte mask length. + */ + /* keep track of the guest's capability masks */ - ef->receive_mask = be32_to_cpu(we_mask->cp_receive_mask); + copy_mask((uint8_t *)&tmp_mask, WEM_CP_RECEIVE_MASK(we_mask, mask_length), + sizeof(tmp_mask), mask_length); + ef->receive_mask = be32_to_cpu(tmp_mask); /* return the SCLP's capability masks to the guest */ - we_mask->send_mask = cpu_to_be32(get_host_send_mask(ef)); - we_mask->receive_mask = cpu_to_be32(get_host_receive_mask(ef)); + tmp_mask = cpu_to_be32(get_host_send_mask(ef)); + copy_mask(WEM_RECEIVE_MASK(we_mask, mask_length), (uint8_t *)&tmp_mask, + mask_length, sizeof(tmp_mask)); + tmp_mask = cpu_to_be32(get_host_receive_mask(ef)); + copy_mask(WEM_SEND_MASK(we_mask, mask_length), (uint8_t *)&tmp_mask, + mask_length, sizeof(tmp_mask)); sccb->h.response_code = cpu_to_be16(SCLP_RC_NORMAL_COMPLETION); diff --git a/include/hw/s390x/event-facility.h b/include/hw/s390x/event-facility.h index def1bb0..5119b9b 100644 --- a/include/hw/s390x/event-facility.h +++ b/include/hw/s390x/event-facility.h @@ -49,16 +49,28 @@ #define TYPE_SCLP_CPU_HOTPLUG "sclp-cpu-hotplug" #define TYPE_SCLP_QUIESCE "sclpquiesce" +#define SCLP_EVENT_MASK_LEN_MAX 1021 + typedef struct WriteEventMask { SCCBHeader h; uint16_t _reserved; uint16_t mask_length; - uint32_t cp_receive_mask; - uint32_t cp_send_mask; - uint32_t receive_mask; - uint32_t send_mask; + uint8_t masks[]; +/* + * Layout of the masks is + * uint8_t cp_receive_mask[mask_length]; + * uint8_t cp_send_mask[mask_length]; + * uint8_t receive_mask[mask_length]; + * uint8_t send_mask[mask_length]; + * where 1 <= mask_length <= SCLP_EVENT_MASK_LEN_MAX + */ } QEMU_PACKED WriteEventMask; +#define WEM_CP_RECEIVE_MASK(wem, mask_len) ((wem)->masks) +#define WEM_CP_SEND_MASK(wem, mask_len) ((wem)->masks + (mask_len)) +#define WEM_RECEIVE_MASK(wem, mask_len) ((wem)->masks + 2 * (mask_len)) +#define WEM_SEND_MASK(wem, mask_len) ((wem)->masks + 3 * (mask_len)) + typedef struct EventBufferHeader { uint16_t length; uint8_t type;