From patchwork Mon Jan 20 05:54:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6BEC413A4 for ; Mon, 20 Jan 2020 05:59:27 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E2B7F2073D for ; Mon, 20 Jan 2020 05:59:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="IDSh7trz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E2B7F2073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58898 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ5t-00043x-C6 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 00:59:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35136) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1L-0006jf-UR for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1K-0006EE-7z for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:43 -0500 Received: from mail-bn7nam10on2099.outbound.protection.outlook.com ([40.107.92.99]:53408 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1K-0006Cs-2K for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:42 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BfHav3OJ2V4QeQ0mqmSfUexG++8TF89LMybKVvaJUA/gSKJLCHv/TfnDECVBip1FHKTLT+U/fg6M4Ir/OZzqMmx5LwZYg4IYCiUJP03ia6EHGoxfjZM+Fy3TTDJf2V00tav7FxVeJGKdlGx9zPYjOJeHoSiDUxWeWArjwydbu0lVADh7ngc1KvhE5XHH6VqPTCzzdZY/9SYlqo2gvXivRvUdZIaPh7IKgiGF8gqr5NMprMaSAdv3fZZ39C1+VoUMn3eZBYlzKyzf/M2C97e33wq2avI59QoHWUwHqOPPMPRUKJ7J9cu5GVAFAQuFW7zbOgWFFaifKrb1mweWGEEn3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AUyxkMgSXmZiu/Rc1nJfJkjjXVUMnmlDUGvnTkwt2jI=; b=QHjtUgRcqlSIU5dp2v7avuqncRwIGiNWT4nUYZAr/WxSNJJOD0jnZm3BxosL+crVAqS1vsaim39dzhWjBkADFCFpYV3/EL5FbreI0C6oQDZMGuJLLylvKdVOUfhMtG+juQG/hj7rsIY/EufqmC+7GBBbD4xn6s9z/9AP9LAbACEE99fmLtk9Hj5LZ4Svh/UVbPyJb7HMAPWinJSDoKnPxTyRV39A24eo3HQU4eUyimwLgEuLap8E/PUbDKl/oNmBcCbFEFq11joJ9rfepiv6RCN2Oipqh7ZeMg4vlgrAj9Xm8nECF3w1vWOBKv5hGF4FtNs7RaHYd8R/boRJ1bX4Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=AUyxkMgSXmZiu/Rc1nJfJkjjXVUMnmlDUGvnTkwt2jI=; b=IDSh7trzoWXoUFSyKmWKHW9JZqeW4YccW4kRxPCNM+y1MigunsyqhWRns7OM9TCwuvV13NnHixs0OG9h9mzqmiYZe3U0gbOVPa2VRvSqfamLdvFfD5Nh1ttLfm43ONxhj80tniI/feruS+RtkfRtOMDFpqhXKcIRlYgmuIW6x00= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:41 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:41 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:37 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 01/20] softmmu: split off vl.c:main() into main.c Thread-Topic: [PATCH v7 01/20] softmmu: split off vl.c:main() into main.c Thread-Index: AQHVz1YZvX5VLYzcBUSUoT2caaa2xw== Date: Mon, 20 Jan 2020 05:54:38 +0000 Message-ID: <20200120055410.22322-2-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 56d109b1-d738-4206-6562-08d79d6d3c28 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: JPdP9/2DpAUH+yw0vuf9TVhjJCxm106nijbAzRWxtw165sK0jVhPJLc9+GoZfs/eQoSGgHORgznNgbeH3XX6eVz0Nk8ZjQbKe1WQlVpGqMV3ULtNukOdPaLTjBOEBXnv2bldd8YPClSeI26I8AQdFzKUcbyUtjOW/9qeW5MrmugPcJ9+1g09AUZc0EU48Yw9bvK4Uad2W2UsEdS2TmEGVJuPxw2Kwc3QGuLWQobCGKuWusso86Bbws31iv+s0EBGcCnDYZ6wBb26VrbNvX1FL3kKQ6EKY38i1MjK2j8oF9/zS0bzPoTtPDes2CW4IKdesjdiOFkGcZm2jpKYRArjMVNlVo/AiYJbqCeFZ/W+o8pYzKDfMyckR+eVKto/Jy3+HpIaBMkptwX8u6m1ztRxrq1o+64yRkvOejvg3OxruLFViWw75+8yAbo4/Vg6GGLd MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 56d109b1-d738-4206-6562-08d79d6d3c28 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:38.7897 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: E9AqJA0Ajzf/AalcJHzZTx34M7+kxEOVY8dJQpJZgVX2k93v26sKOFg+rL1uU7Hv X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.99 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , "stefanha@redhat.com" , "Bulekov, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" A program might rely on functions implemented in vl.c, but implement its own main(). By placing main into a separate source file, there are no complaints about duplicate main()s when linking against vl.o. For example, the virtual-device fuzzer uses a main() provided by libfuzzer, and needs to perform some initialization before running the softmmu initialization. Now, main simply calls three vl.c functions which handle the guest initialization, main loop and cleanup. Signed-off-by: Alexander Bulekov --- Makefile | 1 + Makefile.objs | 2 ++ Makefile.target | 2 +- include/sysemu/sysemu.h | 4 ++++ main.c | 53 +++++++++++++++++++++++++++++++++++++++++ vl.c | 38 ++++++++--------------------- 6 files changed, 71 insertions(+), 29 deletions(-) create mode 100644 main.c diff --git a/Makefile b/Makefile index 32bd554480..e6de7a47bb 100644 --- a/Makefile +++ b/Makefile @@ -473,6 +473,7 @@ $(SOFTMMU_ALL_RULES): $(chardev-obj-y) $(SOFTMMU_ALL_RULES): $(crypto-obj-y) $(SOFTMMU_ALL_RULES): $(io-obj-y) $(SOFTMMU_ALL_RULES): config-all-devices.mak +$(SOFTMMU_ALL_RULES): $(softmmu-main-y) ifdef DECOMPRESS_EDK2_BLOBS $(SOFTMMU_ALL_RULES): $(edk2-decompressed) endif diff --git a/Makefile.objs b/Makefile.objs index 7c1e50f9d6..5ab166fed5 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -84,6 +84,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o # qapi common-obj-y += qapi/ + +softmmu-obj-y = main.o endif ####################################################################### diff --git a/Makefile.target b/Makefile.target index 6e61f607b1..8dcf3dddd8 100644 --- a/Makefile.target +++ b/Makefile.target @@ -202,7 +202,7 @@ endif COMMON_LDADDS = ../libqemuutil.a # build either PROG or PROGW -$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS) +$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS) $(softmmu-obj-y) $(call LINK, $(filter-out %.mak, $^)) ifdef CONFIG_DARWIN $(call quiet-command,Rez -append $(SRC_PATH)/pc-bios/qemu.rsrc -o $@,"REZ","$(TARGET_DIR)$@") diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 80c57fdc4e..270df5fa34 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -118,6 +118,10 @@ QemuOpts *qemu_get_machine_opts(void); bool defaults_enabled(void); +void qemu_init(int argc, char **argv, char **envp); +void qemu_main_loop(void); +void qemu_cleanup(void); + extern QemuOptsList qemu_legacy_drive_opts; extern QemuOptsList qemu_common_drive_opts; extern QemuOptsList qemu_drive_opts; diff --git a/main.c b/main.c new file mode 100644 index 0000000000..f10ceda541 --- /dev/null +++ b/main.c @@ -0,0 +1,53 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "sysemu/sysemu.h" + +#ifdef CONFIG_SDL +#if defined(__APPLE__) || defined(main) +#include +int main(int argc, char **argv) +{ + return qemu_main(argc, argv, NULL); +} +#undef main +#define main qemu_main +#endif +#endif /* CONFIG_SDL */ + +#ifdef CONFIG_COCOA +#undef main +#define main qemu_main +#endif /* CONFIG_COCOA */ + +int main(int argc, char **argv, char **envp) +{ + qemu_init(argc, argv, envp); + qemu_main_loop(); + qemu_cleanup(); + + return 0; +} diff --git a/vl.c b/vl.c index 751401214c..132a41ac0f 100644 --- a/vl.c +++ b/vl.c @@ -36,25 +36,6 @@ #include "sysemu/seccomp.h" #include "sysemu/tcg.h" -#ifdef CONFIG_SDL -#if defined(__APPLE__) || defined(main) -#include -int qemu_main(int argc, char **argv, char **envp); -int main(int argc, char **argv) -{ - return qemu_main(argc, argv, NULL); -} -#undef main -#define main qemu_main -#endif -#endif /* CONFIG_SDL */ - -#ifdef CONFIG_COCOA -#undef main -#define main qemu_main -#endif /* CONFIG_COCOA */ - - #include "qemu/error-report.h" #include "qemu/sockets.h" #include "sysemu/accel.h" @@ -1657,7 +1638,7 @@ static bool main_loop_should_exit(void) return false; } -static void main_loop(void) +void qemu_main_loop(void) { #ifdef CONFIG_PROFILER int64_t ti; @@ -2820,7 +2801,7 @@ static void configure_accelerators(const char *progname) } } -int main(int argc, char **argv, char **envp) +void qemu_init(int argc, char **argv, char **envp) { int i; int snapshot, linux_boot; @@ -3372,7 +3353,7 @@ int main(int argc, char **argv, char **envp) case QEMU_OPTION_watchdog: if (watchdog) { error_report("only one watchdog option may be given"); - return 1; + exit(1); } watchdog = optarg; break; @@ -3813,7 +3794,7 @@ int main(int argc, char **argv, char **envp) set_memory_options(&ram_slots, &maxram_size, machine_class); os_daemonize(); - rcu_disable_atfork(); + /* rcu_disable_atfork(); */ if (pid_file && !qemu_write_pidfile(pid_file, &err)) { error_reportf_err(err, "cannot create PID file: "); @@ -4284,7 +4265,7 @@ int main(int argc, char **argv, char **envp) parse_numa_opts(current_machine); /* do monitor/qmp handling at preconfig state if requested */ - main_loop(); + qemu_main_loop(); audio_init_audiodevs(); @@ -4394,7 +4375,7 @@ int main(int argc, char **argv, char **envp) if (vmstate_dump_file) { /* dump and exit */ dump_vmstate_json_to_file(vmstate_dump_file); - return 0; + exit(0); } if (incoming) { @@ -4411,8 +4392,11 @@ int main(int argc, char **argv, char **envp) accel_setup_post(current_machine); os_setup_post(); - main_loop(); + return; +} +void qemu_cleanup(void) +{ gdbserver_cleanup(); /* @@ -4449,6 +4433,4 @@ int main(int argc, char **argv, char **envp) qemu_chr_cleanup(); user_creatable_cleanup(); /* TODO: unref root container, check all devices are ok */ - - return 0; } From patchwork Mon Jan 20 05:54:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341025 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95E5F6C1 for ; Mon, 20 Jan 2020 05:56:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6C1DA2073D for ; Mon, 20 Jan 2020 05:56:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="WeCZdafe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6C1DA2073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ3A-0000Tu-QJ for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 00:56:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35156) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1N-0006lo-8R for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1L-0006F6-Vl for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:45 -0500 Received: from mail-bn7nam10on2090.outbound.protection.outlook.com ([40.107.92.90]:54177 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1L-0006Eg-RS for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:43 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UDIpBl4QvSsqHXScCRpC0vGlwv/WcTjELvK5XNYrsg79vc+0zxs9A9+/hbQDce+xlRcIDbORboOmhwbVvp8V02qiB1gaIyKeIx8FFPLXMSdVeoh9m9Z8ymPa+VBSdmgWs2WP9RuX3I14heT7HEYPIdGoplOXRLMUq0p/M2aoZYSwWJ97TbES1OgcJx7HJiicV1LnBf+cULMKk5G+gScAnZrlTkbVbm0nBU9dgnpf+nkc0xdhP5hILIPW/PDSY0O0md1VBxlVfP3nCMW8kZQatAKa4ZEjwQ3lGJyacDgkYikRLD9DdMLPu5BlQO/BsF7uxirEzZHbctY5P3muiZQrTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t5mnk3e1ZGtlIjME4MaJ9YJ8gCqwJraw8SK866ibAro=; b=BOlMj6wXja/je8Q/E2C/Z7/JmVEicxqwpygqq+wcTjaNoCKZe90U5/WCfeS/1QIxgNAvm01v3q6WyXBsQHhsIr6fSZBly3QrXu7fQ90qfij0nZ8pqgtWwW/zk+fRVkBj3kVC2xV8uUBUQJv4moY50wwaowNmQ725rkHPykxrEo/8pPUfoR3qfxR/n/be8HBXLe89QKFIoKeA2k6ID9U4gwQFMoEN8qJCb1ez1O2KhuZZbNhF3hNn+qt/YmESPvknSMzhDm90EhQEY3FSzri4Upa3M2zHGVAhJ+Kasj235/GqU5Lgf9WxXabx5vDRnBI2bT+d2K3Quzh0zZKzBY3lEg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=t5mnk3e1ZGtlIjME4MaJ9YJ8gCqwJraw8SK866ibAro=; b=WeCZdafeWiyybGvzIWlyV0KUfV4yU+X8WXU8fQ1Vfha2aPMSC8eOceQOFRnN+5kRH1EkFM27NiA9t4Jj2LTO4YeVakmIN02XQpLjBoQNKBw1KV9Yu24SF05y64Wo0UVjdhSyluWSJXZ6t091Jn47SgtzLM3lEOn55X3i19RlBRs= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:42 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:42 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:39 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 02/20] libqos: rename i2c_send and i2c_recv Thread-Topic: [PATCH v7 02/20] libqos: rename i2c_send and i2c_recv Thread-Index: AQHVz1YbXRWJ0H44Rk6okJGziXoYMQ== Date: Mon, 20 Jan 2020 05:54:41 +0000 Message-ID: <20200120055410.22322-3-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0dcd91ff-cb5c-46f8-4e9b-08d79d6d3cfb x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3173; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(6666004)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EGmqM93MchUlH51JXaZ4oGUGIaAuBRtqKAEJcys/DAVVY5/i2FY15Grfsb2ZUR+Vk1QW6xYB9xvyom/R8IZyR38MZz5eqQN5MZD9NmxgQEMFpp4cmZ/1gyIvkrShM3POnU1Lskl/i0dvtnN7gKd17KjZDfBM34zSULg8tEADPreDdvP5hP9b1QdYdPNBy8CZAS0RZokrWEsaEqstl8hoe61qLokuRvaEMDnW/cxuj6nD+04HgyYRTl2lW6qbsuFwsCzYmgt/M5SjcirxZ+PhlAyHJ1sAo4lJufrIbSkPvoQlT96jGtFYh7JmtidlAewNq6WfIFjTBM2qiAyGnZ8KBeArC2h+sKBqOlZe7MIPuu16n1VIGoc6PMjlove8O9MqEUrj6sWr52PpWuaCWoHg75uzCOY3jULnErz7PN05YepG6h7rPpr57sFJSXXq8Dh9 MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 0dcd91ff-cb5c-46f8-4e9b-08d79d6d3cfb X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:41.3953 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: w4VF7MjqiIr72qDqJwfX7iT3c35HuT/qgPcLTlWDtBhDVi0RBO5l5yJuEYoU38JN X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.90 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The names i2c_send and i2c_recv collide with functions defined in hw/i2c/core.c. This causes an error when linking against libqos and softmmu simultaneously (for example when using qtest inproc). Rename the libqos functions to avoid this. Signed-off-by: Alexander Bulekov Acked-by: Thomas Huth Reviewed-by: Stefan Hajnoczi --- tests/qtest/libqos/i2c.c | 10 +++++----- tests/qtest/libqos/i2c.h | 4 ++-- tests/qtest/pca9552-test.c | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/qtest/libqos/i2c.c b/tests/qtest/libqos/i2c.c index 156114e745..38f800dbab 100644 --- a/tests/qtest/libqos/i2c.c +++ b/tests/qtest/libqos/i2c.c @@ -10,12 +10,12 @@ #include "libqos/i2c.h" #include "libqtest.h" -void i2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len) +void qi2c_send(QI2CDevice *i2cdev, const uint8_t *buf, uint16_t len) { i2cdev->bus->send(i2cdev->bus, i2cdev->addr, buf, len); } -void i2c_recv(QI2CDevice *i2cdev, uint8_t *buf, uint16_t len) +void qi2c_recv(QI2CDevice *i2cdev, uint8_t *buf, uint16_t len) { i2cdev->bus->recv(i2cdev->bus, i2cdev->addr, buf, len); } @@ -23,8 +23,8 @@ void i2c_recv(QI2CDevice *i2cdev, uint8_t *buf, uint16_t len) void i2c_read_block(QI2CDevice *i2cdev, uint8_t reg, uint8_t *buf, uint16_t len) { - i2c_send(i2cdev, ®, 1); - i2c_recv(i2cdev, buf, len); + qi2c_send(i2cdev, ®, 1); + qi2c_recv(i2cdev, buf, len); } void i2c_write_block(QI2CDevice *i2cdev, uint8_t reg, @@ -33,7 +33,7 @@ void i2c_write_block(QI2CDevice *i2cdev, uint8_t reg, uint8_t *cmd = g_malloc(len + 1); cmd[0] = reg; memcpy(&cmd[1], buf, len); - i2c_send(i2cdev, cmd, len + 1); + qi2c_send(i2cdev, cmd, len + 1); g_free(cmd); } diff --git a/tests/qtest/libqos/i2c.h b/tests/qtest/libqos/i2c.h index 945b65b34c..c65f087834 100644 --- a/tests/qtest/libqos/i2c.h +++ b/tests/qtest/libqos/i2c.h @@ -47,8 +47,8 @@ struct QI2CDevice { void *i2c_device_create(void *i2c_bus, QGuestAllocator *alloc, void *addr); void add_qi2c_address(QOSGraphEdgeOptions *opts, QI2CAddress *addr); -void i2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len); -void i2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len); +void qi2c_send(QI2CDevice *dev, const uint8_t *buf, uint16_t len); +void qi2c_recv(QI2CDevice *dev, uint8_t *buf, uint16_t len); void i2c_read_block(QI2CDevice *dev, uint8_t reg, uint8_t *buf, uint16_t len); diff --git a/tests/qtest/pca9552-test.c b/tests/qtest/pca9552-test.c index 4b800d3c3e..d80ed93cd3 100644 --- a/tests/qtest/pca9552-test.c +++ b/tests/qtest/pca9552-test.c @@ -32,22 +32,22 @@ static void receive_autoinc(void *obj, void *data, QGuestAllocator *alloc) pca9552_init(i2cdev); - i2c_send(i2cdev, ®, 1); + qi2c_send(i2cdev, ®, 1); /* PCA9552_LS0 */ - i2c_recv(i2cdev, &resp, 1); + qi2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, ==, 0x54); /* PCA9552_LS1 */ - i2c_recv(i2cdev, &resp, 1); + qi2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, ==, 0x55); /* PCA9552_LS2 */ - i2c_recv(i2cdev, &resp, 1); + qi2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, ==, 0x55); /* PCA9552_LS3 */ - i2c_recv(i2cdev, &resp, 1); + qi2c_recv(i2cdev, &resp, 1); g_assert_cmphex(resp, ==, 0x54); } From patchwork Mon Jan 20 05:54:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341037 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D943109A for ; Mon, 20 Jan 2020 06:03:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C3A72073D for ; Mon, 20 Jan 2020 06:03:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="LUS1vhgX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C3A72073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58948 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ9v-0008Bb-C1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:03:35 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35178) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1P-0006ow-Ar for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1N-0006Fx-6b for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:47 -0500 Received: from mail-bn7nam10on2115.outbound.protection.outlook.com ([40.107.92.115]:59757 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1N-0006Fc-2K for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:45 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gNBpxbS7ZrctVDxE81gTX2gMOkZWLn9SSaOSZzA9FRVbT+JytFlTccsBT0ThianycX4LYevoGPi2nnwle2PXiHOT1f3cjiVjePb/qvpGf2OIEpnEICKP3AyEcd34w+kr8F0JyBy8LP3wiWmEgzPeMeIa4FHrtdRAGdUGGdDvXD429Q3SFFHzPsqMxsJUnumyIl4SqMRwXYMjejgUqOJvuz75dynvLSCjfwr31H7dWXOvvTOmnngqKMncM1/BUGOg2kGTf6PZacAr1R6OGs5rnyBowEH+CKwnEtEvOaOSy56b5OCJwM3uSk2/6Z53FLLrigyQCMWMeawsZgLkRklCwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDcyKBGnhfVKL9MV14vCpp1u3vtovcs2UihQKuSPZwg=; b=dBhOgNrjaCELR+YFroUY7uV+T7e0CwqLP4fmTZlKgUCqQFljEv7oMxi8Ke+wS2CyTLwHY7pRDxCtbYeGNLtjBNG8PDDuVg6S2FAYiX4gb7rCbn7LMR0rMfVTFYjdJdkip6Qscc1kezNN/ewaClAIxJaWgt54p1P8OSf8y4+rGfkatDXkbtaPvnoL0ids0iiSdWePgGQh4hSbm8DCbmubPMnstssmec0rqbw74yc1fdw1MWiyk6Wd734cCaT6OMV0ng3hYEe6E47VRmeKvqK1J81fmGjw2qRBLr0LItfq5qillTZNO36K7cEZKum839vgRkWAbxx/1lYSSQBCFW0e0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=sDcyKBGnhfVKL9MV14vCpp1u3vtovcs2UihQKuSPZwg=; b=LUS1vhgXF4ztdBXucAcpDvzDaygEaM9pa1ENtRdWSLN4VCPKTdR0KU/pBQbWOSn2eqhgJG8t11dHnjeqXFVfXX/mlYXcn9H2rGGchalP5oeBMuXfhc4+OsADC7jepLjCP+G8lcHdcvgT6oPUfYhoYKItLwA2+pShIkq4KwkoRTA= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:44 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:44 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:43 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 03/20] fuzz: add FUZZ_TARGET module type Thread-Topic: [PATCH v7 03/20] fuzz: add FUZZ_TARGET module type Thread-Index: AQHVz1YcpvhXbPp/Y0+K3YHEi9Rxiw== Date: Mon, 20 Jan 2020 05:54:43 +0000 Message-ID: <20200120055410.22322-5-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 57aad507-e68a-4680-632b-08d79d6d3f55 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:229; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(4744005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ErgJBw/XTsOxJbI7hTMnC3LcatxN2AW98ot1xohKEa6eYf0s0VjdmsfGg1Arta4GLj3cMQY8iJsC7FKR9aRhOaaWmoWFs2paPe/XuOyuP+Zng4cdi2meoHUu2UAzS5t8XPhzY3+0nT35AoGzASnyd99zRYzJbj+AFG/by49sOsjsezKRLHCKZlsdKHJR1klN+B3PIMUWQvoIjR2DaNN7DrAlT+iwQHMVZixADbnTBimN4MkVmruy7fxfsCoF6kkoG/s//GK5D/WycjEHHfAJE5e3/7hz2bkjEO0Hm5NpqX9IVuxwheDypPZdd33ZY3Eqjinr3Z6tNMy1GAupJApnVQPx1h3Gn/WMHYSnU3Nglp2j63L/u9NTSkquQSPgBg41E9SbRFlbg/bik0evfmVbvGZ5mS/H1DOqqR3mYW9PRAUhu09mRyjpEWiAKdDt7Iyj MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 57aad507-e68a-4680-632b-08d79d6d3f55 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:43.9029 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 3s60BPWYf/bcWq2pMfsSJE1I9gfrpPM56tBSr3ZzWGaTMzOHUC/uzR3QwsIFTRJp X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.115 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , "stefanha@redhat.com" , "Bulekov, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/qemu/module.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/qemu/module.h b/include/qemu/module.h index 65ba596e46..684753d808 100644 --- a/include/qemu/module.h +++ b/include/qemu/module.h @@ -46,6 +46,7 @@ typedef enum { MODULE_INIT_TRACE, MODULE_INIT_XEN_BACKEND, MODULE_INIT_LIBQOS, + MODULE_INIT_FUZZ_TARGET, MODULE_INIT_MAX } module_init_type; @@ -56,7 +57,8 @@ typedef enum { #define xen_backend_init(function) module_init(function, \ MODULE_INIT_XEN_BACKEND) #define libqos_init(function) module_init(function, MODULE_INIT_LIBQOS) - +#define fuzz_target_init(function) module_init(function, \ + MODULE_INIT_FUZZ_TARGET) #define block_module_load_one(lib) module_load_one("block-", lib) #define ui_module_load_one(lib) module_load_one("ui-", lib) #define audio_module_load_one(lib) module_load_one("audio-", lib) From patchwork Mon Jan 20 05:54:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341023 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D53EA188B for ; Mon, 20 Jan 2020 05:56:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A60D22073D for ; Mon, 20 Jan 2020 05:56:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="x96VEo9E" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A60D22073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58876 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ3A-0000T6-GT for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 00:56:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35182) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1P-0006pT-KM for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1O-0006IC-Fp for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:47 -0500 Received: from mail-bn7nam10on2110.outbound.protection.outlook.com ([40.107.92.110]:23840 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1O-0006Gh-Ae for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:46 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DCeSI3rXWPLC8/PicHQRvM2HzPjlz0WlEF541nmzfl1XlXO9zCVxRi9AvNkCds9/3plGFhOz1vxRo7wZv2tNqoGJIFK/5TB6OKk0Y+Xr9hf0u7PdoU0GqyKhNIVNJM2grGx655LGASvn/vY5NRYysfpn3zzIZPXm76gEMza53MLSma8lq2gt3Nuns6OxkFafCQ39PgLT38XHd1XugscuycyKq9Ee6KygV+G4LYXqSH1Q/fw1a5uzo4rpgL1NdDUIBYDISfq4y6DhXFLU/Ibt8rXUAzv4HP4mxW1wO0AMjDPRHwTv3+APFusPBQyN1cn7hASFGxJopkR10amSMHOxVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZKcOoJCL17pZWw8iaVvIqTC73gmiBUaK4eT5muvua7g=; b=mxrWVcp6ysq2hxpsStavM3UBU/Ld/xeWppJC9KFuMTFkjeBgRwQZADHjZWg9iDYAR+xmwUBj87VzcPPeQdLZIDwMfbXmOdnOIBoDSZ1ER7ViWE3y6vg7lOVh3ZwaZ0JLt75/ko8RHt5ed3psVy/mbeWVvY7FB8Qpul9LrsgVPpVi1WpojXLfm8NUlPxMwCKWNO/F7X5m59f26TAXFtWJH+Z/8YQbmT8cJUO7gdN5NfVQB1J/iZltJGRS3gAsBgYhB6Cm4X5SXCW4V6ZtgxjpbubyjfgSrPvhC3c8wP+IoDyg4fgQXE6nTP2EQvqq92nQ6weaZ+Z4bFJcu6Spee9QqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ZKcOoJCL17pZWw8iaVvIqTC73gmiBUaK4eT5muvua7g=; b=x96VEo9Er0IXWCLqFjFS4DcfLEb9Wpc2baQ3wRbivaG5x71ecMA9H3tA45rhQ2X1KS7G6g13CwerW68Fm7oLHeYKuFrb4wSlQHW/Ph3z0jPBhTLGLJE7lBBDwAZDb/mO8l5HltqY2isBVzqBvG1JwuXbcejp/KiKWpEUq+J1Bhw= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:45 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:45 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:44 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 04/20] qtest: add qtest_server_send abstraction Thread-Topic: [PATCH v7 04/20] qtest: add qtest_server_send abstraction Thread-Index: AQHVz1YdkBRcp/nvekGe+H+4f1sQyg== Date: Mon, 20 Jan 2020 05:54:45 +0000 Message-ID: <20200120055410.22322-6-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: c0af5f6b-a531-4a69-a917-08d79d6d4010 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7691; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bxfh8wO6frw/oVbZkEu3yjqGAjUa/Hy1EbiFD/tv5mXjjfyFekNs6TzuaB9kcEMulR6+wTo6QofYmE+obDyJrv6zg+327LTWYyDnYq2l+euJKaPuS6t1NPMWBoTqb1eAv7kkYrleyllbllvyNRlfMJNeMSaFDMOCC9BhT4+fyHhwYZ3kN5m3G0cwoDZuQ7GDE6CvhiG0KWWgS6jEoPWV+04HgSnmgA6itDTrCUcVqOOMnTk+2hYqI3dTTCzFjnREd6lHFn8KIShR9GJrm3YcOVkcavPZjb17cZDpE0rB1ejo1SggB/U9OxJdkbKZHAAszp/EGPxP/fbSmoMmFCwDZXg6+g5KD4lVkBrOxUOtT7m9RXrPlhk4eNCbETBuS7odd8tc16JYkFpoox20O35i9ZrxV+Fgu9q1/E3++6u5pRhJIsiDEVXBBRZhH5UbPnAt MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: c0af5f6b-a531-4a69-a917-08d79d6d4010 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:45.1872 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: VxW6CNDIOYogVsRl453OzGE6VCFHIRSff8u195CP2q6wPSkWMhK9irHjJi7GCU6Y X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.110 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" qtest_server_send is a function pointer specifying the handler used to transmit data to the qtest client. In the standard configuration, this calls the CharBackend handler, but now it is possible for other types of handlers, e.g direct-function calls if the qtest client and server exist within the same process (inproc) Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Acked-by: Thomas Huth --- include/sysemu/qtest.h | 3 +++ qtest.c | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index 5ed09c80b1..e2f1047fd7 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -26,4 +26,7 @@ bool qtest_driver(void); void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **errp); +void qtest_server_set_send_handler(void (*send)(void *, const char *), + void *opaque); + #endif diff --git a/qtest.c b/qtest.c index 12432f99cf..938c3746d6 100644 --- a/qtest.c +++ b/qtest.c @@ -42,6 +42,8 @@ static GString *inbuf; static int irq_levels[MAX_IRQ]; static qemu_timeval start_time; static bool qtest_opened; +static void (*qtest_server_send)(void*, const char*); +static void *qtest_server_send_opaque; #define FMT_timeval "%ld.%06ld" @@ -228,8 +230,10 @@ static void GCC_FMT_ATTR(1, 2) qtest_log_send(const char *fmt, ...) va_end(ap); } -static void do_qtest_send(CharBackend *chr, const char *str, size_t len) +static void qtest_server_char_be_send(void *opaque, const char *str) { + size_t len = strlen(str); + CharBackend* chr = (CharBackend *)opaque; qemu_chr_fe_write_all(chr, (uint8_t *)str, len); if (qtest_log_fp && qtest_opened) { fprintf(qtest_log_fp, "%s", str); @@ -238,7 +242,7 @@ static void do_qtest_send(CharBackend *chr, const char *str, size_t len) static void qtest_send(CharBackend *chr, const char *str) { - do_qtest_send(chr, str, strlen(str)); + qtest_server_send(qtest_server_send_opaque, str); } static void GCC_FMT_ATTR(2, 3) qtest_sendf(CharBackend *chr, @@ -783,6 +787,16 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** qemu_chr_fe_set_echo(&qtest_chr, true); inbuf = g_string_new(""); + + if (!qtest_server_send) { + qtest_server_set_send_handler(qtest_server_char_be_send, &qtest_chr); + } +} + +void qtest_server_set_send_handler(void (*send)(void*, const char*), void *opaque) +{ + qtest_server_send = send; + qtest_server_send_opaque = opaque; } bool qtest_driver(void) From patchwork Mon Jan 20 05:54:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341055 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 443F4924 for ; Mon, 20 Jan 2020 06:10:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 194C72073A for ; Mon, 20 Jan 2020 06:10:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="69X/tkJ4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 194C72073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQGA-0007IP-B3 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:10:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35206) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1S-0006ta-8e for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1P-0006J9-DZ for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:50 -0500 Received: from mail-bn7nam10on2120.outbound.protection.outlook.com ([40.107.92.120]:10600 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1P-0006IL-9B for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dOhVUCNv0/8m1E9dhWYmm6fLFlKm+gnGFhUhgR2bQbLYjQOrEfAjpo/44w4hY6E24u/0Gy3+7T8hIpP9Fm/rXgHr1HaExkBdxLzQqf8sNKmcj+nr9jisU0biJiF1Sxb3Y8/QCpZm0Ov9lFm/99G1ma8bH5DH40kae2JEDY5N6N4hTnnmhPINu/eVmrSSct7D+Lo9mL/piddM2igNt07mEK9+t8EeFJSAbsJ+9ThtmdXN7m/yXGZauMlC8h2LNqkc710aaTl/P1x0R09ic9QRXj6hHa08481n6sDkc/QzAk7GTqNpKss8RnpEJS8mvEFTAlZmcyiX65rm8FBcQMKDXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6/nC58PkrV1BS/kZeyEjMo6kMm9lskCxHO6QiHS9JfI=; b=NDgWqAniJtEDHwGlMbeAprdduULH1wux0gT5hKonKrlf6OCo8GFeU6t43U5l1lzsz7nwXKTq9YwNopXwOOGILpZhY/4qK/rmJOfg2SOYLYtubr7OBZKS9OCM3lFJ/8HiNuYisoxB0NNcMjEgyHOHpDhCXn5lxGh8cqivrtSSlZEzax0vb6J8/jQDw/28aDfuqzwh4rp5OAymGUJlVX7kd0wGmsauu7tfbFx7S+sG59jGc9QMYeQiafumqhBieirUMhWgwJWwFeM4khI3kJzKASkP+jmFURyiVRcWOxzcLYCAcLvNiTG7jco9f3RufhARtPlskCXF/tUADhfkVbyH5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6/nC58PkrV1BS/kZeyEjMo6kMm9lskCxHO6QiHS9JfI=; b=69X/tkJ4eKaSBSdZWVskjPNPeDEpVK/+4KNWcPRqZOibfz5cmUfZ/5tfTx1/6EUumGLGVR2def7cOIkNOZeU0KRbqpxZ1oeYtbHZWE6HfR1HLyJeQ0932Gr41wVxrWHado2/UEzK9ITTTlMmWwL4wCmFboFpQLbfGOrXQr9H0gw= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:46 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:46 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:45 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 05/20] libqtest: add a layer of abstraction to send/recv Thread-Topic: [PATCH v7 05/20] libqtest: add a layer of abstraction to send/recv Thread-Index: AQHVz1YeeZwutwWwZUK2NRbndcImpw== Date: Mon, 20 Jan 2020 05:54:45 +0000 Message-ID: <20200120055410.22322-7-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 52fa0906-cf65-484f-ec5c-08d79d6d40b2 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:268; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: wUpEstNb3IbF5eMIa5Y0KsXaj4pZsU9W7d1gUEGr8+Qw4E8nfl8gpts3UBEvsFdJsrhpkW9xxDuYPDyppL62gnt4D9ouU5qvQqld2JmsHKQjbxwJgFX+N8IbcbHbS8HeLc/R9GM1CfS1y/oFa2QtnY6K/PEZaK8+aPFF5QuuNOtsA4dWKHN0KPVADPmMRzfcn2bSCL6IDBqwUqSfHtgm64SSuCFQEJa/8p1fM1x5BdKs8S81BltbHNMQts+T+zXWjZgBMum46pwuWny/jjlQWhpUAkasPy3037molhI+ARAS2mjd+9CKQT7j+njPh8DI1D1iElaCfiEfe6Pu+S6gsGvVTxzyn+T/nNsDVfjFKhVkEQziFQRsTo4iLiP8xMFMAA9LUPcUHHM+f017WvpO06rFrpjsE71YGha1yCuX9mGmEvrCATH9amxx5v0HUyZS MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 52fa0906-cf65-484f-ec5c-08d79d6d40b2 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:46.0637 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: zAsgqfje7xsoO6bE9BDISNqbH12HcGTdzqBMuF0IINJk8ldXCab2VqIHbwAdNw9n X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This makes it simple to swap the transport functions for qtest commands to and from the qtest client. For example, now it is possible to directly pass qtest commands to a server handler that exists within the same process, without the standard way of writing to a file descriptor. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/libqtest.c | 48 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 76c9f8eade..e5056a1d0f 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -35,6 +35,15 @@ #define SOCKET_TIMEOUT 50 #define SOCKET_MAX_FDS 16 + +typedef void (*QTestSendFn)(QTestState *s, const char *buf); +typedef GString* (*QTestRecvFn)(QTestState *); + +typedef struct QTestClientTransportOps { + QTestSendFn send; /* for sending qtest commands */ + QTestRecvFn recv_line; /* for receiving qtest command responses */ +} QTestTransportOps; + struct QTestState { int fd; @@ -45,6 +54,7 @@ struct QTestState bool big_endian; bool irq_level[MAX_IRQ]; GString *rx; + QTestTransportOps ops; }; static GHookList abrt_hooks; @@ -52,6 +62,14 @@ static struct sigaction sigact_old; static int qtest_query_target_endianness(QTestState *s); +static void qtest_client_socket_send(QTestState*, const char *buf); +static void socket_send(int fd, const char *buf, size_t size); + +static GString *qtest_client_socket_recv_line(QTestState *); + +static void qtest_client_set_tx_handler(QTestState *s, QTestSendFn send); +static void qtest_client_set_rx_handler(QTestState *s, QTestRecvFn recv); + static int init_socket(const char *socket_path) { struct sockaddr_un addr; @@ -234,6 +252,9 @@ QTestState *qtest_init_without_qmp_handshake(const char *extra_args) sock = init_socket(socket_path); qmpsock = init_socket(qmp_socket_path); + qtest_client_set_rx_handler(s, qtest_client_socket_recv_line); + qtest_client_set_tx_handler(s, qtest_client_socket_send); + qtest_add_abrt_handler(kill_qemu_hook_func, s); command = g_strdup_printf("exec %s " @@ -379,13 +400,9 @@ static void socket_send(int fd, const char *buf, size_t size) } } -static void socket_sendf(int fd, const char *fmt, va_list ap) +static void qtest_client_socket_send(QTestState *s, const char *buf) { - gchar *str = g_strdup_vprintf(fmt, ap); - size_t size = strlen(str); - - socket_send(fd, str, size); - g_free(str); + socket_send(s->fd, buf, strlen(buf)); } static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) @@ -393,8 +410,11 @@ static void GCC_FMT_ATTR(2, 3) qtest_sendf(QTestState *s, const char *fmt, ...) va_list ap; va_start(ap, fmt); - socket_sendf(s->fd, fmt, ap); + gchar *str = g_strdup_vprintf(fmt, ap); va_end(ap); + + s->ops.send(s, str); + g_free(str); } /* Sends a message and file descriptors to the socket. @@ -431,7 +451,7 @@ static void socket_send_fds(int socket_fd, int *fds, size_t fds_num, g_assert_cmpint(ret, >, 0); } -static GString *qtest_recv_line(QTestState *s) +static GString *qtest_client_socket_recv_line(QTestState *s) { GString *line; size_t offset; @@ -468,7 +488,7 @@ static gchar **qtest_rsp(QTestState *s, int expected_args) int i; redo: - line = qtest_recv_line(s); + line = s->ops.recv_line(s); words = g_strsplit(line->str, " ", 0); g_string_free(line, TRUE); @@ -1337,3 +1357,13 @@ void qmp_assert_error_class(QDict *rsp, const char *class) qobject_unref(rsp); } + +static void qtest_client_set_tx_handler(QTestState *s, + QTestSendFn send) +{ + s->ops.send = send; +} +static void qtest_client_set_rx_handler(QTestState *s, QTestRecvFn recv) +{ + s->ops.recv_line = recv; +} From patchwork Mon Jan 20 05:54:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341031 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 19CB713A4 for ; Mon, 20 Jan 2020 05:59:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E3F582073D for ; Mon, 20 Jan 2020 05:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="ByAs60aC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E3F582073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ6C-0004SH-B1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 00:59:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35224) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1T-0006vQ-HD for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1R-0006Ku-Nv for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:51 -0500 Received: from mail-bn7nam10on2111.outbound.protection.outlook.com ([40.107.92.111]:52129 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1R-0006Ke-KN for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:49 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UajoMDR0z0s+gIx0Difv6eGqE+d7LwvuYVy2N3L1da2nV1P7o2XzegcJQay+UTVKKTwHnoIsdXFDrtm607nCI7jXO8R7PHikryTsgm3QejbQB+jQdjQ8p51imaVHJdQ6K282fkkMmnitsug3WafWdCA+x/eOws5jIGXAG62HL/vutc6jufw57ediBI5/mnEhVxUDnXQFOoIJyyJQOj48MCVi+AQ9jZApn0vuY0VMKBoS3+JcmcVipigcUZwboHD4wB8A1x5DGCk6xEItL80bOTi14oDUXll/uMJgv8AhSwxV4TwMTgLPSNFaB1JjTLTHCVk2SorfEaOlFamQkUhNoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ns3uR7r40f3Hn5it1jv0Pcc2ZA1fNyAHsn2M9Jhx4kw=; b=cXOrHCC0aGCiCh5DbAFen5Pe61D3WKAzlMu4Xle9XVqR2JCELef30KQ73Suwy/1yp2JzwMaB90rs9GBLDdPWrmrNign5ZgZ2hPyghPDXQP6EJiOAX+AkjtOtcZXbGL3fvKVaUANiI3YxnB1ZIiQbSeoYzgks+hYcluH2Lc445oKq5u/UU5TW2cNU4psIvVrB1a/Rc+LaZwnsuGxyJos2XzZKZXnPJ5p+Hd7xVJq0Paa5/0l7QULxKna2SYqGYUHzmdF/+dNO1pkaWeCZ1b4ZNZE2z1s3t5AQX79zRbNXO76Tg3SeOZqVQ3rl/KhQ6OY2XTvfBdpKteZT1I8kNKTjzQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ns3uR7r40f3Hn5it1jv0Pcc2ZA1fNyAHsn2M9Jhx4kw=; b=ByAs60aCEqoN62BOOKTI58V9R9vNatVhdg9zWQlyp22anTalupYB/7UIARozHbRvgqWhmmsqIJH599APVZlvwy4uy5KRAmj+2kFva7V7H3tcekWoeVO/Iwyz3AXKucZB9Fn3mrocJ14W20wBBxCwwuj2pqWVHZxAfJoWwONR508= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:48 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:48 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:47 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 06/20] module: check module wasn't already initialized Thread-Topic: [PATCH v7 06/20] module: check module wasn't already initialized Thread-Index: AQHVz1YfW+Qp8n0VzEqKKJ29h5/4EA== Date: Mon, 20 Jan 2020 05:54:48 +0000 Message-ID: <20200120055410.22322-9-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ba4366fa-c1c1-4608-fef6-08d79d6d41e4 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4303; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: RwmlOT5KGh9QR0oFE6rfZVBVw4K3qv5SRIZtZ3rwVhhKNsz59w6ybno9YEE0rTjxs3uLcY6JyA+rElN5mgbj6Q6JshUdI0ZxS7Uv5aoPBg+LZ1gOUkLTZk0CiydQwhnf4fjjWTXffFYIPCH9/F6DPUVljGl+c0Wibfy15VWC1ORP2j+RdITWFBdlSm1SUkxQD3hKI5FnSEA4IjMSXwm5ZwRUCRZsXWowvK6AzsE480CZoGms30VwIxPNgC6HBuorhxfqfuNkQbzNs1RUaCo/mP2sMVuuoAVY7Dgy/kbuCXDfBiWPnoVRGCfpBQMyI7tP0WvNd2j5E0ZsGKSJA+e2AfsY/Zak4BLdjH+wPcD0mb0Y9SRNbeIsXGtusyD+kEq/n967uiQLzCPvMZd0wnUETaNdWGcED95LZ5TDYfJIT+o0zoOZ2I8rviDRqqD5csZh Content-ID: <567CC6D7B947CD40A75121299F6039B1@namprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: ba4366fa-c1c1-4608-fef6-08d79d6d41e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:48.0766 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5PGYoxb8wQ8ad23VHmisfqg51pq6R7t3NLsfvQxj3xE8+OvDTOaRNhUGN3ERSn/0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.111 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Bulekov, Alexander" , Darren Kenny , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The virtual-device fuzzer must initialize QOM, prior to running vl:qemu_init, so that it can use the qos_graph to identify the arguments required to initialize a guest for libqos-assisted fuzzing. This change prevents errors when vl:qemu_init tries to (re)initialize the previously initialized QOM module. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Darren Kenny Reviewed-by: Philippe Mathieu-Daudé --- util/module.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/module.c b/util/module.c index 8c5315a7a3..236a7bb52a 100644 --- a/util/module.c +++ b/util/module.c @@ -30,6 +30,7 @@ typedef struct ModuleEntry typedef QTAILQ_HEAD(, ModuleEntry) ModuleTypeList; static ModuleTypeList init_type_list[MODULE_INIT_MAX]; +static bool modules_init_done[MODULE_INIT_MAX]; static ModuleTypeList dso_init_list; @@ -91,11 +92,17 @@ void module_call_init(module_init_type type) ModuleTypeList *l; ModuleEntry *e; + if (modules_init_done[type]) { + return; + } + l = find_type(type); QTAILQ_FOREACH(e, l, node) { e->init(); } + + modules_init_done[type] = true; } #ifdef CONFIG_MODULES From patchwork Mon Jan 20 05:54:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E5A617EA for ; Mon, 20 Jan 2020 06:12:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 346492073A for ; Mon, 20 Jan 2020 06:12:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="QQuFAISV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 346492073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59112 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQIr-0002rI-Rm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:12:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35227) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1T-0006vg-NH for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1S-0006Lc-JT for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:51 -0500 Received: from mail-bn7nam10on2100.outbound.protection.outlook.com ([40.107.92.100]:50976 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1S-0006LJ-Ek for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:50 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bXu0FDJyTyX914mp4wG1TUX+ZrrUO7FUAB37fk0SzRfz+JH5LvgUxWweWyIlSp5kVjUkvY0CgQAI7WZl5q/ZLF0UvwJyvyLdDuWI5Hju2KnJfQEABuWGWFMdBexMX2qOi0kQHBiUcO0uBh1aS38L8SywUWRZ1Prtm00F1weqvNdV0gYnyZcXeQ6Vw2OQ297Zguv5lp0V9ZRBSbxPJrmhH5jNb5ZJt3FMUcxQE0IuVS3EfkQYKtYRupTbI/GjmAdkzFNyzn9RtFiqip/mCPVblNIeugvhixc3CLWINZQGdxNFdHm+KHppfOb+ylwFdIc8XF4j5ProKeGj2ktg5ovJhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9pyU+EWwWoz7a+tVKk2F3sx5oHPPmQUWy8kzp3v+g28=; b=c+MuDu8wPvu9ciEbAIb9fe//4mDx/uuKq1VUAPxfUTl8hWgwjv6gUd3saaWbRDt74XrtjfsypOihlAi9l/YxaP3r2OfjGHErCipJO1f6DE/En0WLDlqjHadiQkXo75SGkxevC4LWW6c5HuG2ysRKsZYo97tvslz1L7TrT7DMXxHBV68ycokWmvnl2HDEB/zQ6m3dtqiaiJ+QHglq81jg73e6eMQanx4uzu0o/uUFGoQDuyy22ifEnhvqwGwDK/EXHeN1L1f6VDZKGvnzrVCx8k4C9eq7yayF1RYNDYLqF24N71BBcCJee1fBOCAh2XdsSv8dF0vW4DS/x3aShZMaSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9pyU+EWwWoz7a+tVKk2F3sx5oHPPmQUWy8kzp3v+g28=; b=QQuFAISVCmnAaKk/4H0/jCB8E+EU5wKz1X4EsbMA6mLKRZXdS/Il2k8+xsgk5gxIoy0M7XGfNggaKuHFsBRkC6lYIHP4VCrIpAS75LbDTDW42TsCIQW7ArbwXCFkZnkfhiRr0OvSoKV0iZ20C0P7/Nr8sdlUxSxW6t4RKNPSB68= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:49 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:49 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:48 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 07/20] qtest: add in-process incoming command handler Thread-Topic: [PATCH v7 07/20] qtest: add in-process incoming command handler Thread-Index: AQHVz1YgoQju/shf0UaMzvpGLh31iw== Date: Mon, 20 Jan 2020 05:54:49 +0000 Message-ID: <20200120055410.22322-10-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 3655422b-51b4-400d-3228-08d79d6d4274 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1824; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: xzafJe02tG9xcDredDAM1GSDYwafJXE3yA/E9YcTrr6M4hKr/Qkps1EsMZhokxh+VB6FpTRu2Xz44lKjK4mf9xrpXhY+5LBGjYFqROFlI/DUIvNghnUxkhrGHAuJYxfn17NGwVpM8iG5aT0MCR6WfoS3lJF3a+JQm/h5CAMAvkr8tW+5dcPCp8SP0TeA7xYLql3cDH0RJMbG5judkDcgeCJ3DORddVSoLjfqhDv8s+uH4uZyuq9DUQeUYNecrrFgNjX3dJ6dYI4gNQV1XavxF/JOToRheXcFtHBlz7q9BqhJiIl994l+n3drXEu8IGxoNFp5cuuG+knXnMvOnBRE9p9t7c03i/Y00BqDM71Gw/FneNPSdLCOlXW/3bOEps2hawZvQZBEYAQa9PmovcuSQmQZidQjNDbawp+h7IweUMnLiWWesRLSm5VAfaH3qrau MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 3655422b-51b4-400d-3228-08d79d6d4274 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:49.0100 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: JkuWTMVLwgQrx6LgECgE2a6Sj1atFDzJ1EY2amF68bz6kznndtRhO9GfINLqWUyk X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.100 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The handler allows a qtest client to send commands to the server by directly calling a function, rather than using a file/CharBackend Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- include/sysemu/qtest.h | 1 + qtest.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h index e2f1047fd7..eedd3664f0 100644 --- a/include/sysemu/qtest.h +++ b/include/sysemu/qtest.h @@ -28,5 +28,6 @@ void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error ** void qtest_server_set_send_handler(void (*send)(void *, const char *), void *opaque); +void qtest_server_inproc_recv(void *opaque, const char *buf); #endif diff --git a/qtest.c b/qtest.c index 938c3746d6..ad6eb6a526 100644 --- a/qtest.c +++ b/qtest.c @@ -803,3 +803,16 @@ bool qtest_driver(void) { return qtest_chr.chr != NULL; } + +void qtest_server_inproc_recv(void *dummy, const char *buf) +{ + static GString *gstr; + if (!gstr) { + gstr = g_string_new(NULL); + } + g_string_append(gstr, buf); + if (gstr->str[gstr->len - 1] == '\n') { + qtest_process_inbuf(NULL, gstr); + g_string_truncate(gstr, 0); + } +} From patchwork Mon Jan 20 05:54:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341033 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 196CB924 for ; Mon, 20 Jan 2020 05:59:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D31712073D for ; Mon, 20 Jan 2020 05:59:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="LfEqZIzo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D31712073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ6F-0004Wt-Aw for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 00:59:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35264) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1X-000732-Mh for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1W-0006Ng-68 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:55 -0500 Received: from mail-bn7nam10on2126.outbound.protection.outlook.com ([40.107.92.126]:17071 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1W-0006NK-1i for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:54 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZRXm82yreJnXCIHCSaIFxcRSpdlz9PTO2Cih8JceEZjTGk7Ck5Zmynov7hng6n6W97fQQBVpathX/YSgGWrY/ZtYSDmesuna80Ah7nFXWZdQAOqwDgQ+T+okLU8DSixYeKBHnVxBqoggU9FK9FzLF4FlyJWnfZy9+BreFn+P4S1NRDS5ihyNUOJkaZZwT+GgAhzW3fZV9lHGRfMytIri2gMAJNbMYd9AuWDoQl7ViwXEiU74AhEWNOjzOc+ghZ+B8in1Ka5+O8UC/1oO4MHC7ETP0QiCORIt5aPqzOcXlzhSVEC8BjuR7HsZKOfb5YR/bnNmk8ejS/DG1RszxxRVdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BMCyJN3nzC2ixzb7DkXR5cQ3SesaeOMGZjfVp8Oc6oQ=; b=iKXDiuTWD096P1dARlL0VAXzLkQUgpk776vKp1DXJF7fltHH3Oz4P4dw4SOU+3DuQa9yFIFpLO66+gQY5+AFuyOFx7P+SspDrFX3VFpnc12I0kfTLxf+vX62taTPYgkoFCn08fpfWDn7l+TgdDhHQMewKz3PVPPPGM0PQ+d9mjeC1DYnxQSIVIJ92+lEXE95bQZs2cYNLQwUzgJzr+5n63OOYeziKC8LyNQuBEcQLMzFxcZwcUDD85lueO59QjHrrEvfYfSuSVr2OvB+/skHtZGnv3GyxDXUCKyVSj+RZo/EuXkjQYLJiySZVTAFFjYVY5oDcR6F5zB0DJxjR+iYGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BMCyJN3nzC2ixzb7DkXR5cQ3SesaeOMGZjfVp8Oc6oQ=; b=LfEqZIzoeiIt3dQWcU4T3MTFKsFm0rHKZSaYKNUgtePJqVuHZiPlHXY4kmSevJHsWpUq8Er1jlusOMIdPyTm2RpEsiMrd1MlZhYKpZu+i1hjsD0lY9LMms43ouoRZ+OgV4sVXddJtQreP8aYU5M3eVT3I6OX/YX8qxTR3w8toVA= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:52 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:52 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:51 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 08/20] libqos: split qos-test and libqos makefile vars Thread-Topic: [PATCH v7 08/20] libqos: split qos-test and libqos makefile vars Thread-Index: AQHVz1YhFzIEa01c/EuPWo3PhXfTOQ== Date: Mon, 20 Jan 2020 05:54:52 +0000 Message-ID: <20200120055410.22322-12-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fb26aac4-7ac7-4213-255d-08d79d6d4437 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2958; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: KVEWfeWYRYZXlJ0cmMvrBnsTcKuZPHEAmK6JZ2Yu1j9bLubkyH4Zv0G2O/0qkDV27qt353nxnVa6w31eMvh78w79uHKhqXECwAAmEMeZsQULTPuiZ3++Lc8WhrlSQYr4Brv7eKUSsr9YjKdaGoOO9y/bT48exy8jEi4xXHoaASqhanNCkTLdJL3s8YvycEhImWWmH9uqJBhTTN6CapKGQNUyeI+bELR4QyWCpYg7BxuZ9J85Hvbbp4UzWucBrrje3QifKWkmNXUvmKO6vg1m//WEJXL1e9N9Fhi6MClSahvlgF6XGagf/9dUKI/At/WzkZ8G4mqZi7MwQUqsC5SoHCqTLr2h1aMbI99/xUKiKuowDZ47pv6tnne10lZ5IFvqeXrOk1UhoRqzROaIQpUj7MimiUUzsk4SBFMPy3BNb6UjNlUflTwsqoUUu4VUZ1Wc Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: fb26aac4-7ac7-4213-255d-08d79d6d4437 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:52.3312 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kMIyCOEONBtM48cTV3CLjzwz2VLBbu3s2AgXA5sl5AG90xi/d9TuKYC1XduDpPTC X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.126 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , Darren Kenny , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Most qos-related objects were specified in the qos-test-obj-y variable. qos-test-obj-y also included qos-test.o which defines a main(). This made it difficult to repurpose qos-test-obj-y to link anything beside tests/qos-test against libqos. This change separates objects that are libqos-specific and ones that are qos-test specific into different variables. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/Makefile.include | 71 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index e6bb4ab28c..08a48c1252 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -157,52 +157,53 @@ check-qtest-s390x-y += migration-test # libqos / qgraph : libqgraph-obj-y = tests/qtest/libqos/qgraph.o -libqos-obj-y = $(libqgraph-obj-y) tests/qtest/libqos/pci.o tests/qtest/libqos/fw_cfg.o -libqos-obj-y += tests/qtest/libqos/malloc.o -libqos-obj-y += tests/qtest/libqos/libqos.o -libqos-spapr-obj-y = $(libqos-obj-y) tests/qtest/libqos/malloc-spapr.o +libqos-core-obj-y = $(libqgraph-obj-y) tests/qtest/libqos/pci.o tests/qtest/libqos/fw_cfg.o +libqos-core-obj-y += tests/qtest/libqos/malloc.o +libqos-core-obj-y += tests/qtest/libqos/libqos.o +libqos-spapr-obj-y = $(libqos-core-obj-y) tests/qtest/libqos/malloc-spapr.o libqos-spapr-obj-y += tests/qtest/libqos/libqos-spapr.o libqos-spapr-obj-y += tests/qtest/libqos/rtas.o libqos-spapr-obj-y += tests/qtest/libqos/pci-spapr.o -libqos-pc-obj-y = $(libqos-obj-y) tests/qtest/libqos/pci-pc.o +libqos-pc-obj-y = $(libqos-core-obj-y) tests/qtest/libqos/pci-pc.o libqos-pc-obj-y += tests/qtest/libqos/malloc-pc.o tests/qtest/libqos/libqos-pc.o libqos-pc-obj-y += tests/qtest/libqos/ahci.o libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/qtest/libqos/usb.o # qos devices: -qos-test-obj-y = tests/qtest/qos-test.o $(libqgraph-obj-y) -qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) -qos-test-obj-y += tests/qtest/libqos/e1000e.o -qos-test-obj-y += tests/qtest/libqos/i2c.o -qos-test-obj-y += tests/qtest/libqos/i2c-imx.o -qos-test-obj-y += tests/qtest/libqos/i2c-omap.o -qos-test-obj-y += tests/qtest/libqos/sdhci.o -qos-test-obj-y += tests/qtest/libqos/tpci200.o -qos-test-obj-y += tests/qtest/libqos/virtio.o -qos-test-obj-$(CONFIG_VIRTFS) += tests/qtest/libqos/virtio-9p.o -qos-test-obj-y += tests/qtest/libqos/virtio-balloon.o -qos-test-obj-y += tests/qtest/libqos/virtio-blk.o -qos-test-obj-y += tests/qtest/libqos/virtio-mmio.o -qos-test-obj-y += tests/qtest/libqos/virtio-net.o -qos-test-obj-y += tests/qtest/libqos/virtio-pci.o -qos-test-obj-y += tests/qtest/libqos/virtio-pci-modern.o -qos-test-obj-y += tests/qtest/libqos/virtio-rng.o -qos-test-obj-y += tests/qtest/libqos/virtio-scsi.o -qos-test-obj-y += tests/qtest/libqos/virtio-serial.o +libqos-obj-y = $(libqgraph-obj-y) +libqos-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) +libqos-obj-y += tests/qtest/libqos/e1000e.o +libqos-obj-y += tests/qtest/libqos/i2c.o +libqos-obj-y += tests/qtest/libqos/i2c-imx.o +libqos-obj-y += tests/qtest/libqos/i2c-omap.o +libqos-obj-y += tests/qtest/libqos/sdhci.o +libqos-obj-y += tests/qtest/libqos/tpci200.o +libqos-obj-y += tests/qtest/libqos/virtio.o +libqos-obj-$(CONFIG_VIRTFS) += tests/qtest/libqos/virtio-9p.o +libqos-obj-y += tests/qtest/libqos/virtio-balloon.o +libqos-obj-y += tests/qtest/libqos/virtio-blk.o +libqos-obj-y += tests/qtest/libqos/virtio-mmio.o +libqos-obj-y += tests/qtest/libqos/virtio-net.o +libqos-obj-y += tests/qtest/libqos/virtio-pci.o +libqos-obj-y += tests/qtest/libqos/virtio-pci-modern.o +libqos-obj-y += tests/qtest/libqos/virtio-rng.o +libqos-obj-y += tests/qtest/libqos/virtio-scsi.o +libqos-obj-y += tests/qtest/libqos/virtio-serial.o # qos machines: -qos-test-obj-y += tests/qtest/libqos/aarch64-xlnx-zcu102-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-imx25-pdk-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-n800-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-raspi2-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-sabrelite-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-smdkc210-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-virt-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-xilinx-zynq-a9-machine.o -qos-test-obj-y += tests/qtest/libqos/ppc64_pseries-machine.o -qos-test-obj-y += tests/qtest/libqos/x86_64_pc-machine.o +libqos-obj-y += tests/qtest/libqos/aarch64-xlnx-zcu102-machine.o +libqos-obj-y += tests/qtest/libqos/arm-imx25-pdk-machine.o +libqos-obj-y += tests/qtest/libqos/arm-n800-machine.o +libqos-obj-y += tests/qtest/libqos/arm-raspi2-machine.o +libqos-obj-y += tests/qtest/libqos/arm-sabrelite-machine.o +libqos-obj-y += tests/qtest/libqos/arm-smdkc210-machine.o +libqos-obj-y += tests/qtest/libqos/arm-virt-machine.o +libqos-obj-y += tests/qtest/libqos/arm-xilinx-zynq-a9-machine.o +libqos-obj-y += tests/qtest/libqos/ppc64_pseries-machine.o +libqos-obj-y += tests/qtest/libqos/x86_64_pc-machine.o # qos tests: +qos-test-obj-y += tests/qtest/qos-test.o qos-test-obj-y += tests/qtest/ac97-test.o qos-test-obj-y += tests/qtest/ds1338-test.o qos-test-obj-y += tests/qtest/e1000-test.o @@ -234,7 +235,7 @@ check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) check-qtest-generic-y += qos-test -tests/qtest/qos-test$(EXESUF): $(qos-test-obj-y) +tests/qtest/qos-test$(EXESUF): $(qos-test-obj-y) $(libqos-obj-y) # QTest dependencies: tests/qtest/qmp-test$(EXESUF): tests/qtest/qmp-test.o From patchwork Mon Jan 20 05:54:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341069 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83E84139A for ; Mon, 20 Jan 2020 06:14:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 06FE42077C for ; Mon, 20 Jan 2020 06:14:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="NjvFnXXO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 06FE42077C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQKg-0005q8-Nf for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:14:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35288) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1a-00076q-2d for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1Y-0006P7-GH for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:57 -0500 Received: from mail-bn7nam10on2103.outbound.protection.outlook.com ([40.107.92.103]:38113 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1Y-0006Ou-CQ for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:56 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l9V0aEvwB3cI2cNerX0fU5eUSutMLza3TGRDx7n4HBFFN5Jr2dF1Kmwjl+T50UHy+ZVu5+438cJ8o37Vmxge3Ond6H0lYGLPsNnMmjvYfIjdop8Hcs3kXwr7tZ2FM+neiJprRGATjjeAQV31j5ENBC5MFsWHlqxZaj+ozjeXeWVwSgwH6HjSbw1VLJkn2K/VcZHak9wDRuO5PqQR0m8RlrigE4q14GEhNV+A4RZ9GRFLJ6zNrgOQltAVayXP6Qso1YK2rqvGbCHhJys+TPFpiOPlYik24fUwDDDsAHGyfjkE/d8JFuo6wfwb7bT2tNNPZQdzC28p5wJYZaf2Lu48Fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BMCyJN3nzC2ixzb7DkXR5cQ3SesaeOMGZjfVp8Oc6oQ=; b=aFBMIyykUtWylBvx0jpoEmDwihh4Puw4/zFIkvZUpEGB3XnJUu+UAuVh/qK+eIFUzzQ6A70uF8FM+RTlkLV9Xlg1sWho8iNxGVNlnFXwXhcGkMe/P/nMDxztIKhcJlGvDDkM0LFkzL9XKp1wdzpQruj9MXWP9dD6yXomB5xL1K6NCpzIh3ToP+oZqAHC3i/SdnLduoHB7aG+DNoykqJsOACcZU/aaBqp+jLzCGn15ggevlnO6+dCERnPbMeWKAZ1406n2xwcrZFsy2ezRmOmiPbbBvuptblIdXyKczOUCIUmE5tHyX4K6kzewbmE/i8S6EsiPuEg6OE11svMmw+KrQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BMCyJN3nzC2ixzb7DkXR5cQ3SesaeOMGZjfVp8Oc6oQ=; b=NjvFnXXOeStX5uHWs/9p8eKENpbeFa6MHvIKHxHvs0SfkqPsAD8LpdbHCG0eK42UNYwtyEVGIuTS/mAZyN9miA/p1JCty8LK3Aguj0nmavTN+63And9VcSmg6VAwU85UQdOs9WgOX4ZVoElKxAShd1BwzkavaEHLMSfcm9cJlks= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:55 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:55 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:54 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 09/20] libqos: split qos-test and libqos makefile vars Thread-Topic: [PATCH v7 09/20] libqos: split qos-test and libqos makefile vars Thread-Index: AQHVz1YjAh3VVXV3W0yi2moYqESzFg== Date: Mon, 20 Jan 2020 05:54:54 +0000 Message-ID: <20200120055410.22322-14-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7f4d10c2-64e4-4088-22b5-08d79d6d45e4 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2958; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lqqKjoB0bT7Zs9QiAAJVLbOeKHn58MzMh128m3Bmxaf7wcUVnKKcArf9OX5SiBRkLuK66AjFoVoQ4+92WaZvamh1wXTe+/UrEcWDkIZrsGpjbkIks6bvlW0r60tRgALPc5cKe+zSPC9bWlUZQbS7/shyIpbV67ncz3MfTiY0z+GnH/eJcL7HKEZZH8QicpWBnaP+nGV1W0VY3CgQNLWekBSmI9OdvZhhCT6fuGY2mMWApicgQUZLLEg7lE+3a5OsZSx0ec6d6qWwZHQTBNm/CWHxv5Ua7OawunUlE9uWme84FEpfKpdlrnWIbkKOs2Mzy0BCcels2wSSGwNlsoVHeqnLl/U8b5+mH/oIRGHfJvOJulBX65ZCT/lw38CWIj5PHbB4ke4qEGxM/DUkQ1Ydy95djL4Z5F+wIMiRnNNqKMZZu0+pABhjjdV9Mi1pODfs Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 7f4d10c2-64e4-4088-22b5-08d79d6d45e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:54.7988 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: b8hesdP6xycM5q3IA2TmBM+iOqrVvXsG3CAEBu0pSjjcGUgBbnirQq6Hq+T7iArf X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.103 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , Darren Kenny , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Most qos-related objects were specified in the qos-test-obj-y variable. qos-test-obj-y also included qos-test.o which defines a main(). This made it difficult to repurpose qos-test-obj-y to link anything beside tests/qos-test against libqos. This change separates objects that are libqos-specific and ones that are qos-test specific into different variables. Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- tests/qtest/Makefile.include | 71 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/tests/qtest/Makefile.include b/tests/qtest/Makefile.include index e6bb4ab28c..08a48c1252 100644 --- a/tests/qtest/Makefile.include +++ b/tests/qtest/Makefile.include @@ -157,52 +157,53 @@ check-qtest-s390x-y += migration-test # libqos / qgraph : libqgraph-obj-y = tests/qtest/libqos/qgraph.o -libqos-obj-y = $(libqgraph-obj-y) tests/qtest/libqos/pci.o tests/qtest/libqos/fw_cfg.o -libqos-obj-y += tests/qtest/libqos/malloc.o -libqos-obj-y += tests/qtest/libqos/libqos.o -libqos-spapr-obj-y = $(libqos-obj-y) tests/qtest/libqos/malloc-spapr.o +libqos-core-obj-y = $(libqgraph-obj-y) tests/qtest/libqos/pci.o tests/qtest/libqos/fw_cfg.o +libqos-core-obj-y += tests/qtest/libqos/malloc.o +libqos-core-obj-y += tests/qtest/libqos/libqos.o +libqos-spapr-obj-y = $(libqos-core-obj-y) tests/qtest/libqos/malloc-spapr.o libqos-spapr-obj-y += tests/qtest/libqos/libqos-spapr.o libqos-spapr-obj-y += tests/qtest/libqos/rtas.o libqos-spapr-obj-y += tests/qtest/libqos/pci-spapr.o -libqos-pc-obj-y = $(libqos-obj-y) tests/qtest/libqos/pci-pc.o +libqos-pc-obj-y = $(libqos-core-obj-y) tests/qtest/libqos/pci-pc.o libqos-pc-obj-y += tests/qtest/libqos/malloc-pc.o tests/qtest/libqos/libqos-pc.o libqos-pc-obj-y += tests/qtest/libqos/ahci.o libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/qtest/libqos/usb.o # qos devices: -qos-test-obj-y = tests/qtest/qos-test.o $(libqgraph-obj-y) -qos-test-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) -qos-test-obj-y += tests/qtest/libqos/e1000e.o -qos-test-obj-y += tests/qtest/libqos/i2c.o -qos-test-obj-y += tests/qtest/libqos/i2c-imx.o -qos-test-obj-y += tests/qtest/libqos/i2c-omap.o -qos-test-obj-y += tests/qtest/libqos/sdhci.o -qos-test-obj-y += tests/qtest/libqos/tpci200.o -qos-test-obj-y += tests/qtest/libqos/virtio.o -qos-test-obj-$(CONFIG_VIRTFS) += tests/qtest/libqos/virtio-9p.o -qos-test-obj-y += tests/qtest/libqos/virtio-balloon.o -qos-test-obj-y += tests/qtest/libqos/virtio-blk.o -qos-test-obj-y += tests/qtest/libqos/virtio-mmio.o -qos-test-obj-y += tests/qtest/libqos/virtio-net.o -qos-test-obj-y += tests/qtest/libqos/virtio-pci.o -qos-test-obj-y += tests/qtest/libqos/virtio-pci-modern.o -qos-test-obj-y += tests/qtest/libqos/virtio-rng.o -qos-test-obj-y += tests/qtest/libqos/virtio-scsi.o -qos-test-obj-y += tests/qtest/libqos/virtio-serial.o +libqos-obj-y = $(libqgraph-obj-y) +libqos-obj-y += $(libqos-pc-obj-y) $(libqos-spapr-obj-y) +libqos-obj-y += tests/qtest/libqos/e1000e.o +libqos-obj-y += tests/qtest/libqos/i2c.o +libqos-obj-y += tests/qtest/libqos/i2c-imx.o +libqos-obj-y += tests/qtest/libqos/i2c-omap.o +libqos-obj-y += tests/qtest/libqos/sdhci.o +libqos-obj-y += tests/qtest/libqos/tpci200.o +libqos-obj-y += tests/qtest/libqos/virtio.o +libqos-obj-$(CONFIG_VIRTFS) += tests/qtest/libqos/virtio-9p.o +libqos-obj-y += tests/qtest/libqos/virtio-balloon.o +libqos-obj-y += tests/qtest/libqos/virtio-blk.o +libqos-obj-y += tests/qtest/libqos/virtio-mmio.o +libqos-obj-y += tests/qtest/libqos/virtio-net.o +libqos-obj-y += tests/qtest/libqos/virtio-pci.o +libqos-obj-y += tests/qtest/libqos/virtio-pci-modern.o +libqos-obj-y += tests/qtest/libqos/virtio-rng.o +libqos-obj-y += tests/qtest/libqos/virtio-scsi.o +libqos-obj-y += tests/qtest/libqos/virtio-serial.o # qos machines: -qos-test-obj-y += tests/qtest/libqos/aarch64-xlnx-zcu102-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-imx25-pdk-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-n800-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-raspi2-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-sabrelite-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-smdkc210-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-virt-machine.o -qos-test-obj-y += tests/qtest/libqos/arm-xilinx-zynq-a9-machine.o -qos-test-obj-y += tests/qtest/libqos/ppc64_pseries-machine.o -qos-test-obj-y += tests/qtest/libqos/x86_64_pc-machine.o +libqos-obj-y += tests/qtest/libqos/aarch64-xlnx-zcu102-machine.o +libqos-obj-y += tests/qtest/libqos/arm-imx25-pdk-machine.o +libqos-obj-y += tests/qtest/libqos/arm-n800-machine.o +libqos-obj-y += tests/qtest/libqos/arm-raspi2-machine.o +libqos-obj-y += tests/qtest/libqos/arm-sabrelite-machine.o +libqos-obj-y += tests/qtest/libqos/arm-smdkc210-machine.o +libqos-obj-y += tests/qtest/libqos/arm-virt-machine.o +libqos-obj-y += tests/qtest/libqos/arm-xilinx-zynq-a9-machine.o +libqos-obj-y += tests/qtest/libqos/ppc64_pseries-machine.o +libqos-obj-y += tests/qtest/libqos/x86_64_pc-machine.o # qos tests: +qos-test-obj-y += tests/qtest/qos-test.o qos-test-obj-y += tests/qtest/ac97-test.o qos-test-obj-y += tests/qtest/ds1338-test.o qos-test-obj-y += tests/qtest/e1000-test.o @@ -234,7 +235,7 @@ check-unit-y += tests/test-qgraph$(EXESUF) tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y) check-qtest-generic-y += qos-test -tests/qtest/qos-test$(EXESUF): $(qos-test-obj-y) +tests/qtest/qos-test$(EXESUF): $(qos-test-obj-y) $(libqos-obj-y) # QTest dependencies: tests/qtest/qmp-test$(EXESUF): tests/qtest/qmp-test.o From patchwork Mon Jan 20 05:54:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341043 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E1D9924 for ; Mon, 20 Jan 2020 06:05:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 043372073D for ; Mon, 20 Jan 2020 06:05:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="JuPpLvlX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 043372073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58958 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQBm-0001Lv-Qe for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:05:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35310) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1c-00079r-0I for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1a-0006QG-Ln for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:59 -0500 Received: from mail-bn7nam10on2116.outbound.protection.outlook.com ([40.107.92.116]:31998 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1a-0006Q3-Ho for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YukunFqCfmH5jSh9MR1/UIfQLAuWqQm9LXW98eUwy4kNeqdYPelEDaK/YG2++lf4LYZoiTNNxFYRnQbxdyWVEM9EHR8bzqffT7t3HIKrtvW4t2UC24tj5KcPpjsu4JEno2MTVh647+dpjxT6Y5qvKABSCe5u5ReFDv5o2EAFgWIDni4tlbUdW9KFNrE88I1OR0lymDK0+C/1Re/m/kX5HaaOtc+aO5alLcIC5UKtwjlPTlF89Fk9Bm/YR8zIOoDuKVYxnMq52ysLXpJFVFHzgmhG6lXR0l1BEEXgrLl8MYBeVn7b3HX4U6sxz1Y/U58qbbckxvm9QjQNk9o4fKgPmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1hQfW9/9q8KnXyTWzkxHml6DPaJtmQZHPkWi5XPf+6I=; b=WgJNaykvdgGhWPdIQmkVfnxejmJjpGWeKXkXvroVOGBm1AVr8ylZSO5B8luJ6c4mUS9yprIomlDPowIs9OfHFF2rs1rRsfkMVQBx17WR7JbrpKWc2iKnSDUQqfnqtexxdzSlqoXTmUt6moHk2wBH8CLlO4mRvX8Qd60zu7JDlp8UhmrhTdYNuU8RH26WsT12dwBOJrug3k0Uf8cm2LWDzEg+BzHjkMhu1Ym/E55Zv8QRBC2AppLe6sKUM77zBp6An46L5XCe6hX0H0pnZJTJw6OtsUCOUA81IqAJxi1a4P8te3P7T2qPvSB9aGoDWLDsEVtPQzNNDnEZK0HSvPhTsA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1hQfW9/9q8KnXyTWzkxHml6DPaJtmQZHPkWi5XPf+6I=; b=JuPpLvlXSuXLiEVIaG6fyFo03mNdG8M54MCrZjicnkibos9m7zDgZ1P8TsmtEf4nCtkQrr8R0JopbwpvjmnYvYcMTXenezc2MU+SY7S5ndb+JjJhPm9FA28WniB7uk21VaO/1yzLBsJX3gwcqScH+An5hTpwnaimB7FxWq2i+vE= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:57 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:57 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:56 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 10/20] libqtest: make bufwrite rely on the TransportOps Thread-Topic: [PATCH v7 10/20] libqtest: make bufwrite rely on the TransportOps Thread-Index: AQHVz1Ykz539ApCc2kOWg771utMEUQ== Date: Mon, 20 Jan 2020 05:54:57 +0000 Message-ID: <20200120055410.22322-16-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 70d61398-015b-42b9-05ec-08d79d6d4711 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1468; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: VBpEhFjBPyUf5SCoKSlbn1DdgKMPoke80LXxhh6v/rii9poX+zb5CWl4KxN0eAlWwLU1NrhqgfGuEbKVniNCevSRrG9f+FgucNR29djNOmEDzZndAMDXBa00R83gtjH7Gm+hNTeqhTbzsZeyBXA54Y15qqGJC+DgKLQM4OonK8wLjCa9r0es/n0ZVaueXParkL7Kx9ZxvEm8NDky9Itj3iTvCK+MrdHHKrBVFeBCXnZbPeta9drEK61wb+Hlsiqo4fz8ZWAORuPjNa0lmvaB/TYK7uk0esTylALrqDkTPS9oPZ5C4HMgMONzN5XzTUUBu2TqOUXRHI2wneOAgiDs8wra0kf08dGiQES5DrxWoYwaDe+6jBmZous6V3/iA1yq4dfLHrD2VMTS3FFdQdYlv7Tl8qVh8Eb76eDLaePsKwZy200odGIEmrG/1oAwEKj7 MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 70d61398-015b-42b9-05ec-08d79d6d4711 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:57.1455 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: TrVuI0YtNYV85HMNko2Zd8EfNoQoRkrivBv2VqV7IMy5q79v86gPvUAZ1LLsp/aT X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.116 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" When using qtest "in-process" communication, qtest_sendf directly calls a function in the server (qtest.c). Previously, bufwrite used socket_send, which bypasses the TransportOps enabling the call into qtest.c. This change replaces the socket_send calls with ops->send, maintaining the benefits of the direct socket_send call, while adding support for in-process qtest calls. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/libqtest.c | 71 ++++++++++++++++++++++++++++++++++++++++-- tests/qtest/libqtest.h | 4 +++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index e5056a1d0f..49075b55a1 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -37,10 +37,18 @@ typedef void (*QTestSendFn)(QTestState *s, const char *buf); +typedef void (*ExternalSendFn)(void *s, const char *buf); typedef GString* (*QTestRecvFn)(QTestState *); typedef struct QTestClientTransportOps { QTestSendFn send; /* for sending qtest commands */ + + /* + * use external_send to send qtest command strings through functions which + * do not accept a QTestState as the first parameter. + */ + ExternalSendFn external_send; + QTestRecvFn recv_line; /* for receiving qtest command responses */ } QTestTransportOps; @@ -1078,8 +1086,8 @@ void qtest_bufwrite(QTestState *s, uint64_t addr, const void *data, size_t size) bdata = g_base64_encode(data, size); qtest_sendf(s, "b64write 0x%" PRIx64 " 0x%zx ", addr, size); - socket_send(s->fd, bdata, strlen(bdata)); - socket_send(s->fd, "\n", 1); + s->ops.send(s, bdata); + s->ops.send(s, "\n"); qtest_rsp(s, 0); g_free(bdata); } @@ -1367,3 +1375,62 @@ static void qtest_client_set_rx_handler(QTestState *s, QTestRecvFn recv) { s->ops.recv_line = recv; } +/* A type-safe wrapper for s->send() */ +static void send_wrapper(QTestState *s, const char *buf) +{ + s->ops.external_send(s, buf); +} + +static GString *qtest_client_inproc_recv_line(QTestState *s) +{ + GString *line; + size_t offset; + char *eol; + + eol = strchr(s->rx->str, '\n'); + offset = eol - s->rx->str; + line = g_string_new_len(s->rx->str, offset); + g_string_erase(s->rx, 0, offset + 1); + return line; +} + +QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch, + void (*send)(void*, const char*)) +{ + QTestState *qts; + qts = g_new0(QTestState, 1); + *s = qts; /* Expose qts early on, since the query endianness relies on it */ + qts->wstatus = 0; + for (int i = 0; i < MAX_IRQ; i++) { + qts->irq_level[i] = false; + } + + qtest_client_set_rx_handler(qts, qtest_client_inproc_recv_line); + + /* send() may not have a matching protoype, so use a type-safe wrapper */ + qts->ops.external_send = send; + qtest_client_set_tx_handler(qts, send_wrapper); + + qts->big_endian = qtest_query_target_endianness(qts); + + /* + * Set a dummy path for QTEST_QEMU_BINARY. Doesn't need to exist, but this + * way, qtest_get_arch works for inproc qtest. + */ + gchar *bin_path = g_strconcat("/qemu-system-", arch, NULL); + setenv("QTEST_QEMU_BINARY", bin_path, 0); + g_free(bin_path); + + return qts; +} + +void qtest_client_inproc_recv(void *opaque, const char *str) +{ + QTestState *qts = *(QTestState **)opaque; + + if (!qts->rx) { + qts->rx = g_string_new(NULL); + } + g_string_append(qts->rx, str); + return; +} diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index c9e21e05b3..f5cf93c386 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -729,4 +729,8 @@ bool qtest_probe_child(QTestState *s); */ void qtest_set_expected_status(QTestState *s, int status); +QTestState *qtest_inproc_init(QTestState **s, bool log, const char* arch, + void (*send)(void*, const char*)); + +void qtest_client_inproc_recv(void *opaque, const char *str); #endif From patchwork Mon Jan 20 05:54:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B694109A for ; Mon, 20 Jan 2020 06:07:55 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 50D6A2073A for ; Mon, 20 Jan 2020 06:07:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="PBdt3rqy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50D6A2073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59052 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQE5-0004ZM-S8 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:07:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35328) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1d-0007CG-Kc for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1b-0006R0-RL for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:01 -0500 Received: from mail-bn7nam10on2096.outbound.protection.outlook.com ([40.107.92.96]:25288 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1b-0006Qb-Mb for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:54:59 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lGAEeA2nqA3M7jv1ayFIU8W3h2IOOpm3rK5Y1fR80YhnyuYKIchy+I1Z+5r0d8aUAie10TZeI3mYpIuwZ4xiMyeteRDY6rplAqMcxyJOSomEGsAzq0YJ33JEyiZ86E7IcLIuSTNwqW/0DJEHspom18W4mK/T6EBko1F4/60l3Css3Ud37OHF0wGH7SKo89tQltv8D05qwP3X7OrZiifB0NdjVjLieTIOlID7ev4CfPRJ02nQ2TmMK/g53I2BxAoqOA3CMXa2nj30xpEYGdXt1JXOE6H604sTNnIWRXq98pN6+BNQGaidqGj5ARuB/Q1Z49GEI8M6XzRwAVaM/AFN7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tl0/ILW0g0Hz8hjxyHNzbtrsBdyyLkU/GgwK3UTS5tU=; b=SaISarfNvFpq2dMDwjPL6n5i8LTa8eJh0Mr13tbzc6Qd+tr96rh5tK8SnBtGMEE0ZD9XKK9J/JBWjdvGSICQHcdhQFu3/SjqucomNWpBvHQHyoNRLBwndOe8mU7JNwhP5y33PBFX+aeWaxUihqnfQe9vpDuWaueB2A3dmNv+YF6diWEECylLlZnZs07W4WFReHO3efEyvvjEmpLVakQaA2UiMnjTqViDmKBu9ckWmqK84TlNX8A69AvCmAwsAidTMOnUmz88r2Kgf3Sipy6Xb2xB1LVJuM6yKmtb54yT5/7JlwEd39JfrcSvHUN+RQxSZh59HwTVtRVS1KW/tHfoqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Tl0/ILW0g0Hz8hjxyHNzbtrsBdyyLkU/GgwK3UTS5tU=; b=PBdt3rqyHAXzx8o8+vlBVVIB4CvsPn8LtIg6YVg+WHGJbkUmCG80NK8GdljwxpqaWkc98otMLskhE6jgB5oIid0hhLx/CBASlYn8I6o3IjAqcPD4fsRs20w472Ki1m7HZT5d1h77+ZJTwe5OMJsXJ0wJ92p+G3KisHS0xlQa3Ls= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:58 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:58 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:57 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 11/20] fuzz: add fuzzer skeleton Thread-Topic: [PATCH v7 11/20] fuzz: add fuzzer skeleton Thread-Index: AQHVz1Yl7EIuhCEXAE6SVHuKCAM4Pw== Date: Mon, 20 Jan 2020 05:54:58 +0000 Message-ID: <20200120055410.22322-17-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 06dca6a5-bc3d-4f1d-61d4-08d79d6d4808 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2512; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: uqW1K1UcHeuE1vHNTAnPIFOYCAc1B9DcvO0gneyRME6GHpEeqJlQ2/aBuTbEuGe0VnP9QaS7Lh9lhIgkNUsNXQMD4dX+EIzW3hwm+apyOaSsEJleAmgfZMcM297ebt1FkI7nrWdfFyZupGGplHDXUneWXR6cwRToQ1puOe/jXvzw6KTHk4NS8THzPmBfUhSrR89aikZjZSFPdyatzovijE/Q24lWKKqLfUpRK7/YYuK0FuN3GTGvzQcwECW7mnwA9GJLvpwMiHXHn33sweC8HAnEvBfZKHXVJ67pcHuOKk1u8EZ8ovlpNEvUfYHfuowMT0bE/kXFG45AGHF4IE8TZGCHS06C48YCCkqw6uYrFXkngep3dXTTARaPTBUSepoT/53GnSy5tKnelcDDDwI95DKVzikRuCU0pXck7gZb/CVyyO3lGHl68gj7vq4sNbau MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 06dca6a5-bc3d-4f1d-61d4-08d79d6d4808 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:58.3448 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: KfRsTT9g9IxFy4a/pAKaP/sBIgSWXxMFYqcOp+82kygvty5py5o1gzz3GYFwgrQF X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.96 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" tests/fuzz/fuzz.c serves as the entry point for the virtual-device fuzzer. Namely, libfuzzer invokes the LLVMFuzzerInitialize and LLVMFuzzerTestOneInput functions, both of which are defined in this file. This change adds a "FuzzTarget" struct, along with the fuzz_add_target function, which should be used to define new fuzz targets. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 6 + tests/qtest/fuzz/fuzz.c | 179 ++++++++++++++++++++++++++++++ tests/qtest/fuzz/fuzz.h | 95 ++++++++++++++++ 3 files changed, 280 insertions(+) create mode 100644 tests/qtest/fuzz/Makefile.include create mode 100644 tests/qtest/fuzz/fuzz.c create mode 100644 tests/qtest/fuzz/fuzz.h diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include new file mode 100644 index 0000000000..8632bb89f4 --- /dev/null +++ b/tests/qtest/fuzz/Makefile.include @@ -0,0 +1,6 @@ +QEMU_PROG_FUZZ=qemu-fuzz-$(TARGET_NAME)$(EXESUF) + +fuzz-obj-y += tests/qtest/libqtest.o +fuzz-obj-y += tests/qtest/fuzz/fuzz.o # Fuzzer skeleton + +FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/fuzz.c b/tests/qtest/fuzz/fuzz.c new file mode 100644 index 0000000000..afceb4300a --- /dev/null +++ b/tests/qtest/fuzz/fuzz.c @@ -0,0 +1,179 @@ +/* + * fuzzing driver + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" + +#include + +#include "sysemu/qtest.h" +#include "sysemu/runstate.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/qgraph.h" +#include "fuzz.h" + +#define MAX_EVENT_LOOPS 10 + +typedef struct FuzzTargetState { + FuzzTarget *target; + QSLIST_ENTRY(FuzzTargetState) target_list; +} FuzzTargetState; + +typedef QSLIST_HEAD(, FuzzTargetState) FuzzTargetList; + +static const char *fuzz_arch = TARGET_NAME; + +static FuzzTargetList *fuzz_target_list; +static FuzzTarget *fuzz_target; +static QTestState *fuzz_qts; + + + +void flush_events(QTestState *s) +{ + int i = MAX_EVENT_LOOPS; + while (g_main_context_pending(NULL) && i-- > 0) { + main_loop_wait(false); + } +} + +static QTestState *qtest_setup(void) +{ + qtest_server_set_send_handler(&qtest_client_inproc_recv, &fuzz_qts); + return qtest_inproc_init(&fuzz_qts, false, fuzz_arch, + &qtest_server_inproc_recv); +} + +void fuzz_add_target(const FuzzTarget *target) +{ + FuzzTargetState *tmp; + FuzzTargetState *target_state; + if (!fuzz_target_list) { + fuzz_target_list = g_new0(FuzzTargetList, 1); + } + + QSLIST_FOREACH(tmp, fuzz_target_list, target_list) { + if (g_strcmp0(tmp->target->name, target->name) == 0) { + fprintf(stderr, "Error: Fuzz target name %s already in use\n", + target->name); + abort(); + } + } + target_state = g_new0(FuzzTargetState, 1); + target_state->target = g_new0(FuzzTarget, 1); + *(target_state->target) = *target; + QSLIST_INSERT_HEAD(fuzz_target_list, target_state, target_list); +} + + + +static void usage(char *path) +{ + printf("Usage: %s --fuzz-target=FUZZ_TARGET [LIBFUZZER ARGUMENTS]\n", path); + printf("where FUZZ_TARGET is one of:\n"); + FuzzTargetState *tmp; + if (!fuzz_target_list) { + fprintf(stderr, "Fuzz target list not initialized\n"); + abort(); + } + QSLIST_FOREACH(tmp, fuzz_target_list, target_list) { + printf(" * %s : %s\n", tmp->target->name, + tmp->target->description); + } + exit(0); +} + +static FuzzTarget *fuzz_get_target(char* name) +{ + FuzzTargetState *tmp; + if (!fuzz_target_list) { + fprintf(stderr, "Fuzz target list not initialized\n"); + abort(); + } + + QSLIST_FOREACH(tmp, fuzz_target_list, target_list) { + if (strcmp(tmp->target->name, name) == 0) { + return tmp->target; + } + } + return NULL; +} + + +/* Executed for each fuzzing-input */ +int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size) +{ + /* + * Do the pre-fuzz-initialization before the first fuzzing iteration, + * instead of before the actual fuzz loop. This is needed since libfuzzer + * may fork off additional workers, prior to the fuzzing loop, and if + * pre_fuzz() sets up e.g. shared memory, this should be done for the + * individual worker processes + */ + static int pre_fuzz_done; + if (!pre_fuzz_done && fuzz_target->pre_fuzz) { + fuzz_target->pre_fuzz(fuzz_qts); + pre_fuzz_done = true; + } + + fuzz_target->fuzz(fuzz_qts, Data, Size); + return 0; +} + +/* Executed once, prior to fuzzing */ +int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp) +{ + + char *target_name; + + /* Initialize qgraph and modules */ + qos_graph_init(); + module_call_init(MODULE_INIT_FUZZ_TARGET); + module_call_init(MODULE_INIT_QOM); + module_call_init(MODULE_INIT_LIBQOS); + + if (*argc <= 1) { + usage(**argv); + } + + /* Identify the fuzz target */ + target_name = (*argv)[1]; + if (!strstr(target_name, "--fuzz-target=")) { + usage(**argv); + } + + target_name += strlen("--fuzz-target="); + + fuzz_target = fuzz_get_target(target_name); + if (!fuzz_target) { + usage(**argv); + } + + fuzz_qts = qtest_setup(); + + if (fuzz_target->pre_vm_init) { + fuzz_target->pre_vm_init(); + } + + /* Run QEMU's softmmu main with the fuzz-target dependent arguments */ + const char *init_cmdline = fuzz_target->get_init_cmdline(fuzz_target); + + /* Split the runcmd into an argv and argc */ + wordexp_t result; + wordexp(init_cmdline, &result, 0); + + qemu_init(result.we_wordc, result.we_wordv, NULL); + + return 0; +} diff --git a/tests/qtest/fuzz/fuzz.h b/tests/qtest/fuzz/fuzz.h new file mode 100644 index 0000000000..03901d414e --- /dev/null +++ b/tests/qtest/fuzz/fuzz.h @@ -0,0 +1,95 @@ +/* + * fuzzing driver + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef FUZZER_H_ +#define FUZZER_H_ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" + +#include "tests/qtest/libqtest.h" + +/** + * A libfuzzer fuzzing target + * + * The QEMU fuzzing binary is built with all available targets, each + * with a unique @name that can be specified on the command-line to + * select which target should run. + * + * A target must implement ->fuzz() to process a random input. If QEMU + * crashes in ->fuzz() then libfuzzer will record a failure. + * + * Fuzzing targets are registered with fuzz_add_target(): + * + * static const FuzzTarget fuzz_target = { + * .name = "my-device-fifo", + * .description = "Fuzz the FIFO buffer registers of my-device", + * ... + * }; + * + * static void register_fuzz_target(void) + * { + * fuzz_add_target(&fuzz_target); + * } + * fuzz_target_init(register_fuzz_target); + */ +typedef struct FuzzTarget { + const char *name; /* target identifier (passed to --fuzz-target=)*/ + const char *description; /* help text */ + + + /* + * returns the arg-list that is passed to qemu/softmmu init() + * Cannot be NULL + */ + const char* (*get_init_cmdline)(struct FuzzTarget *); + + /* + * will run once, prior to running qemu/softmmu init. + * eg: set up shared-memory for communication with the child-process + * Can be NULL + */ + void(*pre_vm_init)(void); + + /* + * will run once, after QEMU has been initialized, prior to the fuzz-loop. + * eg: detect the memory map + * Can be NULL + */ + void(*pre_fuzz)(QTestState *); + + /* + * accepts and executes an input from libfuzzer. this is repeatedly + * executed during the fuzzing loop. Its should handle setup, input + * execution and cleanup. + * Cannot be NULL + */ + void(*fuzz)(QTestState *, const unsigned char *, size_t); + +} FuzzTarget; + +void flush_events(QTestState *); +void reboot(QTestState *); + +/* + * makes a copy of *target and adds it to the target-list. + * i.e. fine to set up target on the caller's stack + */ +void fuzz_add_target(const FuzzTarget *target); + +int LLVMFuzzerTestOneInput(const unsigned char *Data, size_t Size); +int LLVMFuzzerInitialize(int *argc, char ***argv, char ***envp); + +#endif + From patchwork Mon Jan 20 05:54:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AB33139A for ; Mon, 20 Jan 2020 06:19:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 506D62077C for ; Mon, 20 Jan 2020 06:19:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="k7/IheOB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 506D62077C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQPK-0003Mh-9S for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:19:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35341) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1f-0007Es-8f for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1c-0006Rd-PT for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:03 -0500 Received: from mail-bn7nam10on2137.outbound.protection.outlook.com ([40.107.92.137]:56161 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1c-0006RK-Kx for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:00 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AaoNWI6boG0/naGiZhBzznc9/dtwqVk0cgoIabqa5wWO9dt9yCSAtytB9ElfYbS402wIJHtaTSq7soAWB+nq5+1ra4VSWaozbNcV/uqNqRryLFlbFStwYgIhaOHaMjhnNzj0ZM9qK+m2E/lJ6grH89av9NLUW8zhSPwxRVydHYaA+Rjh2l4uaki08xAdVyEYqnB8PXP578fmOExnKq1iCuSYawI1DiQEOVuB2w7WAd9Y4jkqtdvCvZZthuIk1t3U0UnIRsQz/eVlU3AfhI6v5nXfytPi1b/GtQJmvRdO3fogs3ZWfsmki+icZIffTkHXCGPGrMOdB3LB2GujHHckLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ui0cO3mn4zGmGs0rIHRGsmsj5MEjM8q6EfnLFSQsmv4=; b=VFkHZCM7annUsUPAiYNF5vGnTKunYIpLj72eQT2tRV8VKd5bhpgKLcLECeXDzdTmNfPSW1GiNfoG78EdpBjQ7MSZ86JN2+RssgGaIxUQpeIOGy02iS8FfO2hkdlTY3MJo+xEKa8zsww8wbg7OsTeh5TLiVAZ4bKLhR2Eeh6XqsE9BevbNLc/Ki131bGLAd78KEL3ZYMs/iFw/ZR0wjYt9mxGhzqo0k0sPwFauz2+sx75ma/3BNsUmpQQTjv+1bs6mCC3QCnVM421PP93biIZoimWFQBjzgxqk77xb3OjUz/yxv67wmXebYsSdEyGVdWdkRYxlwTq3gV2e87jATI7AA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ui0cO3mn4zGmGs0rIHRGsmsj5MEjM8q6EfnLFSQsmv4=; b=k7/IheOBAQ+WzqHJvGr+2cBq3h7Xb03PGc5Hc74MSc1ZyIcsSXfNYLn/IY51xrGE6yttvs2fWFmtgLGvRX6ovX8D45ZkOvVAhIVRiv9QjUWWnGbGl6nw99BPG4VSDJor6v2QWRRqlyYaW3LSMFccyd4ez2CqVVsstYshbxaArmw= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:54:59 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:54:59 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:58 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 12/20] exec: keep ram block across fork when using qtest Thread-Topic: [PATCH v7 12/20] exec: keep ram block across fork when using qtest Thread-Index: AQHVz1YmyMQHZuW7XUiNZvtV7JSQOw== Date: Mon, 20 Jan 2020 05:54:59 +0000 Message-ID: <20200120055410.22322-18-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 305f31b8-2321-429a-8ddd-08d79d6d4880 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:4941; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: pXIRwzizj6sulw+IzwxNWjEn5VtFWV3sgo8ROLq1mL0FaHRAQD26mw6ptuHv7Z3Nrv9BadE7EoaSRQjtzPp5RyqQJfpi2314p8cS6bns8Axv2GuEqol5q+zWeOW3ErlAapS9XyP0uJucW/nECgQXh+GbbzW6tBtGyMFasOcGO/Og2PU/QGBNeX+NW6bBM6hhBqWF3rngyMD0cloPjkrwU4fZHxfxm1vIbXniycUiyJCZvYbKMTuX3kQ+0YNYQxguQptbAy6l9c3F4RB+rKDtvpBp/zojqhy96PiWo/O6VCA+C5FR4P6RSoo3NPA845b4Z66YLJ2H3cFua5nm6nBGz+RpSQgSbcAm6uq3z92qxF1G4ytn/IXs13Bl7ZOYyS3I+tS7/0VGtOESeehWWPt+/x80atYY2ThsotFgmSsYTFisg9BzUiZGqKzaE484iZHP MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 305f31b8-2321-429a-8ddd-08d79d6d4880 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:54:59.3293 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: HPST2ncAgTM4bT7I8EOnrrg5HWibEjXe8le1tgov4cA4LE9Uq4MvhqEmzO3ZpTbQ X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.137 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , Richard Henderson , "stefanha@redhat.com" , "Bulekov, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Ram blocks were marked MADV_DONTFORK breaking fuzzing-tests which execute each test-input in a forked process. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- exec.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/exec.c b/exec.c index d4b769d0d4..99368f175b 100644 --- a/exec.c +++ b/exec.c @@ -35,6 +35,7 @@ #include "sysemu/kvm.h" #include "sysemu/sysemu.h" #include "sysemu/tcg.h" +#include "sysemu/qtest.h" #include "qemu/timer.h" #include "qemu/config-file.h" #include "qemu/error-report.h" @@ -2306,8 +2307,15 @@ static void ram_block_add(RAMBlock *new_block, Error **errp, bool shared) if (new_block->host) { qemu_ram_setup_dump(new_block->host, new_block->max_length); qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_HUGEPAGE); - /* MADV_DONTFORK is also needed by KVM in absence of synchronous MMU */ - qemu_madvise(new_block->host, new_block->max_length, QEMU_MADV_DONTFORK); + /* + * MADV_DONTFORK is also needed by KVM in absence of synchronous MMU + * Configure it unless the machine is a qtest server, in which case + * KVM is not used and it may be forked (eg for fuzzing purposes). + */ + if (!qtest_enabled()) { + qemu_madvise(new_block->host, new_block->max_length, + QEMU_MADV_DONTFORK); + } ram_block_notify_add(new_block->host, new_block->max_length); } } From patchwork Mon Jan 20 05:55:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341057 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7795924 for ; Mon, 20 Jan 2020 06:10:38 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD9322073A for ; Mon, 20 Jan 2020 06:10:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="00w2MYKH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD9322073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQGj-0008Af-BP for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:10:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35347) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1f-0007FY-Le for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1e-0006SP-2f for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:03 -0500 Received: from mail-bn7nam10on2098.outbound.protection.outlook.com ([40.107.92.98]:14528 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1d-0006S7-Tz for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:02 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SN3VMyTSkjWFTs68tRoHYD//KAwpa/OMel2xVU4DcjocEQPjsvh1k6WPP7+7PmUJhfWy6/g/cLKqqSUQHTRrC2Pt8gv3n0E62l0q+B9K50rA0/ykjgas7gcBvI/3FYiLH4nr0EzOyjUa2cZa4jaUf21fmYvuVUxp7InHSDMRN9UNunjt0Z5f075Aljmtb8rF9DJm1ubb24CrT94b/vVd3WDLSanU4BVn5nQxqcsv4Eglsq15Tckgux79eCcvQLq9Xbx34n1/pOWqoH6/Tb0bEWr14/ympm1u6r2k2ffpOHpSZ+Ib22R1RaG7KJ7eG4W8dL0H7b9rPFCfRwzSRk+zkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fryQK8xhDZQ/FTsWZyYBSV50LhpNP2y8Q2iAmhkAd6c=; b=CrrEP5HCNirtM8MltOaujByKKQ9r+CB+xu2x5BPuE6ceyDRALtFUJmcf3G7IDsIVERT+cvIs5DBut5PzWrfMyo0VhJV/l8TLNbxoIjebuTLQERZOHSidRyPM5ieyLsKPCIoeJPDFKCneUTD8Rk0oi34DC3zqlW3ZLiksgtEIMbw+z6NC14erhtR/96mupFRv/lbFptfr4XYvczfMGXl8jpB20uAICgjCIxyoc5Oi7ylG4IoIp2Ncw9TgiJkgaZr7St0S0H9HmKs6obK9e4HmjVqLzueshAu6qzMg6WFSltbfmjaUhSPjbFLcv3tyswo+PGNBM5FzdWMkG6HlESIEMQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fryQK8xhDZQ/FTsWZyYBSV50LhpNP2y8Q2iAmhkAd6c=; b=00w2MYKHrwQd/xnZNpjIPoQ2EgEF8CMicSJPX96UZdKNpjQnvIY8rjRd0opSwZByazLDbZStcVONSO+9n3i26627KHFjFQrcH8ZXMbQ67FweiAYzMhPYhbKru0QlWF/JRXA/NKZLcBs/a07ZsMjnq07+gxixpHeg942LCEERBP8= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:00 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:00 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:54:59 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 13/20] fuzz: support for fork-based fuzzing. Thread-Topic: [PATCH v7 13/20] fuzz: support for fork-based fuzzing. Thread-Index: AQHVz1YnOBDAY/WqDEGgvxlgfET9KA== Date: Mon, 20 Jan 2020 05:55:00 +0000 Message-ID: <20200120055410.22322-19-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e55500ca-a1a9-488e-513c-08d79d6d4941 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(6666004)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: p30TOs4AjVOJvcv/BP5UAFQw6Wj/T7jbD+X9ut+LMSRrX0fPBBC4HUH5H0SbFMjwLGhWNEovK+4Fqfb4zgRLNH2evBHQWAqal1zOMnBaf1siHIPsWR/AUHx2DjxZQIT1dx+h/JERLC/oU23fHDTLjxkoa4WmCd5ad2SXXDBDdzH8vzYKti2mOHHht5xpu+MRtdpYozwhTZKRDWAJTL4J+w/PwgE7Kt0wt/OS5KXc7F5kdr9oq9Qccq8MD/wrZUaHARma+/PPEoH/+UBZX2w1O90UzmMAQRFosWguibs2RaSbiPLCszGTaMYoihxYgGrmiNcL+f2X9ubUxIUGuDcZWqe2ubZ2nP2tkQYCetiDr7g+wQjwIE0Dada1NXwd6keqJZnDhU1/q+ugHO5zFST2ENUZGffz0Dv/GjEzBV3wOHy0jiZ4dAFOqN99zqb6BmvS MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: e55500ca-a1a9-488e-513c-08d79d6d4941 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:00.7295 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: guR2jZCAUe8giJmb1PkahofWhPXt8i6kjz0sTWAMigVcZg7arQdsKCBooA+SfQsn X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.98 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" fork() is a simple way to ensure that state does not leak in between fuzzing runs. Unfortunately, the fuzzer mutation engine relies on bitmaps which contain coverage information for each fuzzing run, and these bitmaps should be copied from the child to the parent(where the mutation occurs). These bitmaps are created through compile-time instrumentation and they are not shared with fork()-ed processes, by default. To address this, we create a shared memory region, adjust its size and map it _over_ the counter region. Furthermore, libfuzzer doesn't generally expose the globals that specify the location of the counters/coverage bitmap. As a workaround, we rely on a custom linker script which forces all of the bitmaps we care about to be placed in a contiguous region, which is easy to locate and mmap over. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 5 +++ tests/qtest/fuzz/fork_fuzz.c | 55 +++++++++++++++++++++++++++++++ tests/qtest/fuzz/fork_fuzz.h | 23 +++++++++++++ tests/qtest/fuzz/fork_fuzz.ld | 37 +++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 tests/qtest/fuzz/fork_fuzz.c create mode 100644 tests/qtest/fuzz/fork_fuzz.h create mode 100644 tests/qtest/fuzz/fork_fuzz.ld diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index 8632bb89f4..a90915d56d 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -2,5 +2,10 @@ QEMU_PROG_FUZZ=qemu-fuzz-$(TARGET_NAME)$(EXESUF) fuzz-obj-y += tests/qtest/libqtest.o fuzz-obj-y += tests/qtest/fuzz/fuzz.o # Fuzzer skeleton +fuzz-obj-y += tests/qtest/fuzz/fork_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest + +# Linker Script to force coverage-counters into known regions which we can mark +# shared +FUZZ_LDFLAGS += -Xlinker -T$(SRC_PATH)/tests/qtest/fuzz/fork_fuzz.ld diff --git a/tests/qtest/fuzz/fork_fuzz.c b/tests/qtest/fuzz/fork_fuzz.c new file mode 100644 index 0000000000..2bd0851903 --- /dev/null +++ b/tests/qtest/fuzz/fork_fuzz.c @@ -0,0 +1,55 @@ +/* + * Fork-based fuzzing helpers + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "fork_fuzz.h" + + +void counter_shm_init(void) +{ + char *shm_path = g_strdup_printf("/qemu-fuzz-cntrs.%d", getpid()); + int fd = shm_open(shm_path, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + g_free(shm_path); + + if (fd == -1) { + perror("Error: "); + exit(1); + } + if (ftruncate(fd, &__FUZZ_COUNTERS_END - &__FUZZ_COUNTERS_START) == -1) { + perror("Error: "); + exit(1); + } + /* Copy what's in the counter region to the shm.. */ + void *rptr = mmap(NULL , + &__FUZZ_COUNTERS_END - &__FUZZ_COUNTERS_START, + PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + memcpy(rptr, + &__FUZZ_COUNTERS_START, + &__FUZZ_COUNTERS_END - &__FUZZ_COUNTERS_START); + + munmap(rptr, &__FUZZ_COUNTERS_END - &__FUZZ_COUNTERS_START); + + /* And map the shm over the counter region */ + rptr = mmap(&__FUZZ_COUNTERS_START, + &__FUZZ_COUNTERS_END - &__FUZZ_COUNTERS_START, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, 0); + + close(fd); + + if (!rptr) { + perror("Error: "); + exit(1); + } +} + + diff --git a/tests/qtest/fuzz/fork_fuzz.h b/tests/qtest/fuzz/fork_fuzz.h new file mode 100644 index 0000000000..9ecb8b58ef --- /dev/null +++ b/tests/qtest/fuzz/fork_fuzz.h @@ -0,0 +1,23 @@ +/* + * Fork-based fuzzing helpers + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef FORK_FUZZ_H +#define FORK_FUZZ_H + +extern uint8_t __FUZZ_COUNTERS_START; +extern uint8_t __FUZZ_COUNTERS_END; + +void counter_shm_init(void); + +#endif + diff --git a/tests/qtest/fuzz/fork_fuzz.ld b/tests/qtest/fuzz/fork_fuzz.ld new file mode 100644 index 0000000000..b23a59f194 --- /dev/null +++ b/tests/qtest/fuzz/fork_fuzz.ld @@ -0,0 +1,37 @@ +/* We adjust linker script modification to place all of the stuff that needs to + * persist across fuzzing runs into a contiguous seciton of memory. Then, it is + * easy to re-map the counter-related memory as shared. +*/ + +SECTIONS +{ + .data.fuzz_start : ALIGN(4K) + { + __FUZZ_COUNTERS_START = .; + __start___sancov_cntrs = .; + *(_*sancov_cntrs); + __stop___sancov_cntrs = .; + + /* Lowest stack counter */ + *(__sancov_lowest_stack); + } + .data.fuzz_ordered : + { + /* Coverage counters. They're not necessary for fuzzing, but are useful + * for analyzing the fuzzing performance + */ + __start___llvm_prf_cnts = .; + *(*llvm_prf_cnts); + __stop___llvm_prf_cnts = .; + + /* Internal Libfuzzer TracePC object which contains the ValueProfileMap */ + FuzzerTracePC*(.bss*); + } + .data.fuzz_end : ALIGN(4K) + { + __FUZZ_COUNTERS_END = .; + } +} +/* Dont overwrite the SECTIONS in the default linker script. Instead insert the + * above into the default script */ +INSERT AFTER .data; From patchwork Mon Jan 20 05:55:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 028A417EA for ; Mon, 20 Jan 2020 06:11:23 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD3CA2073A for ; Mon, 20 Jan 2020 06:11:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="d5veXLEu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD3CA2073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQHR-0000dP-F0 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:11:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35365) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1h-0007Hf-3U for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1f-0006Sv-22 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:04 -0500 Received: from mail-bn7nam10on2122.outbound.protection.outlook.com ([40.107.92.122]:57128 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1e-0006Sd-Sn for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:03 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ut4Cru+uWTe3eh5CFMqZgvz2pvi/2BxSeEQYA5rREkl30im2/2Gja1gg5YlP2zb0rILI/JX0UDUSZZqfz1SjaU+GMPxa1PV2oeBbYqoOG0XpTRUTy70BIM4DDfMJlEcrI07oFFMmilBS8NoSecGz964qpttGNA5WwaR4yzXYzgaWSCqv8jruM7GhDdx5gxBs5w1dEhJCEqoHn+mYex+FzIzueLt7OMYDF3a6IX0bZS69lYFayE6YP7sdmqdFtcmn3dy+74E9iVJjFpflTbvfzOcV8i1dR68tESE9qqg+56xITgG7fgs0uPeXia75tw9FjrbScSBAh+iZDWeDYJ68tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K3/v88HWAuWAPx4PQlybO5l5a9/rWxQ9WHHkxquveJY=; b=alx7jJtK8TVbhi0rVbuHjSmpZzoDCOfOnhmALX2syN/Y8CMtqeWDWGS0ciNICqDITVF5Ih6Ek4knGV9eDwU+myRGsQxBFGwCAuUEyoLIJW+JpiipraEgUxLex2ZYHqM6eLqMlDH0gAGRLk2T/cEmHPfDQhf9OcANPFyY+QO1AA2BHkkpxTsejr/kuXbyY5HwfjVYlB7+wSglF6wcSEibUxPBvhCanXbvIj2Qjh6KsiSuwjutnEk/DMCFyAnVqdVWFI6dJxB9XWc6Wfc+zSBMdXAIRGogLxqHVsLzLd+KdTca9ctWkV5vhgt0LyQI9TpW2t5gCzGqtXXlrcGpJMcm7Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K3/v88HWAuWAPx4PQlybO5l5a9/rWxQ9WHHkxquveJY=; b=d5veXLEuMetrN6xxyfYd+2y2Ue8WnVRU/y0kUVp3zML6vux5isrDgm8h7QdibnGBQ/lHKs6o/pDb5/w4+XXzyrBGaoFYby3yw9bjriW/GKzRIYc2NV4Fwm7tTuVrsyVoStJrpR+Pkdf7vCcX2Z8r338nQjjxwPJh+wHn6BdeBGE= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:01 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:01 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:01 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 14/20] fuzz: add support for qos-assisted fuzz targets Thread-Topic: [PATCH v7 14/20] fuzz: add support for qos-assisted fuzz targets Thread-Index: AQHVz1YnOj+xCYNAl06oCwVpnFIxuw== Date: Mon, 20 Jan 2020 05:55:01 +0000 Message-ID: <20200120055410.22322-20-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 790c33d7-1d84-4395-b163-08d79d6d49f9 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3276; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003)(2004002); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: so09w5CLEzUTWc0oz94NVd5WAOzoqC8c0B3hIlEzzwNxFzW99+xSCK5xsPZ+/GakCoPaYRV9v5ddBfls4sAWEDN5Bzwj3N7G24ixUjYVa12lrZUNBZZzkNm1qzS6UqDl9CQ36w7tTpIqYADPX7DtFa8mcD/NxObpV+s5TVdfhw1KJcSdNSs0YQrnJhbf8Y+888DO+/j2dCO1iVYQvw72QysqeT+3Wd0NUX7roWtVB9Uo135pNh8UsvKRb3O94kwu77fT2W3CAj7CWZQI8DMYIzAcQiVV/MhT5y857aVf3/Q37CTOecsmDsu/ZhCDkDnEnGrZKaWk0qaxqalx/u/Kz45M1pdddQWg7sQJWwKUumkNVUvJf9h1Z/R/OwmdrB5YU7hrPoCeeJvrr9cLm8I+tYNibafQlP8V05bygFXNrRUfcYjc66ZOjbVIgibvSrWdpQeK2j6Eaq+PeCDbxMjBvJ+2MnTuAFRGjhCLtZUos1k8REDnM3rIPtnvKRhom4mOXS0cHmCQNgQeU9SJOaDXRwERNPTN8EMihVfYLsFruMb+FUmkBH66qACEoHyu7Jc1 MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 790c33d7-1d84-4395-b163-08d79d6d49f9 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:01.7279 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: C4ANWNvcaDrrXurlV1L+YVfnoatiTJuyfyiGl6f3HoBEqL6Yl1RHcnQtJ71EJn3z X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.122 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 2 + tests/qtest/fuzz/qos_fuzz.c | 229 ++++++++++++++++++++++++++++++ tests/qtest/fuzz/qos_fuzz.h | 33 +++++ 3 files changed, 264 insertions(+) create mode 100644 tests/qtest/fuzz/qos_fuzz.c create mode 100644 tests/qtest/fuzz/qos_fuzz.h diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index a90915d56d..e3bdd33ff4 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -1,8 +1,10 @@ QEMU_PROG_FUZZ=qemu-fuzz-$(TARGET_NAME)$(EXESUF) fuzz-obj-y += tests/qtest/libqtest.o +fuzz-obj-y += $(libqos-obj-y) fuzz-obj-y += tests/qtest/fuzz/fuzz.o # Fuzzer skeleton fuzz-obj-y += tests/qtest/fuzz/fork_fuzz.o +fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/qos_fuzz.c b/tests/qtest/fuzz/qos_fuzz.c new file mode 100644 index 0000000000..efdcc6e9d3 --- /dev/null +++ b/tests/qtest/fuzz/qos_fuzz.c @@ -0,0 +1,229 @@ +/* + * QOS-assisted fuzzing helpers + * + * Copyright (c) 2018 Emanuele Giuseppe Esposito + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "qemu/osdep.h" +#include "qemu/units.h" +#include "qapi/error.h" +#include "qemu-common.h" +#include "exec/memory.h" +#include "exec/address-spaces.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" + +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/malloc.h" +#include "tests/qtest/libqos/qgraph.h" +#include "tests/qtest/libqos/qgraph_internal.h" +#include "tests/qtest/libqos/qos_external.h" + +#include "fuzz.h" +#include "qos_fuzz.h" + +#include "qapi/qapi-commands-machine.h" +#include "qapi/qapi-commands-qom.h" +#include "qapi/qmp/qlist.h" + + +void *fuzz_qos_obj; +QGuestAllocator *fuzz_qos_alloc; + +static const char *fuzz_target_name; +static char **fuzz_path_vec; + +/* + * Replaced the qmp commands with direct qmp_marshal calls. + * Probably there is a better way to do this + */ +static void qos_set_machines_devices_available(void) +{ + QDict *req = qdict_new(); + QObject *response; + QDict *args = qdict_new(); + QList *lst; + Error *err = NULL; + + qmp_marshal_query_machines(NULL, &response, &err); + assert(!err); + lst = qobject_to(QList, response); + apply_to_qlist(lst, true); + + qobject_unref(response); + + + qdict_put_str(req, "execute", "qom-list-types"); + qdict_put_str(args, "implements", "device"); + qdict_put_bool(args, "abstract", true); + qdict_put_obj(req, "arguments", (QObject *) args); + + qmp_marshal_qom_list_types(args, &response, &err); + assert(!err); + lst = qobject_to(QList, response); + apply_to_qlist(lst, false); + qobject_unref(response); + qobject_unref(req); +} + +static char **current_path; + +void *qos_allocate_objects(QTestState *qts, QGuestAllocator **p_alloc) +{ + return allocate_objects(qts, current_path + 1, p_alloc); +} + +static const char *qos_build_main_args(void) +{ + char **path = fuzz_path_vec; + QOSGraphNode *test_node; + GString *cmd_line = g_string_new(path[0]); + void *test_arg; + + /* Before test */ + current_path = path; + test_node = qos_graph_get_node(path[(g_strv_length(path) - 1)]); + test_arg = test_node->u.test.arg; + if (test_node->u.test.before) { + test_arg = test_node->u.test.before(cmd_line, test_arg); + } + /* Prepend the arguments that we need */ + g_string_prepend(cmd_line, + TARGET_NAME " -display none -machine accel=qtest -m 64 "); + return cmd_line->str; +} + +/* + * This function is largely a copy of qos-test.c:walk_path. Since walk_path + * is itself a callback, its a little annoying to add another argument/layer of + * indirection + */ +static void walk_path(QOSGraphNode *orig_path, int len) +{ + QOSGraphNode *path; + QOSGraphEdge *edge; + + /* etype set to QEDGE_CONSUMED_BY so that machine can add to the command line */ + QOSEdgeType etype = QEDGE_CONSUMED_BY; + + /* twice QOS_PATH_MAX_ELEMENT_SIZE since each edge can have its arg */ + char **path_vec = g_new0(char *, (QOS_PATH_MAX_ELEMENT_SIZE * 2)); + int path_vec_size = 0; + + char *after_cmd, *before_cmd, *after_device; + GString *after_device_str = g_string_new(""); + char *node_name = orig_path->name, *path_str; + + GString *cmd_line = g_string_new(""); + GString *cmd_line2 = g_string_new(""); + + path = qos_graph_get_node(node_name); /* root */ + node_name = qos_graph_edge_get_dest(path->path_edge); /* machine name */ + + path_vec[path_vec_size++] = node_name; + path_vec[path_vec_size++] = qos_get_machine_type(node_name); + + for (;;) { + path = qos_graph_get_node(node_name); + if (!path->path_edge) { + break; + } + + node_name = qos_graph_edge_get_dest(path->path_edge); + + /* append node command line + previous edge command line */ + if (path->command_line && etype == QEDGE_CONSUMED_BY) { + g_string_append(cmd_line, path->command_line); + g_string_append(cmd_line, after_device_str->str); + g_string_truncate(after_device_str, 0); + } + + path_vec[path_vec_size++] = qos_graph_edge_get_name(path->path_edge); + /* detect if edge has command line args */ + after_cmd = qos_graph_edge_get_after_cmd_line(path->path_edge); + after_device = qos_graph_edge_get_extra_device_opts(path->path_edge); + before_cmd = qos_graph_edge_get_before_cmd_line(path->path_edge); + edge = qos_graph_get_edge(path->name, node_name); + etype = qos_graph_edge_get_type(edge); + + if (before_cmd) { + g_string_append(cmd_line, before_cmd); + } + if (after_cmd) { + g_string_append(cmd_line2, after_cmd); + } + if (after_device) { + g_string_append(after_device_str, after_device); + } + } + + path_vec[path_vec_size++] = NULL; + g_string_append(cmd_line, after_device_str->str); + g_string_free(after_device_str, true); + + g_string_append(cmd_line, cmd_line2->str); + g_string_free(cmd_line2, true); + + /* + * here position 0 has /, position 1 has . + * The path must not have the , qtest_add_data_func adds it. + */ + path_str = g_strjoinv("/", path_vec + 1); + + /* Check that this is the test we care about: */ + char *test_name = strrchr(path_str, '/') + 1; + if (strcmp(test_name, fuzz_target_name) == 0) { + /* + * put arch/machine in position 1 so run_one_test can do its work + * and add the command line at position 0. + */ + path_vec[1] = path_vec[0]; + path_vec[0] = g_string_free(cmd_line, false); + + fuzz_path_vec = path_vec; + } else { + g_free(path_vec); + } + + g_free(path_str); +} + +static const char *qos_get_cmdline(FuzzTarget *t) +{ + /* + * Set a global variable that we use to identify the qos_path for our + * fuzz_target + */ + fuzz_target_name = t->name; + qos_set_machines_devices_available(); + qos_graph_foreach_test_path(walk_path); + return qos_build_main_args(); +} + +void fuzz_add_qos_target( + FuzzTarget *fuzz_opts, + const char *interface, + QOSGraphTestOptions *opts + ) +{ + qos_add_test(fuzz_opts->name, interface, NULL, opts); + fuzz_opts->get_init_cmdline = qos_get_cmdline; + fuzz_add_target(fuzz_opts); +} + +void qos_init_path(QTestState *s) +{ + fuzz_qos_obj = qos_allocate_objects(s , &fuzz_qos_alloc); +} diff --git a/tests/qtest/fuzz/qos_fuzz.h b/tests/qtest/fuzz/qos_fuzz.h new file mode 100644 index 0000000000..477f11b02b --- /dev/null +++ b/tests/qtest/fuzz/qos_fuzz.h @@ -0,0 +1,33 @@ +/* + * QOS-assisted fuzzing helpers + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#ifndef _QOS_FUZZ_H_ +#define _QOS_FUZZ_H_ + +#include "tests/qtest/fuzz/fuzz.h" +#include "tests/qtest/libqos/qgraph.h" + +int qos_fuzz(const unsigned char *Data, size_t Size); +void qos_setup(void); + +extern void *fuzz_qos_obj; +extern QGuestAllocator *fuzz_qos_alloc; + +void fuzz_add_qos_target( + FuzzTarget *fuzz_opts, + const char *interface, + QOSGraphTestOptions *opts + ); + +void qos_init_path(QTestState *); + +#endif From patchwork Mon Jan 20 05:55:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341039 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EF522924 for ; Mon, 20 Jan 2020 06:04:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C584C2073D for ; Mon, 20 Jan 2020 06:04:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="J3IaHCAE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C584C2073D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQAR-0000It-4h for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:04:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35391) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1j-0007Kv-BV for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1g-0006Tf-01 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:07 -0500 Received: from mail-bn7nam10on2111.outbound.protection.outlook.com ([40.107.92.111]:18623 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1f-0006TL-QT for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:03 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GQFiWZmVVxzkY2oALYFK6NE35iqduQU6wTJoacKXw0K2SUunz3LQdPN3/bMoWY+4sAhCYyvslFO265AEzFPmWPND9Wx+f9BnscDw9/x3d06z37jYO8ahxP29jU2K0tj+zzB7d6uxe5eDD2AE0hH7RWx/SGnzJKjs+qpji+Oen+/bh8PGSvUBtBndZhD/jJ+4+kIQCPCguGT6QBRnqpx+S65wFvCjzeqTkZXwQ4A1eklnVUx47YZLskNoQ3IDq5NpVHZ+x25/oL2oEb8O/zlZCGNcZkQ9mfmLiOmpbN77qBD5mg/G+XCtkbQ5bzrtg+fIZVY6RFUT3BThi0TcnziGww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FfY1+16kphmDJ7KfW3C1Len7PaAQLoDr0wlMmfRhp+w=; b=G59Fnu5/L7+aMQ+qKEeNJVh7tlIW0RvdHWGmQfPmwqkgKZpC6EpvE450kAlh6l7Ed6WX7XgD55BK4ONTvh0K/L895ZWCiKCxSwAh7HDgMXQSOHRylrdnrGgmeVglzH+5u8Cp9YX8b71h7Z6a0B6/go6ol3IAV59MTWZbjlfRrWyUwnYWZCoPG9LwgtBM6z1NUba3BXMTHmoY/0n45YMWWqmA3lAIMvTmlyxP53h+YuJyr/jQBRwknRIxom0CYVlaadEN8xxiMndBDFPpkMn3OYKe848AL6mdjmjzadtEnXwlrCQPrzh6RMz6zeN5hoRnsK2p40q0iH30LOuPyYIWjw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FfY1+16kphmDJ7KfW3C1Len7PaAQLoDr0wlMmfRhp+w=; b=J3IaHCAE2gIW49KoTbtsSMPiaVdTwJKP0Zk2vXAoYbyRcreubE+ZYM73ncqH21FkbgO7cTwy3Ak04vr5HQEP306N+B9NY++DXhl4VE5WY11FDF1NfLnxpwqS5NEcj83Xxtvg626n2eg98qqAGwiq7q7nLKMeguzBYPhCkJy1oSs= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:03 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:03 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:01 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 15/20] fuzz: add target/fuzz makefile rules Thread-Topic: [PATCH v7 15/20] fuzz: add target/fuzz makefile rules Thread-Index: AQHVz1YozqjYdhj3yUy1KAakuF80Pw== Date: Mon, 20 Jan 2020 05:55:02 +0000 Message-ID: <20200120055410.22322-21-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 100b29b4-6c82-4aa4-033a-08d79d6d4a84 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:478; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 1Tus7UVIvX3P08BshOIS4GYbkT+CetiMeLONwOE3Nx29pLG81eT8EUwVsgxOPEUjSVBkv9sC7As+06s/BKk4xxaazieAbj5SCR0S0y41NApWJTD1qI8xRhefKvFOQbXQPlTH/otZ7W4QGlZKRtd6xyX9MedN0rueaDFEn8dzsAQ2ZHiLsb8CQBvZcASAKY4+zWvnxL1B295LppgAokO9eiVbp6sMVsUNcS81FbFE600Q9jEWGWLU3Qus95f6DQcoq6v/uZRv7BYdQJEFLh8IG6hnpZPLHA71HiEorUMcA0c4lrnHNcjUxFMJYmo/OU5zJsrzusTKj8Trn922lNKrhFuZhDE+cqbtD+DsMiIZ8QOGLprCl7WsokU4Md53G+2y3ZANKXDB5aDCtDCr5LM8wVUjMyOLDs2pC6k7/kWjrzujFexSC8ihJ8E4Oaydl/S/ MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 100b29b4-6c82-4aa4-033a-08d79d6d4a84 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:02.5584 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: SFLvqxpReEiMIDB2vaJRWraOH8xN0Zb32DqUwd9pQT6jVekTdm4aXw7/v8DQwCNG X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.111 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , Darren Kenny , "stefanha@redhat.com" , "Bulekov, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Darren Kenny Reviewed-by: Stefan Hajnoczi --- Makefile | 15 ++++++++++++++- Makefile.objs | 2 +- Makefile.target | 16 ++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index e6de7a47bb..dab291455f 100644 --- a/Makefile +++ b/Makefile @@ -464,7 +464,7 @@ config-host.h-timestamp: config-host.mak qemu-options.def: $(SRC_PATH)/qemu-options.hx $(SRC_PATH)/scripts/hxtool $(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$@") -TARGET_DIRS_RULES := $(foreach t, all clean install, $(addsuffix /$(t), $(TARGET_DIRS))) +TARGET_DIRS_RULES := $(foreach t, all fuzz clean install, $(addsuffix /$(t), $(TARGET_DIRS))) SOFTMMU_ALL_RULES=$(filter %-softmmu/all, $(TARGET_DIRS_RULES)) $(SOFTMMU_ALL_RULES): $(authz-obj-y) @@ -478,6 +478,15 @@ ifdef DECOMPRESS_EDK2_BLOBS $(SOFTMMU_ALL_RULES): $(edk2-decompressed) endif +SOFTMMU_FUZZ_RULES=$(filter %-softmmu/fuzz, $(TARGET_DIRS_RULES)) +$(SOFTMMU_FUZZ_RULES): $(authz-obj-y) +$(SOFTMMU_FUZZ_RULES): $(block-obj-y) +$(SOFTMMU_FUZZ_RULES): $(chardev-obj-y) +$(SOFTMMU_FUZZ_RULES): $(crypto-obj-y) +$(SOFTMMU_FUZZ_RULES): $(io-obj-y) +$(SOFTMMU_FUZZ_RULES): config-all-devices.mak +$(SOFTMMU_FUZZ_RULES): $(edk2-decompressed) + .PHONY: $(TARGET_DIRS_RULES) # The $(TARGET_DIRS_RULES) are of the form SUBDIR/GOAL, so that # $(dir $@) yields the sub-directory, and $(notdir $@) yields the sub-goal @@ -528,6 +537,9 @@ subdir-slirp: slirp/all $(filter %/all, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \ $(qom-obj-y) +$(filter %/fuzz, $(TARGET_DIRS_RULES)): libqemuutil.a $(common-obj-y) \ + $(qom-obj-y) $(crypto-user-obj-$(CONFIG_USER_ONLY)) + ROM_DIRS = $(addprefix pc-bios/, $(ROMS)) ROM_DIRS_RULES=$(foreach t, all clean, $(addsuffix /$(t), $(ROM_DIRS))) # Only keep -O and -g cflags @@ -537,6 +549,7 @@ $(ROM_DIRS_RULES): .PHONY: recurse-all recurse-clean recurse-install recurse-all: $(addsuffix /all, $(TARGET_DIRS) $(ROM_DIRS)) +recurse-fuzz: $(addsuffix /fuzz, $(TARGET_DIRS) $(ROM_DIRS)) recurse-clean: $(addsuffix /clean, $(TARGET_DIRS) $(ROM_DIRS)) recurse-install: $(addsuffix /install, $(TARGET_DIRS)) $(addsuffix /install, $(TARGET_DIRS)): all diff --git a/Makefile.objs b/Makefile.objs index 5ab166fed5..9d87a1009e 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -84,8 +84,8 @@ common-obj-$(CONFIG_FDT) += device_tree.o # qapi common-obj-y += qapi/ - softmmu-obj-y = main.o + endif ####################################################################### diff --git a/Makefile.target b/Makefile.target index 8dcf3dddd8..fd6fe79495 100644 --- a/Makefile.target +++ b/Makefile.target @@ -227,6 +227,22 @@ ifdef CONFIG_TRACE_SYSTEMTAP rm -f *.stp endif +ifdef CONFIG_FUZZ +include $(SRC_PATH)/tests/qtest/fuzz/Makefile.include +include $(SRC_PATH)/tests/qtest/Makefile.include + +fuzz: fuzz-vars +fuzz-vars: QEMU_CFLAGS := $(FUZZ_CFLAGS) $(QEMU_CFLAGS) +fuzz-vars: QEMU_LDFLAGS := $(FUZZ_LDFLAGS) $(QEMU_LDFLAGS) +fuzz-vars: $(QEMU_PROG_FUZZ) +dummy := $(call unnest-vars,, fuzz-obj-y) + + +$(QEMU_PROG_FUZZ): config-devices.mak $(all-obj-y) $(COMMON_LDADDS) $(fuzz-obj-y) + $(call LINK, $(filter-out %.mak, $^)) + +endif + install: all ifneq ($(PROGS),) $(call install-prog,$(PROGS),$(DESTDIR)$(bindir)) From patchwork Mon Jan 20 05:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341067 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 03E6617EA for ; Mon, 20 Jan 2020 06:13:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CE1062077C for ; Mon, 20 Jan 2020 06:13:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="e5anO+0i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE1062077C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQJm-0004Cp-Np for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:13:46 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35389) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1j-0007Ks-83 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1h-0006UK-54 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:07 -0500 Received: from mail-bn7nam10on2106.outbound.protection.outlook.com ([40.107.92.106]:1376 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1h-0006Tr-0W for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:05 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y092sJNmoxdgCWsouClObyaCoG2/Z9ZE0xnW9xetubVe4nUsWbDH/sOlf2mIOe4grVqCOANn2qKHR4bEBM6gy3h8VcRQMdbqy31ScJZxudGKAVrM3372r0QELHHJxvNHo/WzCEdy5pEjFWZMcGz5kmW28v0KvXr6SuMPo4Nik4/vmQlwb9TxToQbg30ia/LrUghiCVFOWzEpyUomxwufZ1Rz4kXoBlqSDjNglmKUvZpIlXk5FgSNEsfC+szUhTkqn7+q0nMEzcStRvN1wmXafbF+7sMyp7rk5prKgJWRpVIl0wA0w2bjEWatNyQgNCmEVivk1gH+rOMkB7k8vEY47w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dvNYeeaXgAhc60bU8SP/MWFwQDDsLlrZP1iRKlujo9A=; b=a4/UdlntJoDcFJJ0qEy5N/4xq0dvMhwOy8/x+s5cSphIyb7uJ1L6ygMlZUSE94g6XHxhrIMBy9cqd+pfJu3zci1b2IXD7ul5gzqrlWsO7tgSQi/he9fcoMh/Z++MUQ6xjLxkW0MywpcYmji2Jnqu5hj4m7lnevD0ruN6qihCKC6pZ/HmC90zh7Ex96G3fJ52R/CNbcxbRyyyDFxJUOB812KleuEe3lZIUT7tMdTFzkUFgfyRKmxArvlYJVHvl1Y8AnzPgH5hvHv9WTvQ4lsD9labSNl4vApzagSoDCdl0Zp9PzquBhFPCFRtdbPPlXgmq7IEJtzketQ1jAA+dnUh5g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dvNYeeaXgAhc60bU8SP/MWFwQDDsLlrZP1iRKlujo9A=; b=e5anO+0iKEhazDS6GENl+VG/Y/b8Dpn0TMXG9dPVdM1ZbZJgK2wBnsC89RsIOq4ClkZjEEShjJoQ9kmtBQ1kXDlgu6Hp+JpTex0dDDJBAvsOPXoj7eV9l+3jcxt+F9BpoT5HwH6+WXRBR5T+jJSmY8wFRF9+u6wJEo7Xn3TQ+I0= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:04 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:04 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:02 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 16/20] fuzz: add configure flag --enable-fuzzing Thread-Topic: [PATCH v7 16/20] fuzz: add configure flag --enable-fuzzing Thread-Index: AQHVz1YogdWBjjfeR0OaAS+bGjs0Eg== Date: Mon, 20 Jan 2020 05:55:03 +0000 Message-ID: <20200120055410.22322-22-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 5a1273b8-fc3d-45c2-e5a4-08d79d6d4af9 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:962; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: iqvuJ03dwg/6pbqNG6QUueOOZmYISa8nAUS9KXQlECexZ3NQhecJoQmyhDmc7pSGM6W5iBC+e4nShYhXsvT/C9ly7sJkgOcdERab6jGKP3f0SyMGsJY54ETcbhdtNPuX9kR2nBxEL7vCQkNkBoL42MPmhw6YZmq4usf+XNs8E3GH8Qcyw1qcXnNktNRAwu8w5cH9FH7UEeIsIb7FgkCFym0tw2AZu3E87tTJJYO4QAK7oR/wE1CU5DT9JM7+3nBO1f4uYrTr7eGMj04kuUTHN2xO968M5NZqre851WvVKuTeH4yS97wmTmtallvTPMz2FWsdG8mJUe3kGFD9zeC5ydvenLfWAJah84t65sWvFY/rYIjfoM5ycxBtGXSSMsYryZRZteE0f4Liertcsxje+noC/tNCv+u+ttsYrpWUFnDaqGJuJG8fdTs9cdR1uSE7 Content-ID: MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 5a1273b8-fc3d-45c2-e5a4-08d79d6d4af9 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:03.5329 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ZoiBYnTKXzXBE28/khl9wdN9oW+lnJAO2wIyMBiSkkKumgY3jNE/xPWMJER5SmGK X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.106 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "pbonzini@redhat.com" , "bsd@redhat.com" , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , "stefanha@redhat.com" , "Bulekov, Alexander" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi Reviewed-by: Philippe Mathieu-Daudé --- configure | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/configure b/configure index 08c3a1c1f0..17aa5d02ee 100755 --- a/configure +++ b/configure @@ -504,6 +504,7 @@ debug_mutex="no" libpmem="" default_devices="yes" plugins="no" +fuzzing="no" supported_cpu="no" supported_os="no" @@ -634,6 +635,15 @@ int main(void) { return 0; } EOF } +write_c_fuzzer_skeleton() { + cat > $TMPC < +#include +int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size); +int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 0; } +EOF +} + if check_define __linux__ ; then targetos="Linux" elif check_define _WIN32 ; then @@ -1540,6 +1550,10 @@ for opt do ;; --disable-containers) use_containers="no" ;; + --enable-fuzzing) fuzzing=yes + ;; + --disable-fuzzing) fuzzing=no + ;; *) echo "ERROR: unknown option $opt" echo "Try '$0 --help' for more information" @@ -5992,6 +6006,15 @@ EOF fi fi +########################################## +# checks for fuzzer +if test "$fuzzing" = "yes" ; then + write_c_fuzzer_skeleton + if compile_prog "$CPU_CFLAGS -Werror -fsanitize=address,fuzzer" ""; then + have_fuzzer=yes + fi +fi + ########################################## # check for libpmem @@ -6576,6 +6599,7 @@ echo "libpmem support $libpmem" echo "libudev $libudev" echo "default devices $default_devices" echo "plugin support $plugins" +echo "fuzzing support $fuzzing" if test "$supported_cpu" = "no"; then echo @@ -7400,6 +7424,16 @@ fi if test "$sheepdog" = "yes" ; then echo "CONFIG_SHEEPDOG=y" >> $config_host_mak fi +if test "$fuzzing" = "yes" ; then + if test "$have_fuzzer" = "yes"; then + FUZZ_LDFLAGS=" -fsanitize=address,fuzzer" + FUZZ_CFLAGS=" -fsanitize=address,fuzzer" + CFLAGS=" -fsanitize=address,fuzzer" + else + error_exit "Your compiler doesn't support -fsanitize=address,fuzzer" + exit 1 + fi +fi if test "$plugins" = "yes" ; then echo "CONFIG_PLUGIN=y" >> $config_host_mak @@ -7502,6 +7536,11 @@ if test "$libudev" != "no"; then echo "CONFIG_LIBUDEV=y" >> $config_host_mak echo "LIBUDEV_LIBS=$libudev_libs" >> $config_host_mak fi +if test "$fuzzing" != "no"; then + echo "CONFIG_FUZZ=y" >> $config_host_mak + echo "FUZZ_CFLAGS=$FUZZ_CFLAGS" >> $config_host_mak + echo "FUZZ_LDFLAGS=$FUZZ_LDFLAGS" >> $config_host_mak +fi if test "$edk2_blobs" = "yes" ; then echo "DECOMPRESS_EDK2_BLOBS=y" >> $config_host_mak From patchwork Mon Jan 20 05:55:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341071 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D8EC413A4 for ; Mon, 20 Jan 2020 06:15:15 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9E0622073A for ; Mon, 20 Jan 2020 06:15:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="bVit6hRi" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9E0622073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59142 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQLC-0006X3-Cz for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:15:14 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35445) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1q-0007Tz-MY for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1j-0006VX-56 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:14 -0500 Received: from mail-bn7nam10on2107.outbound.protection.outlook.com ([40.107.92.107]:56064 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1i-0006V3-V7 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:07 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Odkc+EPPSdhHMCEPye4v/LeEx2rS1dKxmNoAvtvf4F5x8mDi5yjaAbXF41Ekb7Ha7qI9tV3dRLuSt8CwSge20cDfBK6wv3uxEmOjLNO7iTAZalHZi7renqFb1hecslERjh3RDsvSt7kM5tGtcWFsER0HsttnksK+4WSfn55UFWcBm5ZeVPDKR+a3oA0kehbBfzqRuji54SMmXr1wegp7DH6PJpzXbors5D4gQ08Qh74r4wMTcZslT+gTp4zHxURoYUiK+lDmN7Vi3BveE7k9LbodBtxeQ8rI++MVhWoyA3QBXv/Kra1XH+U+6DehkN97BSsQPoqdYB3BQrI5V6dWbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/jacTnSYQO9B6P4X+uTDjis9yDkqwXHMLQYl0ahzxws=; b=C3z7TN0gtsKx19FEn2gsiEEH2+l21LubQO+7uvavKVuWKXlGWGICzagHfl2+v20G4+eQ+enH4jvp3Few7jAzFxkP9eBIhdGv6lgs1tCWI8wbALTtb/+VDhacXYuQ56ab9iJfGhB7YE7derKDER7NYVwXVvtrh7OKIUET8rFQ2FokYP4MbkHm7UwuRcEjE/Klw6VHGRmMLzR4sW9FyAfr3a1Irqsatt4LClKi4Zg4oonuN1BqR1pMsgvxCRuZ05uv0vvBkl53peUnPcxrj/D3F1cyEa7hLcKS382EFb5LonEZccHEmF/JZzaLnite2kxzXqHml+YLhNgcN/4hI3d82Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/jacTnSYQO9B6P4X+uTDjis9yDkqwXHMLQYl0ahzxws=; b=bVit6hRiXrMmC0Z3/hAqSkMWErvWx3R+8DU8CcrTSOidcQhQ/NiBTdMitiNch4/HiR600L/chiZtN1jW8O+4XG8QZZIjKfcBl/ejYvnaWcD6JiEFZoFEJIJZYeVZRdFXPbt3NgYn+95oINNS3//017NC4MI8uYsUgJmwpLXRt9M= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:05 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:05 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:04 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 17/20] fuzz: add i440fx fuzz targets Thread-Topic: [PATCH v7 17/20] fuzz: add i440fx fuzz targets Thread-Index: AQHVz1YpRpqO6qKd7ke6IKkiB7MQ6g== Date: Mon, 20 Jan 2020 05:55:05 +0000 Message-ID: <20200120055410.22322-24-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: e9849722-e91f-457b-20b3-08d79d6d4c57 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3826; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 7l9HcSP1rT6c7j1jr1M0HF44dVDMnNJj0Du5igx2Zkh9+dsyWd69mAoXifQdRSRZWnfbEApuCm+m0tfWUoOPrzDsAIBRHQDaYNG+xzPpYIFJdPQjAjx0xf8PQioKumbqVksj6quCxdT3My7qkCE5Q7gluHd7LRo4GEHNDpXGwMGmBuM3UBJBxQg1gUqPfd8d9Yt58ZFjBBjxPLVHeupWB+A4s3oYJG/jOv5V/bkFZSDvw8nf+Lpvm3gCBpYbc/taGLefWpMLE2AXtF+8gvm732vXFdaUSvYYkR0wSJbOQPDcQrqmnBkJZ2WSZ7OvSaes63elzDanrbBDfaQa7Wt8KDoiJpxqBoGEwjvVw5d9R3G4ZXlHy6g+WELsS2MipX8z9L94YWTxXfMCPWM6pbiGAt2AEmBM+ih6tPZTuuRjnmwkJvY+ey4fF1F/Duafmbwk MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: e9849722-e91f-457b-20b3-08d79d6d4c57 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:05.7077 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: fmVehqvPmCplUcBtzD1Zdtg9eBLNNxqoAAqgG77spiPNQz45YJEHdF3ArkfcTS6w X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.107 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" These three targets should simply fuzz reads/writes to a couple ioports, but they mostly serve as examples of different ways to write targets. They demonstrate using qtest and qos for fuzzing, as well as using rebooting and forking to reset state, or not resetting it at all. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 3 + tests/qtest/fuzz/i440fx_fuzz.c | 178 ++++++++++++++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 tests/qtest/fuzz/i440fx_fuzz.c diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index e3bdd33ff4..38b8cdd9f1 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -6,6 +6,9 @@ fuzz-obj-y += tests/qtest/fuzz/fuzz.o # Fuzzer skeleton fuzz-obj-y += tests/qtest/fuzz/fork_fuzz.o fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o +# Targets +fuzz-obj-y += tests/qtest/fuzz/i440fx_fuzz.o + FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest # Linker Script to force coverage-counters into known regions which we can mark diff --git a/tests/qtest/fuzz/i440fx_fuzz.c b/tests/qtest/fuzz/i440fx_fuzz.c new file mode 100644 index 0000000000..c7791182b8 --- /dev/null +++ b/tests/qtest/fuzz/i440fx_fuzz.c @@ -0,0 +1,178 @@ +/* + * I440FX Fuzzing Target + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "qemu/main-loop.h" +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/pci.h" +#include "tests/qtest/libqos/pci-pc.h" +#include "fuzz.h" +#include "fuzz/qos_fuzz.h" +#include "fuzz/fork_fuzz.h" + + +#define I440FX_PCI_HOST_BRIDGE_CFG 0xcf8 +#define I440FX_PCI_HOST_BRIDGE_DATA 0xcfc + +enum action_id { + WRITEB, + WRITEW, + WRITEL, + READB, + READW, + READL, + ACTION_MAX +}; + +static void i440fx_fuzz_qtest(QTestState *s, + const unsigned char *Data, size_t Size) { + typedef struct QTestFuzzAction { + uint32_t value; + uint8_t id; + uint8_t addr; + } QTestFuzzAction; + QTestFuzzAction a; + + while (Size >= sizeof(a)) { + memcpy(&a, Data, sizeof(a)); + uint16_t addr = a.addr % 2 ? I440FX_PCI_HOST_BRIDGE_CFG : + I440FX_PCI_HOST_BRIDGE_DATA; + switch (a.id % ACTION_MAX) { + case WRITEB: + qtest_outb(s, addr, (uint8_t)a.value); + break; + case WRITEW: + qtest_outw(s, addr, (uint16_t)a.value); + break; + case WRITEL: + qtest_outl(s, addr, (uint32_t)a.value); + break; + case READB: + qtest_inb(s, addr); + break; + case READW: + qtest_inw(s, addr); + break; + case READL: + qtest_inl(s, addr); + break; + } + Size -= sizeof(a); + Data += sizeof(a); + } + flush_events(s); +} + +static void i440fx_fuzz_qos(QTestState *s, + const unsigned char *Data, size_t Size) { + + typedef struct QOSFuzzAction { + uint32_t value; + int devfn; + uint8_t offset; + uint8_t id; + } QOSFuzzAction; + + static QPCIBus *bus; + if (!bus) { + bus = qpci_new_pc(s, fuzz_qos_alloc); + } + + QOSFuzzAction a; + while (Size >= sizeof(a)) { + memcpy(&a, Data, sizeof(a)); + switch (a.id % ACTION_MAX) { + case WRITEB: + bus->config_writeb(bus, a.devfn, a.offset, (uint8_t)a.value); + break; + case WRITEW: + bus->config_writew(bus, a.devfn, a.offset, (uint16_t)a.value); + break; + case WRITEL: + bus->config_writel(bus, a.devfn, a.offset, (uint32_t)a.value); + break; + case READB: + bus->config_readb(bus, a.devfn, a.offset); + break; + case READW: + bus->config_readw(bus, a.devfn, a.offset); + break; + case READL: + bus->config_readl(bus, a.devfn, a.offset); + break; + } + Size -= sizeof(a); + Data += sizeof(a); + } + flush_events(s); +} + +static void i440fx_fuzz_qos_fork(QTestState *s, + const unsigned char *Data, size_t Size) { + if (fork() == 0) { + i440fx_fuzz_qos(s, Data, Size); + _Exit(0); + } else { + wait(NULL); + } +} + +static const char *i440fx_qtest_argv = TARGET_NAME " -machine accel=qtest" + "-m 0 -display none"; +static const char *i440fx_argv(FuzzTarget *t) +{ + return i440fx_qtest_argv; +} + +static void fork_init(void) +{ + counter_shm_init(); +} + +static void register_pci_fuzz_targets(void) +{ + /* Uses simple qtest commands and reboots to reset state */ + fuzz_add_target(&(FuzzTarget){ + .name = "i440fx-qtest-reboot-fuzz", + .description = "Fuzz the i440fx using raw qtest commands and" + "rebooting after each run", + .get_init_cmdline = i440fx_argv, + .fuzz = i440fx_fuzz_qtest}); + + /* Uses libqos and forks to prevent state leakage */ + fuzz_add_qos_target(&(FuzzTarget){ + .name = "i440fx-qos-fork-fuzz", + .description = "Fuzz the i440fx using raw qtest commands and" + "rebooting after each run", + .pre_vm_init = &fork_init, + .fuzz = i440fx_fuzz_qos_fork,}, + "i440FX-pcihost", + &(QOSGraphTestOptions){} + ); + + /* + * Uses libqos. Doesn't do anything to reset state. Note that if we were to + * reboot after each run, we would also have to redo the qos-related + * initialization (qos_init_path) + */ + fuzz_add_qos_target(&(FuzzTarget){ + .name = "i440fx-qos-noreset-fuzz", + .description = "Fuzz the i440fx using raw qtest commands and" + "rebooting after each run", + .fuzz = i440fx_fuzz_qos,}, + "i440FX-pcihost", + &(QOSGraphTestOptions){} + ); +} + +fuzz_target_init(register_pci_fuzz_targets); From patchwork Mon Jan 20 05:55:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C5B3E139A for ; Mon, 20 Jan 2020 06:13:22 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8BE622073A for ; Mon, 20 Jan 2020 06:13:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="EevIPBX8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BE622073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQJN-0003ax-KA for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:13:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35444) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1q-0007Tx-LX for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1l-0006Ww-Td for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:14 -0500 Received: from mail-bn7nam10on2137.outbound.protection.outlook.com ([40.107.92.137]:7744 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1l-0006Wd-O6 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:09 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WJMarrCqvyI5uH94AJrL2+vMj/bXMrZzcY5TvrrLm+S+z9Jmg5GOdOJiFGEZyL32BUv7O/QgF4XwxA3pDWbqL0Va3IFSPazCC2TGZhHe/dEg5Sedm0F4wKSMHz2Vr0dmqmTUrGSMJ7yvoGIktkmDiVCSqwcyjx4rhpk9qtUPunIF+UeA6D/TL7mZk4AEOIwpy06O9Gv86JHDhopnXgp7wkwhR1QWdFGBnaqWv9Yb7nd6PjJXCqivUQC/vLgjZCB2dGVLZFsLnCq7Pzh8FVCyx1fjOb7jadSZL3qZidrEHhUVQWXXjew9u6frlY76RkBpX+CFOJcsHqlr0JiunqDVzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K9nZbM1cHG8+T2w6lWAIJ8R9dKsYeRQJZHQu6VGGuXI=; b=CYeQXP7W0mIvwGUtXC7iHnu4b6KLCtqUeeP5pV58J0q8911lLIjJTtJy+QBQUkCD6cP5I/iew3FFiwUAGJASMc+4zXvPasSv1UTKxV4zdMTryBqJgSTaZ+KNTmRoTOQMKLm4IL/VmoAmOW5eHyC/I0GhZj0hF7DLEMGtZ/PSxaSI1is7ydDVZ+1pRC1edOGXTHE+k1uBYmI4yWsYQmIla3URDz4xs7TZ4oNUbG41WIGUfv4ibbg43FJNDEzWOtFKZZSgX8ZLVd+6i+Ui3cz3bIuu1Ew+LWjntmGR0dLpZMGXTSu6FRgu498Hv8Ftivll5UBEzynWh3JI1m2UiXqB8g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=K9nZbM1cHG8+T2w6lWAIJ8R9dKsYeRQJZHQu6VGGuXI=; b=EevIPBX8Xp5cE5QO81X6WeowKSzvIscjZJIeT2VcUSp3awOqq2ckeB1qtKV984gtoacRm21MPWMqCYvMo1CiF7HckrJFmV16ExVKf50V7S/IIiu9fKNxSFyZwCUVq7vWQn/SP/6TNH17/E6/jpJBYj4I498NZ6IOOFIBfUj8BSM= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:08 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:08 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:08 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 18/20] fuzz: add virtio-net fuzz target Thread-Topic: [PATCH v7 18/20] fuzz: add virtio-net fuzz target Thread-Index: AQHVz1YrCuOUdpnUh0q1DYVR7GBu5w== Date: Mon, 20 Jan 2020 05:55:08 +0000 Message-ID: <20200120055410.22322-26-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 26a23474-76e1-4b37-dcfa-08d79d6d4e43 x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2399; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ko1rOK1uRYLWpk8vrmFkCcQZWuJcsjija0MbBI6MjXe58ue62c4Mi2RPIYyd3FdcZGdUNYucHxfF1u33Wq17v2d+uHO/9iu2+hwDS5rT8WwNkcLW5Pc5U/x4fd5ZuRYYQhXd/17Z+DExCCCk4QMstOtcK/wDxFX/8DJyWevQSVqj3TpmiYAzD7wn/pW0aK8OY4TNdF65H6RpPpc2b2ZNHNky8txT+j6JmtPR1Ns60qGfwWD3Sqmuj3+S65ZbsZ40R3VrL14o/V5PgZiEOJjxQVm8mE3H/NlqSRm922UhsjbW7OX2RVmDlp10D2ohScdnDV/zcLbebJGY5X7/il0pipOJlv7ajXSzffIhB2n3pjr7Ru+mehS6lqhuNiX6g4e6yIMFrX3qinX4JBank2DLMh3UPyerNZ5SzV2z3R9Wa5fmjPG7+fr5+VS1m4nzo1zd MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 26a23474-76e1-4b37-dcfa-08d79d6d4e43 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:08.7700 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: GpyoylSEj0QeHzKHUqsmOYa+jgKEswFMyulDt4TfdBDqMS23tCueQQLx1r4bYUls X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.137 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The virtio-net fuzz target feeds inputs to all three virtio-net virtqueues, and uses forking to avoid leaking state between fuzz runs. Signed-off-by: Alexander Bulekov --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_net_fuzz.c | 190 +++++++++++++++++++++++++++++ 2 files changed, 191 insertions(+) create mode 100644 tests/qtest/fuzz/virtio_net_fuzz.c diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index 38b8cdd9f1..77385777ef 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -8,6 +8,7 @@ fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o # Targets fuzz-obj-y += tests/qtest/fuzz/i440fx_fuzz.o +fuzz-obj-y += tests/qtest/fuzz/virtio_net_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/virtio_net_fuzz.c b/tests/qtest/fuzz/virtio_net_fuzz.c new file mode 100644 index 0000000000..3b1b79fd93 --- /dev/null +++ b/tests/qtest/fuzz/virtio_net_fuzz.c @@ -0,0 +1,190 @@ +/* + * virtio-net Fuzzing Target + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/virtio-net.h" +#include "fuzz.h" +#include "fork_fuzz.h" +#include "qos_fuzz.h" + +#define QVIRTIO_NET_TIMEOUT_US (30 * 1000 * 1000) +#define QVIRTIO_RX_VQ 0 +#define QVIRTIO_TX_VQ 1 +#define QVIRTIO_CTRL_VQ 2 + +#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40 + +static int *sv; + +static void virtio_net_fuzz_multi(QTestState *s, + const unsigned char *Data, size_t Size, bool check_used) +{ + typedef struct vq_action { + uint8_t queue; + uint8_t length; + uint8_t write; + uint8_t next; + uint8_t rx; + } vq_action; + + uint32_t free_head = 0; + + QGuestAllocator *t_alloc = fuzz_qos_alloc; + + QVirtioNet *net_if = fuzz_qos_obj; + QVirtioDevice *dev = net_if->vdev; + QVirtQueue *q; + vq_action vqa; + while (Size >= sizeof(vqa)) { + memcpy(&vqa, Data, sizeof(vqa)); + Data += sizeof(vqa); + Size -= sizeof(vqa); + + q = net_if->queues[vqa.queue % 3]; + + vqa.length = vqa.length >= Size ? Size : vqa.length; + if (vqa.rx && sv) { + write(sv[0], Data, vqa.length); + } else { + vqa.rx = 0; + uint64_t req_addr = guest_alloc(t_alloc, vqa.length); + /* + * If checking used ring, ensure that the fuzzer doesn't trigger + * trivial asserion failure on zero-zied buffer + */ + qtest_memwrite(s, req_addr, Data, vqa.length); + + + free_head = qvirtqueue_add(s, q, req_addr, vqa.length, + vqa.write, vqa.next); + qvirtqueue_add(s, q, req_addr, vqa.length, vqa.write , vqa.next); + qvirtqueue_kick(s, dev, q, free_head); + } + + /* + * normally, we could just use qvirtio_wait_used_elem, but since we + * must manually run the main-loop for all the bhs to run, we use + * this hack with flush_events(), to run the main_loop + */ + gint64 start_time = g_get_monotonic_time(); + for (;;) { + /* Run the main loop */ + qtest_clock_step(s, 100); + flush_events(s); + /* Poll the used vring only if we added to the TX or CTRL vq */ + if (check_used && !vqa.rx && q != net_if->queues[QVIRTIO_RX_VQ]) { + uint32_t got_desc_idx; + /* Input led to a virtio_error */ + if (dev->bus->get_status(dev) & VIRTIO_CONFIG_S_NEEDS_RESET) { + break; + } + if (dev->bus->get_queue_isr_status(dev, q) && + qvirtqueue_get_buf(s, q, &got_desc_idx, NULL)) { + g_assert_cmpint(got_desc_idx, ==, free_head); + break; + } + g_assert(g_get_monotonic_time() - start_time + <= QVIRTIO_NET_TIMEOUT_US); + } else { + break; + } + } + Data += vqa.length; + Size -= vqa.length; + } +} + +static void virtio_net_fork_fuzz(QTestState *s, + const unsigned char *Data, size_t Size) +{ + if (fork() == 0) { + virtio_net_fuzz_multi(s, Data, Size, false); + flush_events(s); + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_net_fork_fuzz_check_used(QTestState *s, + const unsigned char *Data, size_t Size) +{ + if (fork() == 0) { + virtio_net_fuzz_multi(s, Data, Size, true); + flush_events(s); + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_net_pre_fuzz(QTestState *s) +{ + qos_init_path(s); + counter_shm_init(); +} + +static void *virtio_net_test_setup_socket(GString *cmd_line, void *arg) +{ + if (!sv) { + sv = g_new(int, 2); + int ret = socketpair(PF_UNIX, SOCK_STREAM, 0, sv); + fcntl(sv[0], F_SETFL, O_NONBLOCK); + g_assert_cmpint(ret, !=, -1); + } + g_string_append_printf(cmd_line, " -netdev socket,fd=%d,id=hs0 ", sv[1]); + return arg; +} + +static void *virtio_net_test_setup_user(GString *cmd_line, void *arg) +{ + g_string_append_printf(cmd_line, " -netdev user,id=hs0 "); + return arg; +} + +static void register_virtio_net_fuzz_targets(void) +{ + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-net-socket", + .description = "Fuzz the virtio-net virtual queues. Fuzz incoming " + "traffic using the socket backend", + .pre_fuzz = &virtio_net_pre_fuzz, + .fuzz = virtio_net_fork_fuzz,}, + "virtio-net", + &(QOSGraphTestOptions){.before = virtio_net_test_setup_socket} + ); + + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-net-socket-check-used", + .description = "Fuzz the virtio-net virtual queues. Wait for the " + "descriptors to be used. Timeout may indicate improperly handled " + "input", + .pre_fuzz = &virtio_net_pre_fuzz, + .fuzz = virtio_net_fork_fuzz_check_used,}, + "virtio-net", + &(QOSGraphTestOptions){.before = virtio_net_test_setup_socket} + ); + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-net-slirp", + .description = "Fuzz the virtio-net virtual queues with the slirp " + " backend. Warning: May result in network traffic emitted from the " + " process. Run in an isolated network environment.", + .pre_fuzz = &virtio_net_pre_fuzz, + .fuzz = virtio_net_fork_fuzz,}, + "virtio-net", + &(QOSGraphTestOptions){.before = virtio_net_test_setup_user} + ); +} + +fuzz_target_init(register_virtio_net_fuzz_targets); From patchwork Mon Jan 20 05:55:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 21B29924 for ; Mon, 20 Jan 2020 06:07:46 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB2A62077C for ; Mon, 20 Jan 2020 06:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="UIMu8aXL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB2A62077C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQDw-0004Pr-Kt for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:07:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35473) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1s-0007VY-CJ for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1q-0006ZH-7Q for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:16 -0500 Received: from mail-bn7nam10on2102.outbound.protection.outlook.com ([40.107.92.102]:54912 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1o-0006Y0-MF for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:12 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q6SJq79RC+HKomv3YkCLbpTdjqhcrhjMJaBxr/MaFmuJz9KNDVrDvYGu0QWNHYnDr0vswRUee8ehKp5uqqaL5vMg6VV1XL5dRumjZPErSA66qeuAiW5QCluq0xt+stdt2PxO3seTzKmwnxR7dspgGC2lXDPS+SacmLw+K1UmFQCG2Wt+SF81RxomwfV0ATDDCRdxd6uRlPhFNmu4VxEAqx9uzUAZtWoyO2GLieNMRVVuG3IVC/UgKYNkEpjoM71vUBsfv1EU/JWxvubnTdh+WQUnjNmMU5oClfxP9or9joTZIdeQWnqZgJJkCucQjBRoUkr8zDef40QIN7lTCPmS1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1iW1YSnhR2Q4tcvdA9noTP2UB1kdSEfm0N7alL1p/I=; b=km7li5FuDyQSQel99cJx3vQ7c3tdsBJS82QMJHbouDptImuqTCTZAbtoWPWwqdiag6Bo6XUNgyvzH/O1lO6704nYB2cDa/DhczhzHk6r8Axy09aHQCBDKsjfEt6c/GXPUfovvrS+Te3rIBfX1mbedXoWeC8o2kUxUGdwFKNSIYCK4pM3gxolmpsKd1cUuXuO0D7mhxy8jjT9vsAlV/SaSxhrWWBl+P/NUHyjt8kW/nMV0CWDUpqVGbZ6ceBanZKkXsXI9V4wh4XtQEMCPbad84TSK33Y4p3Ip5vpWmOdX6cKdWCT7+e+45B0l2EU8hAIMmbeQQR2eF/BUV1hryJO+g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1iW1YSnhR2Q4tcvdA9noTP2UB1kdSEfm0N7alL1p/I=; b=UIMu8aXLblbvnEA7iHIW4nzk3pjSCA/5kh6yXQen/8z3WrlZjHDSgdxASOXqGgXGiKW3hHMWJYjgAeb28KbdePq3fJun5haRL+vgAeF08MlWPAObt0HszWNzmgeH9qLVFG3RbruzghrbdrwLAhrhZY2HI7HMIjt6UMg8FLpi3uo= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:11 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:10 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:09 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 19/20] fuzz: add virtio-scsi fuzz target Thread-Topic: [PATCH v7 19/20] fuzz: add virtio-scsi fuzz target Thread-Index: AQHVz1YscpBbXOe9vEqX83WYFJAEcg== Date: Mon, 20 Jan 2020 05:55:10 +0000 Message-ID: <20200120055410.22322-28-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 66307ed5-4fae-43c3-231d-08d79d6d4f3c x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:317; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(6666004)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bFUFQnnSzkDO3FRLHlCH6386iuMRMUVILQKjkAKWwtKfwjmdYNg2pDuSsM2oroAOGGyezT1Z1NNRBn82BYcwyN46B+RSYd/Z7+B1qQmegX+FsFi9InJWRq2ZDb/ZGq2CuHKUICnm+kSBxE7Pgdf+E/KBEPbpaXm2OUdluqp6uTfKyEw6MH97iR5iOaCj8k1ERxNGgqD15+jb2+1rRSHXh2M7lCXBVB4BCxXjV2aJcrecanVG3hzpJKEDyADJqzDHx/sAJUjDMuxTR8hCJg4uE0gRr6m2SXlU3zvaKG6ZD9fiip7o3h0iQg4Ggn8M5HY2AqBtmpzF9GmtOpGCVy8hjRFqcyZy2d8acjomEx1Zc+o6WQJUSF3K8NF/mMWBDFJO/+ON8MZYNGe7cLwVbFrGIYohnEpt4ZpQqfikct5telFJwbrGqZ4pbZat1swso0S4 MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: 66307ed5-4fae-43c3-231d-08d79d6d4f3c X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:10.5700 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: d5MBI8/E5BIsv/fklkQRlHsE6xLk62HdQU64/HIPTvzHKMLtHrGbkDnZkIPUQiN7 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.102 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The virtio-scsi fuzz target sets up and fuzzes the available virtio-scsi queues. After an element is placed on a queue, the fuzzer can select whether to perform a kick, or continue adding elements. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_scsi_fuzz.c | 200 ++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 tests/qtest/fuzz/virtio_scsi_fuzz.c diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index 77385777ef..cde3e9636c 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -9,6 +9,7 @@ fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o # Targets fuzz-obj-y += tests/qtest/fuzz/i440fx_fuzz.o fuzz-obj-y += tests/qtest/fuzz/virtio_net_fuzz.o +fuzz-obj-y += tests/qtest/fuzz/virtio_scsi_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/virtio_scsi_fuzz.c b/tests/qtest/fuzz/virtio_scsi_fuzz.c new file mode 100644 index 0000000000..ee7ca5448c --- /dev/null +++ b/tests/qtest/fuzz/virtio_scsi_fuzz.c @@ -0,0 +1,200 @@ +/* + * virtio-serial Fuzzing Target + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/virtio-net.h" +#include "libqos/virtio-scsi.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_scsi.h" +#include "fuzz.h" +#include "fork_fuzz.h" +#include "qos_fuzz.h" + +#define PCI_SLOT 0x02 +#define PCI_FN 0x00 +#define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000) + +#define MAX_NUM_QUEUES 64 + +/* Based on tests/virtio-scsi-test.c */ +typedef struct { + int num_queues; + QVirtQueue *vq[MAX_NUM_QUEUES + 2]; +} QVirtioSCSIQueues; + +static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevice *dev, uint64_t mask) +{ + QVirtioSCSIQueues *vs; + uint64_t feat; + int i; + + vs = g_new0(QVirtioSCSIQueues, 1); + + feat = qvirtio_get_features(dev); + if (mask) { + feat &= ~QVIRTIO_F_BAD_FEATURE | mask; + } else { + feat &= ~(QVIRTIO_F_BAD_FEATURE | (1ull << VIRTIO_RING_F_EVENT_IDX)); + } + qvirtio_set_features(dev, feat); + + vs->num_queues = qvirtio_config_readl(dev, 0); + + for (i = 0; i < vs->num_queues + 2; i++) { + vs->vq[i] = qvirtqueue_setup(dev, fuzz_qos_alloc, i); + } + + qvirtio_set_driver_ok(dev); + + return vs; +} + +static void virtio_scsi_fuzz(QTestState *s, QVirtioSCSIQueues* queues, + const unsigned char *Data, size_t Size) +{ + typedef struct vq_action { + uint8_t queue; + uint8_t length; + uint8_t write; + uint8_t next; + uint8_t kick; + } vq_action; + + uint32_t free_head[MAX_NUM_QUEUES + 2] = {0}; + QGuestAllocator *t_alloc = fuzz_qos_alloc; + + QVirtioSCSI *scsi = fuzz_qos_obj; + QVirtioDevice *dev = scsi->vdev; + QVirtQueue *q; + vq_action vqa; + while (Size >= sizeof(vqa)) { + memcpy(&vqa, Data, sizeof(vqa)); + + Data += sizeof(vqa); + Size -= sizeof(vqa); + + vqa.queue = vqa.queue % queues->num_queues; + vqa.length = vqa.length >= Size ? Size : vqa.length; + vqa.write = vqa.write & 1; + vqa.next = vqa.next & 1; + vqa.kick = vqa.kick & 1; + + + q = queues->vq[vqa.queue]; + + uint64_t req_addr = guest_alloc(t_alloc, vqa.length); + qtest_memwrite(s, req_addr, Data, vqa.length); + if (free_head[vqa.queue] == 0) { + free_head[vqa.queue] = qvirtqueue_add(s, q, req_addr, vqa.length, + vqa.write, vqa.next); + } else { + qvirtqueue_add(s, q, req_addr, vqa.length, vqa.write , vqa.next); + } + + if (vqa.kick) { + qvirtqueue_kick(s, dev, q, free_head[vqa.queue]); + free_head[vqa.queue] = 0; + } + Data += vqa.length; + Size -= vqa.length; + } + for (int i = 0; i < MAX_NUM_QUEUES + 2; i++) { + if (free_head[i]) { + qvirtqueue_kick(s, dev, queues->vq[i], free_head[i]); + } + } +} + +static void virtio_scsi_fork_fuzz(QTestState *s, + const unsigned char *Data, size_t Size) +{ + QVirtioSCSI *scsi = fuzz_qos_obj; + static QVirtioSCSIQueues *queues; + if (!queues) { + queues = qvirtio_scsi_init(scsi->vdev, 0); + } + if (fork() == 0) { + virtio_scsi_fuzz(s, queues, Data, Size); + flush_events(s); + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_scsi_with_flag_fuzz(QTestState *s, + const unsigned char *Data, size_t Size) +{ + QVirtioSCSI *scsi = fuzz_qos_obj; + static QVirtioSCSIQueues *queues; + + if (fork() == 0) { + if (Size >= sizeof(uint64_t)) { + queues = qvirtio_scsi_init(scsi->vdev, *(uint64_t *)Data); + virtio_scsi_fuzz(s, queues, + Data + sizeof(uint64_t), Size - sizeof(uint64_t)); + flush_events(s); + } + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_scsi_pre_fuzz(QTestState *s) +{ + qos_init_path(s); + counter_shm_init(); +} + +static void *virtio_scsi_test_setup(GString *cmd_line, void *arg) +{ + g_string_append(cmd_line, + " -drive file=blkdebug::null-co://," + "file.image.read-zeroes=on," + "if=none,id=dr1,format=raw,file.align=4k " + "-device scsi-hd,drive=dr1,lun=0,scsi-id=1"); + return arg; +} + + +static void register_virtio_scsi_fuzz_targets(void) +{ + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-scsi-fuzz", + .description = "Fuzz the virtio-net virtual queues, forking" + "for each fuzz run", + .pre_vm_init = &counter_shm_init, + .pre_fuzz = &virtio_scsi_pre_fuzz, + .fuzz = virtio_scsi_fork_fuzz,}, + "virtio-scsi", + &(QOSGraphTestOptions){.before = virtio_scsi_test_setup} + ); + + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-scsi-flags-fuzz", + .description = "Fuzz the virtio-net virtual queues, forking" + "for each fuzz run (also fuzzes the virtio flags)", + .pre_vm_init = &counter_shm_init, + .pre_fuzz = &virtio_scsi_pre_fuzz, + .fuzz = virtio_scsi_with_flag_fuzz,}, + "virtio-scsi", + &(QOSGraphTestOptions){.before = virtio_scsi_test_setup} + ); +} + +fuzz_target_init(register_virtio_scsi_fuzz_targets); From patchwork Mon Jan 20 05:55:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Bulekov X-Patchwork-Id: 11341089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B6927139A for ; Mon, 20 Jan 2020 06:21:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A6722073A for ; Mon, 20 Jan 2020 06:21:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=bushare.onmicrosoft.com header.i=@bushare.onmicrosoft.com header.b="zV5RVYOq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A6722073A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bu.edu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:59232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQQp-0004tK-JM for patchwork-qemu-devel@patchwork.kernel.org; Mon, 20 Jan 2020 01:21:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35493) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1itQ1u-0007Xa-Dk for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1itQ1s-0006aj-I5 for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:18 -0500 Received: from mail-bn7nam10on2102.outbound.protection.outlook.com ([40.107.92.102]:54912 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1itQ1s-0006Y0-2a for qemu-devel@nongnu.org; Mon, 20 Jan 2020 00:55:16 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I5SpLqMUS3jCojXlXpOnD9ojLsU9cRWIWXJQRoan0n05XL0ke/B06YYlIoBVWjkfUaUueXuZRbZIWWd1rY7zN2vT9f2k2wmHHxnp2YJ2gmDpIhpYngHk77eP+UX+LBi7cLpvUZkKmr9Lhqb4/pvuZ2iZtK0qt2OLxal/2ewiXg2JIEgJuwhew4HskilMj/c99wFsXaDLmT8+J2A0BMymI8xpi5X9C9iKLJUtQd4fq9TyyOpMHxGshkJhspWv+5n2OJnhLlrpt2V6vxQKxcHPX7kVxD+Z1+x8pZjpDkX5WwKEjUsBPr7KD6d9RWIXRRl1DbERad4rP7Jd/5IcC87FdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1iW1YSnhR2Q4tcvdA9noTP2UB1kdSEfm0N7alL1p/I=; b=JU8vnerje1/+mHl/7Ch+CZk0UQDfaKm5zoth8JeQyBCuv60CfpH2pS1pODcqizvZ8g4SJNc3uGqqFU8e1Ibc7pelsyqh82l7dIgwVjTm611uyWvsH7hrFLL1KPzgIyLr8oPEr+8PcUHLPfRAFPGwb0F8esadZyjDJkVcHOD+r3sBgSpsJW7hMhaWd5SVBeqCelc3R20JH7xs7iBVTeHiKPMo+grIS2ij6nFIbCYqQSNbRWLiO0kfD48/fmnmUR8WFoVM/TXYjgZ7+XenhMuOh6TbDo0NHTbviZbte32K9ugeIljbUaQDpmemwJmD4nKDoXdk8s5T8gOslX0g/zYyEA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=bu.edu; dmarc=pass action=none header.from=bu.edu; dkim=pass header.d=bu.edu; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bushare.onmicrosoft.com; s=selector2-bushare-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=S1iW1YSnhR2Q4tcvdA9noTP2UB1kdSEfm0N7alL1p/I=; b=zV5RVYOqIR/Pq4zUmNHxPwX4Fy3I05pv36sP3Fp5bc+aVJX13yqChvcyvPk/xdIloEJbc5zSLxQTtV5PdpGTKKzGScRchscCWg0avFzwDWmqYWbhnSNlCmlIYjL85SyE5bnGrUmIvM8f1v2sc/rZHX2ZdMTtq3lNvR0b0e00igw= Received: from SN6PR03MB3871.namprd03.prod.outlook.com (52.135.102.32) by SN6PR03MB4399.namprd03.prod.outlook.com (20.178.6.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.23; Mon, 20 Jan 2020 05:55:13 +0000 Received: from SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8]) by SN6PR03MB3871.namprd03.prod.outlook.com ([fe80::9c11:10cd:6e97:bbe8%7]) with mapi id 15.20.2644.024; Mon, 20 Jan 2020 05:55:13 +0000 Received: from mozz.bu.edu (128.197.127.33) by MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2644.20 via Frontend Transport; Mon, 20 Jan 2020 05:55:11 +0000 From: "Bulekov, Alexander" To: "qemu-devel@nongnu.org" Subject: [PATCH v7 20/20] fuzz: add virtio-scsi fuzz target Thread-Topic: [PATCH v7 20/20] fuzz: add virtio-scsi fuzz target Thread-Index: AQHVz1YuZoWWVRJhQUmoP23RVO6eRg== Date: Mon, 20 Jan 2020 05:55:13 +0000 Message-ID: <20200120055410.22322-30-alxndr@bu.edu> References: <20200120055410.22322-1-alxndr@bu.edu> In-Reply-To: <20200120055410.22322-1-alxndr@bu.edu> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.23.0 x-originating-ip: [128.197.127.33] x-clientproxiedby: MN2PR20CA0032.namprd20.prod.outlook.com (2603:10b6:208:e8::45) To SN6PR03MB3871.namprd03.prod.outlook.com (2603:10b6:805:6d::32) authentication-results: spf=none (sender IP is ) smtp.mailfrom=alxndr@bu.edu; x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: bab89e83-6f8c-4655-7a30-08d79d6d507b x-ms-traffictypediagnostic: SN6PR03MB4399: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:317; x-forefront-prvs: 0288CD37D9 x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(4636009)(136003)(366004)(39860400002)(346002)(376002)(396003)(189003)(199004)(5660300002)(956004)(2616005)(8936002)(86362001)(6916009)(6486002)(7696005)(1076003)(52116002)(316002)(71200400001)(16526019)(186003)(786003)(478600001)(2906002)(26005)(81166006)(66946007)(66476007)(64756008)(36756003)(8676002)(75432002)(81156014)(66446008)(4326008)(66556008)(54906003); DIR:OUT; SFP:1102; SCL:1; SRVR:SN6PR03MB4399; H:SN6PR03MB3871.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: bu.edu does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: bkScRJkgYQ7lJgFGTPZDFzv8eLGVNbH8Ss9Q4+GDFZ7aLf+Tkj5F/t1ZroCP4AFU66SZW8LQvyf1KvVe0b1jRYyQ1ruAoqHctf+ALmtZjs3oM7UqLJj1sZftDNrNI6ExdbbVO/6/GlsgXTLLi5YzotE91bR+mfAno+Sv4yStzUDOjfLAiJm3QIcV0J/oFxHV9PcEHmcHBJcDbvh3Bb+YvJ+9b/lB71xjvFbxqloGLPfsQUM5kTmBbXRDQWGGZpglf440HP/tREHD1RvMA/E2uxekZSQMEQCjRY5pjOI9VBiMRVOj40nhldxNZomz+UmRfnMVC+j2eQqEObGxMg3vJJ8oTupMJ4SojjVToMBEdDrQNXwg54BZOYcYXxmHu+IuaCfWPXlq8L3gpRf3Hc9LCCIPm4JJm/jF/hRgcsFAE9HId/EIHgUbw8fDQmjj2cVV MIME-Version: 1.0 X-OriginatorOrg: bu.edu X-MS-Exchange-CrossTenant-Network-Message-Id: bab89e83-6f8c-4655-7a30-08d79d6d507b X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Jan 2020 05:55:13.7662 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: d57d32cc-c121-488f-b07b-dfe705680c71 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: jCW/9BpdpUoJ2KGJ6lZqAP77Ec5twFIg4bWdAPn2hwZOeFaTr0iV0O4k27bqXg04 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR03MB4399 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.92.102 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Thomas Huth , "Bulekov, Alexander" , "bsd@redhat.com" , "stefanha@redhat.com" , "pbonzini@redhat.com" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The virtio-scsi fuzz target sets up and fuzzes the available virtio-scsi queues. After an element is placed on a queue, the fuzzer can select whether to perform a kick, or continue adding elements. Signed-off-by: Alexander Bulekov Reviewed-by: Stefan Hajnoczi --- tests/qtest/fuzz/Makefile.include | 1 + tests/qtest/fuzz/virtio_scsi_fuzz.c | 200 ++++++++++++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 tests/qtest/fuzz/virtio_scsi_fuzz.c diff --git a/tests/qtest/fuzz/Makefile.include b/tests/qtest/fuzz/Makefile.include index 77385777ef..cde3e9636c 100644 --- a/tests/qtest/fuzz/Makefile.include +++ b/tests/qtest/fuzz/Makefile.include @@ -9,6 +9,7 @@ fuzz-obj-y += tests/qtest/fuzz/qos_fuzz.o # Targets fuzz-obj-y += tests/qtest/fuzz/i440fx_fuzz.o fuzz-obj-y += tests/qtest/fuzz/virtio_net_fuzz.o +fuzz-obj-y += tests/qtest/fuzz/virtio_scsi_fuzz.o FUZZ_CFLAGS += -I$(SRC_PATH)/tests -I$(SRC_PATH)/tests/qtest diff --git a/tests/qtest/fuzz/virtio_scsi_fuzz.c b/tests/qtest/fuzz/virtio_scsi_fuzz.c new file mode 100644 index 0000000000..ee7ca5448c --- /dev/null +++ b/tests/qtest/fuzz/virtio_scsi_fuzz.c @@ -0,0 +1,200 @@ +/* + * virtio-serial Fuzzing Target + * + * Copyright Red Hat Inc., 2019 + * + * Authors: + * Alexander Bulekov + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" + +#include "tests/qtest/libqtest.h" +#include "tests/qtest/libqos/virtio-net.h" +#include "libqos/virtio-scsi.h" +#include "libqos/virtio.h" +#include "libqos/virtio-pci.h" +#include "standard-headers/linux/virtio_ids.h" +#include "standard-headers/linux/virtio_pci.h" +#include "standard-headers/linux/virtio_scsi.h" +#include "fuzz.h" +#include "fork_fuzz.h" +#include "qos_fuzz.h" + +#define PCI_SLOT 0x02 +#define PCI_FN 0x00 +#define QVIRTIO_SCSI_TIMEOUT_US (1 * 1000 * 1000) + +#define MAX_NUM_QUEUES 64 + +/* Based on tests/virtio-scsi-test.c */ +typedef struct { + int num_queues; + QVirtQueue *vq[MAX_NUM_QUEUES + 2]; +} QVirtioSCSIQueues; + +static QVirtioSCSIQueues *qvirtio_scsi_init(QVirtioDevice *dev, uint64_t mask) +{ + QVirtioSCSIQueues *vs; + uint64_t feat; + int i; + + vs = g_new0(QVirtioSCSIQueues, 1); + + feat = qvirtio_get_features(dev); + if (mask) { + feat &= ~QVIRTIO_F_BAD_FEATURE | mask; + } else { + feat &= ~(QVIRTIO_F_BAD_FEATURE | (1ull << VIRTIO_RING_F_EVENT_IDX)); + } + qvirtio_set_features(dev, feat); + + vs->num_queues = qvirtio_config_readl(dev, 0); + + for (i = 0; i < vs->num_queues + 2; i++) { + vs->vq[i] = qvirtqueue_setup(dev, fuzz_qos_alloc, i); + } + + qvirtio_set_driver_ok(dev); + + return vs; +} + +static void virtio_scsi_fuzz(QTestState *s, QVirtioSCSIQueues* queues, + const unsigned char *Data, size_t Size) +{ + typedef struct vq_action { + uint8_t queue; + uint8_t length; + uint8_t write; + uint8_t next; + uint8_t kick; + } vq_action; + + uint32_t free_head[MAX_NUM_QUEUES + 2] = {0}; + QGuestAllocator *t_alloc = fuzz_qos_alloc; + + QVirtioSCSI *scsi = fuzz_qos_obj; + QVirtioDevice *dev = scsi->vdev; + QVirtQueue *q; + vq_action vqa; + while (Size >= sizeof(vqa)) { + memcpy(&vqa, Data, sizeof(vqa)); + + Data += sizeof(vqa); + Size -= sizeof(vqa); + + vqa.queue = vqa.queue % queues->num_queues; + vqa.length = vqa.length >= Size ? Size : vqa.length; + vqa.write = vqa.write & 1; + vqa.next = vqa.next & 1; + vqa.kick = vqa.kick & 1; + + + q = queues->vq[vqa.queue]; + + uint64_t req_addr = guest_alloc(t_alloc, vqa.length); + qtest_memwrite(s, req_addr, Data, vqa.length); + if (free_head[vqa.queue] == 0) { + free_head[vqa.queue] = qvirtqueue_add(s, q, req_addr, vqa.length, + vqa.write, vqa.next); + } else { + qvirtqueue_add(s, q, req_addr, vqa.length, vqa.write , vqa.next); + } + + if (vqa.kick) { + qvirtqueue_kick(s, dev, q, free_head[vqa.queue]); + free_head[vqa.queue] = 0; + } + Data += vqa.length; + Size -= vqa.length; + } + for (int i = 0; i < MAX_NUM_QUEUES + 2; i++) { + if (free_head[i]) { + qvirtqueue_kick(s, dev, queues->vq[i], free_head[i]); + } + } +} + +static void virtio_scsi_fork_fuzz(QTestState *s, + const unsigned char *Data, size_t Size) +{ + QVirtioSCSI *scsi = fuzz_qos_obj; + static QVirtioSCSIQueues *queues; + if (!queues) { + queues = qvirtio_scsi_init(scsi->vdev, 0); + } + if (fork() == 0) { + virtio_scsi_fuzz(s, queues, Data, Size); + flush_events(s); + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_scsi_with_flag_fuzz(QTestState *s, + const unsigned char *Data, size_t Size) +{ + QVirtioSCSI *scsi = fuzz_qos_obj; + static QVirtioSCSIQueues *queues; + + if (fork() == 0) { + if (Size >= sizeof(uint64_t)) { + queues = qvirtio_scsi_init(scsi->vdev, *(uint64_t *)Data); + virtio_scsi_fuzz(s, queues, + Data + sizeof(uint64_t), Size - sizeof(uint64_t)); + flush_events(s); + } + _Exit(0); + } else { + wait(NULL); + } +} + +static void virtio_scsi_pre_fuzz(QTestState *s) +{ + qos_init_path(s); + counter_shm_init(); +} + +static void *virtio_scsi_test_setup(GString *cmd_line, void *arg) +{ + g_string_append(cmd_line, + " -drive file=blkdebug::null-co://," + "file.image.read-zeroes=on," + "if=none,id=dr1,format=raw,file.align=4k " + "-device scsi-hd,drive=dr1,lun=0,scsi-id=1"); + return arg; +} + + +static void register_virtio_scsi_fuzz_targets(void) +{ + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-scsi-fuzz", + .description = "Fuzz the virtio-net virtual queues, forking" + "for each fuzz run", + .pre_vm_init = &counter_shm_init, + .pre_fuzz = &virtio_scsi_pre_fuzz, + .fuzz = virtio_scsi_fork_fuzz,}, + "virtio-scsi", + &(QOSGraphTestOptions){.before = virtio_scsi_test_setup} + ); + + fuzz_add_qos_target(&(FuzzTarget){ + .name = "virtio-scsi-flags-fuzz", + .description = "Fuzz the virtio-net virtual queues, forking" + "for each fuzz run (also fuzzes the virtio flags)", + .pre_vm_init = &counter_shm_init, + .pre_fuzz = &virtio_scsi_pre_fuzz, + .fuzz = virtio_scsi_with_flag_fuzz,}, + "virtio-scsi", + &(QOSGraphTestOptions){.before = virtio_scsi_test_setup} + ); +} + +fuzz_target_init(register_virtio_scsi_fuzz_targets);