Re: [RFC PATCH v4 11/28] x86: Add support to determine the E820 type of an address

2017-03-03 Thread Borislav Petkov
On Tue, Feb 28, 2017 at 04:34:39PM -0600, Tom Lendacky wrote:
> Or if we want to guard against ACPI adding a type 0 in the future, I
> could make the function return an int and then return -EINVAL if an e820
> entry isn't found.  This might be the better option.

Yap, think so too. I don't trust specs anyway :)

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


Re: [RFC PATCH v4 11/28] x86: Add support to determine the E820 type of an address

2017-02-28 Thread Tom Lendacky

On 2/20/2017 2:09 PM, Borislav Petkov wrote:

On Thu, Feb 16, 2017 at 09:44:30AM -0600, Tom Lendacky wrote:

This patch adds support to return the E820 type associated with an address


s/This patch adds/Add/


range.

Signed-off-by: Tom Lendacky 
---
 arch/x86/include/asm/e820/api.h   |2 ++
 arch/x86/include/asm/e820/types.h |2 ++
 arch/x86/kernel/e820.c|   26 +++---
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 8e0f8b8..7c1bdc9 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -38,6 +38,8 @@
 extern void e820__reallocate_tables(void);
 extern void e820__register_nosave_regions(unsigned long limit_pfn);

+extern enum e820_type e820__get_entry_type(u64 start, u64 end);
+
 /*
  * Returns true iff the specified range [start,end) is completely contained 
inside
  * the ISA region.
diff --git a/arch/x86/include/asm/e820/types.h 
b/arch/x86/include/asm/e820/types.h
index 4adeed0..bf49591 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -7,6 +7,8 @@
  * These are the E820 types known to the kernel:
  */
 enum e820_type {
+   E820_TYPE_INVALID   = 0,
+


Now this is strange - ACPI spec doesn't explicitly say that range type 0
is invalid. Am I looking at the wrong place?

"Table 15-312 Address Range Types12" in ACPI spec 6.

If 0 is really the invalid entry, then e820_print_type() needs updating
too. And then the invalid-entry-add should be a separate patch.


The 0 return (originally) was to indicate that an e820 entry for the
range wasn't found. This series just gave it a name.  So it's not that
the type field held a 0.  Since 0 isn't defined in the ACPI spec I don't
see an issue with creating it and I can add a comment to the effect that
this value is used for the type when an e820 entry isn't found. I could
always rename it to E820_TYPE_NOT_FOUND if that would help.

Or if we want to guard against ACPI adding a type 0 in the future, I
could make the function return an int and then return -EINVAL if an e820
entry isn't found.  This might be the better option.

Thanks,
Tom





E820_TYPE_RAM   = 1,
E820_TYPE_RESERVED  = 2,
E820_TYPE_ACPI  = 3,



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


Re: [RFC PATCH v4 11/28] x86: Add support to determine the E820 type of an address

2017-02-20 Thread Borislav Petkov
On Thu, Feb 16, 2017 at 09:44:30AM -0600, Tom Lendacky wrote:
> This patch adds support to return the E820 type associated with an address

s/This patch adds/Add/

> range.
> 
> Signed-off-by: Tom Lendacky 
> ---
>  arch/x86/include/asm/e820/api.h   |2 ++
>  arch/x86/include/asm/e820/types.h |2 ++
>  arch/x86/kernel/e820.c|   26 +++---
>  3 files changed, 27 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
> index 8e0f8b8..7c1bdc9 100644
> --- a/arch/x86/include/asm/e820/api.h
> +++ b/arch/x86/include/asm/e820/api.h
> @@ -38,6 +38,8 @@
>  extern void e820__reallocate_tables(void);
>  extern void e820__register_nosave_regions(unsigned long limit_pfn);
>  
> +extern enum e820_type e820__get_entry_type(u64 start, u64 end);
> +
>  /*
>   * Returns true iff the specified range [start,end) is completely contained 
> inside
>   * the ISA region.
> diff --git a/arch/x86/include/asm/e820/types.h 
> b/arch/x86/include/asm/e820/types.h
> index 4adeed0..bf49591 100644
> --- a/arch/x86/include/asm/e820/types.h
> +++ b/arch/x86/include/asm/e820/types.h
> @@ -7,6 +7,8 @@
>   * These are the E820 types known to the kernel:
>   */
>  enum e820_type {
> + E820_TYPE_INVALID   = 0,
> +

Now this is strange - ACPI spec doesn't explicitly say that range type 0
is invalid. Am I looking at the wrong place?

"Table 15-312 Address Range Types12" in ACPI spec 6.

If 0 is really the invalid entry, then e820_print_type() needs updating
too. And then the invalid-entry-add should be a separate patch.

>   E820_TYPE_RAM   = 1,
>   E820_TYPE_RESERVED  = 2,
>   E820_TYPE_ACPI  = 3,

-- 
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
___
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu


[RFC PATCH v4 11/28] x86: Add support to determine the E820 type of an address

2017-02-16 Thread Tom Lendacky
This patch adds support to return the E820 type associated with an address
range.

Signed-off-by: Tom Lendacky 
---
 arch/x86/include/asm/e820/api.h   |2 ++
 arch/x86/include/asm/e820/types.h |2 ++
 arch/x86/kernel/e820.c|   26 +++---
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h
index 8e0f8b8..7c1bdc9 100644
--- a/arch/x86/include/asm/e820/api.h
+++ b/arch/x86/include/asm/e820/api.h
@@ -38,6 +38,8 @@
 extern void e820__reallocate_tables(void);
 extern void e820__register_nosave_regions(unsigned long limit_pfn);
 
+extern enum e820_type e820__get_entry_type(u64 start, u64 end);
+
 /*
  * Returns true iff the specified range [start,end) is completely contained 
inside
  * the ISA region.
diff --git a/arch/x86/include/asm/e820/types.h 
b/arch/x86/include/asm/e820/types.h
index 4adeed0..bf49591 100644
--- a/arch/x86/include/asm/e820/types.h
+++ b/arch/x86/include/asm/e820/types.h
@@ -7,6 +7,8 @@
  * These are the E820 types known to the kernel:
  */
 enum e820_type {
+   E820_TYPE_INVALID   = 0,
+
E820_TYPE_RAM   = 1,
E820_TYPE_RESERVED  = 2,
E820_TYPE_ACPI  = 3,
diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
index 6e9b26f..2ee7ee2 100644
--- a/arch/x86/kernel/e820.c
+++ b/arch/x86/kernel/e820.c
@@ -84,7 +84,8 @@ bool e820__mapped_any(u64 start, u64 end, enum e820_type type)
  * Note: this function only works correctly once the E820 table is sorted and
  * not-overlapping (at least for the range specified), which is the case 
normally.
  */
-bool __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
+static struct e820_entry *__e820__mapped_all(u64 start, u64 end,
+enum e820_type type)
 {
int i;
 
@@ -110,9 +111,28 @@ bool __init e820__mapped_all(u64 start, u64 end, enum 
e820_type type)
 * coverage of the desired range exists:
 */
if (start >= end)
-   return 1;
+   return entry;
}
-   return 0;
+
+   return NULL;
+}
+
+/*
+ * This function checks if the entire range  is mapped with type.
+ */
+bool __init e820__mapped_all(u64 start, u64 end, enum e820_type type)
+{
+   return __e820__mapped_all(start, end, type) ? 1 : 0;
+}
+
+/*
+ * This function returns the type associated with the range .
+ */
+enum e820_type e820__get_entry_type(u64 start, u64 end)
+{
+   struct e820_entry *entry = __e820__mapped_all(start, end, 0);
+
+   return entry ? entry->type : E820_TYPE_INVALID;
 }
 
 /*

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