All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: Xen-devel <xen-devel@lists.xenproject.org>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH 4/4] AMD/IOMMU: Treat head/tail pointers as byte offsets
Date: Mon, 10 Feb 2020 14:55:56 +0000	[thread overview]
Message-ID: <cf596ea9-f9dd-b938-9666-34165edb8a0c@citrix.com> (raw)
In-Reply-To: <76961409-b553-0ccc-6cd1-33ccf5cc75a0@suse.com>

On 05/02/2020 10:36, Jan Beulich wrote:
> On 03.02.2020 15:43, Andrew Cooper wrote:
>> --- a/xen/drivers/passthrough/amd/iommu_cmd.c
>> +++ b/xen/drivers/passthrough/amd/iommu_cmd.c
>> @@ -24,16 +24,14 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[])
>>  {
>>      uint32_t tail, head;
>>  
>> -    tail = iommu->cmd_buffer.tail;
>> -    if ( ++tail == iommu->cmd_buffer.entries )
>> +    tail = iommu->cmd_buffer.tail + IOMMU_CMD_BUFFER_ENTRY_SIZE;
>> +    if ( tail == iommu->cmd_buffer.size )
>>          tail = 0;
>>  
>> -    head = iommu_get_rb_pointer(readl(iommu->mmio_base +
>> -                                      IOMMU_CMD_BUFFER_HEAD_OFFSET));
>> +    head = readl(iommu->mmio_base + IOMMU_CMD_BUFFER_HEAD_OFFSET);
>>      if ( head != tail )
> Surely you want to mask off reserved (or more generally
> unrelated) bits, before consuming the value for the purpose
> here (and elsewhere below)?

Reserved bits are defined in the IOMMU spec to be read-only zero.

It is also undefined behaviour for this value to ever be outside of the
size configured for command buffer, so using the value like this is spec
compliant.

As for actually masking the values, that breaks the optimisers ability
to construct commands in the command ring.  This aspect can be worked
around with other code changes, but I also think it is implausible that
the remaining reserved bits here are going to sprout incompatible future
uses.

>
>> @@ -45,13 +43,11 @@ static int queue_iommu_command(struct amd_iommu *iommu, u32 cmd[])
>>  
>>  static void commit_iommu_command_buffer(struct amd_iommu *iommu)
>>  {
>> -    u32 tail = 0;
>> -
>> -    iommu_set_rb_pointer(&tail, iommu->cmd_buffer.tail);
>> -    writel(tail, iommu->mmio_base+IOMMU_CMD_BUFFER_TAIL_OFFSET);
>> +    writel(iommu->cmd_buffer.tail,
>> +           iommu->mmio_base + IOMMU_CMD_BUFFER_TAIL_OFFSET);
> I guess not preserving the reserved bits isn't a problem
> right now, but is doing so a good idea in general?

As above - there are by definition no bits to preserve.

>> @@ -316,22 +316,20 @@ static int iommu_read_log(struct amd_iommu *iommu,
>>          IOMMU_PPR_LOG_HEAD_OFFSET;
>>  
>>      tail = readl(iommu->mmio_base + tail_offest);
>> -    tail = iommu_get_rb_pointer(tail);
>>  
>>      while ( tail != log->head )
>>      {
>>          /* read event log entry */
>> -        entry = (u32 *)(log->buffer + log->head * entry_size);
>> +        entry = (u32 *)(log->buffer + log->head);
> Would you mind dropping the pointless cast here at the same time?

Can do.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2020-02-10 14:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-03 14:43 [Xen-devel] [PATCH 0/4] AMD/IOMMU: Cleanup Andrew Cooper
2020-02-03 14:43 ` [Xen-devel] [PATCH 1/4] AMD/IOMMU: Move headers to be local Andrew Cooper
2020-02-03 16:24   ` George Dunlap
2020-02-05  9:47   ` Jan Beulich
2020-02-10 14:30     ` Andrew Cooper
2020-02-10 14:56       ` Jan Beulich
2020-02-03 14:43 ` [Xen-devel] [PATCH 2/4] AMD/IOMMU: Delete iommu_{get, set, clear}_bit() helpers Andrew Cooper
2020-02-05  9:57   ` Jan Beulich
2020-02-10 14:39     ` Andrew Cooper
2020-02-10 14:59       ` Jan Beulich
2020-02-03 14:43 ` [Xen-devel] [PATCH 3/4] AMD/IOMMU: Treat guest head/tail pointers as byte offsets Andrew Cooper
2020-02-05 10:22   ` Jan Beulich
2020-02-10 15:01     ` Andrew Cooper
2020-02-03 14:43 ` [Xen-devel] [PATCH 4/4] AMD/IOMMU: Treat " Andrew Cooper
2020-02-05 10:36   ` Jan Beulich
2020-02-10 14:55     ` Andrew Cooper [this message]
2020-02-10 15:02       ` Jan Beulich
2020-02-10 15:19         ` Andrew Cooper
2020-02-10 16:38           ` Jan Beulich
2020-02-10 17:33   ` [Xen-devel] [PATCH v2 " Andrew Cooper
2020-02-11  9:23     ` Jan Beulich

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=cf596ea9-f9dd-b938-9666-34165edb8a0c@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.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.