From nobody Wed Nov 5 10:41:22 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533837465956781.4778140886548; Thu, 9 Aug 2018 10:57:45 -0700 (PDT) Received: from localhost ([::1]:52236 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnpBw-0000rM-Ng for importer@patchew.org; Thu, 09 Aug 2018 13:57:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnpAG-0008Lm-Ql for qemu-devel@nongnu.org; Thu, 09 Aug 2018 13:56:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnpAD-0004hl-D4 for qemu-devel@nongnu.org; Thu, 09 Aug 2018 13:56:00 -0400 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]:46893) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fnpAD-0004gs-3B for qemu-devel@nongnu.org; Thu, 09 Aug 2018 13:55:57 -0400 Received: by mail-wr1-x434.google.com with SMTP id h14-v6so5870792wrw.13 for ; Thu, 09 Aug 2018 10:55:56 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 198-v6sm14848982wmm.0.2018.08.09.10.55.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 09 Aug 2018 10:55:55 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E2D473E0619; Thu, 9 Aug 2018 18:55:53 +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=m9XHKczBCfZKJnBKtgcKHhJOx0keN4+gJldX0UXceRM=; b=FYmsII/IGOYs4nNdfRPN4pkiFTRl1akZeRRHLmQHlVvH9kKvBZJL/pdMPLgOYUDj40 YyLG5EcqeKxJiPYIuUKm0veHVrv0PGVl2ESI0ladZwDQ867hFFWfdB/HCVphh4kdBkXt GwmD2VSYXP+FmIJjjmi3jbDr5MERAFappabl0= 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=m9XHKczBCfZKJnBKtgcKHhJOx0keN4+gJldX0UXceRM=; b=roXJhGX6uvLQVzsaskavBbXNiOfRCvgavA6HlX9WCJv3L659oiO375IfQ0RIucvyXL ay/ftaQ1J0fX0rYban+SqxLxNAs4SGJfD00s/ge2TXKGeKk7J9510GTu8XWlsYcdRQ43 df3te+1moRilynJ8VQkYhoVyzgZkXpnYMUQ6MxJaf8ZONNyNM2/MJzHIrrl0/NdnBXMO MiQgzLL9gcMGs0Vdz9fLcshCgFki7+MCaW2TkB0MDmQleP8gtaBiYGNrdee2GC5Igl4R rkGLtFx1GQy9NTcLt96h9vdczk7K9aSRhRFQUYXgP+vAUSOxTHjJyG763+GQS881DBuH 79oQ== X-Gm-Message-State: AOUpUlFC5HJj/+NZy5lCl6QA51M49dZtFLHSw2WZxZrG70MlZ7xzlv9X 677iWXTkp5WsLu0EyAZ9iqZG2w== X-Google-Smtp-Source: AA+uWPwDDCrsBcGgaE1WTvgkMFyeEj4thLP9WAo+AOiDS7s7F2ISW5wMgy7TAiR3gzyldibEmO/Nyw== X-Received: by 2002:adf:e887:: with SMTP id d7-v6mr2175717wrm.43.1533837355849; Thu, 09 Aug 2018 10:55:55 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2018 18:55:51 +0100 Message-Id: <20180809175553.18479-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180809175553.18479-1-alex.bennee@linaro.org> References: <20180809175553.18479-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::434 Subject: [Qemu-devel] [RFC PATCH 1/3] util/log: allow -dfilter to stack X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?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) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 The original dfilter was patched to avoid a leak in the case of multiple -dfilter ranges. There is no reason not to allow the user to stack several dfilter options rather than push them all into one mega line. We avoid the leak by simply only allocating the first time around. As we are using a g_array it will automatically re-size as needed. The allocation is pushed to a helper as future patches will offer additional ways to add to the dfilter. We also add a helper qemu_reset_dfilter_ranges() so we can be explicit in our unit tests. Signed-off-by: Alex Benn=C3=A9e --- include/qemu/log.h | 1 + tests/test-logging.c | 14 ++++++++++++++ util/log.c | 23 +++++++++++++++++------ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/include/qemu/log.h b/include/qemu/log.h index b097a6cae1..8ed932ec24 100644 --- a/include/qemu/log.h +++ b/include/qemu/log.h @@ -116,6 +116,7 @@ void qemu_set_log(int log_flags); void qemu_log_needs_buffers(void); void qemu_set_log_filename(const char *filename, Error **errp); void qemu_set_dfilter_ranges(const char *ranges, Error **errp); +void qemu_reset_dfilter_ranges(void); bool qemu_log_in_addr_range(uint64_t addr); int qemu_str_to_log_mask(const char *str); =20 diff --git a/tests/test-logging.c b/tests/test-logging.c index a12585f70a..fbddd70ebc 100644 --- a/tests/test-logging.c +++ b/tests/test-logging.c @@ -43,6 +43,8 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x10ff)); g_assert_false(qemu_log_in_addr_range(0x1100)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000-0x100", &error_abort); =20 g_assert_false(qemu_log_in_addr_range(0x1001)); @@ -50,6 +52,8 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x0f01)); g_assert_false(qemu_log_in_addr_range(0x0f00)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000..0x1100", &error_abort); =20 g_assert_false(qemu_log_in_addr_range(0xfff)); @@ -57,26 +61,36 @@ static void test_parse_range(void) g_assert(qemu_log_in_addr_range(0x1100)); g_assert_false(qemu_log_in_addr_range(0x1101)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000..0x1000", &error_abort); =20 g_assert_false(qemu_log_in_addr_range(0xfff)); g_assert(qemu_log_in_addr_range(0x1000)); g_assert_false(qemu_log_in_addr_range(0x1001)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0x1000+0x100,0x2100-0x100,0x3000..0x3100", &error_abort); g_assert(qemu_log_in_addr_range(0x1050)); g_assert(qemu_log_in_addr_range(0x2050)); g_assert(qemu_log_in_addr_range(0x3050)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0xffffffffffffffff-1", &error_abort); g_assert(qemu_log_in_addr_range(UINT64_MAX)); g_assert_false(qemu_log_in_addr_range(UINT64_MAX - 1)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("0..0xffffffffffffffff", &err); g_assert(qemu_log_in_addr_range(0)); g_assert(qemu_log_in_addr_range(UINT64_MAX)); =20 + qemu_reset_dfilter_ranges(); + qemu_set_dfilter_ranges("2..1", &err); error_free_or_abort(&err); =20 diff --git a/util/log.c b/util/log.c index c0dbbd4700..c6c197cbb3 100644 --- a/util/log.c +++ b/util/log.c @@ -149,19 +149,30 @@ bool qemu_log_in_addr_range(uint64_t addr) } } =20 +static void maybe_allocate_dfilter(int size_hint) +{ + if (!debug_regions) { + debug_regions =3D g_array_sized_new(FALSE, FALSE, + sizeof(Range), + size_hint ? size_hint : 1); + } +} + +/* This is only really used for testing, usually dfilter stacks */ +void qemu_reset_dfilter_ranges(void) +{ + GArray *old =3D debug_regions; + debug_regions =3D NULL; + g_array_free(old, TRUE); +} =20 void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp) { gchar **ranges =3D g_strsplit(filter_spec, ",", 0); int i; =20 - if (debug_regions) { - g_array_unref(debug_regions); - debug_regions =3D NULL; - } + maybe_allocate_dfilter(g_strv_length(ranges)); =20 - debug_regions =3D g_array_sized_new(FALSE, FALSE, - sizeof(Range), g_strv_length(ranges)= ); for (i =3D 0; ranges[i]; i++) { const char *r =3D ranges[i]; const char *range_op, *r2, *e; --=20 2.17.1