From nobody Sun Feb 8 14:41:51 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654645170; cv=none; d=zohomail.com; s=zohoarc; b=ROIglWDFiv6tzpL4fItGHJJLpCAeqdRxPr30Z4r+ZVQAfPcw58qjdgziXYnurjrXzHgyV+uKbjfrlD0RfBVjaaiPgB+P0IhIBFlJModoovCnz5OEZ/OXWuftl/8RBHHKOnuTOrBpZHATSM1Rca34EPDq7/Qk82zWqG8rrxS8Uos= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654645170; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=C5SDL/3f9u/neTqnxCPoh9gqsnwEb6tm3hePdNROKyA=; b=RHa3ECElVCsAZzT+qHuIQN+h/eMGnt92rRKGCg5eymDMzeaYL0fUIKbNV/ZOeBF6Z0S7UB4CTrZWQGm7xYXjGfdqx0R9cepU90vvgNZRdFhGxnCP60W/sPTIyVWjduY7ffesNwNynTi/DyHNUHG4pCDtoG9bjnpZ8jysukcBmg4= ARC-Authentication-Results: i=1; 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; 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 1654645170470660.1083380296654; Tue, 7 Jun 2022 16:39:30 -0700 (PDT) Received: from localhost ([::1]:60712 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyinI-0002dE-Az for importer@patchew.org; Tue, 07 Jun 2022 19:39:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHn-0007Tt-UO for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:55 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHk-0005FR-U6 for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:54 -0400 Received: from mail-il1-f200.google.com (mail-il1-f200.google.com [209.85.166.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-26-OEDYHVomNu25aMqEn_3TqQ-1; Tue, 07 Jun 2022 19:06:51 -0400 Received: by mail-il1-f200.google.com with SMTP id g8-20020a92cda8000000b002d15f63967eso14632609ild.21 for ; Tue, 07 Jun 2022 16:06:51 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id f6-20020a056602038600b00665862d12bbsm7035375iov.46.2022.06.07.16.06.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jun 2022 16:06:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654643212; 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=C5SDL/3f9u/neTqnxCPoh9gqsnwEb6tm3hePdNROKyA=; b=Z5fICTPiyvDJGqPawY7nKeOgxgn1bNIR1KKm/goJNoqtpE+SzCfJqBrfS0dTsH5y+njzBB oqpwgD2tLKWgyIdpogjT1Sxbq9+pFmChnxvGLKL/xcQdRAf4JofikVlkwg/SFhf9TRvyKK 2kMYcqS6PljZ09IABchVuohSLXddnUw= X-MC-Unique: OEDYHVomNu25aMqEn_3TqQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C5SDL/3f9u/neTqnxCPoh9gqsnwEb6tm3hePdNROKyA=; b=eeFC+jbhzhaZoXAvXbF0E6RVkTs+Bni6Fl4oBRuYtYNyGccKpVicAi+WluAy8WurJN Q8LhfrKd6+f8qL9mvxoyruCIV14rUJed5wzsVRdwi0h5uOckKZSoOxpt8aoojPKVpgDP sh6fRrrPIUAC1p6aFZ0lL8Kx3mnYS+6Bwu0yFAuri2ZmR8GNZz1zDeYk9b0gC4dAmWsr eE17oke3h3FPUEEeIqdvV0AValSzfYF/1+jngMnOYG4cBKpA7gy6A2UgNtdAiN8OpWol f1dXxRHtbr9Nly7ApzBySChuecrINT5HHnSJD6y9BWZYD1TVQSbXfNW8ubfP2iry1a3c dyOQ== X-Gm-Message-State: AOAM530t3Bpkb+zIZwDFF2AG4Q1G4NvWJAZPrukrXbpZOIS7nvMOveiC 69FtquTna26MVDVtVnXL5kzBsBDGkhb2fc3b2qsC9v8CLl0h/LWLBfxUeNykiWgNpZ1QZ0KKtXH 3Si4FLD5NaMG3MOl673g71eZFuAT0+bq3knaq0E/JZCQ1uc3ZJhKplKBQKY+30Dud X-Received: by 2002:a05:6638:3e1b:b0:331:d0b5:18e9 with SMTP id co27-20020a0566383e1b00b00331d0b518e9mr2996910jab.207.1654643210350; Tue, 07 Jun 2022 16:06:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgWQRzlAa4dG9MPJCKK5HjtIA8xeducuSvtMdAXx7FoSdy9ojAaY+bYB++9BYXLiBD4jrFjw== X-Received: by 2002:a05:6638:3e1b:b0:331:d0b5:18e9 with SMTP id co27-20020a0566383e1b00b00331d0b518e9mr2996898jab.207.1654643210101; Tue, 07 Jun 2022 16:06:50 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson , Igor Mammedov , peterx@redhat.com Subject: [PATCH RFC 1/5] cpus-common: Introduce run_on_cpu_func2 which allows error returns Date: Tue, 7 Jun 2022 19:06:41 -0400 Message-Id: <20220607230645.53950-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607230645.53950-1-peterx@redhat.com> References: <20220607230645.53950-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654645173741100001 Content-Type: text/plain; charset="utf-8" run_on_cpu API does not yet support any way to pass over an error message to above. Add a new run_on_cpu_func2 hook to grant possibility of that. Note that this only changes the cpus-common core, no API is yet introduced for v2 of the run_on_cpu_func function. Signed-off-by: Peter Xu --- cpus-common.c | 28 +++++++++++++++++++++++++--- include/hw/core/cpu.h | 2 ++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cpus-common.c b/cpus-common.c index db459b41ce..1db7bbbb88 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -116,9 +116,20 @@ __thread CPUState *current_cpu; =20 struct qemu_work_item { QSIMPLEQ_ENTRY(qemu_work_item) node; - run_on_cpu_func func; + union { + run_on_cpu_func func; /* When has_errp=3D=3Dfalse */ + run_on_cpu_func2 func2; /* When has_errp=3D=3Dtrue */ + }; run_on_cpu_data data; bool free, exclusive, done; + + /* + * Below are only used by v2 of work item, where we allow to return + * errors for cpu work items. When has_errp=3D=3Dtrue, then: (1) we c= all + * func2 rather than func, and (2) we pass in errp into func2() call. + */ + bool has_errp; + Error **errp; }; =20 static void queue_work_on_cpu(CPUState *cpu, struct qemu_work_item *wi) @@ -314,6 +325,17 @@ void async_safe_run_on_cpu(CPUState *cpu, run_on_cpu_f= unc func, queue_work_on_cpu(cpu, wi); } =20 +static void process_one_work_item(struct qemu_work_item *wi, CPUState *cpu) +{ + if (wi->has_errp) { + /* V2 of work item, allows errors */ + wi->func2(cpu, wi->data, wi->errp); + } else { + /* Old version of work item, no error returned */ + wi->func(cpu, wi->data); + } +} + void process_queued_cpu_work(CPUState *cpu) { struct qemu_work_item *wi; @@ -336,11 +358,11 @@ void process_queued_cpu_work(CPUState *cpu) */ qemu_mutex_unlock_iothread(); start_exclusive(); - wi->func(cpu, wi->data); + process_one_work_item(wi, cpu); end_exclusive(); qemu_mutex_lock_iothread(); } else { - wi->func(cpu, wi->data); + process_one_work_item(wi, cpu); } qemu_mutex_lock(&cpu->work_mutex); if (wi->free) { diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 996f94059f..7a303576d0 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -252,6 +252,8 @@ typedef union { #define RUN_ON_CPU_NULL RUN_ON_CPU_HOST_PTR(NULL) =20 typedef void (*run_on_cpu_func)(CPUState *cpu, run_on_cpu_data data); +/* Same as run_on_cpu_func but allows to return an error */ +typedef void (*run_on_cpu_func2)(CPUState *cpu, run_on_cpu_data data, Erro= r **errp); =20 struct qemu_work_item; =20 --=20 2.32.0 From nobody Sun Feb 8 14:41:51 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654645486; cv=none; d=zohomail.com; s=zohoarc; b=KyG5LfNL0xHPlaSAJZZAB/ypmw2GXGQkbi984YibDATOxgKNGVJgqMdGtlR/UzTEZxWeWcWi/apEBled3/Xk66xKrJpsS/XtbPUtjwKvlWvqvLGtah2AoG3EZ6K97e56omt6K+DhSJA6b/N8McOM8hMLvHq57KOdQgKqtCJJ4dE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654645486; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M/PXw7pEzuqwylRIsTPT0+m7UJmDqzIPfq4d+hlw3f0=; b=N+J4Q5yrFeOKYz/6wCJpYdCM+n+0WOZYcADWZuDHNDBq697ygpupvPAsQBvSfurf8jeboy5g6NcRJemofKzF8RI45/3EVMAbpXEvcNXCsYEZVpKq3k+sXMeoAHvQJ6BDah1vnPIgloKSBoHSvP5E88yipQZZOuJxJmZnpXWedlE= ARC-Authentication-Results: i=1; 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; 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 1654645486165543.7006059821634; Tue, 7 Jun 2022 16:44:46 -0700 (PDT) Received: from localhost ([::1]:39638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyisP-0007f9-5A for importer@patchew.org; Tue, 07 Jun 2022 19:44:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35410) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHo-0007ZF-Hl for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:56 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31713) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHm-0005FX-ML for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:56 -0400 Received: from mail-io1-f69.google.com (mail-io1-f69.google.com [209.85.166.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-594-_5spUCrpPVqjvfbi_JS8PQ-1; Tue, 07 Jun 2022 19:06:53 -0400 Received: by mail-io1-f69.google.com with SMTP id i126-20020a6bb884000000b006691e030971so6364039iof.15 for ; Tue, 07 Jun 2022 16:06:53 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id f6-20020a056602038600b00665862d12bbsm7035375iov.46.2022.06.07.16.06.50 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jun 2022 16:06:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654643214; 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=M/PXw7pEzuqwylRIsTPT0+m7UJmDqzIPfq4d+hlw3f0=; b=VZQPz5D0O49u30/alNdpH/X7hh12Wh7zRWng3UZfVdaDToQLHEyymd2bX3ewkOzUElfjkm Cc4tt+Y8NK47BmP0/nUm2AFrCsc9fC2YR+h2q50K/Dw1qHDcDbGk17ugWs4C+stayXZS8M 3upcP+KQodxm08NuC130vgfhdXiHHMs= X-MC-Unique: _5spUCrpPVqjvfbi_JS8PQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M/PXw7pEzuqwylRIsTPT0+m7UJmDqzIPfq4d+hlw3f0=; b=wXXBuaF6PZU3EBzhEiGdXfrhJyJSwkFLOBbtauOW01AH3BotapwWRoBwm7NhGDEGck qF4iynuSYMjzUzLoAYVYAbmGRotYfeU6lM3kUiJrQisXUNy99JkuEoPJLYsEnZH1ylbF X8viyY4uaJ23W88b24WRex5LCUlzE7Bzuh1sHoPSqEKKz0qDU6+0lwSjDZDfBBTX+mE/ oDaruK8i+G0LaDHQJOwz9quKuYf4c+OcFnmZ/yvl/F7aCfMieWgUUvRK1Pc8rYa30qAo hkeFQuYW4tZbAhHQERddp2pPCte2uMZvN9O8q2RTpRAy/VPGP7aXtqoMOI1nzwtUptCs gY2w== X-Gm-Message-State: AOAM531es3Ip4QbICYqb0LPLtxJxSUnTmzYtpsZrRuq0XYzRlP+z12F9 VdSNTNJzpfxav7xXCrNTifNBUvOavtnaDatPgFUVXY0cWqzRlqHhN102vuoT/2QlMtS1OaRWNRl B5hHE+a1Aeov3A24PB2oTcr21kBtALOHL4fQFq5wiQSZvfCiGWMfOESWjSDZ0UBWW X-Received: by 2002:a05:6638:22c9:b0:32e:d436:be11 with SMTP id j9-20020a05663822c900b0032ed436be11mr18426247jat.156.1654643212130; Tue, 07 Jun 2022 16:06:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcj7Rewtqj/LcT3QJRssRrF2eeqRuF5tEJR/NjQDlZrKx115ZotgCu/7VwER6C0aPyq1AWpQ== X-Received: by 2002:a05:6638:22c9:b0:32e:d436:be11 with SMTP id j9-20020a05663822c900b0032ed436be11mr18426233jat.156.1654643211800; Tue, 07 Jun 2022 16:06:51 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson , Igor Mammedov , peterx@redhat.com Subject: [PATCH RFC 2/5] cpus-common: Add run_on_cpu2() Date: Tue, 7 Jun 2022 19:06:42 -0400 Message-Id: <20220607230645.53950-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607230645.53950-1-peterx@redhat.com> References: <20220607230645.53950-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654645489413100001 Content-Type: text/plain; charset="utf-8" This version of run_on_cpu() allows to take an Error** to detect errors. Signed-off-by: Peter Xu --- cpus-common.c | 27 +++++++++++++++++++++++++++ include/hw/core/cpu.h | 26 ++++++++++++++++++++++++++ softmmu/cpus.c | 6 ++++++ 3 files changed, 59 insertions(+) diff --git a/cpus-common.c b/cpus-common.c index 1db7bbbb88..1d67c0c655 100644 --- a/cpus-common.c +++ b/cpus-common.c @@ -167,6 +167,33 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func= , run_on_cpu_data data, } } =20 +void do_run_on_cpu2(CPUState *cpu, run_on_cpu_func2 func2, run_on_cpu_data= data, + QemuMutex *mutex, Error **errp) +{ + struct qemu_work_item wi; + + if (qemu_cpu_is_self(cpu)) { + func2(cpu, data, errp); + return; + } + + wi.func2 =3D func2; + wi.data =3D data; + wi.done =3D false; + wi.free =3D false; + wi.exclusive =3D false; + wi.has_errp =3D true; + wi.errp =3D errp; + + queue_work_on_cpu(cpu, &wi); + while (!qatomic_mb_read(&wi.done)) { + CPUState *self_cpu =3D current_cpu; + + qemu_cond_wait(&qemu_work_cond, mutex); + current_cpu =3D self_cpu; + } +} + void async_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data= data) { struct qemu_work_item *wi; diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h index 7a303576d0..4bb40a03cf 100644 --- a/include/hw/core/cpu.h +++ b/include/hw/core/cpu.h @@ -709,6 +709,19 @@ bool cpu_is_stopped(CPUState *cpu); void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data da= ta, QemuMutex *mutex); =20 +/** + * do_run_on_cpu2: + * @cpu: The vCPU to run on. + * @func2: The function to be executed. + * @data: Data to pass to the function. + * @mutex: Mutex to release while waiting for @func2 to run. + * @errp: The Error** pointer to be passed into @func2. + * + * Used internally in the implementation of run_on_cpu2. + */ +void do_run_on_cpu2(CPUState *cpu, run_on_cpu_func2 func2, run_on_cpu_data= data, + QemuMutex *mutex, Error **errp); + /** * run_on_cpu: * @cpu: The vCPU to run on. @@ -719,6 +732,19 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func= , run_on_cpu_data data, */ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data); =20 +/** + * run_on_cpu2: + * @cpu: The vCPU to run on. + * @func: The function to be executed. + * @data: Data to pass to the function. + * @errp: The Error** pointer to be passed into @func2. + * + * Schedules the function @func2 for execution on the vCPU @cpu, capture + * any error and put it into *@errp when provided. + */ +void run_on_cpu2(CPUState *cpu, run_on_cpu_func2 func2, run_on_cpu_data da= ta, + Error **errp); + /** * async_run_on_cpu: * @cpu: The vCPU to run on. diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 23b30484b2..898363a1d0 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -391,6 +391,12 @@ void run_on_cpu(CPUState *cpu, run_on_cpu_func func, r= un_on_cpu_data data) do_run_on_cpu(cpu, func, data, &qemu_global_mutex); } =20 +void run_on_cpu2(CPUState *cpu, run_on_cpu_func2 func2, run_on_cpu_data da= ta, + Error **errp) +{ + do_run_on_cpu2(cpu, func2, data, &qemu_global_mutex, errp); +} + static void qemu_cpu_stop(CPUState *cpu, bool exit) { g_assert(qemu_cpu_is_self(cpu)); --=20 2.32.0 From nobody Sun Feb 8 14:41:51 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654644293; cv=none; d=zohomail.com; s=zohoarc; b=O0Si7QKuPberFQwS74oHf2OS2+trxp+6w+nKeBFENCTXKBtQx49Rdg46Hk4/J6Seayx639nWqmhJFrf2RjyhLH17JN0MLihkjQuTht4hMYymm+ctHSA0ueZ2qmrblNAO0ehGGFj3CQOuUkQVyHQEEAGzz72Gc44eL73Bkd9c81c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654644293; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jhsaJl6DZcSKy+hQsn73Ph11xFbQ58wRWae9eT8xHuk=; b=S9m9SGgJtabJoirss09tblYPrCCoKZ/T4PP9CHdJtSyzFiMuTQ7J2WO9mJHbj7Z1C68Zrr53zvqmoiDaZBvFmraZiE3H/huJQM/BPv6ZmgYSw6DIeVsX2KSefhEB722JsSUsXL2MhOejNONxRuR6AmP/9GIbJ+Z87sACz+KPGAA= ARC-Authentication-Results: i=1; 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; 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 1654644293051987.6842089047584; Tue, 7 Jun 2022 16:24:53 -0700 (PDT) Received: from localhost ([::1]:34342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyiZ8-00014J-U8 for importer@patchew.org; Tue, 07 Jun 2022 19:24:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHq-0007gX-AE for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:58 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:50296) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHo-0005Fo-Id for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:58 -0400 Received: from mail-io1-f70.google.com (mail-io1-f70.google.com [209.85.166.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-417-U4CTROG8NeWIcgu6euCjJQ-1; Tue, 07 Jun 2022 19:06:54 -0400 Received: by mail-io1-f70.google.com with SMTP id q5-20020a6b2a05000000b006696f97731aso2689892ioq.8 for ; Tue, 07 Jun 2022 16:06:54 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id f6-20020a056602038600b00665862d12bbsm7035375iov.46.2022.06.07.16.06.51 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jun 2022 16:06:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654643215; 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=jhsaJl6DZcSKy+hQsn73Ph11xFbQ58wRWae9eT8xHuk=; b=LHSrciRD3GUtjRSIMoiGSeCM0h39+VfcJOJMwAgR59dAuuUY2/YrJ6STFCD/adi6gDObdC i8LeANOp58HxLSICNnghGeAexWEnCQGWyjxYDo5US2qnEiBzv1B49Bpvx/f5NznjBJ/7I8 y0EimgxsLznxbaTcnbSEhNof1FPg1/E= X-MC-Unique: U4CTROG8NeWIcgu6euCjJQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jhsaJl6DZcSKy+hQsn73Ph11xFbQ58wRWae9eT8xHuk=; b=SFdA+IpJwf6e4PmMwduQMq46l8yCZf2UxNrn7aL1qfs5RWsS1J4clMU9jjUHCa4lPK XCN4wgrpSDdjnzGL6RPSsMZ0baqB4ClVF3/g5mwtRGhq4Ao+tkPNW0/J7TxDo5SFbeub hP5eHODWc2jjI14LkS0i/k5kkK9iC136A5yiuf3pXnvNp3hCUn0+iQRK83sXkEFCk6jB wab5acN/bKjUlB8Y+h5fs+k9aXUgAlgsaa7crefgF6ehl+UF0GYH2CqLgSVeR2lY2lSe zc+cfiXZjSFxD/GvLBSmOS1qFCba7fmNFBeVlDFRoLVHubmvjwxwf/bfMwTRia54p0SI ut9w== X-Gm-Message-State: AOAM5318SebCrOYwAZuCeY9pMf4dRY4Y8Sbj2690Dg/O/zQR+fQ6vpY/ /H9Ad0frDL7RYAbvUXDXJ+oaUzoElx47K8ivufpqaNtFntOiD6c+rKc3wHk9Yg5rXw/wvwMA2QN VlDCkumzCMdEorVlN3Khs+e06S0LS14EVekRrn42x4+LaapXjgjh+wIUL0qJrnIpT X-Received: by 2002:a92:ca91:0:b0:2d3:b54f:d83b with SMTP id t17-20020a92ca91000000b002d3b54fd83bmr17647178ilo.89.1654643213684; Tue, 07 Jun 2022 16:06:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDPPznbuFxlq2cq2OIUiAsc0Pj83Pti5cBy/kG4Q1DPxMDfOJ03BD3q3NBN9AozI+m2iAMAw== X-Received: by 2002:a92:ca91:0:b0:2d3:b54f:d83b with SMTP id t17-20020a92ca91000000b002d3b54fd83bmr17647164ilo.89.1654643213399; Tue, 07 Jun 2022 16:06:53 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson , Igor Mammedov , peterx@redhat.com Subject: [PATCH RFC 3/5] accel: Allow synchronize_post_init() to take an Error** Date: Tue, 7 Jun 2022 19:06:43 -0400 Message-Id: <20220607230645.53950-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607230645.53950-1-peterx@redhat.com> References: <20220607230645.53950-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654644295795100003 Content-Type: text/plain; charset="utf-8" It allows accel->synchronize_post_init() hook to return an error upwards. Add a new cpu_synchronize_post_init_full() for it, then let the existing cpu_synchronize_post_init() to call it with errp=3D=3DNULL. Signed-off-by: Peter Xu --- accel/hvf/hvf-accel-ops.c | 2 +- accel/kvm/kvm-all.c | 2 +- include/sysemu/accel-ops.h | 2 +- include/sysemu/hw_accel.h | 1 + softmmu/cpus.c | 10 ++++++++-- stubs/cpu-synchronize-state.c | 3 +++ target/i386/hax/hax-all.c | 2 +- target/i386/nvmm/nvmm-all.c | 2 +- target/i386/whpx/whpx-all.c | 2 +- 9 files changed, 18 insertions(+), 8 deletions(-) diff --git a/accel/hvf/hvf-accel-ops.c b/accel/hvf/hvf-accel-ops.c index a70e2eb375..b439e0c104 100644 --- a/accel/hvf/hvf-accel-ops.c +++ b/accel/hvf/hvf-accel-ops.c @@ -228,7 +228,7 @@ static void hvf_cpu_synchronize_post_reset(CPUState *cp= u) run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL); } =20 -static void hvf_cpu_synchronize_post_init(CPUState *cpu) +static void hvf_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL); } diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 32e177bd26..1caed1a295 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2767,7 +2767,7 @@ static void do_kvm_cpu_synchronize_post_init(CPUState= *cpu, run_on_cpu_data arg) cpu->vcpu_dirty =3D false; } =20 -void kvm_cpu_synchronize_post_init(CPUState *cpu) +void kvm_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { run_on_cpu(cpu, do_kvm_cpu_synchronize_post_init, RUN_ON_CPU_NULL); } diff --git a/include/sysemu/accel-ops.h b/include/sysemu/accel-ops.h index a0572ea87a..7e526d3c65 100644 --- a/include/sysemu/accel-ops.h +++ b/include/sysemu/accel-ops.h @@ -35,7 +35,7 @@ struct AccelOpsClass { bool (*cpu_thread_is_idle)(CPUState *cpu); =20 void (*synchronize_post_reset)(CPUState *cpu); - void (*synchronize_post_init)(CPUState *cpu); + void (*synchronize_post_init)(CPUState *cpu, Error **errp); void (*synchronize_state)(CPUState *cpu); void (*synchronize_pre_loadvm)(CPUState *cpu); void (*synchronize_pre_resume)(bool step_pending); diff --git a/include/sysemu/hw_accel.h b/include/sysemu/hw_accel.h index 22903a55f7..3ee3508411 100644 --- a/include/sysemu/hw_accel.h +++ b/include/sysemu/hw_accel.h @@ -21,6 +21,7 @@ void cpu_synchronize_state(CPUState *cpu); void cpu_synchronize_post_reset(CPUState *cpu); void cpu_synchronize_post_init(CPUState *cpu); +void cpu_synchronize_post_init_full(CPUState *cpu, Error **errp); void cpu_synchronize_pre_loadvm(CPUState *cpu); =20 #endif /* QEMU_HW_ACCEL_H */ diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 898363a1d0..464c06201c 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -178,13 +178,19 @@ void cpu_synchronize_post_reset(CPUState *cpu) } } =20 -void cpu_synchronize_post_init(CPUState *cpu) +void cpu_synchronize_post_init_full(CPUState *cpu, Error **errp) { if (cpus_accel->synchronize_post_init) { - cpus_accel->synchronize_post_init(cpu); + cpus_accel->synchronize_post_init(cpu, errp); } } =20 +void cpu_synchronize_post_init(CPUState *cpu) +{ + /* errp=3DNULL means we won't capture any error */ + cpu_synchronize_post_init_full(cpu, NULL); +} + void cpu_synchronize_pre_loadvm(CPUState *cpu) { if (cpus_accel->synchronize_pre_loadvm) { diff --git a/stubs/cpu-synchronize-state.c b/stubs/cpu-synchronize-state.c index d9211da66c..6d2c9f509a 100644 --- a/stubs/cpu-synchronize-state.c +++ b/stubs/cpu-synchronize-state.c @@ -7,3 +7,6 @@ void cpu_synchronize_state(CPUState *cpu) void cpu_synchronize_post_init(CPUState *cpu) { } +void cpu_synchronize_post_init_full(CPUState *cpu, Error **errp) +{ +} diff --git a/target/i386/hax/hax-all.c b/target/i386/hax/hax-all.c index b185ee8de4..782d83b531 100644 --- a/target/i386/hax/hax-all.c +++ b/target/i386/hax/hax-all.c @@ -651,7 +651,7 @@ static void do_hax_cpu_synchronize_post_init(CPUState *= cpu, run_on_cpu_data arg) cpu->vcpu_dirty =3D false; } =20 -void hax_cpu_synchronize_post_init(CPUState *cpu) +void hax_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { run_on_cpu(cpu, do_hax_cpu_synchronize_post_init, RUN_ON_CPU_NULL); } diff --git a/target/i386/nvmm/nvmm-all.c b/target/i386/nvmm/nvmm-all.c index b75738ee9c..f429e940af 100644 --- a/target/i386/nvmm/nvmm-all.c +++ b/target/i386/nvmm/nvmm-all.c @@ -869,7 +869,7 @@ void nvmm_cpu_synchronize_post_reset(CPUState *cpu) run_on_cpu(cpu, do_nvmm_cpu_synchronize_post_reset, RUN_ON_CPU_NULL); } =20 -void nvmm_cpu_synchronize_post_init(CPUState *cpu) +void nvmm_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { run_on_cpu(cpu, do_nvmm_cpu_synchronize_post_init, RUN_ON_CPU_NULL); } diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index b22a3314b4..09bf5681ce 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -2123,7 +2123,7 @@ void whpx_cpu_synchronize_post_reset(CPUState *cpu) run_on_cpu(cpu, do_whpx_cpu_synchronize_post_reset, RUN_ON_CPU_NULL); } =20 -void whpx_cpu_synchronize_post_init(CPUState *cpu) +void whpx_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { run_on_cpu(cpu, do_whpx_cpu_synchronize_post_init, RUN_ON_CPU_NULL); } --=20 2.32.0 From nobody Sun Feb 8 14:41:51 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654644766; cv=none; d=zohomail.com; s=zohoarc; b=EhBj8m0wDz/0QNJQysPWLVT8YNcBH8a8byMu9ovJ93NGYKIjBkpwBi8dJplRdVgCHBELslLJZQwgtC8NY4xYcSWuot+Xz+1x1ZLb8BuhM0ALInYT5ueH09EjW+NlvxnE3aGlgtNYhD30cMBC3gcyUgOXTS3OZNO1BWgTHHYstHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654644766; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hVuTnZmfWtxZ4QXxya2rZaIVRCmdCqRL6AV8ufV87M0=; b=cS1hs5vo4PVLPYuXzPzsI4HQ1D/y5+Rl2jk+rTTKfBogM7/H0JRKxJzZQlla31VdT0JCI4GtAZQcvJvd64IjXGXe3qxMl5j9LqJhUGGNupw+4KPUujPHGBAa76IZDeedsapdipXO2ekYpsBsVnyHijRwJEnIhkpF4ONrLUDjjYE= ARC-Authentication-Results: i=1; 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; 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 1654644765996443.59753479188157; Tue, 7 Jun 2022 16:32:45 -0700 (PDT) Received: from localhost ([::1]:51160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyigm-0004Qd-LN for importer@patchew.org; Tue, 07 Jun 2022 19:32:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHr-0007mD-O7 for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:59 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54951) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHq-0005GC-39 for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:06:59 -0400 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-318-aZWRwcXrN3qzYCIzyK6DWg-1; Tue, 07 Jun 2022 19:06:56 -0400 Received: by mail-io1-f72.google.com with SMTP id w16-20020a5d8450000000b00669877b9ce2so1077008ior.20 for ; Tue, 07 Jun 2022 16:06:56 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id f6-20020a056602038600b00665862d12bbsm7035375iov.46.2022.06.07.16.06.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jun 2022 16:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654643217; 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=hVuTnZmfWtxZ4QXxya2rZaIVRCmdCqRL6AV8ufV87M0=; b=OlXcntBcd0DLHYIbEwqs3gkXq0f4JR+ZQfDyg4clX/fzyekBTlQGKAV/j66F5csFuO+zK/ mVPWJqkelCwCt79ICMg+gnf8xbhyGudG/fGDR0PM7v2/8AfomLq3DuppRF/oHJ5ReD8b95 qWJzDlNjJRh5VgCriVYdWlh5CJoX4pY= X-MC-Unique: aZWRwcXrN3qzYCIzyK6DWg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hVuTnZmfWtxZ4QXxya2rZaIVRCmdCqRL6AV8ufV87M0=; b=stVug6r6lX/eEmoXwgGsw5wmV7KL19eqQNM8xq1YhQi/3dyRyIWN7iTk8YTdo+7vL+ YWnDC/U/BDdycZvWwD2lu+ojEvWn8CDzWTlxMFku73WeaqzMyLmJ0M4dj8LDBNJxIC6W 3LxQluoTQeG42k08xcvMs/bznJCWqaKNevWKQAGzrtXJ7IQIX9oKDbxUGMXblBmTdBXw S/JavpwIhsZ1YcfeQCPDbjTQ2qUdSGJXWb9JHE8eqUsER00zD/QyEete+gKBWZhLcGvl KK64GzsMRYnhGO1r0VNzIYlkkLdKH0jiw2jKlW0vR2jXo37loNFFJ1a2B7WeuYE++VB5 qx1w== X-Gm-Message-State: AOAM533Esg6IDBrovumdWU7FrZ/agzp+IM4eRgMg4Krv+71+Nfc/w07Q HZ7y3Fkc/tbgrZLis+ZavvyXj+WjzlGE+XizJXr5TKBE7tHLVK1CWn9GvbSlfPfaRebB5nhY5GY v3ACL+LncU0gVpGMzekoo5uNjFLYY5c+5JUw1m+4bd7eJ75ZpKjCI/y4+NMLTsBAP X-Received: by 2002:a05:6e02:1b0c:b0:2d3:bfdf:e3c5 with SMTP id i12-20020a056e021b0c00b002d3bfdfe3c5mr18242846ilv.138.1654643215633; Tue, 07 Jun 2022 16:06:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzReFK3G/dsvopsshu544F2UsRS33cSv536GmHPdfgfoMZhppkKoZ0NlkPik9D6MRTZpBQ60A== X-Received: by 2002:a05:6e02:1b0c:b0:2d3:bfdf:e3c5 with SMTP id i12-20020a056e021b0c00b002d3bfdfe3c5mr18242826ilv.138.1654643215337; Tue, 07 Jun 2022 16:06:55 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson , Igor Mammedov , peterx@redhat.com Subject: [PATCH RFC 4/5] cpu: Allow cpu_synchronize_all_post_init() to take an errp Date: Tue, 7 Jun 2022 19:06:44 -0400 Message-Id: <20220607230645.53950-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607230645.53950-1-peterx@redhat.com> References: <20220607230645.53950-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.133.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654644769795100001 Content-Type: text/plain; charset="utf-8" Allow cpu_synchronize_all_post_init() to fail with an errp when it's set. Modify both precopy and postcopy to try to detect such error. Signed-off-by: Peter Xu --- hw/core/machine.c | 2 +- include/sysemu/cpus.h | 2 +- migration/savevm.c | 20 +++++++++++++++++--- softmmu/cpus.c | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/hw/core/machine.c b/hw/core/machine.c index c53548d0b1..b5daad82f8 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1447,7 +1447,7 @@ void qemu_remove_machine_init_done_notifier(Notifier = *notify) =20 void qdev_machine_creation_done(void) { - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(NULL); =20 if (current_machine->boot_config.has_once) { qemu_boot_set(current_machine->boot_config.once, &error_fatal); diff --git a/include/sysemu/cpus.h b/include/sysemu/cpus.h index b5c87d48b3..a51ee46441 100644 --- a/include/sysemu/cpus.h +++ b/include/sysemu/cpus.h @@ -45,7 +45,7 @@ bool cpus_are_resettable(void); =20 void cpu_synchronize_all_states(void); void cpu_synchronize_all_post_reset(void); -void cpu_synchronize_all_post_init(void); +void cpu_synchronize_all_post_init(Error **errp); void cpu_synchronize_all_pre_loadvm(void); =20 #ifndef CONFIG_USER_ONLY diff --git a/migration/savevm.c b/migration/savevm.c index d9076897b8..1175ddefd4 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -2005,7 +2005,17 @@ static void loadvm_postcopy_handle_run_bh(void *opaq= ue) /* TODO we should move all of this lot into postcopy_ram.c or a shared= code * in migration.c */ - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(&local_err); + if (local_err) { + /* + * TODO: a better way to do this is to tell the src that we cannot + * run the VM here so hopefully we can keep the VM running on src + * and immediately halt the switch-over. But that needs work. + */ + error_report_err(local_err); + local_err =3D NULL; + autostart =3D false; + } =20 trace_loadvm_postcopy_handle_run_bh("after cpu sync"); =20 @@ -2772,7 +2782,11 @@ int qemu_loadvm_state(QEMUFile *f) } =20 qemu_loadvm_state_cleanup(); - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(&local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } =20 return ret; } @@ -2789,7 +2803,7 @@ int qemu_load_device_state(QEMUFile *f) return ret; } =20 - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(NULL); return 0; } =20 diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 464c06201c..59c70fd496 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -146,7 +146,7 @@ void cpu_synchronize_all_post_reset(void) } } =20 -void cpu_synchronize_all_post_init(void) +void cpu_synchronize_all_post_init(Error **errp) { CPUState *cpu; =20 --=20 2.32.0 From nobody Sun Feb 8 14:41:51 2026 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; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1654645606; cv=none; d=zohomail.com; s=zohoarc; b=H1PG5BaKpD6q26eda5K4vaEj5adGeQE3xRxM4XuwqdJGxNGoH1d6LoWVaPrLwlMpYuNJxWpxsITFb7kFzlmq4naDyvN0vrjxtdd2ROo9GWUnHcjpmdP2rcSPNze2QbGUXJSiE/kmKSS+pQCEgRiBWpOTRVX5LQB4iQyb27+BVEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1654645606; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cTuHYQvixT43pjNuKBwV9c99vHGFjiIKeNvL7DBRfeQ=; b=oEYofKxje4cTIPbQHae2Ez6Pii3T6lI2eWXqwAZVEBpFuDHnglwau9JEtpI9eBq7ASKE8JNDmBLbgjrVe5ykT3PEMwNq3mqAArso40IYLE4RgSI7Mx4vDRHsey3pK3wRbPuuzGlgdZXQ1pi7UZF+sJN7bp4wtdAQflLMNHKqUB8= ARC-Authentication-Results: i=1; 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; 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 1654645606770586.8684760586756; Tue, 7 Jun 2022 16:46:46 -0700 (PDT) Received: from localhost ([::1]:42180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyiuL-00019l-N6 for importer@patchew.org; Tue, 07 Jun 2022 19:46:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHt-0007s0-1v for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:07:01 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyiHr-0005GU-HD for qemu-devel@nongnu.org; Tue, 07 Jun 2022 19:07:00 -0400 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-351-gWIDJOcfOMu7A9DbSvSrJw-1; Tue, 07 Jun 2022 19:06:58 -0400 Received: by mail-il1-f199.google.com with SMTP id 3-20020a056e0220c300b002d3d7ebdfdeso14292829ilq.16 for ; Tue, 07 Jun 2022 16:06:57 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id f6-20020a056602038600b00665862d12bbsm7035375iov.46.2022.06.07.16.06.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 07 Jun 2022 16:06:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654643218; 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=cTuHYQvixT43pjNuKBwV9c99vHGFjiIKeNvL7DBRfeQ=; b=KibfOBbKZU4FOHEoD5l4ycmVetFrkO4IWs4Ie4+9S486VlB6fohrpsxFCNI20fcthTlTir SuNpfMbKbQ5Jzxl6boISsP73m7NpDdvjGmNnQCZbFuOYJbddX3wyASixx+035lFY3RWtDo 9uVrmBHa6u9hufDRuQe8SE/ArdbqP84= X-MC-Unique: gWIDJOcfOMu7A9DbSvSrJw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cTuHYQvixT43pjNuKBwV9c99vHGFjiIKeNvL7DBRfeQ=; b=iLFlxsv4J9HkJmnouo9HAK+BmDnWbLkfmWgj85g1ay9IKDZ1ZFkwMFcv7BWw6AwyRy AqKjqKnPHoGFXQDavvRo7zSXphyov7mmp2PbstZH+NmQyOOq3ehA+/wDly9ZazbINkZI X/U5SKMAq3wstitCSpdhLB1sGGIXtLUV6DsGLtNMk9b6mOz/j80d7CdGl0YJaRO6/Lma I7w/K4EJCnniLeTz4K8iaIiNw1D3wNV6+9ujZVGyektzshalPi1wPznEO3GQ1hMM+CRr yiby2wQDgB59oFu2+E9zhbNQRZGUBf7PtZ60JRP7uIY50qMW+JXIRgfLb8ReXLncCRvO I5uA== X-Gm-Message-State: AOAM531niGZfcU9Y4aebOuEChUBl4gDVznMrOpjiZEn/ZW4VUF/ApUmt jdnWt3LA/vydJHZZY2+Z7FUf9X7/Rp4iBGzcx9KfVonAUMLnBwE7x1lwaYxWqX/4/f7l51Inb5V tRcaWXHaxwullvA9uaUtrHstZTrRN+Udm74sGfmErE65G0j9zgW+58nCMngcye/X5 X-Received: by 2002:a05:6e02:20e7:b0:2d3:ca08:64b0 with SMTP id q7-20020a056e0220e700b002d3ca0864b0mr18608204ilv.195.1654643217029; Tue, 07 Jun 2022 16:06:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzk6i621ieFSncDDt2m1ayH8NSPDIM3ZhFMbN893fDIcHztb3/XS58QxCnjawNRJeWi+nj9Yw== X-Received: by 2002:a05:6e02:20e7:b0:2d3:ca08:64b0 with SMTP id q7-20020a056e0220e700b002d3ca0864b0mr18608182ilv.195.1654643216776; Tue, 07 Jun 2022 16:06:56 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , Leonardo Bras Soares Passos , "Dr . David Alan Gilbert" , Paolo Bonzini , Richard Henderson , Igor Mammedov , peterx@redhat.com Subject: [PATCH RFC 5/5] KVM: Hook kvm_arch_put_registers() errors to the caller Date: Tue, 7 Jun 2022 19:06:45 -0400 Message-Id: <20220607230645.53950-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220607230645.53950-1-peterx@redhat.com> References: <20220607230645.53950-1-peterx@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=170.10.129.124; envelope-from=peterx@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, 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, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1654645609752100001 Content-Type: text/plain; charset="utf-8" Leverage the new mechanism to pass over errors to upper stack for kvm_arch_put_registers() when called for the post_init() accel hook. Signed-off-by: Peter Xu --- accel/kvm/kvm-all.c | 13 ++++++++++--- accel/kvm/kvm-cpus.h | 2 +- softmmu/cpus.c | 5 ++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 1caed1a295..71be723d24 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2761,15 +2761,22 @@ void kvm_cpu_synchronize_post_reset(CPUState *cpu) run_on_cpu(cpu, do_kvm_cpu_synchronize_post_reset, RUN_ON_CPU_NULL); } =20 -static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_dat= a arg) +static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_dat= a arg, + Error **errp) { - kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); + int ret =3D kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); + + if (ret) { + error_setg(errp, "kvm_arch_put_registers() failed with retval=3D%d= ", ret); + return; + } + cpu->vcpu_dirty =3D false; } =20 void kvm_cpu_synchronize_post_init(CPUState *cpu, Error **errp) { - run_on_cpu(cpu, do_kvm_cpu_synchronize_post_init, RUN_ON_CPU_NULL); + run_on_cpu2(cpu, do_kvm_cpu_synchronize_post_init, RUN_ON_CPU_NULL, er= rp); } =20 static void do_kvm_cpu_synchronize_pre_loadvm(CPUState *cpu, run_on_cpu_da= ta arg) diff --git a/accel/kvm/kvm-cpus.h b/accel/kvm/kvm-cpus.h index bf0bd1bee4..c9b8262704 100644 --- a/accel/kvm/kvm-cpus.h +++ b/accel/kvm/kvm-cpus.h @@ -16,7 +16,7 @@ int kvm_init_vcpu(CPUState *cpu, Error **errp); int kvm_cpu_exec(CPUState *cpu); void kvm_destroy_vcpu(CPUState *cpu); void kvm_cpu_synchronize_post_reset(CPUState *cpu); -void kvm_cpu_synchronize_post_init(CPUState *cpu); +void kvm_cpu_synchronize_post_init(CPUState *cpu, Error **errp); void kvm_cpu_synchronize_pre_loadvm(CPUState *cpu); =20 #endif /* KVM_CPUS_H */ diff --git a/softmmu/cpus.c b/softmmu/cpus.c index 59c70fd496..6c0b5b87f0 100644 --- a/softmmu/cpus.c +++ b/softmmu/cpus.c @@ -151,7 +151,10 @@ void cpu_synchronize_all_post_init(Error **errp) CPUState *cpu; =20 CPU_FOREACH(cpu) { - cpu_synchronize_post_init(cpu); + cpu_synchronize_post_init_full(cpu, errp); + if (errp && *errp) { + break; + } } } =20 --=20 2.32.0