Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2376984imu; Sun, 18 Nov 2018 22:42:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/WmBSKD/bhCts8Ep3Pi+GgrrYU1ZLvU+LqRCp5pilGSLgJeUR5sbO9H6MqlP4PRcu709p47 X-Received: by 2002:a17:902:4124:: with SMTP id e33mr1785315pld.236.1542609758968; Sun, 18 Nov 2018 22:42:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542609758; cv=none; d=google.com; s=arc-20160816; b=RvpyiMQbvJU0v6oZT9HvgtzZZ16jX4hBdc27W+OnFjvqFAirrfYWCSWjA4ex/4IC3z DkGSvi6bL9p3uyto1INAGhTjFM2Wnp/AlyVBKy/8fl11T+CWpo6PVuUq6/QWRkjHuka3 UPeLqBNT1XI5y/JthB1e7dk8kxK9C7rKwtEepdIET2U4S0F13KwcP/iyjH0Sby7ZljCQ lDp0Ps3vAwfFkC8Imzq6Ddh0RA1l8w/arxVqs5zIrH1TEKLJa5nMTj+6K8OQed4LDrUr 8OJIMP3fldL03WN5y5/J2U6HIXJodBWxf35kxDJ6zZUFcqUwBZXGMTEAvYYEy7hKOrWy yMtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UDT54jwBEeJeCxhwoFkc1m7zkKIYfMK+M0AOVC/oiIQ=; b=sfZQUIYFq4h8ID5Wd79kWkFhkY/Ehz+3kChamMbe0F+3B6iwuoxkAT8MoBXafXH/Jh ZhIZd6nR7aGPhk8oK9kK1I1bTQtwtpb3JPogl6b55pggwqJbDOtVg/JjNbFGb9UVXt45 o6kBS8q8Rby1tyRJIqVPCVxvVeKe6309RNcaPywmRly2Wm5d6RW1JYREYXBttmz2ZJAj gPOIkxN7Uo+AIRlASwAreh9Etgqkg6U+WLbGjMgXcqOkI0HphyE0/C02l+TOKUWSwWVa GM5FEqM0t76bmZoR5CGw9QITghgL1YtotcmE/hbOyuC5HvxZJkDmNXQ6R/42N/PKratr MOVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=X0bR59k4; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y20si9465954plr.106.2018.11.18.22.42.21; Sun, 18 Nov 2018 22:42:38 -0800 (PST) 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; dkim=pass header.i=@gibson.dropbear.id.au header.s=201602 header.b=X0bR59k4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726224AbeKSREV (ORCPT + 99 others); Mon, 19 Nov 2018 12:04:21 -0500 Received: from ozlabs.org ([203.11.71.1]:48309 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725908AbeKSREV (ORCPT ); Mon, 19 Nov 2018 12:04:21 -0500 Received: by ozlabs.org (Postfix, from userid 1007) id 42yzl56fytz9sBQ; Mon, 19 Nov 2018 17:41:37 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1542609697; bh=HtMtsGYqlqi6aIXFoBgtOpeGfTbmd65176UllwGh7f0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X0bR59k494bcKnlmInsDvHWVwUNRIOqlDoMWyNm4M827sPQMJUhpeBxwo7Fs8CWd4 GDUiUVGIRbeoDMR4GPbked1K6SQBwlkEnhHeeXu2qX8nyTuWpqeVj4v568QdvAgekv Z3ONU9bVno5dXe6H2Msyllu7s2w8up/G86ynmeK4= Date: Mon, 19 Nov 2018 17:41:31 +1100 From: David Gibson To: Alex Williamson Cc: Wenwen Wang , Kangjie Lu , kvm@vger.kernel.org, open list , aik@ozlabs.ru Subject: Re: [PATCH v4] drivers/vfio: Fix a redundant copy bug Message-ID: <20181119064131.GK23503@umbus> References: <1539803924-3190-1-git-send-email-wang6495@umn.edu> <20181029153234.36e67a6f@t450s.home> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rnP2AJ7yb1j09OW/" Content-Disposition: inline In-Reply-To: <20181029153234.36e67a6f@t450s.home> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --rnP2AJ7yb1j09OW/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Oct 29, 2018 at 03:32:34PM -0600, Alex Williamson wrote: > On Mon, 29 Oct 2018 13:56:54 -0500 > Wenwen Wang wrote: >=20 > > Hello, > >=20 > > Could you please apply this patch? Thanks! >=20 > 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, I didn't spot this for ages, since I wasn't CCed, I'm guessing the same is true for Alexey. TBH, I don't think it's worth bothering with this. It's a tiny amount of extra work on a rare debug path. A couple of code lines simplicity is worth more than a few bytes worth of redundant copy here. Testing is.. difficult, since the EEH is already so broken it's hard to know what to compare against. Sam Bobroff is already looking medium-long term at a bunch of EEH rework, so it's quite possible this will be rewritten then anyway. >=20 > Alex >=20 > > 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 t= he > > > '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 a= gain > > > to 'op' to obtain the err information. However, in the following exec= ution > > > of this case, the fields of 'op', except the field 'err', are actuall= y not > > > used. That is, the second copy has a redundant part. Therefore, for > > > performance consideration, the redundant part of the second copy shou= ld 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 =3D -EINVAL; > > > > > > switch (cmd) { > > > @@ -86,10 +87,12 @@ long vfio_spapr_iommu_eeh_ioctl(struct iommu_grou= p *group, > > > ret =3D eeh_pe_configure(pe); > > > break; > > > case VFIO_EEH_PE_INJECT_ERR: > > > - minsz =3D offsetofend(struct vfio_eeh_pe_op, = err.mask); > > > - if (op.argsz < minsz) > > > + start =3D offsetof(struct vfio_eeh_pe_op, err= =2Etype); > > > + end =3D offsetofend(struct vfio_eeh_pe_op, er= r.mask); > > > + if (op.argsz < end) > > > return -EINVAL; > > > - if (copy_from_user(&op, (void __user *)arg, m= insz)) > > > + if (copy_from_user(&op.err, (char __user *)ar= g + > > > + start, end - start)) > > > return -EFAULT; > > > > > > ret =3D eeh_pe_inject_err(pe, op.err.type, op= =2Eerr.func, >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --rnP2AJ7yb1j09OW/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAlvyWxkACgkQbDjKyiDZ s5JWxQ//SVEE+8+PaxFpc/YZcNHDN6i7I+IZlc9pWPWXB/7OH+Jg6UP+xDxXKtdC t4ktsuom46ek0UP1eR7Kt5fbGIyG38sGu+X4b5fefgBMA8NrepULft6A/e8jWaov EBCuutpReATymzBSA2RjOalbGW102GbOpUXM8LnnWVLwQHhv2Asb8xDtCBeCwow0 xRETRRGNiKfEfnTjCoY+1zGRLRNg2KtmJrJS/6Kp8dnMQpCR50kHuBMc8fyfZfKF x1Gvsv/yMihnThdfGHPduU39MKuBwGJC+04jL3DXD/koxbmk5omix3jqFOylThYT oonvEpfI+boRjwBrgtSiyJyUppCw25Do/4WmWUNentYfYbiHlAn6ouLzmNkM85X3 Acnt8YNLD9HmCuu32XnArpQCG2KPNQ3Rdc2HwPCDmD3TP7T7s5Q9pkChBrKydzRc LKGEeiiT8fRpVFWPqcreG6cmreDeLG5QHNiBE3G/QKWm2s+pufbJUoGKv3dSRYBZ SKYfTa3c8Fn5PWNBfwG4dLmB5mxHBLoDYQ371mW+vMaVdTxs8o2lJ/YCXiUpDfdS 3X+HDV+2YC98rqEjQGg7+lk/jPJtA4eKCkXQj92z8VmbG2JO5NXakawlHpDGJwjF p9LPUqQFgIfI+579l3k8Dzpppd7DnhmCBP4HhI9pZVWrHyZRYdI= =TFwv -----END PGP SIGNATURE----- --rnP2AJ7yb1j09OW/--