Re: [PATCH v2 2/2] iommu/vt-d: skip invalid RMRR entries

2020-01-10 Thread Chen, Yian

Hi Barret,

this looks good.

thanks
Yian

On 1/7/2020 11:16 AM, Barret Rhoden wrote:

The VT-d docs specify requirements for the RMRR entries base and end
(called 'Limit' in the docs) addresses.

This commit will cause the DMAR processing to skip any RMRR entries that
do not meet these requirements and mark the firmware as tainted, since
the firmware is giving us junk.

Signed-off-by: Barret Rhoden 
---
  drivers/iommu/intel-iommu.c | 14 +-
  1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a8bb458845bc..32c3c6338a3d 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4315,13 +4315,25 @@ static void __init init_iommu_pm_ops(void)
  static inline void init_iommu_pm_ops(void) {}
  #endif/* CONFIG_PM */
  
+static int rmrr_validity_check(struct acpi_dmar_reserved_memory *rmrr)

+{
+   if ((rmrr->base_address & PAGE_MASK) ||
+   (rmrr->end_address <= rmrr->base_address) ||
+   ((rmrr->end_address - rmrr->base_address + 1) & PAGE_MASK)) {
+   pr_err(FW_BUG "Broken RMRR base: %#018Lx end: %#018Lx\n",
+  rmrr->base_address, rmrr->end_address);
+   return -EINVAL;
+   }
+   return 0;
+}
+
  int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
  {
struct acpi_dmar_reserved_memory *rmrr;
struct dmar_rmrr_unit *rmrru;
  
  	rmrr = (struct acpi_dmar_reserved_memory *)header;

-   if (arch_rmrr_sanity_check(rmrr)) {
+   if (rmrr_validity_check(rmrr) || arch_rmrr_sanity_check(rmrr)) {
WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
   "Your BIOS is broken; bad RMRR [%#018Lx-%#018Lx]\n"
   "BIOS vendor: %s; Ver: %s; Product Version: %s\n",


___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [PATCH v2 2/2] iommu/vt-d: skip invalid RMRR entries

2020-01-08 Thread Barret Rhoden via iommu

On 1/7/20 8:27 PM, Lu Baolu wrote:

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a8bb458845bc..32c3c6338a3d 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4315,13 +4315,25 @@ static void __init init_iommu_pm_ops(void)
  static inline void init_iommu_pm_ops(void) {}
  #endif    /* CONFIG_PM */
+static int rmrr_validity_check(struct acpi_dmar_reserved_memory *rmrr)
+{
+    if ((rmrr->base_address & PAGE_MASK) ||
+    (rmrr->end_address <= rmrr->base_address) ||
+    ((rmrr->end_address - rmrr->base_address + 1) & PAGE_MASK)) {
+    pr_err(FW_BUG "Broken RMRR base: %#018Lx end: %#018Lx\n",
+   rmrr->base_address, rmrr->end_address);


Since you will WARN_TAINT below, do you still want an error message
here?


I'm fine either way.

I put it in since arch_rmrr_sanity_check() also has a pr_err():

pr_err(FW_BUG "No firmware reserved region can cover this RMRR
   [%#018Lx-%#018Lx], contact BIOS vendor for fixes\n",
   start, end - 1);

Thanks,

Barret

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

Re: [PATCH v2 2/2] iommu/vt-d: skip invalid RMRR entries

2020-01-07 Thread Lu Baolu

Hi,

On 1/8/20 3:16 AM, Barret Rhoden via iommu wrote:

The VT-d docs specify requirements for the RMRR entries base and end
(called 'Limit' in the docs) addresses.

This commit will cause the DMAR processing to skip any RMRR entries that
do not meet these requirements and mark the firmware as tainted, since
the firmware is giving us junk.

Signed-off-by: Barret Rhoden 
---
  drivers/iommu/intel-iommu.c | 14 +-
  1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a8bb458845bc..32c3c6338a3d 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4315,13 +4315,25 @@ static void __init init_iommu_pm_ops(void)
  static inline void init_iommu_pm_ops(void) {}
  #endif/* CONFIG_PM */
  
+static int rmrr_validity_check(struct acpi_dmar_reserved_memory *rmrr)

+{
+   if ((rmrr->base_address & PAGE_MASK) ||
+   (rmrr->end_address <= rmrr->base_address) ||
+   ((rmrr->end_address - rmrr->base_address + 1) & PAGE_MASK)) {
+   pr_err(FW_BUG "Broken RMRR base: %#018Lx end: %#018Lx\n",
+  rmrr->base_address, rmrr->end_address);


Since you will WARN_TAINT below, do you still want an error message
here?


+   return -EINVAL;
+   }
+   return 0;
+}
+
  int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
  {
struct acpi_dmar_reserved_memory *rmrr;
struct dmar_rmrr_unit *rmrru;
  
  	rmrr = (struct acpi_dmar_reserved_memory *)header;

-   if (arch_rmrr_sanity_check(rmrr)) {
+   if (rmrr_validity_check(rmrr) || arch_rmrr_sanity_check(rmrr)) {
WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
   "Your BIOS is broken; bad RMRR [%#018Lx-%#018Lx]\n"
   "BIOS vendor: %s; Ver: %s; Product Version: %s\n",



Best regards,
baolu
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[PATCH v2 2/2] iommu/vt-d: skip invalid RMRR entries

2020-01-07 Thread Barret Rhoden via iommu
The VT-d docs specify requirements for the RMRR entries base and end
(called 'Limit' in the docs) addresses.

This commit will cause the DMAR processing to skip any RMRR entries that
do not meet these requirements and mark the firmware as tainted, since
the firmware is giving us junk.

Signed-off-by: Barret Rhoden 
---
 drivers/iommu/intel-iommu.c | 14 +-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index a8bb458845bc..32c3c6338a3d 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -4315,13 +4315,25 @@ static void __init init_iommu_pm_ops(void)
 static inline void init_iommu_pm_ops(void) {}
 #endif /* CONFIG_PM */
 
+static int rmrr_validity_check(struct acpi_dmar_reserved_memory *rmrr)
+{
+   if ((rmrr->base_address & PAGE_MASK) ||
+   (rmrr->end_address <= rmrr->base_address) ||
+   ((rmrr->end_address - rmrr->base_address + 1) & PAGE_MASK)) {
+   pr_err(FW_BUG "Broken RMRR base: %#018Lx end: %#018Lx\n",
+  rmrr->base_address, rmrr->end_address);
+   return -EINVAL;
+   }
+   return 0;
+}
+
 int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
 {
struct acpi_dmar_reserved_memory *rmrr;
struct dmar_rmrr_unit *rmrru;
 
rmrr = (struct acpi_dmar_reserved_memory *)header;
-   if (arch_rmrr_sanity_check(rmrr)) {
+   if (rmrr_validity_check(rmrr) || arch_rmrr_sanity_check(rmrr)) {
WARN_TAINT(1, TAINT_FIRMWARE_WORKAROUND,
   "Your BIOS is broken; bad RMRR [%#018Lx-%#018Lx]\n"
   "BIOS vendor: %s; Ver: %s; Product Version: %s\n",
-- 
2.24.1.735.g03f4e72817-goog

___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu