From patchwork Tue Jun 30 19:13:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634617 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4776E13B4 for ; Tue, 30 Jun 2020 19:14:56 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CFE2206A1 for ; Tue, 30 Jun 2020 19:14:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ehMtRkpT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1CFE2206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLiY-0007wR-Pd for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:14:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhF-0005yF-7H for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:33 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21438 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhD-0005Vj-Oo for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544411; 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=oDXkElBCSL5Fje+j3PutyCwM6gIK6a01PpGIaTigzW4=; b=ehMtRkpT+yxnnQNe2BF5uLiESR7RM7pYYMwjBLiFNJ49DNuUEqbXoVcypZLR032lz5v2bD 0ztpqMKx80uLxOfjMmJxT+O6h8QM768V4b8LqxI/VlC4tmeHDxxOICKtX/63B4RVzRMdfx YkNnQXS76oBgtpgy547Ytvkx0S5QKfs= 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-217-f6_TNI6BPDeCH-0mQYI7wA-1; Tue, 30 Jun 2020 15:13:27 -0400 X-MC-Unique: f6_TNI6BPDeCH-0mQYI7wA-1 Received: by mail-wm1-f70.google.com with SMTP id q20so11579753wme.3 for ; Tue, 30 Jun 2020 12:13:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oDXkElBCSL5Fje+j3PutyCwM6gIK6a01PpGIaTigzW4=; b=SBNfuebIkC1irm3UTEOvWnVvl9RF3yvvaEO7jRBpliQKBJRDMp6fNfOafVbkTcKEeO 3h5czwDCovyK/a3TGR0KNWXSOnk8hNdUoZPq8+mJkRyNDnS+bd/V9gWygMNZIqhPCMIl rnPIXA4Niiwwl++o8ivRXFAw79oGxlSjeB4W0rgbC1f/6eKRY9gCA5RyClRQM3zXlvaL GIGPWVr+2pGwg/iQh6wZvCjQM+zVDMaAdzaT8Wwn0Otywy6YNip64isuP1Sc1M9dSoUc 4TSzx/qaRi7MYNz7h5Y63o/cxao6gX6VnytlmsugMOMzsOag2kvp1LzfxlTSxxWu7kET Pnxg== X-Gm-Message-State: AOAM531y2anAWzlhqRvzMmVhSe5v4mMOMr9nPV9AHTmsEO1UHhFP2kWV eDLQjm5RPJCXNGcBkDtvEfxGoOOlfN8pvEzC0MMt7cZpz5+1j+VhnChZbPVSqwkZ3jXY/5KigNY nKSEjc4rO039zPEc= X-Received: by 2002:a7b:c055:: with SMTP id u21mr22142438wmc.132.1593544405935; Tue, 30 Jun 2020 12:13:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjM85LW5DmxOv6Awt6/4b1jhrOzm3MXlEFAr2qP7AdnzrwJJ62ZtEn+gKE2mBtaPe1hxsz9g== X-Received: by 2002:a7b:c055:: with SMTP id u21mr22142408wmc.132.1593544405652; Tue, 30 Jun 2020 12:13:25 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id w17sm4989638wra.42.2020.06.30.12.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:25 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 01/12] block/nvme: Replace magic value by SCALE_MS definition Date: Tue, 30 Jun 2020 21:13:07 +0200 Message-Id: <20200630191318.30021-2-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 02:00:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Use self-explicit SCALE_MS definition instead of magic value. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index 374e268915..2f5e3c2adf 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 = cpu_to_le32(le32_to_cpu(s->regs->cc) & 0xFE); /* Wait for CSTS.RDY = 0. */ - deadline = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * 1000000ULL; + deadline = qemu_clock_get_ns(QEMU_CLOCK_REALTIME) + timeout_ms * SCALE_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 (%" From patchwork Tue Jun 30 19:13:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2EF3013B4 for ; Tue, 30 Jun 2020 19:14:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 058CD206A1 for ; Tue, 30 Jun 2020 19:14:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MUqWCk1f" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 058CD206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:48508 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLiW-0007px-76 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:14:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhL-000627-7N for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:39 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51970 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhG-0005W9-Bq for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544413; 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=sSpxL68KI0zjY+P0ZTv/agflMQHnncdM/JAB05rWw4M=; b=MUqWCk1fAyLdZ4ENaxkf+eA6qC71is5wdgHnB8QYlZB5gxj9r0EEglts62rZzXw6EWVvkw L37PObXtcrZN/E+rHkNp0V/ZszzX7h6l+anppx9eME3NTY/3HYNLkDWfxHpG1MrWZ9UF1s gU4E/bLKPy+1PxSzuDqwAtMAnB6mt50= 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-313-05q7PtuFPqapqQmFngKUMg-1; Tue, 30 Jun 2020 15:13:32 -0400 X-MC-Unique: 05q7PtuFPqapqQmFngKUMg-1 Received: by mail-wm1-f69.google.com with SMTP id v24so21394945wmh.3 for ; Tue, 30 Jun 2020 12:13:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sSpxL68KI0zjY+P0ZTv/agflMQHnncdM/JAB05rWw4M=; b=I4A7GyUboRGiJqRTK3XVrqLDNMaO32KJiByLmcROvHpK/ZtW8Vvyh/YpcNOmGgd8H9 86qAG/rBnVrEHnrPiGlv6UGF34tffdBbbhmUrtHd9KUQqSGhL7ed420r5r8AZ4nyNrUu bXM/7VtANPcYv/0g3ig25RxpLXNln0QtwUFtpAebEdQ/PpLO8draOqw253jASDIy3n5Y e0aZgd/WPb7skQmRHIEgTJtvMngCqu9DaYBacruA0Se7b1clRnacRZQKFf09F7zFwINq oWBDA/2S9nDpna7YXuoUDuzDopSKRzYi4L7YYkI6/uKo0uQqwZQwSXTrSGL7216nOrcG HoTg== X-Gm-Message-State: AOAM532pg1dUxhmIu1+ppBZW3Ett0BWtl4mI9mrQbI9TSN5yBIRWt4JY xzxn1UVaIZ3VfbCUe33p1+mqFA43f7vcTAlIqHvN7NBZ3doiejpF68qU2npAa2XtMPXjMNFO+Q5 DXumdegVqTI1GESU= X-Received: by 2002:a1c:2602:: with SMTP id m2mr23955274wmm.50.1593544410828; Tue, 30 Jun 2020 12:13:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLyipKg//WKrV8o5D+oPIV/Utzm3hTol8MMrTlA3AQVAJTLZ+Tx5dgMEDayArhX8VC+GGiLw== X-Received: by 2002:a1c:2602:: with SMTP id m2mr23955260wmm.50.1593544410661; Tue, 30 Jun 2020 12:13:30 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id c6sm4670385wma.15.2020.06.30.12.13.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:30 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 02/12] block/nvme: Avoid further processing if trace event not enabled Date: Tue, 30 Jun 2020 21:13:08 +0200 Message-Id: <20200630191318.30021-3-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.81; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 02:00:02 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Avoid further processing if TRACE_NVME_SUBMIT_COMMAND_RAW is not enabled. This is an untested intend of performance optimization. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/nvme.c b/block/nvme.c index 2f5e3c2adf..8c30a5fee2 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -441,6 +441,9 @@ static void nvme_trace_command(const NvmeCmd *cmd) { int i; + if (!trace_event_get_state_backends(TRACE_NVME_SUBMIT_COMMAND_RAW)) { + return; + } for (i = 0; i < 8; ++i) { uint8_t *cmdp = (uint8_t *)cmd + i * 8; trace_nvme_submit_command_raw(cmdp[0], cmdp[1], cmdp[2], cmdp[3], From patchwork Tue Jun 30 19:13:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634619 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11D1013BD for ; Tue, 30 Jun 2020 19:15:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB543206A1 for ; Tue, 30 Jun 2020 19:15:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="YR4YaC1a" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DB543206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53292 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLjR-0001ge-W9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:15:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhO-00068n-0x for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:42 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:51489 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhM-0005We-IQ for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544419; 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=KdE6JsIw8dAhfeVIz93JjPSKDmry/14DEkZ0JE7PkKI=; b=YR4YaC1aE5u9Bf8s2zFxIQRmhcZ2yLhuXhqA75u4bDRedToyGafGASEFS9XkvCKb7Iwlff 5rSJ7aOZWU55nU/UoeYvdgFrdJCBPvjm9oYi6R4kK/jzKCyIalT7qZOuDnKlmQ4XH5kntJ IZ9e4+dY9cy4OImfKqnSIPls4bCW8Xc= 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-362-dLk15A7RNcKnXnv2Qh9C4A-1; Tue, 30 Jun 2020 15:13:37 -0400 X-MC-Unique: dLk15A7RNcKnXnv2Qh9C4A-1 Received: by mail-wm1-f69.google.com with SMTP id f68so9848695wmf.1 for ; Tue, 30 Jun 2020 12:13:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KdE6JsIw8dAhfeVIz93JjPSKDmry/14DEkZ0JE7PkKI=; b=QSixNxp//kXSZugMz02iyBhMS/NJmZnMi/2Cj18o57yKJsywkxUd247Smoae9N7xYu GELcYdY1qjFBzqNT7chuGe8u3sWPwwlg2HumUBsIuZqQDcYhoUg06yck/5EW7a9vrxRn b17Idmp87DQcFXOfkittFbPzO9+PQ6LFqst33NNYlWMwUw4iGjbgB6dbLUKhNSm/a2sY EYf6iPu4dd2RM3OFuNsQxvCHFy7stQ1XTTyZPyxgrYzc7uEQK9rBVB8q0d75JNM7d6xk IxZZSL+h8Icql9EJcNLZnUVN9fb2w/EpOxfAdiTcEPr4Zj3PBV1P4ess3TFCqp6VySnB BA0w== X-Gm-Message-State: AOAM530LwmQPaYegNahmEXwRKIf8eppZWtzQ0gG7ARiwbv7C4lvSTQib MKgJ52Z/ZhUqX9+AYGy/cV43TTwqHxzLEjDzHoxQWLrfDTN2HJk6teosSWIr7A5DK+gh8plwd1z c1VST7ckzl50oYjI= X-Received: by 2002:adf:8168:: with SMTP id 95mr23392316wrm.104.1593544415496; Tue, 30 Jun 2020 12:13:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhGtkqbtq5kDafv1A2Eo+oeXUyQvOonJJ/uL4Ooy6GdcKDkFti91dhNzt9/l6aG6NaBC3gEQ== X-Received: by 2002:adf:8168:: with SMTP id 95mr23392299wrm.104.1593544415295; Tue, 30 Jun 2020 12:13:35 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id p29sm4524114wmi.43.2020.06.30.12.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:34 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 03/12] block/nvme: Let nvme_create_queue_pair() fail gracefully Date: Tue, 30 Jun 2020 21:13:09 +0200 Message-Id: <20200630191318.30021-4-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 03:55:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" As nvme_create_queue_pair() is allowed to fail, replace the alloc() calls by try_alloc() to avoid aborting QEMU. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 8c30a5fee2..e1893b4e79 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -213,14 +213,22 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, int i, r; BDRVNVMeState *s = bs->opaque; Error *local_err = NULL; - NVMeQueuePair *q = g_new0(NVMeQueuePair, 1); + NVMeQueuePair *q; uint64_t prp_list_iova; + q = g_try_new0(NVMeQueuePair, 1); + if (!q) { + return NULL; + } + q->prp_list_pages = qemu_try_blockalign0(bs, + s->page_size * NVME_QUEUE_SIZE); + if (!q->prp_list_pages) { + goto fail; + } qemu_mutex_init(&q->lock); q->s = s; q->index = idx; qemu_co_queue_init(&q->free_req_queue); - q->prp_list_pages = qemu_blockalign0(bs, s->page_size * NVME_NUM_REQS); q->completion_bh = aio_bh_new(bdrv_get_aio_context(bs), nvme_process_completion_bh, q); r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, From patchwork Tue Jun 30 19:13:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634623 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C6BFE13B4 for ; Tue, 30 Jun 2020 19:17:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9BCE0206A1 for ; Tue, 30 Jun 2020 19:17:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SzkC8cGN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9BCE0206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:58726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLl2-000443-CE for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:17:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhS-0006Jm-Dl for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:46 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:30644 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhQ-0005X3-Mb for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544423; 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=ljXJ2uXsj/Qn3r9/6qBf8Xo9qcaKqcWoVzmWGn+EjKs=; b=SzkC8cGNLws81IvaK1HN02pzTxeI1ZrVz0ZXq1dXdcWg50zUCYOizTOCEqh1rv0/tp83eR 7gjQfisHAMQHsDWJbn98V1sdRJWte6/H6axte4xq1dRcTsGPCdWk/BzFSTQ8pakNZ5BEhw omYmsFuIurXav6T0WlA5BdV2d9TuZ08= 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-118-DrC7Z-coM6K4f3TteWka2w-1; Tue, 30 Jun 2020 15:13:42 -0400 X-MC-Unique: DrC7Z-coM6K4f3TteWka2w-1 Received: by mail-wm1-f71.google.com with SMTP id o13so21340584wmh.9 for ; Tue, 30 Jun 2020 12:13:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ljXJ2uXsj/Qn3r9/6qBf8Xo9qcaKqcWoVzmWGn+EjKs=; b=lBO6OqioXeOQMPeEinBM7tavDvtOh0eegngTx6F1C5ACInz/tug+/GjfiDLfRJH4Vb kG9/yDw3tPvGgO01oRnWpv2UHA6Xae5gThPBA38qyOWZayfq4lKTpPO8hr3+Ei5muqj3 4zCZCA3GnZd1+dUpxtDpN0gdXEdpbfdtkj8Jj0mgfuPCYSTIFfxo+K96ox/p2xvZh5aT hWSi6GHzCJguIeQDzuN9Bg28uLtFSvLtuADYGTmqw9/WtEuXch7Lho/BN+p7Yw85YQ+I CnCYeq8DKHQZtudcqo4GIaaFoxgUrTb8aUj9DDjsJ+ZFhjj3uequL2NH1lcNv6E4XMAa Rziw== X-Gm-Message-State: AOAM530R4AI32dvEZGSCqRKLHtuJyTjoTs1Jf0FQ1jwVPkUvXvBHFa+K EWeCj+8pTHPJualAs2Ob9g3jgJyvyOQ8SQWsYL1bGw+lpZa6mCX3f5NTOwlOSeHwM/qvlnpsfZH p4BdITmRPNWI7feE= X-Received: by 2002:a5d:6a90:: with SMTP id s16mr22443601wru.8.1593544420475; Tue, 30 Jun 2020 12:13:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSyzgvY1w+RsuRX1LZtlarjiZHg7gtqiinAx2X00WNtHkvg4kmiKvFn5hmTgrzaek5JKEzIg== X-Received: by 2002:a5d:6a90:: with SMTP id s16mr22443575wru.8.1593544419910; Tue, 30 Jun 2020 12:13:39 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id l8sm4663941wrq.15.2020.06.30.12.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:39 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 04/12] block/nvme: Define QUEUE_INDEX macros to ease code review Date: Tue, 30 Jun 2020 21:13:10 +0200 Message-Id: <20200630191318.30021-5-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 01:11:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Use definitions instead of '0' or '1' indexes. Also this will be useful when using multi-queues later. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index e1893b4e79..28762d7ee8 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -103,6 +103,9 @@ typedef volatile struct { QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) != 0x1000); +#define QUEUE_INDEX_ADMIN 0 +#define QUEUE_INDEX_IO(n) (1 + n) + struct BDRVNVMeState { AioContext *aio_context; QEMUVFIOState *vfio; @@ -531,7 +534,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) } cmd.prp1 = cpu_to_le64(iova); - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify controller"); goto out; } @@ -555,7 +558,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify namespace"); goto out; } @@ -644,7 +647,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 = cpu_to_le32(0x3), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -655,7 +658,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) .cdw10 = cpu_to_le32(((queue_size - 1) << 16) | (n & 0xFFFF)), .cdw11 = cpu_to_le32(0x1 | (n << 16)), }; - if (nvme_cmd_sync(bs, s->queues[0], &cmd)) { + if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to create io queue [%d]", n); nvme_free_queue_pair(q); return false; @@ -739,16 +742,18 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, /* Set up admin queue. */ s->queues = g_new(NVMeQueuePair *, 1); - s->queues[0] = nvme_create_queue_pair(bs, 0, NVME_QUEUE_SIZE, errp); - if (!s->queues[0]) { + s->queues[QUEUE_INDEX_ADMIN] = nvme_create_queue_pair(bs, 0, + NVME_QUEUE_SIZE, + errp); + if (!s->queues[QUEUE_INDEX_ADMIN]) { ret = -EINVAL; goto out; } s->nr_queues = 1; QEMU_BUILD_BUG_ON(NVME_QUEUE_SIZE & 0xF000); s->regs->aqa = cpu_to_le32((NVME_QUEUE_SIZE << 16) | NVME_QUEUE_SIZE); - s->regs->asq = cpu_to_le64(s->queues[0]->sq.iova); - s->regs->acq = cpu_to_le64(s->queues[0]->cq.iova); + s->regs->asq = cpu_to_le64(s->queues[QUEUE_INDEX_ADMIN]->sq.iova); + s->regs->acq = cpu_to_le64(s->queues[QUEUE_INDEX_ADMIN]->cq.iova); /* After setting up all control registers we can enable device now. */ s->regs->cc = cpu_to_le32((ctz32(NVME_CQ_ENTRY_BYTES) << 20) | @@ -839,7 +844,7 @@ static int nvme_enable_disable_write_cache(BlockDriverState *bs, bool enable, .cdw11 = cpu_to_le32(enable ? 0x01 : 0x00), }; - ret = nvme_cmd_sync(bs, s->queues[0], &cmd); + ret = nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd); if (ret) { error_setg(errp, "Failed to configure NVMe write cache"); } @@ -1056,7 +1061,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, { int r; BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[QUEUE_INDEX_IO(0)]; NVMeRequest *req; uint32_t cdw12 = (((bytes >> s->blkshift) - 1) & 0xFFFF) | @@ -1171,7 +1176,7 @@ static coroutine_fn int nvme_co_pwritev(BlockDriverState *bs, static coroutine_fn int nvme_co_flush(BlockDriverState *bs) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[QUEUE_INDEX_IO(0)]; NVMeRequest *req; NvmeCmd cmd = { .opcode = NVME_CMD_FLUSH, @@ -1202,7 +1207,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, BdrvRequestFlags flags) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[QUEUE_INDEX_IO(0)]; NVMeRequest *req; uint32_t cdw12 = ((bytes >> s->blkshift) - 1) & 0xFFFF; @@ -1255,7 +1260,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, int bytes) { BDRVNVMeState *s = bs->opaque; - NVMeQueuePair *ioq = s->queues[1]; + NVMeQueuePair *ioq = s->queues[QUEUE_INDEX_IO(0)]; NVMeRequest *req; NvmeDsmRange *buf; QEMUIOVector local_qiov; @@ -1398,7 +1403,7 @@ static void nvme_aio_unplug(BlockDriverState *bs) BDRVNVMeState *s = bs->opaque; assert(s->plugged); s->plugged = false; - for (i = 1; i < s->nr_queues; i++) { + for (i = QUEUE_INDEX_IO(0); i < s->nr_queues; i++) { NVMeQueuePair *q = s->queues[i]; qemu_mutex_lock(&q->lock); nvme_kick(q); From patchwork Tue Jun 30 19:13:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634627 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBF3913B4 for ; Tue, 30 Jun 2020 19:19:47 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B2194206A1 for ; Tue, 30 Jun 2020 19:19:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="A+xkyFnh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2194206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:37286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLnG-0007Rp-UG for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:19:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42270) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLha-0006Uw-B6 for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:54 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:40639 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhX-0005XV-Vd for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:13:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544429; 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=JwOS0dTFEWL6oyJkADDTKayrcrCvjz0aXfTaNffA7dY=; b=A+xkyFnhnBN7pSVTVJtB2f/FWv115ToqGxC7GhRFC1dWTVR0Klnkeg4OtQcbNM0SOVZqKS 8/2sOOVpq7KFqRtKZ4oRnAHTgY5satxKUHCvJ6Rzh+zAFcK3Qp8zryIUYliTiQw7TIjSB0 ScUbrNjJflTzR3X5I1/avSIZpH3R8VE= 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-236-oxSFFa8sPv6rTRujviHvQg-1; Tue, 30 Jun 2020 15:13:48 -0400 X-MC-Unique: oxSFFa8sPv6rTRujviHvQg-1 Received: by mail-wm1-f72.google.com with SMTP id a21so21154028wmd.0 for ; Tue, 30 Jun 2020 12:13:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JwOS0dTFEWL6oyJkADDTKayrcrCvjz0aXfTaNffA7dY=; b=X72gJTF8ujGeZ8PjuuumZhupi32kd7/LV9MAIwBaoRg+C0lVfn99+9wwQqyz1mKJ8l W3bp8u1OYycCWoSmmg/ID82mqLcCG+o1qLK84k3VlNkkKuSF6IBBq2GZ6JvOW5OBYYxP BSVB7NxPlRFLvU1Ih0vAiuAK+8s8Pn4tM46zZRAkMju5MmnsTORdhMdDqIpjitnVqkNQ kSKWlRoRxK6tYvfl837NGIOpQCFkfjl/vReKGG1+IjLplbeanGNrLt/+daGCWdjXMrcG tGrNEyB+Lr/xWotP/gkU9cOxUQp5Jg4ZbHLZEczJLHJWRjrLckoJjuEQgN7LeLh9nqxa KVTQ== X-Gm-Message-State: AOAM531MvsMlcugflJT8byAhZ4rCoo+71PQUnXh3w4mwiCB5yB2yqNIr 51efT+LdU6l81UgcLW32s6o6Ylj8A2pz26gg/pDZnrexuAttbOkRalUDsWtl64kJtOmKaccMNZE MF/+SrwlN2ugb/9A= X-Received: by 2002:adf:e948:: with SMTP id m8mr23627167wrn.398.1593544426608; Tue, 30 Jun 2020 12:13:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6sSf6GxnS8+vTJS8mFterJVik6kcKKrFZr5Z33nidnpIjIjpS8zSEYkw8IA7Rk6e1NcoHOQ== X-Received: by 2002:adf:e948:: with SMTP id m8mr23627062wrn.398.1593544424684; Tue, 30 Jun 2020 12:13:44 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id w17sm4990456wra.42.2020.06.30.12.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:44 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 05/12] block/nvme: Rename local variable Date: Tue, 30 Jun 2020 21:13:11 +0200 Message-Id: <20200630191318.30021-6-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 01:11:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We are going to modify the code in the next commit. Renaming the 'resp' variable to 'id' first makes the next commit easier to review. No logical changes. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 28762d7ee8..b9760ff04f 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -510,8 +510,8 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) BDRVNVMeState *s = bs->opaque; NvmeIdCtrl *idctrl; NvmeIdNs *idns; + uint8_t *id; NvmeLBAF *lbaf; - uint8_t *resp; uint16_t oncs; int r; uint64_t iova; @@ -520,14 +520,14 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - resp = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); - if (!resp) { + id = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl = (NvmeIdCtrl *)resp; - idns = (NvmeIdNs *)resp; - r = qemu_vfio_dma_map(s->vfio, resp, sizeof(NvmeIdCtrl), true, &iova); + idctrl = (NvmeIdCtrl *)id; + idns = (NvmeIdNs *)id; + r = qemu_vfio_dma_map(s->vfio, id, sizeof(NvmeIdCtrl), true, &iova); if (r) { error_setg(errp, "Cannot map buffer for DMA"); goto out; @@ -554,8 +554,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) s->supports_write_zeroes = !!(oncs & NVME_ONCS_WRITE_ZEROS); s->supports_discard = !!(oncs & NVME_ONCS_DSM); - memset(resp, 0, 4096); - + memset(id, 0, 4096); cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { @@ -587,8 +586,8 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) s->blkshift = lbaf->ds; out: - qemu_vfio_dma_unmap(s->vfio, resp); - qemu_vfree(resp); + qemu_vfio_dma_unmap(s->vfio, id); + qemu_vfree(id); } static bool nvme_poll_queues(BDRVNVMeState *s) From patchwork Tue Jun 30 19:13:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634633 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3594213B4 for ; Tue, 30 Jun 2020 19:22:16 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0AFC5206C0 for ; Tue, 30 Jun 2020 19:22:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XWo2dr3L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0AFC5206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:45284 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLpf-0002S1-8T for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:22:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLht-0006uR-Fh for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:13 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:29592 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhp-0005ZM-11 for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544447; 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=EcEIQ0Xt95Hgt2rsFb2a6/aei8m4wjvow7AnP4TfaSs=; b=XWo2dr3LzxmA11kvVhfg/0XTZTll52/bcS8s9m3vlLd1OmuwxmdOocD2VHaHrevD/PQ7ov joBcLWmcc+gz3P9gsf70Pcip9O9a816QYJXIgn9TBhNO/HIN0UuUUXnijQvDukK0weJ9WZ lxfsy8t40gQRvj2CvSUcKBvFRXW7Kws= 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-13-a3ThsnsIPA2pf3dMFdcq-Q-1; Tue, 30 Jun 2020 15:13:51 -0400 X-MC-Unique: a3ThsnsIPA2pf3dMFdcq-Q-1 Received: by mail-wr1-f70.google.com with SMTP id o12so19019113wrj.23 for ; Tue, 30 Jun 2020 12:13:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EcEIQ0Xt95Hgt2rsFb2a6/aei8m4wjvow7AnP4TfaSs=; b=S+PARvbU3X1B7kaXjs+kIP4FDQ7BGhc7ZzTAScCrm7skxddbOhXjh8A5DyrvpWCy7B oy58i7XUTvMKng8qF+rQHS4cAkEAcyYxxtdHFeOWqWdK2qb+bAqbsqIrRDDs0udM4rcr 8jP7CFBbuBwCxKF3UjQBSBH8XnXMSfA/to/ifg9waV7k3nBApPFYbSGTCVUif/htnDP8 MvMZv48nxYY4wBKRpKkiac0dzirxouS6ptipw909MOPnIpvWWZu3anN28Lx8pdsVMruE eFWQeSiRlHefLeTg1vSC51NTbfobMJh1c6TfTTRrF1RGx7MGfqloC2vD70xdYKllf96r Vy7A== X-Gm-Message-State: AOAM5305WSAdUjtVFzJZh7vfJT4s/BAzO1t+uNAnaCUtwsZbODyJixuH sfrstpy15wTx+Ub4SCg9sFkdaluF2az2vnulFv7Y48nGx2usM+Uf3REUpAUZvVnbTG7oFnUI//J 5+hpjU+Z3X+y4P/E= X-Received: by 2002:a1c:4d11:: with SMTP id o17mr22304554wmh.134.1593544429923; Tue, 30 Jun 2020 12:13:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOmAb1pXfLdMTML9O6YmWsoD58SvUu2/u2ZsHvpSZX+YLHW1yBXSmPY3zUc9mG8On17Zm/yA== X-Received: by 2002:a1c:4d11:: with SMTP id o17mr22304540wmh.134.1593544429733; Tue, 30 Jun 2020 12:13:49 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id c2sm4731485wrv.47.2020.06.30.12.13.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:48 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 06/12] block/nvme: Use union of NvmeIdCtrl / NvmeIdNs structures Date: Tue, 30 Jun 2020 21:13:12 +0200 Message-Id: <20200630191318.30021-7-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 00:34:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" We allocate an unique chunk of memory then use it for two different structures. By using an union, we make it clear the data is overlapping (and we can remove the casts). Suggested-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index b9760ff04f..7ebd5be1f3 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -508,9 +508,10 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) { BDRVNVMeState *s = bs->opaque; - NvmeIdCtrl *idctrl; - NvmeIdNs *idns; - uint8_t *id; + union { + NvmeIdCtrl ctrl; + NvmeIdNs ns; + } *id; NvmeLBAF *lbaf; uint16_t oncs; int r; @@ -520,14 +521,12 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - id = qemu_try_blockalign0(bs, sizeof(NvmeIdCtrl)); + id = qemu_try_blockalign0(bs, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; } - idctrl = (NvmeIdCtrl *)id; - idns = (NvmeIdNs *)id; - r = qemu_vfio_dma_map(s->vfio, id, sizeof(NvmeIdCtrl), true, &iova); + r = qemu_vfio_dma_map(s->vfio, id, sizeof(*id), true, &iova); if (r) { error_setg(errp, "Cannot map buffer for DMA"); goto out; @@ -539,22 +538,22 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) goto out; } - if (le32_to_cpu(idctrl->nn) < namespace) { + if (le32_to_cpu(id->ctrl.nn) < namespace) { error_setg(errp, "Invalid namespace"); goto out; } - s->write_cache_supported = le32_to_cpu(idctrl->vwc) & 0x1; - s->max_transfer = (idctrl->mdts ? 1 << idctrl->mdts : 0) * s->page_size; + s->write_cache_supported = le32_to_cpu(id->ctrl.vwc) & 0x1; + s->max_transfer = (id->ctrl.mdts ? 1 << id->ctrl.mdts : 0) * s->page_size; /* For now the page list buffer per command is one page, to hold at most * s->page_size / sizeof(uint64_t) entries. */ s->max_transfer = MIN_NON_ZERO(s->max_transfer, s->page_size / sizeof(uint64_t) * s->page_size); - oncs = le16_to_cpu(idctrl->oncs); + oncs = le16_to_cpu(id->ctrl.oncs); s->supports_write_zeroes = !!(oncs & NVME_ONCS_WRITE_ZEROS); s->supports_discard = !!(oncs & NVME_ONCS_DSM); - memset(id, 0, 4096); + memset(id, 0, sizeof(*id)); cmd.cdw10 = 0; cmd.nsid = cpu_to_le32(namespace); if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { @@ -562,11 +561,11 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) goto out; } - s->nsze = le64_to_cpu(idns->nsze); - lbaf = &idns->lbaf[NVME_ID_NS_FLBAS_INDEX(idns->flbas)]; + s->nsze = le64_to_cpu(id->ns.nsze); + lbaf = &id->ns.lbaf[NVME_ID_NS_FLBAS_INDEX(id->ns.flbas)]; - if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(idns->dlfeat) && - NVME_ID_NS_DLFEAT_READ_BEHAVIOR(idns->dlfeat) == + if (NVME_ID_NS_DLFEAT_WRITE_ZEROES(id->ns.dlfeat) && + NVME_ID_NS_DLFEAT_READ_BEHAVIOR(id->ns.dlfeat) == NVME_ID_NS_DLFEAT_READ_BEHAVIOR_ZEROES) { bs->supported_write_flags |= BDRV_REQ_MAY_UNMAP; } From patchwork Tue Jun 30 19:13:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634637 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E341613B4 for ; Tue, 30 Jun 2020 19:23:45 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B8B69206C0 for ; Tue, 30 Jun 2020 19:23:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JSKcGYF4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B8B69206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50064 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLr7-0004Uo-1M for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:23:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLiB-0007ML-HY for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:34 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:33631 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLi8-0005c5-Q9 for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544468; 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=xAix5j6fBTu5J6nPbJGKsMJBRsOhK42Lg6OcyQOGwZc=; b=JSKcGYF4t1pYN06U+nDCPUQoOiFyEqrRpeFyyN+cpk9RS36HLukja4fIji5YJMN7SEfWZH 0EDeWd1k7AVJjfTMlvmLQHLxpNlhlpnHNrZW0NcdcV5mP4zcmtiX+HzUT+6WzGLYdq0ibZ y1gNn0vQnap2FEFPYLTN1xsnOzvoF9s= 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-108-VR0k5xBkOC2m9RzD0pTMfw-1; Tue, 30 Jun 2020 15:13:57 -0400 X-MC-Unique: VR0k5xBkOC2m9RzD0pTMfw-1 Received: by mail-wm1-f72.google.com with SMTP id t145so21419068wmt.2 for ; Tue, 30 Jun 2020 12:13:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xAix5j6fBTu5J6nPbJGKsMJBRsOhK42Lg6OcyQOGwZc=; b=PmEPfiid5b27a0OMLFaOm4pOzkxQvsHbYA8x7jYXH+kN8PQ+RtqrYPRrIxN5iA3Pfm QWi4vsaViYUYYlSl4MFzbQuFqLXLXiHidZCCrJ0cUyaLRe+R6Q0dVkOXPwQyOWZPWR11 q1AyYaM5AJ4aDHcqCpPxAfazxkPjLxceTBULANtn/nuBHQZ7dQJwZqSnTUT+O8XmkTtI JobmeB25874KMmtW8+bfjbdFbLycK4yd9LnOfR5n7kka6jZsRZos/OyGYWMPov4DucsK JIuBZdMzMEIlXLXvB6e020M6VklSBMDDD8Q1ELhB8MeHvm8trmvMaJmzteehTdW7Dl4f 0Gdw== X-Gm-Message-State: AOAM533XoWJWHRomMy8Il9oHv2FI+mY8iYg+HwQgu1JQh2mcfuf3LfWD wr2zmTgtGfukHDxdIMjOF1dl3kJWsXWbA/McFIeailajgkfOeVoN0passAzUp48vCCKhFuYJrgU oxzzDZcq2+wF9b3s= X-Received: by 2002:a5d:4fce:: with SMTP id h14mr22884002wrw.199.1593544436505; Tue, 30 Jun 2020 12:13:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhruJ8mI3C5RCoqABBkYuxHHuvtJP8Eowyx5JB9C2yerOF6aJ6+ucGR2EFxhiO+TJ+LpjcIg== X-Received: by 2002:a5d:4fce:: with SMTP id h14mr22883902wrw.199.1593544434428; Tue, 30 Jun 2020 12:13:54 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id r8sm4472994wrp.40.2020.06.30.12.13.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:53 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 07/12] block/nvme: Replace qemu_try_blockalign0 by qemu_try_blockalign/memset Date: Tue, 30 Jun 2020 21:13:13 +0200 Message-Id: <20200630191318.30021-8-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 03:55:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 7ebd5be1f3..5b0bb9a8d7 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -174,12 +174,12 @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, bytes = ROUND_UP(nentries * entry_bytes, s->page_size); q->head = q->tail = 0; - q->queue = qemu_try_blockalign0(bs, bytes); - + q->queue = qemu_try_blockalign(bs, bytes); if (!q->queue) { error_setg(errp, "Cannot allocate queue"); return; } + memset(q->queue, 0, bytes); r = 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(BlockDriverState *bs, if (!q) { return NULL; } - q->prp_list_pages = qemu_try_blockalign0(bs, + q->prp_list_pages = qemu_try_blockalign(bs, s->page_size * NVME_QUEUE_SIZE); if (!q->prp_list_pages) { goto fail; } + memset(q->prp_list_pages, 0, s->page_size * NVME_QUEUE_SIZE); qemu_mutex_init(&q->lock); q->s = s; q->index = idx; @@ -521,7 +522,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - id = qemu_try_blockalign0(bs, sizeof(*id)); + id = 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 namespace, Error **errp) error_setg(errp, "Cannot map buffer for DMA"); goto out; } - cmd.prp1 = cpu_to_le64(iova); + memset(id, 0, sizeof(*id)); + cmd.prp1 = cpu_to_le64(iova); if (nvme_cmd_sync(bs, s->queues[QUEUE_INDEX_ADMIN], &cmd)) { error_setg(errp, "Failed to identify controller"); goto out; @@ -1282,11 +1284,11 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, assert(s->nr_queues > 1); - buf = qemu_try_blockalign0(bs, s->page_size); + buf = qemu_try_blockalign(bs, s->page_size); if (!buf) { return -ENOMEM; } - + memset(buf, 0, s->page_size); buf->nlb = cpu_to_le32(bytes >> s->blkshift); buf->slba = cpu_to_le64(offset >> s->blkshift); buf->cattr = 0; From patchwork Tue Jun 30 19:13:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634629 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 44E1513B4 for ; Tue, 30 Jun 2020 19:20:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1B1D92068F for ; Tue, 30 Jun 2020 19:20:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="UlVkjj4b" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B1D92068F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLnc-0008BD-7e for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:20:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42346) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhr-0006ru-GT for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:11 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:39317 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLho-0005ZK-LK for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544447; 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=zJXkiU+zUDdCxJIrGhqvrdqSAXvINFmtZ8OHT+4C18g=; b=UlVkjj4bdTnewlXaE3T5TbutfBmFoyHCA8dlkUnXLRgIW2/A/AFXJIoohmawPwyHslxS6N cE44C8jggXpBaMWJbtrZ0QMQnViWfmYPf6ALeq1AJDHUDxu8T7etFXY0cd8axxXhpg460x TL392i0WVT95IMZi0KnU+hZ6NU3pBfA= 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-292-OofM12ocMBG9_h7OqaGezg-1; Tue, 30 Jun 2020 15:14:00 -0400 X-MC-Unique: OofM12ocMBG9_h7OqaGezg-1 Received: by mail-wm1-f72.google.com with SMTP id v11so2744922wmb.1 for ; Tue, 30 Jun 2020 12:14:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zJXkiU+zUDdCxJIrGhqvrdqSAXvINFmtZ8OHT+4C18g=; b=QdU/clwmZ3tg0sfcvSyAOEWJHQaFgAMOYAeVMLAvsHJe/7TKxgj+LL+HpdmxKcurm9 P/O6UW22K7v3IHsWcj9qbIQAxMLoa5V3eWeTYLnXETMXTfWxcu1e0kSSia+WTRgsitrX Es0//R8p+QbQ4r1aAhUoMqb+oXimAiLFpm4uO7YsQBHibc9ZxqdvmCPZEk0F1JwoHIOB CLYMUCjCxv0wg+2cRpmCAggTO1dWDx3bwtkbLo41YpcvGy9Ezd9VMfy8X4+1bzZZsK4+ R7qt/BAPCUocsKnpad2On1PJNZYjxz9buJa5Rq9u2grBdlcm1SdaqsspMzm1MRGIS3Os kbBA== X-Gm-Message-State: AOAM532zMyE64h6G8hmCW9ucxjBTfjELohWlhY3hNqHdV1xPVBynXtgZ jvoJzzumZcg2hAYjdZHzQnIU0jOxbBcZaiHVyhgzpOK2d+9wkbxaCCm74oW3+mLpGQOtRVfgdYW wMl/2ziM5TJ3pbxs= X-Received: by 2002:a1c:ab56:: with SMTP id u83mr22295319wme.94.1593544439292; Tue, 30 Jun 2020 12:13:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziHrzDf2mF4+g9g4C/qcXZkOdsUL16wMN3Diry8DYUA539wBsUBlqrJgGg1aJq2Agr7gv6Pw== X-Received: by 2002:a1c:ab56:: with SMTP id u83mr22295299wme.94.1593544439095; Tue, 30 Jun 2020 12:13:59 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id s8sm4634990wru.38.2020.06.30.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:13:58 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 08/12] block/nvme: Replace qemu_try_blockalign(bs) by qemu_try_memalign(pg_sz) Date: Tue, 30 Jun 2020 21:13:14 +0200 Message-Id: <20200630191318.30021-9-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 03:55:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi --- block/nvme.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 5b0bb9a8d7..8b4d957a8e 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -174,7 +174,7 @@ static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, bytes = ROUND_UP(nentries * entry_bytes, s->page_size); q->head = q->tail = 0; - q->queue = qemu_try_blockalign(bs, bytes); + q->queue = 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(BlockDriverState *bs, if (!q) { return NULL; } - q->prp_list_pages = qemu_try_blockalign(bs, + q->prp_list_pages = qemu_try_memalign(s->page_size, s->page_size * NVME_QUEUE_SIZE); if (!q->prp_list_pages) { goto fail; @@ -522,7 +522,7 @@ static void nvme_identify(BlockDriverState *bs, int namespace, Error **errp) .cdw10 = cpu_to_le32(0x1), }; - id = qemu_try_blockalign(bs, sizeof(*id)); + id = qemu_try_memalign(s->page_size, sizeof(*id)); if (!id) { error_setg(errp, "Cannot allocate buffer for identify response"); goto out; @@ -1140,7 +1140,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, flags); } trace_nvme_prw_buffered(s, offset, bytes, qiov->niov, is_write); - buf = qemu_try_blockalign(bs, bytes); + buf = qemu_try_memalign(s->page_size, bytes); if (!buf) { return -ENOMEM; @@ -1284,7 +1284,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, assert(s->nr_queues > 1); - buf = qemu_try_blockalign(bs, s->page_size); + buf = qemu_try_memalign(s->page_size, s->page_size); if (!buf) { return -ENOMEM; } From patchwork Tue Jun 30 19:13:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634625 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DCEB13B4 for ; Tue, 30 Jun 2020 19:18:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 12F26206A1 for ; Tue, 30 Jun 2020 19:18:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZsYMNyV/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12F26206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:33612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLmJ-0005ZB-5g for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:18:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42380) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhu-0006vM-B6 for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:29211 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhp-0005ZT-Ci for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544448; 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=tuXzLILJ7FT7I+1GOee4KI1h3HYM5KlaYdYlB+vyW7M=; b=ZsYMNyV/J8YqlxKW9oVXhdM6Day2Q3YidvMmM249D9ClbccU0CioPLTrgDeSGHh0VZRdfF rT+q9iWOg0e/g5aA12zXmcT+14MUZ0+22HbCEBaPe5qChykQFL8LdD+rlt5z4LllzS0BR9 QUfJdWqjXrkvtub8wynajwuZ5m3N0jc= 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-88-6f-JqpFcPjC8ZCriJSM0yQ-1; Tue, 30 Jun 2020 15:14:06 -0400 X-MC-Unique: 6f-JqpFcPjC8ZCriJSM0yQ-1 Received: by mail-wm1-f72.google.com with SMTP id g6so15598977wmk.4 for ; Tue, 30 Jun 2020 12:14:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tuXzLILJ7FT7I+1GOee4KI1h3HYM5KlaYdYlB+vyW7M=; b=H4/OtJn7dwmPYbhbuD/JoatVqGTEkRKiTkjzN4QyV9b6jb5PU9hde3RuK1WT0wWS47 f50W9cA0mBvsLAk/XUxKlVObkiNzbvQ2AZN1WXIsqZy8344xsVRn+0oAYH3dthYNg9p4 rbC4z51DS37na3hmt8npjXSxUeUrrbMXPW8cOiVcvi0A45W80YTlqZ34/AzLSY2Gnd7Y p47OPzHpaJZB3hZhE0Tht9wnbqPZ8vkzwiV02E4/OOG+AJkWjVY/BM2GkIMoHjHBfPt8 hkrGg0mPtp2R3/rITJzx2vkkl6cDcg7UGTH/waggUoKT6bjLNsT52IiwkJcHs8nSDeZ4 9gOA== X-Gm-Message-State: AOAM532ADahivjYf5YAwxHyMzJ9jiNn/aGNLhDknUciQruJV9H7zahTd Gy+EucNCAO4ueLEFA35CFB/TXnjgng0BwyAfMHJaYBW8pQuekptWpQyPVq8Qw5b9Pnq01kcqi9V gdhC2ScqbKcRMPdg= X-Received: by 2002:a5d:664e:: with SMTP id f14mr23197623wrw.6.1593544444112; Tue, 30 Jun 2020 12:14:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwuuJsDa+yK4/Rkce9dWMBX06w+o1lBpOcWhfDJnvRKOmk/YZqeeGkAtA0VFdnrGuxaxZBo9w== X-Received: by 2002:a5d:664e:: with SMTP id f14mr23197598wrw.6.1593544443854; Tue, 30 Jun 2020 12:14:03 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id s10sm4633017wme.31.2020.06.30.12.14.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:14:03 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 09/12] block/nvme: Simplify nvme_init_queue() arguments Date: Tue, 30 Jun 2020 21:13:15 +0200 Message-Id: <20200630191318.30021-10-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.61; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 01:11:03 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" nvme_init_queue() doesn't require BlockDriverState anymore. Replace it by BDRVNVMeState to simplify. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 8b4d957a8e..c28c08b3e3 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -165,10 +165,9 @@ static QemuOptsList runtime_opts = { }, }; -static void nvme_init_queue(BlockDriverState *bs, NVMeQueue *q, +static void nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q, int nentries, int entry_bytes, Error **errp) { - BDRVNVMeState *s = bs->opaque; size_t bytes; int r; @@ -251,14 +250,14 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, req->prp_list_iova = prp_list_iova + i * s->page_size; } - nvme_init_queue(bs, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); + nvme_init_queue(s, &q->sq, size, NVME_SQ_ENTRY_BYTES, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; } q->sq.doorbell = &s->regs->doorbells[idx * 2 * s->doorbell_scale]; - nvme_init_queue(bs, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); + nvme_init_queue(s, &q->cq, size, NVME_CQ_ENTRY_BYTES, &local_err); if (local_err) { error_propagate(errp, local_err); goto fail; From patchwork Tue Jun 30 19:13:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D781413BD for ; Tue, 30 Jun 2020 19:16:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD7E6206A1 for ; Tue, 30 Jun 2020 19:16:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="NixcHs8m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD7E6206A1 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:56968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLkN-0003EZ-Lr for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:16:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLhz-0006ym-Jt for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:19 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:56495 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhs-0005Zx-Lu for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544451; 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=KOpQpvHqMfX4FPMLDJD68SQU34AdCnwRx9P5g+DPasA=; b=NixcHs8m+u3HEC6pHi72fbeqXzjBN/kY+eTB/CQeJAxD+wSyZY3q5AB1JHfH/m1Vd3aijY ySnHs328YqECBw80AlJAPBEieduvqMDE11FvYivpmincjXVkZ+DJytN6LVVCIK6+z++/6T nwDfPZymQFV1+iGdNWn0/Mkg5XbDUjU= 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-170-gdVpSrkmOuyyUIkEBQtHoA-1; Tue, 30 Jun 2020 15:14:09 -0400 X-MC-Unique: gdVpSrkmOuyyUIkEBQtHoA-1 Received: by mail-wr1-f70.google.com with SMTP id o25so19038196wro.16 for ; Tue, 30 Jun 2020 12:14:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KOpQpvHqMfX4FPMLDJD68SQU34AdCnwRx9P5g+DPasA=; b=ByMwIxX1C+qPrYtswDK24mMwDBCis1UGYdMqtEab0WmVhpWctie+mTQ1mKwmSZvtEC RgHCqma92vSrQw3jOoipZDJVCaoA0UORKtjhTDGjKvgRo68X6YNqLadmK6CyF3CPquVM +gXqcKJhVqme0GMRKE8njFBp6/BavWCvMDRnk99cFrhK0yPDoSHJrqnHKUlRs9LbYoSe +HvV1L0R+gi2kLGVg+JOCe/cTkWhaDs1ToZsLT3vF+R4OAPVEmJQBY9/c4eWRRoGXw/x KrMFXBc/iHr2aUB008BvEUbu4YsfeHTIfjw1tHc1ewqRjorFoqRlzTVNI+s+8RFClYSx HiBQ== X-Gm-Message-State: AOAM530GABbHNpn05H0lDn6yU4JGh69Pic57idoOuuk9SpEUeH7SsNyG 68vUWGZS0suqKPKc2obqjsB7lH5fZPvfhQBgzRNWKPkXdRGp6gJkQPFiOJFxMUwhPn21M2ccKcF /Mg34rDvm6LrTtao= X-Received: by 2002:adf:e38b:: with SMTP id e11mr22761568wrm.65.1593544448681; Tue, 30 Jun 2020 12:14:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw1EZVpTdd6iXbH3PSnKeVnsDO0FFxLn8ufo5u4r8UFQHUawa91336cWUspmUwMIrMWX837DQ== X-Received: by 2002:adf:e38b:: with SMTP id e11mr22761556wrm.65.1593544448497; Tue, 30 Jun 2020 12:14:08 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id i19sm4911419wrb.56.2020.06.30.12.14.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:14:08 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 10/12] block/nvme: Replace BDRV_POLL_WHILE by AIO_WAIT_WHILE Date: Tue, 30 Jun 2020 21:13:16 +0200 Message-Id: <20200630191318.30021-11-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 03:55:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" BDRV_POLL_WHILE() is defined as: #define BDRV_POLL_WHILE(bs, cond) ({ \ BlockDriverState *bs_ = (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 Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/nvme.c b/block/nvme.c index c28c08b3e3..010286e8ad 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 = bdrv_get_aio_context(bs); NVMeRequest *req; int ret = -EINPROGRESS; req = nvme_get_free_req(q); @@ -501,7 +502,7 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, } nvme_submit_command(q, req, cmd, nvme_cmd_sync_cb, &ret); - BDRV_POLL_WHILE(bs, ret == -EINPROGRESS); + AIO_WAIT_WHILE(aio_context, ret == -EINPROGRESS); return ret; } From patchwork Tue Jun 30 19:13:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634635 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4034F13B4 for ; Tue, 30 Jun 2020 19:23:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1469E206C0 for ; Tue, 30 Jun 2020 19:23:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="XbDaR9FZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1469E206C0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47380 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLqN-0003Ju-0P for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:22:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLi0-00072Q-VQ for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:20 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:51213 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLhz-0005aj-8C for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544456; 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=2lvVHFOutT4xNyLe5+eXbBjp3teTx1IVF01y815xjeo=; b=XbDaR9FZ0wzuzZ3DQ7G7ZF+XFICF+5K5tf4cQ1Cal9ZR5Vb8b2Y46NdUq+AiCBDQN3JSqr tp/KhoM3/4HaZzGkc27ngduk/HuAiLDw6pgyJ1fdMJd5qptaT+iJFMHDF/SONqmw3+YIsA 14thS5RokKyAxtDb+Qs8JLyxB41lTzA= 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-339-2WH3npdbOAGMT_5ruAF77Q-1; Tue, 30 Jun 2020 15:14:14 -0400 X-MC-Unique: 2WH3npdbOAGMT_5ruAF77Q-1 Received: by mail-wm1-f71.google.com with SMTP id a21so21154546wmd.0 for ; Tue, 30 Jun 2020 12:14:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2lvVHFOutT4xNyLe5+eXbBjp3teTx1IVF01y815xjeo=; b=r5CSkxGfStpnRekocxcSafgC9GEqASsieGjx6ITG4nr0nNjzLL9DChRBmnWx0Ly52j Ckb6XrD01tNtDqqWww7sq3QO6e80WA9kEG0CdMG21gZ7HohugHNLbjAkifA0Y1/mLxth RHxNopocV/gvC7J0IVNzze3rsG17A4TsKVkeU1XzZ0xCha2E1JN6KkoYoPU8DDx63Brw fbuA5vDwQ2Umg9ZsOwEHZcg/Vgr2QptiFs7kL53Vlh0jRufsnpDVRw7zyrBwFayju0+z vLcNFfw9RGHAtg+3EXFKBIF1rgXg3EngA2JtKPxW9uPaiEzH0hh3OgcZFYDuTYTTW3xD ds5g== X-Gm-Message-State: AOAM533pFrbDdaYIzYq0ZhFhdKzL1yqfK640KO0nfPSWzyybJ6Bgz0z1 q+Kyhit79OlxORMtXAOrk7fJk1jFFQlYGg1/YbPxWfr2yNlADuT8rZrMUPQUicxHMEvwnewwdbx 6l4bjt+w84FDshZ4= X-Received: by 2002:a7b:c775:: with SMTP id x21mr7981681wmk.34.1593544453477; Tue, 30 Jun 2020 12:14:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGZM7NxTJSQKKuMFFlvtMBFSlO59hmL8uK6jk8OfYAQMXly4R54KczyTR9KdpmWogkyRkb3w== X-Received: by 2002:a7b:c775:: with SMTP id x21mr7981658wmk.34.1593544453216; Tue, 30 Jun 2020 12:14:13 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id f14sm5135901wro.90.2020.06.30.12.14.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:14:12 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 11/12] block/nvme: Simplify nvme_create_queue_pair() arguments Date: Tue, 30 Jun 2020 21:13:17 +0200 Message-Id: <20200630191318.30021-12-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=207.211.31.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 00:34:33 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" nvme_create_queue_pair() doesn't require BlockDriverState anymore. Replace it by BDRVNVMeState and AioContext to simplify. Reviewed-by: Stefan Hajnoczi Signed-off-by: Philippe Mathieu-Daudé --- block/nvme.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 010286e8ad..90b2e00e8d 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); } -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 = bs->opaque; Error *local_err = NULL; NVMeQueuePair *q; uint64_t prp_list_iova; @@ -232,8 +232,7 @@ static NVMeQueuePair *nvme_create_queue_pair(BlockDriverState *bs, q->s = s; q->index = idx; qemu_co_queue_init(&q->free_req_queue); - q->completion_bh = aio_bh_new(bdrv_get_aio_context(bs), - nvme_process_completion_bh, q); + q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q); r = 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, Error **errp) NvmeCmd cmd; int queue_size = NVME_QUEUE_SIZE; - q = nvme_create_queue_pair(bs, n, queue_size, errp); + q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs), + n, queue_size, errp); if (!q) { return false; } @@ -682,6 +682,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, Error **errp) { BDRVNVMeState *s = bs->opaque; + AioContext *aio_context = bdrv_get_aio_context(bs); int ret; uint64_t cap; uint64_t timeout_ms; @@ -742,7 +743,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, /* Set up admin queue. */ s->queues = g_new(NVMeQueuePair *, 1); - s->queues[QUEUE_INDEX_ADMIN] = nvme_create_queue_pair(bs, 0, + s->queues[QUEUE_INDEX_ADMIN] = nvme_create_queue_pair(s, aio_context, 0, NVME_QUEUE_SIZE, errp); if (!s->queues[QUEUE_INDEX_ADMIN]) { From patchwork Tue Jun 30 19:13:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 11634631 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B3D6E13B4 for ; Tue, 30 Jun 2020 19:21:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7A15220702 for ; Tue, 30 Jun 2020 19:21:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Og6/WfJU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7A15220702 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:42768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jqLoj-0001O0-Dn for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 Jun 2020 15:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42522) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jqLi5-0007FO-UO for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:25 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34823 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jqLi3-0005bh-C4 for qemu-devel@nongnu.org; Tue, 30 Jun 2020 15:14:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1593544462; 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=zAFtHKEAEKWoAOfXmSXZPp5z9h7DCo+BkNURFMtuFac=; b=Og6/WfJUzBQFQrirxH6c16Wx/1IC8WIWHs6oeXxSsQtyIGhEOeQho7ktOjr5ZoxrUJ3SPn S/Qpcvy+579YwYUcYcCbhyH3PW3y5D+ZPMlYvWxPHMdwbDcltwxso1DeOnCIsln8CjcwAc y5wrZNRxXKZjoD2UWCd9hjhqAMJZeQI= 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-54-R1nmEce5NDSjSZL7075G_A-1; Tue, 30 Jun 2020 15:14:20 -0400 X-MC-Unique: R1nmEce5NDSjSZL7075G_A-1 Received: by mail-wm1-f70.google.com with SMTP id v6so19114730wmg.1 for ; Tue, 30 Jun 2020 12:14:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zAFtHKEAEKWoAOfXmSXZPp5z9h7DCo+BkNURFMtuFac=; b=sdkx4mSrc0sqmIG0+qt3T8aTrgX77QxkSgSQdy0gimNlCemvGJKEC9zOuZLMSqS5zY raYgzbIkCbROYRcs0HRyLB4xHHQBzSxhBTfvIbcZgyLvW4+fFH5cCDuxo8uJnwDQe+MQ aW0bcXre2iJBZKBOKm+3h49XS5rOxnL6h6LHQllhHdnkmQEKAaVfDbCz4fd2wAUEd4A7 m47bgt4JJ4yfwRIJFmdJHG3lU2XDa0Os2iR5VjysjFsHq1tfOrXchvyP13bXgSFJQoxT D+QMs8ayBGVDmtJL/6r+o1L/NZSKHn+aYHSpkDclUWjcNisAJ880DodLTaRFrObcve/w qsrw== X-Gm-Message-State: AOAM530mF6cPVQH2U0BRlbw+FEDHmhkwqCzmMdJhMWErPKil24BJZjBg rkpVAwOJVMdMt8afP28GyJJUTBiNMmz6QYYDDQFMp8mPNR2Jrb6tPg0Ej3Bx8hMirAdbhWNyVei UhX7K/U4s2VtVM04= X-Received: by 2002:a7b:c099:: with SMTP id r25mr24195355wmh.159.1593544459154; Tue, 30 Jun 2020 12:14:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzS+GVZcXdBdr03+WUdIODlRoiYh+OrDBOfQ3oZdX5CH4N1AC5cjse7JHuOB0xcP1Uld5yNLA== X-Received: by 2002:a7b:c099:: with SMTP id r25mr24195270wmh.159.1593544457866; Tue, 30 Jun 2020 12:14:17 -0700 (PDT) Received: from localhost.localdomain (1.red-83-51-162.dynamicip.rima-tde.net. [83.51.162.1]) by smtp.gmail.com with ESMTPSA id v20sm4225841wmh.26.2020.06.30.12.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jun 2020 12:14:17 -0700 (PDT) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: Stefan Hajnoczi , qemu-devel@nongnu.org Subject: [PATCH v2 12/12] block/nvme: Use per-queue AIO context Date: Tue, 30 Jun 2020 21:13:18 +0200 Message-Id: <20200630191318.30021-13-philmd@redhat.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200630191318.30021-1-philmd@redhat.com> References: <20200630191318.30021-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 X-Mimecast-Originator: redhat.com Received-SPF: pass client-ip=205.139.110.120; envelope-from=philmd@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/30 03:55:26 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Fam Zheng , qemu-block@nongnu.org, Maxim Levitsky , Max Reitz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" To be able to use multiple queues on the same hardware, we need to have each queue able to receive IRQ notifications in the correct AIO context. The AIO context and the notification handler have to be proper to each queue, not to the block driver. Move aio_context and irq_notifier from BDRVNVMeState to NVMeQueuePair. Signed-off-by: Philippe Mathieu-Daudé --- Since v1: Moved irq_notifier to NVMeQueuePair --- block/nvme.c | 71 +++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/block/nvme.c b/block/nvme.c index 90b2e00e8d..e7b9ecec41 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -60,6 +60,8 @@ typedef struct { typedef struct { QemuMutex lock; + AioContext *aio_context; + EventNotifier irq_notifier; /* Read from I/O code path, initialized under BQL */ BDRVNVMeState *s; @@ -107,7 +109,6 @@ QEMU_BUILD_BUG_ON(offsetof(NVMeRegs, doorbells) != 0x1000); #define QUEUE_INDEX_IO(n) (1 + n) struct BDRVNVMeState { - AioContext *aio_context; QEMUVFIOState *vfio; NVMeRegs *regs; /* The submission/completion queue pairs. @@ -120,7 +121,6 @@ struct BDRVNVMeState { /* How many uint32_t elements does each doorbell entry take. */ size_t doorbell_scale; bool write_cache_supported; - EventNotifier irq_notifier; uint64_t nsze; /* Namespace size reported by identify command */ int nsid; /* The namespace id to read/write data. */ @@ -227,11 +227,17 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s, if (!q->prp_list_pages) { goto fail; } + r = event_notifier_init(&q->irq_notifier, 0); + if (r) { + error_setg(errp, "Failed to init event notifier"); + goto fail; + } memset(q->prp_list_pages, 0, s->page_size * NVME_QUEUE_SIZE); qemu_mutex_init(&q->lock); q->s = s; q->index = idx; qemu_co_queue_init(&q->free_req_queue); + q->aio_context = aio_context; q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q); r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, s->page_size * NVME_NUM_REQS, @@ -325,7 +331,7 @@ static void nvme_put_free_req_locked(NVMeQueuePair *q, NVMeRequest *req) static void nvme_wake_free_req_locked(NVMeQueuePair *q) { if (!qemu_co_queue_empty(&q->free_req_queue)) { - replay_bh_schedule_oneshot_event(q->s->aio_context, + replay_bh_schedule_oneshot_event(q->aio_context, nvme_free_req_queue_cb, q); } } @@ -492,7 +498,6 @@ static void nvme_cmd_sync_cb(void *opaque, int ret) static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, NvmeCmd *cmd) { - AioContext *aio_context = bdrv_get_aio_context(bs); NVMeRequest *req; int ret = -EINPROGRESS; req = nvme_get_free_req(q); @@ -501,7 +506,7 @@ static int nvme_cmd_sync(BlockDriverState *bs, NVMeQueuePair *q, } nvme_submit_command(q, req, cmd, nvme_cmd_sync_cb, &ret); - AIO_WAIT_WHILE(aio_context, ret == -EINPROGRESS); + AIO_WAIT_WHILE(q->aio_context, ret == -EINPROGRESS); return ret; } @@ -621,14 +626,16 @@ static bool nvme_poll_queues(BDRVNVMeState *s) static void nvme_handle_event(EventNotifier *n) { - BDRVNVMeState *s = container_of(n, BDRVNVMeState, irq_notifier); + NVMeQueuePair *q = container_of(n, NVMeQueuePair, irq_notifier); + BDRVNVMeState *s = q->s; trace_nvme_handle_event(s); event_notifier_test_and_clear(n); nvme_poll_queues(s); } -static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) +static bool nvme_add_io_queue(BlockDriverState *bs, + AioContext *aio_context, Error **errp) { BDRVNVMeState *s = bs->opaque; int n = s->nr_queues; @@ -636,8 +643,7 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) NvmeCmd cmd; int queue_size = NVME_QUEUE_SIZE; - q = nvme_create_queue_pair(s, bdrv_get_aio_context(bs), - n, queue_size, errp); + q = nvme_create_queue_pair(s, aio_context, n, queue_size, errp); if (!q) { return false; } @@ -672,7 +678,8 @@ static bool nvme_add_io_queue(BlockDriverState *bs, Error **errp) static bool nvme_poll_cb(void *opaque) { EventNotifier *e = opaque; - BDRVNVMeState *s = container_of(e, BDRVNVMeState, irq_notifier); + NVMeQueuePair *q = container_of(e, NVMeQueuePair, irq_notifier); + BDRVNVMeState *s = q->s; trace_nvme_poll_cb(s); return nvme_poll_queues(s); @@ -693,12 +700,6 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, qemu_co_queue_init(&s->dma_flush_queue); s->device = g_strdup(device); s->nsid = namespace; - s->aio_context = bdrv_get_aio_context(bs); - ret = event_notifier_init(&s->irq_notifier, 0); - if (ret) { - error_setg(errp, "Failed to init event notifier"); - return ret; - } s->vfio = qemu_vfio_open_pci(device, errp); if (!s->vfio) { @@ -773,12 +774,14 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } } - ret = qemu_vfio_pci_init_irq(s->vfio, &s->irq_notifier, + ret = qemu_vfio_pci_init_irq(s->vfio, + &s->queues[QUEUE_INDEX_ADMIN]->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(aio_context, + &s->queues[QUEUE_INDEX_ADMIN]->irq_notifier, false, nvme_handle_event, nvme_poll_cb); nvme_identify(bs, namespace, &local_err); @@ -789,7 +792,7 @@ static int nvme_init(BlockDriverState *bs, const char *device, int namespace, } /* Set up command queues. */ - if (!nvme_add_io_queue(bs, errp)) { + if (!nvme_add_io_queue(bs, aio_context, errp)) { ret = -EIO; } out: @@ -858,12 +861,14 @@ static void nvme_close(BlockDriverState *bs) BDRVNVMeState *s = bs->opaque; for (i = 0; i < s->nr_queues; ++i) { - nvme_free_queue_pair(s->queues[i]); + NVMeQueuePair *q = s->queues[i]; + + aio_set_event_notifier(q->aio_context, + &q->irq_notifier, false, NULL, NULL); + event_notifier_cleanup(&q->irq_notifier); + nvme_free_queue_pair(q); } g_free(s->queues); - aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, - false, NULL, NULL); - event_notifier_cleanup(&s->irq_notifier); qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE); qemu_vfio_close(s->vfio); @@ -1075,7 +1080,7 @@ static coroutine_fn int nvme_co_prw_aligned(BlockDriverState *bs, .cdw12 = cpu_to_le32(cdw12), }; NVMeCoData data = { - .ctx = bdrv_get_aio_context(bs), + .ctx = ioq->aio_context, .ret = -EINPROGRESS, }; @@ -1184,7 +1189,7 @@ static coroutine_fn int nvme_co_flush(BlockDriverState *bs) .nsid = cpu_to_le32(s->nsid), }; NVMeCoData data = { - .ctx = bdrv_get_aio_context(bs), + .ctx = ioq->aio_context, .ret = -EINPROGRESS, }; @@ -1225,7 +1230,7 @@ static coroutine_fn int nvme_co_pwrite_zeroes(BlockDriverState *bs, }; NVMeCoData data = { - .ctx = bdrv_get_aio_context(bs), + .ctx = ioq->aio_context, .ret = -EINPROGRESS, }; @@ -1275,7 +1280,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs, }; NVMeCoData data = { - .ctx = bdrv_get_aio_context(bs), + .ctx = ioq->aio_context, .ret = -EINPROGRESS, }; @@ -1368,10 +1373,10 @@ static void nvme_detach_aio_context(BlockDriverState *bs) qemu_bh_delete(q->completion_bh); q->completion_bh = NULL; - } - aio_set_event_notifier(bdrv_get_aio_context(bs), &s->irq_notifier, - false, NULL, NULL); + aio_set_event_notifier(bdrv_get_aio_context(bs), &q->irq_notifier, + false, NULL, NULL); + } } static void nvme_attach_aio_context(BlockDriverState *bs, @@ -1379,13 +1384,11 @@ static void nvme_attach_aio_context(BlockDriverState *bs, { BDRVNVMeState *s = bs->opaque; - s->aio_context = new_context; - aio_set_event_notifier(new_context, &s->irq_notifier, - false, nvme_handle_event, nvme_poll_cb); - for (int i = 0; i < s->nr_queues; i++) { NVMeQueuePair *q = s->queues[i]; + aio_set_event_notifier(new_context, &q->irq_notifier, + false, nvme_handle_event, nvme_poll_cb); q->completion_bh = aio_bh_new(new_context, nvme_process_completion_bh, q); }