From patchwork Fri Jun 17 14:48:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885764 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 87E0FC433EF for ; Fri, 17 Jun 2022 14:51:58 +0000 (UTC) Received: from localhost ([::1]:38904 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2DKH-0006Fm-6R for qemu-devel@archiver.kernel.org; Fri, 17 Jun 2022 10:51:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHY-0003cQ-0y for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:31137) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHU-0008CI-Tv for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477344; 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=YstJnHlE5tAltaCPDxkftMOEMs0+0jA5OYZiWGJbD2v8fJe50KyAugakgS9L2IhcFSEhig nrAfdqZOwKs6VCQzN+1VJGLKMupr9X/OVS/3IkX83h5jD2K5g7DqaYgKk0bdqEl4+MTUng rhvmdvIGtlNyRdxlcSTLwB5oZ3j3ACo= 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-660-9x-90ReYN5eJoOMC_z9rtw-1; Fri, 17 Jun 2022 10:49:03 -0400 X-MC-Unique: 9x-90ReYN5eJoOMC_z9rtw-1 Received: by mail-il1-f200.google.com with SMTP id w7-20020a056e021c8700b002d3bc8e95cbso2802594ill.3 for ; Fri, 17 Jun 2022 07:49:03 -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=mdfcRfBVEaRy4SaKDvuwxwKYMt7L1Zhk+8fZ+3N8iFMs4hLnyjwWzf7s1qAsCXapBQ Jynw1qAqJCPjXJRS+TLQkW5PLDGa8SaXxT8nDS0vRF+dfSgMayMyRKKKrDdpgfnbpnKx ouxRk7zRgO6mCymHcg+P7MzwzkV3Bqwpx7Oadat1RyNAdmwT2tRdriUARsGg0SdTpdeC YRjBo3yVoYLzfk7w0WEBoGIiKn9N0aaDAjOtMWffUXmUKr/7A+e7RpuErMvZnel/peQR cgICxV2OXOCAJTaFBY1ME1+URpl+ZyexT+XYxgWvJJzyXDeVGUSQQn5BjLlhzxuWdbtx Obew== X-Gm-Message-State: AJIora/6epxpC5ysPfTGNkZ9PWLOQMzWo7hNZV8q0BzyhMYGyjRmxQoy N3pFTY4rMZQ6AO3yO8YEU6JylSK6Z1VEvBF+QYGAC4cIG2VM7gVSUK2udRgppxH/RXan1yK/+PY KrRSkHkS/a5iaQ7pKlFn3Y03p2fpD6kIdgf6+be3xnxBV+Bqputn7vPvukXdGMbco X-Received: by 2002:a05:6e02:198c:b0:2d8:e8bd:d8ff with SMTP id g12-20020a056e02198c00b002d8e8bdd8ffmr1164826ilf.66.1655477342098; Fri, 17 Jun 2022 07:49:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s/O7kGfVBZ/hAahW0L8thCJgr1GWgNaA/SlNgtqxHdE6Nt7rlDLoGzK0OgwS3zyQ7T7M86+w== X-Received: by 2002:a05:6e02:198c:b0:2d8:e8bd:d8ff with SMTP id g12-20020a056e02198c00b002d8e8bdd8ffmr1164800ilf.66.1655477341815; Fri, 17 Jun 2022 07:49:01 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n24-20020a02cc18000000b0032e168fa56fsm2294838jap.83.2022.06.17.07.49.00 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Jun 2022 07:49:01 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , peterx@redhat.com, Paolo Bonzini , Richard Henderson , Igor Mammedov Subject: [PATCH 1/5] cpus-common: Introduce run_on_cpu_func2 which allows error returns Date: Fri, 17 Jun 2022 10:48:53 -0400 Message-Id: <20220617144857.34189-2-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220617144857.34189-1-peterx@redhat.com> References: <20220617144857.34189-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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, 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+qemu-devel=archiver.kernel.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 Fri Jun 17 14:48:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885768 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 0F808C433EF for ; Fri, 17 Jun 2022 14:56:12 +0000 (UTC) Received: from localhost ([::1]:46570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2DON-0003Uq-52 for qemu-devel@archiver.kernel.org; Fri, 17 Jun 2022 10:56:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35544) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHb-0003iw-36 for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41859) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHY-0008Ca-Bk for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477346; 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=UKkLwF1Vc9VLRucu16n4U9hlB6I39Nn5tmSo0ltdU4JffQfsRRtbQmhbELIK3tQtTC8Pcv r00UZLwE0DTak1bmc126ftLXL3/otBMtQ0m7RiK7F3s2GPybb66W9zSqV6mWhoQShAC4N4 Qd/eKXafncia/wRq1AAywl/kSfbYlc0= Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-113-ZV-U1A2YPSKAu0KM2BZQ_g-1; Fri, 17 Jun 2022 10:49:04 -0400 X-MC-Unique: ZV-U1A2YPSKAu0KM2BZQ_g-1 Received: by mail-io1-f71.google.com with SMTP id z137-20020a6bc98f000000b00669b0a179c7so2637266iof.6 for ; Fri, 17 Jun 2022 07:49:04 -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=ou+R3Ihn6QFIDPqmpBMPfRdbN9MZ5rOpnDgucv3sBec1iVjaga05DbcDORKflBj+zv Quej19LVi3x2vpkvxpuvrZ61qi6teLADm4CP+mlghbn21BHu/BZ4AKaENAIizFKGy9po lnnxFUBtJaaSOSC4nZPJDQR8R09hL3YAV/Hm3NN8Kia9mHKvNYRgKkHZe1rSZA2vcyLc 7xj+OfYKkXH8X0SHpZBahT6dHBshhDrdt7fhPCE2PR3d3l3Oyr3L9+nuvdeCvKkik33a v0Wke9w2PWfoa3frB/EgC07vHIQ7BfLhOxpCFDwivesJI84meMTpUCtF7DJDbo+JFHZQ FtTA== X-Gm-Message-State: AJIora+UWkgp5bp9Ux7pw/bAxWxJpK9sJ4HjuKvxtAM90qd0FOpk6Cbf FVnpZLudXxg6FNCrGdZ67gfodlxGBKv8OfT+85ink3tDLK+HcnfJQRPcAJwujvr+o5bZBslErq6 DByHdblWXMmjFcgOklU14gKVTRwYnpV94P7Jqwqn49u1Nkl+tV5ir2V+Bj5T9mvsM X-Received: by 2002:a05:6638:2486:b0:331:f9b9:a8ef with SMTP id x6-20020a056638248600b00331f9b9a8efmr5452868jat.139.1655477344007; Fri, 17 Jun 2022 07:49:04 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBBqYD+/sD/XX4jJkPOXcBhQa61tP3yHCuQjvlmvoMdyFnlv2icOEsUcj0KskCh7AVdaXpng== X-Received: by 2002:a05:6638:2486:b0:331:f9b9:a8ef with SMTP id x6-20020a056638248600b00331f9b9a8efmr5452844jat.139.1655477343722; Fri, 17 Jun 2022 07:49:03 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n24-20020a02cc18000000b0032e168fa56fsm2294838jap.83.2022.06.17.07.49.01 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Jun 2022 07:49:03 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , peterx@redhat.com, Paolo Bonzini , Richard Henderson , Igor Mammedov Subject: [PATCH 2/5] cpus-common: Add run_on_cpu2() Date: Fri, 17 Jun 2022 10:48:54 -0400 Message-Id: <20220617144857.34189-3-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220617144857.34189-1-peterx@redhat.com> References: <20220617144857.34189-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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, 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+qemu-devel=archiver.kernel.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 Fri Jun 17 14:48:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id DF60FC433EF for ; Fri, 17 Jun 2022 14:52:04 +0000 (UTC) Received: from localhost ([::1]:39096 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2DKN-0006O2-RF for qemu-devel@archiver.kernel.org; Fri, 17 Jun 2022 10:52:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35530) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHa-0003hP-BC for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:10 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:57088) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHY-0008Ce-Bq for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477347; 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=pBk6B+Bo0PfX83P4HlyD0NwaXmkNfrQ4M7ZS6wcjkwk=; b=QVa8pepOXOlYtn2pQYUCOSu3uK2p5oBjHzZGAkgmbI7ShCNhy8FGEexoR+UDCkyrMuswj6 rS405sWaUK+1q5Utjy99CpsRO50U2dKlzYe95ZUvhWa0oY5lX+KQ4/AYkXG8NDviqF7kYB zN+cURbU4wa0wewaNpMUMF6lE838v2U= 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-593-PfqqNHyQOtKxEZR7Y2WSfw-1; Fri, 17 Jun 2022 10:49:06 -0400 X-MC-Unique: PfqqNHyQOtKxEZR7Y2WSfw-1 Received: by mail-io1-f70.google.com with SMTP id i198-20020a6b3bcf000000b0066cf0d427daso821212ioa.11 for ; Fri, 17 Jun 2022 07:49:06 -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=pBk6B+Bo0PfX83P4HlyD0NwaXmkNfrQ4M7ZS6wcjkwk=; b=Vs3HZgI+6Iqsr6GXPgtsCE5mRNtsUpEGZJOjU49XUdly7AX1XXdgtJjOfohgl3dJK3 WGPjQY5TWhMMHbpur+MSjMkLV2M4Pffrqsi89jWhyp16573OBmYOugyX+0OjV7i1qot4 83Y/IdnRtaiPJM3kuRQuXAcUZ7T54yjLQYMCXeCCIxACGWGiSPx/suykQITrUCW5P7pG PJM5v7Tm07gN+c0eXAlE5p8fH5xUy/Q4YkeXh77YI0/2JreomND+egzhA3s0mCHc48ss uSD0cY/hkhXzYAoBWT7s/IuM4Ysf4CsUqzqa7ttZkjy5/Q+PxPadRC5ticuK1+S5pbs3 Ts+g== X-Gm-Message-State: AJIora+fQ7z+GO424iy6wCRKgyPX07P3WNsCVHYpajHDHakmtpgnANVc z8BxfQVfoK3gnEF3ZNQPRLZIvq2qxePQTGRHYDGky7A+3Ac6jXWAvcSqa+lKEYYJSjGBplzfOB/ 8kWlySW3NZhwTHIdYu3okOeBadZI4BYkMIslpU6Q4/lSwlZB3Kw6Q14xU5ZhDPcIn X-Received: by 2002:a05:6e02:1b87:b0:2d6:5e74:217a with SMTP id h7-20020a056e021b8700b002d65e74217amr5846250ili.74.1655477345544; Fri, 17 Jun 2022 07:49:05 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u6yRIwVZ534mz7LIJewh/FPli5QiG3BeAdZA73rhJnm8g8dLaGUAwpm5Gpdbdj2/wIuX4D3w== X-Received: by 2002:a05:6e02:1b87:b0:2d6:5e74:217a with SMTP id h7-20020a056e021b8700b002d65e74217amr5846227ili.74.1655477345236; Fri, 17 Jun 2022 07:49:05 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n24-20020a02cc18000000b0032e168fa56fsm2294838jap.83.2022.06.17.07.49.03 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Jun 2022 07:49:04 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , peterx@redhat.com, Paolo Bonzini , Richard Henderson , Igor Mammedov Subject: [PATCH 3/5] accel: Allow synchronize_post_init() to take an Error** Date: Fri, 17 Jun 2022 10:48:55 -0400 Message-Id: <20220617144857.34189-4-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220617144857.34189-1-peterx@redhat.com> References: <20220617144857.34189-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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, 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+qemu-devel=archiver.kernel.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 24913ca9c4..dec4446264 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 ba3210b1c1..df4f7c98f3 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2777,7 +2777,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 Fri Jun 17 14:48:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id C0A6AC43334 for ; Fri, 17 Jun 2022 14:56:14 +0000 (UTC) Received: from localhost ([::1]:46714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2DOP-0003ae-Tr for qemu-devel@archiver.kernel.org; Fri, 17 Jun 2022 10:56:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHb-0003k0-Mc for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:59413) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHZ-0008Cu-Vg for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477349; 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=pP2NADRE9oOFEa/D5phGxp4aqs8ySJ4/3PmGOiorPaI=; b=ZIvszDdzJ3N2/4n4Y0ejoFyF0z0dLaZg5EFXoyG+3N2OJ1/+hL+0HG9ybz/leQK98Xx8Wd 9p4ajl7EYrw9gqf91O9jh+1uPV1AbA2OKef1CQAjDnLLm2xIsIx6FUcUXqvZYSyBnV+2GU mituONwfZRpiZqpdMkaizS08lqqE4H8= 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-528-JQyx64t-PDuhRFLza_nRsg-1; Fri, 17 Jun 2022 10:49:08 -0400 X-MC-Unique: JQyx64t-PDuhRFLza_nRsg-1 Received: by mail-io1-f70.google.com with SMTP id e195-20020a6bb5cc000000b0066cc9ece80fso2647333iof.5 for ; Fri, 17 Jun 2022 07:49:08 -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=pP2NADRE9oOFEa/D5phGxp4aqs8ySJ4/3PmGOiorPaI=; b=5uY0E1rRxJnU5XZSB/kClAisnFFRKFZ6jvbXybgzwyhrksrw4/s+L8oPwiSzmXaU47 QUq89Rd4dsoonyqkIzIy1BZugSoD5Gj5Q1g7whchQlNPjpcraLuOwphrrYPoGOSZrEBB z2JTxUAdC7KAC8yuGSbzCHWCPyq3Uz18gFB9Ztrt7yv5kesj80kREf2aD4FBgjaPP6mv UCyZMsjvJCAaMoNsYnc2ur/uEunvQGsTXo5jDxAaFWzH6hSE4Jv5zpul5S762C3725tK Fgd3J1/I7BLrkFh/QWoo8GCvDB+PToXGqeuemGncAQrjQmy/W8Hq1fnQZ9kp9BgZLyPN uIMw== X-Gm-Message-State: AJIora/J6m6qOiHMP2iHUZdQRpz5KrVuSv2rRyM/Q4gZoeK3hn0EMZ7e BSZKrfKxJ2YzlV3p5Yo9ub//VShFWrRGp+uDAewFeed6X41JLZ3V1hWdLX+idU0zO+cn3rEIiov LBgyJRDpPu9AVNj1w291fT5AkkAs9+uuKR4HYOobroEWO/2WO8MB4Kp4kvtb/s1kn X-Received: by 2002:a5e:c307:0:b0:668:b809:ecbb with SMTP id a7-20020a5ec307000000b00668b809ecbbmr5074392iok.174.1655477347419; Fri, 17 Jun 2022 07:49:07 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ulTI5jf9v+SxLsKOm0xVjWjOhqBBUMtqTPrYVM5hTCGt4mVyXcz0pwN4eP4CRlSWGCrbaeHA== X-Received: by 2002:a5e:c307:0:b0:668:b809:ecbb with SMTP id a7-20020a5ec307000000b00668b809ecbbmr5074366iok.174.1655477347096; Fri, 17 Jun 2022 07:49:07 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n24-20020a02cc18000000b0032e168fa56fsm2294838jap.83.2022.06.17.07.49.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Jun 2022 07:49:06 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , peterx@redhat.com, Paolo Bonzini , Richard Henderson , Igor Mammedov Subject: [PATCH 4/5] cpu: Allow cpu_synchronize_all_post_init() to take an errp Date: Fri, 17 Jun 2022 10:48:56 -0400 Message-Id: <20220617144857.34189-5-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220617144857.34189-1-peterx@redhat.com> References: <20220617144857.34189-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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, 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+qemu-devel=archiver.kernel.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 a673302cce..e1a072080a 100644 --- a/hw/core/machine.c +++ b/hw/core/machine.c @@ -1419,7 +1419,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 Fri Jun 17 14:48:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12885766 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 6A1C0C43334 for ; Fri, 17 Jun 2022 14:52:11 +0000 (UTC) Received: from localhost ([::1]:39500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o2DKU-0006fW-CQ for qemu-devel@archiver.kernel.org; Fri, 17 Jun 2022 10:52:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35566) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHd-0003pN-9u for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o2DHb-0008DV-Po for qemu-devel@nongnu.org; Fri, 17 Jun 2022 10:49:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655477351; 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=WfTEtGtV60xCo5tf6z0boZW/OxUUTeobdYFSqWKTCck=; b=UIth3IJGZLagmAutCR5EolLvBkIbkNSh7/RwxsyRZbZjD36i5psqIpEj9PzkecKKezKhZ4 BZDZYKF8U7ZJneg0xbRKJ5q7rJzlQ+F6lZvgonOn0NvoiulHeRnOAH6yO0RBcaZ+3AMuiI XV9+Yzyytafh8DPoybzJOgmhJap0XM8= Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-484-WkQ2HuF4O3aocb2nth4ipw-1; Fri, 17 Jun 2022 10:49:09 -0400 X-MC-Unique: WkQ2HuF4O3aocb2nth4ipw-1 Received: by mail-il1-f197.google.com with SMTP id s15-20020a056e02216f00b002d3d5e41565so2783979ilv.10 for ; Fri, 17 Jun 2022 07:49:09 -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=WfTEtGtV60xCo5tf6z0boZW/OxUUTeobdYFSqWKTCck=; b=cGnH9GstPsw308LlBW0JlT6xwMOUb2kyLoapm467VRo0k7JKpcnC7GXZwsf7OXkPHS xngebBd3qBlilxXJLs4jKOMJQXEkkltKczmnFt2fuCzGyVDqFcmDRIMrWIDUhrL+1B4x 11Kt5MKnczc4Mw+fEf1dfDB9sJvaeO2hMdIYnTPg9yqcu6C/fg4Lps6QR4d/r8RTYXcr w6t27FB3TK9mSEXbg2nMqHcmOTDbY1Fw9bYMPNtFdQFYoFSVVGc7qXNih6wp/z+u/BeZ S4tjONEXCHcM16rWsZLtHfkwsTr4t5VMB3deoFZhEKdwLtOaROWajjrTJGHmLUVIio50 GTEQ== X-Gm-Message-State: AJIora//rzLmLok+l/X59kIa57w3Rma10rqPdQGh66J2jB4ql63tO85g 3GiwYaIUEFkSQTUJxhiuZ0GM4Aobabs9MaikYoS5P9+9zRsga6Om8Ts/99UdqmMq+xQH3PxG+nE +Hrfucw1cgUvO7+zWQnaN0ebYBPKsAyoh9ZjBcPBL9REDDcVkHePgaSFWf6X/RtX/ X-Received: by 2002:a02:aa92:0:b0:331:c856:fe69 with SMTP id u18-20020a02aa92000000b00331c856fe69mr5335916jai.187.1655477348965; Fri, 17 Jun 2022 07:49:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s2mXVZTbiDztK44Y0DAQSHQpmjKvvYQtFF2kBx0IP1w5TOu4Jtkxlqjed5eEmdGdxsWFMfbg== X-Received: by 2002:a02:aa92:0:b0:331:c856:fe69 with SMTP id u18-20020a02aa92000000b00331c856fe69mr5335897jai.187.1655477348705; Fri, 17 Jun 2022 07:49:08 -0700 (PDT) Received: from localhost.localdomain (cpec09435e3e0ee-cmc09435e3e0ec.cpe.net.cable.rogers.com. [99.241.198.116]) by smtp.gmail.com with ESMTPSA id n24-20020a02cc18000000b0032e168fa56fsm2294838jap.83.2022.06.17.07.49.07 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 17 Jun 2022 07:49:08 -0700 (PDT) From: Peter Xu To: qemu-devel@nongnu.org Cc: Juan Quintela , Sean Christopherson , "Dr . David Alan Gilbert" , Leonardo Bras Soares Passos , peterx@redhat.com, Paolo Bonzini , Richard Henderson , Igor Mammedov Subject: [PATCH 5/5] KVM: Hook kvm_arch_put_registers() errors to the caller Date: Fri, 17 Jun 2022 10:48:57 -0400 Message-Id: <20220617144857.34189-6-peterx@redhat.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220617144857.34189-1-peterx@redhat.com> References: <20220617144857.34189-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: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_LOW=-0.7, 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+qemu-devel=archiver.kernel.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 df4f7c98f3..03e29ab1ed 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2771,15 +2771,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; + } } }