From nobody Mon Feb 9 23:42:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1602505966; cv=none; d=zohomail.com; s=zohoarc; b=eylekLl2qBdiGOzGvvDPCMyUtXxNtag7zOwtqTGNpmbX4i0gqywKprVak2rS19lKd8gSUApCB9YNlyee1yRz5hzscarAysShBFbtzYIKiuhfK7F9z8vmi9neIw3oqC234Ef6nY/GUTBS7UB+xinByekpNvCTv6KJzivU9u+lFkg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602505966; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=k+NaAoMRkUFyZRKc4oUofZeoSY0+phvTxE4YV4+hM2E=; b=HoVp5WFxF5Ra0/M12uaRomzLFkcJgiR0W4z8uL47+05oFKl1465oGKEVjq8+LBatEg2KNpjmw+P1TyMYMOTEDWM5l103qs2Hatb/rf2sqa/i//kF3FvnM3QBty1svsbmurSlypg54fjRxTJrQfTIx+r+7C5Xw3ClaPGqNb3EOIo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1602505966956811.4517232467039; Mon, 12 Oct 2020 05:32:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-27-pMypovjAMeyvTZ2LtQhHNg-1; Mon, 12 Oct 2020 08:32:43 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B9C4F18BE16C; Mon, 12 Oct 2020 12:32:37 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 95E1A6CE4D; Mon, 12 Oct 2020 12:32:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 632B9A21EB; Mon, 12 Oct 2020 12:32:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 09CCWNGQ027699 for ; Mon, 12 Oct 2020 08:32:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7411D2166BDD; Mon, 12 Oct 2020 12:32:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6E1932166BA4 for ; Mon, 12 Oct 2020 12:32:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D0DD858289 for ; Mon, 12 Oct 2020 12:32:20 +0000 (UTC) Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-164-cvQlnGWpNAaj2VKx_QjpwA-1; Mon, 12 Oct 2020 08:32:18 -0400 Received: by mail-pg1-f178.google.com with SMTP id n9so656737pgt.8 for ; Mon, 12 Oct 2020 05:32:18 -0700 (PDT) Received: from libai.bytedance.net ([61.120.150.71]) by smtp.gmail.com with ESMTPSA id c10sm20288392pfc.196.2020.10.12.05.32.14 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Oct 2020 05:32:16 -0700 (PDT) X-MC-Unique: pMypovjAMeyvTZ2LtQhHNg-1 X-MC-Unique: cvQlnGWpNAaj2VKx_QjpwA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k+NaAoMRkUFyZRKc4oUofZeoSY0+phvTxE4YV4+hM2E=; b=NZSmvz6Snryb+gCxvVXqMgbRchF2scIJmyXdacep1tON8QYQNZHnDkZ33gYx0xFKAa /cn72A7nY5qJlXpsmMJqYOpE8v7j9qbBkdhs0taSLphQiP/eS0yHg6JekE+nXDjVRZNu OrzeEoUvZo/clAoS6r8AiNqmZN0qw2L27vz0C7BJf/ARqJ+mtckHqyF2yO3o1XFDofS5 lVxp+4McRFKNee2xb4iBq1giUPqXA+LpsHtKng6W75zE72zURiptjF+sH2RsY6VnbGpC JMPc8y4J7Qt4DgcfpAjlypYtjPDpi/fZhoK9tNH+ycxfZymbyytnnEzRRAKWVYUlhtoO KRuQ== X-Gm-Message-State: AOAM533957acCwmhSLtO7JKmINkkovW6bjZ3eZbds45tUOwMZsGf9Xo0 F4cpORcs/Zrg5LdtPMOT8twLUnM1urUTAA== X-Google-Smtp-Source: ABdhPJxo2wMMjqInCOkuMadgbGondiH1B7YvRAfcO1+dLJl7JkuI8Zc4OJfXmNtDEsPFYo/QbQ/9jw== X-Received: by 2002:a17:90a:940e:: with SMTP id r14mr12810236pjo.227.1602505937177; Mon, 12 Oct 2020 05:32:17 -0700 (PDT) From: zhenwei pi To: pkrempa@redhat.com, berrange@redhat.com Subject: [PATCH v2 3/4] qemu: monitor: handle memory failure event Date: Mon, 12 Oct 2020 20:31:58 +0800 Message-Id: <20201012123159.908654-4-pizhenwei@bytedance.com> In-Reply-To: <20201012123159.908654-1-pizhenwei@bytedance.com> References: <20201012123159.908654-1-pizhenwei@bytedance.com> X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com, pizhenwei@bytedance.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 2 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Handle memory failure by json string from QEMU, then process by domainMemoryFailure callback function. Signed-off-by: zhenwei pi --- src/qemu/qemu_monitor.c | 21 ++++++++++++++++++- src/qemu/qemu_monitor.h | 39 +++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.c | 49 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 8c991fefbb..189b789bb8 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -159,7 +159,6 @@ static int qemuMonitorOnceInit(void) =20 VIR_ONCE_GLOBAL_INIT(qemuMonitor); =20 - VIR_ENUM_IMPL(qemuMonitorMigrationStatus, QEMU_MONITOR_MIGRATION_STATUS_LAST, "inactive", "setup", @@ -197,6 +196,14 @@ VIR_ENUM_IMPL(qemuMonitorDumpStatus, "none", "active", "completed", "failed", ); =20 +VIR_ENUM_IMPL(qemuMonitorMemoryFailureRecipient, + QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_LAST, + "hypervisor", "guest"); + +VIR_ENUM_IMPL(qemuMonitorMemoryFailureAction, + QEMU_MONITOR_MEMORY_FAILURE_ACTION_LAST, + "ignore", "inject", + "fatal", "reset"); =20 #if DEBUG_RAW_IO static char * @@ -1428,6 +1435,18 @@ qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon) =20 =20 int +qemuMonitorEmitMemoryFailure(qemuMonitorPtr mon, + qemuMonitorEventMemoryFailurePtr mfp) +{ + int ret =3D -1; + + QEMU_MONITOR_CALLBACK(mon, ret, domainMemoryFailure, mon->vm, mfp); + + return ret; +} + + +int qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon, int status) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index a744c8975b..17ba006a2f 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -340,6 +340,40 @@ typedef int (*qemuMonitorDomainGuestCrashloadedCallbac= k)(qemuMonitorPtr mon, virDomainObjPtr v= m, void *opaque); =20 +typedef enum { + QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_HYPERVISOR, + QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_GUEST, + + QEMU_MONITOR_MEMORY_FAILURE_RECIPIENT_LAST +} qemuMonitorMemoryFailureRecipient; + +VIR_ENUM_DECL(qemuMonitorMemoryFailureRecipient); + +typedef enum { + QEMU_MONITOR_MEMORY_FAILURE_ACTION_IGNORE, + QEMU_MONITOR_MEMORY_FAILURE_ACTION_INJECT, + QEMU_MONITOR_MEMORY_FAILURE_ACTION_FATAL, + QEMU_MONITOR_MEMORY_FAILURE_ACTION_RESET, + + QEMU_MONITOR_MEMORY_FAILURE_ACTION_LAST +} qemuMonitorMemoryFailureAction; + +VIR_ENUM_DECL(qemuMonitorMemoryFailureAction); + +typedef struct _qemuMonitorEventMemoryFailure qemuMonitorEventMemoryFailur= e; +typedef qemuMonitorEventMemoryFailure *qemuMonitorEventMemoryFailurePtr; +struct _qemuMonitorEventMemoryFailure { + qemuMonitorMemoryFailureRecipient recipient; + qemuMonitorMemoryFailureAction action; + bool action_required; + bool recursive; +}; + +typedef int (*qemuMonitorDomainMemoryFailureCallback)(qemuMonitorPtr mon, + virDomainObjPtr vm, + qemuMonitorEventMemo= ryFailurePtr mfp, + void *opaque); + typedef struct _qemuMonitorCallbacks qemuMonitorCallbacks; typedef qemuMonitorCallbacks *qemuMonitorCallbacksPtr; struct _qemuMonitorCallbacks { @@ -376,6 +410,7 @@ struct _qemuMonitorCallbacks { qemuMonitorDomainPRManagerStatusChangedCallback domainPRManagerStatusC= hanged; qemuMonitorDomainRdmaGidStatusChangedCallback domainRdmaGidStatusChang= ed; qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded; + qemuMonitorDomainMemoryFailureCallback domainMemoryFailure; }; =20 qemuMonitorPtr qemuMonitorOpen(virDomainObjPtr vm, @@ -475,6 +510,10 @@ int qemuMonitorEmitSerialChange(qemuMonitorPtr mon, const char *devAlias, bool connected); int qemuMonitorEmitSpiceMigrated(qemuMonitorPtr mon); + +int qemuMonitorEmitMemoryFailure(qemuMonitorPtr mon, + qemuMonitorEventMemoryFailurePtr mfp); + int qemuMonitorEmitMigrationStatus(qemuMonitorPtr mon, int status); int qemuMonitorEmitMigrationPass(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 26ac499fc5..aa256727d6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -112,6 +112,7 @@ static void qemuMonitorJSONHandleBlockThreshold(qemuMon= itorPtr mon, virJSONValue static void qemuMonitorJSONHandleDumpCompleted(qemuMonitorPtr mon, virJSON= ValuePtr data); static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitorPtr mon= , virJSONValuePtr data); static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitorPtr mon, = virJSONValuePtr data); +static void qemuMonitorJSONHandleMemoryFailure(qemuMonitorPtr mon, virJSON= ValuePtr data); =20 typedef struct { const char *type; @@ -132,6 +133,7 @@ static qemuEventHandler eventHandlers[] =3D { { "GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded, }, { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, }, { "JOB_STATUS_CHANGE", qemuMonitorJSONHandleJobStatusChange, }, + { "MEMORY_FAILURE", qemuMonitorJSONHandleMemoryFailure, }, { "MIGRATION", qemuMonitorJSONHandleMigrationStatus, }, { "MIGRATION_PASS", qemuMonitorJSONHandleMigrationPass, }, { "NIC_RX_FILTER_CHANGED", qemuMonitorJSONHandleNicRxFilterChanged, }, @@ -1336,6 +1338,53 @@ qemuMonitorJSONHandleSpiceMigrated(qemuMonitorPtr mo= n, =20 =20 static void +qemuMonitorJSONHandleMemoryFailure(qemuMonitorPtr mon, + virJSONValuePtr data) +{ + virJSONValuePtr flagsjson =3D virJSONValueObjectGetObject(data, "flags= "); + const char *str; + int recipient; + int action; + bool ar =3D false; + bool recursive =3D false; + qemuMonitorEventMemoryFailure mf =3D {0}; + + if (!(str =3D virJSONValueObjectGetString(data, "recipient"))) { + VIR_WARN("missing recipient in memory failure event"); + return; + } + + recipient =3D qemuMonitorMemoryFailureRecipientTypeFromString(str); + if (recipient =3D=3D -1) { + VIR_WARN("unknown recipient '%s' in memory_failure event", str); + return; + } + + if (!(str =3D virJSONValueObjectGetString(data, "action"))) { + VIR_WARN("missing action in memory failure event"); + return; + } + + action =3D qemuMonitorMemoryFailureActionTypeFromString(str); + if (action =3D=3D -1) { + VIR_WARN("unknown action '%s' in memory_failure event", str); + return; + } + + if (flagsjson) { + virJSONValueObjectGetBoolean(flagsjson, "action-required", &ar); + virJSONValueObjectGetBoolean(flagsjson, "recursive", &recursive); + } + + mf.recipient =3D recipient; + mf.action =3D action; + mf.action_required =3D ar; + mf.recursive =3D recursive; + qemuMonitorEmitMemoryFailure(mon, &mf); +} + + +static void qemuMonitorJSONHandleMigrationStatus(qemuMonitorPtr mon, virJSONValuePtr data) { --=20 2.11.0