Received: by 10.192.165.148 with SMTP id m20csp3320965imm; Mon, 23 Apr 2018 04:42:18 -0700 (PDT) X-Google-Smtp-Source: AIpwx49LH8qfeDfyNqYjH4UM7PPZjc5Yr0adkh2OEVcJoqirOwjtceAZk5K4o7uBo/E8E/rUsT0p X-Received: by 10.99.62.201 with SMTP id l192mr16652006pga.318.1524483738532; Mon, 23 Apr 2018 04:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524483738; cv=none; d=google.com; s=arc-20160816; b=cGfQIJhPXeZQ4GK9S/oW6EPVGuy6b1wuUNWNYk5ZjYV/X5U3l299rFyAQSh4jrKmph SjN0jJgWEdyxCw8pHkD4mB5OP09CZn8grXsy31mYmZg0yJEwax8nt4JS3bq2Qq/FsHu7 6FRirxPjKdDKJZANk1bqbuCnKYJyyoTDCd/yeLexpmAM/k4xMQPlA6ptY6U50C9FERl7 utPmN76pZ9xMgdrk8PFYE/GTNWmj64d3kC3RRYd8+8lEKc8/oq7DiHf6CdA7BKWghjfb e1YKQhYHxNobzYFA0mdrzSvWUEk4GY35/30AFu8ep+vOiYRkAAbzc2evA/JIYgykTACi LdSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:arc-authentication-results; bh=SYeHXt7NSNoJPEstashvNi5GJiSPGVE7mWXB7jHOj+o=; b=lI+33rrtK0QYcaZtQ2/6IuD2LA2sd7L6pEnDt2UinT/XK66cPQWDWTFqXzPIcwJenw iOjtquGbMKc0FimyRkPIb7Zqspiq7BBHD4qz+ZHc51/KkfEQMqv94TQq+BtyDCMySRyI d5NjLkxIW5lafUt1RySDUAG4/cOZO5pFpRIslL5YTn0/l9tR46H7Bikrw7w6ALKyuTNX PgwsZThI7+rPYnVaRh0ifLPF8kGzr54otqXCgq7r3AWgCuwaSPcYa34NiqEAr/PywAwD C3d9PJf+6jtGsQ3xqKsV6PS7NIVpW6RJZXsqF+f/EYtqzbd5thfhyBys7TUNpuaEC+PV 5rtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m21si11395121pfj.25.2018.04.23.04.42.04; Mon, 23 Apr 2018 04:42:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754828AbeDWLlC (ORCPT + 99 others); Mon, 23 Apr 2018 07:41:02 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57962 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754710AbeDWLk7 (ORCPT ); Mon, 23 Apr 2018 07:40:59 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B174981A88A0; Mon, 23 Apr 2018 11:40:58 +0000 (UTC) Received: from gondolin (ovpn-116-250.ams2.redhat.com [10.36.116.250]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F2061208F76; Mon, 23 Apr 2018 11:40:56 +0000 (UTC) Date: Mon, 23 Apr 2018 13:40:54 +0200 From: Cornelia Huck To: Dong Jia Shi Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, borntraeger@de.ibm.com, bjsdjshi@linux.ibm.com, pasic@linux.ibm.com, pmorel@linux.ibm.com, Halil Pasic Subject: Re: [PATCH v2 1/5] vfio: ccw: fix cleanup if cp_prefetch fails Message-ID: <20180423134054.2f7692d1.cohuck@redhat.com> In-Reply-To: <20180423110113.59385-2-bjsdjshi@linux.vnet.ibm.com> References: <20180423110113.59385-1-bjsdjshi@linux.vnet.ibm.com> <20180423110113.59385-2-bjsdjshi@linux.vnet.ibm.com> Organization: Red Hat GmbH MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 11:40:58 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Mon, 23 Apr 2018 11:40:58 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'cohuck@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 23 Apr 2018 13:01:09 +0200 Dong Jia Shi wrote: > From: Halil Pasic > > If the translation of a channel program fails, we may end up attempting > to clean up (free, unpin) stuff that never got translated (and allocated, > pinned) in the first place. > > By adjusting the lengths of the chains accordingly (so the element that > failed, and all subsequent elements are excluded) cleanup activities > based on false assumptions can be avoided. > > Let's make sure cp_free works properly after cp_prefetch returns with an > error by setting ch_len of a ccw chain to the number of the translated > CCWs on that chain. Should that be cc:stable? This problem has been there probably since we introduced vfio-ccw, no? > > Acked-by: Pierre Morel > Reviewed-by: Dong Jia Shi > Signed-off-by: Halil Pasic > Signed-off-by: Dong Jia Shi > --- > drivers/s390/cio/vfio_ccw_cp.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c > index 2c7550797ec2..62d66e195304 100644 > --- a/drivers/s390/cio/vfio_ccw_cp.c > +++ b/drivers/s390/cio/vfio_ccw_cp.c > @@ -715,6 +715,10 @@ void cp_free(struct channel_program *cp) > * and stores the result to ccwchain list. @cp must have been > * initialized by a previous call with cp_init(). Otherwise, undefined > * behavior occurs. > + * For each chain composing the channel program: > + * - On entry ch_len holds the count of CCW to be translated. > + * - On exit ch_len is adjusted to the count of successfully translated CCW. > + * This allows cp_free to find in ch_len the count of CCW to free in a chain. s/CCW/CCWs/ (x3)? Can change on applying. > * > * The S/390 CCW Translation APIS (prefixed by 'cp_') are introduced > * as helpers to do ccw chain translation inside the kernel. Basically > @@ -749,11 +753,18 @@ int cp_prefetch(struct channel_program *cp) > for (idx = 0; idx < len; idx++) { > ret = ccwchain_fetch_one(chain, idx, cp); > if (ret) > - return ret; > + goto out_err; > } > } > > return 0; > +out_err: > + /* Only cleanup the chain elements that were actually translated. */ > + chain->ch_len = idx; > + list_for_each_entry_continue(chain, &cp->ccwchain_list, next) { > + chain->ch_len = 0; > + } > + return ret; > } > > /** Else, looks good.