From patchwork Wed Feb 22 02:00:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 655656 Delivered-To: patch@linaro.org Received: by 2002:adf:a3c6:0:0:0:0:0 with SMTP id m6csp444492wrb; Tue, 21 Feb 2023 18:02:29 -0800 (PST) X-Google-Smtp-Source: AK7set+P/lFA1u+1AS/0H6FZOh3Dl4ZMzJW2cnFzFwJWV8BZ+jzXZhNTQDx36PVPdH+hSaHD/03Y X-Received: by 2002:a05:622a:189c:b0:3b6:3577:2fe7 with SMTP id v28-20020a05622a189c00b003b635772fe7mr26574742qtc.49.1677031349216; Tue, 21 Feb 2023 18:02:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677031349; cv=none; d=google.com; s=arc-20160816; b=bGg9gKTrM6MDSWSpfct69NQInXK7v8dH9aY5Y5zIiE9BbyrhmuXRjWzZclc22uZOPy g61NzdpJCN88NelpqHoowBJTrhKvNq+6ohh2Vj9MDYyfGEi8SXtZ6kPETO/zeT8+WkpJ IaZr110I8yStG8U+3Mdlzl59qJ0qmRnzqI1HnTTatnFtTrQwoKvKJEpuv71NhM1cTK6J dFZ7uom+oxrFRJQiHvRswPnCTR+2sZQ7mZOCUo51BOU9vIP9rG5nXWNtGjVojjbJ3/pI zRbV39B/7rkedbz4KUF4q9Y2i8sAXobq2vZpiVYz4KMK2l0WYFvh/ojFtyilRwZVL4Kl n25w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=ArLpIkQ7c47yNJU4L0ZrsYinx0893WVjwfNUj2QQbmKnga0JTJ0pCnnq6zuYpRnjXc 3kF2BiQSfdz9J1EpvnapatYzo30aV1HgHnO7BcMYoClW0u/HTTrqCNtv3UqVH+JBytUk e/0ZZgWkHccTalvwP6DW1dB+5ul7C0ssw1fV+NXsG5qgCUgZalfq91KGqYw2l5JepLtz 9h5Rt4fu470gn12O1y9sqCpT03ZhWhPiUu4/mg3oTQx9s44g/YC3qalAT+bCzC0qrcWH 1UoUoHzDdLtMxQkX5vcIOiDMNB0SJAkWX8hdjmgYjfopRkujRXTfIDqwZ7/3fT+qXo/K bfeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vWAf7VNJ; 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=pass (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 t137-20020a37aa8f000000b006fcaae20037si3747215qke.741.2023.02.21.18.02.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 21 Feb 2023 18:02:29 -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=pass header.i=@linaro.org header.s=google header.b=vWAf7VNJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pUeQx-00036A-5o; Tue, 21 Feb 2023 21:00:39 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pUeQu-00032z-7i for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:36 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pUeQs-00014S-L4 for qemu-devel@nongnu.org; Tue, 21 Feb 2023 21:00:35 -0500 Received: by mail-pl1-x630.google.com with SMTP id q11so7478272plx.5 for ; Tue, 21 Feb 2023 18:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=vWAf7VNJ8cFB73zb5ZKFtVK3NU5Ie3Ya1NJtuBimgfYWPUPGfoqBPYInxDOOjxi0U7 lgn9rMDNrH1dCh8tRJVPSQqZdFAgzu2z4YVEGM6iXjtU8iLpJ9YRmqwibGHu0hzHQo5h NcEQUjegHb+2YTyivB5UUEmREzswegrIfXA3nDUfvdQh8poKhLCxtQVFn8L3oJyAfRgM SeZxahAzoHQTxgOiMROQeberGnUqVN8lwFqMT/hvbsOhUg52C7NLOskDqIywb26aO5Cm egHksOAc6xWyArzKm2NAzvIi+w0sobxo9yuTPwmgOS17F5ypCE64pRAWcrFGhLXRzwyq rGFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zxPSc8yJkvzSaYSSEPoT7SrrtEyyDZGvKalhQ2ISznU=; b=rmTiwqBiNToQ8IrzM4KZ8WI2sM8j4jIy/Q9vDwcKZn+5lDnIx18KGHLay5PC48rWds FUpW0r4+gV66R1Czm9fmLr/V6W57L3ky4yjtH4C008DnrmSCit2KJfTLWdRsOOOiDLuL NXATin/ZBIGwUzQIxPoSoTAeopFTk28fdkAbD6kfLBkWPqhVLHN6G1bbvkZsfWjhylSJ 9jUPzmn58xR2N4GkO4+rBAAnzgOkEZHKjDNp+rnq3zVcA0Cyw01/dKPHjzP/djbMQtgb DiPpga+8y5FZXKWztIafngTg4XqECg1Oy3fBnonFyGKogQsr8zTRDmEr3LYsyz6di+xk QY9A== X-Gm-Message-State: AO0yUKWcPBzJT+KsJxaYhSDU838w0QASeQsgfUKsGweBFT8QaWpjURd9 fWJZXW0CDdCkjfwl8hfIuRADie6A9OOh7T0c5Uw= X-Received: by 2002:a17:902:e884:b0:198:dd3f:2847 with SMTP id w4-20020a170902e88400b00198dd3f2847mr10095406plg.21.1677031232896; Tue, 21 Feb 2023 18:00:32 -0800 (PST) Received: from stoup.. (rrcs-173-198-77-218.west.biz.rr.com. [173.198.77.218]) by smtp.gmail.com with ESMTPSA id 2-20020a170902c10200b00189743ed3b6sm91468pli.64.2023.02.21.18.00.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Feb 2023 18:00:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, Ilya Leoshkevich , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL v2 4/8] cpus: Make {start,end}_exclusive() recursive Date: Tue, 21 Feb 2023 16:00:19 -1000 Message-Id: <20230222020023.904232-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230222020023.904232-1-richard.henderson@linaro.org> References: <20230222020023.904232-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.google.com 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=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Ilya Leoshkevich Currently dying to one of the core_dump_signal()s deadlocks, because dump_core_and_abort() calls start_exclusive() two times: first via stop_all_tasks(), and then via preexit_cleanup() -> qemu_plugin_user_exit(). There are a number of ways to solve this: resume after dumping core; check cpu_in_exclusive_context() in qemu_plugin_user_exit(); or make {start,end}_exclusive() recursive. Pick the last option, since it's the most straightforward one. Fixes: da91c1920242 ("linux-user: Clean up when exiting due to a signal") Reviewed-by: Richard Henderson Reviewed-by: Alex Bennée Signed-off-by: Ilya Leoshkevich Message-Id: <20230214140829.45392-3-iii@linux.ibm.com> Signed-off-by: Richard Henderson --- include/hw/core/cpu.h | 4 ++-- cpus-common.c | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 2417597236..671f041bec 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -349,7 +349,7 @@ struct CPUState { bool unplug; bool crash_occurred; bool exit_request; - bool in_exclusive_context; + int exclusive_context_count; uint32_t cflags_next_tb; /* updates protected by BQL */ uint32_t interrupt_request; @@ -758,7 +758,7 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data */ static inline bool cpu_in_exclusive_context(const CPUState *cpu) { - return cpu->in_exclusive_context; + return cpu->exclusive_context_count; } /** diff --git a/cpus-common.c b/cpus-common.c index 793364dc0e..39f355de98 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -192,6 +192,11 @@ void start_exclusive(void) CPUState *other_cpu; int running_cpus; + if (current_cpu->exclusive_context_count) { + current_cpu->exclusive_context_count++; + return; + } + qemu_mutex_lock(&qemu_cpu_list_lock); exclusive_idle(); @@ -219,13 +224,16 @@ void start_exclusive(void) */ qemu_mutex_unlock(&qemu_cpu_list_lock); - current_cpu->in_exclusive_context = true; + current_cpu->exclusive_context_count = 1; } /* Finish an exclusive operation. */ void end_exclusive(void) { - current_cpu->in_exclusive_context = false; + current_cpu->exclusive_context_count--; + if (current_cpu->exclusive_context_count) { + return; + } qemu_mutex_lock(&qemu_cpu_list_lock); qatomic_set(&pending_cpus, 0);