From patchwork Thu Apr 4 13:20:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 10885611 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B0AE17EE for ; Thu, 4 Apr 2019 13:22:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 059F7286C0 for ; Thu, 4 Apr 2019 13:22:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE0FA286D6; Thu, 4 Apr 2019 13:22:21 +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.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham 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 75B2A286C6 for ; Thu, 4 Apr 2019 13:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729743AbfDDNWU (ORCPT ); Thu, 4 Apr 2019 09:22:20 -0400 Received: from foss.arm.com ([217.140.101.70]:60222 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729204AbfDDNWT (ORCPT ); Thu, 4 Apr 2019 09:22:19 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5396616A3; Thu, 4 Apr 2019 06:22:19 -0700 (PDT) Received: from ostrya.cambridge.arm.com (ostrya.cambridge.arm.com [10.1.196.129]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 8AB1D3F68F; Thu, 4 Apr 2019 06:22:18 -0700 (PDT) From: Jean-Philippe Brucker To: Will.Deacon@arm.com Cc: Andre.Przywara@arm.com, kvm@vger.kernel.org Subject: [PATCH kvmtool v2 5/9] disk/aio: Fix use of disk->async Date: Thu, 4 Apr 2019 14:20:46 +0100 Message-Id: <20190404132050.37309-6-jean-philippe.brucker@arm.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404132050.37309-1-jean-philippe.brucker@arm.com> References: <20190404132050.37309-1-jean-philippe.brucker@arm.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add an 'async' attribute to disk_image_operations, that describes if they can submit async I/O or not. disk_image->async is now set iff CONFIG_HAS_AIO and the ops do use AIO. This fixes qcow1, which used to set async = 1 even though the qcow operations don't use AIO. The disk core would perform the read/write operation without pushing the completion onto the virtio queue, and the guest would be stuck waiting. Reviewed-by: Andre Przywara Signed-off-by: Jean-Philippe Brucker --- disk/aio.c | 9 +++++++++ disk/blk.c | 9 ++------- disk/qcow.c | 2 -- disk/raw.c | 15 +++------------ include/kvm/disk-image.h | 1 + 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/disk/aio.c b/disk/aio.c index 6afcffe5a..007415c69 100644 --- a/disk/aio.c +++ b/disk/aio.c @@ -90,6 +90,10 @@ int disk_aio_setup(struct disk_image *disk) int r; pthread_t thread; + /* No need to setup AIO if the disk ops won't make use of it */ + if (!disk->ops->async) + return 0; + disk->evt = eventfd(0, 0); if (disk->evt < 0) return -errno; @@ -101,11 +105,16 @@ int disk_aio_setup(struct disk_image *disk) close(disk->evt); return r; } + + disk->async = true; return 0; } void disk_aio_destroy(struct disk_image *disk) { + if (!disk->async) + return; + close(disk->evt); io_destroy(disk->ctx); } diff --git a/disk/blk.c b/disk/blk.c index 37581d331..48922e028 100644 --- a/disk/blk.c +++ b/disk/blk.c @@ -9,6 +9,7 @@ static struct disk_image_operations blk_dev_ops = { .read = raw_image__read, .write = raw_image__write, + .async = true, }; static bool is_mounted(struct stat *st) @@ -35,7 +36,6 @@ static bool is_mounted(struct stat *st) struct disk_image *blkdev__probe(const char *filename, int flags, struct stat *st) { - struct disk_image *disk; int fd, r; u64 size; @@ -67,10 +67,5 @@ struct disk_image *blkdev__probe(const char *filename, int flags, struct stat *s * mmap large disk. There is not enough virtual address space * in 32-bit host. However, this works on 64-bit host. */ - disk = disk_image__new(fd, size, &blk_dev_ops, DISK_IMAGE_REGULAR); -#ifdef CONFIG_HAS_AIO - if (!IS_ERR_OR_NULL(disk)) - disk->async = 1; -#endif - return disk; + return disk_image__new(fd, size, &blk_dev_ops, DISK_IMAGE_REGULAR); } diff --git a/disk/qcow.c b/disk/qcow.c index bed70c65c..dd6be62ee 100644 --- a/disk/qcow.c +++ b/disk/qcow.c @@ -1337,7 +1337,6 @@ static struct disk_image *qcow2_probe(int fd, bool readonly) if (IS_ERR_OR_NULL(disk_image)) goto free_refcount_table; - disk_image->async = 0; disk_image->priv = q; return disk_image; @@ -1474,7 +1473,6 @@ static struct disk_image *qcow1_probe(int fd, bool readonly) if (!disk_image) goto free_l1_table; - disk_image->async = 1; disk_image->priv = q; return disk_image; diff --git a/disk/raw.c b/disk/raw.c index 09da7e081..e869d6cc2 100644 --- a/disk/raw.c +++ b/disk/raw.c @@ -67,6 +67,7 @@ int raw_image__close(struct disk_image *disk) static struct disk_image_operations raw_image_regular_ops = { .read = raw_image__read, .write = raw_image__write, + .async = true, }; struct disk_image_operations ro_ops = { @@ -77,12 +78,11 @@ struct disk_image_operations ro_ops = { struct disk_image_operations ro_ops_nowrite = { .read = raw_image__read, + .async = true, }; struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly) { - struct disk_image *disk; - if (readonly) { /* * Use mmap's MAP_PRIVATE to implement non-persistent write @@ -93,10 +93,6 @@ struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly) disk = disk_image__new(fd, st->st_size, &ro_ops, DISK_IMAGE_MMAP); if (IS_ERR_OR_NULL(disk)) { disk = disk_image__new(fd, st->st_size, &ro_ops_nowrite, DISK_IMAGE_REGULAR); -#ifdef CONFIG_HAS_AIO - if (!IS_ERR_OR_NULL(disk)) - disk->async = 1; -#endif } return disk; @@ -104,11 +100,6 @@ struct disk_image *raw_image__probe(int fd, struct stat *st, bool readonly) /* * Use read/write instead of mmap */ - disk = disk_image__new(fd, st->st_size, &raw_image_regular_ops, DISK_IMAGE_REGULAR); -#ifdef CONFIG_HAS_AIO - if (!IS_ERR_OR_NULL(disk)) - disk->async = 1; -#endif - return disk; + return disk_image__new(fd, st->st_size, &raw_image_regular_ops, DISK_IMAGE_REGULAR); } } diff --git a/include/kvm/disk-image.h b/include/kvm/disk-image.h index 953beb2d5..adc9fe465 100644 --- a/include/kvm/disk-image.h +++ b/include/kvm/disk-image.h @@ -42,6 +42,7 @@ struct disk_image_operations { int iovcount, void *param); int (*flush)(struct disk_image *disk); int (*close)(struct disk_image *disk); + bool async; }; struct disk_image_params {