lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20210713113301-mutt-send-email-mst@kernel.org>
Date:   Tue, 13 Jul 2021 11:34:31 -0400
From:   "Michael S. Tsirkin" <mst@...hat.com>
To:     Viresh Kumar <viresh.kumar@...aro.org>
Cc:     Jie Deng <jie.deng@...el.com>, linux-i2c@...r.kernel.org,
        virtualization@...ts.linux-foundation.org,
        linux-kernel@...r.kernel.org, wsa@...nel.org,
        wsa+renesas@...g-engineering.com, arnd@...db.de,
        jasowang@...hat.com, andriy.shevchenko@...ux.intel.com,
        yu1.wang@...el.com, shuo.a.liu@...el.com, conghui.chen@...el.com,
        stefanha@...hat.com, gregkh@...uxfoundation.org,
        vincent.guittot@...aro.org, alex.bennee@...aro.org
Subject: Re: [PATCH v14] i2c: virtio: add a virtio i2c frontend driver

On Fri, Jul 09, 2021 at 09:14:07AM +0530, Viresh Kumar wrote:
> On 09-07-21, 10:25, Jie Deng wrote:
> > Add an I2C bus driver for virtio para-virtualization.
> > 
> > The controller can be emulated by the backend driver in
> > any device model software by following the virtio protocol.
> > 
> > The device specification can be found on
> > https://lists.oasis-open.org/archives/virtio-comment/202101/msg00008.html.
> > 
> > By following the specification, people may implement different
> > backend drivers to emulate different controllers according to
> > their needs.
> > 
> > Co-developed-by: Conghui Chen <conghui.chen@...el.com>
> > Signed-off-by: Conghui Chen <conghui.chen@...el.com>
> > Signed-off-by: Jie Deng <jie.deng@...el.com>
> > ---
> > Changes v13 -> v14
> > 	- Put the headers in virtio_i2c.h in alphabetical order.
> > 	- Dropped I2C_FUNC_SMBUS_QUICK support.
> > 	- Dropped few unnecessary variables and checks.
> > 	- Use "num" everywhere instead of num or nr, to be consistent.
> > 	- Added few comments which make the design more clear. 
> 
> Thanks a lot for following this up so far :)
> 
> > +static int virtio_i2c_prepare_reqs(struct virtqueue *vq,
> > +				   struct virtio_i2c_req *reqs,
> > +				   struct i2c_msg *msgs, int num)
> > +{
> > +	struct scatterlist *sgs[3], out_hdr, msg_buf, in_hdr;
> > +	int i;
> > +
> > +	for (i = 0; i < num; i++) {
> > +		int outcnt = 0, incnt = 0;
> > +
> > +		/*
> > +		 * We don't support 0 length messages and so masked out
> > +		 * I2C_FUNC_SMBUS_QUICK in virtio_i2c_func().
> > +		 */
> > +		if (!msgs[i].len)
> > +			break;
> > +
> > +		/*
> > +		 * Only 7-bit mode supported for this moment. For the address
> > +		 * format, Please check the Virtio I2C Specification.
> > +		 */
> > +		reqs[i].out_hdr.addr = cpu_to_le16(msgs[i].addr << 1);
> > +
> > +		if (i != num - 1)
> > +			reqs[i].out_hdr.flags = cpu_to_le32(VIRTIO_I2C_FLAGS_FAIL_NEXT);
> > +
> > +		sg_init_one(&out_hdr, &reqs[i].out_hdr, sizeof(reqs[i].out_hdr));
> > +		sgs[outcnt++] = &out_hdr;
> > +
> > +		reqs[i].buf = i2c_get_dma_safe_msg_buf(&msgs[i], 1);
> > +		if (!reqs[i].buf)
> > +			break;
> > +
> > +		sg_init_one(&msg_buf, reqs[i].buf, msgs[i].len);
> > +
> > +		if (msgs[i].flags & I2C_M_RD)
> > +			sgs[outcnt + incnt++] = &msg_buf;
> > +		else
> > +			sgs[outcnt++] = &msg_buf;
> > +
> > +		sg_init_one(&in_hdr, &reqs[i].in_hdr, sizeof(reqs[i].in_hdr));
> > +		sgs[outcnt + incnt++] = &in_hdr;
> > +
> > +		if (virtqueue_add_sgs(vq, sgs, outcnt, incnt, &reqs[i], GFP_KERNEL)) {
> > +			i2c_put_dma_safe_msg_buf(reqs[i].buf, &msgs[i], false);
> > +			break;
> > +		}
> > +	}
> > +
> > +	return i;
> > +}
> 
> Wolfram, in case you wonder why we don't error out early as discussed earlier,
> then ...
> 
> > +static int virtio_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
> > +			   int num)
> > +{
> 
> ...
> 
> > +	/*
> > +	 * For the case where count < num, i.e. we weren't able to queue all the
> > +	 * msgs, ideally we should abort right away and return early, but some
> > +	 * of the messages are already sent to the remote I2C controller and the
> > +	 * virtqueue will be left in undefined state in that case. We kick the
> > +	 * remote here to clear the virtqueue, so we can try another set of
> > +	 * messages later on.
> > +	 */
> 
> ... here is the reasoning for that.
> 
> Please see if you can still get it merged into 5.14-rc1/2. Thanks.
> 
> Reviewed-by: Viresh Kumar <viresh.kumar@...aro.org>
> Tested-by: Viresh Kumar <viresh.kumar@...aro.org>

Well a new driver so maybe rc2 is still ok ...

Acked-by: Michael S. Tsirkin <mst@...hat.com>



> -- 
> viresh

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ