qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Gonglei (Arei)" <arei.gonglei@huawei.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"virtio-dev@lists.oasis-open.org"
	<virtio-dev@lists.oasis-open.org>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>,
	"linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>,
	Luonengjun <luonengjun@huawei.com>,
	"stefanha@redhat.com" <stefanha@redhat.com>,
	"Huangweidong (C)" <weidong.huang@huawei.com>,
	"Wubin (H)" <wu.wubin@huawei.com>,
	"xin.zeng@intel.com" <xin.zeng@intel.com>,
	Claudio Fontana <Claudio.Fontana@huawei.com>,
	"herbert@gondor.apana.org.au" <herbert@gondor.apana.org.au>,
	"pasic@linux.vnet.ibm.com" <pasic@linux.vnet.ibm.com>,
	"davem@davemloft.net" <davem@davemloft.net>,
	"Zhoujian (jay, Euler)" <jianjay.zhou@huawei.com>,
	"Hanweidong (Randy)" <hanweidong@huawei.com>,
	"arei.gonglei@hotmail.com" <arei.gonglei@hotmail.com>,
	"cornelia.huck@de.ibm.com" <cornelia.huck@de.ibm.com>,
	"Xuquan (Quan Xu)" <xuquan8@huawei.com>,
	longpeng <longpeng2@huawei.com>,
	"salvatore.benedetto@intel.com" <salvatore.benedetto@intel.com>
Subject: Re: [Qemu-devel] [virtio-dev] Re: [PATCH v2 1/2] virtio: introduce little edian functions for virtio_cread/write# family
Date: Mon, 28 Nov 2016 04:54:01 +0200	[thread overview]
Message-ID: <20161128044845-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20161128042142-mutt-send-email-mst@kernel.org>

On Mon, Nov 28, 2016 at 04:34:56AM +0200, Michael S. Tsirkin wrote:
> On Mon, Nov 28, 2016 at 01:56:04AM +0000, Gonglei (Arei) wrote:
> > Hi Michael,
> > 
> > Thanks for your feedback firstly!
> > 
> > > -----Original Message-----
> > > From: virtio-dev@lists.oasis-open.org [mailto:virtio-dev@lists.oasis-open.org]
> > > On Behalf Of Michael S. Tsirkin
> > > Sent: Sunday, November 27, 2016 11:33 AM
> > > To: Gonglei (Arei)
> > > Subject: [virtio-dev] Re: [PATCH v2 1/2] virtio: introduce little edian functions for
> > > virtio_cread/write# family
> > > 
> > > On Tue, Nov 22, 2016 at 04:10:22PM +0800, Gonglei wrote:
> > > > Virtio modern devices are always little edian, let's introduce
> > > > the LE functions for read/write configuration space for
> > > > virtio modern devices, which avoid complaint by Sparse when
> > > > we use the virtio_creaed/virtio_cwrite in VIRTIO_1 devices.
> > > >
> > > > Signed-off-by: Gonglei <arei.gonglei@huawei.com>
> > > > ---
> > > >  include/linux/virtio_config.h | 45
> > > +++++++++++++++++++++++++++++++++++++++++++
> > > >  1 file changed, 45 insertions(+)
> > > >
> > > > diff --git a/include/linux/virtio_config.h b/include/linux/virtio_config.h
> > > > index 26c155b..de05707 100644
> > > > --- a/include/linux/virtio_config.h
> > > > +++ b/include/linux/virtio_config.h
> > > > @@ -414,4 +414,49 @@ static inline void virtio_cwrite64(struct virtio_device
> > > *vdev,
> > > >  		_r;							\
> > > >  	})
> > > >
> > > > +static inline __le16 virtio_cread16_le(struct virtio_device *vdev,
> > > > +				 unsigned int offset)
> > > > +{
> > > > +	__le16 ret;
> > > > +
> > > > +	vdev->config->get(vdev, offset, &ret, sizeof(ret));
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static inline void virtio_cwrite16_le(struct virtio_device *vdev,
> > > > +				   unsigned int offset, __le16 val)
> > > > +{
> > > > +	vdev->config->set(vdev, offset, &val, sizeof(val));
> > > > +}
> > > > +
> > > > +static inline __le32 virtio_cread32_le(struct virtio_device *vdev,
> > > > +				 unsigned int offset)
> > > > +{
> > > > +	__le32 ret;
> > > > +
> > > > +	vdev->config->get(vdev, offset, &ret, sizeof(ret));
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static inline void virtio_cwrite32_le(struct virtio_device *vdev,
> > > > +				   unsigned int offset, __le32 val)
> > > > +{
> > > > +	vdev->config->set(vdev, offset, &val, sizeof(val));
> > > > +}
> > > > +
> > > > +static inline __le64 virtio_cread64_le(struct virtio_device *vdev,
> > > > +				 unsigned int offset)
> > > > +{
> > > > +	__le64 ret;
> > > > +
> > > > +	__virtio_cread_many(vdev, offset, &ret, 1, sizeof(ret));
> > > > +	return ret;
> > > > +}
> > > > +
> > > > +static inline void virtio_cwrite64_le(struct virtio_device *vdev,
> > > > +				   unsigned int offset, __le64 val)
> > > > +{
> > > > +	vdev->config->set(vdev, offset, &val, sizeof(val));
> > > > +}
> > > > +
> > > >  #endif /* _LINUX_VIRTIO_CONFIG_H */
> > > 
> > > Could you please better explain what is the issue you are facing?
> > > virtio_cwrite/virtio_cread all accept and return native types.
> > > 
> > virtio_cwrite/virtio_cread are used to write/read configuration
> > space for virtio devices. For virtio-crypto device, I used __le32/64 directly
> > in struct virtio_crypto_config. The sparse reports warnings if I use virtio_cread()
> > for virtio-crypto device.
> 
> I suspect that's because you are doing cread into an le32 variable.
> 
> 
> 
> > Furthermore, it means the warnings exist for all VIRTIO_1 devices because
> > they are definitely LE, which it's not necessary to use virtio_to_cpu/cpu_to_virtio.
> > 
> > 
> > PS: I googled a discussion about this topic for virtio-input device, pls see:
> >  http://linux.kernel.narkive.com/3argfbWz/patch-1-1-add-virtio-input-driver
> > 
> > Regards,
> > -Gonglei
> 
> Looks like we changed the macros since - at least ATM
> virtio_console_config uses __u16 fields (which is probably a bug -
> I'll look into fixing it up) and they
> do not seem to trigger warnings.


Sorry, I recall now. We use u32 and similar types in the config
space, and endian-ness is implicit.
This works fine if you are using virtio_cread interfaces which will swap
to/from LE for you.

What doesn't work correctly is shadowing the whole config space
using ->get since that does not byte-swap. so just don't do it.

I would say just do what everyone does in this version and
we can revisit this later.

> 
> > > If you want it in LE format, swap it!
> > > 
> > > 
> > > 
> > > > --
> > > > 1.8.3.1
> > > >
> > > 
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
> > > For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org

  parent reply	other threads:[~2016-11-28  2:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22  8:10 [Qemu-devel] [PATCH v2 0/2] virtio-crypto: add Linux driver Gonglei
2016-11-22  8:10 ` [Qemu-devel] [PATCH v2 1/2] virtio: introduce little edian functions for virtio_cread/write# family Gonglei
2016-11-27  3:32   ` Michael S. Tsirkin
2016-11-28  1:56     ` [Qemu-devel] [virtio-dev] " Gonglei (Arei)
2016-11-28  2:34       ` Michael S. Tsirkin
2016-11-28  2:53         ` Gonglei (Arei)
2016-11-28  2:54         ` Michael S. Tsirkin [this message]
2016-11-28  2:57           ` Gonglei (Arei)
2016-11-22  8:10 ` [Qemu-devel] [PATCH v2 2/2] crypto: add virtio-crypto driver Gonglei
2016-11-27  3:27   ` Michael S. Tsirkin
2016-11-28  4:47     ` [Qemu-devel] [virtio-dev] " Gonglei (Arei)
2016-11-28  5:09       ` Michael S. Tsirkin
2016-11-28  5:38         ` Gonglei (Arei)
2016-11-26  9:38 ` [Qemu-devel] [PATCH v2 0/2] virtio-crypto: add Linux driver Gonglei (Arei)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161128044845-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=Claudio.Fontana@huawei.com \
    --cc=arei.gonglei@hotmail.com \
    --cc=arei.gonglei@huawei.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=davem@davemloft.net \
    --cc=hanweidong@huawei.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jianjay.zhou@huawei.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=longpeng2@huawei.com \
    --cc=luonengjun@huawei.com \
    --cc=pasic@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=salvatore.benedetto@intel.com \
    --cc=stefanha@redhat.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=weidong.huang@huawei.com \
    --cc=wu.wubin@huawei.com \
    --cc=xin.zeng@intel.com \
    --cc=xuquan8@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).