Received: by 10.213.65.68 with SMTP id h4csp1323579imn; Mon, 26 Mar 2018 05:29:55 -0700 (PDT) X-Google-Smtp-Source: AG47ELupUQk/BojMFLzA6rLPeVD5Q4uAlR7jY6myrpJkakP1XGJCsXrZnlyaNzd9vvTgN6Lom4dC X-Received: by 10.101.76.10 with SMTP id u10mr16380604pgq.445.1522067395506; Mon, 26 Mar 2018 05:29:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522067395; cv=none; d=google.com; s=arc-20160816; b=t6Y+gO7Xwo0YxlL6/6JLNqwRysZKH9P/DBqtCUQSDzDrTyjgGG0KOdze5uFKr0s9gj 0XobceUAwC4KKs7KCmhbdDcAHGtrL4lAUS6XgzConnTj0VVhwE275m+AlmmoWTknzoij FDTOVMmvCt3OIJfzb3gq2nCoSL2ckn0rkLxWjuYf+KHUlizJJxelSziAv8lpPJdwtHzH bDp6H/JK2gtGhB4T0joxffC28KvKxcz6vjSvTgqsFidWqlqHrCxUqjp5L1lkssAu9Di4 3/NAHxQnt0t3lYvgTkJ/vt/IakZ3vxKHseHxBAENoWAYWDfTbZs0zJ1NJ1dKmuhIPK3m SxHw== 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=7BphXdlmUJ88QvlV5g/mxc2NFjXFX2vtybib/nxY0p4=; b=psiCW8etMXI7dh7/kTeHn6T1zqMZsZTi1HIwUtF3gtYEu5OUE2v3JJIQJLtkFTVwqk XuXrFU5boKW/EPZigWQVTyHJ1BT5wL+u+q+NrEsXRkAyIUUPwL/gK1yIGZ1/4feQGJaK 8Ewg13IeQ4QFyWSrUA2j7Dyw71sHV/qmL3WRWswx7VxpV8dH9cLrKkVPr39W2wp/4ZGs M8od9ECVtP6AF1TkWvOEnQzyfrik5s2akWpXsges/P1Vq/Em4Pd6TKVqebFgqhztlxe2 Gfs2hjWGJfcVinyKu5AzD4bZEmsYH6muwtw/KjY+Gug1BUO923ZiLBSLrxv4RHVVvnhJ o3wQ== 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 64-v6si14456174plk.152.2018.03.26.05.29.41; Mon, 26 Mar 2018 05:29:55 -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 S1752008AbeCZM2p (ORCPT + 99 others); Mon, 26 Mar 2018 08:28:45 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:35034 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751141AbeCZM2o (ORCPT ); Mon, 26 Mar 2018 08:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7DB02401DECF; Mon, 26 Mar 2018 12:28:43 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id 64C3D7C4F; Mon, 26 Mar 2018 12:28:42 +0000 (UTC) Date: Mon, 26 Mar 2018 14:28:39 +0200 From: Cornelia Huck To: Pierre Morel Cc: Dong Jia Shi , Halil Pasic , linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, kvm@vger.kernel.org, borntraeger@de.ibm.com Subject: Re: [PATCH 1/4] vfio: ccw: fix cleanup if cp_prefetch fails Message-ID: <20180326142839.23bfc4f6.cohuck@redhat.com> In-Reply-To: <54fd02cd-bd0b-889b-c40f-f9a32aa25d77@linux.vnet.ibm.com> References: <20180321020822.86255-1-bjsdjshi@linux.vnet.ibm.com> <20180321020822.86255-2-bjsdjshi@linux.vnet.ibm.com> <682d8b1c-5aca-7015-043b-a3f1446bf378@linux.vnet.ibm.com> <20180322022248.GB12194@bjsdjshi@linux.vnet.ibm.com> <54fd02cd-bd0b-889b-c40f-f9a32aa25d77@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.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 26 Mar 2018 12:28:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Mon, 26 Mar 2018 12:28:43 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.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 Thu, 22 Mar 2018 10:37:36 +0100 Pierre Morel wrote: > On 22/03/2018 03:22, Dong Jia Shi wrote: > > * Halil Pasic [2018-03-21 13:49:54 +0100]: > > > >> > >> On 03/21/2018 03:08 AM, 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 to 0 for the ccw chains those are not prefetched. > >> This sentence used to be: > >> > >> Let's make sure cp_free works properly after cp_prefetch returns with an > >> error. > >> > >> @Dong Jia > >> I find the 'by setting ch_len to 0 for the ccw chains those are not prefetched' > >> you added for clarification (I guess) somewhat problematic. > >> The chain in which the translation failure occurred > >> + chain->ch_len = idx; > > I made a mistake. When rewording the message, I missed this part... > > Sorry for the problem! > > > >> is shortened so that only the translated elements (ccws) are going to > >> get cleaned up (on a per element basis) by cp_free. This may or may > >> not be the first ccw. Subsequent chains are shortened to 0 as there > >> no translation took place. > >> > >> So as a result of this change only properly translated ccws are going > >> to get (re)visited by cp_free as only those may have resources bound > >> to them which need to be released. > >> > >> I'm not against improving the commit message. But this ain't > >> an improvement to me. > > You are right. How about: > > 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. > > By the way, since you will propose a new version, > you have a long description of the cp_prefetch function in the code. > I think you should modify it according to the changes and describe how and > why the ch_len field of each chain is used and changed by this function. > > Something like: > > " > For each chain composing the channel program: > On entry ch_len hold the count of CCW to be translated. s/hold/holds/ ? > 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. > " > > Could also be inside the commit message. > > Pierre > > > > > >>> 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 | 9 ++++++++- > >>> 1 file changed, 8 insertions(+), 1 deletion(-) > >>> > >>> diff --git a/drivers/s390/cio/vfio_ccw_cp.c b/drivers/s390/cio/vfio_ccw_cp.c > >>> index d9a2fffd034b..2be114db02f9 100644 > >>> --- a/drivers/s390/cio/vfio_ccw_cp.c > >>> +++ b/drivers/s390/cio/vfio_ccw_cp.c > >>> @@ -749,11 +749,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 where actually translated. */ s/where/were/ > >>> + chain->ch_len = idx; > >>> + list_for_each_entry_continue(chain, &cp->ccwchain_list, next) { > >>> + chain->ch_len = 0; > >>> + } > >>> + return ret; > >>> } > >>> > >>> /** > >>> >