Re: [PATCH v4 02/22] iommu: introduce device fault data

From: Jean-Philippe Brucker
Date: Wed Mar 06 2019 - 07:08:30 EST


On 06/03/2019 09:38, Auger Eric wrote:
>>> +struct iommu_fault_unrecoverable {
>>> +ÂÂÂ __u32ÂÂ reason; /* enum iommu_fault_reason */
>>> +#define IOMMU_FAULT_UNRECOV_PASID_VALIDÂÂÂÂÂÂÂÂÂÂÂÂ (1 << 0)
>>> +#define IOMMU_FAULT_UNRECOV_PERM_VALIDÂÂÂÂÂÂÂÂÂÂÂÂÂ (1 << 1)
>>
>> Not needed, since @perm is already a bitfield
> not exactly, READ is encoded as 0. We need to differentiate read fault
> from no perm provided. However if I follow your recommendation below and
> transform the READ FAULT into a set bit this makes sense.

Ah yes, seeing four defines I assumed read was in there. No need for
INST I think, it's already described by EXEC

>>> +#define IOMMU_FAULT_UNRECOV_ADDR_VALIDÂÂÂÂÂÂÂÂÂÂÂÂÂ (1 << 2)
>>> +#define IOMMU_FAULT_UNRECOV_FETCH_ADDR_VALIDÂÂÂÂÂÂÂ (1 << 3)
>>> +ÂÂÂ __u32ÂÂ flags;
>>> +ÂÂÂ __u32ÂÂ pasid;
>>> +#define IOMMU_FAULT_PERM_WRITEÂÂÂÂÂ (1 << 0) /* write */
>>> +#define IOMMU_FAULT_PERM_EXECÂÂÂÂÂÂ (1 << 1) /* exec */
>>> +#define IOMMU_FAULT_PERM_PRIVÂÂÂÂÂÂ (1 << 2) /* priviledged */
>>
>> typo "privileged"
> OK
>>
>>> +#define IOMMU_FAULT_PERM_INSTÂÂÂÂÂÂ (1 << 3) /* instruction */
>>
>> Could you move these outside the struct definition? They are shared with
>> the other struct. And it would be less confusing, from the device driver
>> point of view, to merge those with the existing IOMMU_FAULT_* defines
>> (but moving them to UAPI and making them bits)
> ok I will look at this. Need to check if the read fault value is not
> hardcoded anywhere.

Oh right, looks like a couple of IOMMU drivers do. Hard to say if they
mean READ or just "don't care", at first glance. I guess we can keep the
FAULT_PERM variant until we actually unify the fault reporting API (not
overly complicated since there are three users. I have patches for that
buried somewhere)

>>
>>> +ÂÂÂ __u32ÂÂ perm;
>>> +ÂÂÂ __u64ÂÂ addr;
>>> +ÂÂÂ __u64ÂÂ fetch_addr;
>>> +};
>>> +
>>> +/*
>>> + * Page Request data (aka. recoverable fault data)
>>> + * @flags : encodes whether the pasid is valid and whether this
>>> + * is the last page in group
>>> + * @pasid: pasid
>>> + * @grpid: page request group index
>>> + * @perm: requested page permissions
>>> + * @addr: page address
>>> + */
>>> +struct iommu_fault_page_request {
>>> +#define IOMMU_FAULT_PAGE_REQUEST_PASID_PRESENTÂÂÂÂÂ (1 << 0)
>>
>> PASID_VALID, to be consistent with the other set of flags?
> OK
>>
>>> +#define IOMMU_FAULT_PAGE_REQUEST_LAST_PAGEÂ (1 << 1)
>>> +#define IOMMU_FAULT_PAGE_REQUEST_PRIV_DATAÂ (1 << 2)
>>> +ÂÂÂ __u32ÂÂ flags;
>>> +ÂÂÂ __u32ÂÂ pasid;
>>> +ÂÂÂ __u32ÂÂ grpid;
>>> +ÂÂÂ __u32ÂÂ perm;
>>> +ÂÂÂ __u64ÂÂ addr;
>>
>> Given that we'll be reporting stall faults using this struct, it would
>> be good to have the fetch_addr field and flag here as well.
> OK
>>
>>> +ÂÂÂ __u64ÂÂ private_data[2];
>>> +};
>>> +
>>> +/**
>>> + * struct iommu_fault - Generic fault data
>>> + *
>>> + * @type contains fault type
>>> + */
>>> +
>>> +struct iommu_fault {
>>> +ÂÂÂ __u32ÂÂ type;ÂÂ /* enum iommu_fault_type */
>>> +ÂÂÂ __u32ÂÂ reserved;
>>> +ÂÂÂ union {
>>> +ÂÂÂÂÂÂÂÂÂÂÂ struct iommu_fault_unrecoverable event;
>>> +ÂÂÂÂÂÂÂÂÂÂÂ struct iommu_fault_page_request prm;
>>
>> What's the 'm' in "prm"? Maybe just "pr"?
> This stands for page request message, I think this is the Intel's naming?

Looks like it's the PCI naming, let's stick with it then

Thanks,
Jean