All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
To: Auger Eric <eric.auger@redhat.com>,
	"iommu@lists.linux-foundation.org"
	<iommu@lists.linux-foundation.org>,
	"devel@acpica.org" <devel@acpica.org>,
	"linux-acpi@vger.kernel.org" <linux-acpi@vger.kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>,
	"kvmarm@lists.cs.columbia.edu" <kvmarm@lists.cs.columbia.edu>,
	"virtualization@lists.linux-foundation.org"
	<virtualization@lists.linux-foundation.org>,
	"virtio-dev@lists.oasis-open.org"
	<virtio-dev@lists.oasis-open.org>
Cc: "Jayachandran.Nair@cavium.com" <Jayachandran.Nair@cavium.com>,
	Lorenzo Pieralisi <Lorenzo.Pieralisi@arm.com>,
	"ashok.raj@intel.com" <ashok.raj@intel.com>,
	"mst@redhat.com" <mst@redhat.com>,
	Marc Zyngier <Marc.Zyngier@arm.com>,
	Will Deacon <Will.Deacon@arm.com>,
	"rjw@rjwysocki.net" <rjw@rjwysocki.net>,
	"robert.moore@intel.com" <robert.moore@intel.com>,
	"lv.zheng@intel.com" <lv.zheng@intel.com>,
	Sudeep Holla <Sudeep.Holla@arm.com>,
	"lenb@kernel.org" <lenb@kernel.org>,
	Robin Murphy <Robin.Murphy@arm.com>,
	"joro@8bytes.org" <joro@8bytes.org>,
	"hanjun.guo@linaro.org" <hanjun.guo@linaro.org>
Subject: Re: [RFC PATCH v2 3/5] iommu/virtio-iommu: Add event queue
Date: Tue, 16 Jan 2018 17:48:15 +0000	[thread overview]
Message-ID: <874c9d45-d2a0-d77b-8606-bd1c13b63032__32193.7237786644$1516124650$gmane$org@arm.com> (raw)
In-Reply-To: <3061e653-38bb-bffa-0f16-43047724a0ae@redhat.com>

On 16/01/18 10:10, Auger Eric wrote:
> Hi,
> 
> On 17/11/17 19:52, Jean-Philippe Brucker wrote:
>> The event queue offers a way for the device to report access faults from
>> devices.
> end points?

Yes

[...]
>> +static void viommu_event_handler(struct virtqueue *vq)
>> +{
>> +	int ret;
>> +	unsigned int len;
>> +	struct scatterlist sg[1];
>> +	struct viommu_event *evt;
>> +	struct viommu_dev *viommu = vq->vdev->priv;
>> +
>> +	while ((evt = virtqueue_get_buf(vq, &len)) != NULL) {
>> +		if (len > sizeof(*evt)) {
>> +			dev_err(viommu->dev,
>> +				"invalid event buffer (len %u != %zu)\n",
>> +				len, sizeof(*evt));
>> +		} else if (!(evt->head & VIOMMU_FAULT_RESV_MASK)) {
>> +			viommu_fault_handler(viommu, &evt->fault);
>> +		}
>> +
>> +		sg_init_one(sg, evt, sizeof(*evt));
> in case of above error case, ie. len > sizeof(*evt), is it safe to push
> evt again?

I think it is, len is just what the device reports as written. The above
error would be a device bug, very unlikely and not worth a special
treatment (freeing the buffer), maybe not even worth the dev_err()
actually.

>> +		ret = virtqueue_add_inbuf(vq, sg, 1, evt, GFP_ATOMIC);
>> +		if (ret)
>> +			dev_err(viommu->dev, "could not add event buffer\n");
>> +	}
>> +
>> +	if (!virtqueue_kick(vq))
>> +		dev_err(viommu->dev, "kick failed\n");
>> +}
>> +
>>  /* IOMMU API */
>>  
>>  static bool viommu_capable(enum iommu_cap cap)
>> @@ -938,19 +1018,44 @@ static struct iommu_ops viommu_ops = {
>>  	.put_resv_regions	= viommu_put_resv_regions,
>>  };
>>  
>> -static int viommu_init_vq(struct viommu_dev *viommu)
>> +static int viommu_init_vqs(struct viommu_dev *viommu)
>>  {
>>  	struct virtio_device *vdev = dev_to_virtio(viommu->dev);
>> -	const char *name = "request";
>> -	void *ret;
>> +	const char *names[] = { "request", "event" };
>> +	vq_callback_t *callbacks[] = {
>> +		NULL, /* No async requests */
>> +		viommu_event_handler,
>> +	};
>> +
>> +	return virtio_find_vqs(vdev, VIOMMU_NUM_VQS, viommu->vqs, callbacks,
>> +			       names, NULL);
>> +}
>>  
>> -	ret = virtio_find_single_vq(vdev, NULL, name);
>> -	if (IS_ERR(ret)) {
>> -		dev_err(viommu->dev, "cannot find VQ\n");
>> -		return PTR_ERR(ret);
>> +static int viommu_fill_evtq(struct viommu_dev *viommu)
>> +{
>> +	int i, ret;
>> +	struct scatterlist sg[1];
>> +	struct viommu_event *evts;
>> +	struct virtqueue *vq = viommu->vqs[VIOMMU_EVENT_VQ];
>> +	size_t nr_evts = min_t(size_t, PAGE_SIZE / sizeof(struct viommu_event),
>> +			       viommu->vqs[VIOMMU_EVENT_VQ]->num_free);
>> +
>> +	evts = devm_kmalloc_array(viommu->dev, nr_evts, sizeof(*evts),
>> +				  GFP_KERNEL);
>> +	if (!evts)
>> +		return -ENOMEM;
>> +
>> +	for (i = 0; i < nr_evts; i++) {
>> +		sg_init_one(sg, &evts[i], sizeof(*evts));
>> +		ret = virtqueue_add_inbuf(vq, sg, 1, &evts[i], GFP_KERNEL);
> who does the deallocation of evts?

I think it should be viommu_remove, which should also remove the
virtqueues. I'll add this.

Thanks,
Jean

  parent reply	other threads:[~2018-01-16 17:48 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-17 18:52 [RFC PATCH v2 0/5] Add virtio-iommu driver Jean-Philippe Brucker
2017-11-17 18:52 ` [virtio-dev] " Jean-Philippe Brucker
2017-11-17 18:52 ` [RFC PATCH v2 1/5] iommu: " Jean-Philippe Brucker
2017-11-17 18:52   ` [virtio-dev] " Jean-Philippe Brucker
2017-11-29 15:17   ` Jean-Philippe Brucker
2017-11-29 15:17   ` Jean-Philippe Brucker
2017-11-29 15:17     ` Jean-Philippe Brucker
2018-01-15 15:12   ` Auger Eric
2018-01-15 15:12     ` [virtio-dev] " Auger Eric
2018-01-16 17:45     ` Jean-Philippe Brucker
2018-01-16 17:45     ` Jean-Philippe Brucker
2018-01-16 17:45       ` [virtio-dev] " Jean-Philippe Brucker
2018-01-15 15:12   ` Auger Eric
2017-11-17 18:52 ` Jean-Philippe Brucker
2017-11-17 18:52 ` [RFC PATCH v2 2/5] iommu/virtio-iommu: Add probe request Jean-Philippe Brucker
2017-11-17 18:52   ` [virtio-dev] " Jean-Philippe Brucker
2018-01-16  9:25   ` Auger Eric
2018-01-16  9:25     ` [virtio-dev] " Auger Eric
2018-01-16 17:46     ` Jean-Philippe Brucker
2018-01-16 17:46     ` Jean-Philippe Brucker
2018-01-16 17:46       ` [virtio-dev] " Jean-Philippe Brucker
2018-01-16  9:25   ` Auger Eric
2018-01-16 23:26   ` Auger Eric
2018-01-16 23:26     ` [virtio-dev] " Auger Eric
2018-01-19 16:21     ` Jean-Philippe Brucker
2018-01-19 16:21       ` [virtio-dev] " Jean-Philippe Brucker
2018-01-19 17:22       ` Auger Eric
2018-01-19 17:22       ` Auger Eric
2018-01-19 17:22         ` [virtio-dev] " Auger Eric
2018-01-19 16:21     ` Jean-Philippe Brucker
2018-01-16 23:26   ` Auger Eric
2017-11-17 18:52 ` Jean-Philippe Brucker
2017-11-17 18:52 ` [RFC PATCH v2 3/5] iommu/virtio-iommu: Add event queue Jean-Philippe Brucker
2017-11-17 18:52   ` [virtio-dev] " Jean-Philippe Brucker
2018-01-16 10:10   ` Auger Eric
2018-01-16 10:10     ` [virtio-dev] " Auger Eric
2018-01-16 17:48     ` Jean-Philippe Brucker
2018-01-16 17:48       ` [virtio-dev] " Jean-Philippe Brucker
2018-01-16 17:48     ` Jean-Philippe Brucker [this message]
2018-01-16 10:10   ` Auger Eric
2017-11-17 18:52 ` Jean-Philippe Brucker
2017-11-17 18:52 ` [RFC PATCH v2 4/5] ACPI/IORT: Support paravirtualized IOMMU Jean-Philippe Brucker
2017-11-17 18:52 ` Jean-Philippe Brucker
2017-11-17 18:52   ` [virtio-dev] " Jean-Philippe Brucker
2017-11-29 15:17   ` Jean-Philippe Brucker
2017-11-29 15:17   ` Jean-Philippe Brucker
2017-11-29 15:17     ` Jean-Philippe Brucker
2017-11-17 18:52 ` [RFC PATCH v2 5/5] ACPI/IORT: Move IORT to the ACPI folder Jean-Philippe Brucker
2017-11-17 18:52   ` [virtio-dev] " Jean-Philippe Brucker
2017-11-17 18:52 ` Jean-Philippe Brucker

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='874c9d45-d2a0-d77b-8606-bd1c13b63032__32193.7237786644$1516124650$gmane$org@arm.com' \
    --to=jean-philippe.brucker@arm.com \
    --cc=Jayachandran.Nair@cavium.com \
    --cc=Lorenzo.Pieralisi@arm.com \
    --cc=Marc.Zyngier@arm.com \
    --cc=Robin.Murphy@arm.com \
    --cc=Sudeep.Holla@arm.com \
    --cc=Will.Deacon@arm.com \
    --cc=ashok.raj@intel.com \
    --cc=devel@acpica.org \
    --cc=eric.auger@redhat.com \
    --cc=hanjun.guo@linaro.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=mst@redhat.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.