From patchwork Mon Nov 18 21:15:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 179611 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp3429411ilf; Mon, 18 Nov 2019 13:21:15 -0800 (PST) X-Google-Smtp-Source: APXvYqxQLRE6a1fmOgH77b7sV0vs6QzNTt9RLggqqsonUKER3vGOMI84uj9NTEd9gJq8Z15w+wy8 X-Received: by 2002:a5d:6390:: with SMTP id p16mr30941139wru.55.1574112075218; Mon, 18 Nov 2019 13:21:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574112075; cv=none; d=google.com; s=arc-20160816; b=SEBNpfuav1DnxBTUyaWjB5NkuRl5aW4njaf8T0hwo5qYugwq8Ylg31Opk7tsvYGurI SWC8+rK0wbkBbP0Cz1fgZBVXVbRE8HY5If1hCkSXwPiO49soW6SiplZblllZ36OKnXUN BNwjUk0j7kWErJGufrMRxX8RW1fKhBamkNHIlzM4O8pLa5ChvEOJSE6F+9mYgHSad8Vi zqu6G4KPc05LYRbnRW3Q932l6ykDaELN5AYyxDsj+DEOiFp1kmClEQ3C7CPzElWwmuzu WRvRpuq3FnquKNMFCQ+es0h9brwS8FRYI/LsU1u21fneSVmFtGag703JGr6o0isiPM3A EBjQ== 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=qWgWHy/VsErSeqWDM+/otxG0psdTm5gcLYEEVbdKoW0=; b=z5FttFDflqAZgty/ejOw5jqikReUeRLhUd4AK+e8hY0i5WkA3S6uxNQCCuAMq357bU IaC/cQJ4gvxjkpJqNcmSfTUauQ7K7jGOecFAm2NUvCFaaLBRMRQ1MHkE4q/jRc14d+h3 HzJ1FE1Kc2J17AJQ5oKTAPyzxMZFJYcfy6mDzvtN8LMzDEWihDYJrtSiffbNrG+Dj/PZ IDyQDX/LpafC6LLyxUgg6P9NYbKrQlUvZb+/3kviVz5V7VRWt/hQ4CfqF97I+zVF0Aa/ XVMWZjDTeftSYPH4JveAJHaqg6M0yhV2LNqRRmnhBoVtGcxz6uFXdgW+OR4279C2LlAe xebg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=GNMlAj2l; 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 i6si13204674edg.76.2019.11.18.13.21.15 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Nov 2019 13:21:15 -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=GNMlAj2l; 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]:39640 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWoSP-0006WN-JW for patch@linaro.org; Mon, 18 Nov 2019 16:21:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35756) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWoN8-0008Q4-5z for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWoN3-0005hq-Ub for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:45 -0500 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:33050) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iWoN3-0005hZ-Nt for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:41 -0500 Received: by mail-pl1-x62f.google.com with SMTP id ay6so10482166plb.0 for ; Mon, 18 Nov 2019 13:15:41 -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=qWgWHy/VsErSeqWDM+/otxG0psdTm5gcLYEEVbdKoW0=; b=GNMlAj2l1HjUUaJHvhBCslxnJ1KeT4MIy5WTjsaUqTpabvEf3lTB0yCZHCieirPFeO c5WHTJky81py5wkkE2GnMbpG8g3Jru2j59VMbbp7lQy6Cd6wQTPS8ZzlkFfejYpXs4f/ 7nSwqpSu/rWlxLVNSA1tUNqVT9YNmZ/MWz1OOf3TUz2DM4w99sJixru24cwq9mb3itsl Jq8zILMc7Ik1FOU6ysLAK9ry4yXUjnJN1ItsnMXz5ldLGJ6h5hpDCbV3NAtf4cBipINl 5DfeEZHLBPRtpp4MawcqNZt1v6olbzC5gNtzfhb4Tv8VOQ2ThLH8nHh9O9g2/5EhGCtq u51w== 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=qWgWHy/VsErSeqWDM+/otxG0psdTm5gcLYEEVbdKoW0=; b=gSmJJfMO86SmQjlDhFE/3GE188QgPPQ4zwUwgNlldQ+HCh5EqZRcK3IAb6CtKF+7wa Uxi18buYO9jt0uAqxIV8MaVDr/y1m5czGuGXAWLB5ItZTy4s8v9lSnKB+qJ+VKjQENE9 XYRPutvvZIKxqaECl55ZxMoPYJ6AqdmxY2Ji7nZDxoSd2b+N3y1TZHnXd6CLJtjicfhm xjL4Ruf0GY00c5IRgswfFDL28SZOa7n43QVBGRVQfuemuZOVGVoRm5IbYLA0zvimKFCV t2oSPIq61KFN1XKk19S4l6goMT4lm14Q/FOpoFTRoEhbGLkcxfNNA+zLVAxEDqIaEOYW 9P+g== X-Gm-Message-State: APjAAAUrZCmSiocGtj0mbLilrENQCjOPVXPF5dWxjpmajPPdXToSa2L0 ijgkKsxcdsqy1Y4Hr6XnIW3V1E9vY4M= X-Received: by 2002:a17:90a:de4:: with SMTP id 91mr1366099pjv.113.1574111739882; Mon, 18 Nov 2019 13:15:39 -0800 (PST) Received: from Rfoley-MA01.usrd.futurewei.com ([12.111.81.71]) by smtp.gmail.com with ESMTPSA id v15sm22301728pfe.44.2019.11.18.13.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2019 13:15:37 -0800 (PST) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 0/6] Make the qemu_logfile handle thread safe. Date: Mon, 18 Nov 2019 16:15:22 -0500 Message-Id: <20191118211528.3221-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::62f 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: richard.henderson@linaro.org, alex.bennee@linaro.org, robert.foley@linaro.org, peter.puhov@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(). --- v3 - This version of the patch incorporates a few minor changes. - Change patch which adds qemu_logfile_mutex to remove the asserts that mutex is initialized, instead we will rely on the constructor. - Also added details to commit for patch adding mutex to explain some unavoidable temporary ugliness that we cleanup in a later patch. - Change qemu_log_lock() to unconditionally hold the rcu_read_lock() until qemu_log_unlock(). - Also changed one use case in target/tilegx/translate.c to eliminate use of qemu_log_lock()/unlock(). --- 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 | 48 +++++++++++++--- 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 | 6 -- target/unicore32/translate.c | 4 +- tcg/tcg.c | 28 ++++++---- tests/test-logging.c | 80 +++++++++++++++++++++++++++ util/log.c | 100 ++++++++++++++++++++++++++-------- 18 files changed, 268 insertions(+), 77 deletions(-) -- 2.17.1