From patchwork Fri Sep 25 16:02:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 11800199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A1E5092C for ; Fri, 25 Sep 2020 16:02:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4872120759 for ; Fri, 25 Sep 2020 16:02:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Dr2kkros" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728492AbgIYQCx (ORCPT ); Fri, 25 Sep 2020 12:02:53 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:30696 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727201AbgIYQCw (ORCPT ); Fri, 25 Sep 2020 12:02:52 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08PG1tVC138146; Fri, 25 Sep 2020 12:02:52 -0400 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=Etdk7PsqeLaD3Vusxf283pn0UpNfftluNM0Nl0Hj960=; b=Dr2kkrosiZlfGK2ingIVQlJsmmoocA+ZlvWqpno42OC/wGbMztC4QEW0ktKCE1T2zSKW bw6TUNHhrhDbbdg04d0hrCft3jeqIWrr8J9gcltyLZRauYxI8KZQJNYpxUuYx2L+LzyA bwDCgVWEBw+PWWmlpBmwExQdXJSV24E/w0B2EblvbuA9MFW4/IbNrlcDSui7Kq9Y3/yq SwJhVANVZO7LUV1IVm9sfMWsaJYEFsmog1e5uJkWCStpPVB7nKpv2NJSJBZyUMBSHtO1 f9MJkzWx/oRAvoYwGMZWuahsNqsE+Yq8/2wDWegpEdWJRzayy6MecBMRxcD1vCeZubNp oQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33skhp0bf1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:02:51 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08PG24X6139218; Fri, 25 Sep 2020 12:02:51 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 33skhp0bd4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:02:51 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08PG2jXK024957; Fri, 25 Sep 2020 16:02:49 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 33s5a98cms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 16:02:49 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08PG2kHc30474522 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Sep 2020 16:02:46 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80EEFA405B; Fri, 25 Sep 2020 16:02:46 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1730FA4054; Fri, 25 Sep 2020 16:02:46 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.49.151]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 Sep 2020 16:02:46 +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 Subject: [PATCH v1 1/4] memory: allocation in low memory Date: Fri, 25 Sep 2020 18:02:41 +0200 Message-Id: <1601049764-11784-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601049764-11784-1-git-send-email-pmorel@linux.ibm.com> References: <1601049764-11784-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.235,18.0.687 definitions=2020-09-25_14:2020-09-24,2020-09-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 spamscore=0 bulkscore=0 phishscore=0 lowpriorityscore=0 mlxscore=0 malwarescore=0 suspectscore=1 adultscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009250109 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Some architectures need allocations to be done under a specific address limit to allow DMA from I/O. We propose here a very simple page allocator to get pages allocated under this specific limit. The DMA page allocator will only use part of the available memory under the DMA address limit to let room for the standard allocator. Signed-off-by: Pierre Morel --- lib/alloc_dma_page.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ lib/alloc_dma_page.h | 24 +++++++++++++++++++ lib/s390x/sclp.c | 2 ++ s390x/Makefile | 1 + 4 files changed, 84 insertions(+) create mode 100644 lib/alloc_dma_page.c create mode 100644 lib/alloc_dma_page.h diff --git a/lib/alloc_dma_page.c b/lib/alloc_dma_page.c new file mode 100644 index 0000000..6a16e38 --- /dev/null +++ b/lib/alloc_dma_page.c @@ -0,0 +1,57 @@ +/* + * Page allocator for DMA + * + * Copyright (c) IBM, Corp. 2020 + * + * Authors: + * Pierre Morel + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ +#include +#include +#include + +static struct spinlock lock; +static void *dma_freelist = 0; + +void put_dma_page(void *dma_page) +{ + spin_lock(&lock); + *(void **)dma_page = dma_freelist; + dma_freelist = dma_page; + spin_unlock(&lock); +} + +void *get_dma_page(void) +{ + void *p = NULL; + + spin_lock(&lock); + if (!dma_freelist) + goto end_unlock; + + p = dma_freelist; + dma_freelist = *(void **)dma_freelist; + +end_unlock: + spin_unlock(&lock); + return p; +} + +phys_addr_t dma_page_alloc_init(phys_addr_t start, phys_addr_t end) +{ + int start_pfn = start >> PAGE_SHIFT; + int nb_pfn = ((end - start) >> PAGE_SHIFT) - 1; + int max, pfn; + + max = start_pfn + nb_pfn / DMA_ALLOC_RATIO; + if (max > DMA_MAX_PFN) + max = DMA_MAX_PFN; + + for (pfn = start_pfn; pfn < max; pfn++) + put_dma_page((void *)((unsigned long) pfn << PAGE_SHIFT)); + + return (phys_addr_t)pfn << PAGE_SHIFT; +} diff --git a/lib/alloc_dma_page.h b/lib/alloc_dma_page.h new file mode 100644 index 0000000..85e1d2f --- /dev/null +++ b/lib/alloc_dma_page.h @@ -0,0 +1,24 @@ +/* + * Page allocator for DMA definitions + * + * Copyright (c) IBM, Corp. 2020 + * + * Authors: + * Pierre Morel + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ +#ifndef _ALLOC_DMA_PAGE_H_ +#define _ALLOC_DMA_PAGE_H_ + +#include + +void put_dma_page(void *dma_page); +void *get_dma_page(void); +phys_addr_t dma_page_alloc_init(phys_addr_t start_pfn, phys_addr_t nb_pages); + +#define DMA_MAX_PFN (0x80000000 >> PAGE_SHIFT) +#define DMA_ALLOC_RATIO 8 + +#endif /* _ALLOC_DMA_PAGE_H_ */ diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index 4054d0e..9c95ca5 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -19,6 +19,7 @@ #include "sclp.h" #include #include +#include extern unsigned long stacktop; @@ -35,6 +36,7 @@ static void mem_init(phys_addr_t mem_end) phys_addr_t freemem_start = (phys_addr_t)&stacktop; phys_addr_t base, top; + freemem_start = dma_page_alloc_init(freemem_start, mem_end); phys_alloc_init(freemem_start, mem_end - freemem_start); phys_alloc_get_unused(&base, &top); base = (base + PAGE_SIZE - 1) & -PAGE_SIZE; diff --git a/s390x/Makefile b/s390x/Makefile index 9144d57..109ef9f 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -52,6 +52,7 @@ cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc_page.o cflatobjs += lib/vmalloc.o cflatobjs += lib/alloc_phys.o +cflatobjs += lib/alloc_dma_page.o cflatobjs += lib/s390x/io.o cflatobjs += lib/s390x/stack.o cflatobjs += lib/s390x/sclp.o From patchwork Fri Sep 25 16:02:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 11800203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 875526CB for ; Fri, 25 Sep 2020 16:03:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69E8B2311D for ; Fri, 25 Sep 2020 16:03:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="hrVDpFDi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728524AbgIYQDP (ORCPT ); Fri, 25 Sep 2020 12:03:15 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:23160 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728148AbgIYQDO (ORCPT ); Fri, 25 Sep 2020 12:03:14 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08PG2xfP061999; Fri, 25 Sep 2020 12:03:14 -0400 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=ZRVzO9kDmoyT7pGzE7Gyiex38XywGmdAlXT+v+oP+Ig=; b=hrVDpFDi8/0ydierxrd8J/ymK25Yv6uCK5v3yQqicHxNqebMklb0QCmMmsov/TIkvpLQ vUNFW8iS7tbFLdESzk+HHddfukHEdLawHNYIoa+rIOdG2H8yp6+Gc/weLlpW+wXLj9+G cCBdbk+r7W3YxtHEbipGmWEFxLIR6ax7rUpAkg576XqFeU0wPTcEzyYX3WD31u72p2F1 k8XCWJz+dCPQryW5QM3TVmbQU6sqRB5ozYXGAUtZUDNtleoWSc2pUGqoswktfANQ7Uab u76m1mXsFU6hUwIZc4E/86zeSHCFiztoZBU6YdTq1rr06TYGBK+SKcA0GKUk1GCiHy26 Ew== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33sjn6a6qu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:03:13 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08PG3CsO063113; Fri, 25 Sep 2020 12:03:12 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 33sjn6a69p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:03:12 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08PG1qCT006904; Fri, 25 Sep 2020 16:02:50 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04fra.de.ibm.com with ESMTP id 33n9m7ubrj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 16:02:49 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08PG2lhj33882460 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Sep 2020 16:02:47 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0A03EA405B; Fri, 25 Sep 2020 16:02:47 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9381CA405C; Fri, 25 Sep 2020 16:02:46 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.49.151]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 Sep 2020 16:02:46 +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 Subject: [PATCH v1 2/4] s390x: pv: implement routine to share/unshare memory Date: Fri, 25 Sep 2020 18:02:42 +0200 Message-Id: <1601049764-11784-3-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601049764-11784-1-git-send-email-pmorel@linux.ibm.com> References: <1601049764-11784-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.235,18.0.687 definitions=2020-09-25_14:2020-09-24,2020-09-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 clxscore=1015 malwarescore=0 impostorscore=0 mlxscore=0 suspectscore=1 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009250111 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 --- lib/s390x/asm/uv.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 4c2fc48..19019e4 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -71,4 +71,37 @@ 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 + }; + + uv_call(0, (u64)&uvcb); + return uvcb.header.rc; +} + +/* + * 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 Fri Sep 25 16:02:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 11800359 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1084D618 for ; Fri, 25 Sep 2020 16:39:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C17872344C for ; Fri, 25 Sep 2020 16:39:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="Tqsju7Tz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729478AbgIYQjC (ORCPT ); Fri, 25 Sep 2020 12:39:02 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:43550 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729125AbgIYQjB (ORCPT ); Fri, 25 Sep 2020 12:39:01 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08PGXKGG182834; Fri, 25 Sep 2020 12:39:01 -0400 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=ZsaqBb9u3bxkMNLlzPiyzpHkhV5HbI2l5uX6gwUHYGU=; b=Tqsju7TzwChW8FXHZRTcLDLLMOY3rE3Quc4kCp5r4cSC4juIsVi/WeUu8yBmbXAs4JWT RLisgU285Cwe3re7xwua52O+hwGhp9mKgx++O0d74B7oP+2FtOwtWXqlNUQ5h/WsIkyy RdxF5+X6NPrBJ9wgsQjcH0zU3inGwNF0G5Rmr4dZUnq9h+aL0dwwst4x9TPXxbI2P/0Q m5pGex8tTuYdwFSuJ7NqyxcTox+EjSfLsGmyESlru+O/4NxK/izTh+uhzO/HVLCaOZLf azzw+ZxCo54qBZjExL9mT1vNndUKK2zvxqU3AhqIDrSfulqMXDSHgGOMRyFFhxNDSi6V +A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33skujrnkh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:39:01 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08PGXWDZ183487; Fri, 25 Sep 2020 12:39:01 -0400 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 33skujrngp-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:39:00 -0400 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 08PG2lmQ022991; Fri, 25 Sep 2020 16:02:50 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 33payud76n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 16:02:50 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08PG2l5d27328790 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Sep 2020 16:02:47 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 924E8A405B; Fri, 25 Sep 2020 16:02:47 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1D2FFA405C; Fri, 25 Sep 2020 16:02:47 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.49.151]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 Sep 2020 16:02:47 +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 Subject: [PATCH v1 3/4] s390: define UV compatible I/O allocation Date: Fri, 25 Sep 2020 18:02:43 +0200 Message-Id: <1601049764-11784-4-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601049764-11784-1-git-send-email-pmorel@linux.ibm.com> References: <1601049764-11784-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.235,18.0.687 definitions=2020-09-25_14:2020-09-24,2020-09-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 suspectscore=3 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009250113 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To centralize the memory allocation for I/O we define the alloc/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..b84a06a --- /dev/null +++ b/lib/s390x/malloc_io.c @@ -0,0 +1,50 @@ +/* + * I/O page allocation + * + * Copyright (c) 2020 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 + +void *alloc_io_page(int size) +{ + void *p; + + assert(size <= PAGE_SIZE); + p = get_dma_page(); + if (!p) { + report(0, "Memory allocation"); + return NULL; + } + + if (!test_facility(158)) + return p; + + if (!uv_set_shared((unsigned long)p)) { + report(0, "Sharing memory"); + return NULL; + } + + return p; +} + +void free_io_page(void *p) +{ + if (test_facility(158) && !uv_remove_shared((unsigned long)p)) + report(0, "Unsharing memory"); + put_dma_page(p); +} diff --git a/lib/s390x/malloc_io.h b/lib/s390x/malloc_io.h new file mode 100644 index 0000000..c6ed481 --- /dev/null +++ b/lib/s390x/malloc_io.h @@ -0,0 +1,18 @@ +/* + * I/O allocations + * + * Copyright (c) 2020 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 109ef9f..1b1dc9f 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 Fri Sep 25 16:02:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 11800253 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D015A112C for ; Fri, 25 Sep 2020 16:14:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AC7E823718 for ; Fri, 25 Sep 2020 16:14:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="d03JTlto" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728731AbgIYQO1 (ORCPT ); Fri, 25 Sep 2020 12:14:27 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:11958 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728365AbgIYQO0 (ORCPT ); Fri, 25 Sep 2020 12:14:26 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08PGEBTS064961; Fri, 25 Sep 2020 12:14:25 -0400 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=tZWG+2p/xlDOByL5lYGeOEc7ZMoYpuu8PiqCDJ6CaFM=; b=d03JTltoDn6YAY4sDSgm/Y1UlmGTlcSg2Kq5jhzRDWIkkZC95tCNQ0UyQA8Y7+1qq8SA k7Vr+0Cxk+JmmvNu3sGNHfByvyJ93Nd0IuJOgX9weePX32VPMOVzSwPSM9+9ja4eXbvK wrUx/GnTrli00ZJ0Ss8x+iojTG7qZxRQIXVEKBL+UUgUYVJJLHlfQPJyXAE6MkhnvNCd vS5UIFKS8UoikYgzdEjhyt4rHI+Iv04i/Xr0y0Bemsk7DoEQTf3hDf40IPZlodNxd5YS YUbUazI/oBtWQEVzFB73vwoo7V+Qdz9NBi5AXf7GdQLLScfQCkR6HY4GthV9JdbQfjGQ zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33skw10021-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:14:24 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08PFWZ2g143948; Fri, 25 Sep 2020 12:03:28 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 33sj762nwe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 12:03:27 -0400 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 08PFdCFF024477; Fri, 25 Sep 2020 16:02:51 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 33n9m8ef2b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 25 Sep 2020 16:02:50 +0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08PG2m3e34275698 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 25 Sep 2020 16:02:48 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 25A62A405F; Fri, 25 Sep 2020 16:02:48 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A5646A405C; Fri, 25 Sep 2020 16:02:47 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.49.151]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 25 Sep 2020 16:02:47 +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 Subject: [PATCH v1 4/4] s390x: css: pv: css test adaptation for PV Date: Fri, 25 Sep 2020 18:02:44 +0200 Message-Id: <1601049764-11784-5-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1601049764-11784-1-git-send-email-pmorel@linux.ibm.com> References: <1601049764-11784-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.235,18.0.687 definitions=2020-09-25_14:2020-09-24,2020-09-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 impostorscore=0 spamscore=0 suspectscore=3 clxscore=1015 priorityscore=1501 phishscore=0 bulkscore=0 malwarescore=0 adultscore=0 mlxlogscore=698 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009250109 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); }