From nobody Thu Nov 28 09:38:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=outlook.com); dmarc=pass(p=none dis=none) header.from=outlook.com ARC-Seal: i=2; a=rsa-sha256; t=1693211280; cv=pass; d=zohomail.com; s=zohoarc; b=HGokKHe3+MXfVaYsQ1gPUCXco3WjbH/UNAeZNtslhA1TacpO7gyLYkjNIdLa3NMnrtq26H0ZBLsBFzX/WYbvYHrNG/EEqOCJWeiy4ADi/MweWg7KgaPJxyjr3zUUVCXLtIw11yFCMT98tbsYvsBYhhhX6k/BlhcFjrYT4aHA8Kw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1693211280; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=iHLbtrHS3JmLLeRIJcIqJKU02U/YbbCgPid0CBqYSW0=; b=KEt+LT8pRVlkuA4bfoDmtkezQObzUgjm3U240BXlQ1Bk7RkfYn7jjuqtxSkn+WFkQRoyU5zV+9FpNUvY3CFRI9OP9Vg743513Rqhxrop055o8dMpv2n75STTvSYCrxUdipXD1kpfJT2V0DY2aQKu4p+Swi87Yt31/4gvIRvjHnY= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1 dmarc=pass fromdomain=outlook.com); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1693211280384114.31056284755391; Mon, 28 Aug 2023 01:28:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qaXb4-0007Tv-6N; Mon, 28 Aug 2023 04:27:43 -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 1qaXay-0007Sl-Dl for qemu-devel@nongnu.org; Mon, 28 Aug 2023 04:27:37 -0400 Received: from mail-dm6nam10olkn2081.outbound.protection.outlook.com ([40.92.41.81] helo=NAM10-DM6-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qaXav-0004mI-1R for qemu-devel@nongnu.org; Mon, 28 Aug 2023 04:27:35 -0400 Received: from SA1PR11MB6760.namprd11.prod.outlook.com (2603:10b6:806:25f::14) by SA0PR11MB4605.namprd11.prod.outlook.com (2603:10b6:806:95::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.34; Mon, 28 Aug 2023 08:22:27 +0000 Received: from SA1PR11MB6760.namprd11.prod.outlook.com ([fe80::df85:2db:d56b:38bf]) by SA1PR11MB6760.namprd11.prod.outlook.com ([fe80::df85:2db:d56b:38bf%5]) with mapi id 15.20.6699.034; Mon, 28 Aug 2023 08:22:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HQ3MsGH7dxyFXvAnHFy25SUBlMfYjaFxcssH7uy/OoHtSY41poPLK9rVZlJh+BaBoBLotb8qVuxrYfvuN7kRbFsCIwZbXy1vNY2zRT2KH7dgW4EJoN1itL2EWf0/9+kZOcCTZEPUCjHcBCV+sBNwicem2W47DZQT+7nKuUf8iWw9u0nygP51RVG+hcvaSbuzL+cPFsUqUtIqV++bHDfd6EjISnaU4iog2DklRqaMUe/tVXgWFm//HoRn4PI2sQILyKJJv/rjBycfFW8un54MEkQSluY6T0L5OiYmSyXlh1w7PlG5TF8YfjHnqNMjypxSusio2wP9eZKH9LEYBE4o7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iHLbtrHS3JmLLeRIJcIqJKU02U/YbbCgPid0CBqYSW0=; b=Z6zZIqlIFv8XCFV4sT3Ko/QbjRpJQVl6xVRtQV8WrqZeUngIL+F6+daKUHrR6fwhKAdLJ5MDl62ffo+/e1yeTvU2oonEiAx/2i39q/8o5/LUU+NkkbgtXrBFxclh+qL4vJU4NF03xJKN5RcfEwsAZimXIuEHIII3KKXXpWDkmPvgYKjvjhWePxTJzZQMKKd8pxeFmQw5ayM6WVJOy2/71MTg+BUBuItR6nBFFascz0uVZXFT4ZJ+hxf9sqR/tTxSxtjZ1uqc2ZO6/tkGf1QElRuJlbe+DcvZA46EVDz1Vde3Ez6vTQfAPOBuC5F9gAEae/JpUlTgiI2HHc+nGxtyHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iHLbtrHS3JmLLeRIJcIqJKU02U/YbbCgPid0CBqYSW0=; b=cIx4MTYXUZ14EZB85Q8Fi306SJSyE6AfqSR5HinpizsJ9wR86SDRvQgwlfprfNRVxXEwlnLKe+T+4i7FcII24tIz/CXnScAJfGpaXjSS1/YbDnzUqir4+GSCyJQjkX/HgbwnQtSY/65mQ4Wg7jdPBSXWabf7Vbq2kbtB4tSoArk8D7D7Pb5QQj4PbkPFwmNL6PeNt1pXokn7/fSKNznvE1Vl51dC3qtJmRjdJtaCc1mqWhnFPjzAN+RYAEfMh0U5/QhLtTf3X/7MEbEXon98MXrw4JgY+PhVb15TAv/s5Zp7tvKZmum9T3G0tfnlGUDh2AYlo1oF3bpKasY25kePUg== From: alloc.young@outlook.com To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, qemu-devel@nongnu.org, alloc Subject: [PATCH] accel/kvm: Fix dirty reaper thread crash Date: Mon, 28 Aug 2023 16:22:04 +0800 Message-ID: X-Mailer: git-send-email 2.39.3 Content-Transfer-Encoding: quoted-printable X-TMN: [9+DJXloxmERZguKQAUJsVjU3/588wANMEatKQszgLkA=] X-ClientProxiedBy: SG2PR03CA0091.apcprd03.prod.outlook.com (2603:1096:4:7c::19) To SA1PR11MB6760.namprd11.prod.outlook.com (2603:10b6:806:25f::14) X-Microsoft-Original-Message-ID: <20230828082204.1238103-1-alloc.young@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA1PR11MB6760:EE_|SA0PR11MB4605:EE_ X-MS-Office365-Filtering-Correlation-Id: e16dc2b7-562e-465b-8d9a-08dba79fea40 X-MS-Exchange-SLBlob-MailProps: 70qbaZjg4mvG1DVpcZ16y0G0e8zk20SA5z8eNdbbqXO8KZYrIiWQvvRs7zw+kNL+E0ugxk3BEyEKuBc2IpjhirY424Rdak3qwhljrEsghWX+cXR7xp+teEoITS2b1k+0X7xEp7d63G/lAoxdkGgWphlvAvQ3G8cql4N5Oi30RXs1Jh1Vqin7cQ/5ofCcSkWolaNhzcq0Ufh8ltl1d4V9sqQZNzaDXbFh0ehuiNW5HfI5DVZfgZHSA17uFWKlhV/hkzglp5I7cDW3S1wHrw3so38VQy1yPtWwDvvFNqNwCXEYGc5EoJmup4/lDN3U/dTxNGIm/nQUaZYrXWTXMbLmC10xGjxKbSWARJiD2i+HUDxKOYGOpj1d+D+Hz6ECrm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ii?Q?yjU4ITrD5YfuCKGI2983rVFAN9tBxkXq4a7k/PadjW/G8B+csP0ifhWWPsEm?= =?us-ascii?Q?giue+YxN9JUo6K1762BFr7Q8UMPHiuRM3CylaD37VwIVIxMraQfsfiYB24jP?= =?us-ascii?Q?MgdTUIOvFr9u2AeAVxDVqQk3NP0BUWwYtpXQF2QjqHhNE0N0CpC/NFXtNWkD?= =?us-ascii?Q?q2TZpSBYPo5xKXx6f3b9YJcLNjcvdunr1cCRjCjS+NmpwfMsMplyyAW0qgCB?= =?us-ascii?Q?8cf7DQRkkan6Y5etFionY3tFqZfEkusCB9Y0G0hriYtPc4w0EH94Q3GGMdHB?= =?us-ascii?Q?Ngomt2lFh5qk/uqwtDpOY0o5eS8w4cAGH2uDQTHg2oGpKK3Ui/CatVqQyYdl?= =?us-ascii?Q?+oZfpkZnFVq2nJ6ePcRIsyQLFOpEXEOOjmzfX8mRRDNrillzH/RdzpC00+M?= =?us-ascii?Q?=3D?= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e16dc2b7-562e-465b-8d9a-08dba79fea40 X-MS-Exchange-CrossTenant-AuthSource: SA1PR11MB6760.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Aug 2023 08:22:27.8483 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR11MB4605 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.92.41.81; envelope-from=alloc.young@outlook.com; helo=NAM10-DM6-obe.outbound.protection.outlook.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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @outlook.com) X-ZM-MESSAGEID: 1693211281858100003 Content-Type: text/plain; charset="utf-8" From: alloc kvm_dirty_ring_reaper_init is called much early than vcpu creation, so it's possibe the reaper get a crash before vcpu mmap kvm_dirty_gfns. Add a machine done notifier to ensure dirty reaper get run after vcpu inited. Signed-off-by: alloc --- accel/kvm/kvm-all.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index d07f1ecbd3..5ae7e27a72 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -51,6 +51,7 @@ =20 #include "hw/boards.h" #include "sysemu/stats.h" +#include "sysemu/sysemu.h" =20 /* This check must be after config-host.h is included */ #ifdef CONFIG_EVENTFD @@ -133,6 +134,8 @@ static QLIST_HEAD(, KVMResampleFd) kvm_resample_fd_list= =3D =20 static QemuMutex kml_slots_lock; =20 +static Notifier dirty_ring_reaper_machine_done; + #define kvm_slots_lock() qemu_mutex_lock(&kml_slots_lock) #define kvm_slots_unlock() qemu_mutex_unlock(&kml_slots_lock) =20 @@ -1454,8 +1457,9 @@ static void *kvm_dirty_ring_reaper_thread(void *data) return NULL; } =20 -static void kvm_dirty_ring_reaper_init(KVMState *s) +static void kvm_dirty_ring_reaper_init(Notifier *n, void *unused) { + KVMState *s =3D kvm_state; struct KVMDirtyRingReaper *r =3D &s->reaper; =20 qemu_thread_create(&r->reaper_thr, "kvm-reaper", @@ -2742,7 +2746,8 @@ static int kvm_init(MachineState *ms) } =20 if (s->kvm_dirty_ring_size) { - kvm_dirty_ring_reaper_init(s); + dirty_ring_reaper_machine_done.notify =3D kvm_dirty_ring_reaper_in= it; + qemu_add_machine_init_done_notifier(&dirty_ring_reaper_machine_don= e); } =20 if (kvm_check_extension(kvm_state, KVM_CAP_BINARY_STATS_FD)) { --=20 2.39.3