From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804607; cv=none; d=zohomail.com; s=zohoarc; b=Ywlb9QIhY8imk3RmzHTOcZMVzpcMaK7hELWppK4up6CRxR9hVtSZg5ZFvnhSBycJTmNo0qFWqldG6cj3ZOpcN4jUbwb4Lxo54GcHmNuCDOt8bgzT9UJ3LyVg2omByCiKSlUPa9WZ5VbIbs/vtRzDcCBTo5DCUpUmCtbPYVGnVis= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804607; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tLxHap7xM5B8vl55s/tokESX8SHGpSJI34kzmwiZhNU=; b=Y3FLNGcWnSvEIH6/jZHcliNTlVrp2fnUVefOu3q++Nz+loSEpP2UR6CS8yfh/UJ8D4LygPq9ra/tsBJDwGDvgTCIJwC/bVMpEFLP4eia0Hgothokbx4skfNlWPfksuhyQyMFnuDjMFy+t5ySrsQz3lqeTBeiXpLEiWmnWxYn2XM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591804607692956.9658798533375; Wed, 10 Jun 2020 08:56:47 -0700 (PDT) Received: from localhost ([::1]:35582 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj35q-0005TI-8J for importer@patchew.org; Wed, 10 Jun 2020 11:56:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55888) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34X-0003dN-PN for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:25 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]:37556) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34W-0005AM-MY for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:25 -0400 Received: by mail-wm1-x332.google.com with SMTP id y20so2304512wmi.2 for ; Wed, 10 Jun 2020 08:55:16 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f9sm342176wrf.74.2020.06.10.08.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:11 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 03F691FF87; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tLxHap7xM5B8vl55s/tokESX8SHGpSJI34kzmwiZhNU=; b=sfmFmpRIZczBnvka/HtSZIF3jUzpWQxrunexyGqlPT/x0A18W/WP0oQkrUN4Ssrj4e 67xM/VgP5YByPwzRk2tuxWzRT9+FLaQWeQazsWlENKvJerMlNYpsNh6NB97tCnQVEGZO ScOkgrXZ+hJZosdQEyRHdytgwpzvQ4HHV5lutxpMC7HUPp4SqeNOdWsXsgLoCS4Xiq95 BJN17wvgduR7UkW44+iPhz5HFkM6LUMwHGiJWoC0jxn+6s+NBzBom0cnVKVstZyqdnXQ oQX5yryhzdbI77t0RkaLJGY7SE27vydyDQaBTfd4a6UM55fbTwM8hTW9uoGPAlV6drVO 9NYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tLxHap7xM5B8vl55s/tokESX8SHGpSJI34kzmwiZhNU=; b=J8n4M9YDdlldFfudyIyIDUl1K//Lz+wVAzx473Xp7U4SNmogSelWNKCOu5djhdYb/s svhp7qxE1wB55jQSdcUPTI3ZPy9MkXec6wxhir/a9Z4NNgnJ0z+k72AaPfOwHnFBM6T9 vSc/rSdrMTydofve8YDB+1NwJ/d7mwnoCstJASTZTupvpYXAB6NobtoKpALwpkNxflov WH9UhlLcJL9iYmPmCS0pVgcxST0XTz+80uf3D69w+MQWs1MVL5jIuRM0rOG2F50g1Vb0 4P1Qoylmx9gLghMmjjVP7koLCf2siKCxb6EwcaVz3ca2k8Vz77hyPlxqQYzbYSgzoK3o xBxQ== X-Gm-Message-State: AOAM530re3G35mTLNfCSoLa4VrGwEnbnwGtHJ6/Zv2qdwJIOxqb5O4Dl bvN6j4YERO5wXeR1P6Ice6GxKA== X-Google-Smtp-Source: ABdhPJylBadDa7A7fRrejhAH4mqjWNEQJhdATseCHzzM846Q+mZIvs8qx4I97Slf2cyYrn5vbwfeew== X-Received: by 2002:a05:600c:22c9:: with SMTP id 9mr4143789wmg.68.1591804515275; Wed, 10 Jun 2020 08:55:15 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 1/6] iotests: 194: wait migration completion on target too Date: Wed, 10 Jun 2020 16:55:04 +0100 Message-Id: <20200610155509.12850-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: Kevin Wolf , Thomas Huth , Vladimir Sementsov-Ogievskiy , robert.foley@linaro.org, "open list:Block layer core" , =?UTF-8?q?Alex=20Benn=C3=A9e?= , robhenry@microsoft.com, Max Reitz , aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Vladimir Sementsov-Ogievskiy It is possible, that shutdown on target occurs earlier than migration finish. In this case we crash in bdrv_release_dirty_bitmap_locked() on assertion "assert(!bdrv_dirty_bitmap_busy(bitmap));" as we do have busy bitmap, as bitmap migration is ongoing. We'll fix bitmap migration to gracefully cancel on early shutdown soon. Now let's fix iotest 194 to wait migration completion before shutdown. Note that in this test dest_vm.shutdown() is called implicitly, as vms used as context-providers, see __exit__() method of QEMUMachine class. Actually, not waiting migration finish is a wrong thing, but the test started to crash after commit ae00aa239847682 "iotests: 194: test also migration of dirty bitmap", which added dirty bitmaps here. So, Fixes: tag won't hurt. Fixes: ae00aa2398476824f0eca80461da215e7cdc1c3b Reported-by: Thomas Huth Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Thomas Huth Reviewed-by: Eric Blake Signed-off-by: Alex Benn=C3=A9e Message-Id: <20200604083341.26978-1-vsementsov@virtuozzo.com> --- tests/qemu-iotests/194 | 10 ++++++++++ tests/qemu-iotests/194.out | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194 index 3fad7c6c1ab..6dc2bc94d7e 100755 --- a/tests/qemu-iotests/194 +++ b/tests/qemu-iotests/194 @@ -87,4 +87,14 @@ with iotests.FilePath('source.img') as source_img_path, \ iotests.log(dest_vm.qmp('nbd-server-stop')) break =20 + iotests.log('Wait migration completion on target...') + migr_events =3D (('MIGRATION', {'data': {'status': 'completed'}}), + ('MIGRATION', {'data': {'status': 'failed'}})) + event =3D dest_vm.events_wait(migr_events) + iotests.log(event, filters=3D[iotests.filter_qmp_event]) + + iotests.log('Check bitmaps on source:') iotests.log(source_vm.qmp('query-block')['return'][0]['dirty-bitmaps']) + + iotests.log('Check bitmaps on target:') + iotests.log(dest_vm.qmp('query-block')['return'][0]['dirty-bitmaps']) diff --git a/tests/qemu-iotests/194.out b/tests/qemu-iotests/194.out index dd60dcc14f1..f70cf7610e0 100644 --- a/tests/qemu-iotests/194.out +++ b/tests/qemu-iotests/194.out @@ -21,4 +21,9 @@ Gracefully ending the `drive-mirror` job on source... {"data": {"device": "mirror-job0", "len": 1073741824, "offset": 1073741824= , "speed": 0, "type": "mirror"}, "event": "BLOCK_JOB_COMPLETED", "timestamp= ": {"microseconds": "USECS", "seconds": "SECS"}} Stopping the NBD server on destination... {"return": {}} +Wait migration completion on target... +{"data": {"status": "completed"}, "event": "MIGRATION", "timestamp": {"mic= roseconds": "USECS", "seconds": "SECS"}} +Check bitmaps on source: +[{"busy": false, "count": 0, "granularity": 65536, "name": "bitmap0", "per= sistent": false, "recording": true, "status": "active"}] +Check bitmaps on target: [{"busy": false, "count": 0, "granularity": 65536, "name": "bitmap0", "per= sistent": false, "recording": true, "status": "active"}] --=20 2.20.1 From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804619; cv=none; d=zohomail.com; s=zohoarc; b=j0lpPrGDkKMlgW6BfAvo3G+jCQDEFwIF7uJBOekA0lX2yeCb0Je+zB5g4Z5efeInddXp7kPLfsGqvI1fL0dJAfrhB/9re/piY6SKHrrlJRGprB6PdQrX7RP0qHVpdUnNvjTWqSPDu8UwbsHHCIfZD1uKpRybhOXgiLe8nDrMc6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804619; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t6TltwBrO/H4+UuBeh2Az6/wBriymiMCvdLIFdXcB4g=; b=L4mag0QNGkMlt652UAVEEvVcrdXyO6BbVY7RLQAQ93ogCYyn4yr3Piz/HVfVYrN7XeIMCTodWbBa1AujIuid3tyQFnIciltFAEoVfzgbfYkY1s4yV2jUyJTPSU11LSS4ap65vuJV4JxPQr380HPjO4vi3SAOqfW0BOlqNdx78RE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591804619473136.60503758306857; Wed, 10 Jun 2020 08:56:59 -0700 (PDT) Received: from localhost ([::1]:36344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj362-0005ne-0l for importer@patchew.org; Wed, 10 Jun 2020 11:56:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55984) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34c-0003kp-QG for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:30 -0400 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]:34115) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34Z-0005Co-W8 for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:29 -0400 Received: by mail-wr1-x42b.google.com with SMTP id r7so2881538wro.1 for ; Wed, 10 Jun 2020 08:55:19 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z16sm290502wrm.70.2020.06.10.08.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:12 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 1F4B31FF8C; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=t6TltwBrO/H4+UuBeh2Az6/wBriymiMCvdLIFdXcB4g=; b=RYmUJWyD8wgwM2nMB89roU4VqG6Mw/ltd6MgCTXrm8l4/c/ttx/RgkcLTRQdYnsI6v BLhoZfh5la/Ck47zSKx1BPs5iB+rU1NlhMgu5jVdsiRoFSBoQHq5zm7yyEQR91cd6wb3 h9D8CQoe/1tPW6NCloSQryJdKpl5bZE792kaggiDwS/HyuGXOHwpw93suhypRmtltzmJ yodOZjXbtwR7P//Fhq2UqSlzAvn1/PRVzewrPudcUFZOBLDX554cnDJ+hQ185WRzWs64 TK+UtCLbuBWcF7tMXxyNAgJPM/jQm4zqDfaVCriA4QJM6aSt5FrplnUH7e2xiZvF9Zum y6uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=t6TltwBrO/H4+UuBeh2Az6/wBriymiMCvdLIFdXcB4g=; b=VI8QsUAc/M9lqYB5jQSCANL3GagQ0X928zUckYAb3UVlxADudm/6soW+uq1aTWaC7C Jkw8mRVCxbhDqGxZ6WxmRxDnWNtUQmHndpcHtAvYlVxbFnCsJ6bpvwkKU4UBj099GN8+ 1hCoYG/FxnsCpiBkGBai6bHfypfYEKpUvraF5I6NqgWuSM9hI63u3LCylljhZdyCm7zL EuWRYUg1+r+LalfrXy1z+HjOJcddAN2yVjESQWyD8DHjsQDdMmXF/ierFcjRZyo5iBDE 2aaay+Pojus+pcYU+mOiXK3XZ5CBArg9ZAkqZr2AGY5B/4kyap3BFrW81fsym5C9y08v HwpA== X-Gm-Message-State: AOAM530DVCLP8SBI7IUkPS8hZyZnRFm8u4mJRXWSXDwy4aApgiYdYJOL u6GN1cDp3dxmk78eOcl+cnxEmA== X-Google-Smtp-Source: ABdhPJy/BznxaSlRswsCo2vSzIKgBLp+sBsuH4UWy6V2zIGarn0lSNzcMjJ1C7ZQzwIbrvTI/MsiRQ== X-Received: by 2002:a5d:5585:: with SMTP id i5mr4425057wrv.112.1591804518269; Wed, 10 Jun 2020 08:55:18 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] plugins: new lockstep plugin for debugging TCG changes Date: Wed, 10 Jun 2020 16:55:05 +0100 Message-Id: <20200610155509.12850-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42b.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: robert.foley@linaro.org, Mark Cave-Ayland , Richard Henderson , robhenry@microsoft.com, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When we make changes to the TCG we sometimes cause regressions that are deep into the execution cycle of the guest. Debugging this often requires comparing large volumes of trace information to figure out where behaviour has diverged. The lockstep plugin utilises a shared socket so two QEMU's running with the plugin will write their current execution position and wait to receive the position of their partner process. When execution diverges the plugins output where they were and the previous few blocks before unloading themselves and letting execution continue. Originally I planned for this to be most useful with -icount but it turns out you can get divergence pretty quickly due to asynchronous qemu_cpu_kick_rr_cpus() events causing one side to eventually run into a short block a few cycles before the other side. For this reason I've added a bit of tracking and I think the divergence reporting could be finessed to report only if we really start to diverge in execution. An example run would be: qemu-system-sparc -monitor none -parallel none -net none \ -M SS-20 -m 256 -kernel day11/zImage.elf \ -plugin ./tests/plugin/liblockstep.so,arg=3Dlockstep-sparc.sock \ -d plugin,nochain with an identical command in another window in the same working directory. Signed-off-by: Alex Benn=C3=A9e Cc: Richard Henderson Cc: Mark Cave-Ayland Message-Id: <20200429200754.18327-1-alex.bennee@linaro.org> Reviewed-by: Robert Foley Tested-by: Robert Foley --- v3 - added verbose flag - basic heuristics to detect "real" divergence - checkpatch tweaks --- tests/plugin/lockstep.c | 340 ++++++++++++++++++++++++++++++++++++++ tests/plugin/Makefile | 1 + tests/tcg/Makefile.target | 2 +- 3 files changed, 342 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/lockstep.c diff --git a/tests/plugin/lockstep.c b/tests/plugin/lockstep.c new file mode 100644 index 00000000000..a696673dff3 --- /dev/null +++ b/tests/plugin/lockstep.c @@ -0,0 +1,340 @@ +/* + * Lockstep Execution Plugin + * + * Allows you to execute two QEMU instances in lockstep and report + * when their execution diverges. This is mainly useful for developers + * who want to see where a change to TCG code generation has + * introduced a subtle and hard to find bug. + * + * Caveats: + * - single-threaded linux-user apps only with non-deterministic syscalls + * - no MTTCG enabled system emulation (icount may help) + * + * While icount makes things more deterministic it doesn't mean a + * particular run may execute the exact same sequence of blocks. An + * asynchronous event (for example X11 graphics update) may cause a + * block to end early and a new partial block to start. This means + * serial only test cases are a better bet. -d nochain may also help. + * + * This code is not thread safe! + * + * Copyright (c) 2020 Linaro Ltd + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +/* saved so we can uninstall later */ +static qemu_plugin_id_t our_id; + +static unsigned long bb_count; +static unsigned long insn_count; + +/* Information about a translated block */ +typedef struct { + uint64_t pc; + uint64_t insns; +} BlockInfo; + +/* Information about an execution state in the log */ +typedef struct { + BlockInfo *block; + unsigned long insn_count; + unsigned long block_count; +} ExecInfo; + +/* The execution state we compare */ +typedef struct { + uint64_t pc; + unsigned long insn_count; +} ExecState; + +typedef struct { + GSList *log_pos; + int distance; +} DivergeState; + +/* list of translated block info */ +static GSList *blocks; + +/* execution log and points of divergence */ +static GSList *log, *divergence_log; + +static int socket_fd; +static char *path_to_unlink; + +static bool verbose; + +static void plugin_cleanup(qemu_plugin_id_t id) +{ + /* Free our block data */ + g_slist_free_full(blocks, &g_free); + g_slist_free_full(log, &g_free); + g_slist_free(divergence_log); + + close(socket_fd); + if (path_to_unlink) { + unlink(path_to_unlink); + } +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) out =3D g_string_new("No divergence :-)\n"); + g_string_append_printf(out, "Executed %ld/%d blocks\n", + bb_count, g_slist_length(log)); + g_string_append_printf(out, "Executed ~%ld instructions\n", insn_count= ); + qemu_plugin_outs(out->str); + + plugin_cleanup(id); +} + +static void report_divergance(ExecState *us, ExecState *them) +{ + DivergeState divrec =3D { log, 0 }; + g_autoptr(GString) out =3D g_string_new(""); + bool diverged =3D false; + + /* + * If we have diverged before did we get back on track or are we + * totally loosing it? + */ + if (divergence_log) { + DivergeState *last =3D (DivergeState *) divergence_log->data; + GSList *entry; + + for (entry =3D log; g_slist_next(entry); entry =3D g_slist_next(en= try)) { + if (entry =3D=3D last->log_pos) { + break; + } + divrec.distance++; + } + + /* + * If the last two records are so close it is likely we will + * not recover synchronisation with the other end. + */ + if (divrec.distance =3D=3D 1 && last->distance =3D=3D 1) { + diverged =3D true; + } + } + divergence_log =3D g_slist_prepend(divergence_log, + g_memdup(&divrec, sizeof(divrec))); + + /* Output short log entry of going out of sync... */ + if (verbose || divrec.distance =3D=3D 1 || diverged) { + g_string_printf(out, "@ %#016lx vs %#016lx (%d/%d since last)\n", + us->pc, them->pc, g_slist_length(divergence_log), + divrec.distance); + qemu_plugin_outs(out->str); + } + + if (diverged) { + int i; + GSList *entry; + + g_string_printf(out, "=CE=94 insn_count @ %#016lx (%ld) vs %#016lx= (%ld)\n", + us->pc, us->insn_count, them->pc, them->insn_count= ); + + for (entry =3D log, i =3D 0; + g_slist_next(entry) && i < 5; + entry =3D g_slist_next(entry), i++) { + ExecInfo *prev =3D (ExecInfo *) entry->data; + g_string_append_printf(out, + " previously @ %#016lx/%ld (%ld insns)= \n", + prev->block->pc, prev->block->insns, + prev->insn_count); + } + qemu_plugin_outs(out->str); + qemu_plugin_outs("too much divergence... giving up."); + qemu_plugin_uninstall(our_id, plugin_cleanup); + } +} + +static void vcpu_tb_exec(unsigned int cpu_index, void *udata) +{ + BlockInfo *bi =3D (BlockInfo *) udata; + ExecState us, them; + ssize_t bytes; + ExecInfo *exec; + + us.pc =3D bi->pc; + us.insn_count =3D insn_count; + + /* + * Write our current position to the other end. If we fail the + * other end has probably died and we should shut down gracefully. + */ + bytes =3D write(socket_fd, &us, sizeof(ExecState)); + if (bytes < sizeof(ExecState)) { + qemu_plugin_outs(bytes < 0 ? + "problem writing to socket" : + "wrote less than expected to socket"); + qemu_plugin_uninstall(our_id, plugin_cleanup); + return; + } + + /* + * Now read where our peer has reached. Again a failure probably + * indicates the other end died and we should close down cleanly. + */ + bytes =3D read(socket_fd, &them, sizeof(ExecState)); + if (bytes < sizeof(ExecState)) { + qemu_plugin_outs(bytes < 0 ? + "problem reading from socket" : + "read less than expected"); + qemu_plugin_uninstall(our_id, plugin_cleanup); + return; + } + + /* + * Compare and report if we have diverged. + */ + if (us.pc !=3D them.pc) { + report_divergance(&us, &them); + } + + /* + * Assume this block will execute fully and record it + * in the execution log. + */ + insn_count +=3D bi->insns; + bb_count++; + exec =3D g_new0(ExecInfo, 1); + exec->block =3D bi; + exec->insn_count =3D insn_count; + exec->block_count =3D bb_count; + log =3D g_slist_prepend(log, exec); +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + BlockInfo *bi =3D g_new0(BlockInfo, 1); + bi->pc =3D qemu_plugin_tb_vaddr(tb); + bi->insns =3D qemu_plugin_tb_n_insns(tb); + + /* save a reference so we can free later */ + blocks =3D g_slist_prepend(blocks, bi); + qemu_plugin_register_vcpu_tb_exec_cb(tb, vcpu_tb_exec, + QEMU_PLUGIN_CB_NO_REGS, (void *)b= i); +} + + +/* + * Instead of encoding master/slave status into what is essentially + * two peers we shall just take the simple approach of checking for + * the existence of the pipe and assuming if it's not there we are the + * first process. + */ +static bool setup_socket(const char *path) +{ + struct sockaddr_un sockaddr; + int fd; + + fd =3D socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + perror("create socket"); + return false; + } + + sockaddr.sun_family =3D AF_UNIX; + g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1); + if (bind(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) { + perror("bind socket"); + close(fd); + return false; + } + + /* remember to clean-up */ + path_to_unlink =3D g_strdup(path); + + if (listen(fd, 1) < 0) { + perror("listen socket"); + close(fd); + return false; + } + + socket_fd =3D accept(fd, NULL, NULL); + if (socket_fd < 0 && errno !=3D EINTR) { + perror("accept socket"); + return false; + } + + qemu_plugin_outs("setup_socket::ready\n"); + + return true; +} + +static bool connect_socket(const char *path) +{ + int fd; + struct sockaddr_un sockaddr; + + fd =3D socket(AF_UNIX, SOCK_STREAM, 0); + if (fd < 0) { + perror("create socket"); + return false; + } + + sockaddr.sun_family =3D AF_UNIX; + g_strlcpy(sockaddr.sun_path, path, sizeof(sockaddr.sun_path) - 1); + + if (connect(fd, (struct sockaddr *)&sockaddr, sizeof(sockaddr)) < 0) { + perror("failed to connect"); + return false; + } + + qemu_plugin_outs("connect_socket::ready\n"); + + socket_fd =3D fd; + return true; +} + +static bool setup_unix_socket(const char *path) +{ + if (g_file_test(path, G_FILE_TEST_EXISTS)) { + return connect_socket(path); + } else { + return setup_socket(path); + } +} + + +QEMU_PLUGIN_EXPORT int qemu_plugin_install(qemu_plugin_id_t id, + const qemu_info_t *info, + int argc, char **argv) +{ + int i; + + if (!argc || !argv[0]) { + qemu_plugin_outs("Need a socket path to talk to other instance."); + return -1; + } + + for (i =3D 0; i < argc; i++) { + char *p =3D argv[i]; + if (strcmp(p, "verbose") =3D=3D 0) { + verbose =3D true; + } else if (!setup_unix_socket(argv[0])) { + qemu_plugin_outs("Failed to setup socket for communications."); + return -1; + } + } + + our_id =3D id; + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile index 75467b6db85..b3250e2504c 100644 --- a/tests/plugin/Makefile +++ b/tests/plugin/Makefile @@ -13,6 +13,7 @@ NAMES +=3D mem NAMES +=3D hotblocks NAMES +=3D howvec NAMES +=3D hotpages +NAMES +=3D lockstep =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index b3cff3cad1a..075daf3d22d 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -128,7 +128,7 @@ RUN_TESTS=3D$(patsubst %,run-%, $(TESTS)) ifeq ($(CONFIG_PLUGIN),y) PLUGIN_DIR=3D../../plugin VPATH+=3D$(PLUGIN_DIR) -PLUGINS=3D$(notdir $(wildcard $(PLUGIN_DIR)/*.so)) +PLUGINS=3D$(filter-out liblockstep.so,$(notdir $(wildcard $(PLUGIN_DIR)/*.= so))) =20 # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We --=20 2.20.1 From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804634; cv=none; d=zohomail.com; s=zohoarc; b=P4hwlocFY8jhxg+2Nn3NsthNSFK/ME2uOCxOvdBvRX3j6LnFdR3IElSxEMI7WiTYcdKBaLvZIOGBd1K+zApIsvce+jdrXczlb9u/1TjLUoNSXFcu9iAV11DQC366+2O47TmghOrHV9huersXScE8yoVMfkUIURK4JWfYRH2Nfhw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804634; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AKpSZsmxSDhJv+3Nh7RyP1/bV6hfWgn2W9oECqWqZTw=; b=Lk8zZDN9x97VfhzmUHjeH+MRGaIvJOIRU/ZgaEszj/00X5QM0ohwm/dIzvqBFPgC8lTJfJzokaUa6VpaxovCzbBdNAXcNE2j0xONYVh11Y2ER6AZ4OsdmkqMi1xYcAcdgnheCmgi3iYYDJ+OZLHeqzwkZTWpda4p5w2KDWkHfVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591804634638855.3155173981676; Wed, 10 Jun 2020 08:57:14 -0700 (PDT) Received: from localhost ([::1]:37248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj36H-0006Ga-C2 for importer@patchew.org; Wed, 10 Jun 2020 11:57:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55870) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34X-0003ca-3Y for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:25 -0400 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:51246) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34V-0005A0-Qq for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:24 -0400 Received: by mail-wm1-x342.google.com with SMTP id u13so2305130wml.1 for ; Wed, 10 Jun 2020 08:55:15 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id w17sm276703wra.71.2020.06.10.08.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:11 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 352511FF8F; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AKpSZsmxSDhJv+3Nh7RyP1/bV6hfWgn2W9oECqWqZTw=; b=ntxZaEryANx8smIzth6QaiD+zYPVcmqkRDEek3x85P0KKlD9el60DpgeYa81EvMsrt /YjlN8jnJG+nthU1BYgoBTG6uCloAcFS0NhNaXKQPBlHtET8LZGSX7v9S3P/YpBJJRbO 7cv/SPYELjLv0jwOgv9VLDUTkjs4UvQIMI6b0fFc6xAIzf0S/384I9UhQskg+7xvuNac mEZiR92hBMStF/OPES1FP2pP70nVVBb1tXXnG2i1kQC1uiS2opcoKI+fFCXSFNZZMEN9 vPdsPrqTUzx+tcuoEmn8uVm1MpvfXLCS/6xnK38PXU+9qnDpIGSHbc5688YPGdjUGrab +bpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AKpSZsmxSDhJv+3Nh7RyP1/bV6hfWgn2W9oECqWqZTw=; b=Km+z47fmekcWX1gI1UEB18ybw8VdPx3V7A5gkzWiYE+oMScyiKGS85+UwGNtEspfQ6 GlnhsqVCYcBSnain+DjnX+m7Do0/dce/b5tOccYd+/mq7ohtoEwXFPoWCvXPKK27tvBq btaim8ZZJ2PElz7lvIQQ/PKEli8k5dnEQBjn10cwIxTLdIJupj8Q6QCzkD4hP0vmvPg7 GgdCqbt4S95XCg3huu89cqwB3xZTN1bHXBBTjGD44YADD6jSolBi2/14G7sCr4pfOgG7 mEEMYN6NVBTYfN2ouVynycjn5p6mT0jSI2S7A9yyTXPbLuwnOAJ3WHEbKVe6+QwPZZhA DcJw== X-Gm-Message-State: AOAM533wk9JDVsswFsH7tlnETrPsQo3F7iLDztCYvCz6n/Ra89Q/nwXt uMtKyD8iJCNgwOAq4zITgh6A/g== X-Google-Smtp-Source: ABdhPJzM+80i48OlN4jn6JWv874ZtEC0hbBYihU4fwCl9JD2kjjXPPbE19Nx8PzRrN8q8BPQqOc+Gw== X-Received: by 2002:a7b:c4cc:: with SMTP id g12mr3795348wmk.171.1591804514008; Wed, 10 Jun 2020 08:55:14 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] cputlb: ensure we save the IOTLB data in case of reset Date: Wed, 10 Jun 2020 16:55:06 +0100 Message-Id: <20200610155509.12850-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: robert.foley@linaro.org, Paolo Bonzini , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Any write to a device might cause a re-arrangement of memory triggering a TLB flush and potential re-size of the TLB invalidating previous entries. This would cause users of qemu_plugin_get_hwaddr() to see the warning: invalid use of qemu_plugin_get_hwaddr because of the failed tlb_lookup which should always succeed. To prevent this we save the IOTLB data in case it is later needed by a plugin doing a lookup. Signed-off-by: Alex Benn=C3=A9e --- v2 - save the entry instead of re-running the tlb_fill. squash! cputlb: ensure we save the IOTLB entry in case of reset --- accel/tcg/cputlb.c | 63 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index eb2cf9de5e6..9bf9e479c7c 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1058,6 +1058,47 @@ static uint64_t io_readx(CPUArchState *env, CPUIOTLB= Entry *iotlbentry, return val; } =20 +#ifdef CONFIG_PLUGIN + +typedef struct SavedIOTLB { + struct rcu_head rcu; + struct SavedIOTLB **save_loc; + MemoryRegionSection *section; + hwaddr mr_offset; +} SavedIOTLB; + +static void clean_saved_entry(SavedIOTLB *s) +{ + atomic_rcu_set(s->save_loc, NULL); + g_free(s); +} + +static __thread SavedIOTLB *saved_for_plugin; + +/* + * Save a potentially trashed IOTLB entry for later lookup by plugin. + * + * We also need to track the thread storage address because the RCU + * cleanup that runs when we leave the critical region (the current + * execution) is actually in a different thread. + */ +static void save_iotlb_data(MemoryRegionSection *section, hwaddr mr_offset) +{ + SavedIOTLB *s =3D g_new(SavedIOTLB, 1); + s->save_loc =3D &saved_for_plugin; + s->section =3D section; + s->mr_offset =3D mr_offset; + atomic_rcu_set(&saved_for_plugin, s); + call_rcu(s, clean_saved_entry, rcu); +} + +#else +static void save_iotlb_data(MemoryRegionSection *section, hwaddr mr_offset) +{ + /* do nothing */ +} +#endif + static void io_writex(CPUArchState *env, CPUIOTLBEntry *iotlbentry, int mmu_idx, uint64_t val, target_ulong addr, uintptr_t retaddr, MemOp op) @@ -1077,6 +1118,12 @@ static void io_writex(CPUArchState *env, CPUIOTLBEnt= ry *iotlbentry, } cpu->mem_io_pc =3D retaddr; =20 + /* + * The memory_region_dispatch may trigger a flush/resize + * so for plugins we save the iotlb_data just in case. + */ + save_iotlb_data(section, mr_offset); + if (mr->global_locking && !qemu_mutex_iothread_locked()) { qemu_mutex_lock_iothread(); locked =3D true; @@ -1091,6 +1138,7 @@ static void io_writex(CPUArchState *env, CPUIOTLBEntr= y *iotlbentry, MMU_DATA_STORE, mmu_idx, iotlbentry->attrs,= r, retaddr); } + if (locked) { qemu_mutex_unlock_iothread(); } @@ -1366,8 +1414,11 @@ void *tlb_vaddr_to_host(CPUArchState *env, abi_ptr a= ddr, * in the softmmu lookup code (or helper). We don't handle re-fills or * checking the victim table. This is purely informational. * - * This should never fail as the memory access being instrumented - * should have just filled the TLB. + * This almost never fails as the memory access being instrumented + * should have just filled the TLB. The one corner case is io_writex + * which can cause TLB flushes and potential resizing of the TLBs + * loosing the information we need. In those cases we need to recover + * data from a thread local copy of the io_tlb entry. */ =20 bool tlb_plugin_lookup(CPUState *cpu, target_ulong addr, int mmu_idx, @@ -1391,6 +1442,14 @@ bool tlb_plugin_lookup(CPUState *cpu, target_ulong a= ddr, int mmu_idx, data->v.ram.hostaddr =3D addr + tlbe->addend; } return true; + } else { + SavedIOTLB *saved =3D atomic_rcu_read(&saved_for_plugin); + if (saved) { + data->is_io =3D true; + data->v.io.section =3D saved->section; + data->v.io.offset =3D saved->mr_offset; + return true; + } } return false; } --=20 2.20.1 From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804750; cv=none; d=zohomail.com; s=zohoarc; b=jhuHc1omaLbWgdbJSKLbK/1RRKggFoHcVMZBhJwVVBNw3InJrukcoUlvT0r6/aNeuS2xLKpkyDflvpfqM73hErDs2oSM7wwQDJTUYilZ3FeN0hCZSVaeA1PjallyLdIwoW8NXm/NwG79q6ymYIM5bZoRIQstDv2mxydQR6NFC0s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804750; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8k3vUvil4yeFEKEfxW7+SynAd8ccYx17gBmoCdQYV0E=; b=U6nOpX+42L8XxrvFd5jGjLdSYXHuEvwoCOTGo9hV9rk/TwqB2XilwFcjJXvm2HiFExy0F0ysj9F63VQzGcG3PbIjfEGAHUgl2gh2Pg/iRHWJyKq4G2SoXv9tU6faNZlwZL1kbH1GIl2AS+SW7QaKQ/6l/YbZYG+ih1cnuT5xBCE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159180475010656.868822559186356; Wed, 10 Jun 2020 08:59:10 -0700 (PDT) Received: from localhost ([::1]:44116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj388-00015e-Tw for importer@patchew.org; Wed, 10 Jun 2020 11:59:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34a-0003gQ-2J for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:28 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46903) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34Y-0005Bd-Sg for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:27 -0400 Received: by mail-wr1-x441.google.com with SMTP id x6so2827827wrm.13 for ; Wed, 10 Jun 2020 08:55:17 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q128sm147184wma.38.2020.06.10.08.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:11 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4B20B1FF90; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8k3vUvil4yeFEKEfxW7+SynAd8ccYx17gBmoCdQYV0E=; b=BtEjoK65Y6qRjtdjZrvvJHACecKeP8hvyuOX4TEr+Iodlocidgsxd3UjNoRuahYMbY 0Jv0jG3PlFUHNMxqJg05byDlVjTC5VGlqR+KlfKXtCWo8VBbILMCbnVOY73cGTzwncE1 0r+T7aoGVx+oPq1GowNCUFNTXiuP2ClgFSos3Cne8gOI66XmSC0PCnYGzNhI6uyqgTS1 kCc6Jfraljn/MnPS5HldS3buvt6evoDWVtJxB254UehfjE4LE7qKYZVfb4GFkvmjTnd1 yCYyRMZYmaZ0U8Jy6prrTLcsDIBqU8cyBMiQhvCuFzy/YrVafukKKEqpPAZWsIiPzJbb FbTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8k3vUvil4yeFEKEfxW7+SynAd8ccYx17gBmoCdQYV0E=; b=pog3/8J+Qd3OthcjJgnEkVFp5tX/qhEAs5Fwvza9sIsoRkjgSbEeA+jXE74QxL2Zqx UDVvEvjyUI/3ly8m4OpACQY2OzDlGgYPO05RxC6OU8Ew4/dnLlPivMJxAy/sfEOhixwo TCFK7ZQDp6W+3WRYkbmC6+gTRn1EFnfX4RWhzU08to9j3Bb5Hv8rf2+2Q5fdgY13l7jU rGouswoEYB5YgLDsHQ2OoeT0SjsOyBip/r4IMhSJ2MhKb7EdVroe/M4lpcOtTlnE/tIF bbj4x3C/DyslgebGGL5MeapSsQbUM+BN3JtNfG2MlvUu3I1Etg2NgV8uXazOtq7OSorL aFsg== X-Gm-Message-State: AOAM533/aqKTUqXkmqFHBysGumOztWwgMPQOv3wnvGH4uvpmW65m4FE3 wjYVfziKoPYJsyFK0FGYpCyysw== X-Google-Smtp-Source: ABdhPJxcxv4LZBu8h1sw2awG7E/3QOasCYNVRoESTXFUgKybSynCL/2H+ZYymYqlKzOtv1fwLjy0yg== X-Received: by 2002:a5d:6586:: with SMTP id q6mr4398832wru.319.1591804516736; Wed, 10 Jun 2020 08:55:16 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 4/6] hw/virtio/pci: include vdev name in registered PCI sections Date: Wed, 10 Jun 2020 16:55:07 +0100 Message-Id: <20200610155509.12850-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: robert.foley@linaro.org, "Michael S . Tsirkin" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) When viewing/debugging memory regions it is sometimes hard to figure out which PCI device something belongs to. Make the names unique by including the vdev name in the name string. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Michael S. Tsirkin --- v2 - swap ()'s for an extra - --- hw/virtio/virtio-pci.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index d028c17c240..51ab67304bc 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1390,7 +1390,8 @@ static void virtio_pci_device_write(void *opaque, hwa= ddr addr, } } =20 -static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy) +static void virtio_pci_modern_regions_init(VirtIOPCIProxy *proxy, + const char *vdev_name) { static const MemoryRegionOps common_ops =3D { .read =3D virtio_pci_common_read, @@ -1437,36 +1438,41 @@ static void virtio_pci_modern_regions_init(VirtIOPC= IProxy *proxy) }, .endianness =3D DEVICE_LITTLE_ENDIAN, }; + g_autoptr(GString) name =3D g_string_new(NULL); =20 - + g_string_printf(name, "virtio-pci-common-%s", vdev_name); memory_region_init_io(&proxy->common.mr, OBJECT(proxy), &common_ops, proxy, - "virtio-pci-common", + name->str, proxy->common.size); =20 + g_string_printf(name, "virtio-pci-isr-%s", vdev_name); memory_region_init_io(&proxy->isr.mr, OBJECT(proxy), &isr_ops, proxy, - "virtio-pci-isr", + name->str, proxy->isr.size); =20 + g_string_printf(name, "virtio-pci-device-%s", vdev_name); memory_region_init_io(&proxy->device.mr, OBJECT(proxy), &device_ops, virtio_bus_get_device(&proxy->bus), - "virtio-pci-device", + name->str, proxy->device.size); =20 + g_string_printf(name, "virtio-pci-notify-%s", vdev_name); memory_region_init_io(&proxy->notify.mr, OBJECT(proxy), ¬ify_ops, virtio_bus_get_device(&proxy->bus), - "virtio-pci-notify", + name->str, proxy->notify.size); =20 + g_string_printf(name, "virtio-pci-notify-pio-%s", vdev_name); memory_region_init_io(&proxy->notify_pio.mr, OBJECT(proxy), ¬ify_pio_ops, virtio_bus_get_device(&proxy->bus), - "virtio-pci-notify-pio", + name->str, proxy->notify_pio.size); } =20 @@ -1607,7 +1613,7 @@ static void virtio_pci_device_plugged(DeviceState *d,= Error **errp) =20 struct virtio_pci_cfg_cap *cfg_mask; =20 - virtio_pci_modern_regions_init(proxy); + virtio_pci_modern_regions_init(proxy, vdev->name); =20 virtio_pci_modern_mem_region_map(proxy, &proxy->common, &cap); virtio_pci_modern_mem_region_map(proxy, &proxy->isr, &cap); --=20 2.20.1 From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804726; cv=none; d=zohomail.com; s=zohoarc; b=KQ9RG/ZGNDTtIsBqHHY8zMOSlAsyq4lbRYMFSNZThadiwFZdHMBgynfw/XRbgMi4DZwLeHb+GHGB2bnbXAb5VV1+T6IVVkwkJI0o+an0sY29tSCB7scUX6gei4fSaCRmr2hqI7a7W2afvL+cTNMmnoQ6pJWzVrY9erR2lIVpRAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804726; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=K5O4iBO+Gb4CYP2dkK+QNloWbTQMSg+bPZS/dhOJAdk=; b=iw/XhDN9u1C2XK+q0odobrhg+tgMvLy+7ElAMe06HBuEfL9uFSSDGb93yoaoClE+BCkl2OO/xmIO3Ao21/qVIseiGQrlBDppXhrqTxICCp1FeJa2N8kZXFtAp9yvKaKsue501jCZcJ/FS9LElKleGvFIxZzltywxxTpotjvSYvU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591804726821324.001572696382; Wed, 10 Jun 2020 08:58:46 -0700 (PDT) Received: from localhost ([::1]:42786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj37l-0000SY-Kj for importer@patchew.org; Wed, 10 Jun 2020 11:58:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56004) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34d-0003mx-8J for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:31 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:37657) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34b-0005E3-3A for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:30 -0400 Received: by mail-wm1-x344.google.com with SMTP id y20so2304675wmi.2 for ; Wed, 10 Jun 2020 08:55:20 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id o8sm182467wmb.20.2020.06.10.08.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:18 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 62D901FF91; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K5O4iBO+Gb4CYP2dkK+QNloWbTQMSg+bPZS/dhOJAdk=; b=fygIBSJif8rAz2tfkD2LV5/qVawnF4VGcqNjenqgnS/2a7qqPnbdIo5OBvKTPVUdrx n/iPYFLHqbEkVnNO/foyYEccEnlZWyHrkS6EJtfqp9Ens/4wgfev2sami2BQCFj6eJzm VSkWeUeCDRVirJXPq4nE0NmkKu/fVj4IVKk1A9aajLghfiPlnjd+PNA9x2iSgJ0WRXRz zeIvoY/FkLi/Fmszloz1ReKBAqYMOplPVc92I75CVoVZu04P2tNDYMx/2F2vzFEaySe2 UcQLg4eg7uI9iKlH2RUxB4Q5o6a2m4lcSm7dz7oLwSB6tT8LXnxTfb1dS2vNKHRjFUjf 9KIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K5O4iBO+Gb4CYP2dkK+QNloWbTQMSg+bPZS/dhOJAdk=; b=kHV3x10jW8Rj1qHBNRLLXLwlGk7uuujFCPkdJyUXwZHY/HRUn1+z+VBLL8+dedovNz 45o5gqOnoAmucMp9igmDn+RpLYbjVly9Km04L0WvnvJzvjWL2vVHgTmN51ygvZ2VQJxK oNJqpT2S/kKZIwS5w1g0gLG9rBT59XBBPKdjlWUe1K+JSRpkEFPY4ArpoKk9iQC98l7b wlUDzGbnmKkR7zCy9YiBTFJGiKa7t+Sla8CquYX53aQ41IV275hzRAw8T39Xg8zwDc5u sf8mq5zsrdeWjzd+us6+lgagFgZM/S8fgVuasWrwIqEiQMaMNUADYTTw6hi/cZZ939An p7oQ== X-Gm-Message-State: AOAM531A6TJAt15MEFFnh7ZBmqzzX4ENUYSbRjNE50XFiwmrwW4fsPHm GeDkFGaJoy46goOtxTYybCZKxsAiOUE= X-Google-Smtp-Source: ABdhPJwWEQcuBbKrM/5m0J8DW22Nsjvfy5FUKPZK1/uj2SmLgOUJ6oARcavZcYO9xqczuv8bjmMquA== X-Received: by 2002:a1c:5411:: with SMTP id i17mr3982718wmb.137.1591804519629; Wed, 10 Jun 2020 08:55:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 5/6] plugins: add API to return a name for a IO device Date: Wed, 10 Jun 2020 16:55:08 +0100 Message-Id: <20200610155509.12850-6-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::344; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x344.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: robert.foley@linaro.org, robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, Clement Deschamps , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This may well end up being anonymous but it should always be unique. Signed-off-by: Alex Benn=C3=A9e [r-b provisional given change to g_intern_string] Reviewed-by: Clement Deschamps Reviewed-by: Emilio G. Cota --- v3 - return a non-freeable const g_intern_string() - checkpatch cleanups --- include/qemu/qemu-plugin.h | 6 ++++++ plugins/api.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/include/qemu/qemu-plugin.h b/include/qemu/qemu-plugin.h index bab8b0d4b3a..c98c18d6b05 100644 --- a/include/qemu/qemu-plugin.h +++ b/include/qemu/qemu-plugin.h @@ -335,6 +335,12 @@ struct qemu_plugin_hwaddr *qemu_plugin_get_hwaddr(qemu= _plugin_meminfo_t info, bool qemu_plugin_hwaddr_is_io(const struct qemu_plugin_hwaddr *haddr); uint64_t qemu_plugin_hwaddr_device_offset(const struct qemu_plugin_hwaddr = *haddr); =20 +/* + * Returns a string representing the device. The string is valid for + * the lifetime of the plugin. + */ +const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr= *h); + typedef void (*qemu_plugin_vcpu_mem_cb_t)(unsigned int vcpu_index, qemu_plugin_meminfo_t info, uint64_t vaddr, diff --git a/plugins/api.c b/plugins/api.c index bbdc5a4eb46..4304e63f0cf 100644 --- a/plugins/api.c +++ b/plugins/api.c @@ -303,6 +303,26 @@ uint64_t qemu_plugin_hwaddr_device_offset(const struct= qemu_plugin_hwaddr *haddr return 0; } =20 +const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr= *h) +{ +#ifdef CONFIG_SOFTMMU + if (h && h->is_io) { + MemoryRegionSection *mrs =3D h->v.io.section; + if (!mrs->mr->name) { + unsigned long maddr =3D 0xffffffff & (uintptr_t) mrs->mr; + g_autofree char *temp =3D g_strdup_printf("anon%08lx", maddr); + return g_intern_string(temp); + } else { + return g_intern_string(mrs->mr->name); + } + } else { + return g_intern_string("RAM"); + } +#else + return g_intern_string("Invalid"); +#endif +} + /* * Queries to the number and potential maximum number of vCPUs there * will be. This helps the plugin dimension per-vcpu arrays. --=20 2.20.1 From nobody Mon Feb 9 12:37:10 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1591804917; cv=none; d=zohomail.com; s=zohoarc; b=WCEXoG+aluNXU/tKmfTCDt0VQoqDPXhn9x6DSJAaJDpSfFze/oFgnfmRqmAshePNCVJUjHL0d8qcVy9qX9oU3fSjK4HhBeNOY0AwQ3Qm9uiCT62bo84QfWvlGLVh2eNysV+VeUqkL90O+sOFWA2QYIodvfxgsTVJqBKeaqsGISU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591804917; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2anqeVJ+Kb+4NZIuQSP80ASPU8VcWqGzoCWCikqGhnw=; b=GZTVpgPe71GRqKBlzppvhEfwzPNzcaOfTOn4jvwFjqkYK4647pnxrSZzWbIymS1BgrgPpoOI8wAiwDNRUjyGIKZZUNPMVmgEKThMmbBxrPiCX0Gnv7lD/wvTjMpaJ37TzjcxQu/88f7aXlR2wOWy47wfxAM8o45s/QAAZe+qJr0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591804917381589.0418262979537; Wed, 10 Jun 2020 09:01:57 -0700 (PDT) Received: from localhost ([::1]:49878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jj3Ao-00045S-KO for importer@patchew.org; Wed, 10 Jun 2020 12:01:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jj34f-0003sZ-OE for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:33 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:44227) by eggs.gnu.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jj34d-0005Ff-Sw for qemu-devel@nongnu.org; Wed, 10 Jun 2020 11:55:33 -0400 Received: by mail-wr1-x42d.google.com with SMTP id y17so2842653wrn.11 for ; Wed, 10 Jun 2020 08:55:22 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id j16sm366563wre.21.2020.06.10.08.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 08:55:18 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 7BAA41FF92; Wed, 10 Jun 2020 16:55:10 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2anqeVJ+Kb+4NZIuQSP80ASPU8VcWqGzoCWCikqGhnw=; b=hKBUdPE4ApT0CCkBRsFev3yM7C1i7ZL7oxD/3JM6B4kKGqz/8BTNtPr/yyAtI5n2we b2DSFdmVKoTS2LtkSOA3KyhWiy/nylgujWCmZmot+rmb6MIx43TpTMPcRznkFXeJzA/w 2ddAahbh5mZjndbvur5UcihHXb4aCmqbVS8tJd8UY/QubItTbZasSPgD+HeT9kH4S6mB njG61hbn8RlMx2O4fCrLSaqbKbLwvRkjx/oFMWYwqiR6tjkoWD9iKl2jigbzZeXFIhKm oQ1vle4riBuvg0FcVB7a+ZfajN3oZ7QD/neJxZ1kFPEJiSX/wqR78ydSs5pwlt7bxujA WRtQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2anqeVJ+Kb+4NZIuQSP80ASPU8VcWqGzoCWCikqGhnw=; b=NvA8KfwK7CHjfHG8/kWP3hFrCIUiCPb52UvjwJF+UgrhkuYgcTpQcsSSDS6csM5WAY dPfb37swrYfNcL4bAmyuAGTAiebcyXnZpxsbUdwX+9N+CqiLLLYr6eaNhcoBEthij6Ck j57p6a7PfjtjzjP7ki7LXiirKCj+jT78Xok/ySkuv8KTxToyjgawuXNNE6o4z2nnUDy1 kfCw45y7prry+yDUR9GS7qLcPwsrfzv1ZQIlTtsbrsubM/m+rfr2vHQSu6SXAElGx7Po /DEHbQeWcrhCPI41sxAP039sshMFaqPYW/pTJLeNZtM6Ahe/0GFS0XFkZbEdmhI6kkau 7BNg== X-Gm-Message-State: AOAM5337y7cBN/8KxyrVd8VepUXoNZS2By32TTUJJYy+ZLrL/ZHNXUaQ P2sCt9yK8fi6Pm6coDL3p+H6wA== X-Google-Smtp-Source: ABdhPJxH21krpo/2I69+AuXnwiJZJ5a6x3QX44I9G+1ZYfdThmbTr0fbQfeJo3pfVCzrzeUks2mgnQ== X-Received: by 2002:adf:c6c5:: with SMTP id c5mr4289286wrh.13.1591804521540; Wed, 10 Jun 2020 08:55:21 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 6/6] plugins: new hwprofile plugin Date: Wed, 10 Jun 2020 16:55:09 +0100 Message-Id: <20200610155509.12850-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200610155509.12850-1-alex.bennee@linaro.org> References: <20200610155509.12850-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action 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: robert.foley@linaro.org, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , robhenry@microsoft.com, aaron@os.amperecomputing.com, cota@braap.org, kuhn.chenqun@huawei.com, peter.puhov@linaro.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a plugin intended to help with profiling access to various bits of system hardware. It only really makes sense for system emulation. It takes advantage of the recently exposed helper API that allows us to see the device name (memory region name) associated with a device. You can specify arg=3Dread or arg=3Dwrite to limit the tracking to just reads or writes (by default it does both). The pattern option: -plugin ./tests/plugin/libhwprofile.so,arg=3Dpattern will allow you to see the access pattern to devices, eg: gic_cpu @ 0xffffffc010040000 off:00000000, 8, 1, 8, 1 off:00000000, 4, 1, 4, 1 off:00000000, 2, 1, 2, 1 off:00000000, 1, 1, 1, 1 The source option: -plugin ./tests/plugin/libhwprofile.so,arg=3Dsource will track the virtual source address of the instruction making the access: pl011 @ 0xffffffc010031000 pc:ffffffc0104c785c, 1, 4, 0, 0 pc:ffffffc0104c7898, 1, 4, 0, 0 pc:ffffffc010512bcc, 2, 1867, 0, 0 You cannot mix source and pattern. Finally the match option allow you to limit the tracking to just the devices you care about. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Robert Foley Tested-by: Robert Foley --- v2 - use 64 bit cpu masks - warn if we will exceed cpu mask capability - don't run in linux-user mode - skip in check-tcg for linux-user test v3 - update device name API - re-factor and clean-up - add source tracking - use direct hash for source/pattern - add match function - expand the commit message - checkpatch cleanups --- tests/plugin/hwprofile.c | 305 ++++++++++++++++++++++++++++++++++++++ tests/plugin/Makefile | 1 + tests/tcg/Makefile.target | 9 +- 3 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 tests/plugin/hwprofile.c diff --git a/tests/plugin/hwprofile.c b/tests/plugin/hwprofile.c new file mode 100644 index 00000000000..6dac1d5f854 --- /dev/null +++ b/tests/plugin/hwprofile.c @@ -0,0 +1,305 @@ +/* + * Copyright (C) 2020, Alex Benn=C3=A9e + * + * HW Profile - breakdown access patterns for IO to devices + * + * License: GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +QEMU_PLUGIN_EXPORT int qemu_plugin_version =3D QEMU_PLUGIN_VERSION; + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +typedef struct { + uint64_t cpu_read; + uint64_t cpu_write; + uint64_t reads; + uint64_t writes; +} IOCounts; + +typedef struct { + uint64_t off_or_pc; + IOCounts counts; +} IOLocationCounts; + +typedef struct { + const char *name; + uint64_t base; + IOCounts totals; + GHashTable *detail; +} DeviceCounts; + +static GMutex lock; +static GHashTable *devices; + +/* track the access pattern to a piece of HW */ +static bool pattern; +/* track the source address of access to HW */ +static bool source; +/* track only matched regions of HW */ +static bool check_match; +static gchar **matches; + +static enum qemu_plugin_mem_rw rw =3D QEMU_PLUGIN_MEM_RW; + +static inline bool track_reads(void) +{ + return rw =3D=3D QEMU_PLUGIN_MEM_RW || rw =3D=3D QEMU_PLUGIN_MEM_R; +} + +static inline bool track_writes(void) +{ + return rw =3D=3D QEMU_PLUGIN_MEM_RW || rw =3D=3D QEMU_PLUGIN_MEM_W; +} + +static void plugin_init(void) +{ + devices =3D g_hash_table_new(NULL, NULL); +} + +static gint sort_cmp(gconstpointer a, gconstpointer b) +{ + DeviceCounts *ea =3D (DeviceCounts *) a; + DeviceCounts *eb =3D (DeviceCounts *) b; + return ea->totals.reads + ea->totals.writes > + eb->totals.reads + eb->totals.writes ? -1 : 1; +} + +static gint sort_loc(gconstpointer a, gconstpointer b) +{ + IOLocationCounts *ea =3D (IOLocationCounts *) a; + IOLocationCounts *eb =3D (IOLocationCounts *) b; + return ea->off_or_pc > eb->off_or_pc; +} + +static void fmt_iocount_record(GString *s, IOCounts *rec) +{ + if (track_reads()) { + g_string_append_printf(s, ", %"PRIx64", %"PRId64, + rec->cpu_read, rec->reads); + } + if (track_writes()) { + g_string_append_printf(s, ", %"PRIx64", %"PRId64, + rec->cpu_write, rec->writes); + } +} + +static void fmt_dev_record(GString *s, DeviceCounts *rec) +{ + g_string_append_printf(s, "%s, 0x%"PRIx64, + rec->name, rec->base); + fmt_iocount_record(s, &rec->totals); + g_string_append_c(s, '\n'); +} + +static void plugin_exit(qemu_plugin_id_t id, void *p) +{ + g_autoptr(GString) report =3D g_string_new(""); + GList *counts; + + if (!(pattern || source)) { + g_string_printf(report, "Device, Address"); + if (track_reads()) { + g_string_append_printf(report, ", RCPUs, Reads"); + } + if (track_writes()) { + g_string_append_printf(report, ", WCPUs, Writes"); + } + g_string_append_c(report, '\n'); + } + + counts =3D g_hash_table_get_values(devices); + if (counts && g_list_next(counts)) { + GList *it; + + it =3D g_list_sort(counts, sort_cmp); + + while (it) { + DeviceCounts *rec =3D (DeviceCounts *) it->data; + if (rec->detail) { + GList *accesses =3D g_hash_table_get_values(rec->detail); + GList *io_it =3D g_list_sort(accesses, sort_loc); + const char *prefix =3D pattern ? "off" : "pc"; + g_string_append_printf(report, "%s @ 0x%"PRIx64"\n", + rec->name, rec->base); + while (io_it) { + IOLocationCounts *loc =3D (IOLocationCounts *) io_it->= data; + g_string_append_printf(report, " %s:%08"PRIx64, + prefix, loc->off_or_pc); + fmt_iocount_record(report, &loc->counts); + g_string_append_c(report, '\n'); + io_it =3D io_it->next; + } + } else { + fmt_dev_record(report, rec); + } + it =3D it->next; + }; + g_list_free(it); + } + + qemu_plugin_outs(report->str); +} + +static DeviceCounts *new_count(const char *name, uint64_t base) +{ + DeviceCounts *count =3D g_new0(DeviceCounts, 1); + count->name =3D name; + count->base =3D base; + if (pattern || source) { + count->detail =3D g_hash_table_new(NULL, NULL); + } + g_hash_table_insert(devices, (gpointer) name, count); + return count; +} + +static IOLocationCounts *new_location(GHashTable *table, uint64_t off_or_p= c) +{ + IOLocationCounts *loc =3D g_new0(IOLocationCounts, 1); + loc->off_or_pc =3D off_or_pc; + g_hash_table_insert(table, (gpointer) off_or_pc, loc); + return loc; +} + +static void hwprofile_match_hit(DeviceCounts *rec, uint64_t off) +{ + g_autoptr(GString) report =3D g_string_new("hwprofile: match @ offset"= ); + g_string_append_printf(report, "%"PRIx64", previous hits\n", off); + fmt_dev_record(report, rec); + qemu_plugin_outs(report->str); +} + +static void inc_count(IOCounts *count, bool is_write, unsigned int cpu_ind= ex) +{ + if (is_write) { + count->writes++; + count->cpu_write |=3D (1 << cpu_index); + } else { + count->reads++; + count->cpu_read |=3D (1 << cpu_index); + } +} + +static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t memin= fo, + uint64_t vaddr, void *udata) +{ + struct qemu_plugin_hwaddr *hwaddr =3D qemu_plugin_get_hwaddr(meminfo, = vaddr); + + if (!hwaddr || !qemu_plugin_hwaddr_is_io(hwaddr)) { + return; + } else { + const char *name =3D qemu_plugin_hwaddr_device_name(hwaddr); + uint64_t off =3D qemu_plugin_hwaddr_device_offset(hwaddr); + bool is_write =3D qemu_plugin_mem_is_store(meminfo); + DeviceCounts *counts; + + g_mutex_lock(&lock); + counts =3D (DeviceCounts *) g_hash_table_lookup(devices, name); + + if (!counts) { + uint64_t base =3D vaddr - off; + counts =3D new_count(name, base); + } + + if (check_match) { + if (g_strv_contains((const char * const *)matches, counts->nam= e)) { + hwprofile_match_hit(counts, off); + inc_count(&counts->totals, is_write, cpu_index); + } + } else { + inc_count(&counts->totals, is_write, cpu_index); + } + + /* either track offsets or source of access */ + if (source) { + off =3D (uint64_t) udata; + } + + if (pattern || source) { + IOLocationCounts *io_count =3D g_hash_table_lookup(counts->det= ail, + (gpointer) of= f); + if (!io_count) { + io_count =3D new_location(counts->detail, off); + } + inc_count(&io_count->counts, is_write, cpu_index); + } + + g_mutex_unlock(&lock); + } +} + +static void vcpu_tb_trans(qemu_plugin_id_t id, struct qemu_plugin_tb *tb) +{ + size_t n =3D qemu_plugin_tb_n_insns(tb); + size_t i; + + for (i =3D 0; i < n; i++) { + struct qemu_plugin_insn *insn =3D qemu_plugin_tb_get_insn(tb, i); + gpointer udata =3D (gpointer) (source ? qemu_plugin_insn_vaddr(ins= n) : 0); + qemu_plugin_register_vcpu_mem_cb(insn, vcpu_haddr, + QEMU_PLUGIN_CB_NO_REGS, + rw, udata); + } +} + +QEMU_PLUGIN_EXPORT +int qemu_plugin_install(qemu_plugin_id_t id, const qemu_info_t *info, + int argc, char **argv) +{ + int i; + + for (i =3D 0; i < argc; i++) { + char *opt =3D argv[i]; + if (g_strcmp0(opt, "read") =3D=3D 0) { + rw =3D QEMU_PLUGIN_MEM_R; + } else if (g_strcmp0(opt, "write") =3D=3D 0) { + rw =3D QEMU_PLUGIN_MEM_W; + } else if (g_strcmp0(opt, "pattern") =3D=3D 0) { + pattern =3D true; + } else if (g_strcmp0(opt, "source") =3D=3D 0) { + source =3D true; + } else if (g_str_has_prefix(opt, "match")) { + gchar **parts =3D g_strsplit(opt, "=3D", 2); + check_match =3D true; + matches =3D g_strsplit(parts[1], ",", -1); + g_strfreev(parts); + } else { + fprintf(stderr, "option parsing failed: %s\n", opt); + return -1; + } + } + + if (source && pattern) { + fprintf(stderr, "can only currently track either source or pattern= .\n"); + return -1; + } + + if (!info->system_emulation) { + fprintf(stderr, "hwprofile: plugin only useful for system emulatio= n\n"); + return -1; + } + + /* Just warn about overflow */ + if (info->system.smp_vcpus > 64 || + info->system.max_vcpus > 64) { + fprintf(stderr, "hwprofile: can only track up to 64 CPUs\n"); + } + + plugin_init(); + + qemu_plugin_register_vcpu_tb_trans_cb(id, vcpu_tb_trans); + qemu_plugin_register_atexit_cb(id, plugin_exit, NULL); + return 0; +} diff --git a/tests/plugin/Makefile b/tests/plugin/Makefile index b3250e2504c..d87b8d40699 100644 --- a/tests/plugin/Makefile +++ b/tests/plugin/Makefile @@ -14,6 +14,7 @@ NAMES +=3D hotblocks NAMES +=3D howvec NAMES +=3D hotpages NAMES +=3D lockstep +NAMES +=3D hwprofile =20 SONAMES :=3D $(addsuffix .so,$(addprefix lib,$(NAMES))) =20 diff --git a/tests/tcg/Makefile.target b/tests/tcg/Makefile.target index 075daf3d22d..5785554901b 100644 --- a/tests/tcg/Makefile.target +++ b/tests/tcg/Makefile.target @@ -128,7 +128,14 @@ RUN_TESTS=3D$(patsubst %,run-%, $(TESTS)) ifeq ($(CONFIG_PLUGIN),y) PLUGIN_DIR=3D../../plugin VPATH+=3D$(PLUGIN_DIR) -PLUGINS=3D$(filter-out liblockstep.so,$(notdir $(wildcard $(PLUGIN_DIR)/*.= so))) + +# Some plugins aren't testable automatically +SKIP_PLUGINS=3Dliblockstep.so +ifdef CONFIG_USER_ONLY +SKIP_PLUGINS+=3Dlibhwprofile.so +endif + +PLUGINS=3D$(filter-out $(SKIP_PLUGINS),$(notdir $(wildcard $(PLUGIN_DIR)/*= .so))) =20 # We need to ensure expand the run-plugin-TEST-with-PLUGIN # pre-requistes manually here as we can't use stems to handle it. We --=20 2.20.1