Re: [PATCH]intel-iommu-PMEN support

2007-11-20 Thread mark gross
On Mon, Nov 19, 2007 at 04:38:02PM -0800, Andrew Morton wrote:
> On Fri, 16 Nov 2007 14:39:57 -0800
> mark gross <[EMAIL PROTECTED]> wrote:
> 
> > -#define MAX_FAULT_REASON_IDX   ARRAY_SIZE(fault_reason_strings) - 1
> > +#define MAX_FAULT_REASON_IDX   (ARRAY_SIZE(fault_reason_strings) - 1)
> 
> hm.  The logic in there looks screwy.

I didn't like it when they added the -1 to the above, but after looking
at it sideways for a while I convinced myself that it was ok.  so I
thought it be good to add the parentheses.

> 
> 
> static char *fault_reason_strings[] =
> {
>   "Software",
>   "Present bit in root entry is clear",
>   "Present bit in context entry is clear",
>   "Invalid context entry",
>   "Access beyond MGAW",
>   "PTE Write access is not set",
>   "PTE Read access is not set",
>   "Next page table ptr is invalid",
>   "Root table address invalid",
>   "Context table ptr is invalid",
>   "non-zero reserved fields in RTP",
>   "non-zero reserved fields in CTP",
>   "non-zero reserved fields in PTE",
>   "Unknown"
> };
> #define MAX_FAULT_REASON_IDX  (ARRAY_SIZE(fault_reason_strings) - 1)
> 
> char *dmar_get_fault_reason(u8 fault_reason)
> {
>   if (fault_reason >= MAX_FAULT_REASON_IDX)
>   return fault_reason_strings[MAX_FAULT_REASON_IDX - 1];
>   else
>   return fault_reason_strings[fault_reason];
> }
> 
> 
> so all invalid fault_reasons will cause us to display "non-zero reserved
> fields in PTE".

GAH!  Thats wrong.

I also don't like the use of >= here, its harder for me to parse in my
head than just >.


> 
> Why not just do
> 
>   if (fault_reason >= ARRAY_SIZE(fault_reason_strings))
>   return "Unknown";
>   return fault_reason_strings[fault_reason];
> 
> ?

Why not indeed.  :)

> 
> (might as well make fault_reason_strings[] const, too).

Thats a good thing too.

I'll put together a patch this morning to address these think-ohs.

--mgross
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH]intel-iommu-PMEN support

2007-11-20 Thread mark gross
On Mon, Nov 19, 2007 at 04:38:02PM -0800, Andrew Morton wrote:
 On Fri, 16 Nov 2007 14:39:57 -0800
 mark gross [EMAIL PROTECTED] wrote:
 
  -#define MAX_FAULT_REASON_IDX   ARRAY_SIZE(fault_reason_strings) - 1
  +#define MAX_FAULT_REASON_IDX   (ARRAY_SIZE(fault_reason_strings) - 1)
 
 hm.  The logic in there looks screwy.

I didn't like it when they added the -1 to the above, but after looking
at it sideways for a while I convinced myself that it was ok.  so I
thought it be good to add the parentheses.

 
 
 static char *fault_reason_strings[] =
 {
   Software,
   Present bit in root entry is clear,
   Present bit in context entry is clear,
   Invalid context entry,
   Access beyond MGAW,
   PTE Write access is not set,
   PTE Read access is not set,
   Next page table ptr is invalid,
   Root table address invalid,
   Context table ptr is invalid,
   non-zero reserved fields in RTP,
   non-zero reserved fields in CTP,
   non-zero reserved fields in PTE,
   Unknown
 };
 #define MAX_FAULT_REASON_IDX  (ARRAY_SIZE(fault_reason_strings) - 1)
 
 char *dmar_get_fault_reason(u8 fault_reason)
 {
   if (fault_reason = MAX_FAULT_REASON_IDX)
   return fault_reason_strings[MAX_FAULT_REASON_IDX - 1];
   else
   return fault_reason_strings[fault_reason];
 }
 
 
 so all invalid fault_reasons will cause us to display non-zero reserved
 fields in PTE.

GAH!  Thats wrong.

I also don't like the use of = here, its harder for me to parse in my
head than just .


 
 Why not just do
 
   if (fault_reason = ARRAY_SIZE(fault_reason_strings))
   return Unknown;
   return fault_reason_strings[fault_reason];
 
 ?

Why not indeed.  :)

 
 (might as well make fault_reason_strings[] const, too).

Thats a good thing too.

I'll put together a patch this morning to address these think-ohs.

--mgross
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH]intel-iommu-PMEN support

2007-11-19 Thread Andrew Morton
On Fri, 16 Nov 2007 14:39:57 -0800
mark gross <[EMAIL PROTECTED]> wrote:

> -#define MAX_FAULT_REASON_IDX ARRAY_SIZE(fault_reason_strings) - 1
> +#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)

hm.  The logic in there looks screwy.


static char *fault_reason_strings[] =
{
"Software",
"Present bit in root entry is clear",
"Present bit in context entry is clear",
"Invalid context entry",
"Access beyond MGAW",
"PTE Write access is not set",
"PTE Read access is not set",
"Next page table ptr is invalid",
"Root table address invalid",
"Context table ptr is invalid",
"non-zero reserved fields in RTP",
"non-zero reserved fields in CTP",
"non-zero reserved fields in PTE",
"Unknown"
};
#define MAX_FAULT_REASON_IDX(ARRAY_SIZE(fault_reason_strings) - 1)

char *dmar_get_fault_reason(u8 fault_reason)
{
if (fault_reason >= MAX_FAULT_REASON_IDX)
return fault_reason_strings[MAX_FAULT_REASON_IDX - 1];
else
return fault_reason_strings[fault_reason];
}


so all invalid fault_reasons will cause us to display "non-zero reserved
fields in PTE".

Why not just do

if (fault_reason >= ARRAY_SIZE(fault_reason_strings))
return "Unknown";
return fault_reason_strings[fault_reason];

?

(might as well make fault_reason_strings[] const, too).
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH]intel-iommu-PMEN support

2007-11-19 Thread Andrew Morton
On Fri, 16 Nov 2007 14:39:57 -0800
mark gross [EMAIL PROTECTED] wrote:

 -#define MAX_FAULT_REASON_IDX ARRAY_SIZE(fault_reason_strings) - 1
 +#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)

hm.  The logic in there looks screwy.


static char *fault_reason_strings[] =
{
Software,
Present bit in root entry is clear,
Present bit in context entry is clear,
Invalid context entry,
Access beyond MGAW,
PTE Write access is not set,
PTE Read access is not set,
Next page table ptr is invalid,
Root table address invalid,
Context table ptr is invalid,
non-zero reserved fields in RTP,
non-zero reserved fields in CTP,
non-zero reserved fields in PTE,
Unknown
};
#define MAX_FAULT_REASON_IDX(ARRAY_SIZE(fault_reason_strings) - 1)

char *dmar_get_fault_reason(u8 fault_reason)
{
if (fault_reason = MAX_FAULT_REASON_IDX)
return fault_reason_strings[MAX_FAULT_REASON_IDX - 1];
else
return fault_reason_strings[fault_reason];
}


so all invalid fault_reasons will cause us to display non-zero reserved
fields in PTE.

Why not just do

if (fault_reason = ARRAY_SIZE(fault_reason_strings))
return Unknown;
return fault_reason_strings[fault_reason];

?

(might as well make fault_reason_strings[] const, too).
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH]intel-iommu-PMEN support

2007-11-17 Thread Muli Ben-Yehuda
On Fri, Nov 16, 2007 at 02:39:57PM -0800, mark gross wrote:

> The following patch adds support for protected memory enable bits by
> clearing them if they are set at startup time.  Some future boot
> loaders or firmware could have this bit set after it loads the
> kernel, and it needs to be cleared if DMA's are going to happen
> effectively.
> 
> please apply
> 
> --mgross
> 
> Signed-off-by: mark gross <[EMAIL PROTECTED]>

Acked-by: Muli Ben-Yehuda <[EMAIL PROTECTED]>

Mark, please try in the future to not mix unrelated changes such as
these. This patch should've been two patches, one to disable protected
memory enable and the other to do the cleanups.

> -#define MAX_FAULT_REASON_IDX ARRAY_SIZE(fault_reason_strings) - 1
> +#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)

> -static inline u64 dmar_readq(void *addr)
> +static inline u64 dmar_readq(void __iomem *addr)

Cheers,
Muli
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH]intel-iommu-PMEN support

2007-11-17 Thread Muli Ben-Yehuda
On Fri, Nov 16, 2007 at 02:39:57PM -0800, mark gross wrote:

 The following patch adds support for protected memory enable bits by
 clearing them if they are set at startup time.  Some future boot
 loaders or firmware could have this bit set after it loads the
 kernel, and it needs to be cleared if DMA's are going to happen
 effectively.
 
 please apply
 
 --mgross
 
 Signed-off-by: mark gross [EMAIL PROTECTED]

Acked-by: Muli Ben-Yehuda [EMAIL PROTECTED]

Mark, please try in the future to not mix unrelated changes such as
these. This patch should've been two patches, one to disable protected
memory enable and the other to do the cleanups.

 -#define MAX_FAULT_REASON_IDX ARRAY_SIZE(fault_reason_strings) - 1
 +#define MAX_FAULT_REASON_IDX (ARRAY_SIZE(fault_reason_strings) - 1)

 -static inline u64 dmar_readq(void *addr)
 +static inline u64 dmar_readq(void __iomem *addr)

Cheers,
Muli
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH]intel-iommu-PMEN support

2007-11-16 Thread mark gross
The following patch adds support for protected memory enable bits by
clearing them if they are set at startup time.  Some future boot loaders
or firmware could have this bit set after it loads the kernel, and it
needs to be cleared if DMA's are going to happen effectively.

please apply

--mgross

Signed-off-by: mark gross <[EMAIL PROTECTED]>


Index: linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.c
===
--- linux-2.6.23-rc2-iommu.orig/drivers/pci/intel-iommu.c   2007-11-16 
13:25:14.0 -0800
+++ linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.c2007-11-16 
13:26:07.0 -0800
@@ -692,6 +692,23 @@
DMA_TLB_PSI_FLUSH, non_present_entry_flush);
 }
 
+static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu)
+{
+   u32 pmen;
+   unsigned long flags;
+
+   spin_lock_irqsave(>register_lock, flags);
+   pmen = readl(iommu->reg + DMAR_PMEN_REG);
+   pmen &= ~DMA_PMEN_EPM;
+   writel(pmen, iommu->reg + DMAR_PMEN_REG);
+
+   /* wait for the protected region status bit to clear */
+   IOMMU_WAIT_OP(iommu, DMAR_PMEN_REG,
+   readl, (pmen & DMA_PMEN_PRS), pmen);
+
+   spin_unlock_irqrestore(>register_lock, flags);
+}
+
 static int iommu_enable_translation(struct intel_iommu *iommu)
 {
u32 sts;
@@ -745,7 +762,7 @@
"non-zero reserved fields in PTE",
"Unknown"
 };
-#define MAX_FAULT_REASON_IDX   ARRAY_SIZE(fault_reason_strings) - 1
+#define MAX_FAULT_REASON_IDX   (ARRAY_SIZE(fault_reason_strings) - 1)
 
 char *dmar_get_fault_reason(u8 fault_reason)
 {
@@ -1730,6 +1747,8 @@
iommu_flush_context_global(iommu, 0);
iommu_flush_iotlb_global(iommu, 0);
 
+   iommu_disable_protect_mem_regions(iommu);
+
ret = iommu_enable_translation(iommu);
if (ret)
goto error;
Index: linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.h
===
--- linux-2.6.23-rc2-iommu.orig/drivers/pci/intel-iommu.h   2007-11-16 
13:26:01.0 -0800
+++ linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.h2007-11-16 
13:26:36.0 -0800
@@ -71,7 +71,7 @@
hi = readl(dmar + reg + 4); \
(((u64) hi) << 32) + lo; })
 */
-static inline u64 dmar_readq(void *addr)
+static inline u64 dmar_readq(void __iomem *addr)
 {
u32 lo, hi;
lo = readl(addr);
@@ -139,6 +139,10 @@
 #define DMA_TLB_IH_NONLEAF (((u64)1) << 6)
 #define DMA_TLB_MAX_SIZE (0x3f)
 
+/* PMEN_REG */
+#define DMA_PMEN_EPM (((u32)1)<<31)
+#define DMA_PMEN_PRS (((u32)1)<<0)
+
 /* GCMD_REG */
 #define DMA_GCMD_TE (((u32)1) << 31)
 #define DMA_GCMD_SRTP (((u32)1) << 30)
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH]intel-iommu-PMEN support

2007-11-16 Thread mark gross
The following patch adds support for protected memory enable bits by
clearing them if they are set at startup time.  Some future boot loaders
or firmware could have this bit set after it loads the kernel, and it
needs to be cleared if DMA's are going to happen effectively.

please apply

--mgross

Signed-off-by: mark gross [EMAIL PROTECTED]


Index: linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.c
===
--- linux-2.6.23-rc2-iommu.orig/drivers/pci/intel-iommu.c   2007-11-16 
13:25:14.0 -0800
+++ linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.c2007-11-16 
13:26:07.0 -0800
@@ -692,6 +692,23 @@
DMA_TLB_PSI_FLUSH, non_present_entry_flush);
 }
 
+static void iommu_disable_protect_mem_regions(struct intel_iommu *iommu)
+{
+   u32 pmen;
+   unsigned long flags;
+
+   spin_lock_irqsave(iommu-register_lock, flags);
+   pmen = readl(iommu-reg + DMAR_PMEN_REG);
+   pmen = ~DMA_PMEN_EPM;
+   writel(pmen, iommu-reg + DMAR_PMEN_REG);
+
+   /* wait for the protected region status bit to clear */
+   IOMMU_WAIT_OP(iommu, DMAR_PMEN_REG,
+   readl, (pmen  DMA_PMEN_PRS), pmen);
+
+   spin_unlock_irqrestore(iommu-register_lock, flags);
+}
+
 static int iommu_enable_translation(struct intel_iommu *iommu)
 {
u32 sts;
@@ -745,7 +762,7 @@
non-zero reserved fields in PTE,
Unknown
 };
-#define MAX_FAULT_REASON_IDX   ARRAY_SIZE(fault_reason_strings) - 1
+#define MAX_FAULT_REASON_IDX   (ARRAY_SIZE(fault_reason_strings) - 1)
 
 char *dmar_get_fault_reason(u8 fault_reason)
 {
@@ -1730,6 +1747,8 @@
iommu_flush_context_global(iommu, 0);
iommu_flush_iotlb_global(iommu, 0);
 
+   iommu_disable_protect_mem_regions(iommu);
+
ret = iommu_enable_translation(iommu);
if (ret)
goto error;
Index: linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.h
===
--- linux-2.6.23-rc2-iommu.orig/drivers/pci/intel-iommu.h   2007-11-16 
13:26:01.0 -0800
+++ linux-2.6.23-rc2-iommu/drivers/pci/intel-iommu.h2007-11-16 
13:26:36.0 -0800
@@ -71,7 +71,7 @@
hi = readl(dmar + reg + 4); \
(((u64) hi)  32) + lo; })
 */
-static inline u64 dmar_readq(void *addr)
+static inline u64 dmar_readq(void __iomem *addr)
 {
u32 lo, hi;
lo = readl(addr);
@@ -139,6 +139,10 @@
 #define DMA_TLB_IH_NONLEAF (((u64)1)  6)
 #define DMA_TLB_MAX_SIZE (0x3f)
 
+/* PMEN_REG */
+#define DMA_PMEN_EPM (((u32)1)31)
+#define DMA_PMEN_PRS (((u32)1)0)
+
 /* GCMD_REG */
 #define DMA_GCMD_TE (((u32)1)  31)
 #define DMA_GCMD_SRTP (((u32)1)  30)
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/