Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp3915433imd; Mon, 29 Oct 2018 14:33:23 -0700 (PDT) X-Google-Smtp-Source: AJdET5ff5GJkqpk/9er77MwHpQKs+CuB85RyYwJIdbudIFIVtsdw5E0SUDB0QuNm7eSScJlxATs2 X-Received: by 2002:a17:902:a50e:: with SMTP id s14-v6mr15992071plq.78.1540848802945; Mon, 29 Oct 2018 14:33:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540848802; cv=none; d=google.com; s=arc-20160816; b=P/j9S4/naN37xi8G6piLMn4UPEEKfPWLgQ0WQStmD0+0a2eVKNeJ2VN6akobSgSHXS CjjM9qoj6iJn99IQ7aVGzUguz4RNBFHFT/X4pwM6viNMk6fngw9RH8Pj7lTReleKQT4E oGRkqs96YUydKhcQbrjOopljU0/MhcMdQoVyX95i3r9RBJPyY0sTcssklHHhWJ95Apm6 YqE4u/CDOA4qg7wwpqofuqOzQrbiqyZTTBC/hgwEGg1yUoWYSu9XooIHatQgfzPjqXW9 t6vi7XomTwcoUjf0KU8iuPXexR8tjkr5iz44KByea6j+P5MtL/uo28LVDaPIGzklApHB OD/Q== 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 :references:in-reply-to:message-id:subject:cc:to:from:date; bh=FGOPGpw2yFjOCkEdNrJm+hN6sgXXM6n9tAiP62InZAg=; b=y+IP3BHdkK9f6LWkNEx25RJJzollANtD6wEZmcP2RQyBSM1xIRqPjgp+fRoZ1VSi5s b4UdcQcjBnUx5lUPRp3nwH5mzJAglq3g73bzIpLiaodJD0bL3XR9OM0u8rVhi0b9v81g xQoWmNbCjgtecNdsi0f4CiQQUrbe88lJfSbIilpS5D3PESCrsebtBOoSfRAC+q47umui Y2wylffz2Glwtm4aeUzuqKvqGJF2XPRkjtpy3LVCeG2DRSsMlousgSqGgSyZ0uKFvLbT 9k5S/oRkjyx/aTKviOjsve6AjovA0KOdGK44IrsadgS3MJ7jLECcMvGJ4c4W+BxO5nGK TL4g== 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 x124-v6si18607084pfb.154.2018.10.29.14.33.06; Mon, 29 Oct 2018 14:33:22 -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 S1727597AbeJ3GXF (ORCPT + 99 others); Tue, 30 Oct 2018 02:23:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47108 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727265AbeJ3GXF (ORCPT ); Tue, 30 Oct 2018 02:23:05 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A71C2601B; Mon, 29 Oct 2018 21:32:35 +0000 (UTC) Received: from t450s.home (ovpn-116-133.phx2.redhat.com [10.3.116.133]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B2DF194AF; Mon, 29 Oct 2018 21:32:34 +0000 (UTC) Date: Mon, 29 Oct 2018 15:32:34 -0600 From: Alex Williamson To: Wenwen Wang Cc: Kangjie Lu , kvm@vger.kernel.org, open list , , David Gibson Subject: Re: [PATCH v4] drivers/vfio: Fix a redundant copy bug Message-ID: <20181029153234.36e67a6f@t450s.home> In-Reply-To: References: <1539803924-3190-1-git-send-email-wang6495@umn.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 29 Oct 2018 21:32:35 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 Oct 2018 13:56:54 -0500 Wenwen Wang wrote: > Hello, > > Could you please apply this patch? Thanks! I'd like to see testing and/or review from David or Alexey since I also don't have an environment for spapr/eeh. We're already late into the v4.20 merge window so this is probably v4.21 material. Thanks, Alex > On Wed, Oct 17, 2018 at 2:18 PM Wenwen Wang wrote: > > > > In vfio_spapr_iommu_eeh_ioctl(), if the ioctl command is VFIO_EEH_PE_OP, > > the user-space buffer 'arg' is copied to the kernel object 'op' and the > > 'argsz' and 'flags' fields of 'op' are checked. If the check fails, an > > error code EINVAL is returned. Otherwise, 'op.op' is further checked > > through a switch statement to invoke related handlers. If 'op.op' is > > VFIO_EEH_PE_INJECT_ERR, the whole user-space buffer 'arg' is copied again > > to 'op' to obtain the err information. However, in the following execution > > of this case, the fields of 'op', except the field 'err', are actually not > > used. That is, the second copy has a redundant part. Therefore, for > > performance consideration, the redundant part of the second copy should be > > removed. > > > > This patch removes such a part in the second copy. It only copies from > > 'err.type' to 'err.mask', which is exactly required by the > > VFIO_EEH_PE_INJECT_ERR op. > > > > Signed-off-by: Wenwen Wang > > --- > > drivers/vfio/vfio_spapr_eeh.c | 9 ++++++--- > > 1 file changed, 6 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/vfio/vfio_spapr_eeh.c b/drivers/vfio/vfio_spapr_eeh.c > > index 38edeb4..66634c6 100644 > > --- a/drivers/vfio/vfio_spapr_eeh.c > > +++ b/drivers/vfio/vfio_spapr_eeh.c > > @@ -37,6 +37,7 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, > > struct eeh_pe *pe; > > struct vfio_eeh_pe_op op; > > unsigned long minsz; > > + unsigned long start, end; > > long ret = -EINVAL; > > > > switch (cmd) { > > @@ -86,10 +87,12 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, > > ret = eeh_pe_configure(pe); > > break; > > case VFIO_EEH_PE_INJECT_ERR: > > - minsz = offsetofend(struct vfio_eeh_pe_op, err.mask); > > - if (op.argsz < minsz) > > + start = offsetof(struct vfio_eeh_pe_op, err.type); > > + end = offsetofend(struct vfio_eeh_pe_op, err.mask); > > + if (op.argsz < end) > > return -EINVAL; > > - if (copy_from_user(&op, (void __user *)arg, minsz)) > > + if (copy_from_user(&op.err, (char __user *)arg + > > + start, end - start)) > > return -EFAULT; > > > > ret = eeh_pe_inject_err(pe, op.err.type, op.err.func, > > -- > > 2.7.4 > >