From patchwork Sat Jan 6 22:52:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10148071 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E1BB160153 for ; Sat, 6 Jan 2018 22:58:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD16728769 for ; Sat, 6 Jan 2018 22:58:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F84287F9; Sat, 6 Jan 2018 22:58:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 782CD28769 for ; Sat, 6 Jan 2018 22:58:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753503AbeAFW6w (ORCPT ); Sat, 6 Jan 2018 17:58:52 -0500 Received: from mail-pf0-f195.google.com ([209.85.192.195]:42157 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752802AbeAFW6n (ORCPT ); Sat, 6 Jan 2018 17:58:43 -0500 Received: by mail-pf0-f195.google.com with SMTP id d23so3702322pfe.9; Sat, 06 Jan 2018 14:58:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=5PGeZ3P+8GGlZ6l77fFSeF2tB5c2reA8DNwqvHuczvs=; b=rF7DWer8QzXvIh8Tp2LCqfP6dr35cFIo/ePhv+ADg09RAGdS6pe9m4h2DLm9VLwp3f nti8wwhB4CFs5/UEgFxS5Ui1Er3bEOlFq/NbUgXPGOIvREzqFkF39GaZlQOftiDBuqpF o34/K/iKtsjri5VM6cUvEgYxiuw7Zzn82zokm5NC+80bOwIJK8FE+yWF3VaUBOxd2uSk jiIfXKqMSw1OJ7/dkqr1JLW5N8POyGFf60uYmAy+6j7xhl4PgkrunsdPIdtFc2C9KmKX e6lGFhl0MGZZy+AjtXaFs/19Fl0BrdL05ckFmY9guLtf5h2mGmJMEJceGedlecOtpLDM 28Fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=5PGeZ3P+8GGlZ6l77fFSeF2tB5c2reA8DNwqvHuczvs=; b=nll0/bWqotDPOYZOTyLp+Ugdn+dxYPMW+KGtsM1JTCbQAB+Wpsg5rqHBUWNarUE8lp mnFqsW5nasu5oWTgbs+dEkeBkVleTHbF9b3se87zHS5wRZyts5jlBetSCPO4ZH5kWk7b g+O4gOKss04eWPxpYgkTT373ZQQj/u6KAG14eswPYcSNIvtUJv9pU0Vh0D2DHKgnnBSb R5G37d/44tW15149IShc6W+iztZGGZlYIJ92TWb6VTM/LJzpDCh/S9JcZucPBTTIFks+ XOpuh16AlkiNYODnERLit2B3KJwvYBgbo85t9V7oa3f7AGoC1ZL9vJDcfKuDK+aPJj2T P26g== X-Gm-Message-State: AKGB3mKn+UvsylaLvROc7Yr16UHe5+8sarqgtAxRw+6cz7okJg4/D1T8 9GUx3z7o6PBwts5jxYYUvYOyHzg6 X-Google-Smtp-Source: ACJfBov13RkuiPqNT0TOMf8rbMhxZgacZCc5SIAjJDTzqk6xh/b04FomyWZzjDQKNSdnnQYyuCJrBQ== X-Received: by 10.98.60.15 with SMTP id j15mr6865158pfa.112.1515279522558; Sat, 06 Jan 2018 14:58:42 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id u21sm17904039pfl.102.2018.01.06.14.58.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jan 2018 14:58:42 -0800 (PST) From: Eric Biggers To: linux-fsdevel@vger.kernel.org, Al Viro Cc: kvm@vger.kernel.org, "Michael S . Tsirkin" , Jason Wang , Eric Biggers Subject: [PATCH 3/3] vhost: don't hold onto file pointer for VHOST_SET_LOG_FD Date: Sat, 6 Jan 2018 14:52:21 -0800 Message-Id: <20180106225221.1965-4-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180106225221.1965-1-ebiggers3@gmail.com> References: <20180106225221.1965-1-ebiggers3@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers We already hold a reference to the eventfd_ctx, which is sufficient; there's no need to hold a reference to the struct file as well. So get rid of vhost_dev->log_file. Signed-off-by: Eric Biggers --- drivers/vhost/vhost.c | 24 +++++------------------- drivers/vhost/vhost.h | 1 - 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 39e184b168ce..67ea87a4a526 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -420,7 +420,6 @@ void vhost_dev_init(struct vhost_dev *dev, dev->nvqs = nvqs; mutex_init(&dev->mutex); dev->log_ctx = NULL; - dev->log_file = NULL; dev->umem = NULL; dev->iotlb = NULL; dev->mm = NULL; @@ -627,9 +626,6 @@ void vhost_dev_cleanup(struct vhost_dev *dev, bool locked) if (dev->log_ctx) eventfd_ctx_put(dev->log_ctx); dev->log_ctx = NULL; - if (dev->log_file) - fput(dev->log_file); - dev->log_file = NULL; /* No one will access memory at this point */ vhost_umem_clean(dev->umem); dev->umem = NULL; @@ -1570,8 +1566,7 @@ EXPORT_SYMBOL_GPL(vhost_init_device_iotlb); /* Caller must have device mutex */ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) { - struct file *eventfp, *filep = NULL; - struct eventfd_ctx *ctx = NULL; + struct eventfd_ctx *ctx; u64 p; long r; int i, fd; @@ -1617,19 +1612,12 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) r = get_user(fd, (int __user *)argp); if (r < 0) break; - eventfp = fd == -1 ? NULL : eventfd_fget(fd); - if (IS_ERR(eventfp)) { - r = PTR_ERR(eventfp); + ctx = fd == -1 ? NULL : eventfd_ctx_fdget(fd); + if (IS_ERR(ctx)) { + r = PTR_ERR(ctx); break; } - if (eventfp != d->log_file) { - filep = d->log_file; - d->log_file = eventfp; - ctx = d->log_ctx; - d->log_ctx = eventfp ? - eventfd_ctx_fileget(eventfp) : NULL; - } else - filep = eventfp; + swap(ctx, d->log_ctx); for (i = 0; i < d->nvqs; ++i) { mutex_lock(&d->vqs[i]->mutex); d->vqs[i]->log_ctx = d->log_ctx; @@ -1637,8 +1625,6 @@ long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, void __user *argp) } if (ctx) eventfd_ctx_put(ctx); - if (filep) - fput(filep); break; default: r = -ENOIOCTLCMD; diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 3fe82323f667..da86623871d9 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -161,7 +161,6 @@ struct vhost_dev { struct mutex mutex; struct vhost_virtqueue **vqs; int nvqs; - struct file *log_file; struct eventfd_ctx *log_ctx; struct llist_head work_list; struct task_struct *worker;