From patchwork Thu Sep 3 12:27:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14BDAC433E2 for ; Thu, 3 Sep 2020 12:32:53 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id C29D920639 for ; Thu, 3 Sep 2020 12:32:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ibyWX22c" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C29D920639 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:59328 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoQ7-00057R-6C for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:32:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoLr-00082Z-1K for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:27 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:54551 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoLn-0007oX-GI for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:25 -0400 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= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-391-2ofADi2CN8q5gzvL5BVIyw-1; Thu, 03 Sep 2020 08:28:21 -0400 X-MC-Unique: 2ofADi2CN8q5gzvL5BVIyw-1 Received: by mail-wr1-f72.google.com with SMTP id r16so1008802wrm.18 for ; Thu, 03 Sep 2020 05:28:21 -0700 (PDT) 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=NwoEzlVvyN74l9bJTBIpwqfLYweayml0ucJr57Gdg9mafa9O0rt7SXcAX8GCHl/5kk lSwSJGgcpkDR7kmyVPI0SBPAhaAVLt2s/SqiMlCrezdChd077bNlbsIs463fWUctVyQR /dBgDE4KL48eICz49jFvpwrxG0ATxzF0nuKB8z1EM/yvZOq/HDcYFjW80Hk5rWzSNHCF KBdzZo8e/TsH4TSspCk0Zqtw0gGBlPwReG62ndPoKoAjp+12CfF3IJSEc4ql2oA2Sr/J iAr03LaYbDNNKVwTd23Xet2Yv/C9KSmZICcPe2Lqsu/c7ii3j9iFibP4l83a0ltPH/St Fv3g== X-Gm-Message-State: AOAM532NeIo8ux2OR5TY9cAg3KW5Q+UIGBWsr8YK76SKdK3BLn1Asslg XH2DDAhTb3uWeYFLyuRTN4Ls1qzfJR1Js7+EEEUmjMwgWoUSnN4Q1xZROvov78csiFPMuPyfAn1 bK7lhdR9Jsg46aE4= X-Received: by 2002:a05:6000:7:: with SMTP id h7mr2357962wrx.16.1599136100147; 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) 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) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org 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 Received-SPF: pass client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 04:23:49 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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é --- 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(BlockDriverState *bs, int i, r; BDRVNVMeState *s = bs->opaque; Error *local_err = NULL; - NVMeQueuePair *q = g_new0(NVMeQueuePair, 1); + NVMeQueuePair *q; uint64_t prp_list_iova; + q = g_try_new0(NVMeQueuePair, 1); + if (!q) { + return NULL; + } + q->prp_list_pages = qemu_try_blockalign0(bs, + s->page_size * NVME_NUM_REQS); + if (!q->prp_list_pages) { + goto fail; + } qemu_mutex_init(&q->lock); q->s = s; q->index = idx; qemu_co_queue_init(&q->free_req_queue); - q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_NUM_REQS); q->completion_bh = aio_bh_new(bdrv_get_aio_context(bs), nvme_process_completion_bh, q); r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, From patchwork Thu Sep 3 12:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274683 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 235D6C433E9 for ; Thu, 3 Sep 2020 12:35:09 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CF29B20639 for ; Thu, 3 Sep 2020 12:35:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LYffjeW2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CF29B20639 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:40630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoSJ-0000c5-RR for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:35:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53300) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoLu-00086l-GG for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:30 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:51281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoLs-0007p1-LK for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136108; 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=EBREVqe86w/qV8xj/jHdOJ+D9gTNwJHNOwqeZKQd6RY=; b=LYffjeW2WX3s33oSYh17XwfdAhDQ6AwCxN3C6BXVvLXqRRzmBc9ynKSs2ceM1B4xMLuuXp n78Jqk4Y4940K/PF72U51Re/r/59ww9so3SrKBg7kCjh5fWtOzqaQbC0VXNftwlxbPh2BY +o55z5yVxXHOMFWISIH0TIxfJI+Xx3A= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-AzyYNjP1O2-Gt9CAgr49Xw-1; Thu, 03 Sep 2020 08:28:26 -0400 X-MC-Unique: AzyYNjP1O2-Gt9CAgr49Xw-1 Received: by mail-wm1-f70.google.com with SMTP id c198so920091wme.5 for ; Thu, 03 Sep 2020 05:28:26 -0700 (PDT) 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=EBREVqe86w/qV8xj/jHdOJ+D9gTNwJHNOwqeZKQd6RY=; b=bM18uMbSTZ29gYV2XQzIrf7/ceDB8QBaTscNwmwx68tkxj+DjfBlZCfGa6mPdehjwt U9mCVmca41Vy3NX1A4F5AZ1w3B5uGsvSksIIIa0F+ltYnTdp4f+pGT0xg0gBClJXpV66 S5uCBQQMr/ToSHuyRN31lyWZKU0X9yy8v2Pe3ppxL6c35g2soJYkBeR/TQEHLWE8Myw+ qq6+6ytzuA+q9oNMG2xCkyazRkf6fYv5Bqi3MFlg92IFSI0mqkdSqcWnIFTYZzsIKFgl zJGXb7sYFADfslJLH/WdGAmO+prRVHbD0syBLNPk+DJU852HQQNIpWGEI0r0KkEXtVw7 yueA== X-Gm-Message-State: AOAM533BBrXBnYDMsgi12xu2lv2jrlLwxKwH8is606x1SV/PPVJwDLVT 6dq2J5cFIJoCAFT1KEBrA121sOe5k8pwfEBjPHhkInUAo0720qdXADW/n0mgDg85z84Y1gg6qIl yWBvfWZpo5h7JW8g= X-Received: by 2002:adf:f149:: with SMTP id y9mr2152343wro.93.1599136105025; Thu, 03 Sep 2020 05:28:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym8SdPMuTrQF/qKRC4BamPWHAPQNevAOuB6lz85pdqrdqAmnSUHoQARZi2v12uTEjpcCjfkQ== X-Received: by 2002:adf:f149:: with SMTP id y9mr2152315wro.93.1599136104771; Thu, 03 Sep 2020 05:28:24 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id s124sm4227408wme.29.2020.09.03.05.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:24 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 04/15] block/nvme: Define INDEX macros to ease code review Date: Thu, 3 Sep 2020 14:27:52 +0200 Message-Id: <20200903122803.405265-5-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 01:47:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Use definitions instead of '0' or '1' indexes. Also this will be useful when using multi-queues later. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index ca8b039f4f0..488d4ddb3b8 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -103,6 +103,9 @@ typedef volatile struct { QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) != 0x1000); +#define INDEX_ADMIN 0 +#define INDEX_IO(n) (1 + n) + struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; @@ -531,7 +534,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) } cmd.dptr.prp1 = cpu_to_le64(iova); - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify controller"); goto out; } @@ -555,7 +558,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify namespace"); goto out; } @@ -644,7 +647,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 = cpu_to_le32(0x3), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -655,7 +658,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 = cpu_to_le32(0x1 | (n << 16)), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -739,16 +742,18 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, /* Set up admin queue. */ s->queues = g_new(NVMeQueuePair *, 1); - s->queues[0] = nvme_create_queue_pair(bs, 0, NVME_QUEUE_SIZE, errp); - if (!s->queues[0]) { + s->queues[INDEX_ADMIN] = nvme_create_queue_pair(bs, 0, + NVME_QUEUE_SIZE, + errp); + if (!s->queues[INDEX_ADMIN]) { ret = -EINVAL; goto out; } s->nr_queues = 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); s->regs->aqa = cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE); - s->regs->asq = cpu_to_le64(s->queues[0]->sq.iova); - s->regs->acq = cpu_to_le64(s->queues[0]->cq.iova); + s->regs->asq = cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); + s->regs->acq = cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); /* After setting up all control registers we can enable device now. */ s->regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | @@ -839,7 +844,7 @@ static int nvme_enable_disable_write_cache(BlockDriverState *bs, bool enable, .cdw11 = cpu_to_le32(enable ? 0x01 : 0x00), }; - ret = nvme_cmd_sync(bs, s->queues[0], &cmd); + ret = nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd); if (ret) { error_setg(errp, "Failed to configure NVMe write cache"); } @@ -1056,7 +1061,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, { int r; BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[INDEX_IO(0)]; NVMeRequest *req; uint32_t cdw12 = (((bytes >> s->blkshift) - 1) & 0xFFFF) | @@ -1171,7 +1176,7 @@ static coroutine_fn int nvme_co_pwritev(BlockDriverState *bs, static coroutine_fn int nvme_co_flush(BlockDriverState *bs) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[INDEX_IO(0)]; NVMeRequest *req; NvmeCmd cmd = { .opcode = NVME_CMD_FLUSH, @@ -1202,7 +1207,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, BdrvRequestFlags flags) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[INDEX_IO(0)]; NVMeRequest *req; uint32_t cdw12 = ((bytes >> s->blkshift) - 1) & 0xFFFF; @@ -1255,7 +1260,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, int bytes) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[INDEX_IO(0)]; NVMeRequest *req; NvmeDsmRange *buf; QEMUIOVector local_qiov; @@ -1398,7 +1403,7 @@ static void nvme_aio_unplug(BlockDriverState *bs) BDRVNVMeState *s = bs->opaque; assert(s->plugged); s->plugged = false; - for (i = 1; i < s->nr_queues; i++) { + for (i = INDEX_IO(0); i < s->nr_queues; i++) { NVMeQueuePair *q = s->queues[i]; qemu_mutex_lock(&q->lock); nvme_kick(q); From patchwork Thu Sep 3 12:27:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274686 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A805FC433E9 for ; Thu, 3 Sep 2020 12:29:49 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 648AF20767 for ; Thu, 3 Sep 2020 12:29:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZttGjjjC" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 648AF20767 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:50942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoNA-0001Uu-Du for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:29:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoM0-0008EA-C7 for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:36 -0400 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:26045 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoLx-0007pH-EG for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136112; 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=HgXwbQUt5qjogYM8iFoeW+GHqjN8VyRP3jjf5JuoDPA=; b=ZttGjjjCS3616krHaedR7CdgJC7MYFY6oKjVwhQwCU4y1QLwkhf9il9wSpTIUM38oWncs7 7dgEIjCRIQ0dnAo6J93s7PDSmxOjUw8UpJGmBWWPdBWdevC/nL0wby0ctPFHkZaIAZJKcL 7jyHUrPV/qJiqt8DnGNTkS1RVIPkAzM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-554-XdMnVcZaOyeE1dtvY2kW_A-1; Thu, 03 Sep 2020 08:28:31 -0400 X-MC-Unique: XdMnVcZaOyeE1dtvY2kW_A-1 Received: by mail-wr1-f70.google.com with SMTP id j2so1020585wrr.14 for ; Thu, 03 Sep 2020 05:28:30 -0700 (PDT) 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=HgXwbQUt5qjogYM8iFoeW+GHqjN8VyRP3jjf5JuoDPA=; b=DVJPmNOQwk76BYZ9ZmjHNtWTvPt6MQ4SrfKHXs4yqLtL4ARDqz8HKiWvuLTX+IDNla ixdlkAOMouVrYSMrXRmsb1+j8epjRYUScik/JxCaVLXHjSsRNj2+9KQko8Dl+tkm29Mb MAqIlb0e2FQzo4EFwm3tun+soJFaGtbc+Tzh5ZXIUujq7ROOxXKtUGTdzmvMAaX77rQg x3xDjKQTekhK/fcCgUev7u/BB5BcVdPVZbZotJrQDVtrDkp5KfXjscZ3fEOGMjBwwtzY ODgcuLpaSXTDupEQjRszFI+Dh5Kd66BD4uMgG1sE9ZOmCKvMEW4m4feuCj1amx30ctQy ihQw== X-Gm-Message-State: AOAM5316Is1AS/xzPlWecBbn24H5fqrxpD7qGXnLXcPI3zfQld8jxeHW VLq009RNWuRZVPdZpYQwKeVQl1u7upEoOddRDGB/BSLrqd+Qi/+mW43ZABGUyI0T/4l88w4oQjb 3f2R2VvQLZr2F2t0= X-Received: by 2002:a05:600c:2f8f:: with SMTP id t15mr2339262wmn.41.1599136109718; Thu, 03 Sep 2020 05:28:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmj/53RnlUwP41Kw830eyDzS+S/LEAKExFitdifMhLbzQYjgIiwMnMt/JKVg31cWPCejhtNg== X-Received: by 2002:a05:600c:2f8f:: with SMTP id t15mr2339246wmn.41.1599136109515; Thu, 03 Sep 2020 05:28:29 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id o4sm4079738wrv.86.2020.09.03.05.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:29 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 05/15] block/nvme: Improve error message when IO queue creation failed Date: Thu, 3 Sep 2020 14:27:53 +0200 Message-Id: <20200903122803.405265-6-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 Received-SPF: pass client-ip=205.139.110.61; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 01:28:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Do not use the same error message for different failures. Display a different error whether it is the CQ or the SQ. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 488d4ddb3b8..91dba4ec5db 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -648,7 +648,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw11 = cpu_to_le32(0x3), }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { - error_setg(errp, "Failed to create io queue [%d]", n); + error_setg(errp, "Failed to create CQ io queue [%d]", n); nvme_free_queue_pair(q); return false; } @@ -659,7 +659,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw11 = cpu_to_le32(0x1 | (n << 16)), }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { - error_setg(errp, "Failed to create io queue [%d]", n); + error_setg(errp, "Failed to create SQ io queue [%d]", n); nvme_free_queue_pair(q); return false; } From patchwork Thu Sep 3 12:27:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8D6D6C433E2 for ; Thu, 3 Sep 2020 12:40:10 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3F447206EB for ; Thu, 3 Sep 2020 12:40:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="gdY6th4z" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F447206EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:32838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoXB-0000ho-A2 for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:40:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoMA-00009Z-WA for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:57252) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoM9-0007qK-Cq for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136124; 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=exUO2EBEU4GpUyorzocM/dFFi//P9vU8D1aRpXB50hw=; b=gdY6th4z7YdMfitrlpssrh3vFRvmqlqZEa5cyWDcbLSQZBxnvFjYA+hQoXd28iNJcdIdfx iYqwOtSllDcnPK2ZUQottmPF+nVYuqAE3zASCdpKUpTbedqvD3hnl44KJ/Y/51oSnryhUu TRf0mq89BTF6tUIaU2ZLI/0zyn7MV8M= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-84-4aL5Vu6wNey90HAd5Dulcw-1; Thu, 03 Sep 2020 08:28:41 -0400 X-MC-Unique: 4aL5Vu6wNey90HAd5Dulcw-1 Received: by mail-wm1-f72.google.com with SMTP id c72so909741wme.4 for ; Thu, 03 Sep 2020 05:28:40 -0700 (PDT) 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=exUO2EBEU4GpUyorzocM/dFFi//P9vU8D1aRpXB50hw=; b=OwBo/GRaerfq8GO3NoFw1VrSiBS+zROoryx0S3SVmALygmoRYXoCseMamVzrYd+dUS VO7xzKH6j6bRe3Og0VZuvlTQ9UB2hJDUQlQ7bMo7EEMXXzt/dTSuHm1ziYkc+Ccq1ULA DheduXw3tEY4idS9+TZdXAqNMHtO+IgnTDaKyHN42vyAlTecWt9/atJQIB5teXDPu4Hy W8jKPnM4cW/r4C9rLBbulRzAhnZFsO7ZNkUFv8pFK2M0Nwom/xEdjsmiNzaio9Fnci1i sDUpcfwXPAY1GI0CRakr5JHsa9rtOiWaJtgDW7O6qomm9oVZJjf8N8NBWBl2puxMLQyN bj/Q== X-Gm-Message-State: AOAM532L9xBhCVPVVO6gitPCwzI75a4ajuIhv+hZtJLfuetBGtL5Ve+P WtOUyAe7goHkMlm/6tK3NqzRLXXnfzwEQeqazsKt1e3OO90poeXm9dphFpHJ+W10i+KqKjQtXlA 01kaOmdAJULdp64I= X-Received: by 2002:a5d:4151:: with SMTP id c17mr2372112wrq.302.1599136119611; Thu, 03 Sep 2020 05:28:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweMps3wEorlmNZrDTFoX/ZU5uxPk2jPc2rbAcbuapIyQlYZm6CDSgFmO+ui6wF8NDqf/V1FQ== X-Received: by 2002:a5d:4151:: with SMTP id c17mr2372089wrq.302.1599136119386; Thu, 03 Sep 2020 05:28:39 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id h185sm4345334wme.25.2020.09.03.05.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:38 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 07/15] block/nvme: Rename local variable Date: Thu, 3 Sep 2020 14:27:55 +0200 Message-Id: <20200903122803.405265-8-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 Received-SPF: pass client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 04:23:54 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We are going to modify the code in the next commit. Renaming the 'resp' variable to 'id' first makes the next commit easier to review. No logical changes. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 909a565184d..0992f2fb579 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -510,8 +510,8 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) BDRVNVMeState *s = bs->opaque; NvmeIdCtrl *idctrl; NvmeIdNs *idns; + uint8_t *id; NvmeLBAF *lbaf; - uint8_t *resp; uint16_t oncs; int r; uint64_t iova; @@ -520,14 +520,14 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - resp = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); - if (!resp) { + id = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl = (NvmeIdCtrl *)resp; - idns = (NvmeIdNs *)resp; - r = qemu_vfio_dma_map(s->vfio, resp, sizeof(NvmeIdCtrl), true, &iova); + idctrl = (NvmeIdCtrl *)id; + idns = (NvmeIdNs *)id; + r = qemu_vfio_dma_map(s->vfio, id, sizeof(NvmeIdCtrl), true, &iova); if (r) { error_setg(errp, "Cannot map buffer for DMA"); goto out; @@ -554,8 +554,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) s->supports_write_zeroes = !!(oncs & NVME_ONCS_WRITE_ZEROES); s->supports_discard = !!(oncs & NVME_ONCS_DSM); - memset(resp, 0, 4096); - + memset(id, 0, 4096); cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { @@ -587,8 +586,8 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) s->blkshift = lbaf->ds; out: - qemu_vfio_dma_unmap(s->vfio, resp); - qemu_vfree(resp); + qemu_vfio_dma_unmap(s->vfio, id); + qemu_vfree(id); } static bool nvme_poll_queues(BDRVNVMeState *s) From patchwork Thu Sep 3 12:27:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274684 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 435E2C433E9 for ; Thu, 3 Sep 2020 12:33:04 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id EEA9720639 for ; Thu, 3 Sep 2020 12:33:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="dRGrU0xS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EEA9720639 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:60272 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoQI-0005Xr-UK for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:33:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoMD-0000FI-Tc for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:49 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:25894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoMB-0007qf-SP for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:28:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136127; 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=aOcjV7su5QwStC1VAK815NSfg5qEBVvoHtC3IGwZAQM=; b=dRGrU0xSR+coUb3qpegtU2hYs7uOScU9mSxmlfuF+I48D7tVv0jApxHR/mcPiDz//0rtHM RqV1zynEXZ1i0Y2twxWpPpY9cikrEf9N6zybAsONgQ/Gv5wxeZSfPIcMGJfESAQLWjJQ6a WtZWdUWb1vklHRkXM718JQRt0iNTlMc= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-141-YQx5C8bBOFOEksJAbZdesg-1; Thu, 03 Sep 2020 08:28:46 -0400 X-MC-Unique: YQx5C8bBOFOEksJAbZdesg-1 Received: by mail-wr1-f69.google.com with SMTP id 33so1018022wrk.12 for ; Thu, 03 Sep 2020 05:28:45 -0700 (PDT) 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=aOcjV7su5QwStC1VAK815NSfg5qEBVvoHtC3IGwZAQM=; b=qBb38CEehoqtA745fY7q5k9G95pUtIhAuTvEBA30ru21WV1SAwzzfEsQQzL63lRnD4 zzyoqrBnqvom9tfzChg/uphmFh7RQJtNT7xKXwxDNETJjr5C9bRZG29fxJW8Zi1/ftbX 2JAOGwPVUUfUkwhNNcqveMj+30p+bk8c4SysHXcIYIIZ8d5isbf4S5rHxSUNZuNRZnA9 vQ5h6AXGIV/mPe5v0gWichhO7bC45HjRQYwiNX0ZaqrstTvzjYLthNVuaaAQuyHhEzXa 6Qeo1HAX7e/dKgkm9ypTk5jWV3lUfpaI3Rsu7AgWNu8wn/BVl/0X46jA7Mv2fGBh9qFg R0iA== X-Gm-Message-State: AOAM530bTcPObaf4zy9sXDk+FNeJsL6qctKRVh78rmWoApHXyDSbkzFe bM6uybyOG/5x4X42M66cS7RJMt16EFYghUHhnOd9N/TP7MdjvxkEoZQS40Ygn3XeG0lrMcIXYRL GDZ72bghKmqDh4ik= X-Received: by 2002:a5d:574c:: with SMTP id q12mr2194096wrw.253.1599136124630; Thu, 03 Sep 2020 05:28:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyEpS27EsHSq1Iv/j/QMP8BSqyIEFn+6TH/JW5kRISOmgmT/ihYefQc4XEonpVfSN2ctoQPPA== X-Received: by 2002:a5d:574c:: with SMTP id q12mr2194068wrw.253.1599136124366; Thu, 03 Sep 2020 05:28:44 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id o6sm2966838wrm.76.2020.09.03.05.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:43 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 08/15] block/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures Date: Thu, 3 Sep 2020 14:27:56 +0200 Message-Id: <20200903122803.405265-9-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 Received-SPF: pass client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 01:47:17 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" We allocate an unique chunk of memory then use it for two different structures. By using an union, we make it clear the data is overlapping (and we can remove the casts). Suggested-by: Stefan Hajnoczi Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 0992f2fb579..b0d55ecfb25 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -508,9 +508,10 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) { BDRVNVMeState *s = bs->opaque; - NvmeIdCtrl *idctrl; - NvmeIdNs *idns; - uint8_t *id; + union { + NvmeIdCtrl ctrl; + NvmeIdNs ns; + } *id; NvmeLBAF *lbaf; uint16_t oncs; int r; @@ -520,14 +521,12 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - id = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + id = qemu_try_blockalign0(bs, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl = (NvmeIdCtrl *)id; - idns = (NvmeIdNs *)id; - r = qemu_vfio_dma_map(s->vfio, id, sizeof(NvmeIdCtrl), true, &iova); + r = qemu_vfio_dma_map(s->vfio, id, sizeof(*id), true, &iova); if (r) { error_setg(errp, "Cannot map buffer for DMA"); goto out; @@ -539,22 +538,22 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) goto out; } - if (le32_to_cpu(idctrl->nn) < namespace) { + if (le32_to_cpu(id->ctrl.nn) < namespace) { error_setg(errp, "Invalid namespace"); goto out; } - s->write_cache_supported = le32_to_cpu(idctrl->vwc) & 0x1; - s->max_transfer = (idctrl->mdts ? 1 << idctrl->mdts : 0) * s->page_size; + s->write_cache_supported = le32_to_cpu(id->ctrl.vwc) & 0x1; + s->max_transfer = (id->ctrl.mdts ? 1 << id->ctrl.mdts : 0) * s->page_size; /* For now the page list buffer per command is one page, to hold at most * s->page_size / sizeof(uint64_t) entries. */ s->max_transfer = MIN_NON_ZERO(s->max_transfer, s->page_size / sizeof(uint64_t) * s->page_size); - oncs = le16_to_cpu(idctrl->oncs); + oncs = le16_to_cpu(id->ctrl.oncs); s->supports_write_zeroes = !!(oncs & NVME_ONCS_WRITE_ZEROES); s->supports_discard = !!(oncs & NVME_ONCS_DSM); - memset(id, 0, 4096); + memset(id, 0, sizeof(*id)); cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { @@ -562,11 +561,11 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) goto out; } - s->nsze = le64_to_cpu(idns->nsze); - lbaf = &idns->lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)]; + s->nsze = le64_to_cpu(id->ns.nsze); + lbaf = &id->ns.lbaf[NVME_ID_NS_FLBAS_INDEX(id->ns.flbas)]; - if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(idns->dlfeat) && - NVME_ID_NS_DLFEAT_READ_BEHAVIOR(idns->dlfeat) == + if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(id->ns.dlfeat) && + NVME_ID_NS_DLFEAT_READ_BEHAVIOR(id->ns.dlfeat) == NVME_ID_NS_DLFEAT_READ_BEHAVIOR_ZEROES) { bs->supported_write_flags |= BDRV_REQ_MAY_UNMAP; } From patchwork Thu Sep 3 12:27:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274680 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05019C433E9 for ; Thu, 3 Sep 2020 12:43:08 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4CE33206EB for ; Thu, 3 Sep 2020 12:43:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UNxuMxjq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4CE33206EB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:39236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDoa1-0003Wc-W5 for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:43:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoMV-0000g4-DG for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:29:07 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:23498) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoMS-0007tN-Pu for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:29:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136144; 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=UCjqLrpq3STI/zR0Jd2dpzbux+828cWdkCvReZKkRjw=; b=UNxuMxjqQJ9QSsqeanC+3H3h8MarnINVrakUslpePIBAotKqSw713VQoGRjaDaLkWQ8bbq 6MSrSsy7JEpr+3GitV2Hlsj0bbBPZ0kL9i7oULXlJb3Z76DtlImiz3kZPRS7ErwfucGvbR LdCMPHlRUYizs8TP/rDChrnQZ+3MrCE= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-Bp0jVM3oNsiTqyjFHeMAmw-1; Thu, 03 Sep 2020 08:29:00 -0400 X-MC-Unique: Bp0jVM3oNsiTqyjFHeMAmw-1 Received: by mail-wr1-f71.google.com with SMTP id l17so1016639wrw.11 for ; Thu, 03 Sep 2020 05:29:00 -0700 (PDT) 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=UCjqLrpq3STI/zR0Jd2dpzbux+828cWdkCvReZKkRjw=; b=gdpOKT6PrOFPFixx24z9ltVfSelx4p87KjzcJvAke5UwDM4dxWmfl0mhFrPlo/8b+u xUorZ60Gup+e0kvIa4QE7NwFeBDbr0xceVbBhEURWCva74jQoYbIv9vYH1Guv5+2rujP xERGaI4s7wQnHdxovIuqyqlSf58JVwRYVvxctuO6pptS1jGQSgIRb2junHEPKwobKLzA giDeKLS7Z0VVUyaX7Tt+YSVE7wzR+ZFbZPxNzMootxkAKKk/bJPwXPNUZgu1WkzHGQ4D lWVOccfltCaLql/fYcAPkqNGLEXbdL+WSJfPJ0hFSa3v5+EDIDekdX5KWOjoKakdAjY6 lxpQ== X-Gm-Message-State: AOAM531lCbX7Kq52BblUhDNONO4E+5SmDU3mUvVCOdHYCTH2DuZPm+61 IWhLhcFAPI6b7GxtNZx3NOT6fEOHKlvghlMvS++XoLkExJRemVpq6xTeFJ4+8F8I3uPMXDKDA4r 05UosZ7/GCzjGeuQ= X-Received: by 2002:a05:600c:210c:: with SMTP id u12mr2406005wml.185.1599136139211; Thu, 03 Sep 2020 05:28:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8hFE3CvHTi9Py94SC3XSsO9X1tDGI99PWFdfkU8QM5rLUDH1IojgEtK0eXq5W6MfXjO6VSA== X-Received: by 2002:a05:600c:210c:: with SMTP id u12mr2405983wml.185.1599136139051; Thu, 03 Sep 2020 05:28:59 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id 31sm4270787wrd.26.2020.09.03.05.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 11/15] block/nvme: Simplify nvme_init_queue() arguments Date: Thu, 3 Sep 2020 14:27:59 +0200 Message-Id: <20200903122803.405265-12-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 Received-SPF: pass client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 04:23:54 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" nvme_init_queue() doesn't require BlockDriverState anymore. Replace it by BDRVNVMeState to simplify. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 0c8ad1d60b6..e04e1fa4f8f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -165,10 +165,9 @@ static QemuOptsList runtime_opts = { }, }; -static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, +static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, int nentries, int entry_bytes, Error **errp) { - BDRVNVMeState *s = bs->opaque; size_t bytes; int r; @@ -251,14 +250,14 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, req->prp_list_iova = prp_list_iova + i * s->page_size; } - nvme_init_queue(bs, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); + nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; } q->sq.doorbell = &s->regs->doorbells[idx * 2 * s->doorbell_scale]; - nvme_init_queue(bs, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); + nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; From patchwork Thu Sep 3 12:28:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 274679 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8624C433E2 for ; Thu, 3 Sep 2020 12:45:21 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 823092072A for ; Thu, 3 Sep 2020 12:45:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EHuRz5ld" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 823092072A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:44634 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kDocC-0005pA-Jm for qemu-devel@archiver.kernel.org; Thu, 03 Sep 2020 08:45:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kDoMm-0001L0-L3 for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:29:24 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:42349 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kDoMk-0007un-JE for qemu-devel@nongnu.org; Thu, 03 Sep 2020 08:29:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136161; 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=NpnignYWyGxwS894GY8oMk/a6JEblSgZ3kZBOAlqf6A=; b=EHuRz5ldh7m30rNP6kcSn7OglEJNee23uWnD1qbqDSwGfoAPCJpwQB9o8oLJyAXJc1+tlM 0xOgw/2znYP0ZrIGKntH+3yLhQKHk13tP0yGX/grE4vrkyM1Oq5Fx53vWQKcDyYXgOGkt+ Upgi4BS6XPkdbtYVlJRxbyzEZvuzOpA= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-404-vHrFYYKbNAOakWWihsOSQg-1; Thu, 03 Sep 2020 08:29:20 -0400 X-MC-Unique: vHrFYYKbNAOakWWihsOSQg-1 Received: by mail-wr1-f71.google.com with SMTP id g6so1032041wrv.3 for ; Thu, 03 Sep 2020 05:29:20 -0700 (PDT) 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=NpnignYWyGxwS894GY8oMk/a6JEblSgZ3kZBOAlqf6A=; b=MuLIGhFiG8i0nPSkwSuBOov+NWYA/tCTAIbzjeBP5bhjJV+T2fZIQaAbEjpZ24IbSH p3BYLUxd16K6K83JiWpI6UjCVnmOXCHrF3aRH02TmojZ8HiGo8cnd4I1PDKNtwYYdMr7 MJ31DQQKzxmSyaLmMYEg6OMydHJ94y0e74eRNXXnHv9ULpBWEpzeb3SIhwd+C62r/l8+ 2XCFfKvo7GxuI/gUfMDhN6UQsBhXrTvRxQauXQe6o4mHIIx5Cy0PQBts0r6xy41Z/jDm xTxOcoGk8NcJKBkc8mp2seFJG9x9fTuV4fsEMFaJVw2dypC1BBaxsFqpbg9mbmgguVcy ik1Q== X-Gm-Message-State: AOAM533et1khJu9JWhvqSy9ualbwNl7xWfF0/9lBB0qxlMr+q9UjXRky 4jjyQwf8IscOYt5VILYois8wbwhDB2jjo1SqogEdAagVan24hCmNqSZvN/d6MN/D3gbiWrTJOu+ hNVc6e0HlnL5EUZg= X-Received: by 2002:adf:dfc3:: with SMTP id q3mr2143358wrn.238.1599136159152; Thu, 03 Sep 2020 05:29:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR9VEDlF2c2hXScIfRFO6BMVLUh++Phr1HzLZP45Ib7PyZQGziMgfXkk+UlgLLkTuTZ0hqUg== X-Received: by 2002:adf:dfc3:: with SMTP id q3mr2143341wrn.238.1599136158915; Thu, 03 Sep 2020 05:29:18 -0700 (PDT) Received: from localhost.localdomain (50.red-83-52-54.dynamicip.rima-tde.net. [83.52.54.50]) by smtp.gmail.com with ESMTPSA id f6sm5522520wme.32.2020.09.03.05.29.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:29:18 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH v7 15/15] block/nvme: Use an array of EventNotifier Date: Thu, 3 Sep 2020 14:28:03 +0200 Message-Id: <20200903122803.405265-16-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 Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/03 01:58:20 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Stefan Hajnoczi , Keith Busch , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Stefano Garzarella Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" In preparation of using multiple IRQ (thus multiple eventfds) make BDRVNVMeState::irq_notifier an array (for now of a single element, the admin queue notifier). Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e3719d3bd14..24e6e7f0866 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -106,6 +106,12 @@ QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) != 0x1000); #define INDEX_ADMIN 0 #define INDEX_IO(n) (1 + n) +/* This driver shares a single MSIX IRQ for the admin and I/O queues */ +enum { + MSIX_SHARED_IRQ_IDX = 0, + MSIX_IRQ_COUNT = 1 +}; + struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; @@ -120,7 +126,7 @@ struct BDRVNVMeState { /* How many uint32_t elements does each doorbell entry take. */ size_t doorbell_scale; bool write_cache_supported; - EventNotifier irq_notifier; + EventNotifier irq_notifier[MSIX_IRQ_COUNT]; uint64_t nsze; /* Namespace size reported by identify command */ int nsid; /* The namespace id to read/write data. */ @@ -631,7 +637,8 @@ static bool nvme_poll_queues(BDRVNVMeState *s) static void nvme_handle_event(EventNotifier *n) { - BDRVNVMeState *s = container_of(n, BDRVNVMeState, irq_notifier); + BDRVNVMeState *s = container_of(n, BDRVNVMeState, + irq_notifier[MSIX_SHARED_IRQ_IDX]); trace_nvme_handle_event(s); event_notifier_test_and_clear(n); @@ -683,7 +690,8 @@ out_error: static bool nvme_poll_cb(void *opaque) { EventNotifier *e = opaque; - BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier); + BDRVNVMeState *s = container_of(e, BDRVNVMeState, + irq_notifier[MSIX_SHARED_IRQ_IDX]); trace_nvme_poll_cb(s); return nvme_poll_queues(s); @@ -705,7 +713,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, s->device = g_strdup(device); s->nsid = namespace; s->aio_context = bdrv_get_aio_context(bs); - ret = event_notifier_init(&s->irq_notifier, 0); + ret = event_notifier_init(&s->irq_notifier[MSIX_SHARED_IRQ_IDX], 0); if (ret) { error_setg(errp, "Failed to init event notifier"); return ret; @@ -784,12 +792,13 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } } - ret = qemu_vfio_pci_init_irq(s->vfio, &s->irq_notifier, + ret = qemu_vfio_pci_init_irq(s->vfio, s->irq_notifier, VFIO_PCI_MSIX_IRQ_INDEX, errp); if (ret) { goto out; } - aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, + aio_set_event_notifier(bdrv_get_aio_context(bs), + &s->irq_notifier[MSIX_SHARED_IRQ_IDX], false, nvme_handle_event, nvme_poll_cb); nvme_identify(bs, namespace, &local_err); @@ -872,9 +881,10 @@ static void nvme_close(BlockDriverState *bs) nvme_free_queue_pair(s->queues[i]); } g_free(s->queues); - aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, + aio_set_event_notifier(bdrv_get_aio_context(bs), + &s->irq_notifier[MSIX_SHARED_IRQ_IDX], false, NULL, NULL); - event_notifier_cleanup(&s->irq_notifier); + event_notifier_cleanup(&s->irq_notifier[MSIX_SHARED_IRQ_IDX]); qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE); qemu_vfio_close(s->vfio); @@ -1381,7 +1391,8 @@ static void nvme_detach_aio_context(BlockDriverState *bs) q->completion_bh = NULL; } - aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, + aio_set_event_notifier(bdrv_get_aio_context(bs), + &s->irq_notifier[MSIX_SHARED_IRQ_IDX], false, NULL, NULL); } @@ -1391,7 +1402,7 @@ static void nvme_attach_aio_context(BlockDriverState *bs, BDRVNVMeState *s = bs->opaque; s->aio_context = new_context; - aio_set_event_notifier(new_context, &s->irq_notifier, + aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_IDX], false, nvme_handle_event, nvme_poll_cb); for (int i = 0; i < s->nr_queues; i++) {