Received: by 10.213.65.68 with SMTP id h4csp176103imn; Wed, 28 Mar 2018 01:05:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/T71J3eZ53IqIZ5YOA/qFjKK3XG+rdEqwusiw6rDFWdGMZbeBeooLIY2GUBK3LtN9I3l// X-Received: by 10.99.112.77 with SMTP id a13mr1822507pgn.253.1522224321402; Wed, 28 Mar 2018 01:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522224321; cv=none; d=google.com; s=arc-20160816; b=SdRiQsbFs4vnnHTIzr5IL+UQ6hjhHWzD7YWTmJ9RWRHHXnKimp1/TYB4MkLZeuXNit l/br9IoTVEEsLzdTGot7GW5T8MwgncHquyji27RsQiU/YLZGWB3wRLckeEabT5+dd3I/ EYvJr7Li9iIjCXzpdLXvcFhTJ1dZ88CycXO4EM4/gLq9eeQ8GM+TmAxAEGVTOLdHoFyJ gRjTBpWSIaHtng44ZbWH6iAb+0ZpKVcNmKhMrTfCI+sDS/WpQtZ7pY5ntdS81ZBbnOLH nezrCs1Op6NYUuy8T4kUgE3c6j1EMrLBoVsJyAKHkc9tOA2HpwVPX4NN8PvZVTxVx6tu 52NA== 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=GVt26mApaZGoCsFwaEbf//O6ajNol8omBY8vGLKC3FQ=; b=M45rNf/ajrIK+51LCtXLvDINowbiFeUrdqAwuQqCvSyD+nXmvQmF5qkP67BTeJD45k QZRxpyS+LqY1dYUToxKA9pz9KIciW+SL4vU4Xmf7v7fSIMEDRVYNuJAS0/rP6odNwi4+ dzcejxCTmD2caMOE58wUNlusJPXjRFh7uhUMjC9r3jvTvGai8ntDwrn2Sel+BUwb4Rye wXlHECsRY4JTNP+dUNK/YYfhmHEjOx7ZNlRnZcIQhta2S38zcSyaYGocB7KLcm1v1OuA Lbws+TFCLcOb8dAGII2vi4DaaY7XPcLXqd419hF2stbEO8n9G+CAzS9RQMpoqcDZt8vm wQ8Q== 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 n10-v6si3007764plk.689.2018.03.28.01.05.07; Wed, 28 Mar 2018 01:05:21 -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 S1752180AbeC1H6Q (ORCPT + 99 others); Wed, 28 Mar 2018 03:58:16 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:58532 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751903AbeC1H6O (ORCPT ); Wed, 28 Mar 2018 03:58:14 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C65644023150; Wed, 28 Mar 2018 07:58:13 +0000 (UTC) Received: from gondolin (dhcp-192-222.str.redhat.com [10.33.192.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADE32215CDB5; Wed, 28 Mar 2018 07:58:12 +0000 (UTC) Date: Wed, 28 Mar 2018 09:58:10 +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, pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com Subject: Re: [PATCH 2/4] vfio: ccw: refactor and improve pfn_array_alloc_pin() Message-ID: <20180328095810.24807263.cohuck@redhat.com> In-Reply-To: <20180328023638.GL12194@bjsdjshi@linux.vnet.ibm.com> References: <20180321020822.86255-1-bjsdjshi@linux.vnet.ibm.com> <20180321020822.86255-3-bjsdjshi@linux.vnet.ibm.com> <20180326152846.2ef1ae07.cohuck@redhat.com> <20180327030026.GI12194@bjsdjshi@linux.vnet.ibm.com> <20180327120127.16f7884f.cohuck@redhat.com> <20180328023638.GL12194@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.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 07:58:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Wed, 28 Mar 2018 07:58:13 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 Wed, 28 Mar 2018 10:36:38 +0800 Dong Jia Shi wrote: > * Cornelia Huck [2018-03-27 12:01:27 +0200]: > > [...] > > > > > > > > > So, basically everything is filled by pfn_array_alloc_pin()? > > > Yes. > > > > > > > Should we expect a clean struct pfn_array handed in by the caller, > > > > then (not just pa_nr == 0)? > > > The current idea is: > > > - It is a clean struct that pfn_array_alloc_pin() expects from its > > > caller. > > > - pfn_array_alloc_pin() and pfn_array_unpin_free() should be used in > > > pair. They are the only functions those change the values of the > > > elements of a pfn_array struct. > > > - Caller of pfn_array_alloc_pin() should either hand in a new allocated > > > pfn_array (zeroed out), or a freed-after-used one. > > > - So using pa_nr == 0, is enough to identify all the good cases. > > > [We set pa_nr to 0 in pfn_array_unpin_free().] > > > > > > Validating all of the elements only helps when there is case that a > > > caller breaks the usage rule of these interfaces - the caller itself > > > assigns values for pfn_pa elements directly... I don't think we allow > > > this to happen. > > > > > > So I think the current logic is fine. > > > > Yes, I think it is fine -- I was mainly wondering whether we wanted > > more sanity checks. > > > Ok. > Check on (pa->pa_iova_pfn != NULL) could be added. It's easy to do so. > Check on pa->pa_iova doesn't make sense, since its value will be > re-assigned anyway. > Check on pa->pa_pfn doesn't make sense, since we treat it as a pointer > that points to part of the memory area that was pointed by > pa->pa_iova_pfn. And we will re-assign it with new pa->pa_iova_pfn > value. Yeah, so additional checks are probably not very useful. > > > > > > > > > > > > Would it make sense to describe the contents of the struct pfn_array > > > > fields at the struct's definition instead? You could then shorten the > > > > description here to "we expect pa_nr == 0, any field in this structure > > > > will be filled in by this function". > > > Sounds good! > > > Do you want a separated patch for this, or I do this change on this > > > patch? Either will be ok with me. > > > > Perhaps as an additional patch in front of this one? > > > It's doable. I will do that. > Cool, thx!