From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1599136093; cv=none; d=zohomail.com; s=zohoarc; b=Nb/SzS2R/s/hCSwKOs43BhFzuSrr9tgujAFVXutQn7mQMKl5jz5nAPYrDOEsts4SVqIBqHAa6Xg2vRcrbf3NaV1LE1qi0EgJm0RNy1UaE9N+tJba80MoiZBp+9DKsT54dvzNftAm+zHi0LFABVn2c+L90EpuPiejyM0FWSufkaQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136093; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=UbGtgnVOqvqBbChkwfkGif/qNdiRkoX+i++pJMa/DR4=; b=ng5CJgenqSDYKvejgLxICREddhGzD4xIe+HFgbc1xGL52N4rgKG3vBglegoN+jV7ZhLx+y4R9te23YHY7a15uyxsX9vlp9ud73MqiN0dj7hdqerYFP5gehz/cCm1r/zYMaooRg0fVq6tQ0i5h6Mu9tTpfp8zVT2i3voeXhMa2hY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599136093912326.7652851595375; Thu, 3 Sep 2020 05:28:13 -0700 (PDT) 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-106-j6VaanjtNlSjA6YFmrMoRw-1; Thu, 03 Sep 2020 08:28:11 -0400 Received: by mail-wr1-f72.google.com with SMTP id m7so1007994wrb.20 for ; Thu, 03 Sep 2020 05:28:11 -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 l21sm4112872wmj.25.2020.09.03.05.28.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136093; 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=UbGtgnVOqvqBbChkwfkGif/qNdiRkoX+i++pJMa/DR4=; b=ecazPpGyQZtVLbEJTTjXPKxk4HWQVeGH+3FDCtr60v0wtzLzkymMwk0as/scWQ8+pbnO+J MjNAO54HpI6VKWx5UAQXE3Mw2IJ8yY6pCDkyp+4a5SGWThWjTr2AM194qU/ip1uorW53GS ygaLmE+yg78dHxVd4KprMsRqHYiK5Vs= X-MC-Unique: j6VaanjtNlSjA6YFmrMoRw-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=UbGtgnVOqvqBbChkwfkGif/qNdiRkoX+i++pJMa/DR4=; b=naEr0r2II4XCYJpCvecsxz+qZw5CrtOasbeAxJSfMfQLKxr9RSJ8QtMvsQPWahqc/j ZPpiLte8meFrC3SZBEK4s5yGiS5xlDWyFik49Rbq1r/azoPcca17HE7phC9muA+us/Kq lZtUHTZ337MSC+GgHHlK8aJDmfA1nbdBZ6UDlE3akKMp+YZcnHhkAZfKVgpwPIjMbfT9 DnkuNVxA9QozCmxUNH5ejmnQC2riacBmguV31JHLoyycBAKX9rbDT/ZDux9hYLZjY5gt 0KNegyst1MAiJBbeawdTtp5KtFqY6VDTcb/hq7+EXJmtzAuD/HJSp7EgwW6Di5AUCmvG EQ2w== X-Gm-Message-State: AOAM530Aauccu5TcIoGghGbZiPLN3qK4YfNa6hNTiLrpVAq+8N7au6Y+ mD1AaYmL0AzUKHcuAO2IejNeT+UJXo04i8kyTUD+vUoDMdZNFpYvsJITSP+jTETmE2t0sPHsvKq PsiQ07aiA65UR3w== X-Received: by 2002:adf:ec0a:: with SMTP id x10mr2132448wrn.47.1599136090375; Thu, 03 Sep 2020 05:28:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmAljjZHGAQ3AKo5HHF65v5jXYKT3hQud4OSbkqsAy81mlP2ECJDa0ubrTbZ4mQU+X85Obrg== X-Received: by 2002:adf:ec0a:: with SMTP id x10mr2132430wrn.47.1599136090222; Thu, 03 Sep 2020 05:28:10 -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 01/15] block/nvme: Replace magic value by SCALE_MS definition Date: Thu, 3 Sep 2020 14:27:49 +0200 Message-Id: <20200903122803.405265-2-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) Use self-explicit SCALE_MS definition instead of magic value. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 05485fdd118..a2b006be56d 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -715,7 +715,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, /* Reset device to get a clean state. */ s->regs->cc =3D cpu_to_le32(le32_to_cpu(s->regs->cc) & 0xFE); /* Wait for CSTS.RDY =3D 0. */ - deadline =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * 100= 0000ULL; + deadline =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCA= LE_MS; while (le32_to_cpu(s->regs->csts) & 0x1) { if (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) > deadline) { error_setg(errp, "Timeout while waiting for device to reset (%" --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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=1599136101; cv=none; d=zohomail.com; s=zohoarc; b=A9Y2xHO4s0sXihBWCvYqI8boMISg6kpijtRmWvextOL2J8FLk+pRazVjv/KQXRTbDAuLTTIOQegPAIVICIFSm4Z59ITTagWL0eQTUe+hyg3cyWgZQ0Ofvfdckuw6KVY66cXpGR5cJXbKXPUZ2NWBqXBFJ9VWJyAaTx2CRImu9tY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136101; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=+7z5+e7/E61U4fRcXXvYvhWwXvlJc3olBRQ++jvakag=; b=lTd2H6EALMZRkrKywAVPToUgdp593ITXg81P2z2HyVUK1STkRGZhOcGBl7jbkIYU85kQhunk4FCOLAsjpQeIXLhw4yrKjSuxlxTO3weePhbSrgFBJDFLLn4epVc2ZBLcdR6HZB1/oVmNCKFzhB/E5X9w1wM2QlrH0VUFLmFjPdg= 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 1599136101156931.116202682753; Thu, 3 Sep 2020 05:28:21 -0700 (PDT) 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-519-LqYnEBlsOFOUnFA1FdTpHg-1; Thu, 03 Sep 2020 08:28:16 -0400 Received: by mail-wm1-f70.google.com with SMTP id b14so913726wmj.3 for ; Thu, 03 Sep 2020 05:28:16 -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 m3sm4197434wmb.26.2020.09.03.05.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136100; 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=+7z5+e7/E61U4fRcXXvYvhWwXvlJc3olBRQ++jvakag=; b=N6xflfsVlsylmUGcobUuTzS4S/umCkg/cwFAfbKcqu+HnHW1/kgxCnl7yAi1tQZiDj4YA3 /mtntxhRXNjGIH3gxtprrIWeO00ALx0w7OXe3z+h/gDWaScc5Aq920ztRgaSUwF7Q8Ip/s eTIsQ/Lv9vuafYsz1KNHvOpaKhFfa98= X-MC-Unique: LqYnEBlsOFOUnFA1FdTpHg-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=+7z5+e7/E61U4fRcXXvYvhWwXvlJc3olBRQ++jvakag=; b=CrMxraHMvezUnpWWZhZf/2UOQHyrdPaDQtu4HDLBJLfwnjXNBGvL+sYaXddgT1Cvu1 Umop2eAsC4HDAaAEpXVnEdfz4ZEt3NySudTHJ8jVIU4kXSkn9Tuwaxjy+yR3JqY7LZtv MH6NjAtXbeR5/3Ww8bqBloVcvk4SNPR+2hIJws44nwBCQkWIFmlgvbOMbGPDYBHddTAX b1K+raOHFc7RG90KDCIMmjQWyAC9WC462rWhZqsm6fAdgj8Q7H7eHH8Ka+jOpgufxT/o zCDpEIFb5E8Y4e+MwdpMzLhRsVIcdDL6k12p42j3l47KlkU/KOIy7i6KQmnzIweGYUD7 j1hA== X-Gm-Message-State: AOAM531Enugd4xjZBruAusC8rxuOegzIo1lOgiMQTI69gra16pBSFad/ rhs0TPdSiS8cNkDqsBSFnkS7w9UUTChjJVZ/KZ9H4KNcwGoSleaKecS7rTSqqe3HBZoGbwKQWS4 U93f7W+uNWI8AFA== X-Received: by 2002:adf:f149:: with SMTP id y9mr2151721wro.93.1599136095284; Thu, 03 Sep 2020 05:28:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz5KnYvmOYgjIWd+xJOB2ZjZt26hiMyyQIshol0yYlICSgCfoxw8TF+P0sC9PbkNh66W8hmZw== X-Received: by 2002:adf:f149:: with SMTP id y9mr2151709wro.93.1599136095092; Thu, 03 Sep 2020 05:28:15 -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 Subject: [PATCH v7 02/15] block/nvme: Avoid further processing if trace event not enabled Date: Thu, 3 Sep 2020 14:27:50 +0200 Message-Id: <20200903122803.405265-3-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) Avoid further processing if TRACE_NVME_SUBMIT_COMMAND_RAW is not enabled. This is an untested intend of performance optimization. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index a2b006be56d..4d4f728159f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -441,6 +441,9 @@ static void nvme_trace_command(const NvmeCmd *cmd) { int i; =20 + if (!trace_event_get_state_backends(TRACE_NVME_SUBMIT_COMMAND_RAW)) { + return; + } for (i =3D 0; i < 8; ++i) { uint8_t *cmdp =3D (uint8_t *)cmd + i * 8; trace_nvme_submit_command_raw(cmdp[0], cmdp[1], cmdp[2], cmdp[3], --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1599136108; cv=none; d=zohomail.com; s=zohoarc; b=IpwNRvxJFE6XZdjRrxmO5cy92TK8XNYSHSDUPg3LL3YUPJNM3kLhD8gtOIJk4EGVkVI9L7tRij7S3HF4OQIEAISem2CCAfga/UVGsxEEJTj1KTuPTC4C02EMl/b0pRILyC1VE3oCIRRCTQdjMYjnRu+PMJya2jy+1XgmQgDvHms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136108; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=EBREVqe86w/qV8xj/jHdOJ+D9gTNwJHNOwqeZKQd6RY=; b=HiJIAvc8KYRw9C+4MKKcfunru1Fa/JHPHqryGkFMblkSQ0q6YTx8opCMmispz/7oScFgFs8WkIaiKdEWH08/Y3Yw5YOALbrCREZP8td4yubZeJU/0M8eAA3F3ObkLMQuiRuCPiM6JigpmTTwrMbUX5Kpeu71xNBk2F35RX7/hEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599136108457910.3382877234483; Thu, 3 Sep 2020 05:28:28 -0700 (PDT) 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-132-3rW6a5-mMdqW24qVkIwVeQ-1; Thu, 03 Sep 2020 08:28:26 -0400 Received: by mail-wr1-f72.google.com with SMTP id v12so1024492wrm.9 for ; Thu, 03 Sep 2020 05:28:26 -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 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136107; 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=GXyRWn+IFC5SWCcgC3FjtbSsT+ZALiCJLE0g9fFz3/hP81iIDdA/nHxGrJc8Ty+JfRnMKg 7FPYApK5vlUvx8i+eK+tEflteSi1KYxBF9dQgixC8E/05IEd4OJ0x+5+Spng6q8WB3Ai6C ggqMKZ9bxqb+Xa29Cj4mJzeJOmFvjGA= X-MC-Unique: 3rW6a5-mMdqW24qVkIwVeQ-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=EBREVqe86w/qV8xj/jHdOJ+D9gTNwJHNOwqeZKQd6RY=; b=Tb9S0y75WsxNsX4e1AFzQYIQ0nihozW9tj1QfVhWM3styVf+fedBdi/jcAWZa2dqUq mfV1Js2Ob0ox4cj0sb7GmSL/FtOGSez72z6zuvMJnBVLDbVREMc4ZLAWTfER8eo3s0Qi nYoznDRV/tHCFIfeDtUfy+ef/VBBFsZYQ0th6JQq5n59+3QOlTVQOU3yplYUIoYlGCrp DL5YsHzpgf7y9I55+dn2DL7ymJyZ6ZrvNGtCv0Qaob2PGT5aXOmHAqMichv3yEVu3PzY EBunfPbIUL4axgxOFf2JORMrAF3Zx8R7S46T/VPq97g1Yi/u21o9B461ObJXLHIA5Ust mLBA== X-Gm-Message-State: AOAM533faoe614ovEcZHJL8v7oEbzJc8zfJJJMHg7f+OvMBybMli/3x8 yOr9EvOiNvQ0MBb7NuoNjjfGYO+PBijJZRnXrKe4zpsIRF5t0cYaABlEWAjKgqwYq2b2K6Dx/rQ EQsWjyAUDQLM0Yg== X-Received: by 2002:adf:f149:: with SMTP id y9mr2152341wro.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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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 { =20 QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) !=3D 0x1000); =20 +#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 nam= espace, Error **errp) } cmd.dptr.prp1 =3D cpu_to_le64(iova); =20 - 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 nam= espace, Error **errp) =20 cmd.cdw10 =3D 0; cmd.nsid =3D 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, Err= or **errp) .cdw10 =3D cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 =3D 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, Err= or **errp) .cdw10 =3D cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 =3D 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, =20 /* Set up admin queue. */ s->queues =3D g_new(NVMeQueuePair *, 1); - s->queues[0] =3D nvme_create_queue_pair(bs, 0, NVME_QUEUE_SIZE, errp); - if (!s->queues[0]) { + s->queues[INDEX_ADMIN] =3D nvme_create_queue_pair(bs, 0, + NVME_QUEUE_SIZE, + errp); + if (!s->queues[INDEX_ADMIN]) { ret =3D -EINVAL; goto out; } s->nr_queues =3D 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); s->regs->aqa =3D cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE= ); - s->regs->asq =3D cpu_to_le64(s->queues[0]->sq.iova); - s->regs->acq =3D cpu_to_le64(s->queues[0]->cq.iova); + s->regs->asq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->sq.iova); + s->regs->acq =3D cpu_to_le64(s->queues[INDEX_ADMIN]->cq.iova); =20 /* After setting up all control registers we can enable device now. */ s->regs->cc =3D cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | @@ -839,7 +844,7 @@ static int nvme_enable_disable_write_cache(BlockDriverS= tate *bs, bool enable, .cdw11 =3D cpu_to_le32(enable ? 0x01 : 0x00), }; =20 - ret =3D nvme_cmd_sync(bs, s->queues[0], &cmd); + ret =3D 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(BlockDriv= erState *bs, { int r; BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; =20 uint32_t cdw12 =3D (((bytes >> s->blkshift) - 1) & 0xFFFF) | @@ -1171,7 +1176,7 @@ static coroutine_fn int nvme_co_pwritev(BlockDriverSt= ate *bs, static coroutine_fn int nvme_co_flush(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; NvmeCmd cmd =3D { .opcode =3D NVME_CMD_FLUSH, @@ -1202,7 +1207,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDr= iverState *bs, BdrvRequestFlags flags) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D s->queues[INDEX_IO(0)]; NVMeRequest *req; =20 uint32_t cdw12 =3D ((bytes >> s->blkshift) - 1) & 0xFFFF; @@ -1255,7 +1260,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, int bytes) { BDRVNVMeState *s =3D bs->opaque; - NVMeQueuePair *ioq =3D s->queues[1]; + NVMeQueuePair *ioq =3D 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 =3D bs->opaque; assert(s->plugged); s->plugged =3D false; - for (i =3D 1; i < s->nr_queues; i++) { + for (i =3D INDEX_IO(0); i < s->nr_queues; i++) { NVMeQueuePair *q =3D s->queues[i]; qemu_mutex_lock(&q->lock); nvme_kick(q); --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1599136113; cv=none; d=zohomail.com; s=zohoarc; b=UkIHFm90y+WaM3ef0E2vk5WhfV3wBrMUMPeeddBeXYXdrbg8B4v210M9y2IwLXHN8hNnbAEcyifm25JWKfISYoFSjpPfT9NSuqT+OUOV1q5CmEaVIArtAwv4DA/r70+lag5BcvUX9oww0kCuTqVgNldTdbnClIB4AX5YRp6r0G0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136113; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=HgXwbQUt5qjogYM8iFoeW+GHqjN8VyRP3jjf5JuoDPA=; b=LlpJYlqw/1o2ghKS3J7kvZ9y69Iaq5eEL55lROEbwwcXKLFsnQu2wNFRQvTKDTnA6BRNXMdqUK045+PYgwac/Ox52DPT/S0nPFS3SOQiUyCIyAWXNfIqGVDr8zeOo7Rmt/3o+sBX6DSZuBnxJqZb9ML5HRmlTS9AylEvnUVdvWg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599136112999886.9625833852932; Thu, 3 Sep 2020 05:28:32 -0700 (PDT) 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-571-XjKVKWhAPPu3AP0KuFZPIA-1; Thu, 03 Sep 2020 08:28:30 -0400 Received: by mail-wr1-f69.google.com with SMTP id y3so1009750wrl.21 for ; Thu, 03 Sep 2020 05:28:30 -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 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) 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= X-MC-Unique: XjKVKWhAPPu3AP0KuFZPIA-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=HgXwbQUt5qjogYM8iFoeW+GHqjN8VyRP3jjf5JuoDPA=; b=NR0x5dhlk8q2lNYyzE6lKYUHCjU+/RuKkZRZiVPB78HGYSn1sx53PVzWPJtO47HWJD ihrvVUFJwD4vICVUBhs7zHbj1FRdQ/BPJB20RboGXpn+6NAzVwkMw4Esu+Vrec/568cC bxLhWaN57Km7ECUI/me4erFA5zM3Ce2s2sZ0d7rZd/AK6vTmTWJ3rGiG/ux1AdAGqR9F phywBm2wiMKus6ZVleVhASKxqa3ZS4zCPY5B2X7IK0FVIUIaOfXGggUFx6PHK2ZBGaBM P7LDYbAJXJm/mqNb/vvsH2aH+qkV9S37OF7tehxFLiuglmHBs560P5Lhu0UpvMRQTMRd 7Duw== X-Gm-Message-State: AOAM532dVoxNz3w2F6F+51SZaLVZfpoZh+QVOpChTWluzNhirDF2Gz1t Fbysftfjn/VpGdueeCwxW5q/XxDIUz3qWcGepdOaMr7h1WKdormDkFruJ4FbTlKeb11jOJQhhy4 clegFaqY1Vt0r1g== X-Received: by 2002:a05:600c:2f8f:: with SMTP id t15mr2339266wmn.41.1599136109719; 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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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, Err= or **errp) .cdw11 =3D 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, Err= or **errp) .cdw11 =3D 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; } --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 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=1599136118; cv=none; d=zohomail.com; s=zohoarc; b=T/v97S+UTvC6HBxN3WDgYYB4FGe730gdk/9MUDfzJ9aNpfyxi5dFy/DGcspbDZc+bGjNSWlZ3i3E2j+ZUSS5Z3AJGYAjQfT+XxDoOgZru+clbMbbL3IGNICo/oV8lNKo65ujOayq44sV1CzrSFmXGsNrsWRhshytxl/f/ZKj7lc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136118; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=TpInLQtjibVwG+zHArB9u5D41zSFCvAlrqN3dTWS+aM=; b=LjHm+8ktCXQOTivlTGYLM2xTXDySoQtFM5Tj7b9/lpfQsq2RV2E/5k6fIFnOy3YH6v9xLkG+Y1OMMDLD9Pmmy9yWItdQ7bhGW1jTYqUuCLajSFpe5k8EOie9nxhBWyQuwesTX5Ki2PPDWmIir0lQYiCRhLFlrZNqJY8XBto+vko= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1599136117998999.0557417071028; Thu, 3 Sep 2020 05:28:37 -0700 (PDT) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-120-vB4VqMjNObu4-N11GHEQ1g-1; Thu, 03 Sep 2020 08:28:35 -0400 Received: by mail-wm1-f71.google.com with SMTP id m25so933091wmi.0 for ; Thu, 03 Sep 2020 05:28:35 -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 y207sm4495098wmc.17.2020.09.03.05.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136117; 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=TpInLQtjibVwG+zHArB9u5D41zSFCvAlrqN3dTWS+aM=; b=IFUUr7611XcwQORD9cLpiLrR0GqqBhaRWRiv3ZpML8zvkfbq5iy1RwG1ryqNM/pvViIOkj s4lbO5LeJU0/O4B/r0tBUcnMROGo2gS8NPimUgtcD66TNCpiclIDBYQ1cU9G0qrGwwJkOn 48p0kD2mO/gML6k1MSyAhUMFHv8HhFc= X-MC-Unique: vB4VqMjNObu4-N11GHEQ1g-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=TpInLQtjibVwG+zHArB9u5D41zSFCvAlrqN3dTWS+aM=; b=nxOvHZDCuSBv1dR+OqH/J91fwc24gAoTr8/EWQ+fxFnIlrL/K4HuGl6whdnluw734n hsADlCCesO7KCak+GZf15KOFqb/gaasEEnaSRPaMnw8PMnLvbJI9IMOLj9IOyFxWTGiD IVrcD4+DQv5/fhgWne9WvNhON/1BDOJGp5ct456IFLTlZL8eWoDR8pwGf87sBoxLUjZK GP9jULqNOvkWyxn7MhkC4xAYvtSB8EerPPCOJG+0KGGGGmNrlWHsG9NtnbhypvzaJMHV 9DE/XZDKp+K66AGCW9hdibjrwY9pMzFXn3T1xsrtmYjH+zZV9iTTz94WF+83zxYGyHmB i1cQ== X-Gm-Message-State: AOAM530tSlbP6otGumSskx3ySH04GivbD+YIZsn6J2nIh7bfQVEzdg54 5wvl/aKtcIrRQLeTn5mKBY2hWwBWqKGfRrnIs8IJiKb/ACtNqZk+dETA/E1o7mC2/1dKDU1gndy 6GUXAeqMzGdQZWQ== X-Received: by 2002:a5d:6852:: with SMTP id o18mr2196684wrw.113.1599136114512; Thu, 03 Sep 2020 05:28:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8CmIhwAQ9b93PJpqyYHFIs49vhIFH4Ne2ggMTM6P2hhq/nbFCE1VZQ5IjKH/daarphlDDJg== X-Received: by 2002:a5d:6852:: with SMTP id o18mr2196671wrw.113.1599136114366; Thu, 03 Sep 2020 05:28:34 -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 06/15] block/nvme: Use common error path in nvme_add_io_queue() Date: Thu, 3 Sep 2020 14:27:54 +0200 Message-Id: <20200903122803.405265-7-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) Rearrange nvme_add_io_queue() by using a common error path. This will be proven useful in few commits where we add IRQ notification to the IO queues. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 91dba4ec5db..909a565184d 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -649,8 +649,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create CQ io queue [%d]", n); - nvme_free_queue_pair(q); - return false; + goto out_error; } cmd =3D (NvmeCmd) { .opcode =3D NVME_ADM_CMD_CREATE_SQ, @@ -660,13 +659,15 @@ static bool nvme_add_io_queue(BlockDriverState *bs, E= rror **errp) }; if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create SQ io queue [%d]", n); - nvme_free_queue_pair(q); - return false; + goto out_error; } s->queues =3D g_renew(NVMeQueuePair *, s->queues, n + 1); s->queues[n] =3D q; s->nr_queues++; return true; +out_error: + nvme_free_queue_pair(q); + return false; } =20 static bool nvme_poll_cb(void *opaque) --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1599136123; cv=none; d=zohomail.com; s=zohoarc; b=Gfs4ZTjezZi2+eBMttd655GGAz7fNzeSCaWKbM5w6Rjqh4N28zl3fFXnyts65yKcS/p3mGdVgaXG2UjCRigiOd3tK5C0Vgvrs/soMfriZDqrOX6rpe/TFKiD9Fa3/saEO+mYBFvzMs2XaMA5rP+iWr/ot4vpD8eyLVEzdN/J94w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136123; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=exUO2EBEU4GpUyorzocM/dFFi//P9vU8D1aRpXB50hw=; b=nzMHjht/sQVG9kq6OttiWxYUyCd8XPDldL4GSYv1Ro6DqdlUjrQz9RA/yozoYil0wlFFgzeYPZwIQjHiCM1GiQ6hQAu2tlaUXF2BC1j3QKIHWDe1PsGFOdi5r298CqmfCrL3RFMrdp+1zcqMi3nPyaVZ2GXHm3eeYchjL++gp1w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1599136123255322.3703994174209; Thu, 3 Sep 2020 05:28:43 -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-165-0cnzp9rdPlqFC8f43XV21A-1; Thu, 03 Sep 2020 08:28:40 -0400 Received: by mail-wm1-f69.google.com with SMTP id q7so905741wmc.6 for ; Thu, 03 Sep 2020 05:28:40 -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 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) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136122; 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=A77gfYy54TAvt27wHGnSTWfxFbcJIRbpTsFzhg+KHMk7AkhtOUnZrhoDHUupG1VNTEGveI UEjqZ3Vq1eiAH/oU4WMyW0Il0MYeDv+yGHcF0dg7guh9rz0pGb18TWxUKd4R5i1GVSO5kD MYpaj7F0QmgdMq2SE0NIWlwskHqCTKc= X-MC-Unique: 0cnzp9rdPlqFC8f43XV21A-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=exUO2EBEU4GpUyorzocM/dFFi//P9vU8D1aRpXB50hw=; b=PQjJQ6D9NLs/3dhYQEbBIeE4Hh1ik4ONjvWoRgDeyIje32OEBd2SrAi3zeXK4nOXZW BmK0kGYCRu15a/JB1+oZpjWNdADgwnPoBU7hXZ0xXXzEmbqzQGODo/Iv/tzvo4oVZr7h BZTt1FoWrHj7l97jdpuhYNNXtkFGROMBtkcIM7f33cJHEYUZRQgea5fjv9hYxhiNb6ve 2KMWelZcJITO3+P0N7KTb3szjuaLzkX6UYLpihkVfqBycanP8QLLxoHQXgsKcyQ/sV9Y 3RECb36IloGvA5fKb3Ijgmb35b7BQCSuG+O/+uiJEg4e1RgeFj0Ry/0PKkcDSO+Xxdng xsag== X-Gm-Message-State: AOAM531oGfnltTrNJNfzKCelhbcCqqUkQ7VSfzY5sazhLDg5LGDtDkgA UdvNTK7C2cYCHbhDHnw2dnnW1n3pNAtOriDI3S/nEXxe50bbJZ2dkaJ1mvPuFzmo4kPQJ+vRbq0 qC3wMs/36791ETQ== X-Received: by 2002:a5d:4151:: with SMTP id c17mr2372105wrq.302.1599136119610; 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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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 nam= espace, Error **errp) BDRVNVMeState *s =3D 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 n= amespace, Error **errp) .cdw10 =3D cpu_to_le32(0x1), }; =20 - resp =3D qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); - if (!resp) { + id =3D qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl =3D (NvmeIdCtrl *)resp; - idns =3D (NvmeIdNs *)resp; - r =3D qemu_vfio_dma_map(s->vfio, resp, sizeof(NvmeIdCtrl), true, &iova= ); + idctrl =3D (NvmeIdCtrl *)id; + idns =3D (NvmeIdNs *)id; + r =3D 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 nam= espace, Error **errp) s->supports_write_zeroes =3D !!(oncs & NVME_ONCS_WRITE_ZEROES); s->supports_discard =3D !!(oncs & NVME_ONCS_DSM); =20 - memset(resp, 0, 4096); - + memset(id, 0, 4096); cmd.cdw10 =3D 0; cmd.nsid =3D 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 nam= espace, Error **errp) =20 s->blkshift =3D lbaf->ds; out: - qemu_vfio_dma_unmap(s->vfio, resp); - qemu_vfree(resp); + qemu_vfio_dma_unmap(s->vfio, id); + qemu_vfree(id); } =20 static bool nvme_poll_queues(BDRVNVMeState *s) --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1599136127; cv=none; d=zohomail.com; s=zohoarc; b=bj/x/1PCDQtKSnBnIaDmJ1A6uuADhy/8qBZS7PIbOYMTh6qcXP9a1miJc7rR2RtWDT4Nd5BhY1l7NTr+btVdoqz5uurzvWve0dqopxdlYOA10u6I9AnuHs3ymQGygcASQn/+LriIFX8MBf/qqiJHedb7Yln2ZFx7D+2mAlFjrmQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136127; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=aOcjV7su5QwStC1VAK815NSfg5qEBVvoHtC3IGwZAQM=; b=H38fRyV6i40+9GXep1tPyST3aOEj8r7qwAkDwFsTJJIQT0tjZJmigNsgIB+/ntcRyHBmMWIosxY7Dc9KE8riW4WfAT+453sGLW2ofJI9Hzqlga5Dq5Gr/ZtInkQkGT+dbuw/ZSFCOwsqzdu1u0tGpqaDsH4dDCThoUc1p25Jql4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= 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 1599136127964990.5486896033248; Thu, 3 Sep 2020 05:28:47 -0700 (PDT) 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-255-Ro-ZUWYwOGKkb67WjuB38w-1; Thu, 03 Sep 2020 08:28:45 -0400 Received: by mail-wm1-f72.google.com with SMTP id a7so928337wmc.2 for ; Thu, 03 Sep 2020 05:28:45 -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 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) 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= X-MC-Unique: Ro-ZUWYwOGKkb67WjuB38w-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=aOcjV7su5QwStC1VAK815NSfg5qEBVvoHtC3IGwZAQM=; b=CbqNaNVy9GbwBruoLw8qrGOG7Ig+vVaJn5f1AF2+WdpOofvZHQIq2gJkOmF9Cin0zz Pea9PVuNqZ0wQ1IrFebze9WNz+sQBQq3lVK42SHxeVp7dJajUJVZxDIetp7kL7UR03mX zn9VvCE3oAJeVoOEKBXcqzAkjTTgV/wJs6r4euat2aDD5huoNEigJKJFo9qhgU04JBND Swx+UAQvfXlteaAZgqwNwlIS6Y7B1Ly6BcLYOjjIVMEFdDZiz/pLzTyoAMYpsA0giXoO qxOJVuNVDTEG8CmPeCsVwlb9FtpMtW0p83C3Uo3fU4JC7LLU1/IilipIrIOA+ah7Uv6A wg9w== X-Gm-Message-State: AOAM531EtDFRqMKk4FpGjo+gCyPehwMKF4yfpV6Aa3Ytwf27DgzTiYOP XN08xrANvSv0xpItl98ZcFg5qkefoccrW+6ktj8PEjxVE3KhJswseE1lO9sPxDEjZz+MdBACpUk mTmrFrXaiXA0v/g== X-Received: by 2002:a5d:574c:: with SMTP id q12mr2194100wrw.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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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, NVMeQue= uePair *q, static void nvme_identify(BlockDriverState *bs, int namespace, Error **err= p) { BDRVNVMeState *s =3D 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 n= amespace, Error **errp) .cdw10 =3D cpu_to_le32(0x1), }; =20 - id =3D qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + id =3D qemu_try_blockalign0(bs, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl =3D (NvmeIdCtrl *)id; - idns =3D (NvmeIdNs *)id; - r =3D qemu_vfio_dma_map(s->vfio, id, sizeof(NvmeIdCtrl), true, &iova); + r =3D 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 n= amespace, Error **errp) goto out; } =20 - 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 =3D le32_to_cpu(idctrl->vwc) & 0x1; - s->max_transfer =3D (idctrl->mdts ? 1 << idctrl->mdts : 0) * s->page_s= ize; + s->write_cache_supported =3D le32_to_cpu(id->ctrl.vwc) & 0x1; + s->max_transfer =3D (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 mo= st * s->page_size / sizeof(uint64_t) entries. */ s->max_transfer =3D MIN_NON_ZERO(s->max_transfer, s->page_size / sizeof(uint64_t) * s->page_size); =20 - oncs =3D le16_to_cpu(idctrl->oncs); + oncs =3D le16_to_cpu(id->ctrl.oncs); s->supports_write_zeroes =3D !!(oncs & NVME_ONCS_WRITE_ZEROES); s->supports_discard =3D !!(oncs & NVME_ONCS_DSM); =20 - memset(id, 0, 4096); + memset(id, 0, sizeof(*id)); cmd.cdw10 =3D 0; cmd.nsid =3D 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 n= amespace, Error **errp) goto out; } =20 - s->nsze =3D le64_to_cpu(idns->nsze); - lbaf =3D &idns->lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)]; + s->nsze =3D le64_to_cpu(id->ns.nsze); + lbaf =3D &id->ns.lbaf[NVME_ID_NS_FLBAS_INDEX(id->ns.flbas)]; =20 - if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(idns->dlfeat) && - NVME_ID_NS_DLFEAT_READ_BEHAVIOR(idns->dlfeat) =3D=3D + if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(id->ns.dlfeat) && + NVME_ID_NS_DLFEAT_READ_BEHAVIOR(id->ns.dlfeat) =3D=3D NVME_ID_NS_DLFEAT_READ_BEHAVIOR_ZEROES) { bs->supported_write_flags |=3D BDRV_REQ_MAY_UNMAP; } --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1599136135; cv=none; d=zohomail.com; s=zohoarc; b=iQsJdqO70ZhQAODIFr2nbln7CWZlxJxAKFHPpquOxRAdIwYqcOXWxBBT3a3iH35fppwVpEU+CF/dANj/ElnONEJqE9ST59Yhw44HIqt8aOA5vboccPHEPiAaIcl5LWE8DBpfCs+Ww6ZYt+G4j/pLOG6TNcIjaUrIbE3mX6+TSoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136135; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BCC5Fw+MiUlqW0HMIIfQxzi+31vZOBfq2qQvazw+mlU=; b=kxJeHYS431huI1wkA0au9xDV5hlUVshJixFvL1AzYhVkAMLT8IwClCgGTSHifv9Bp2PPARAA4G19/ATU8nODEzEcJPf2Wg8rSw937chZAsWZyhTdbTKa3AO4V6eOyAJNptO5E9MgVK9eza9QYfp/eF1fbhAqp+xiMT0BQfhitXU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 159913613500299.84834237209054; Thu, 3 Sep 2020 05:28:55 -0700 (PDT) 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-476-Pj6TAq46PW-i6n6wGTFOtQ-1; Thu, 03 Sep 2020 08:28:50 -0400 Received: by mail-wr1-f72.google.com with SMTP id s8so1013589wrb.15 for ; Thu, 03 Sep 2020 05:28:50 -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 q186sm4451819wma.45.2020.09.03.05.28.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136134; 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=BCC5Fw+MiUlqW0HMIIfQxzi+31vZOBfq2qQvazw+mlU=; b=WErzbKIpiRpnU+RDz/PmXYMBJiZNhPruj6uvjWT67mD6IyW6tJIR5vC+7ftRIIYcj33xxv gt86EG/Og/SndbcjTfJ21YNvgHK+v2OzH3y6uqJ6Iy9OE2/Mwu/hGDlWtZrdaewJ68YYTj MVaItuiD9JAQO4y7tO57wFqgL0ddO5U= X-MC-Unique: Pj6TAq46PW-i6n6wGTFOtQ-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=BCC5Fw+MiUlqW0HMIIfQxzi+31vZOBfq2qQvazw+mlU=; b=OcwMmfMtORC5cbL0v+NytDwDKF9EPnSkDcbXxTVv75KnHNuCa62oqTOzqjGr8fdzAm /h9ONbHneIVYph71J6a8zPq2l0RbexXJozMXRPXnF30WrYm4duC6u7DmktICa0XaYIol pUYi0VLBZ6SpVJlu3opIz4+DFa/tCddboecBK7rral5j+ztX7k7lkwfhvufqyPEs0/fb byRrDZ1irXzV6kNBUEOrHu/60cmjOFys9lZ0FE+7IUA2jqF9/6CGvaYjRFsOEgeGRMyk wAolZUjwWFBiiXSs3UBacEiz4IljO5L3i2QBRyPq5WCIsNAGEpxu3B1QtdaWNt2zuCAe Kx6Q== X-Gm-Message-State: AOAM530PMzJXs0fK3TYNNlxMqqXKj1KAkIpz4OEuTckfOWlnolpMdmGp wbLRdhWotRmqWe33yH8S+9MZtRkWpI2XdYK/XokUtxCwiy0d8CX/2B1a5FcNVELwM4HMkVcPrie RI0GYlaiYwHA7iQ== X-Received: by 2002:adf:f984:: with SMTP id f4mr2244784wrr.102.1599136129567; Thu, 03 Sep 2020 05:28:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSQ+MU+mHMCK0Ymds2uyXemBfkA9hatSDOQRDvUt5dpj6d430q2JtIhNwlBnkXhCDWfzcZxQ== X-Received: by 2002:adf:f984:: with SMTP id f4mr2244772wrr.102.1599136129408; Thu, 03 Sep 2020 05:28:49 -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 09/15] block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset Date: Thu, 3 Sep 2020 14:27:57 +0200 Message-Id: <20200903122803.405265-10-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) In the next commit we'll get rid of qemu_try_blockalign(). To ease review, first replace qemu_try_blockalign0() by explicit calls to qemu_try_blockalign() and memset(). Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index b0d55ecfb25..60e39b69a23 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -174,12 +174,12 @@ static void nvme_init_queue(BlockDriverState *bs, NVM= eQueue *q, =20 bytes =3D ROUND_UP(nentries * entry_bytes, s->page_size); q->head =3D q->tail =3D 0; - q->queue =3D qemu_try_blockalign0(bs, bytes); - + q->queue =3D qemu_try_blockalign(bs, bytes); if (!q->queue) { error_setg(errp, "Cannot allocate queue"); return; } + memset(q->queue, 0, bytes); r =3D qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova); if (r) { error_setg(errp, "Cannot map queue"); @@ -223,11 +223,12 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDri= verState *bs, if (!q) { return NULL; } - q->prp_list_pages =3D qemu_try_blockalign0(bs, + q->prp_list_pages =3D qemu_try_blockalign(bs, s->page_size * NVME_NUM_REQS); if (!q->prp_list_pages) { goto fail; } + memset(q->prp_list_pages, 0, s->page_size * NVME_NUM_REQS); qemu_mutex_init(&q->lock); q->s =3D s; q->index =3D idx; @@ -521,7 +522,7 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) .cdw10 =3D cpu_to_le32(0x1), }; =20 - id =3D qemu_try_blockalign0(bs, sizeof(*id)); + id =3D qemu_try_blockalign(bs, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; @@ -531,8 +532,9 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) error_setg(errp, "Cannot map buffer for DMA"); goto out; } - cmd.dptr.prp1 =3D cpu_to_le64(iova); =20 + memset(id, 0, sizeof(*id)); + cmd.dptr.prp1 =3D cpu_to_le64(iova); if (nvme_cmd_sync(bs, s->queues[INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify controller"); goto out; @@ -1283,11 +1285,11 @@ static int coroutine_fn nvme_co_pdiscard(BlockDrive= rState *bs, =20 assert(s->nr_queues > 1); =20 - buf =3D qemu_try_blockalign0(bs, s->page_size); + buf =3D qemu_try_blockalign(bs, s->page_size); if (!buf) { return -ENOMEM; } - + memset(buf, 0, s->page_size); buf->nlb =3D cpu_to_le32(bytes >> s->blkshift); buf->slba =3D cpu_to_le64(offset >> s->blkshift); buf->cattr =3D 0; --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1599136140; cv=none; d=zohomail.com; s=zohoarc; b=bCFbncdLMgAvq8r5CClezoVp8IC66qrkv3G6luTId1XxtyotcZzzWrJLEqzm+CdPuUgFNtQI74VRb2wiT8Ki6fS1YOyT0Li2IPLzBCnxdcf+yw6t6O/s2omjLaOl0MPYQhHRfFgQ26RUofgh6lhzTmJow2HebQ+3hNdeAwnXnJE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136140; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=BnPRrVeAnWqBsNzNwsX+5XPQmBcv+SY5NaSBhpbVhLQ=; b=Y7vgd0iTo0hTMBIwL4DzWjH/qB23+dFSrqyktKseSySYblt6p3n1dYibqcuAsAttD2ZdUDRSBpDgifR6y1VHvX0SKUJsryZBcb3ulDqenwbQEbPSb1+Yo0Bre/7oEI+HG5XLI23d4iUJAsGV4Uf67w2Kdas8aEVjV7CcayNRNjg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599136140024584.0506146432336; Thu, 3 Sep 2020 05:29:00 -0700 (PDT) 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-388-WDsfFZUJNu2HLkGx9qY91g-1; Thu, 03 Sep 2020 08:28:55 -0400 Received: by mail-wr1-f72.google.com with SMTP id o6so905126wrp.1 for ; Thu, 03 Sep 2020 05:28:55 -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 c205sm4141814wmd.33.2020.09.03.05.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136139; 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=BnPRrVeAnWqBsNzNwsX+5XPQmBcv+SY5NaSBhpbVhLQ=; b=dX6KyRiUjM1FEBWVAwSw5q/NrcKhOfyql7vDn0vQ/07cFhdj6p810qqzIqnFdcrEdN4cbT Y9BFS3diF0QFwI+OAziwP68MGSEWI0w6MkWq2BIY1QPndZUKCUt1vVermHSR6w5ff12UXF gXhoQOV6wWNcCttFq6ZTjwtxuZx3pNM= X-MC-Unique: WDsfFZUJNu2HLkGx9qY91g-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=BnPRrVeAnWqBsNzNwsX+5XPQmBcv+SY5NaSBhpbVhLQ=; b=h/vIDZnWujXneo1fPeQ6ej7t2fPYx+L4NiLmqK87RL81xskNXpkpDAJRRCc8cTcMTR jO8TKTE5mCcm4iLFVtcjtejS53xE9bNNwfrQgP2Mx2kqedCOrDi7S17Y4tZ7joktPw/Z ctEgE1DSQ5qXEjS84a65Midub+ncmrHFPvxvNG7clw805MA5ky3nDr/xCsBZyX78rrSO BPp7C0vuPeGRhe1fVevg4gzm5FIYpr0TTEv70b2cL4XikFodn/PPRM/J/uiU11oguh54 ZNaIwPidbj1EO17vcvuoj6gLjs0yFQ3tPal8WPmeHU7pUfPq1hMcEGzwAs51YVBNK7AL th7Q== X-Gm-Message-State: AOAM531fxX9gKdHCkKl3T+GuuCkk6BGUMIfYjpdjaAU9CznAv6/Xsj/h 6sq+MoJueVavbmkskmh1GB5Z5bHejfADRekz6yNM6c/+QBBRSG27v85AlICDgwxe/Qu6Nt05LUP P/mAyvaeiTt2XFg== X-Received: by 2002:a05:600c:4104:: with SMTP id j4mr2216238wmi.36.1599136134374; Thu, 03 Sep 2020 05:28:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1P3xKCkdotZ0ihxXbFO5u+kzSZKJ7KrT0DsSjzP8T2WwFaB08L3C0krZVqlKTXYKNziB4Ig== X-Received: by 2002:a05:600c:4104:: with SMTP id j4mr2216219wmi.36.1599136134193; Thu, 03 Sep 2020 05:28:54 -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 10/15] block/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz) Date: Thu, 3 Sep 2020 14:27:58 +0200 Message-Id: <20200903122803.405265-11-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.003 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) qemu_try_blockalign() is a generic API that call back to the block driver to return its page alignment. As we call from within the very same driver, we already know to page alignment stored in our state. Remove indirections and use the value from BDRVNVMeState. This change is required to later remove the BlockDriverState argument, to make nvme_init_queue() per hardware, and not per block driver. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 60e39b69a23..0c8ad1d60b6 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -174,7 +174,7 @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQ= ueue *q, =20 bytes =3D ROUND_UP(nentries * entry_bytes, s->page_size); q->head =3D q->tail =3D 0; - q->queue =3D qemu_try_blockalign(bs, bytes); + q->queue =3D qemu_try_memalign(s->page_size, bytes); if (!q->queue) { error_setg(errp, "Cannot allocate queue"); return; @@ -223,7 +223,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDrive= rState *bs, if (!q) { return NULL; } - q->prp_list_pages =3D qemu_try_blockalign(bs, + q->prp_list_pages =3D qemu_try_memalign(s->page_size, s->page_size * NVME_NUM_REQS); if (!q->prp_list_pages) { goto fail; @@ -522,7 +522,7 @@ static void nvme_identify(BlockDriverState *bs, int nam= espace, Error **errp) .cdw10 =3D cpu_to_le32(0x1), }; =20 - id =3D qemu_try_blockalign(bs, sizeof(*id)); + id =3D qemu_try_memalign(s->page_size, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; @@ -1141,7 +1141,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t= offset, uint64_t bytes, return nvme_co_prw_aligned(bs, offset, bytes, qiov, is_write, flag= s); } trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); - buf =3D qemu_try_blockalign(bs, bytes); + buf =3D qemu_try_memalign(s->page_size, bytes); =20 if (!buf) { return -ENOMEM; @@ -1285,7 +1285,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverS= tate *bs, =20 assert(s->nr_queues > 1); =20 - buf =3D qemu_try_blockalign(bs, s->page_size); + buf =3D qemu_try_memalign(s->page_size, s->page_size); if (!buf) { return -ENOMEM; } --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1599136145; cv=none; d=zohomail.com; s=zohoarc; b=LbLjRXUuGM8oO3wrv9t5ypIarJsPHZCGHsXIHBAYJ2O8oA9XvAvS+rGLe03QfA+TmaqM3JWZD2W/h3k/dcIoVo2S/wlrkgwjiyaOncwEr3FoGUdY/9r/HLt2LEN3EtoXw9DRh6QXFT2dLwDGYzRaix0mA3H7ed0Ct36a150/4no= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136145; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=UCjqLrpq3STI/zR0Jd2dpzbux+828cWdkCvReZKkRjw=; b=MLMLEvwlamqmKFJ14pLfVV5fPlBfQ74BGWhTCvM09LQLKk6YMHTnKXcdSPKLVZNlD0AbkFv39PfWx1o2UwbF4z/1y5UVG2iNQ8/QnWAz3Ul5XDHdNbg2unWo5R0KSJpJBWe4Urzly2l5+R8xmgx2l/GQj2g+enASsW44OVKVsDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= 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 1599136145389485.1188829063026; Thu, 3 Sep 2020 05:29:05 -0700 (PDT) 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-87-Qm1G3sNSNiG-Zursm4XIxA-1; Thu, 03 Sep 2020 08:29:00 -0400 Received: by mail-wr1-f72.google.com with SMTP id k11so1015624wrw.16 for ; Thu, 03 Sep 2020 05:29:00 -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 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) 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= X-MC-Unique: Qm1G3sNSNiG-Zursm4XIxA-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=UCjqLrpq3STI/zR0Jd2dpzbux+828cWdkCvReZKkRjw=; b=HtCZOH8GkbWEdphyfzQivawANhRrE/9YtrO5rTXttxD1WbRcLYud1JsHMLVdi4iwq+ ttUcLp16Z7YhwC++HQHCGie/mTbajynJ8777stZbXA/syVDW7EpziHrOD6vAqk1Jh4rX UPqzLgt+Ry1GJfrSHiYAXrSEk1OW1egGbwmiHLVz0v9nZW2kboTNYJhGjwkyTlxEqSzd JrqLJmq4Dg4zbOpPJM1kpPdyE07hM8Bf+pOElwEfKpnUXVkP8jOoHgHwe7EgDUmx061M UNzUvesYJIFFknp1i9ztOCN206uWf3Dw0e8yv47AjLtvC908KEek98yD2fPC/+rt/N7C uPBQ== X-Gm-Message-State: AOAM530QqHiYFXkGS4R/UNmifAr46ITeenrNvtB0SIHGF1Sajiw69yTC V7hxZg1gZ9sJH1ANc5l5zez8KdN8zPFTQ9N/NWKQu4STrCnjRZtId3r22ZnkfQVTx5MdTuz/a7S VFVNm68y95CL8bg== X-Received: by 2002:a05:600c:210c:: with SMTP id u12mr2405995wml.185.1599136139208; 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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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 =3D { }, }; =20 -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 =3D bs->opaque; size_t bytes; int r; =20 @@ -251,14 +250,14 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDri= verState *bs, req->prp_list_iova =3D prp_list_iova + i * s->page_size; } =20 - 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 =3D &s->regs->doorbells[idx * 2 * s->doorbell_scale]; =20 - 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; --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1599136148; cv=none; d=zohomail.com; s=zohoarc; b=UAIv6zqXePIaLFZyZkj21/2+KAh1PWO1DFqNALDM4HNq5pBdBMaxnr53Aa5+jGeh353g2m7kYtah19t0mlSKG/xQursEp24eFFBrmvUYeW5nZDr30UobU7E+AThzGmm2bzh8q4Kz3zRAYeEq+MxG52j/j72DXSWfQ9relZ1Ruf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136148; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=bI0r63FdmYwhNblRvmKN2aGqhdP0Y0JOEVbpUaFc+z8=; b=DB+4gXAJmSsHdZ0wwF58jsaE8Xj4NsC+XyFDqXPrSWQo/43Sot2OzX4/oRhzBcq68DwbQIpAueTU20jdtB0QZrQmU9qrcsBmS78MzkhD0bvQDvhWruwNrS69IE8yk+dGkt96lSk43oGMdH6qTDjsb7R3o2VWYmudbCxC/16kz0I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1599136148382824.3228555212339; Thu, 3 Sep 2020 05:29:08 -0700 (PDT) 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-454-wtbXeHswMH-chjVUrhPVzA-1; Thu, 03 Sep 2020 08:29:06 -0400 Received: by mail-wr1-f71.google.com with SMTP id b7so1027446wrn.6 for ; Thu, 03 Sep 2020 05:29:05 -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 g143sm3894220wme.0.2020.09.03.05.29.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:29:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136147; 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=bI0r63FdmYwhNblRvmKN2aGqhdP0Y0JOEVbpUaFc+z8=; b=WSzz1+0NNmFNYh42lWpc14h2tiAPow7HOYbQJIyq29SB4tx8pkkv32ln0AXy1xc4Z2c+9s LXe/vQcrdAMnzA84VIgJgLJJiEtb8/G5kEse/mSk0hUg4Yu+fmC9qZZ5QP48OPejJ9bMH/ FD59J5uDGOSqLrqa/0wwvK6NHRwsTrg= X-MC-Unique: wtbXeHswMH-chjVUrhPVzA-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=bI0r63FdmYwhNblRvmKN2aGqhdP0Y0JOEVbpUaFc+z8=; b=tJ0epaem0qCtefT9vpZ0OIVikpoxhKRA6SdiTS4GHRicnln1t+DTe0Vl8wjUcVuSBk 2We1FnIBZnEfzfTWw+gwCSgOgIMkoQnjiRQtiYSESFobUxWThgYsHwUnG00nGqzuoEkj NWpLtIqMGyDj8ePHnl1VDbQd/QFAdi4USijNBO++8iPyh2Sa4wqn6EYHyBqRuyVYd7RE iBKJjI0OXfjIYyhBUCD7l+eTl68ypdIq3vuC8CTRiRSNvWl9a5KZtZFzMKNGHtoKfDas EuvbGE8xOr0MK3T2QHzGZWvRuD2kAzAktW4s9Vf01ncqPIu3CUBOryQrvY047H4mHQE2 9FzQ== X-Gm-Message-State: AOAM530k9fzrEspTbMn2YFuVoqGwIrvzorMjTCNG0HTnJwYasbNJxDWV kFgbaNT20xhtanuXYeBXbVQ1H8ET1l898PxYa9NKArqD7e2g4N0Kdhl30qu6r1j9stv54cun287 M8lhvU0M3niUPeg== X-Received: by 2002:adf:db8b:: with SMTP id u11mr2324782wri.143.1599136144278; Thu, 03 Sep 2020 05:29:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3bP8rcDPxsSDvpTH3+9l4mfbHBSy4lu4/3lw6Lgqy/8W+o/PZz+GYuTalcxE+st4zRRuQdw== X-Received: by 2002:adf:db8b:: with SMTP id u11mr2324752wri.143.1599136144061; Thu, 03 Sep 2020 05:29:04 -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 12/15] block/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE Date: Thu, 3 Sep 2020 14:28:00 +0200 Message-Id: <20200903122803.405265-13-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) BDRV_POLL_WHILE() is defined as: #define BDRV_POLL_WHILE(bs, cond) ({ \ BlockDriverState *bs_ =3D (bs); \ AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) As we will remove the BlockDriverState use in the next commit, start by using the exploded version of BDRV_POLL_WHILE(). Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index e04e1fa4f8f..b03735129d3 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -493,6 +493,7 @@ static void nvme_cmd_sync_cb(void *opaque, int ret) static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, NvmeCmd *cmd) { + AioContext *aio_context =3D bdrv_get_aio_context(bs); NVMeRequest *req; int ret =3D -EINPROGRESS; req =3D nvme_get_free_req(q); @@ -501,7 +502,7 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueu= ePair *q, } nvme_submit_command(q, req, cmd, nvme_cmd_sync_cb, &ret); =20 - BDRV_POLL_WHILE(bs, ret =3D=3D -EINPROGRESS); + AIO_WAIT_WHILE(aio_context, ret =3D=3D -EINPROGRESS); return ret; } =20 --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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 205.139.110.61 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=1599136152; cv=none; d=zohomail.com; s=zohoarc; b=CTlAY22ncGeuLSVCRf6Cq0VCWkbp2b2AM57hC2bunpXd2RGWR+DqqTcIfRxmz5kSSTqisBnjD1XUeuX/jJbBO5x4RdTAbgTiKjT4/pKuzzePf+f7tAKNNuy/lPZKBR6bT9MpOPxYhB250eGjOkWCQUHPd+ooOjvxK2jnthH9vEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136152; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=x5/xQskK0Ke2FAX64uYiLcx+1Sf83WT/CYfOUHG+VA0=; b=GvOo0/qRzpS3s4+O+1x489Fv6j5JHnGA7NAEUiyrMptK/pifwdX1hsYYtO75uVPlWYH5EnfvETy6kk7XGguBitq8hsSyDaSJc5MtUQ1SagAavFg0wTl6AgAvHsWuyKMAd43KaEKyDsFtLHk5nBpOhlVH2Plsv8vCOUMWCNnaaug= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1599136152521969.7711744857386; Thu, 3 Sep 2020 05:29:12 -0700 (PDT) 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-362-IhrEWrR0OA25wpHumsdrig-1; Thu, 03 Sep 2020 08:29:10 -0400 Received: by mail-wr1-f70.google.com with SMTP id m7so1009121wrb.20 for ; Thu, 03 Sep 2020 05:29:10 -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 f17sm4442865wru.13.2020.09.03.05.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136151; 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=x5/xQskK0Ke2FAX64uYiLcx+1Sf83WT/CYfOUHG+VA0=; b=ItSOUFUpyVZDtg+PuPZTdcCU/nbuuqp92CddQpK31/jWLgH3zVOox0BwKNuOCVn33W8Y+y Zpw/L7WHQVPmHwpsTiPtw0Z5PUFMDTpkRCuQuwU0YeRimmvJiUnjAk3he4LZn/Yys/ML93 8LPCFxuCLHcyGWA+gd/NF9UcaR0aJW4= X-MC-Unique: IhrEWrR0OA25wpHumsdrig-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=x5/xQskK0Ke2FAX64uYiLcx+1Sf83WT/CYfOUHG+VA0=; b=raroQVwPDLUrJHBR9VkR1+MD0G67D6QTyZ/rj1xrSPXjCTjhMs4fwucg4VOlQC5v1x XP8gnOOyhDXq/kiRzqsN5wq2Im4rVCH0oMzlg+S7t534N52F7DS3dvkYqb26ZbhfV8al u8h6lOTKvbUKMKVRuTaxJ+GCceRaF6eAsBuxtszYFQPzH55m9A6po0d6xMWdgd7E1lVU begwdWZQwlRmughWghuv67cDcD5nwPjTVnbas8R2peHnbTgwDdGHkYtqLP70+BGZ1XgS YLyCoFC1RYKY8S/KA7CHODfkcIuXfYVB8eJtjQHKXKHK1LxXF4+1d6pDGyfvGiAXzqWT gHCQ== X-Gm-Message-State: AOAM531im3EPiK4PVqdGmdz5eigUjtAyAbRtKv9ISbPUZrqiSwD9R3xb VdrpI73IFCJeINoslRXy5TBM4r4ckZEM0wFsp7j8mQLW9SEgvYuRv4dNFYnvvBnNLbEXJWvkXF7 /jiRq68OP39my0w== X-Received: by 2002:a7b:c84a:: with SMTP id c10mr2227570wml.139.1599136149185; Thu, 03 Sep 2020 05:29:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5NMKKDbITg75Dhbnj9Yb4GEJg7u7c/HGsjaFHbKZce9YPq+wSot8h//t4GqgNxa6X9ZnlFQ== X-Received: by 2002:a7b:c84a:: with SMTP id c10mr2227549wml.139.1599136149031; Thu, 03 Sep 2020 05:29:09 -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 13/15] block/nvme: Simplify nvme_create_queue_pair() arguments Date: Thu, 3 Sep 2020 14:28:01 +0200 Message-Id: <20200903122803.405265-14-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) nvme_create_queue_pair() doesn't require BlockDriverState anymore. Replace it by BDRVNVMeState and AioContext to simplify. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index b03735129d3..914a3c4ab31 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -208,12 +208,12 @@ static void nvme_free_req_queue_cb(void *opaque) qemu_mutex_unlock(&q->lock); } =20 -static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, +static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, + AioContext *aio_context, int idx, int size, Error **errp) { int i, r; - BDRVNVMeState *s =3D bs->opaque; Error *local_err =3D NULL; NVMeQueuePair *q; uint64_t prp_list_iova; @@ -232,8 +232,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDrive= rState *bs, q->s =3D s; q->index =3D idx; qemu_co_queue_init(&q->free_req_queue); - q->completion_bh =3D aio_bh_new(bdrv_get_aio_context(bs), - nvme_process_completion_bh, q); + q->completion_bh =3D aio_bh_new(aio_context, nvme_process_completion_b= h, q); r =3D qemu_vfio_dma_map(s->vfio, q->prp_list_pages, s->page_size * NVME_NUM_REQS, false, &prp_list_iova); @@ -637,7 +636,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Err= or **errp) NvmeCmd cmd; int queue_size =3D NVME_QUEUE_SIZE; =20 - q =3D nvme_create_queue_pair(bs, n, queue_size, errp); + q =3D nvme_create_queue_pair(s, bdrv_get_aio_context(bs), + n, queue_size, errp); if (!q) { return false; } @@ -683,6 +683,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, Error **errp) { BDRVNVMeState *s =3D bs->opaque; + AioContext *aio_context =3D bdrv_get_aio_context(bs); int ret; uint64_t cap; uint64_t timeout_ms; @@ -743,7 +744,7 @@ static int nvme_init(BlockDriverState *bs, const char *= device, int namespace, =20 /* Set up admin queue. */ s->queues =3D g_new(NVMeQueuePair *, 1); - s->queues[INDEX_ADMIN] =3D nvme_create_queue_pair(bs, 0, + s->queues[INDEX_ADMIN] =3D nvme_create_queue_pair(s, aio_context, 0, NVME_QUEUE_SIZE, errp); if (!s->queues[INDEX_ADMIN]) { --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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=1599136157; cv=none; d=zohomail.com; s=zohoarc; b=VGJu1J4+1Sm6kMT6juTDr3nLJRuj9CRu6kDleEQs2KhGAkLBzOikoxf9WthA7eKdyY1JeiVvlSFPEXX8ZpDbEbYV7D62OpX4+7OS9p6J/dgE/2lT+rsym/iSQJvUJ6D8PV5nbgdA6h9XsbSnS5FGGDhSLIFmb3FV42DL7HOkz1Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136157; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=D/1bfeigNPBAr+CZsKwZjr8MJ2jC3u5ha14iMiW2Qnc=; b=j7hRIS5Ao6MK/WuedqMJ7IcLdg6qjn4C+nkmcLyzNkydvAjBhOXsJfS1BvkILG5rIrvCG0m9m+vx+y5axEDSS6a5wUNyXV8hiqdTJnvr43njthXF2fspxLearZCTI5neJmnKapLPGtUmgTZVfJw1+O7L0lXy+Iy3Sb0DKe8z3dk= 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-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1599136157882904.2238013107337; Thu, 3 Sep 2020 05:29:17 -0700 (PDT) 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-259-WsbZCKc5Msy1Z9umqcWWFw-1; Thu, 03 Sep 2020 08:29:15 -0400 Received: by mail-wm1-f72.google.com with SMTP id x6so918361wmb.6 for ; Thu, 03 Sep 2020 05:29:15 -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 o6sm2969158wrm.76.2020.09.03.05.29.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Sep 2020 05:29:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1599136157; 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=D/1bfeigNPBAr+CZsKwZjr8MJ2jC3u5ha14iMiW2Qnc=; b=DxpGBcXWsrVOtynwsKnJOm+AqE2gmrgslrN//II7gjmbk5kj/yiNbFFxD5mKU101l5EBRx /swcMREj4evgjFAzAfNRDazvoXxnDe1ORyFkuz8tEIlZrH/9h02xI04dJeQXjuj9YHYjXt Z3d52E9DfsKSqsS+DN2oLdNyojrUe2w= X-MC-Unique: WsbZCKc5Msy1Z9umqcWWFw-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=D/1bfeigNPBAr+CZsKwZjr8MJ2jC3u5ha14iMiW2Qnc=; b=As3Vh/jWYKW6HNr3kSNoltJ7GAKEelH4k+mmzw4s2YQh8BLM7H4bjceuXbggqz56/c T2c2uZ6tNhunoWDitn9DrDsfkGeTNDxVHq5hM4yrOUHofPSaDoqZk8XF6w14Xr3f4wt6 GimT8OfSksmPEjgEE7qW5yymaf/mkUaJVzUBCmHiMYIQPktIhP6fY9A7NpocbAFYFaTD CEyk7tYIRuP/hjJAUjloaha+T4Lx954gTVihX3+XEcLBKDRzp5aA9Ayfy+3DzpuxqP0Y Etom/WkCKT/PUssvIVjK8yXuQtGX1Hv7P5XLpv2yJWXYpPXxbJSNPzkl6rTVOya2qq3l 7GYg== X-Gm-Message-State: AOAM531DeAaDGwg9rPtfwsWGZDlURh0arfuzm3VLvdnXo7cgtKaEryLi BCoxVG8/KhGUJXcsC9jw7MC40umG3YEWNbbj9aTIUkQEXEx/xBWwEcjYqIbXhtmU0RiXeYCIyZt topHwqrGQBnBFgA== X-Received: by 2002:a5d:56cd:: with SMTP id m13mr2161732wrw.261.1599136154266; Thu, 03 Sep 2020 05:29:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTPgSinKaIRHqtaXlf7sopCZGc1ejfatwJo/w0wG4f1Xj7w3z5sSAL1AT7yvfuRQwI3YvN5Q== X-Received: by 2002:a5d:56cd:: with SMTP id m13mr2161703wrw.261.1599136154021; Thu, 03 Sep 2020 05:29:14 -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 14/15] block/nvme: Extract nvme_poll_queue() Date: Thu, 3 Sep 2020 14:28:02 +0200 Message-Id: <20200903122803.405265-15-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 we want to do per-queue polling, extract the nvme_poll_queue() method which operates on a single queue. Reviewed-by: Stefan Hajnoczi Reviewed-by: Stefano Garzarella Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- block/nvme.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 914a3c4ab31..e3719d3bd14 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -590,31 +590,41 @@ out: qemu_vfree(id); } =20 +static bool nvme_poll_queue(NVMeQueuePair *q) +{ + bool progress =3D false; + + const size_t cqe_offset =3D q->cq.head * NVME_CQ_ENTRY_BYTES; + NvmeCqe *cqe =3D (NvmeCqe *)&q->cq.queue[cqe_offset]; + + /* + * Do an early check for completions. q->lock isn't needed because + * nvme_process_completion() only runs in the event loop thread and + * cannot race with itself. + */ + if ((le16_to_cpu(cqe->status) & 0x1) =3D=3D q->cq_phase) { + return false; + } + + qemu_mutex_lock(&q->lock); + while (nvme_process_completion(q)) { + /* Keep polling */ + progress =3D true; + } + qemu_mutex_unlock(&q->lock); + + return progress; +} + static bool nvme_poll_queues(BDRVNVMeState *s) { bool progress =3D false; int i; =20 for (i =3D 0; i < s->nr_queues; i++) { - NVMeQueuePair *q =3D s->queues[i]; - const size_t cqe_offset =3D q->cq.head * NVME_CQ_ENTRY_BYTES; - NvmeCqe *cqe =3D (NvmeCqe *)&q->cq.queue[cqe_offset]; - - /* - * Do an early check for completions. q->lock isn't needed because - * nvme_process_completion() only runs in the event loop thread and - * cannot race with itself. - */ - if ((le16_to_cpu(cqe->status) & 0x1) =3D=3D q->cq_phase) { - continue; - } - - qemu_mutex_lock(&q->lock); - while (nvme_process_completion(q)) { - /* Keep polling */ + if (nvme_poll_queue(s->queues[i])) { progress =3D true; } - qemu_mutex_unlock(&q->lock); } return progress; } --=20 2.26.2 From nobody Fri May 10 13:50:32 2024 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=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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=1599136163; cv=none; d=zohomail.com; s=zohoarc; b=mvldujYtOqoRKgT8ReA/goeAIsVucpMjbVmvldOJ4bboKQC7ZYxOvafTrBbKOpxzoRhi6P/A63ONOukbNz4AEo1J+qB6uPdNJkFpH6A+iKmz8YVnHBSXu8f6B0ZOHtKT9DCdFjdSWiKOFPMxDpY131oKTtYUB9ZLFBMFxEfHRrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1599136163; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=NpnignYWyGxwS894GY8oMk/a6JEblSgZ3kZBOAlqf6A=; b=Mw4fvzS/f32vLHuaGvXJWFAwc98uMbR7AbrcbbftGtx0x5r8N80t/4WLXByxLAvoci6Br16I5sOfZJpHqzdE5IYPDTVzkonreRWIgvnYMXLD+UcPdfU6Cwf6VTWcuMBPw6pzoZGvzc74SCVXaIcWlPaihnox+kgKPP2mzvYDKhw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= 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 1599136162486353.57572734608334; Thu, 3 Sep 2020 05:29:22 -0700 (PDT) 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-541-RjP3tR66MqiEEl8cUw34Bw-1; Thu, 03 Sep 2020 08:29:20 -0400 Received: by mail-wr1-f69.google.com with SMTP id y3so1010681wrl.21 for ; Thu, 03 Sep 2020 05:29:20 -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 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) 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= X-MC-Unique: RjP3tR66MqiEEl8cUw34Bw-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=NpnignYWyGxwS894GY8oMk/a6JEblSgZ3kZBOAlqf6A=; b=QZTOVQ97/nqE0Z155GbIVDW3baqOnuDHYT8BFb5aLaBBQSZi7Oeb/HaeW15qP4qAwK r/Jj6KGXefl2ctzHnjHKipjhEMzWTZpue2Fsc+uBoDXZrUA40t5fXrsMvp0xCxDaeDWR 1pf+430Eeo1tyu3i08r+VH1zo0cib1YZItrKevcgihPxIhaFcZ0ifWOJ/SFuS2wHYYk3 d3K/LXe22VTEolDcCmB+NU0WE4X2UQSQPVVpyF24Bb6R9Du0qtuYAZ2zXdz6oLJdOkZl qL5M+4eNDx0b1fWu9eFjPpCoFgSJ0M0xTwu0G6ann3lMOo4MyZK8Eczy74GwxmAuY3w9 /Buw== X-Gm-Message-State: AOAM533u3IXfjljYVkqzWUQswBs4oXo8FYHyKzTPODwEipI+H8Rj8a4g fT2/yWZRQKwMQ8p1IpDqkJdtwTMLtQRk10sCfF9sIGtsNVf+DgDeSeb+8lnhsa33xOkPvcbxsZB yho9+LJ96g/OkRA== X-Received: by 2002:adf:dfc3:: with SMTP id q3mr2143363wrn.238.1599136159153; 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) 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 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 Content-Type: text/plain; charset="utf-8"; text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) 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=C3=A9 --- 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) !=3D 0= x1000); #define INDEX_ADMIN 0 #define INDEX_IO(n) (1 + n) =20 +/* This driver shares a single MSIX IRQ for the admin and I/O queues */ +enum { + MSIX_SHARED_IRQ_IDX =3D 0, + MSIX_IRQ_COUNT =3D 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]; =20 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) =20 static void nvme_handle_event(EventNotifier *n) { - BDRVNVMeState *s =3D container_of(n, BDRVNVMeState, irq_notifier); + BDRVNVMeState *s =3D container_of(n, BDRVNVMeState, + irq_notifier[MSIX_SHARED_IRQ_IDX]); =20 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 =3D opaque; - BDRVNVMeState *s =3D container_of(e, BDRVNVMeState, irq_notifier); + BDRVNVMeState *s =3D container_of(e, BDRVNVMeState, + irq_notifier[MSIX_SHARED_IRQ_IDX]); =20 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 =3D g_strdup(device); s->nsid =3D namespace; s->aio_context =3D bdrv_get_aio_context(bs); - ret =3D event_notifier_init(&s->irq_notifier, 0); + ret =3D 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, } } =20 - ret =3D qemu_vfio_pci_init_irq(s->vfio, &s->irq_notifier, + ret =3D 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); =20 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); =20 @@ -1381,7 +1391,8 @@ static void nvme_detach_aio_context(BlockDriverState = *bs) q->completion_bh =3D NULL; } =20 - 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); } =20 @@ -1391,7 +1402,7 @@ static void nvme_attach_aio_context(BlockDriverState = *bs, BDRVNVMeState *s =3D bs->opaque; =20 s->aio_context =3D new_context; - aio_set_event_notifier(new_context, &s->irq_notifier, + aio_set_event_notifier(new_context, &s->irq_notifier[MSIX_SHARED_IRQ_I= DX], false, nvme_handle_event, nvme_poll_cb); =20 for (int i =3D 0; i < s->nr_queues; i++) { --=20 2.26.2