From nobody Tue Apr 23 23:29:05 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) client-ip=80.81.252.135; envelope-from=seabios-bounces@seabios.org; helo=mail.coreboot.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@amazon.de; spf=none (zoho.com: 80.81.252.135 is neither permitted nor denied by domain of seabios.org) smtp.mailfrom=seabios-bounces@seabios.org Return-Path: Received: from mail.coreboot.org (mail.coreboot.org [80.81.252.135]) by mx.zohomail.com with SMTPS id 1507668213654988.5278983518642; Tue, 10 Oct 2017 13:43:33 -0700 (PDT) Received: from [127.0.0.1] (helo=ra.coreboot.org) by mail.coreboot.org with esmtp (Exim 4.86_2) (envelope-from ) id 1e21My-0000VR-Fu; Tue, 10 Oct 2017 22:43:16 +0200 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]) by mail.coreboot.org with esmtps (TLSv1.2:RC4-SHA:128) (Exim 4.86_2) (envelope-from ) id 1e21Mn-0000Of-4v for seabios@seabios.org; Tue, 10 Oct 2017 22:43:15 +0200 Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-2b-81e76b79.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-out-6001.iad6.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 10 Oct 2017 20:42:53 +0000 Received: from uf8b156e456a5587c9af4.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2b-81e76b79.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id v9AKgnxd056375 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 10 Oct 2017 20:42:50 GMT Received: from uf8b156e456a5587c9af4.ant.amazon.com (localhost [127.0.0.1]) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id v9AKgm8d020087; Tue, 10 Oct 2017 22:42:48 +0200 Received: (from sironi@localhost) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Submit) id v9AKgmfY020086; Tue, 10 Oct 2017 22:42:48 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1507668185; x=1539204185; h=from:to:cc:subject:date:message-id; bh=MsHDm1sWnDVaZy/H0P7Dq1Jp02sxz9FyLVrL6bv27Vs=; b=eRDh5qxHC+oMPcFFfMsEullfNzXKWjktNNvi8cxZky4bWbqWb0ejXJM/ /URHOWJ87GrtsFMAsWCSXQYgVpknmqcsa+dLnwkIy6a5fskAwyuS5J9Mf LE45W/VHOxK7LGFefu1nRRTN90Z8PYDbUtjqndzJlLm5Zucn/lCncnUYT M=; X-IronPort-AV: E=Sophos;i="5.43,359,1503360000"; d="scan'208";a="313154002" From: Filippo Sironi To: seabios@seabios.org Date: Tue, 10 Oct 2017 22:42:03 +0200 Message-Id: <1507668123-19960-1-git-send-email-sironi@amazon.de> X-Mailer: git-send-email 2.7.4 X-Spam-Score: -13.1 (-------------) Subject: [SeaBIOS] [PATCH] nvme: Use the Maximum Queue Entries Supported (MQES) to initialize I/O queues X-BeenThere: seabios@seabios.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SeaBIOS mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: seabios-bounces@seabios.org Sender: "SeaBIOS" X-Duff: Orig. Duff, Duff Lite, Duff Dry, Duff Dark, Raspberry Duff, Lady Duff, Red Duff, Tartar Control Duff X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" ... and cap the length to 256 to avoid oom-ing. Signed-off-by: Filippo Sironi --- src/hw/nvme.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/hw/nvme.c b/src/hw/nvme.c index 946487f4fd43..19a4e7a48d3c 100644 --- a/src/hw/nvme.c +++ b/src/hw/nvme.c @@ -20,6 +20,8 @@ #include "nvme.h" #include "nvme-int.h" =20 +#define min(a, b) ({ typeof(a) _a =3D a; typeof(b) _b =3D b; _a < _b ? _a = : _b; }) + static void * zalloc_page_aligned(struct zone_s *zone, u32 size) { @@ -318,8 +320,10 @@ nvme_create_io_cq(struct nvme_ctrl *ctrl, struct nvme_= cq *cq, u16 q_idx) { int rc; struct nvme_sqe *cmd_create_cq; + u16 length; =20 - rc =3D nvme_init_cq(ctrl, cq, q_idx, NVME_PAGE_SIZE / sizeof(struct nv= me_cqe)); + length =3D min(1 + (ctrl->reg->cap & 0xffff), NVME_PAGE_SIZE / sizeof(= struct nvme_cqe)); + rc =3D nvme_init_cq(ctrl, cq, q_idx, length); if (rc) { goto err; } @@ -359,8 +363,10 @@ nvme_create_io_sq(struct nvme_ctrl *ctrl, struct nvme_= sq *sq, u16 q_idx, struct { int rc; struct nvme_sqe *cmd_create_sq; + u16 length; =20 - rc =3D nvme_init_sq(ctrl, sq, q_idx, NVME_PAGE_SIZE / sizeof(struct nv= me_cqe), cq); + length =3D min(1 + (ctrl->reg->cap & 0xffff), NVME_PAGE_SIZE / sizeof(= struct nvme_cqe)); + rc =3D nvme_init_sq(ctrl, sq, q_idx, length, cq); if (rc) { goto err; } --=20 2.7.4 _______________________________________________ SeaBIOS mailing list SeaBIOS@seabios.org https://mail.coreboot.org/mailman/listinfo/seabios