From patchwork Fri Nov 9 02:39:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675249 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 85FBE17D4 for ; Fri, 9 Nov 2018 02:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75AAC2EB5C for ; Fri, 9 Nov 2018 02:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 699102EB71; Fri, 9 Nov 2018 02:40:13 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E11902EB52 for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727830AbeKIMSm (ORCPT ); Fri, 9 Nov 2018 07:18:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51220 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727544AbeKIMSm (ORCPT ); Fri, 9 Nov 2018 07:18:42 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XWas053463 for ; Thu, 8 Nov 2018 21:40:10 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2nmwmd8aem-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:10 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:08 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 9 Nov 2018 02:40:05 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3qG9371918 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 868DA52052; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 700FD5204E; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id F321820F64C; Fri, 9 Nov 2018 03:40:02 +0100 (CET) From: Eric Farman To: Cornelia Huck , Pierre Morel Cc: Eric Farman , linux-s390@vger.kernel.org, kvm@vger.kernel.org, Halil Pasic , Farhan Ali , "Jason J . Herne" Subject: [RFC PATCH v1 06/10] s390/cio: Combine ccwchain_fetch _idal and _direct Date: Fri, 9 Nov 2018 03:39:33 +0100 X-Mailer: git-send-email 2.16.4 In-Reply-To: <20181109023937.96105-1-farman@linux.ibm.com> References: <20181109023937.96105-1-farman@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18110902-0016-0000-0000-000002241CDD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0017-0000-0000-0000327C1DF3 Message-Id: <20181109023937.96105-7-farman@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-11-08_13:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=899 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1811090022 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's so much overlap between these functions, and the only difference is whether or not the input CCW is a direct-address or an Indirect Data Address (IDA) List or not. Since the output is an IDAL for both, let's combine the two routines. We rename the resulting function ccwchain_fetch_ccw to express its combined purpose. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 98 ++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 65 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 3957c46bdaea..efc30152a89a 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -450,14 +450,16 @@ static int ccwchain_fetch_tic(struct ccwchain *chain, return -EFAULT; } -static int ccwchain_fetch_direct(struct ccwchain *chain, - int idx, - struct channel_program *cp) +static int ccwchain_fetch_ccw(struct ccwchain *chain, + int idx, + struct channel_program *cp) { struct ccw1 *ccw; struct pfn_array_table *pat; unsigned long *idaws; - int ret; + u64 idaw_iova; + unsigned int idaw_nr, idaw_len; + int i, ret; ccw = chain->ch_ccw + idx; @@ -471,60 +473,17 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, return 0; } - /* - * Pin data page(s) in memory. - * The number of pages actually is the count of the idaws which will be - * needed when translating a direct ccw to a idal ccw. - */ - pat = chain->ch_pat + idx; - ret = pfn_array_table_init(pat, 1); - if (ret) - goto out_init; - - ret = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, ccw->cda, ccw->count); - if (ret < 0) - goto out_unpin; - - /* Translate this direct ccw to a idal ccw. */ - idaws = kcalloc(ret, sizeof(*idaws), GFP_DMA | GFP_KERNEL); - if (!idaws) { - ret = -ENOMEM; - goto out_unpin; + if (ccw_is_idal(ccw)) { + /* Read first IDAW to see if it's 4K-aligned or not. */ + /* All subsequent IDAws will be 4K-aligned. */ + ret = copy_from_iova(cp->mdev, &idaw_iova, ccw->cda, + sizeof(idaw_iova)); + if (ret) + return ret; + } else { + idaw_iova = ccw->cda; } - ccw->cda = (__u32) virt_to_phys(idaws); - ccw->flags |= CCW_FLAG_IDA; - - pfn_array_table_idal_create_words(pat, idaws); - return 0; - -out_unpin: - pfn_array_table_unpin_free(pat, cp->mdev); -out_init: - ccw->cda = 0; - return ret; -} - -static int ccwchain_fetch_idal(struct ccwchain *chain, - int idx, - struct channel_program *cp) -{ - struct ccw1 *ccw; - struct pfn_array_table *pat; - unsigned long *idaws; - u64 idaw_iova; - unsigned int idaw_nr, idaw_len; - int i, ret; - - ccw = chain->ch_ccw + idx; - - if (!ccw->count) - return 0; - - /* Calculate size of idaws. */ - ret = copy_from_iova(cp->mdev, &idaw_iova, ccw->cda, sizeof(idaw_iova)); - if (ret) - return ret; idaw_nr = idal_nr_words((void *)(idaw_iova), ccw->count); idaw_len = idaw_nr * sizeof(*idaws); @@ -534,18 +493,27 @@ static int ccwchain_fetch_idal(struct ccwchain *chain, if (ret) goto out_init; - /* Translate idal ccw to use new allocated idaws. */ idaws = kzalloc(idaw_len, GFP_DMA | GFP_KERNEL); if (!idaws) { ret = -ENOMEM; goto out_unpin; } - ret = copy_from_iova(cp->mdev, idaws, ccw->cda, idaw_len); - if (ret) - goto out_free_idaws; + if (ccw_is_idal(ccw)) { + /* Copy the IDAL to our storage */ + ret = copy_from_iova(cp->mdev, idaws, ccw->cda, idaw_len); + if (ret) + goto out_free_idaws; + } else { + /* Build an IDAL based off the cda and subsequent pages */ + idal_create_words(idaws, (void *)(u64)ccw->cda, ccw->count); + } - ccw->cda = virt_to_phys(idaws); + /* + * We now have an IDAL of guest addresses, either because the CCW we + * are processing provided an IDA, or we built one from the CDA. + * Build the pfn structure so we can pin the associated pages. + */ for (i = 0; i < idaw_nr; i++) { idaw_iova = *(idaws + i); @@ -556,6 +524,9 @@ static int ccwchain_fetch_idal(struct ccwchain *chain, goto out_free_idaws; } + ccw->cda = virt_to_phys(idaws); + ccw->flags |= CCW_FLAG_IDA; + pfn_array_table_idal_create_words(pat, idaws); return 0; @@ -587,10 +558,7 @@ static int ccwchain_fetch_one(struct ccwchain *chain, if (ccw_is_tic(ccw)) return ccwchain_fetch_tic(chain, idx, cp); - if (ccw_is_idal(ccw)) - return ccwchain_fetch_idal(chain, idx, cp); - - return ccwchain_fetch_direct(chain, idx, cp); + return ccwchain_fetch_ccw(chain, idx, cp); } int process_channel_program(struct channel_program *cp, u32 iova)