qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/timer/hpet: Detect invalid access to TN registers
@ 2025-02-18  7:37 Zhao Liu
  2025-02-18  8:53 ` Paolo Bonzini
  0 siblings, 1 reply; 7+ messages in thread
From: Zhao Liu @ 2025-02-18  7:37 UTC (permalink / raw)
  To: Paolo Bonzini, Michael S . Tsirkin; +Cc: qemu-devel, Zhao Liu

"addr & 0x18" ignores invalid address, so that the trace in default
branch (trace_hpet_ram_{read|write}_invalid()) doesn't work.

Mask addr by "0x1f & ~4", in which 0x1f means to get the complete TN
registers access and ~4 means to keep any invalid address offset.

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 * Note: This patch applies the changes from Rust HPET [*] to C HPET to
   ensure logic consistency.
   [*]: The original comment should use "(0x1f & ~4)":
        https://lore.kernel.org/qemu-devel/Z6edKxYFzA6suDlj@intel.com/
---
 hw/timer/hpet.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index dcff18a9871d..0f786047e54f 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -455,7 +455,7 @@ static uint64_t hpet_ram_read(void *opaque, hwaddr addr,
             return 0;
         }
 
-        switch (addr & 0x18) {
+        switch (addr & (0x1f & ~4)) {
         case HPET_TN_CFG: // including interrupt capabilities
             return timer->config >> shift;
         case HPET_TN_CMP: // comparator register
@@ -511,7 +511,8 @@ static void hpet_ram_write(void *opaque, hwaddr addr,
             trace_hpet_timer_id_out_of_range(timer_id);
             return;
         }
-        switch (addr & 0x18) {
+
+        switch (addr & (0x1f & ~4)) {
         case HPET_TN_CFG:
             trace_hpet_ram_write_tn_cfg(addr & 4);
             old_val = timer->config;
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-02-19 14:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-18  7:37 [PATCH] hw/timer/hpet: Detect invalid access to TN registers Zhao Liu
2025-02-18  8:53 ` Paolo Bonzini
2025-02-18  9:07   ` Philippe Mathieu-Daudé
2025-02-19  3:34     ` Zhao Liu
2025-02-19  9:25     ` Paolo Bonzini
2025-02-19 14:38       ` Zhao Liu
2025-02-19  6:12   ` Zhao Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).