Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp327885ybt; Thu, 25 Jun 2020 23:59:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPOQZtnew7lP3jVarY9QiSg5y+KvqB++02yyft0iHfLiDN5xfqIQXAu34zOet3hKtfHLfC X-Received: by 2002:a05:6402:b57:: with SMTP id bx23mr1810211edb.304.1593154775319; Thu, 25 Jun 2020 23:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593154775; cv=none; d=google.com; s=arc-20160816; b=F4CwVYikS5H4PE3Xbh/AVhM4ZE3BKWvTR30FxFW+VtPk/ZooFXioNVUsE+MoKEs3F1 2sGwnX2VNXgeEU5CWqQIde57PXGy7sBbZ3lh4msf+zPHURV4m6AixD1zLBw683ZR4SRr fJ8pxCaEA6mfHYlC9Ew+0J5s2gb38u/BCObJLPXmPKEj0WHutoXFyvvrwsXlDkTXkY6Q mHciiJrDYRKUzhBDf4c094fidLI03N6f/GEconxubHEfk81RLpxhy6A3qOSiYnrTxv6R izTmqEJzQXP299toGJb5IzLe9J1Nszqpowt2qaHgXVVw8e4Sq/FzTUTxUoh695TTp1mO ACPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=V+l+muZt/sw8G/XSlHsPuBLXnNDdXq2H/AVjO/IHBoc=; b=w8pGfp4x45QSoyJiwEc1boYHtzeFM3JC4zSLPP7mA6z/0BY6pnH7Wv0rHPcAiPs0FL DIJh9+0eKQOvQZ4rVbaqnj/H6OhFKQeu+/kxPmMrLsKCi30kGPX1MMFB7rsVvfojWyd1 nU9H5thGj7WqujNarutEZFAnF8yD78JnsyoK6cWlXwmY1rC6UriVB8quCb9X5ubfRlGD rnzcqpSpFQDBZ7ZvDqopjB2kPQ4VzbEXF+fdAHaPAXZflD5AalLSJ8B3PXZpbGU9cyFt msG6x5LPIM45cYhfYo4CUpjsn0hRjVaF1ZaA4XIWTgfv2R+eFnV3t67D09npKDQpUcbV AvQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K5UV7DHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si16446122eds.404.2020.06.25.23.58.26; Thu, 25 Jun 2020 23:59:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=K5UV7DHm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbgFZFgb (ORCPT + 99 others); Fri, 26 Jun 2020 01:36:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbgFZFga (ORCPT ); Fri, 26 Jun 2020 01:36:30 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E50C08C5C1 for ; Thu, 25 Jun 2020 22:36:30 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id s9so8974670ljm.11 for ; Thu, 25 Jun 2020 22:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=V+l+muZt/sw8G/XSlHsPuBLXnNDdXq2H/AVjO/IHBoc=; b=K5UV7DHm9sm3s0sHYb6ba/xN6yhjka7U9GIVRvzcWhmYHefr1XG5DjTflYuMoeUMSq TUAn/RBtSxiX3HJvfVtUk9kCwiQmGcHx/xCyazjugjCJln4lJo5EjMf8spOFgpo0T5+N TRYQ6oLyMEmgzyYAjoUipGDHORX2lcIkK4ubblOYSITS0iDoK2UpHWGivXGOyqJQSgLs m/7M1p1kk233506tloZkznzt9JpH7aJ4qt/pW3GsFC699uzoZUruaZJJpnl04B+wQUcM V0UlqtGFtm0T2l2ovrVzXP8pqGkyWo7CGCtTYMnXKAMz4D0ityGEf68qvnJ7rktsoQbh FyZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=V+l+muZt/sw8G/XSlHsPuBLXnNDdXq2H/AVjO/IHBoc=; b=tvZ1BCykjExGqlsstbDtEV7ZOwyJTG8tIeuThjLiuD3lF2UU+M+RHzz9e1HIGKUzDL k13to/2S0hQjxjQg2/7I+5rkaTOWoHzBiN7iko86Ljse1xSH4RAtpA+kXiEbJMrUETb+ gcX5SaC9VR6kpEtKkME7ESyXYQQ85WCVEQHsyk08aDnPXrIg2y75ARNdHdo+m51XtG4i EQZ08gP7jgGbPgLoFlss/totNLl61c3IpktAoDl0LiCDniz302snpvs5YcAA739sMc6S I9TASk8iWKTor1gKTYSFm8NETPvcqvD3XkIGGLWvk9lDUoRF1UzMNUlSSosNDSP5Yovu wfPA== X-Gm-Message-State: AOAM5339nrGFwDNX8iOtAAWAvocwKAqn08VO1aKp4ZxxtV/rJ2Bq69M9 LRBX1XyI4SV9PFjZBlJTj1NCj8wtt6OCqXijUyI= X-Received: by 2002:a2e:7208:: with SMTP id n8mr516027ljc.315.1593149788481; Thu, 25 Jun 2020 22:36:28 -0700 (PDT) MIME-Version: 1.0 References: <1593054160-12628-1-git-send-email-jrdr.linux@gmail.com> In-Reply-To: From: Souptick Joarder Date: Fri, 26 Jun 2020 11:06:17 +0530 Message-ID: Subject: Re: [PATCH 1/2] xen/privcmd: Corrected error handling path and mark pages dirty To: Boris Ostrovsky Cc: Juergen Gross , sstabellini@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, John Hubbard , Paul Durrant Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 26, 2020 at 5:01 AM Boris Ostrovsky wrote: > > On 6/24/20 11:02 PM, Souptick Joarder wrote: > > Previously, if lock_pages() end up partially mapping pages, it used > > to return -ERRNO due to which unlock_pages() have to go through > > each pages[i] till *nr_pages* to validate them. This can be avoided > > by passing correct number of partially mapped pages & -ERRNO separately, > > while returning from lock_pages() due to error. > > > > With this fix unlock_pages() doesn't need to validate pages[i] till > > *nr_pages* for error scenario and few condition checks can be ignored. > > > > As discussed, pages need to be marked as dirty before unpinned it in > > unlock_pages() which was oversight. > > > There are two unrelated changes here (improving error path and marking > pages dirty), they should be handled by separate patches. Sure, will do it in v2. > > > (I assume marking pages dirty is something you want to go to stable tree > since otherwise there is no reason for making this change) > > > > > > Signed-off-by: Souptick Joarder > > Cc: John Hubbard > > Cc: Boris Ostrovsky > > Cc: Paul Durrant > > --- > > Hi, > > > > I'm compile tested this, > > > I don't think so. I compile test it against ARM and it was fine. Against which ARCH is it failing ? > > > > but unable to run-time test, so any testing > > help is much appriciated. > > > > drivers/xen/privcmd.c | 34 +++++++++++++++++++--------------- > > 1 file changed, 19 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c > > index a250d11..0da417c 100644 > > --- a/drivers/xen/privcmd.c > > +++ b/drivers/xen/privcmd.c > > @@ -580,43 +580,44 @@ static long privcmd_ioctl_mmap_batch( > > > > static int lock_pages( > > struct privcmd_dm_op_buf kbufs[], unsigned int num, > > - struct page *pages[], unsigned int nr_pages) > > + struct page *pages[], unsigned int nr_pages, int *pinned) > > { > > unsigned int i; > > + int errno = 0, page_count = 0; > > > No need for error, really --- you can return the value immediately. yes, this is unnecessary. > > > > > > for (i = 0; i < num; i++) { > > unsigned int requested; > > - int pinned; > > > > + *pinned += page_count; > > > I'd move this lower, after a successful call to get_user_pages_fast() > (and then you won't need to initialize it) Ok. > > > > requested = DIV_ROUND_UP( > > offset_in_page(kbufs[i].uptr) + kbufs[i].size, > > PAGE_SIZE); > > if (requested > nr_pages) > > return -ENOSPC; > > > > - pinned = get_user_pages_fast( > > + page_count = get_user_pages_fast( > > (unsigned long) kbufs[i].uptr, > > requested, FOLL_WRITE, pages); > > - if (pinned < 0) > > - return pinned; > > + if (page_count < 0) { > > + errno = page_count; > > + return errno; > > + } > > > > - nr_pages -= pinned; > > - pages += pinned; > > + nr_pages -= page_count; > > + pages += page_count; > > } > > > > - return 0; > > + return errno; > > } > > > > static void unlock_pages(struct page *pages[], unsigned int nr_pages) > > { > > unsigned int i; > > > > - if (!pages) > > - return; > > - > > for (i = 0; i < nr_pages; i++) { > > - if (pages[i]) > > - put_page(pages[i]); > > + if (!PageDirty(page)) > > + set_page_dirty_lock(page); > > + put_page(pages[i]); > > } > > > This won't compile. > > > -boris > > >