From patchwork Fri Nov 15 13:10:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 179494 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp12432972ilf; Fri, 15 Nov 2019 05:11:49 -0800 (PST) X-Google-Smtp-Source: APXvYqwpC0bDAtRW0AKEt5yT60eetyvrROJf0xeTN6yMjtVAqZrUD+8pBCb3zyQF2ZqL7UpAdJqq X-Received: by 2002:ac8:6f3a:: with SMTP id i26mr13859335qtv.344.1573823509733; Fri, 15 Nov 2019 05:11:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573823509; cv=none; d=google.com; s=arc-20160816; b=kIsdKjew/UwoxXuWWHChT702IXWtJ4dx7T/Oj1BwD2qvPWvZk+dDUREaplCKs/6rrH FrDSoHlgWCuV0NPNQe83YW3CKYHwGxhQblWfwvU1Na0FcuaWX2O+z0i0xXk9Cg+wc72V GYNl3+Bl+Qx6GWxWHw6CR/czpwExN5fWcfgsv4t1LcQ/XGAdqFuad5urS9ctT/7wc/0A mkVl6FC8QPM5aYBVqQ/sHJJVOvZ11ZkofGidykcjKVBJAK4AWRcAbY32731miCxsm6Qr 3vO6xat+TF+B+uTL6iWEc2DXOR3ZcBecY/8d5SPBpMR2BegB3pH/SXUxMZoePen9aowp SDng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature; bh=wI02htXvbaCF/QBVlfvNuM25qEJJGrUPkf5so08TzqY=; b=0PeiIR9aldym663lEb+QeMWUuhWJhBKgWt9jsnH63PmT0tksvsw0m+v06LrOoLxjn3 XBMmKL4xnh1afjN82Xg8njvhWxM0CWTV3Hti9zLkTxF6CPEjQPihQRg7BQuYTvyxWC9y R+D3xiC6Xb/TzEwi90gpU6+EgGySYJhRx/A4PjDOc9/zFWKfeemZFpEYC14/uGFTlFuU izQwiK8QATjwIqJr8rs75E+aq9qvncMDfYFdcXOEx7zPXRdgPenq5HSb6U1PRuj23i9t uqphLKOJmmhRsSNbeqGKQDGEX/ClLEpVB4dYn732H6AZJtpBLzZzRyFl7dFkj5aKC/5q 7kjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R8GkTNlO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id x20si5915196qtm.244.2019.11.15.05.11.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2019 05:11:49 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=R8GkTNlO; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbO8-0004OM-Te for patch@linaro.org; Fri, 15 Nov 2019 08:11:49 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49393) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbNv-0004No-GW for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVbNu-0004No-BA for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:35 -0500 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:36637) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVbNu-0004NP-21 for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:34 -0500 Received: by mail-pg1-x542.google.com with SMTP id k13so6014750pgh.3 for ; Fri, 15 Nov 2019 05:11:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=wI02htXvbaCF/QBVlfvNuM25qEJJGrUPkf5so08TzqY=; b=R8GkTNlObqdMjoNPQEN0c994wbzQhcbz+h9v0vxQFyZa7KXXvxM0WW4nj1P2ymZZeZ aw4tcHcWA8YRGkvZbIt6HIyjOc3wYDWFganONoOv+qjkATdyqxWNAiW9zNYHXfBDNUiQ 6rvlhDflZrX5XbOaWI3oTo7BdKskAqpvb8uf6t1Bylwa44/5ZBn+MDhywAi0lS8//PBY 9aAAVDht9vdXMihmnDvQ9STRvjFXvSXtF0Ys2FoMX7AHaet5UxGcrAsyZ3UykAtZPyVr PrZKtMJreGf9FegxzEmYz8xoooUi3dTMsGZfWY+qiIizjYTr7x19WWnK4rr4AylMBTxr fIRQ== 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:mime-version :content-transfer-encoding; bh=wI02htXvbaCF/QBVlfvNuM25qEJJGrUPkf5so08TzqY=; b=L4VBeeJr+zZ5bZn5BAdQU6iF8yFJqWcIXbSYPA6YRRgm2qnzvaLm4kExqN0Y1ng+FU afjER6+XkBE+3ZXaXkGgED2cSEbhigMe09geG1W72cKjrhs0QFrTerWEaRxN190TPzL1 NcoIJrDrfMkzrDvBTb42dUr5OT5ydlYNFNViO6ZpzgGzqRfUbPOUmmVYGcHkQlESk9Fo Y12lFLMB+PviVSAbNkHXi/VxVgF+S0y0n+3YEbdRkjkBUAXoB/3/g949K8fIgoXV+hhK 7RT0wlYd1LItIVbv4VgAtejNFKRcoNuHnMUyB5C8ySDs6ROc/b1raiNmClxXPljymPI8 MkRw== X-Gm-Message-State: APjAAAXHQuqXmChfYLqpWLSdkltvjCgWgrK8P/FHBdI4xfyIZC8/SDcl uHgLqprV56Kr1IkVY/k777O9drlDDl8= X-Received: by 2002:a62:1bd0:: with SMTP id b199mr17611326pfb.44.1573823492158; Fri, 15 Nov 2019 05:11:32 -0800 (PST) Received: from Rfoley-MA01.usrd.futurewei.com ([12.111.81.71]) by smtp.gmail.com with ESMTPSA id w138sm12007249pfc.68.2019.11.15.05.11.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 05:11:31 -0800 (PST) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 0/6] Make the qemu_logfile handle thread safe. Date: Fri, 15 Nov 2019 08:10:34 -0500 Message-Id: <20191115131040.2834-1-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 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: peter.puhov@linaro.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This patch adds thread safety to the qemu_logfile handle. This now allows changing the logfile while logging is active, and also solves the issue of a seg fault while changing the logfile. This patch adds use of RCU for handling the swap out of the old qemu_logfile file descriptor. Also added a few tests for logfile including changing the logfile and closing the logfile. One change also added for a pre-existing double free issue in qemu_set_log_filename() uncovered with the new test. We also cleaned up the flow of code in qemu_set_log(). --- v2 - This version of the patch adds some cleanup of code in qemu_set_log(). - Also changed the order of patches to move our fix for the double free issue in qemu_set_log_filename() up to the beginning of the patch. --- v1 - This version of the patch incorporates changes from the first round of review. - It also includes a fix for an issue in qemu_set_log_filename(). This issue was uncovered by the test added for this patch. --- Robert Foley (6): Fix double free issue in qemu_set_log_filename(). Cleaned up flow of code in qemu_set_log(), to simplify and clarify. Add a mutex to guarantee single writer to qemu_logfile handle. qemu_log_lock/unlock now preserves the qemu_logfile handle. Add use of RCU for qemu_logfile. Added tests for close and change of logfile. accel/tcg/cpu-exec.c | 4 +- accel/tcg/translate-all.c | 4 +- accel/tcg/translator.c | 4 +- exec.c | 4 +- hw/net/can/can_sja1000.c | 4 +- include/exec/log.h | 33 +++++++++-- include/qemu/log.h | 49 +++++++++++++--- net/can/can_socketcan.c | 5 +- target/cris/translate.c | 4 +- target/i386/translate.c | 5 +- target/lm32/translate.c | 4 +- target/microblaze/translate.c | 4 +- target/nios2/translate.c | 4 +- target/tilegx/translate.c | 7 ++- target/unicore32/translate.c | 4 +- tcg/tcg.c | 28 ++++++---- tests/test-logging.c | 80 ++++++++++++++++++++++++++ util/log.c | 102 ++++++++++++++++++++++++++-------- 18 files changed, 275 insertions(+), 74 deletions(-) -- 2.17.1