From patchwork Wed Nov 2 11:41:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1698117 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=NZakEL/P; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N2Q5D2z9fz23l6 for ; Wed, 2 Nov 2022 22:43:44 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8M-0005Cr-EF; Wed, 02 Nov 2022 07:42:14 -0400 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 1oqC7m-00058B-4b for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqC7i-000525-Ue for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JhwjMHIjGnSGMT9O2iGklK6hwOae6WjgYLZOF8fZMBo=; b=NZakEL/Pxzhw8Sc2JW8iWkyHBAdrTHdINChiVRzCoCHzuwHQn47SK/YlV+sBY76vkQYgyD nzdIkL4mse7rKlo4Ylvuxs+qwTZF2o8PUIv3ABks/1stz4MqDd1wQDeQRCJW7BJvUHbpcX R+lbvEAs7u3EXNcnmOTtLX4MAgSSxqc= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-518-R3wvkuC2PZW00LE4emKBCA-1; Wed, 02 Nov 2022 07:41:32 -0400 X-MC-Unique: R3wvkuC2PZW00LE4emKBCA-1 Received: by mail-ej1-f70.google.com with SMTP id hq18-20020a1709073f1200b007ade8dd3494so3477337ejc.2 for ; Wed, 02 Nov 2022 04:41:32 -0700 (PDT) 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=JhwjMHIjGnSGMT9O2iGklK6hwOae6WjgYLZOF8fZMBo=; b=744FiPbT3BigfcqFqboCNWD5fwecBYCBW+VU01Qkqvvvi2169ud1QwLkuhnLCYOODN UsROJsZ+CI2TbVt7i1im4IdPrtKufS4zGSK4EQHjAf3dwMBr2y9WA6zz0m/Wf0u5ilA8 8uOLtTLQI2zVwHQXu6qqeooD31kOuuz/5OguTWc8GJqmC/ZifLpyQJPpOquxanfTORMj MGMO1Abu5m9AaEUXiMAm/nRZtVEbnAwkJpzX1g0RN4soPHFFJjolB01Oefi+oagRVMxd JoawCuJ5ZkOrQmPzgUCrPcFBBLiFgk+5EC2bTtVvLRKHK7A6eh+mnDfwWcpydtIidVSx E6OA== X-Gm-Message-State: ACrzQf1xk1elwIkfntTJtncJr59lUMdCqIV9sdrefrV0vJN5q1VSxWFo kivEiJZ/8m/Nn3NFbUXtRWO6I/9j/HTMyxIg4m1FXYgOLSabu2H5pBTn4fYVVkDhIB1AfpqCzVA Kl3uXDV9jN5pE4Zd58g1qVa0b/1HxVXB91QUj/rAwpf/CDdcRNdsWsGUfeV3pILw5jns= X-Received: by 2002:a05:6402:440c:b0:43a:1124:e56a with SMTP id y12-20020a056402440c00b0043a1124e56amr24765074eda.134.1667389290908; Wed, 02 Nov 2022 04:41:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Y36PxzD+7HpoTsbUuuhyfGFq8fZzFWo6cqBhHmc8xcpP/qvl+94+7aXxKoQsVcybCB+O3iQ== X-Received: by 2002:a05:6402:440c:b0:43a:1124:e56a with SMTP id y12-20020a056402440c00b0043a1124e56amr24765046eda.134.1667389290613; Wed, 02 Nov 2022 04:41:30 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id s29-20020a170906779d00b007add28659b0sm3524131ejm.140.2022.11.02.04.41.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:30 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Qi Hu , Jinyang Shen , Xuehai Chen Subject: [PULL 1/5] target/i386: Fix calculation of LOCK NEG eflags Date: Wed, 2 Nov 2022 12:41:21 +0100 Message-Id: <20221102114125.58902-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Qi Hu After: lock negl -0x14(%rbp) pushf pop %rax %rax will contain the wrong value because the "lock neg" calculates the wrong eflags. Simple test: #include int main() { __volatile__ unsigned test = 0x2363a; __volatile__ char cond = 0; asm( "lock negl %0 \n\t" "sets %1" : "=m"(test), "=r"(cond)); assert(cond & 1); return 0; } Reported-by: Jinyang Shen Co-Developed-by: Xuehai Chen Signed-off-by: Xuehai Chen Signed-off-by: Qi Hu Signed-off-by: Paolo Bonzini --- target/i386/tcg/translate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c index 546c427c232f..c477a10f410c 100644 --- a/target/i386/tcg/translate.c +++ b/target/i386/tcg/translate.c @@ -3300,7 +3300,7 @@ static bool disas_insn(DisasContext *s, CPUState *cpu) tcg_temp_free(t2); tcg_temp_free(a0); - tcg_gen_mov_tl(s->T0, t0); + tcg_gen_neg_tl(s->T0, t0); tcg_temp_free(t0); } else { tcg_gen_neg_tl(s->T0, s->T0); From patchwork Wed Nov 2 11:41:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1698116 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=HzERDFOh; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N2Q591bkdz23l6 for ; Wed, 2 Nov 2022 22:43:41 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8P-0005FI-Bp; Wed, 02 Nov 2022 07:42:17 -0400 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 1oqC7q-00058l-OT for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqC7l-00055c-RH for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TRE/5HZkVNskGDDtdZR7CgqjPZxiIinW3+ucMgGb+Jo=; b=HzERDFOh4CHbD+Kt+jQgpN52u8TOTKSzbSHebguM/NI+MBH63WT7E4yji7On4xQgMaibvG cEGoN1uAe+EFEcDI/mS5IVBB+Sk3CxX65kiOkR02vIFB75LV8cf4ZtXs8BCrkeU93ZYKl3 xlFjEAqV5C7vCJlQnWL5b6058fgZkrs= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-628-Sdik7XHXPtKfxEnI0JwziA-1; Wed, 02 Nov 2022 07:41:36 -0400 X-MC-Unique: Sdik7XHXPtKfxEnI0JwziA-1 Received: by mail-ej1-f72.google.com with SMTP id qw17-20020a1709066a1100b0078e25b6a52fso9678781ejc.3 for ; Wed, 02 Nov 2022 04:41:35 -0700 (PDT) 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=TRE/5HZkVNskGDDtdZR7CgqjPZxiIinW3+ucMgGb+Jo=; b=maXPAvG6HeI5cE5pVNT6+nmqf1yspB1ZfXA76184vk0kOnZjfIP6HJHiytcaRgUyu5 gYWaKcQ3WiL+10LJ6e2xgtoD5q7vx+CLv7IIscetuPFRyDcXbG36YSvvvXZlnCcB6I0J UZPg2LAR6cwv1m3fP+hI+aWWPykzxkULzydH9E/W1/1UBVb2/+Yd4fyIgvAU5diVrvLI 5ZEhxmFFnfWWfd8lll5fem+QvZZfvHCHZzQyRrkFD1r2jtsE2ZH1vXy2mbTS+3DDDhuB DP3d3jqevb2jKvxwylroIJK2TYse0I+hujPSXmvUgyhyu6LSBs0ntJIQhbOYxNcoJ5Yq 0OTQ== X-Gm-Message-State: ACrzQf2VnkC9rKf7ezQWBNT+Ozbi189g1bbcmAnHMkq5cFxwDx3LsP03 +Mf/3rD1O18/fXFhpmNexTbza/VO8Fgp9dU+AZ3RHsEpnZbjjRMsd0+oFPjXWQcyl5QezrfFBxx 1BGsHZkZUtrSGUzfzTlC/NC+UhNsDkHjsxlLNltTPuOzrC7V8nNl8YoKM6ISXsjwCqTI= X-Received: by 2002:a17:907:6288:b0:78d:ab30:c374 with SMTP id nd8-20020a170907628800b0078dab30c374mr23376647ejc.266.1667389293686; Wed, 02 Nov 2022 04:41:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5bz4ZYSZjyk3XelgHbtmDRYSl16PxtodEiiHgRm+CPLzoTDowmBuA7tHGAnBs2IL/L6gzjTg== X-Received: by 2002:a17:907:6288:b0:78d:ab30:c374 with SMTP id nd8-20020a170907628800b0078dab30c374mr23376614ejc.266.1667389293294; Wed, 02 Nov 2022 04:41:33 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id 2-20020a170906218200b0077a8fa8ba55sm5263807eju.210.2022.11.02.04.41.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:32 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Claudio Imbrenda , Murilo Opsfelder Araujo Subject: [PULL 2/5] os-posix: asynchronous teardown for shutdown on Linux Date: Wed, 2 Nov 2022 12:41:22 +0100 Message-Id: <20221102114125.58902-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Claudio Imbrenda This patch adds support for asynchronously tearing down a VM on Linux. When qemu terminates, either naturally or because of a fatal signal, the VM is torn down. If the VM is huge, it can take a considerable amount of time for it to be cleaned up. In case of a protected VM, it might take even longer than a non-protected VM (this is the case on s390x, for example). Some users might want to shut down a VM and restart it immediately, without having to wait. This is especially true if management infrastructure like libvirt is used. This patch implements a simple trick on Linux to allow qemu to return immediately, with the teardown of the VM being performed asynchronously. If the new commandline option -async-teardown is used, a new process is spawned from qemu at startup, using the clone syscall, in such way that it will share its address space with qemu.The new process will have the name "cleanup/". It will wait until qemu terminates completely, and then it will exit itself. This allows qemu to terminate quickly, without having to wait for the whole address space to be torn down. The cleanup process will exit after qemu, so it will be the last user of the address space, and therefore it will take care of the actual teardown. The cleanup process will share the same cgroups as qemu, so both memory usage and cpu time will be accounted properly. If possible, close_range will be used in the cleanup process to close all open file descriptors. If it is not available or if it fails, /proc will be used to determine which file descriptors to close. If the cleanup process is forcefully killed with SIGKILL before the main qemu process has terminated completely, the mechanism is defeated and the teardown will not be asynchronous. This feature can already be used with libvirt by adding the following to the XML domain definition to pass the parameter to qemu directly: Signed-off-by: Claudio Imbrenda Reviewed-by: Murilo Opsfelder Araujo Tested-by: Murilo Opsfelder Araujo Message-Id: <20220812133453.82671-1-imbrenda@linux.ibm.com> Signed-off-by: Paolo Bonzini --- include/qemu/async-teardown.h | 22 +++++ meson.build | 1 + os-posix.c | 6 ++ qemu-options.hx | 19 +++++ util/async-teardown.c | 150 ++++++++++++++++++++++++++++++++++ util/meson.build | 1 + 6 files changed, 199 insertions(+) create mode 100644 include/qemu/async-teardown.h create mode 100644 util/async-teardown.c diff --git a/include/qemu/async-teardown.h b/include/qemu/async-teardown.h new file mode 100644 index 000000000000..092e7a37e7af --- /dev/null +++ b/include/qemu/async-teardown.h @@ -0,0 +1,22 @@ +/* + * Asynchronous teardown + * + * Copyright IBM, Corp. 2022 + * + * Authors: + * Claudio Imbrenda + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at your + * option) any later version. See the COPYING file in the top-level directory. + * + */ +#ifndef QEMU_ASYNC_TEARDOWN_H +#define QEMU_ASYNC_TEARDOWN_H + +#include "config-host.h" + +#ifdef CONFIG_LINUX +void init_async_teardown(void); +#endif + +#endif diff --git a/meson.build b/meson.build index 37737913df6a..17834b3c3def 100644 --- a/meson.build +++ b/meson.build @@ -1949,6 +1949,7 @@ if targetos == 'windows' endif # has_function +config_host_data.set('CONFIG_CLOSE_RANGE', cc.has_function('close_range')) config_host_data.set('CONFIG_ACCEPT4', cc.has_function('accept4')) config_host_data.set('CONFIG_CLOCK_ADJTIME', cc.has_function('clock_adjtime')) config_host_data.set('CONFIG_DUP3', cc.has_function('dup3')) diff --git a/os-posix.c b/os-posix.c index 321fc4bd13b8..4858650c3e38 100644 --- a/os-posix.c +++ b/os-posix.c @@ -39,6 +39,7 @@ #ifdef CONFIG_LINUX #include +#include "qemu/async-teardown.h" #endif /* @@ -150,6 +151,11 @@ int os_parse_cmd_args(int index, const char *optarg) case QEMU_OPTION_daemonize: daemonize = 1; break; +#if defined(CONFIG_LINUX) + case QEMU_OPTION_asyncteardown: + init_async_teardown(); + break; +#endif default: return -1; } diff --git a/qemu-options.hx b/qemu-options.hx index eb38e5dc40bc..e26d1dad3990 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4774,6 +4774,25 @@ HXCOMM Internal use DEF("qtest", HAS_ARG, QEMU_OPTION_qtest, "", QEMU_ARCH_ALL) DEF("qtest-log", HAS_ARG, QEMU_OPTION_qtest_log, "", QEMU_ARCH_ALL) +#ifdef __linux__ +DEF("async-teardown", 0, QEMU_OPTION_asyncteardown, + "-async-teardown enable asynchronous teardown\n", + QEMU_ARCH_ALL) +#endif +SRST +``-async-teardown`` + Enable asynchronous teardown. A new process called "cleanup/" + will be created at startup sharing the address space with the main qemu + process, using clone. It will wait for the main qemu process to + terminate completely, and then exit. + This allows qemu to terminate very quickly even if the guest was + huge, leaving the teardown of the address space to the cleanup + process. Since the cleanup process shares the same cgroups as the + main qemu process, accounting is performed correctly. This only + works if the cleanup process is not forcefully killed with SIGKILL + before the main qemu process has terminated completely. +ERST + DEF("msg", HAS_ARG, QEMU_OPTION_msg, "-msg [timestamp[=on|off]][,guest-name=[on|off]]\n" " control error message format\n" diff --git a/util/async-teardown.c b/util/async-teardown.c new file mode 100644 index 000000000000..62bfce1b3ca8 --- /dev/null +++ b/util/async-teardown.c @@ -0,0 +1,150 @@ +/* + * Asynchronous teardown + * + * Copyright IBM, Corp. 2022 + * + * Authors: + * Claudio Imbrenda + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at your + * option) any later version. See the COPYING file in the top-level directory. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "qemu/osdep.h" +#include "qemu/async-teardown.h" + +#ifdef _SC_THREAD_STACK_MIN +#define CLONE_STACK_SIZE sysconf(_SC_THREAD_STACK_MIN) +#else +#define CLONE_STACK_SIZE 16384 +#endif + +static pid_t the_ppid; + +/* + * Close all open file descriptors. + */ +static void close_all_open_fd(void) +{ + struct dirent *de; + int fd, dfd; + DIR *dir; + +#ifdef CONFIG_CLOSE_RANGE + int r = close_range(0, ~0U, 0); + if (!r) { + /* Success, no need to try other ways. */ + return; + } +#endif + + dir = opendir("/proc/self/fd"); + if (!dir) { + /* If /proc is not mounted, there is nothing that can be done. */ + return; + } + /* Avoid closing the directory. */ + dfd = dirfd(dir); + + for (de = readdir(dir); de; de = readdir(dir)) { + fd = atoi(de->d_name); + if (fd != dfd) { + close(fd); + } + } + closedir(dir); +} + +static void hup_handler(int signal) +{ + /* Check every second if this process has been reparented. */ + while (the_ppid == getppid()) { + /* sleep() is safe to use in a signal handler. */ + sleep(1); + } + + /* At this point the parent process has terminated completely. */ + _exit(0); +} + +static int async_teardown_fn(void *arg) +{ + struct sigaction sa = { .sa_handler = hup_handler }; + sigset_t hup_signal; + char name[16]; + + /* Set a meaningful name for this process. */ + snprintf(name, 16, "cleanup/%d", the_ppid); + prctl(PR_SET_NAME, (unsigned long)name); + + /* + * Close all file descriptors that might have been inherited from the + * main qemu process when doing clone, needed to make libvirt happy. + * Not using close_range for increased compatibility with older kernels. + */ + close_all_open_fd(); + + /* Set up a handler for SIGHUP and unblock SIGHUP. */ + sigaction(SIGHUP, &sa, NULL); + sigemptyset(&hup_signal); + sigaddset(&hup_signal, SIGHUP); + sigprocmask(SIG_UNBLOCK, &hup_signal, NULL); + + /* Ask to receive SIGHUP when the parent dies. */ + prctl(PR_SET_PDEATHSIG, SIGHUP); + + /* + * Sleep forever, unless the parent process has already terminated. The + * only interruption can come from the SIGHUP signal, which in normal + * operation is received when the parent process dies. + */ + if (the_ppid == getppid()) { + pause(); + } + + /* At this point the parent process has terminated completely. */ + _exit(0); +} + +/* + * Allocate a new stack of a reasonable size, and return a pointer to its top. + */ +static void *new_stack_for_clone(void) +{ + size_t stack_size = CLONE_STACK_SIZE; + char *stack_ptr; + + /* Allocate a new stack and get a pointer to its top. */ + stack_ptr = qemu_alloc_stack(&stack_size); +#if !defined(HOST_HPPA) + /* The top is at the end of the area, except on HPPA. */ + stack_ptr += stack_size; +#endif + + return stack_ptr; +} + +/* + * Block all signals, start (clone) a new process sharing the address space + * with qemu (CLONE_VM), then restore signals. + */ +void init_async_teardown(void) +{ + sigset_t all_signals, old_signals; + + the_ppid = getpid(); + + sigfillset(&all_signals); + sigprocmask(SIG_BLOCK, &all_signals, &old_signals); + clone(async_teardown_fn, new_stack_for_clone(), CLONE_VM, NULL); + sigprocmask(SIG_SETMASK, &old_signals, NULL); +} diff --git a/util/meson.build b/util/meson.build index 5e282130df85..63acd59bb02c 100644 --- a/util/meson.build +++ b/util/meson.build @@ -2,6 +2,7 @@ util_ss.add(files('osdep.c', 'cutils.c', 'unicode.c', 'qemu-timer-common.c')) if not config_host_data.get('CONFIG_ATOMIC64') util_ss.add(files('atomic64.c')) endif +util_ss.add(when: 'CONFIG_LINUX', if_true: files('async-teardown.c')) util_ss.add(when: 'CONFIG_POSIX', if_true: files('aio-posix.c')) util_ss.add(when: 'CONFIG_POSIX', if_true: files('fdmon-poll.c')) if config_host_data.get('CONFIG_EPOLL_CREATE1') From patchwork Wed Nov 2 11:41:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1698115 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=D91sZDAu; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N2Q582Hyvz23l6 for ; Wed, 2 Nov 2022 22:43:40 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8N-0005DT-Nb; Wed, 02 Nov 2022 07:42:15 -0400 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 1oqC7s-00058s-3C for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqC7q-0005Bm-Gm for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QbtLKVZd0RBMCQcMwj1oY0O7eZja6HLh6zFQEYp3+Yg=; b=D91sZDAuXEdbKyIxv+48NopcIoDnqvn4z0m3fNs54RQPF2P/Ri4KxZsUgmhKM91EkceBfo Pw5iVeuzb1CBxJFoO5/thJEUnizDNrnoJkSSmtZHCTHj1iyIuTXrPiu8Iw/FLjF//cW21Y o/eGlpIBlbqtBFiJjB9CHSVuOz7f8Xs= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-142-dddgdqDgNmesVIzfHHar6w-1; Wed, 02 Nov 2022 07:41:38 -0400 X-MC-Unique: dddgdqDgNmesVIzfHHar6w-1 Received: by mail-ed1-f70.google.com with SMTP id l18-20020a056402255200b004633509768bso6480699edb.12 for ; Wed, 02 Nov 2022 04:41:38 -0700 (PDT) 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=QbtLKVZd0RBMCQcMwj1oY0O7eZja6HLh6zFQEYp3+Yg=; b=4WxzLK/Y/+3nJmildatpCaOqa4g3Lvt/GRytowz47jC+ySAmaNPe0PN+1uWYiiUVJI SZJeYU/oJIgIo82IAcIYNarIbA7+GRPbNCueRG/zmNoQNKn/mUi/XMrYNxn9VaRUTeRu Ukb/dsFdC1+ErPejn2GyfO7elI0hMem2nYEPwYKNmopw1TPGRZ9tU+B4g+ePek10Em2e amls0GFhmBC4a8eQgKGRm9E+hyH4qqWQrtfBLeoJXbAspHwgU6aemaaSUwJbTziQ1SSc IxzXfp6mpfE6H0Qxev/CEdBIx0YkHU16miY1sDkDwiHqargn6FKd5YJUab0TkW4rSYPU hUEg== X-Gm-Message-State: ACrzQf0tS0Kwai5LHQ6a5DcVzzK6UGmOPr68G4dU9KhBZxQRj+9qxRUQ B9k4Yml9UQpesiT20nbpa4vfWC9AQctrBjIcMc4zChR9Bne0pUISHs3r3Xlc05vOS2m6zlrzYbX eyJy5ecBKKDCV14vcUdfJ4WvzZzgz7Nc6aZiuLxznXAw72GkBqCy11zoQw/HMuvsR26g= X-Received: by 2002:a17:907:6e9e:b0:78c:5533:4158 with SMTP id sh30-20020a1709076e9e00b0078c55334158mr21870582ejc.417.1667389296295; Wed, 02 Nov 2022 04:41:36 -0700 (PDT) X-Google-Smtp-Source: AMsMyM449Cwch6rtuHuxwDLf1qvPyIUKs2DHXPr8o/562xVe6ATxsDxYbijUTCuHRTK79nKEyEhz/w== X-Received: by 2002:a17:907:6e9e:b0:78c:5533:4158 with SMTP id sh30-20020a1709076e9e00b0078c55334158mr21870562ejc.417.1667389296007; Wed, 02 Nov 2022 04:41:36 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id ce24-20020a170906b25800b007a7f9b6318asm5331814ejb.50.2022.11.02.04.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:35 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Zeng Guang , Peter Xu , "Michael S . Tsirkin" Subject: [PULL 3/5] target/i386: Set maximum APIC ID to KVM prior to vCPU creation Date: Wed, 2 Nov 2022 12:41:23 +0100 Message-Id: <20221102114125.58902-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Zeng Guang Specify maximum possible APIC ID assigned for current VM session to KVM prior to the creation of vCPUs. By this setting, KVM can set up VM-scoped data structure indexed by the APIC ID, e.g. Posted-Interrupt Descriptor pointer table to support Intel IPI virtualization, with the most optimal memory footprint. It can be achieved by calling KVM_ENABLE_CAP for KVM_CAP_MAX_VCPU_ID capability once KVM has enabled it. Ignoring the return error if KVM doesn't support this capability yet. Signed-off-by: Zeng Guang Acked-by: Peter Xu Acked-by: Michael S. Tsirkin Message-Id: <20220825025246.26618-1-guang.zeng@intel.com> Signed-off-by: Paolo Bonzini --- hw/i386/x86.c | 4 ++++ target/i386/kvm/kvm-stub.c | 5 +++++ target/i386/kvm/kvm.c | 5 +++++ target/i386/kvm/kvm_i386.h | 2 ++ 4 files changed, 16 insertions(+) diff --git a/hw/i386/x86.c b/hw/i386/x86.c index bd50a064a36d..78cc131926c8 100644 --- a/hw/i386/x86.c +++ b/hw/i386/x86.c @@ -140,6 +140,10 @@ void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version) exit(EXIT_FAILURE); } + if (kvm_enabled()) { + kvm_set_max_apic_id(x86ms->apic_id_limit); + } + possible_cpus = mc->possible_cpu_arch_ids(ms); for (i = 0; i < ms->smp.cpus; i++) { x86_cpu_new(x86ms, possible_cpus->cpus[i].arch_id, &error_fatal); diff --git a/target/i386/kvm/kvm-stub.c b/target/i386/kvm/kvm-stub.c index f6e7e4466e1a..e052f1c7b0ef 100644 --- a/target/i386/kvm/kvm-stub.c +++ b/target/i386/kvm/kvm-stub.c @@ -44,3 +44,8 @@ bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp) { abort(); } + +void kvm_set_max_apic_id(uint32_t max_apic_id) +{ + return; +} diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 4df04280890a..a21320937943 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -5723,3 +5723,8 @@ void kvm_arch_accel_class_init(ObjectClass *oc) "Clock cycles without an event window " "after which a notification VM exit occurs"); } + +void kvm_set_max_apic_id(uint32_t max_apic_id) +{ + kvm_vm_enable_cap(kvm_state, KVM_CAP_MAX_VCPU_ID, 0, max_apic_id); +} diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h index b7c38ba2c462..6a5c24e3dc40 100644 --- a/target/i386/kvm/kvm_i386.h +++ b/target/i386/kvm/kvm_i386.h @@ -66,4 +66,6 @@ typedef struct kvm_msr_handlers { bool kvm_filter_msr(KVMState *s, uint32_t msr, QEMURDMSRHandler *rdmsr, QEMUWRMSRHandler *wrmsr); +void kvm_set_max_apic_id(uint32_t max_apic_id); + #endif From patchwork Wed Nov 2 11:41:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1698118 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e+2tKXrL; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N2Q5f6cy6z23l6 for ; Wed, 2 Nov 2022 22:44:06 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8R-0005HK-MJ; Wed, 02 Nov 2022 07:42:19 -0400 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 1oqC7t-00059I-Jy for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqC7r-0005Kf-7T for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389302; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9rn09GQMUOF2ydOhkJImYso5UybJw5X/9JLC4pgsyc8=; b=e+2tKXrLBtLxBGjhaEvlzi79DO2XjbHhI+DxwjXP1GDxznQug7ySilFfvXwdbXrMpNQNhn u2JBMz/m2T9P+s3pCrqCGPUBXjoM1JD4AR8kiSsu7GCwuqQ7gnN6/hmeO/O1pX0J9jSVE9 /mzJuh1GEYwmcmf6b2TGAWNeD+EoiwE= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-167-SltbX5WxOzCZyo6AzfMn3w-1; Wed, 02 Nov 2022 07:41:41 -0400 X-MC-Unique: SltbX5WxOzCZyo6AzfMn3w-1 Received: by mail-ej1-f70.google.com with SMTP id hq18-20020a1709073f1200b007ade8dd3494so3477498ejc.2 for ; Wed, 02 Nov 2022 04:41:41 -0700 (PDT) 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=9rn09GQMUOF2ydOhkJImYso5UybJw5X/9JLC4pgsyc8=; b=6jBxixp7eeCfJ0daRGkV4EzjiEz8z1BmC5gwkasewQ+MLd4WJyE0UFcVEgIrfWV0DF yHFj2h4V6mhjitLQZfBuUVJT0us2mEWLphQNEoJ2Rq9JCExdkB0W5aqMZ2pRQqsjVgW+ FcT5h8pj73f5lCHxBTcZIZXErQ4J7e8WR2BYS3gVrrJCCJsWM6wdXJ2TDQFIx1o9KZIV 3JbGKWgKJwCP7RkN91jkMXMMe/vRysJ5on72ZE0Ip4csSCrWa99slKAQRoMn+Yl7zF5J nFZ5QyXONiF9Oltai10lp/9gFOnQkghVM1kVvkegH0ZK5z36SY7uW49s56FEPQPkTDyO MiBA== X-Gm-Message-State: ACrzQf0N60WrbqWwz2o6Vhik4YhYDp6sUXbzdG06ccif04HSm7Hwq3pf pqs4i+7iAVTlm8NWqXU8uo/ZsDNPN21zC0Zvn6xKqzScNOC09Y7aVg/+2bmoVJb9Tmw7DNMZeGE AQed/L83PtG2QnDui7eYgA/4SQ6DcywQ7izulsRpr3hzBAGLFfVRSUL64OURV7j+BLAA= X-Received: by 2002:a17:907:b16:b0:7ad:855b:c08c with SMTP id h22-20020a1709070b1600b007ad855bc08cmr23565671ejl.667.1667389299510; Wed, 02 Nov 2022 04:41:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EBYlLU0PEqjhSZ0gRiOuYy2bH/tA7NBwtPf8185P3mXcxH04ZaA5ayzLJMC5nYH771SezQA== X-Received: by 2002:a17:907:b16:b0:7ad:855b:c08c with SMTP id h22-20020a1709070b1600b007ad855bc08cmr23565652ejl.667.1667389299273; Wed, 02 Nov 2022 04:41:39 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id m27-20020a170906259b00b0077016f4c6d4sm5329879ejb.55.2022.11.02.04.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Greg Kurz , richard.henderson@linaro.org Subject: [PULL 4/5] util/log: Close per-thread log file on thread termination Date: Wed, 2 Nov 2022 12:41:24 +0100 Message-Id: <20221102114125.58902-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Greg Kurz When `-D ${logfile} -d tid` is passed, qemu_log_trylock() creates a dedicated log file for the current thread and opens it. The corresponding file descriptor is cached in a __thread variable. Nothing is done to close the corresponding file descriptor when the thread terminates though and the file descriptor is leaked. The issue was found during code inspection and reproduced manually. Fix that with an atexit notifier. Fixes: 4e51069d6793 ("util/log: Support per-thread log files") Cc: richard.henderson@linaro.org Signed-off-by: Greg Kurz Message-Id: <20221021105734.555797-1-groug@kaod.org> Signed-off-by: Paolo Bonzini --- util/log.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/log.c b/util/log.c index d6eb0378c3a3..39866bdaf2fa 100644 --- a/util/log.c +++ b/util/log.c @@ -42,6 +42,7 @@ static QemuMutex global_mutex; static char *global_filename; static FILE *global_file; static __thread FILE *thread_file; +static __thread Notifier qemu_log_thread_cleanup_notifier; int qemu_loglevel; static bool log_append; @@ -77,6 +78,12 @@ static int log_thread_id(void) #endif } +static void qemu_log_thread_cleanup(Notifier *n, void *unused) +{ + fclose(thread_file); + thread_file = NULL; +} + /* Lock/unlock output. */ FILE *qemu_log_trylock(void) @@ -93,6 +100,8 @@ FILE *qemu_log_trylock(void) return NULL; } thread_file = logfile; + qemu_log_thread_cleanup_notifier.notify = qemu_log_thread_cleanup; + qemu_thread_atexit_add(&qemu_log_thread_cleanup_notifier); } else { rcu_read_lock(); /* From patchwork Wed Nov 2 11:41:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1698119 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RCTt4Pth; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4N2Q6x5S0sz23lK for ; Wed, 2 Nov 2022 22:45:13 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8T-0005Hv-1P; Wed, 02 Nov 2022 07:42:21 -0400 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 1oqC7v-00059V-Ek for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oqC7t-0005Nw-My for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389305; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Au5lB1o4PdSr952SmEZ4IrudR5JlexcK/wWief35hc=; b=RCTt4PthLM926DujS36e7eTUMYeTVInjnho0G5k7yNrXxbCx2zTl/u0VfX2vQJfyWNrLS8 03k/oKAX5lZIFm6Tgl3FI3fLA9NtNc9cXgOViqlZhFhMSRAaKlwZ6M33mVFN0evUBjGFrN 5cK/y9mtY+BP6xxlUwSxLnq6aQLLCrM= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-643-qZJJmnHNNHaMWehVzH8Kzg-1; Wed, 02 Nov 2022 07:41:43 -0400 X-MC-Unique: qZJJmnHNNHaMWehVzH8Kzg-1 Received: by mail-ed1-f72.google.com with SMTP id w4-20020a05640234c400b004631f8923baso6817570edc.5 for ; Wed, 02 Nov 2022 04:41:43 -0700 (PDT) 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=7Au5lB1o4PdSr952SmEZ4IrudR5JlexcK/wWief35hc=; b=zZogmpgEN4txnQpMDLzs5RyCtyeyHwCmV8CTJrYfZiVyMaBHSRZCIijMYhIHMNnecC tvKa9htysur7GKm7CJuDmSqF7aT69FZMvncow09MENyvOE99623BW44r3VR06tzHWrZl bJ8KmHtvuOcYuv201Gxw/FWJpmwPP+EAlN4SqkjLg7MHk/SqzKjXCyLMMVw2TyEU7QSo fOJIwTuIIv4xL1iNfuy6PGaTI/LZHCdtm69ROSoWQyElJwalpp50KxEICfLAlKywQnjD ery1YAa/yLAFUy6W38law+ohp6UUpxfZj2zDzBixvOdI38j5HL0ZzOqcYJ9+q/icPPox KlvA== X-Gm-Message-State: ACrzQf1+Vt8l64gDvtjJYEIVrIFdXLXMLQjEg+ma5vlDqbxJ+k3E6Xhb bouYTIhYej6gK3yFQGrPSB6YY7JUrfNqy8h0LdzoMGzNFpnuy4hdNBGM25+MRt+zT4GKYkAyPCK lzsW61IUF4G0n7Xm0j6Vno92adVLV3/q3Amn3kgeXE+m695V8RXj1qG3qErSQzgQeoxE= X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr24222228edi.121.1667389302080; Wed, 02 Nov 2022 04:41:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7MQZwE9mU7Va1DAgmRgQ5CzfF5WctnQM+h98g1Jw9GCHdK/ys9ztbNIrxObWs/3lMT1Ih+rg== X-Received: by 2002:a50:cc07:0:b0:453:4427:a918 with SMTP id m7-20020a50cc07000000b004534427a918mr24222207edi.121.1667389301807; Wed, 02 Nov 2022 04:41:41 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id n11-20020a170906118b00b0078116c361d9sm5384039eja.10.2022.11.02.04.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Richard Henderson , Andreas Gustafsson Subject: [PULL 5/5] target/i386: Fix test for paging enabled Date: Wed, 2 Nov 2022 12:41:25 +0100 Message-Id: <20221102114125.58902-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-1-pbonzini@redhat.com> MIME-Version: 1.0 Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Richard Henderson If CR0.PG is unset, pg_mode will be zero, but it will also be zero for non-PAE/non-PSE page tables with CR0.WP=0. Restore the correct test for paging enabled. Fixes: 98281984a37 ("target/i386: Add MMU_PHYS_IDX and MMU_NESTED_IDX") Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1269 Reported-by: Andreas Gustafsson Signed-off-by: Richard Henderson Message-Id: <20221102091232.1092552-1-richard.henderson@linaro.org> Signed-off-by: Paolo Bonzini --- target/i386/tcg/sysemu/excp_helper.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/i386/tcg/sysemu/excp_helper.c b/target/i386/tcg/sysemu/excp_helper.c index d51b5d7431a0..405a5d414a14 100644 --- a/target/i386/tcg/sysemu/excp_helper.c +++ b/target/i386/tcg/sysemu/excp_helper.c @@ -553,12 +553,12 @@ static bool get_physical_address(CPUX86State *env, vaddr addr, break; default: - in.cr3 = env->cr[3]; - in.mmu_idx = mmu_idx; - in.ptw_idx = use_stage2 ? MMU_NESTED_IDX : MMU_PHYS_IDX; - in.pg_mode = get_pg_mode(env); + if (likely(env->cr[0] & CR0_PG_MASK)) { + in.cr3 = env->cr[3]; + in.mmu_idx = mmu_idx; + in.ptw_idx = use_stage2 ? MMU_NESTED_IDX : MMU_PHYS_IDX; + in.pg_mode = get_pg_mode(env); - if (likely(in.pg_mode)) { if (in.pg_mode & PG_MODE_LMA) { /* test virtual address sign extension */ int shift = in.pg_mode & PG_MODE_LA57 ? 56 : 47;