Linux IOMMU Development
 help / color / mirror / Atom feed
From: Lennert Buytenhek <buytenh@wantstofly.org>
To: "Suthikulpanit, Suravee" <suravee.suthikulpanit@amd.com>
Cc: Ohad Ben-Cohen <ohad@wizery.com>, iommu@lists.linux-foundation.org
Subject: Re: [PATCH v2] iommu/amd: Use report_iommu_fault()
Date: Sat, 21 Aug 2021 18:44:39 +0300	[thread overview]
Message-ID: <YSEfZyrLSWR0gFDu@wantstofly.org> (raw)
In-Reply-To: <0d353fc0-79d0-36b7-eeee-ba27249bb258@amd.com>

On Thu, Aug 05, 2021 at 11:26:25AM -0500, Suthikulpanit, Suravee wrote:

> Lennert,

Hi Suravee,


> > - EVENT_FLAG_I unset, but the request was a translation request
> >   (EVENT_FLAG_TR set) or the target page was not present
> >   (EVENT_FLAG_PR unset): call report_iommu_fault(), but the RW
> >   bit will be invalid, so don't try to map it to a
> >   IOMMU_FAULT_{READ,WRITE} code
> 
> So, why do we need to call report_iommu_fault() for this case?
> My understanding is we only have IOMMU_FAULT_[READ|WRITE].
> So, if we can't identify whether the DMA is read / write,
> we should not need to call report_iommu_fauilt(), is it?

I don't think that we should just altogether avoid logging the subset
of page faults for which we can't determine the read/write direction
on AMD platforms.

E.g. "access to an unmapped address" (which will have PR=0, and thus we
won't know if it was a read or a write access) is just as much of a page
fault as "write to a read-only page" (which will have PR=1, and thus the
RW bit will be accurate) is, and for RAS purposes, both events are
equally interesting, and important to know about.

It's true that we currently don't have a way of signaling to
report_iommu_fault() (and by extension, to the io_page_fault
tracepoint) that we're not sure whether the offending access was a read
or a write, but I think we can just add a bit to include/linux/iommu.h
to indicate that, something along the lines of:

	 /* iommu fault flags */
	 #define IOMMU_FAULT_READ        0x0
	 #define IOMMU_FAULT_WRITE       0x1
	+#define IOMMU_FAULT_RW_UNKNOWN  0x2

(Cc'ing Ohad Ben-Cohen, who originally added this API.)

I don't think that it would be a good idea to just not signal the page
faults for which we don't know the read/write direction.


Thanks,
Lennert



> > - EVENT_FLAG_I unset, the request is a transaction request (EVENT_FLAG_TR
> >    unset) and the target page was present (EVENT_FLAG_PR set): call
> >    report_iommu_fault(), and use the RW bit to set IOMMU_FAULT_{READ,WRITE}
> > 
> > So I don't think we can merge the test for EVENT_FLAG_I with the
> > test for EVENT_FLAG_TR/EVENT_FLAG_PR.
> 
> The only condition that we would report_iommu_fault is
> I=0, TR=0, PR=1, isn't it. So we should be able to just check if PR=1.
> 
> 
> > We could do something like this, if you'd prefer:
> > 
> > 	#define IS_IOMMU_MEM_TRANSACTION(flags)	\
> > 		(((flags) & EVENT_FLAG_I) == 0)
> > 
> > 	#define IS_RW_FLAG_VALID(flags)		\
> > 		(((flags) & (EVENT_FLAG_TR | EVENT_FLAG_PR)) == EVENT_FLAG_PR)
> > 
> > 	#define IS_WRITE_REQUEST(flags)		\
> > 		(IS_RW_FLAG_VALID(flags) && (flags & EVENT_FLAG_RW))
> > 
> > And then do something like:
> > 
> > 	if (dev_data && IS_IOMMU_MEM_TRANSACTION(flags)) {
> > 		if (!report_iommu_fault(&dev_data->domain->domain, &pdev->dev,
> > 					address,
> > 					IS_WRITE_REQUEST(flags) ?
> > 					IOMMU_FAULT_WRITE : IOMMU_FAULT_READ))
> 
> Actually, IS_WRITE_REQUEST() == 0 could mean:
> - I=0, TR=0, PR=1 and RW=0: This is fine.
> - I=0, (TR=1 or PR=0), and we should not be calling report_iommu_fault() here
>   since we cannot specify READ/WRITE here.
> 
> Thanks,
> Suravee
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

  reply	other threads:[~2021-08-21 15:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-26 16:31 [PATCH v2] iommu/amd: Use report_iommu_fault() Lennert Buytenhek
2021-07-28 21:51 ` Suthikulpanit, Suravee via iommu
2021-07-30  2:32   ` Lennert Buytenhek
2021-08-03 16:20     ` Lennert Buytenhek
2021-08-05 16:26     ` Suthikulpanit, Suravee via iommu
2021-08-21 15:44       ` Lennert Buytenhek [this message]
2021-09-25 14:09         ` Lennert Buytenhek

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=YSEfZyrLSWR0gFDu@wantstofly.org \
    --to=buytenh@wantstofly.org \
    --cc=iommu@lists.linux-foundation.org \
    --cc=ohad@wizery.com \
    --cc=suravee.suthikulpanit@amd.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