From patchwork Tue Jun 7 23:06:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1640265 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=Z5fICTPi; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHmvH1K7Lz9sFr for ; Wed, 8 Jun 2022 09:35:55 +1000 (AEST) Received: from localhost ([::1]:57378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyijo-0000Dv-Gd for incoming@patchwork.ozlabs.org; Tue, 07 Jun 2022 19:35:52 -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 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= 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 X-MC-Unique: OEDYHVomNu25aMqEn_3TqQ-1 Received: by mail-il1-f200.google.com with SMTP id g8-20020a92cda8000000b002d15f63967eso14632609ild.21 for ; Tue, 07 Jun 2022 16:06:51 -0700 (PDT) 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) 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) 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-type: text/plain 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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; struct qemu_work_item { QSIMPLEQ_ENTRY(qemu_work_item) node; - run_on_cpu_func func; + union { + run_on_cpu_func func; /* When has_errp==false */ + run_on_cpu_func2 func2; /* When has_errp==true */ + }; 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==true, then: (1) we call + * func2 rather than func, and (2) we pass in errp into func2() call. + */ + bool has_errp; + Error **errp; }; 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_func func, queue_work_on_cpu(cpu, wi); } +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) 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, Error **errp); struct qemu_work_item; From patchwork Tue Jun 7 23:06:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1640268 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=VZQPz5D0; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHn4k1Qx4z9sFr for ; Wed, 8 Jun 2022 09:44:06 +1000 (AEST) Received: from localhost ([::1]:36438 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyirj-0005Q2-S6 for incoming@patchwork.ozlabs.org; Tue, 07 Jun 2022 19:44:04 -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 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= 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 X-MC-Unique: _5spUCrpPVqjvfbi_JS8PQ-1 Received: by mail-io1-f69.google.com with SMTP id i126-20020a6bb884000000b006691e030971so6364039iof.15 for ; Tue, 07 Jun 2022 16:06:53 -0700 (PDT) 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) 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) 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-type: text/plain 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, } } +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 = func2; + wi.data = data; + wi.done = false; + wi.free = false; + wi.exclusive = false; + wi.has_errp = true; + wi.errp = errp; + + queue_work_on_cpu(cpu, &wi); + while (!qatomic_mb_read(&wi.done)) { + CPUState *self_cpu = current_cpu; + + qemu_cond_wait(&qemu_work_cond, mutex); + current_cpu = 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 data, QemuMutex *mutex); +/** + * 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); +/** + * 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 data, + 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, run_on_cpu_data data) do_run_on_cpu(cpu, func, data, &qemu_global_mutex); } +void run_on_cpu2(CPUState *cpu, run_on_cpu_func2 func2, run_on_cpu_data data, + 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)); From patchwork Tue Jun 7 23:06:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1640258 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=LHSrciRD; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHmcP1PXcz9sFr for ; Wed, 8 Jun 2022 09:23:01 +1000 (AEST) Received: from localhost ([::1]:58358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyiXL-0006ao-7k for incoming@patchwork.ozlabs.org; Tue, 07 Jun 2022 19:22:59 -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 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= 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 X-MC-Unique: U4CTROG8NeWIcgu6euCjJQ-1 Received: by mail-io1-f70.google.com with SMTP id q5-20020a6b2a05000000b006696f97731aso2689892ioq.8 for ; Tue, 07 Jun 2022 16:06:54 -0700 (PDT) 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) 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) 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-type: text/plain 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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==NULL. 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 *cpu) run_on_cpu(cpu, do_hvf_cpu_synchronize_set_dirty, RUN_ON_CPU_NULL); } -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 = false; } -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); 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); #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) } } -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); } } +void cpu_synchronize_post_init(CPUState *cpu) +{ + /* errp=NULL 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 = false; } -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); } -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); } -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); } From patchwork Tue Jun 7 23:06:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1640264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=OlXcntBc; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHmpM73v5z9sG0 for ; Wed, 8 Jun 2022 09:31:39 +1000 (AEST) Received: from localhost ([::1]:47260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyifh-0001ZI-Fq for incoming@patchwork.ozlabs.org; Tue, 07 Jun 2022 19:31:37 -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 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= 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 X-MC-Unique: aZWRwcXrN3qzYCIzyK6DWg-1 Received: by mail-io1-f72.google.com with SMTP id w16-20020a5d8450000000b00669877b9ce2so1077008ior.20 for ; Tue, 07 Jun 2022 16:06:56 -0700 (PDT) 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) 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) 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-type: text/plain 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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) void qdev_machine_creation_done(void) { - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(NULL); 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); 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); #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 *opaque) /* 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 = NULL; + autostart = false; + } trace_loadvm_postcopy_handle_run_bh("after cpu sync"); @@ -2772,7 +2782,11 @@ int qemu_loadvm_state(QEMUFile *f) } 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; + } return ret; } @@ -2789,7 +2803,7 @@ int qemu_load_device_state(QEMUFile *f) return ret; } - cpu_synchronize_all_post_init(); + cpu_synchronize_all_post_init(NULL); return 0; } 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) } } -void cpu_synchronize_all_post_init(void) +void cpu_synchronize_all_post_init(Error **errp) { CPUState *cpu; From patchwork Tue Jun 7 23:06:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 1640269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=KibfOBbK; dkim-atps=neutral Authentication-Results: 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=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LHn6Q0WNBz9sFr for ; Wed, 8 Jun 2022 09:45:32 +1000 (AEST) Received: from localhost ([::1]:40040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyit7-0007vN-GC for incoming@patchwork.ozlabs.org; Tue, 07 Jun 2022 19:45:29 -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 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= 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 X-MC-Unique: gWIDJOcfOMu7A9DbSvSrJw-1 Received: by mail-il1-f199.google.com with SMTP id 3-20020a056e0220c300b002d3d7ebdfdeso14292829ilq.16 for ; Tue, 07 Jun 2022 16:06:57 -0700 (PDT) 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) 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) 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-type: text/plain 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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); } -static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg) +static void do_kvm_cpu_synchronize_post_init(CPUState *cpu, run_on_cpu_data arg, + Error **errp) { - kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); + int ret = kvm_arch_put_registers(cpu, KVM_PUT_FULL_STATE); + + if (ret) { + error_setg(errp, "kvm_arch_put_registers() failed with retval=%d", ret); + return; + } + cpu->vcpu_dirty = false; } 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, errp); } static void do_kvm_cpu_synchronize_pre_loadvm(CPUState *cpu, run_on_cpu_data 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); #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; CPU_FOREACH(cpu) { - cpu_synchronize_post_init(cpu); + cpu_synchronize_post_init_full(cpu, errp); + if (errp && *errp) { + break; + } } }