Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3516294imm; Tue, 17 Jul 2018 06:13:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpc9c3sukiuCc2Wp7cedwGuSLO9Mdo/FM5SwvsE0hF+WWAjIzUJnrG6AuALRM5N1HZUm7XZl X-Received: by 2002:a63:5c52:: with SMTP id n18-v6mr1553195pgm.360.1531833183011; Tue, 17 Jul 2018 06:13:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531833182; cv=none; d=google.com; s=arc-20160816; b=Lh38DZSIm6MYXL8WjnW26czOZwBd4Z1d1t5MGlD84jOHMOLIOxXHlBLXi34J9y9Mw5 17m/LDjGbqxZeKUJxFhvSQ1t114z8v1WkiX2WCAx4P+h8qGkhYGaQH4R3DnfrOgAXxKr YDUgIOirtUgK4P3LFKcpJL+eAq7U7PpgPSUXlziaG0TNIBYfoKcl1h6J/7G89oD6vYpL /j+tLwu1UR4fKDCPtvUgqhD55CFeLuV/SiN3q7wfRnPTxAnaoYp8KNMG+A91/60daxnf t5rEeoN9TfNRuc+Tc2h85iWUhaz4xT2HqWaWlNF8UHSRxSeT7/sErbeTrpvMNr+RWqHH vizw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=Rs8fo8yQP1SwHRASGjw1n2bCPAHJs3yT8T2SCHnje38=; b=Q77Pb+TQllT8bPr9p68UVck4LNjX62YvJnJqn9G0sN4fVg1NiAObZSMUf/rgSfk2Ib p14nq4YFVD/xybMGwwcwXr2wlS8+bnPHUCAS3aG3Hr1MNoo6IbXM+YXXCdmgmSLc+Rf7 Dk12CqS4jWNj45Rfu2PlsTFS5ePJUiNJ5WztP7WkEFJqdGn6s9oxZ5Umpx/b5ydxAAAz gLQjiDEHUObSUkX+ueM3DNYxgfDiD3GJimioIDxwf+ES6a6I5GKaF4IRyWUsf+L4tcWY QCLM+dVcf5TzNyC9rBSiwMZnq2qBX6MSSf1tJqqjXcoqu3by3szp4/QOLua46vFl0oJ7 dSDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x13-v6si860640pln.62.2018.07.17.06.12.48; Tue, 17 Jul 2018 06:13:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731644AbeGQNoo (ORCPT + 99 others); Tue, 17 Jul 2018 09:44:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56558 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1731548AbeGQNoo (ORCPT ); Tue, 17 Jul 2018 09:44:44 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 09CEB83221; Tue, 17 Jul 2018 13:12:06 +0000 (UTC) Received: from localhost (ovpn-117-28.ams2.redhat.com [10.36.117.28]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0929E111C481; Tue, 17 Jul 2018 13:11:58 +0000 (UTC) Date: Tue, 17 Jul 2018 14:11:56 +0100 From: Stefan Hajnoczi To: Pankaj Gupta Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, qemu-devel@nongnu.org, linux-nvdimm@ml01.01.org, jack@suse.cz, dan.j.williams@intel.com, riel@surriel.com, haozhong.zhang@intel.com, nilal@redhat.com, kwolf@redhat.com, pbonzini@redhat.com, ross.zwisler@intel.com, david@redhat.com, xiaoguangrong.eric@gmail.com, hch@infradead.org, mst@redhat.com, niteshnarayanlal@hotmail.com, lcapitulino@redhat.com, imammedo@redhat.com, eblake@redhat.com Subject: Re: [RFC v3 2/2] virtio-pmem: Add virtio pmem driver Message-ID: <20180717131156.GA13498@stefanha-x1.localdomain> References: <20180713075232.9575-1-pagupta@redhat.com> <20180713075232.9575-3-pagupta@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="IS0zKkzwUGydFO0o" Content-Disposition: inline In-Reply-To: <20180713075232.9575-3-pagupta@redhat.com> User-Agent: Mutt/1.10.0 (2018-05-17) X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 17 Jul 2018 13:12:06 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Tue, 17 Jul 2018 13:12:06 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'stefanha@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --IS0zKkzwUGydFO0o Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jul 13, 2018 at 01:22:31PM +0530, Pankaj Gupta wrote: > + /* The request submission function */ > +static int virtio_pmem_flush(struct device *dev) > +{ > + int err; > + unsigned long flags; > + struct scatterlist *sgs[2], sg, ret; > + struct virtio_device *vdev = dev_to_virtio(dev->parent->parent); > + struct virtio_pmem *vpmem = vdev->priv; > + struct virtio_pmem_request *req = kmalloc(sizeof(*req), GFP_KERNEL); > + > + req->done = false; > + init_waitqueue_head(&req->acked); > + spin_lock_irqsave(&vpmem->pmem_lock, flags); > + > + sg_init_one(&sg, req, sizeof(req)); What are you trying to do here? sizeof(req) == sizeof(struct virtio_pmem_request *) == sizeof(void *) Did you mean sizeof(*req)? But why map struct virtio_pmem_request to the device? struct virtio_pmem_request is the driver-internal request state and is not part of the hardware interface. > + sgs[0] = &sg; > + sg_init_one(&ret, &req->ret, sizeof(req->ret)); > + sgs[1] = &ret; > + err = virtqueue_add_sgs(vpmem->req_vq, sgs, 1, 1, req, GFP_ATOMIC); > + if (err) { > + dev_err(&vdev->dev, "failed to send command to virtio pmem device\n"); This can happen if the virtqueue is full. Printing a message and failing the flush isn't appropriate. This thread needs to wait until virtqueue space becomes available. > + spin_unlock_irqrestore(&vpmem->pmem_lock, flags); > + return -ENOSPC; req is leaked. > + virtio_device_ready(vdev); This call isn't needed. Driver use it when they wish to submit buffers on virtqueues before ->probe() returns. > diff --git a/include/linux/virtio_pmem.h b/include/linux/virtio_pmem.h > new file mode 100644 > index 0000000..0f83d9c > --- /dev/null > +++ b/include/linux/virtio_pmem.h include/ is for declarations (e.g. kernel APIs) needed by other compilation units. The contents of this header are internal to the virtio_pmem driver implementation and can therefore be in virtio_pmem.c. include/linux/virtio_pmem.h isn't necessary since nothing besides virtio_pmem.c will need to include it. --IS0zKkzwUGydFO0o Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEcBAEBAgAGBQJbTescAAoJEJykq7OBq3PIwPQH/3keU8xWbvv1c729mwMrCSlT GRJkt3AyzE2iIoaXFkeBpnjnpARsajzX0vH/EheCEse46G6aOtia9fALOzf0Fo2l XRB1KM3WhEDIx+xNZuk4/WH5AaSHEJPjSBM6Isv410MASfrDJzyu0vuRSjzqEAT8 augb75qojqCkqkDQm5iMcN6zGwgjJ0MLrXZdN8EKIpgsqeMW7QmwWCwlmWwCgXrq f5nor6oEl3jci/EYjw6ctjWsBCSKdDz813phHbQLCbcMD9IuEngGlZt5b9XwdfNY 5u2SaC66cIPqMYyogb6duBFMZ2AOzkrSZjHbHyh1HArf7Lhd/aoYYMLABy/hwTs= =0jCu -----END PGP SIGNATURE----- --IS0zKkzwUGydFO0o--