From patchwork Fri Nov 9 02:39:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675247 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 C1EDD17D4 for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2BE92EB52 for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A665B2EB71; Fri, 9 Nov 2018 02:40:12 +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 4DEBB2EB52 for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727802AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41612 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727544AbeKIMSk (ORCPT ); Fri, 9 Nov 2018 07:18:40 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XVSn002222 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmv9ekqsa-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) 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:04 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3eK65863714 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4606811C054; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 333FD11C05C; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id E8BF620F647; 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 01/10] s390/cio: Fix cleanup of pfn_array alloc failure Date: Fri, 9 Nov 2018 03:39:28 +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-0012-0000-0000-000002C78161 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0013-0000-0000-000020FBD2FE Message-Id: <20181109023937.96105-2-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=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=740 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 If pfn_array_alloc fails somehow, we need to release the pfn_array_table that was malloc'd earlier. Signed-off-by: Eric Farman Acked-by: Halil Pasic --- drivers/s390/cio/vfio_ccw_cp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index fd77e46eb3b2..ef5ab45d94b3 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -528,7 +528,7 @@ static int ccwchain_fetch_direct(struct ccwchain *chain, ret = pfn_array_alloc_pin(pat->pat_pa, cp->mdev, ccw->cda, ccw->count); if (ret < 0) - goto out_init; + goto out_unpin; /* Translate this direct ccw to a idal ccw. */ idaws = kcalloc(ret, sizeof(*idaws), GFP_DMA | GFP_KERNEL); From patchwork Fri Nov 9 02:39:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675265 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 B5D7617D4 for ; Fri, 9 Nov 2018 02:40:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A77BF2EB52 for ; Fri, 9 Nov 2018 02:40:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BD0C2EB71; Fri, 9 Nov 2018 02:40:23 +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 3C96E2EB52 for ; Fri, 9 Nov 2018 02:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727748AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35346 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727349AbeKIMSk (ORCPT ); Fri, 9 Nov 2018 07:18:40 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XWMW107197 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmwp00c4n-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:08 -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:06 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) 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:04 -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 wA92e3Kf44302590 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 410A8A405C; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2FEE1A405B; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id EAD9920F648; 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 02/10] s390/cio: Fix cleanup when unsupported IDA format is used Date: Fri, 9 Nov 2018 03:39:29 +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-000002241CDC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0017-0000-0000-0000327C1DF2 Message-Id: <20181109023937.96105-3-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=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=916 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 Direct returns from within a loop are rude, but it doesn't mean it gets to avoid releasing the memory acquired beforehand. Signed-off-by: Eric Farman Reviewed-by: Farhan Ali Reviewed-by: Pierre Morel Acked-by: Halil Pasic --- drivers/s390/cio/vfio_ccw_cp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index ef5ab45d94b3..70a006ba4d05 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -387,8 +387,10 @@ static int ccwchain_calc_length(u64 iova, struct channel_program *cp) * orb specified one of the unsupported formats, we defer * checking for IDAWs in unsupported formats to here. */ - if ((!cp->orb.cmd.c64 || cp->orb.cmd.i2k) && ccw_is_idal(ccw)) + if ((!cp->orb.cmd.c64 || cp->orb.cmd.i2k) && ccw_is_idal(ccw)) { + kfree(p); return -EOPNOTSUPP; + } if ((!ccw_is_chain(ccw)) && (!ccw_is_tic(ccw))) break; From patchwork Fri Nov 9 02:39:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675261 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 1BD6015A6 for ; Fri, 9 Nov 2018 02:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D7372EB52 for ; Fri, 9 Nov 2018 02:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01A202EB71; Fri, 9 Nov 2018 02:40:21 +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 9DC0B2EB52 for ; Fri, 9 Nov 2018 02:40:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727954AbeKIMSu (ORCPT ); Fri, 9 Nov 2018 07:18:50 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53240 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727375AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92Xdib085720 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp01.uk.ibm.com (e06smtp01.uk.ibm.com [195.75.94.97]) by mx0b-001b2d01.pphosted.com with ESMTP id 2nmympm00f-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp01.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp01.uk.ibm.com (192.168.101.131) 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:04 -0000 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3Nu58917118 (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 3D14A52050; 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 2B59F52051; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id ECEF320F649; 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 03/10] s390/cio: Squash cp_free and cp_unpin_free Date: Fri, 9 Nov 2018 03:39:30 +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-4275-0000-0000-000002DE1CCC X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-4276-0000-0000-000037EB1D9D Message-Id: <20181109023937.96105-4-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=952 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 The routine cp_free() does nothing but call cp_unpin_free(), and while most places call cp_free() there is one caller of cp_unpin_free(). Let's avoid the confusion, and make cp_free() do all the work. Signed-off-by: Eric Farman Reviewed-by: Farhan Ali Reviewed-by: Pierre Morel --- drivers/s390/cio/vfio_ccw_cp.c | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 70a006ba4d05..a5a701451ef8 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -329,22 +329,6 @@ static void ccwchain_cda_free(struct ccwchain *chain, int idx) kfree((void *)(u64)ccw->cda); } -/* Unpin the pages then free the memory resources. */ -static void cp_unpin_free(struct channel_program *cp) -{ - struct ccwchain *chain, *temp; - int i; - - list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { - for (i = 0; i < chain->ch_len; i++) { - pfn_array_table_unpin_free(chain->ch_pat + i, - cp->mdev); - ccwchain_cda_free(chain, i); - } - ccwchain_free(chain); - } -} - /** * ccwchain_calc_length - calculate the length of the ccw chain. * @iova: guest physical address of the target ccw chain @@ -695,7 +679,7 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) /* Now loop for its TICs. */ ret = ccwchain_loop_tic(chain, cp); if (ret) - cp_unpin_free(cp); + cp_free(cp); /* It is safe to force: if not set but idals used * ccwchain_calc_length returns an error. */ @@ -715,7 +699,17 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) */ void cp_free(struct channel_program *cp) { - cp_unpin_free(cp); + struct ccwchain *chain, *temp; + int i; + + list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { + for (i = 0; i < chain->ch_len; i++) { + pfn_array_table_unpin_free(chain->ch_pat + i, + cp->mdev); + ccwchain_cda_free(chain, i); + } + ccwchain_free(chain); + } } /** From patchwork Fri Nov 9 02:39:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675253 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 D826B15A6 for ; Fri, 9 Nov 2018 02:40:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8F852EB52 for ; Fri, 9 Nov 2018 02:40:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD1232EB71; Fri, 9 Nov 2018 02:40:15 +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 41B552EB52 for ; Fri, 9 Nov 2018 02:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727662AbeKIMSp (ORCPT ); Fri, 9 Nov 2018 07:18:45 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41640 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727656AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XWbb002299 for ; Thu, 8 Nov 2018 21:40:10 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmv9ekqsf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp03.uk.ibm.com (192.168.101.133) 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:04 -0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3BY32505892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DA1711C05E; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 395F711C052; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id EF08A20F64A; 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 04/10] s390/cio: Breakout the processing of a channel program Date: Fri, 9 Nov 2018 03:39:31 +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-0012-0000-0000-000002C7815F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0013-0000-0000-000020FBD300 Message-Id: <20181109023937.96105-5-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=999 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 Handle the things that are specific to one or more CCWs outside of the mainline of the cp_init function. Signed-off-by: Eric Farman Reviewed-by: Farhan Ali --- drivers/s390/cio/vfio_ccw_cp.c | 58 +++++++++++++++++++++++++----------------- drivers/s390/cio/vfio_ccw_cp.h | 1 + 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index a5a701451ef8..383f810ef389 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -624,6 +624,37 @@ static int ccwchain_fetch_one(struct ccwchain *chain, return ccwchain_fetch_direct(chain, idx, cp); } +int process_channel_program(struct channel_program *cp, u32 iova) +{ + struct ccwchain *chain; + int len, ret; + + /* Get chain length. */ + len = ccwchain_calc_length(iova, cp); + if (len < 0) + return len; + + /* Alloc mem for the head chain. */ + chain = ccwchain_alloc(cp, len); + if (!chain) + return -ENOMEM; + chain->ch_iova = iova; + + /* Copy the head chain from guest. */ + ret = copy_ccw_from_iova(cp, chain->ch_ccw, iova, len); + if (ret) { + ccwchain_free(chain); + return ret; + } + + /* Now loop for its TICs. */ + ret = ccwchain_loop_tic(chain, cp); + if (ret) + cp_free(cp); + + return ret; +} + /** * cp_init() - allocate ccwchains for a channel program. * @cp: channel_program on which to perform the operation @@ -643,9 +674,8 @@ static int ccwchain_fetch_one(struct ccwchain *chain, */ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) { - u64 iova = orb->cmd.cpa; - struct ccwchain *chain; - int len, ret; + u32 cpa = orb->cmd.cpa; + int ret; /* * XXX: @@ -658,28 +688,10 @@ int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb) memcpy(&cp->orb, orb, sizeof(*orb)); cp->mdev = mdev; - /* Get chain length. */ - len = ccwchain_calc_length(iova, cp); - if (len < 0) - return len; - - /* Alloc mem for the head chain. */ - chain = ccwchain_alloc(cp, len); - if (!chain) - return -ENOMEM; - chain->ch_iova = iova; - - /* Copy the head chain from guest. */ - ret = copy_ccw_from_iova(cp, chain->ch_ccw, iova, len); - if (ret) { - ccwchain_free(chain); + ret = process_channel_program(cp, cpa); + if (ret) return ret; - } - /* Now loop for its TICs. */ - ret = ccwchain_loop_tic(chain, cp); - if (ret) - cp_free(cp); /* It is safe to force: if not set but idals used * ccwchain_calc_length returns an error. */ diff --git a/drivers/s390/cio/vfio_ccw_cp.h b/drivers/s390/cio/vfio_ccw_cp.h index a4b74fb1aa57..d2e47a12f944 100644 --- a/drivers/s390/cio/vfio_ccw_cp.h +++ b/drivers/s390/cio/vfio_ccw_cp.h @@ -32,6 +32,7 @@ struct channel_program { struct device *mdev; }; +int process_channel_program(struct channel_program *cp, u32 cpa); extern int cp_init(struct channel_program *cp, struct device *mdev, union orb *orb); extern void cp_free(struct channel_program *cp); From patchwork Fri Nov 9 02:39:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675259 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 B06811923 for ; Fri, 9 Nov 2018 02:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A1A492EB52 for ; Fri, 9 Nov 2018 02:40:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95FF82EB71; Fri, 9 Nov 2018 02:40:19 +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 84B2F2EB5C for ; Fri, 9 Nov 2018 02:40:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727885AbeKIMSs (ORCPT ); Fri, 9 Nov 2018 07:18:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57796 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727655AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XW2n039717 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmymnv2qy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp03.uk.ibm.com (192.168.101.133) 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 d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3Yf60620932 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8A0FB42047; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 770B742041; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id F113920F64B; 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 05/10] s390/cio: Use common channel program processor for TIC Date: Fri, 9 Nov 2018 03:39:32 +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-0012-0000-0000-000002C78163 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0013-0000-0000-000020FBD303 Message-Id: <20181109023937.96105-6-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=916 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 Now that a channel program is examined by a separate routine, we can replace much of the TIC code with a call to that function. Signed-off-by: Eric Farman Reviewed-by: Farhan Ali Reviewed-by: Farhan Ali --- drivers/s390/cio/vfio_ccw_cp.c | 39 ++++----------------------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 383f810ef389..3957c46bdaea 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -405,40 +405,6 @@ static int tic_target_chain_exists(struct ccw1 *tic, struct channel_program *cp) return 0; } -static int ccwchain_loop_tic(struct ccwchain *chain, - struct channel_program *cp); - -static int ccwchain_handle_tic(struct ccw1 *tic, struct channel_program *cp) -{ - struct ccwchain *chain; - int len, ret; - - /* May transfer to an existing chain. */ - if (tic_target_chain_exists(tic, cp)) - return 0; - - /* Get chain length. */ - len = ccwchain_calc_length(tic->cda, cp); - if (len < 0) - return len; - - /* Need alloc a new chain for this one. */ - chain = ccwchain_alloc(cp, len); - if (!chain) - return -ENOMEM; - chain->ch_iova = tic->cda; - - /* Copy the new chain from user. */ - ret = copy_ccw_from_iova(cp, chain->ch_ccw, tic->cda, len); - if (ret) { - ccwchain_free(chain); - return ret; - } - - /* Loop for tics on this new chain. */ - return ccwchain_loop_tic(chain, cp); -} - /* Loop for TICs. */ static int ccwchain_loop_tic(struct ccwchain *chain, struct channel_program *cp) { @@ -451,7 +417,10 @@ static int ccwchain_loop_tic(struct ccwchain *chain, struct channel_program *cp) if (!ccw_is_tic(tic)) continue; - ret = ccwchain_handle_tic(tic, cp); + if (tic_target_chain_exists(tic, cp)) + continue; + + ret = process_channel_program(cp, tic->cda); if (ret) return ret; } 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) From patchwork Fri Nov 9 02:39:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675257 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 77DE917D4 for ; Fri, 9 Nov 2018 02:40:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 680062EB52 for ; Fri, 9 Nov 2018 02:40:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C33E2EB74; Fri, 9 Nov 2018 02:40:19 +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 9EF6A2EB52 for ; Fri, 9 Nov 2018 02:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727828AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34430 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727634AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XVj4127805 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmym9c4ka-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) 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 b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3iH62849128 (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 845F852051; 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 7279052050; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id 00FFB20F64E; 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 07/10] s390/cio: Tell pfn_array_alloc_pin to pin pages, not bytes Date: Fri, 9 Nov 2018 03:39:34 +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-0008-0000-0000-0000028F7601 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0009-0000-0000-000021F9BCC6 Message-Id: <20181109023937.96105-8-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=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 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 This simplifies the code a little bit, both now and for later patches. The inline function idal_nr_words() performs the same function that we were doing here, which is figure out how many pages a given contiguous piece of memory might span. (That is, len/4K if aligned on a 4K page, or len/4K + 1 if not.) So we'll use this routine as a matter of convenience, even though we're not building an IDAL. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index efc30152a89a..5f16aa88c629 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -54,7 +54,7 @@ struct ccwchain { * @pa: pfn_array on which to perform the operation * @mdev: the mediated device to perform pin/unpin operations * @iova: target guest physical address - * @len: number of bytes that should be pinned from @iova + * @len: number of pages that should be pinned from @iova * * Attempt to allocate memory for PFNs, and pin user pages in memory. * @@ -80,10 +80,7 @@ static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev, return -EINVAL; pa->pa_iova = iova; - - pa->pa_nr = ((iova & ~PAGE_MASK) + len + (PAGE_SIZE - 1)) >> PAGE_SHIFT; - if (!pa->pa_nr) - return -EINVAL; + pa->pa_nr = len; pa->pa_iova_pfn = kcalloc(pa->pa_nr, sizeof(*pa->pa_iova_pfn) + @@ -209,7 +206,8 @@ static long copy_from_iova(struct device *mdev, int i, ret; unsigned long l, m; - ret = pfn_array_alloc_pin(&pa, mdev, iova, n); + ret = pfn_array_alloc_pin(&pa, mdev, iova, + idal_nr_words((void *)(iova), n)); if (ret <= 0) return ret; From patchwork Fri Nov 9 02:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675263 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 DD85115A6 for ; Fri, 9 Nov 2018 02:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF85E2EB52 for ; Fri, 9 Nov 2018 02:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3E862EB71; Fri, 9 Nov 2018 02:40:22 +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 49BBF2EB52 for ; Fri, 9 Nov 2018 02:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727883AbeKIMSu (ORCPT ); Fri, 9 Nov 2018 07:18:50 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52002 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727445AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XUVL005551 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 2nmwmrrawy-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp03.uk.ibm.com (192.168.101.133) 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 d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e37B55050368 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 951FFA4057; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BFBCA4051; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id 0310E20F64F; Fri, 9 Nov 2018 03:40:03 +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 08/10] s390/cio: Split pfn_array_alloc_pin into pieces Date: Fri, 9 Nov 2018 03:39:35 +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-0012-0000-0000-000002C78162 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0013-0000-0000-000020FBD302 Message-Id: <20181109023937.96105-9-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=954 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 The pfn_array_alloc_pin routine is doing too much. Today, it does the alloc of the pfn_array struct and its member arrays, builds the iova address lists out of a contiguous piece of guest memory, and asks vfio to pin the resulting pages. While the input iova variable points to a contiguous piece of memory, the pfn_array, uh, array would permit a non-contiguous range of addresses such as those provided by an IDA List. By breaking pfn_array_alloc_pin into its component pieces, we will be in a good place to share this code regardless of what pfn_array contains. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 96 +++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 52 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index 5f16aa88c629..d01e146289fb 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -49,37 +49,32 @@ struct ccwchain { struct pfn_array_table *ch_pat; }; -/* - * pfn_array_alloc_pin() - alloc memory for PFNs, then pin user pages in memory - * @pa: pfn_array on which to perform the operation - * @mdev: the mediated device to perform pin/unpin operations - * @iova: target guest physical address - * @len: number of pages that should be pinned from @iova - * - * Attempt to allocate memory for PFNs, and pin user pages in memory. - * - * Usage of pfn_array: - * We expect (pa_nr == 0) and (pa_iova_pfn == NULL), any field in - * this structure will be filled in by this function. - * - * Returns: - * Number of pages pinned on success. - * If @pa->pa_nr is not 0, or @pa->pa_iova_pfn is not NULL initially, - * returns -EINVAL. - * If no pages were pinned, returns -errno. - */ -static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev, - u64 iova, unsigned int len) +static int pfn_array_pin(struct pfn_array *pa, struct device *mdev) { - int i, ret = 0; + int ret = 0; + + ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr, + IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); + + if (ret > 0 && ret != pa->pa_nr) { + vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret); + ret = -EINVAL; + } + if (ret < 0) + pa->pa_iova = 0; + + return ret; +} + +static int pfn_array_alloc(struct pfn_array *pa, unsigned int len) +{ if (!len) return 0; if (pa->pa_nr || pa->pa_iova_pfn) return -EINVAL; - pa->pa_iova = iova; pa->pa_nr = len; pa->pa_iova_pfn = kcalloc(pa->pa_nr, @@ -90,35 +85,14 @@ static int pfn_array_alloc_pin(struct pfn_array *pa, struct device *mdev, return -ENOMEM; pa->pa_pfn = pa->pa_iova_pfn + pa->pa_nr; - pa->pa_iova_pfn[0] = pa->pa_iova >> PAGE_SHIFT; - for (i = 1; i < pa->pa_nr; i++) - pa->pa_iova_pfn[i] = pa->pa_iova_pfn[i - 1] + 1; - - ret = vfio_pin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr, - IOMMU_READ | IOMMU_WRITE, pa->pa_pfn); - - if (ret < 0) { - goto err_out; - } else if (ret > 0 && ret != pa->pa_nr) { - vfio_unpin_pages(mdev, pa->pa_iova_pfn, ret); - ret = -EINVAL; - goto err_out; - } - - return ret; - -err_out: - pa->pa_nr = 0; - kfree(pa->pa_iova_pfn); - pa->pa_iova_pfn = NULL; - - return ret; + return 0; } /* Unpin the pages before releasing the memory. */ static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev) { - vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr); + if (pa->pa_iova) + vfio_unpin_pages(mdev, pa->pa_iova_pfn, pa->pa_nr); pa->pa_nr = 0; kfree(pa->pa_iova_pfn); } @@ -206,11 +180,21 @@ static long copy_from_iova(struct device *mdev, int i, ret; unsigned long l, m; - ret = pfn_array_alloc_pin(&pa, mdev, iova, - idal_nr_words((void *)(iova), n)); - if (ret <= 0) + ret = pfn_array_alloc(&pa, idal_nr_words((void *)(iova), n)); + if (ret < 0) return ret; + pa.pa_iova = iova; + pa.pa_iova_pfn[0] = pa.pa_iova >> PAGE_SHIFT; + for (i = 1; i < pa.pa_nr; i++) + pa.pa_iova_pfn[i] = pa.pa_iova_pfn[i - 1] + 1; + + ret = pfn_array_pin(&pa, mdev); + if (ret <= 0) { + pfn_array_unpin_free(&pa, mdev); + return ret; + } + l = n; for (i = 0; i < pa.pa_nr; i++) { from = pa.pa_pfn[i] << PAGE_SHIFT; @@ -454,6 +438,7 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, { struct ccw1 *ccw; struct pfn_array_table *pat; + struct pfn_array *pa; unsigned long *idaws; u64 idaw_iova; unsigned int idaw_nr, idaw_len; @@ -515,11 +500,18 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, for (i = 0; i < idaw_nr; i++) { idaw_iova = *(idaws + i); + pa = pat->pat_pa + i; - ret = pfn_array_alloc_pin(pat->pat_pa + i, cp->mdev, - idaw_iova, 1); + ret = pfn_array_alloc(pa, 1); if (ret < 0) goto out_free_idaws; + + pa->pa_iova = idaws[0]; + pa->pa_iova_pfn[0] = idaws[i] >> PAGE_SHIFT; + + ret = pfn_array_pin(pa, cp->mdev); + if (ret <= 0) + goto out_free_idaws; } ccw->cda = virt_to_phys(idaws); From patchwork Fri Nov 9 02:39:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675255 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 A297118FD for ; Fri, 9 Nov 2018 02:40:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93F062EB74 for ; Fri, 9 Nov 2018 02:40:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 887382EB83; Fri, 9 Nov 2018 02:40:18 +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 D50472EB74 for ; Fri, 9 Nov 2018 02:40:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727866AbeKIMSp (ORCPT ); Fri, 9 Nov 2018 07:18:45 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51338 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727536AbeKIMSl (ORCPT ); Fri, 9 Nov 2018 07:18:41 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XZ4X004935 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 2nmvgf31pf-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) 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 d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e3ms44892162 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 965B7A405D; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F656A4040; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id 051C220F650; Fri, 9 Nov 2018 03:40:03 +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 09/10] s390/cio: Eliminate the pfn_array_table struct Date: Fri, 9 Nov 2018 03:39:36 +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-0008-0000-0000-0000028F7602 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0009-0000-0000-000021F9BCC5 Message-Id: <20181109023937.96105-10-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=999 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 The pfn_array_table struct is created as an array that is the number of IDA Words, and each of those elements (a pfn_array struct) is itself an array just one element long (one per IDAW, I guess). This unnecessarily complicates a lot of this code, when the whole point of an IDAL is to point to an array of pages. Since we know we have an IDAL in this code path, we can replace this with just an array of pfn_array structs that is itself the number of IDAWs we want and need. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 49 +++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index d01e146289fb..d502dcd09d9a 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -46,7 +46,7 @@ struct ccwchain { /* Count of the valid ccws in chain. */ int ch_len; /* Pinned PAGEs for the original data. */ - struct pfn_array_table *ch_pat; + struct pfn_array *ch_pa; }; static int pfn_array_pin(struct pfn_array *pa, struct device *mdev) @@ -125,14 +125,12 @@ static void pfn_array_table_unpin_free(struct pfn_array_table *pat, } } -static bool pfn_array_table_iova_pinned(struct pfn_array_table *pat, +static bool pfn_array_table_iova_pinned(struct pfn_array *pa, unsigned long iova) { - struct pfn_array *pa = pat->pat_pa; unsigned long iova_pfn = iova >> PAGE_SHIFT; int i, j; - for (i = 0; i < pat->pat_nr; i++, pa++) for (j = 0; j < pa->pa_nr; j++) if (pa->pa_iova_pfn[j] == iova_pfn) return true; @@ -141,10 +139,9 @@ static bool pfn_array_table_iova_pinned(struct pfn_array_table *pat, } /* Create the list idal words for a pfn_array_table. */ static inline void pfn_array_table_idal_create_words( - struct pfn_array_table *pat, + struct pfn_array *pa, unsigned long *idaws) { - struct pfn_array *pa; int i, j, k; /* @@ -155,15 +152,12 @@ static inline void pfn_array_table_idal_create_words( * idaw. */ k = 0; - for (i = 0; i < pat->pat_nr; i++) { - pa = pat->pat_pa + i; for (j = 0; j < pa->pa_nr; j++) { idaws[k] = pa->pa_pfn[j] << PAGE_SHIFT; if (k == 0) idaws[k] += pa->pa_iova & (PAGE_SIZE - 1); k++; } - } } @@ -274,7 +268,7 @@ static struct ccwchain *ccwchain_alloc(struct channel_program *cp, int len) /* Make ccw address aligned to 8. */ size = ((sizeof(*chain) + 7L) & -8L) + sizeof(*chain->ch_ccw) * len + - sizeof(*chain->ch_pat) * len; + sizeof(*chain->ch_pa) * len; chain = kzalloc(size, GFP_DMA | GFP_KERNEL); if (!chain) return NULL; @@ -283,7 +277,7 @@ static struct ccwchain *ccwchain_alloc(struct channel_program *cp, int len) chain->ch_ccw = (struct ccw1 *)data; data = (u8 *)(chain->ch_ccw) + sizeof(*chain->ch_ccw) * len; - chain->ch_pat = (struct pfn_array_table *)data; + chain->ch_pa = (struct pfn_array *)data; chain->ch_len = len; @@ -471,8 +465,8 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, idaw_len = idaw_nr * sizeof(*idaws); /* Pin data page(s) in memory. */ - pat = chain->ch_pat + idx; - ret = pfn_array_table_init(pat, idaw_nr); + pa = chain->ch_pa + idx; + ret = pfn_array_alloc(pa, idaw_nr); if (ret) goto out_init; @@ -498,33 +492,25 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, * Build the pfn structure so we can pin the associated pages. */ - for (i = 0; i < idaw_nr; i++) { - idaw_iova = *(idaws + i); - pa = pat->pat_pa + i; - - ret = pfn_array_alloc(pa, 1); - if (ret < 0) - goto out_free_idaws; + pa->pa_iova = idaws[0]; + for (i = 0; i < idaw_nr; i++) + pa->pa_iova_pfn[i] = idaws[i] >> PAGE_SHIFT; - pa->pa_iova = idaws[0]; - pa->pa_iova_pfn[0] = idaws[i] >> PAGE_SHIFT; - - ret = pfn_array_pin(pa, cp->mdev); - if (ret <= 0) - goto out_free_idaws; - } + ret = pfn_array_pin(pa, cp->mdev); + if (ret <= 0) + goto out_free_idaws; ccw->cda = virt_to_phys(idaws); ccw->flags |= CCW_FLAG_IDA; - pfn_array_table_idal_create_words(pat, idaws); + pfn_array_table_idal_create_words(pa, idaws); return 0; out_free_idaws: kfree(idaws); out_unpin: - pfn_array_table_unpin_free(pat, cp->mdev); + pfn_array_unpin_free(pa, cp->mdev); out_init: ccw->cda = 0; return ret; @@ -643,8 +629,7 @@ void cp_free(struct channel_program *cp) list_for_each_entry_safe(chain, temp, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) { - pfn_array_table_unpin_free(chain->ch_pat + i, - cp->mdev); + pfn_array_unpin_free(chain->ch_pa + i, cp->mdev); ccwchain_cda_free(chain, i); } ccwchain_free(chain); @@ -804,7 +789,7 @@ bool cp_iova_pinned(struct channel_program *cp, u64 iova) list_for_each_entry(chain, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) - if (pfn_array_table_iova_pinned(chain->ch_pat + i, + if (pfn_array_table_iova_pinned(chain->ch_pa + i, iova)) return true; } From patchwork Fri Nov 9 02:39:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Farman X-Patchwork-Id: 10675245 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 2726518FD for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DEE32EB52 for ; Fri, 9 Nov 2018 02:40:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 015E52EB71; Fri, 9 Nov 2018 02:40:11 +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 762982EB52 for ; Fri, 9 Nov 2018 02:40:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727718AbeKIMSk (ORCPT ); Fri, 9 Nov 2018 07:18:40 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55722 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727553AbeKIMSk (ORCPT ); Fri, 9 Nov 2018 07:18:40 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wA92XVKU030124 for ; Thu, 8 Nov 2018 21:40:09 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nmyrwus8b-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 08 Nov 2018 21:40:09 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 9 Nov 2018 02:40:07 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp05.uk.ibm.com (192.168.101.135) 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 d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wA92e32S7143892 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 9 Nov 2018 02:40:03 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 996FE4C046; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 813FD4C040; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Fri, 9 Nov 2018 02:40:03 +0000 (GMT) Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 4958) id 072AF20F651; Fri, 9 Nov 2018 03:40:03 +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 10/10] s390/cio: Remove unused function/variables FIXUP Date: Fri, 9 Nov 2018 03:39:37 +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-0020-0000-0000-000002E3FBAF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18110902-0021-0000-0000-0000213382D9 Message-Id: <20181109023937.96105-11-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=999 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 This should be squashed into the previous commit. It removes things that that are no longer used, and thus causing compiler warnings, but is split out to help with the readability of the refactoring that happened in the previous commit. Signed-off-by: Eric Farman --- drivers/s390/cio/vfio_ccw_cp.c | 70 ++++++++++-------------------------------- 1 file changed, 16 insertions(+), 54 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c index d502dcd09d9a..ee3be5391edc 100644 --- a/drivers/s390/cio/vfio_ccw_cp.c +++ b/drivers/s390/cio/vfio_ccw_cp.c @@ -33,11 +33,6 @@ struct pfn_array { int pa_nr; }; -struct pfn_array_table { - struct pfn_array *pat_pa; - int pat_nr; -}; - struct ccwchain { struct list_head next; struct ccw1 *ch_ccw; @@ -97,52 +92,24 @@ static void pfn_array_unpin_free(struct pfn_array *pa, struct device *mdev) kfree(pa->pa_iova_pfn); } -static int pfn_array_table_init(struct pfn_array_table *pat, int nr) -{ - pat->pat_pa = kcalloc(nr, sizeof(*pat->pat_pa), GFP_KERNEL); - if (unlikely(ZERO_OR_NULL_PTR(pat->pat_pa))) { - pat->pat_nr = 0; - return -ENOMEM; - } - - pat->pat_nr = nr; - - return 0; -} - -static void pfn_array_table_unpin_free(struct pfn_array_table *pat, - struct device *mdev) -{ - int i; - - for (i = 0; i < pat->pat_nr; i++) - pfn_array_unpin_free(pat->pat_pa + i, mdev); - - if (pat->pat_nr) { - kfree(pat->pat_pa); - pat->pat_pa = NULL; - pat->pat_nr = 0; - } -} - -static bool pfn_array_table_iova_pinned(struct pfn_array *pa, - unsigned long iova) +static bool pfn_array_iova_pinned(struct pfn_array *pa, + unsigned long iova) { unsigned long iova_pfn = iova >> PAGE_SHIFT; - int i, j; + int i; - for (j = 0; j < pa->pa_nr; j++) - if (pa->pa_iova_pfn[j] == iova_pfn) - return true; + for (i = 0; i < pa->pa_nr; i++) + if (pa->pa_iova_pfn[i] == iova_pfn) + return true; return false; } -/* Create the list idal words for a pfn_array_table. */ -static inline void pfn_array_table_idal_create_words( + +static inline void pfn_array_idal_create_words( struct pfn_array *pa, unsigned long *idaws) { - int i, j, k; + int i; /* * Idal words (execept the first one) rely on the memory being 4k @@ -151,15 +118,12 @@ static inline void pfn_array_table_idal_create_words( * there will be no problem here to simply use the phys to create an * idaw. */ - k = 0; - for (j = 0; j < pa->pa_nr; j++) { - idaws[k] = pa->pa_pfn[j] << PAGE_SHIFT; - if (k == 0) - idaws[k] += pa->pa_iova & (PAGE_SIZE - 1); - k++; - } -} + for (i = 0; i < pa->pa_nr; i++) + idaws[i] = pa->pa_pfn[i] << PAGE_SHIFT; + + idaws[0] += pa->pa_iova & (PAGE_SIZE - 1); +} /* * Within the domain (@mdev), copy @n bytes from a guest physical @@ -431,7 +395,6 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, struct channel_program *cp) { struct ccw1 *ccw; - struct pfn_array_table *pat; struct pfn_array *pa; unsigned long *idaws; u64 idaw_iova; @@ -503,7 +466,7 @@ static int ccwchain_fetch_ccw(struct ccwchain *chain, ccw->cda = virt_to_phys(idaws); ccw->flags |= CCW_FLAG_IDA; - pfn_array_table_idal_create_words(pa, idaws); + pfn_array_idal_create_words(pa, idaws); return 0; @@ -789,8 +752,7 @@ bool cp_iova_pinned(struct channel_program *cp, u64 iova) list_for_each_entry(chain, &cp->ccwchain_list, next) { for (i = 0; i < chain->ch_len; i++) - if (pfn_array_table_iova_pinned(chain->ch_pa + i, - iova)) + if (pfn_array_iova_pinned(chain->ch_pa + i, iova)) return true; }