From patchwork Tue Jan 19 19:52:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12030655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B30FC433DB for ; Tue, 19 Jan 2021 19:54:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B53F82310D for ; Tue, 19 Jan 2021 19:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729810AbhASTyD (ORCPT ); Tue, 19 Jan 2021 14:54:03 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:4784 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392020AbhASTxX (ORCPT ); Tue, 19 Jan 2021 14:53:23 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10JJXpXK068391; Tue, 19 Jan 2021 14:52:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=Nsj2S9g3UGYn0YL15B/RwQuQTozZIRIjXVlGiMkrA8U=; b=nm2UFjqdtv4KBUxLn9ZQI8kQQFGOVNZws21Yojyh3YtJ3oL9bwa8zZ9m9Sd3gDLCwz4c 6ude27F+j+dEjG949bKYYNM/IH2zlGE1OrkVdGRqkcVjfgvP7PUOpy1qwK+H6OvosCOX 17YT6rOGK0mcYLVTA3BUBYdKnuPj5yRxFc4guORqVuGK7SBD7PInFWjot/x9Ziao2Fyi fnkPgkO918/XuBEOVFzVMLz8ujYzpLH1LEU8zxxEp8Pn0H6gpB5XkvKho2hJkJ4R7hFo xl+w/vjvKZHF08LuS/8sq9AWu2PSFiX6SB/9EgWtlDlyw2sCubEtyhvvYevztgj5ZzYk TQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 36621p7nhg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:32 -0500 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10JJncg2131754; Tue, 19 Jan 2021 14:52:31 -0500 Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com with ESMTP id 36621p7ngp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:31 -0500 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10JJlq4l001790; Tue, 19 Jan 2021 19:52:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06fra.de.ibm.com with ESMTP id 363qdh9s7y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 19:52:29 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10JJqQvG46662098 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 19:52:26 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5942742047; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E6DCB4203F; Tue, 19 Jan 2021 19:52:25 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.38.46]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jan 2021 19:52:25 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v3 1/3] s390x: pv: implement routine to share/unshare memory Date: Tue, 19 Jan 2021 20:52:22 +0100 Message-Id: <1611085944-21609-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> References: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-19_09:2021-01-18,2021-01-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 impostorscore=0 spamscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 phishscore=0 adultscore=0 mlxlogscore=999 clxscore=1015 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190106 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When communicating with the host we need to share part of the memory. Let's implement the ultravisor calls for this. Signed-off-by: Pierre Morel Suggested-by: Janosch Frank Acked-by: Cornelia Huck Acked-by: Thomas Huth --- lib/s390x/asm/uv.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 4c2fc48..1242336 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -71,4 +71,42 @@ static inline int uv_call(unsigned long r1, unsigned long r2) return cc; } +static inline int share(unsigned long addr, u16 cmd) +{ + struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len = sizeof(uvcb), + .paddr = addr + }; + int cc; + + cc = uv_call(0, (u64)&uvcb); + if (!cc && (uvcb.header.rc == 0x0001)) + return 0; + + report_info("cc %d response code: %04x", cc, uvcb.header.rc); + return -1; +} + +/* + * Guest 2 request to the Ultravisor to make a page shared with the + * hypervisor for IO. + * + * @addr: Real or absolute address of the page to be shared + */ +static inline int uv_set_shared(unsigned long addr) +{ + return share(addr, UVC_CMD_SET_SHARED_ACCESS); +} + +/* + * Guest 2 request to the Ultravisor to make a page unshared. + * + * @addr: Real or absolute address of the page to be unshared + */ +static inline int uv_remove_shared(unsigned long addr) +{ + return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); +} + #endif From patchwork Tue Jan 19 19:52:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12030657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB263C433DB for ; Tue, 19 Jan 2021 19:54:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 606802310C for ; Tue, 19 Jan 2021 19:54:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728501AbhASTyY (ORCPT ); Tue, 19 Jan 2021 14:54:24 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:27706 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392053AbhASTxX (ORCPT ); Tue, 19 Jan 2021 14:53:23 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10JJGdEU127929; Tue, 19 Jan 2021 14:52:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=ZQvkzbwz8iU+rMecJtZsQpH7Vo1uQvCsWMNSWZBNpr0=; b=VDUm3LV/p2zuw7Rejc8/A2HvIpnP6tqFjDT1HD4YgRd5KvUcAhkcljMKjavvPENvRcCd AiheTCeLOLuxN1Kf+YvenRfyWCcy52JbZa00A7kYKPDd/hCLRq/3A26hKRWFAax5OdZV +oq14w1ww7RtyZd7fpGuVpGAvQrZJUqCowTYiHA35R47gatj84vnxSvwa3eda1wC+YzP rquFyNe6RC/l4X5PmRcIOsgr75HZN+gqquTF2f70Iqbr0DgW5uGtp5+drNpFmeceCUnh Xviu6c7QhdkqaQp7aevNOT5L/YYNnxuyV/HJjJxPWvUtc+8nxWnMGPDGI68I0yOGgysN hQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3665ebgrp5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:32 -0500 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10JJhqtU080748; Tue, 19 Jan 2021 14:52:32 -0500 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3665ebgrnk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:31 -0500 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10JJkxh2025163; Tue, 19 Jan 2021 19:52:29 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 363qs8bdqw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 19:52:29 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10JJqQ6r21692748 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 19:52:27 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D8EDA42041; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 697D54203F; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.38.46]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v3 2/3] s390x: define UV compatible I/O allocation Date: Tue, 19 Jan 2021 20:52:23 +0100 Message-Id: <1611085944-21609-3-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> References: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-19_07:2021-01-18,2021-01-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 mlxscore=0 suspectscore=0 bulkscore=0 impostorscore=0 spamscore=0 mlxlogscore=999 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190104 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To centralize the memory allocation for I/O we define the alloc_io_page/free_io_page functions which share the I/O memory with the host in case the guest runs with protected virtualization. Signed-off-by: Pierre Morel --- lib/s390x/malloc_io.c | 50 +++++++++++++++++++++++++++++++++++++++++++ lib/s390x/malloc_io.h | 18 ++++++++++++++++ s390x/Makefile | 1 + 3 files changed, 69 insertions(+) create mode 100644 lib/s390x/malloc_io.c create mode 100644 lib/s390x/malloc_io.h diff --git a/lib/s390x/malloc_io.c b/lib/s390x/malloc_io.c new file mode 100644 index 0000000..2a946e0 --- /dev/null +++ b/lib/s390x/malloc_io.c @@ -0,0 +1,50 @@ +/* + * I/O page allocation + * + * Copyright (c) 2021 IBM Corp + * + * Authors: + * Pierre Morel + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + * + * Using this interface provide host access to the allocated pages in + * case the guest is a secure guest. + * This is needed for I/O buffers. + * + */ +#include +#include +#include +#include +#include +#include + +void *alloc_io_page(int size) +{ + void *p; + + assert(size <= PAGE_SIZE); + + p = alloc_pages_flags(1, AREA_DMA31); + if (!p) + return NULL; + memset(p, 0, PAGE_SIZE); + + if (!test_facility(158)) + return p; + + if (uv_set_shared((unsigned long)p) == 0) + return p; + + free_pages(p); + return NULL; +} + +void free_io_page(void *p) +{ + if (test_facility(158)) + uv_remove_shared((unsigned long)p); + free_pages(p); +} diff --git a/lib/s390x/malloc_io.h b/lib/s390x/malloc_io.h new file mode 100644 index 0000000..f780191 --- /dev/null +++ b/lib/s390x/malloc_io.h @@ -0,0 +1,18 @@ +/* + * I/O allocations + * + * Copyright (c) 2021 IBM Corp + * + * Authors: + * Pierre Morel + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ +#ifndef _S390X_MALLOC_IO_H_ +#define _S390X_MALLOC_IO_H_ + +void *alloc_io_page(int size); +void free_io_page(void *p); + +#endif /* _S390X_MALLOC_IO_H_ */ diff --git a/s390x/Makefile b/s390x/Makefile index b079a26..4b6301c 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -63,6 +63,7 @@ cflatobjs += lib/s390x/smp.o cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o +cflatobjs += lib/s390x/malloc_io.o OBJDIRS += lib/s390x From patchwork Tue Jan 19 19:52:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12030653 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DD7D6C433E0 for ; Tue, 19 Jan 2021 19:54:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 95ADD2310D for ; Tue, 19 Jan 2021 19:54:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729434AbhASTx7 (ORCPT ); Tue, 19 Jan 2021 14:53:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:32612 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392074AbhASTxY (ORCPT ); Tue, 19 Jan 2021 14:53:24 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10JJW8w1190112; Tue, 19 Jan 2021 14:52:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=MbFOPjX7APzijhAifwN8gTGQ4+/y6UaXufsco1nF+LU=; b=fRAnmUZJQetUZmChmB7Q2YIm5dzf94gDWfvYsJX6KqUYOhyLuf4RX7lFpPfnGKHUygxz chUbSX+60VDzOfpsoxQExvaN/LYZ9D+WJPRZ+vxG6uSqMbSd25ENEdqOh4uQIlrnOJi3 C2kP2Re/kFO/FSpBfHdOJU9CYoEiLJO7WNxH/juLtrUwHKDy2D24PJ+SPkYt9M0K0Qy4 i1LZdgoOWi8KGbbhXG5Lr6V9PeqtRBfkrTjNOhMB/IE2Fsyjnn7kADb28JsQ2FR3ypqD YyhEfyZOQO/TLRG82mcDru9HH7pBp2VHuQONlJJOEY270h27S2vogoqg2GzQ/pwQelAr Cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 36653s1eb4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:34 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10JJWM9L191080; Tue, 19 Jan 2021 14:52:33 -0500 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 36653s1e9w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 14:52:33 -0500 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 10JJlT1o030352; Tue, 19 Jan 2021 19:52:30 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03ams.nl.ibm.com with ESMTP id 363qs7kdkm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 19 Jan 2021 19:52:30 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10JJqRuU34734520 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 19 Jan 2021 19:52:27 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A4CB42045; Tue, 19 Jan 2021 19:52:27 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E91294203F; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.38.46]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 19 Jan 2021 19:52:26 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v3 3/3] s390x: css: pv: css test adaptation for PV Date: Tue, 19 Jan 2021 20:52:24 +0100 Message-Id: <1611085944-21609-4-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> References: <1611085944-21609-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-19_07:2021-01-18,2021-01-19 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 spamscore=0 mlxscore=0 malwarescore=0 mlxlogscore=999 clxscore=1015 bulkscore=0 phishscore=0 suspectscore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101190104 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We want the tests to automatically work with or without protected virtualisation. To do this we need to share the I/O memory with the host. Let's replace all static allocations with dynamic allocations to clearly separate shared and private memory. Signed-off-by: Pierre Morel --- lib/s390x/css.h | 3 +-- lib/s390x/css_lib.c | 28 ++++++++-------------------- s390x/css.c | 35 ++++++++++++++++++++++++----------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/s390x/css.h b/lib/s390x/css.h index 221b67c..e3dee9f 100644 --- a/lib/s390x/css.h +++ b/lib/s390x/css.h @@ -283,8 +283,7 @@ int css_enable(int schid, int isc); /* Library functions */ int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw); -int start_single_ccw(unsigned int sid, int code, void *data, int count, - unsigned char flags); +struct ccw1 *ccw_alloc(int code, void *data, int count, unsigned char flags); void css_irq_io(void); int css_residual_count(unsigned int schid); diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c index 8e02371..6a0a0ec 100644 --- a/lib/s390x/css_lib.c +++ b/lib/s390x/css_lib.c @@ -18,6 +18,7 @@ #include #include +#include #include static struct schib schib; @@ -202,33 +203,20 @@ int start_ccw1_chain(unsigned int sid, struct ccw1 *ccw) return ssch(sid, &orb); } -/* - * In the future, we want to implement support for CCW chains; - * for that, we will need to work with ccw1 pointers. - */ -static struct ccw1 unique_ccw; - -int start_single_ccw(unsigned int sid, int code, void *data, int count, - unsigned char flags) +struct ccw1 *ccw_alloc(int code, void *data, int count, unsigned char flags) { - int cc; - struct ccw1 *ccw = &unique_ccw; + struct ccw1 *ccw; + + ccw = alloc_io_page(sizeof(*ccw)); + if (!ccw) + return NULL; - report_prefix_push("start_subchannel"); - /* Build the CCW chain with a single CCW */ ccw->code = code; ccw->flags = flags; ccw->count = count; ccw->data_address = (int)(unsigned long)data; - cc = start_ccw1_chain(sid, ccw); - if (cc) { - report(0, "cc = %d", cc); - report_prefix_pop(); - return cc; - } - report_prefix_pop(); - return 0; + return ccw; } /* wait_and_check_io_completion: diff --git a/s390x/css.c b/s390x/css.c index ee3bc83..4b0b6b1 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -17,13 +17,15 @@ #include #include +#include #include +#include #define DEFAULT_CU_TYPE 0x3832 /* virtio-ccw */ static unsigned long cu_type = DEFAULT_CU_TYPE; static int test_device_sid; -static struct senseid senseid; +static struct senseid *senseid; static void test_enumerate(void) { @@ -57,6 +59,7 @@ static void test_enable(void) */ static void test_sense(void) { + struct ccw1 *ccw; int ret; int len; @@ -80,9 +83,15 @@ static void test_sense(void) lowcore_ptr->io_int_param = 0; - memset(&senseid, 0, sizeof(senseid)); - ret = start_single_ccw(test_device_sid, CCW_CMD_SENSE_ID, - &senseid, sizeof(senseid), CCW_F_SLI); + senseid = alloc_io_page(sizeof(*senseid)); + if (!senseid) + goto error_senseid; + + ccw = ccw_alloc(CCW_CMD_SENSE_ID, senseid, sizeof(*senseid), CCW_F_SLI); + if (!ccw) + goto error_ccw; + + ret = start_ccw1_chain(test_device_sid, ccw); if (ret) goto error; @@ -97,7 +106,7 @@ static void test_sense(void) if (ret < 0) { report_info("no valid residual count"); } else if (ret != 0) { - len = sizeof(senseid) - ret; + len = sizeof(*senseid) - ret; if (ret && len < CSS_SENSEID_COMMON_LEN) { report(0, "transferred a too short length: %d", ret); goto error; @@ -105,21 +114,25 @@ static void test_sense(void) report_info("transferred a shorter length: %d", len); } - if (senseid.reserved != 0xff) { - report(0, "transferred garbage: 0x%02x", senseid.reserved); + if (senseid->reserved != 0xff) { + report(0, "transferred garbage: 0x%02x", senseid->reserved); goto error; } report_prefix_pop(); report_info("reserved 0x%02x cu_type 0x%04x cu_model 0x%02x dev_type 0x%04x dev_model 0x%02x", - senseid.reserved, senseid.cu_type, senseid.cu_model, - senseid.dev_type, senseid.dev_model); + senseid->reserved, senseid->cu_type, senseid->cu_model, + senseid->dev_type, senseid->dev_model); - report(senseid.cu_type == cu_type, "cu_type expected 0x%04x got 0x%04x", - (uint16_t) cu_type, senseid.cu_type); + report(senseid->cu_type == cu_type, "cu_type expected 0x%04x got 0x%04x", + (uint16_t) cu_type, senseid->cu_type); error: + free_io_page(ccw); +error_ccw: + free_io_page(senseid); +error_senseid: unregister_io_int_func(css_irq_io); }