From nobody Mon Feb 9 08:57:53 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1599136103; cv=none; d=zohomail.com; s=zohoarc; b=JDf3ndkVtD8wqCe1XEDUIxMNBfd3GwauD0K+ZGLplDY94jI1WyljoPZRBYkCDBpUE1r6a/YRcPv/3lbVMwA0nQs8uOmbhOZvVriIT/XsslwzEsUdKWi5PDH11QDckrokIhxNSyFGXN8o7VncfyJv7LLe6Eai663zT46cU4OpgOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136103; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=TTj5ygyvl3m9X8aG/OG5RYyWnVD4Y1B5IoiAdEvQLwI=; b=eOpmm3SyZGwzmhuIXLQqQ4PV1bZPd5BFuKwmiIjf2eYkpIyPmDdUApeEGMWX1Qg1nFdqITbraw5OXLGCMDiBQM11ZlERQN8PmbTAX+6Um+CEBbXXF5SYonVtgv+zhIZbeFaZdeozFH/X05pNP8lp1aefcYyn7mUeTJHFxgbqtvs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599136103370521.0311864057925; Thu, 3 Sep 2020 05:28:23 -0700 (PDT) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-145-NjYbbAawMGWh3sjs1Xo0cw-1; Thu, 03 Sep 2020 08:28:21 -0400 Received: by mail-wm1-f69.google.com with SMTP id s24so917385wmh.1 for ; Thu, 03 Sep 2020 05:28:21 -0700 (PDT) Return-Path: Return-Path: Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id j7sm4496117wrw.35.2020.09.03.05.28.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136102; 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=TTj5ygyvl3m9X8aG/OG5RYyWnVD4Y1B5IoiAdEvQLwI=; b=ibyWX22cTGDGjhcbJFsD+QSRXysy7FG1eXrVIk5ZsufNErqi3wtq+FD7ZoO8plBMdFF5PB v+2zVFHO4BSAUBnvS32yOEjHmzGZNyt6PW71nWCzs3IXexmEAEj1MljXh3kDeWyBUmuf6K Aa5+hgA61v+zrrYUU6Hazcc4ta+qXL8= X-MC-Unique: NjYbbAawMGWh3sjs1Xo0cw-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:mime-version:content-transfer-encoding; bh=TTj5ygyvl3m9X8aG/OG5RYyWnVD4Y1B5IoiAdEvQLwI=; b=uK1gg2G9liws67xVOmeta9jDsZmEZ81tpXmt4VPjjaPbejHP1SM6qtjKjEqZqDJHq3 h7gFBbgkL/QZbqjChfMkJrYonobrRpw0PLOPHpYKUahnCPduUbwgQs1/9Ojn/oxEUSWo tXoXEcRSJRPt/aXGzy7qtYeBlwGw9Mk+IVAFwhRsBT0LfWklRoTjtvK0nl7XbAxXh61T RshYO+zdO38BUOQQfmN3oPmGFu6bQBgCEvrkvIT9mm/TjjvuJupEByCKpCcV3gnnEww0 fBDYuqXX8QGLDorq6jJ3LdbFUV2lxu4O4l/1KTgvHzlXbrX/y26pkptz8T6HX+kCIhZS vDOw== X-Gm-Message-State: AOAM532zFcsp4ewsAz+ymy1sSSi3+pKJDSfi+XYjbScyabqtsqf+P8dp e0pdgBFXnxaiteBYx1Ex0B+SiG8ubGkX3E0OJv8HpePkHX3III/xxmXcK42A4t/5YFCoEw6aP1x 1R/Gi2PQkMEonCg== X-Received: by 2002:a05:6000:7:: with SMTP id h7mr2357957wrx.16.1599136100146; Thu, 03 Sep 2020 05:28:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6TjWq2xPKpms8KeArySKub5jzPn0mKbR3uB3ouuy30yqVmvG0PwgipO5rYv7AaDwkLgFDSg== X-Received: by 2002:a05:6000:7:: with SMTP id h7mr2357944wrx.16.1599136099996; Thu, 03 Sep 2020 05:28:19 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Klaus Jensen , Fam Zheng , Max Reitz , Keith Busch , Kevin Wolf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Stefano Garzarella Subject: [PATCH v7 03/15] block/nvme: Let nvme_create_queue_pair() fail gracefully Date: Thu, 3 Sep 2020 14:27:51 +0200 Message-Id: <20200903122803.405265-4-philmd@redhat.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200903122803.405265-1-philmd@redhat.com> References: <20200903122803.405265-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) As nvme_create_queue_pair() is allowed to fail, replace the alloc() calls by try_alloc() to avoid aborting QEMU. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 4d4f728159f..ca8b039f4f0 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -213,14 +213,22 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDri= verState *bs, int i, r; BDRVNVMeState *s =3D bs->opaque; Error *local_err =3D NULL; - NVMeQueuePair *q =3D g_new0(NVMeQueuePair, 1); + NVMeQueuePair *q; uint64_t prp_list_iova; =20 + q =3D g_try_new0(NVMeQueuePair, 1); + if (!q) { + return NULL; + } + q->prp_list_pages =3D qemu_try_blockalign0(bs, + s->page_size * NVME_NUM_REQS); + if (!q->prp_list_pages) { + goto fail; + } qemu_mutex_init(&q->lock); q->s =3D s; q->index =3D idx; qemu_co_queue_init(&q->free_req_queue); - q->prp_list_pages =3D qemu_blockalign0(bs, s->page_size * NVME_NUM_REQ= S); q->completion_bh =3D aio_bh_new(bdrv_get_aio_context(bs), nvme_process_completion_bh, q); r =3D qemu_vfio_dma_map(s->vfio, q->prp_list_pages, --=20 2.26.2