Skip to contentSkip to conversation

Fix broken suspend on some machines

PATCH In review Grzegorz Uriasz 4 participants 8 messages Jun 19, 2020 – Jun 25, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover Fix broken suspend on some machines

Hi,

The included patch is a small subset of a bigger patch set spanning few projects aiming to isolate the GPU in Qubes OS to a dedicated security domain. I'm doing this together with 3 colleagues as part of our Bachelors thesis. While working on the project we came across 2 machines - newer gaming laptops on which the suspend functionality on unmodified xen is completely broken.

The affected machines were able to suspend but not always resume. Even if the resume succeeded then the kernel time was trashed in the dmesg log and the machine never managed to suspend another time. After changing the xen clock to hpet, suspend started working again both on stock xen and Qubes OS - this indicates a bug in the ACPI PM Timer. After disassembling the FADT ACPI table on the ASUS FX504GM I understood that the reported bit width is 32 bits but the flags indicate a 24 bit PM timer.

The included patch fixes the suspend feature on ASUS FX504GM and hopefully other laptops - Probably next week I will test this patch on my friend's laptop where this issue also occurs(suspend is broken, trashed kernel time after resume).

Changes in v2:
- Check pm timer access width
- Proper timer width is set when xpm block is not present
- Cleanup timer initialization

Changes in v3:
- Check pm timer bit offset
- Warn about acpi firmware bugs
- Drop int cast in init_pmtimer
- Merge if's in init_pmtimer

Grzegorz Uriasz (1):
x86/acpi: Use FADT flags to determine the PMTMR width

 xen/arch/x86/acpi/boot.c    | 19 +++++++++++++++----
 xen/arch/x86/time.c         | 12 ++++--------
 xen/include/acpi/acmacros.h |  8 ++++++++
 3 files changed, 27 insertions(+), 12 deletions(-)
Signature · 1 line
2.27.0
#1 lore raw

PATCH v3 1/1 x86/acpi: Use FADT flags to determine the PMTMR width

On some computers the bit width of the PM Timer as reported by ACPI is 32 bits when in fact the FADT flags report correctly that the timer is 24 bits wide. On affected machines such as the ASUS FX504GM and never gaming laptops this results in the inability to resume the machine from suspend. Without this patch suspend is broken on affected machines and even if a machine manages to resume correctly then the kernel time and xen timers are trashed.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Changes in v2:
- Check pm timer access width
- Proper timer width is set when xpm block is not present
- Cleanup timer initialization

Changes in v3:
- Check pm timer bit offset
- Warn about acpi firmware bugs
- Drop int cast in init_pmtimer
- Merge if's in init_pmtimer

---
 xen/arch/x86/acpi/boot.c    | 19 +++++++++++++++----
 xen/arch/x86/time.c         | 12 ++++--------
 xen/include/acpi/acmacros.h |  8 ++++++++
 3 files changed, 27 insertions(+), 12 deletions(-)
xen/arch/x86/acpi/boot.c +15 -4
index bcba52e232..24fd236eb5 100644
@@ -475,10 +475,17 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
 
 #ifdef CONFIG_X86_PM_TIMER
 	/* detect the location of the ACPI PM Timer */
-	if (fadt->header.revision >= FADT2_REVISION_ID) {
+	if (fadt->header.revision >= FADT2_REVISION_ID &&
+	    fadt->xpm_timer_block.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
 		/* FADT rev. 2 */
-		if (fadt->xpm_timer_block.space_id ==
-		    ACPI_ADR_SPACE_SYSTEM_IO) {
+		if (fadt->xpm_timer_block.access_width != 0 &&
+		    ACPI_ACCESS_BIT_WIDTH(fadt->xpm_timer_block.access_width) != 32)
+			printk(KERN_WARNING PREFIX "PM-Timer has invalid access width(%u)\n",
+			       fadt->xpm_timer_block.access_width);
+		else if (fadt->xpm_timer_block.bit_offset != 0)
+			printk(KERN_WARNING PREFIX "PM-Timer has invalid bit offset(%u)\n",
+			       fadt->xpm_timer_block.bit_offset);
+		else {
 			pmtmr_ioport = fadt->xpm_timer_block.address;
 			pmtmr_width = fadt->xpm_timer_block.bit_width;
 		}
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");
+	if (pmtmr_width > 24 && !(fadt->flags & ACPI_FADT_32BIT_TIMER))
+		pmtmr_width = 24;
 	if (pmtmr_ioport)
 		printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x (%u bits)\n",
 		       pmtmr_ioport, pmtmr_width);
xen/arch/x86/time.c +4 -8
index d643590c0a..8a45514908 100644
@@ -457,16 +457,13 @@ static u64 read_pmtimer_count(void)
 static s64 __init init_pmtimer(struct platform_timesource *pts)
 {
     u64 start;
-    u32 count, target, mask = 0xffffff;
+    u32 count, target, mask;
 
-    if ( !pmtmr_ioport || !pmtmr_width )
+    if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
         return 0;
 
-    if ( pmtmr_width == 32 )
-    {
-        pts->counter_bits = 32;
-        mask = 0xffffffff;
-    }
+    pts->counter_bits = pmtmr_width;
+    mask = (1ull << pmtmr_width) - 1;
 
     count = inl(pmtmr_ioport) & mask;
     start = rdtsc_ordered();
@@ -486,7 +483,6 @@ static struct platform_timesource __initdata plt_pmtimer =
     .name = "ACPI PM Timer",
     .frequency = ACPI_PM_FREQUENCY,
     .read_counter = read_pmtimer_count,
-    .counter_bits = 24,
     .init = init_pmtimer
 };
 
xen/include/acpi/acmacros.h +8 -0
index 6765535053..86c503c20f 100644
@@ -121,6 +121,14 @@
 #define ACPI_COMPARE_NAME(a,b)          (!ACPI_STRNCMP (ACPI_CAST_PTR (char,(a)), ACPI_CAST_PTR (char,(b)), ACPI_NAME_SIZE))
 #endif
 
+/*
+ * Algorithm to obtain access bit or byte width.
+ * Can be used with access_width of struct acpi_generic_address and access_size of
+ * struct acpi_resource_generic_register.
+ */
+#define ACPI_ACCESS_BIT_WIDTH(size)     (1 << ((size) + 2))
+#define ACPI_ACCESS_BYTE_WIDTH(size)    (1 << ((size) - 1))
+
 /*
  * Macros for moving data around to/from buffers that are possibly unaligned.
  * If the hardware supports the transfer of unaligned data, just do the store.
Signature · 1 line
2.27.0
Reviewed-by on v3 1/1
#2 lore raw

Re: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 503

Quoted 9 lines · Grzegorz Uriasz
xen/arch/x86/acpi/boot.c +3 -1
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");

Indentation is screwed up here.

Quoted 10 lines
xen/arch/x86/time.c +1 -2
@@ -457,16 +457,13 @@ static u64 read_pmtimer_count(void)
 static s64 __init init_pmtimer(struct platform_timesource *pts)
 {
     u64 start;
-    u32 count, target, mask = 0xffffff;
+    u32 count, target, mask;
 
-    if ( !pmtmr_ioport || !pmtmr_width )

xen/arch/x86/time.c static u64 read_pmtimer_count(void) · line 466

Quoted 10 lines
xen/arch/x86/time.c +3 -5
+    if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
         return 0;
 
-    if ( pmtmr_width == 32 )
-    {
-        pts->counter_bits = 32;
-        mask = 0xffffffff;
-    }
+    pts->counter_bits = pmtmr_width;
+    mask = (1ull << pmtmr_width) - 1;

"mask" being of "u32" type, the use of 1ull is certainly a little odd here, and one of the reasons why I think this extra "cleanup" would better go in a separate patch.

Seeing that besides cosmetic aspects the patch looks okay now, I'd be willing to leave the bigger adjustment mostly as is, albeit I'd prefer the 1ull to go away, by instead switching to e.g.

    mask = 0xffffffff >> (32 - pmtmr_width);

With the adjustments (which I'd be happy to make while committing, provided you agree)

Also Cc-ing Paul for a possible release ack (considering this is a backporting candidate).

Jan

#5 lore raw

Re: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

In reply to Grzegorz Uriasz
Quoted 44 lines · Grzegorz Uriasz

On some computers the bit width of the PM Timer as reported by ACPI is 32 bits when in fact the FADT flags report correctly that the timer is 24 bits wide. On affected machines such as the ASUS FX504GM and never gaming laptops this results in the inability to resume the machine from suspend. Without this patch suspend is broken on affected machines and even if a machine manages to resume correctly then the kernel time and xen timers are trashed.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Changes in v2:
- Check pm timer access width
- Proper timer width is set when xpm block is not present
- Cleanup timer initialization

Changes in v3:
- Check pm timer bit offset
- Warn about acpi firmware bugs
- Drop int cast in init_pmtimer
- Merge if's in init_pmtimer

---
 xen/arch/x86/acpi/boot.c    | 19 +++++++++++++++----
 xen/arch/x86/time.c         | 12 ++++--------
 xen/include/acpi/acmacros.h |  8 ++++++++
 3 files changed, 27 insertions(+), 12 deletions(-)
xen/arch/x86/acpi/boot.c +0 -1
index bcba52e232..24fd236eb5 100644
@@ -475,10 +475,17 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
 
 #ifdef CONFIG_X86_PM_TIMER
 	/* detect the location of the ACPI PM Timer */
-	if (fadt->header.revision >= FADT2_REVISION_ID) {

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 485

Quoted 10 lines
xen/arch/x86/acpi/boot.c +7 -2
+	if (fadt->header.revision >= FADT2_REVISION_ID &&
+	    fadt->xpm_timer_block.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
 		/* FADT rev. 2 */
-		if (fadt->xpm_timer_block.space_id ==
-		    ACPI_ADR_SPACE_SYSTEM_IO) {
+		if (fadt->xpm_timer_block.access_width != 0 &&
+		    ACPI_ACCESS_BIT_WIDTH(fadt->xpm_timer_block.access_width) != 32)
+			printk(KERN_WARNING PREFIX "PM-Timer has invalid access width(%u)\n",
+			       fadt->xpm_timer_block.access_width);
+		else if (fadt->xpm_timer_block.bit_offset != 0)

This should be a plain if instead of an else if, it's possible the block has both the access_width and the bit_offset wrong.

Quoted 7 lines
xen/arch/x86/acpi/boot.c +3 -0
+			printk(KERN_WARNING PREFIX "PM-Timer has invalid bit offset(%u)\n",
+			       fadt->xpm_timer_block.bit_offset);
+		else {
 			pmtmr_ioport = fadt->xpm_timer_block.address;
 			pmtmr_width = fadt->xpm_timer_block.bit_width;
 		}

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 503

Quoted 8 lines
xen/arch/x86/acpi/boot.c +3 -1
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");

Indentation. Also this should be a fatal error likely? You should set pmtmr_ioport = 0?

Quoted 43 lines
xen/arch/x86/acpi/boot.c +2 -0
+	if (pmtmr_width > 24 && !(fadt->flags & ACPI_FADT_32BIT_TIMER))
+		pmtmr_width = 24;
 	if (pmtmr_ioport)
 		printk(KERN_INFO PREFIX "PM-Timer IO Port: %#x (%u bits)\n",
 		       pmtmr_ioport, pmtmr_width);
xen/arch/x86/time.c +4 -8
index d643590c0a..8a45514908 100644
@@ -457,16 +457,13 @@ static u64 read_pmtimer_count(void)
 static s64 __init init_pmtimer(struct platform_timesource *pts)
 {
     u64 start;
-    u32 count, target, mask = 0xffffff;
+    u32 count, target, mask;
 
-    if ( !pmtmr_ioport || !pmtmr_width )
+    if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
         return 0;
 
-    if ( pmtmr_width == 32 )
-    {
-        pts->counter_bits = 32;
-        mask = 0xffffffff;
-    }
+    pts->counter_bits = pmtmr_width;
+    mask = (1ull << pmtmr_width) - 1;
 
     count = inl(pmtmr_ioport) & mask;
     start = rdtsc_ordered();
@@ -486,7 +483,6 @@ static struct platform_timesource __initdata plt_pmtimer =
     .name = "ACPI PM Timer",
     .frequency = ACPI_PM_FREQUENCY,
     .read_counter = read_pmtimer_count,
-    .counter_bits = 24,
     .init = init_pmtimer
 };
 
xen/include/acpi/acmacros.h +0 -0
index 6765535053..86c503c20f 100644

xen/include/acpi/acmacros.h line 130

Quoted 10 lines
xen/include/acpi/acmacros.h +7 -0
@@ -121,6 +121,14 @@
 #define ACPI_COMPARE_NAME(a,b)          (!ACPI_STRNCMP (ACPI_CAST_PTR (char,(a)), ACPI_CAST_PTR (char,(b)), ACPI_NAME_SIZE))
 #endif
 
+/*
+ * Algorithm to obtain access bit or byte width.
+ * Can be used with access_width of struct acpi_generic_address and access_size of
+ * struct acpi_resource_generic_register.
+ */
+#define ACPI_ACCESS_BIT_WIDTH(size)     (1 << ((size) + 2))
+#define ACPI_ACCESS_BYTE_WIDTH(size)    (1 << ((size) - 1))

Note sure I would introduce this last one, since it's not used by the code.

Thanks, Roger.

#6 lore raw

Re: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

Quoted 42 lines · Roger Pau Monné
Quoted 41 lines · Grzegorz Uriasz

On some computers the bit width of the PM Timer as reported by ACPI is 32 bits when in fact the FADT flags report correctly that the timer is 24 bits wide. On affected machines such as the ASUS FX504GM and never gaming laptops this results in the inability to resume the machine from suspend. Without this patch suspend is broken on affected machines and even if a machine manages to resume correctly then the kernel time and xen timers are trashed.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]

Changes in v2:
- Check pm timer access width
- Proper timer width is set when xpm block is not present
- Cleanup timer initialization

Changes in v3:
- Check pm timer bit offset
- Warn about acpi firmware bugs
- Drop int cast in init_pmtimer
- Merge if's in init_pmtimer

---
 xen/arch/x86/acpi/boot.c    | 19 +++++++++++++++----
 xen/arch/x86/time.c         | 12 ++++--------
 xen/include/acpi/acmacros.h |  8 ++++++++
 3 files changed, 27 insertions(+), 12 deletions(-)
xen/arch/x86/acpi/boot.c +0 -0
index bcba52e232..24fd236eb5 100644
@@ -475,10 +475,17 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
 
Quoted 16 lines

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 485

Quoted 13 lines
xen/arch/x86/acpi/boot.c +7 -3
 #ifdef CONFIG_X86_PM_TIMER
 	/* detect the location of the ACPI PM Timer */
-	if (fadt->header.revision >= FADT2_REVISION_ID) {
+	if (fadt->header.revision >= FADT2_REVISION_ID &&
+	    fadt->xpm_timer_block.space_id == ACPI_ADR_SPACE_SYSTEM_IO) {
 		/* FADT rev. 2 */
-		if (fadt->xpm_timer_block.space_id ==
-		    ACPI_ADR_SPACE_SYSTEM_IO) {
+		if (fadt->xpm_timer_block.access_width != 0 &&
+		    ACPI_ACCESS_BIT_WIDTH(fadt->xpm_timer_block.access_width) != 32)
+			printk(KERN_WARNING PREFIX "PM-Timer has invalid access width(%u)\n",
+			       fadt->xpm_timer_block.access_width);
+		else if (fadt->xpm_timer_block.bit_offset != 0)

This should be a plain if instead of an else if, it's possible the block has both the access_width and the bit_offset wrong.

My bad, realized this avoids setting pmtmr_ioport.

Roger.

#7 lore raw

Re: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

In reply to Roger Pau Monné
Quoted 13 lines · Roger Pau Monné

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 503

Quoted 9 lines · Grzegorz Uriasz
xen/arch/x86/acpi/boot.c +3 -1
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");

Indentation. Also this should be a fatal error likely? You should set pmtmr_ioport = 0?

Not sure, to be honest. It's entirely fuzzy what mode to use in this case, yet assuming a working 24-bit timer looks valid in this case. And indeed we'd use the timer (with a 24-bit mask) exactly when pmtmr_width == 24 (alongside the bogus set ACPI_FADT_32BIT_TIMER bit).

What I do notice only now though is that inside the if() there's a pair of parentheses missing.

Jan

#3 lore raw

Ping: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

In reply to Jan Beulich
Quoted 42 lines · Jan Beulich

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 503

Quoted 9 lines · Grzegorz Uriasz
xen/arch/x86/acpi/boot.c +3 -1
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");

Indentation is screwed up here.

Quoted 10 lines
xen/arch/x86/time.c +1 -2
@@ -457,16 +457,13 @@ static u64 read_pmtimer_count(void)
 static s64 __init init_pmtimer(struct platform_timesource *pts)
 {
     u64 start;
-    u32 count, target, mask = 0xffffff;
+    u32 count, target, mask;
 
-    if ( !pmtmr_ioport || !pmtmr_width )

xen/arch/x86/time.c static u64 read_pmtimer_count(void) · line 466

Quoted 10 lines
xen/arch/x86/time.c +3 -5
+    if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
         return 0;
 
-    if ( pmtmr_width == 32 )
-    {
-        pts->counter_bits = 32;
-        mask = 0xffffffff;
-    }
+    pts->counter_bits = pmtmr_width;
+    mask = (1ull << pmtmr_width) - 1;

"mask" being of "u32" type, the use of 1ull is certainly a little odd here, and one of the reasons why I think this extra "cleanup" would better go in a separate patch.

Seeing that besides cosmetic aspects the patch looks okay now, I'd be willing to leave the bigger adjustment mostly as is, albeit I'd prefer the 1ull to go away, by instead switching to e.g.

Quoted 8 lines
    mask = 0xffffffff >> (32 - pmtmr_width);

With the adjustments (which I'd be happy to make while committing, provided you agree)

Also Cc-ing Paul for a possible release ack (considering this is a backporting candidate).

Paul?

Thanks, Jan

#4 lore raw

RE: Ping: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

Quoted 54 lines

-----Original Message-----
From: Jan Beulich <[email protected]>
Sent: 24 June 2020 16:32
To: Paul Durrant <[email protected]>
Cc: Grzegorz Uriasz <[email protected]>; Wei Liu <[email protected]>; [email protected]; Andrew Cooper <[email protected]>; [email protected]; [email protected]; xen- [email protected]; [email protected]; Roger Pau Monné <[email protected]>
Subject: Ping: [PATCH v3 1/1] x86/acpi: Use FADT flags to determine the PMTMR width

Quoted 44 lines · Jan Beulich

xen/arch/x86/acpi/boot.c static int __init acpi_parse_fadt(struct acpi_table_header *table) · line 503

Quoted 9 lines · Grzegorz Uriasz
xen/arch/x86/acpi/boot.c +3 -1
@@ -490,8 +497,12 @@ static int __init acpi_parse_fadt(struct acpi_table_header *table)
  	 */
 	if (!pmtmr_ioport) {
 		pmtmr_ioport = fadt->pm_timer_block;
-		pmtmr_width = fadt->pm_timer_length == 4 ? 24 : 0;
+		pmtmr_width = fadt->pm_timer_length == 4 ? 32 : 0;
 	}
+	if (pmtmr_width < 32 && fadt->flags & ACPI_FADT_32BIT_TIMER)
+        printk(KERN_WARNING PREFIX "PM-Timer is too short\n");

Indentation is screwed up here.

Quoted 10 lines
xen/arch/x86/time.c +1 -2
@@ -457,16 +457,13 @@ static u64 read_pmtimer_count(void)
 static s64 __init init_pmtimer(struct platform_timesource *pts)
 {
     u64 start;
-    u32 count, target, mask = 0xffffff;
+    u32 count, target, mask;
 
-    if ( !pmtmr_ioport || !pmtmr_width )

xen/arch/x86/time.c static u64 read_pmtimer_count(void) · line 466

Quoted 10 lines
xen/arch/x86/time.c +3 -5
+    if ( !pmtmr_ioport || (pmtmr_width != 24 && pmtmr_width != 32) )
         return 0;
 
-    if ( pmtmr_width == 32 )
-    {
-        pts->counter_bits = 32;
-        mask = 0xffffffff;
-    }
+    pts->counter_bits = pmtmr_width;
+    mask = (1ull << pmtmr_width) - 1;

"mask" being of "u32" type, the use of 1ull is certainly a little odd here, and one of the reasons why I think this extra "cleanup" would better go in a separate patch.

Seeing that besides cosmetic aspects the patch looks okay now, I'd be willing to leave the bigger adjustment mostly as is, albeit I'd prefer the 1ull to go away, by instead switching to e.g.

    mask = 0xffffffff >> (32 - pmtmr_width);
Quoted 9 lines
Quoted 6 lines

With the adjustments (which I'd be happy to make while committing, provided you agree)

Also Cc-ing Paul for a possible release ack (considering this is a backporting candidate).

Paul?

Looks ok.

Quoted 1 line

Thanks, Jan