* [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation
@ 2025-08-11 2:13 Bibo Mao
2025-08-11 2:13 ` [PATCH 1/5] LoongArch: KVM: Set version information at initial stage Bibo Mao
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
With PCH PIC interrupt controller emulation driver, its access size is
hardcoded now. Instead the MMIO register can be accessed with different
size such 1/2/4/8.
This patchset adds various read/write size support with emulation
function loongarch_pch_pic_read() and loongarch_pch_pic_write().
Bibo Mao (5):
LoongArch: KVM: Set version information at initial stage
LoongArch: KVM: Add read length support in loongarch_pch_pic_read()
LoongArch: KVM: Add IRR and ISR register read emulation
LoongArch: KVM: Add different length support in
loongarch_pch_pic_write()
LoongArch: KVM: Add address alignment check in pch_pic register access
arch/loongarch/include/asm/kvm_pch_pic.h | 15 +-
arch/loongarch/kvm/intc/pch_pic.c | 239 ++++++++++-------------
2 files changed, 120 insertions(+), 134 deletions(-)
base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
--
2.39.3
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/5] LoongArch: KVM: Set version information at initial stage
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
@ 2025-08-11 2:13 ` Bibo Mao
2025-08-11 2:13 ` [PATCH 2/5] LoongArch: KVM: Add read length support in loongarch_pch_pic_read() Bibo Mao
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
Register PCH_PIC_INT_ID constains version and supported irq number
information, and it is read only register. The detailed value can
be set at initial stage, rather than read callback.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/include/asm/kvm_pch_pic.h | 15 +++++++++++-
arch/loongarch/kvm/intc/pch_pic.c | 30 +++++++++++++++++-------
2 files changed, 35 insertions(+), 10 deletions(-)
diff --git a/arch/loongarch/include/asm/kvm_pch_pic.h b/arch/loongarch/include/asm/kvm_pch_pic.h
index e6df6a4c1c70..3228db8f84a3 100644
--- a/arch/loongarch/include/asm/kvm_pch_pic.h
+++ b/arch/loongarch/include/asm/kvm_pch_pic.h
@@ -34,13 +34,26 @@
#define PCH_PIC_INT_ISR_END 0x3af
#define PCH_PIC_POLARITY_START 0x3e0
#define PCH_PIC_POLARITY_END 0x3e7
-#define PCH_PIC_INT_ID_VAL 0x7000000UL
+#define PCH_PIC_INT_ID_VAL 0x7UL
#define PCH_PIC_INT_ID_VER 0x1UL
+union LoongArchPIC_ID {
+ struct {
+ uint8_t _reserved_0[3];
+ uint8_t id;
+ uint8_t version;
+ uint8_t _reserved_1;
+ uint8_t irq_num;
+ uint8_t _reserved_2;
+ } desc;
+ uint64_t data;
+};
+
struct loongarch_pch_pic {
spinlock_t lock;
struct kvm *kvm;
struct kvm_io_device device;
+ union LoongArchPIC_ID id;
uint64_t mask; /* 1:disable irq, 0:enable irq */
uint64_t htmsi_en; /* 1:msi */
uint64_t edge; /* 1:edge triggered, 0:level triggered */
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 6f00ffe05c54..2c26c0836a05 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -120,20 +120,13 @@ static int loongarch_pch_pic_read(struct loongarch_pch_pic *s, gpa_t addr, int l
{
int offset, index, ret = 0;
u32 data = 0;
- u64 int_id = 0;
offset = addr - s->pch_pic_base;
spin_lock(&s->lock);
switch (offset) {
case PCH_PIC_INT_ID_START ... PCH_PIC_INT_ID_END:
- /* int id version */
- int_id |= (u64)PCH_PIC_INT_ID_VER << 32;
- /* irq number */
- int_id |= (u64)31 << (32 + 16);
- /* int id value */
- int_id |= PCH_PIC_INT_ID_VAL;
- *(u64 *)val = int_id;
+ *(u64 *)val = s->id.data;
break;
case PCH_PIC_MASK_START ... PCH_PIC_MASK_END:
offset -= PCH_PIC_MASK_START;
@@ -467,7 +460,7 @@ static int kvm_setup_default_irq_routing(struct kvm *kvm)
static int kvm_pch_pic_create(struct kvm_device *dev, u32 type)
{
- int ret;
+ int ret, i, irq_num;
struct kvm *kvm = dev->kvm;
struct loongarch_pch_pic *s;
@@ -483,6 +476,25 @@ static int kvm_pch_pic_create(struct kvm_device *dev, u32 type)
if (!s)
return -ENOMEM;
+ /*
+ * With Loongson 7A1000 user manual
+ * Chapter 5.2 "Description of Interrupt-related Registers"
+ *
+ * Interrupt controller identification register 1
+ * Bit 24-31 Interrupt Controller ID
+ * Interrupt controller identification register 2
+ * Bit 0-7 Interrupt Controller version number
+ * Bit 16-23 The number of interrupt sources supported
+ */
+ irq_num = 32;
+ s->id.desc.id = PCH_PIC_INT_ID_VAL;
+ s->id.desc.version = PCH_PIC_INT_ID_VER;
+ s->id.desc.irq_num = irq_num - 1;
+ s->mask = -1UL;
+ for (i = 0; i < irq_num; i++) {
+ s->route_entry[i] = 1;
+ s->htmsi_vector[i] = i;
+ }
spin_lock_init(&s->lock);
s->kvm = kvm;
kvm->arch.pch_pic = s;
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/5] LoongArch: KVM: Add read length support in loongarch_pch_pic_read()
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
2025-08-11 2:13 ` [PATCH 1/5] LoongArch: KVM: Set version information at initial stage Bibo Mao
@ 2025-08-11 2:13 ` Bibo Mao
2025-08-11 2:13 ` [PATCH 3/5] LoongArch: KVM: Add IRR and ISR register read emulation Bibo Mao
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
With function loongarch_pch_pic_read(), currently it is hardcoded
length for different registers, the length comes from exising linux
pch_pic driver code. In theory length 1/2/4/8 should be supported
for all the registers, here adding different length support about
register read emulation in function loongarch_pch_pic_read().
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/pch_pic.c | 42 ++++++++++++++-----------------
1 file changed, 19 insertions(+), 23 deletions(-)
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 2c26c0836a05..70b8cbeea869 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -118,61 +118,57 @@ static u32 pch_pic_write_reg(u64 *s, int high, u32 v)
static int loongarch_pch_pic_read(struct loongarch_pch_pic *s, gpa_t addr, int len, void *val)
{
- int offset, index, ret = 0;
- u32 data = 0;
+ int offset, ret = 0;
+ u64 data = 0;
+ void *ptemp;
offset = addr - s->pch_pic_base;
+ offset -= offset & 7;
spin_lock(&s->lock);
switch (offset) {
case PCH_PIC_INT_ID_START ... PCH_PIC_INT_ID_END:
- *(u64 *)val = s->id.data;
+ data = s->id.data;
break;
case PCH_PIC_MASK_START ... PCH_PIC_MASK_END:
- offset -= PCH_PIC_MASK_START;
- index = offset >> 2;
- /* read mask reg */
- data = pch_pic_read_reg(&s->mask, index);
- *(u32 *)val = data;
+ data = s->mask;
break;
case PCH_PIC_HTMSI_EN_START ... PCH_PIC_HTMSI_EN_END:
- offset -= PCH_PIC_HTMSI_EN_START;
- index = offset >> 2;
/* read htmsi enable reg */
- data = pch_pic_read_reg(&s->htmsi_en, index);
- *(u32 *)val = data;
+ data = s->htmsi_en;
break;
case PCH_PIC_EDGE_START ... PCH_PIC_EDGE_END:
- offset -= PCH_PIC_EDGE_START;
- index = offset >> 2;
/* read edge enable reg */
- data = pch_pic_read_reg(&s->edge, index);
- *(u32 *)val = data;
+ data = s->edge;
break;
case PCH_PIC_AUTO_CTRL0_START ... PCH_PIC_AUTO_CTRL0_END:
case PCH_PIC_AUTO_CTRL1_START ... PCH_PIC_AUTO_CTRL1_END:
/* we only use default mode: fixed interrupt distribution mode */
- *(u32 *)val = 0;
break;
case PCH_PIC_ROUTE_ENTRY_START ... PCH_PIC_ROUTE_ENTRY_END:
/* only route to int0: eiointc */
- *(u8 *)val = 1;
+ ptemp = s->route_entry + (offset - PCH_PIC_ROUTE_ENTRY_START);
+ data = *(u64 *)ptemp;
break;
case PCH_PIC_HTMSI_VEC_START ... PCH_PIC_HTMSI_VEC_END:
- offset -= PCH_PIC_HTMSI_VEC_START;
/* read htmsi vector */
- data = s->htmsi_vector[offset];
- *(u8 *)val = data;
+ ptemp = s->htmsi_vector + (offset - PCH_PIC_HTMSI_VEC_START);
+ data = *(u64 *)ptemp;
break;
case PCH_PIC_POLARITY_START ... PCH_PIC_POLARITY_END:
- /* we only use defalut value 0: high level triggered */
- *(u32 *)val = 0;
+ data = s->polarity;
break;
default:
ret = -EINVAL;
}
spin_unlock(&s->lock);
+ if (ret)
+ return ret;
+
+ offset = (addr - s->pch_pic_base) & 7;
+ data = data >> (offset * 8);
+ memcpy(val, &data, len);
return ret;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/5] LoongArch: KVM: Add IRR and ISR register read emulation
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
2025-08-11 2:13 ` [PATCH 1/5] LoongArch: KVM: Set version information at initial stage Bibo Mao
2025-08-11 2:13 ` [PATCH 2/5] LoongArch: KVM: Add read length support in loongarch_pch_pic_read() Bibo Mao
@ 2025-08-11 2:13 ` Bibo Mao
2025-08-11 2:13 ` [PATCH 4/5] LoongArch: KVM: Add different length support in loongarch_pch_pic_write() Bibo Mao
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
With 7A1000 user manual, there is register PCH_PIC_INT_IRR_START
and PCH_PIC_INT_ISR_START, add read access emulation in function
loongarch_pch_pic_read() here.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/pch_pic.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 70b8cbeea869..2e2613c436f6 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -158,6 +158,12 @@ static int loongarch_pch_pic_read(struct loongarch_pch_pic *s, gpa_t addr, int l
case PCH_PIC_POLARITY_START ... PCH_PIC_POLARITY_END:
data = s->polarity;
break;
+ case PCH_PIC_INT_IRR_START:
+ data = s->irr;
+ break;
+ case PCH_PIC_INT_ISR_START:
+ data = s->isr;
+ break;
default:
ret = -EINVAL;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 4/5] LoongArch: KVM: Add different length support in loongarch_pch_pic_write()
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
` (2 preceding siblings ...)
2025-08-11 2:13 ` [PATCH 3/5] LoongArch: KVM: Add IRR and ISR register read emulation Bibo Mao
@ 2025-08-11 2:13 ` Bibo Mao
2025-08-11 2:13 ` [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access Bibo Mao
2025-08-29 10:13 ` [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Huacai Chen
5 siblings, 0 replies; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
With function loongarch_pch_pic_write(), currently there is only
four bytes register write support. In theory length 1/2/4/8 should be
supported for all the registers, here adding different length support
about register write emulation in function loongarch_pch_pic_write().
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/pch_pic.c | 153 ++++++++++--------------------
1 file changed, 51 insertions(+), 102 deletions(-)
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 2e2613c436f6..0710b5ab286e 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -77,45 +77,6 @@ void pch_msi_set_irq(struct kvm *kvm, int irq, int level)
eiointc_set_irq(kvm->arch.eiointc, irq, level);
}
-/*
- * pch pic register is 64-bit, but it is accessed by 32-bit,
- * so we use high to get whether low or high 32 bits we want
- * to read.
- */
-static u32 pch_pic_read_reg(u64 *s, int high)
-{
- u64 val = *s;
-
- /* read the high 32 bits when high is 1 */
- return high ? (u32)(val >> 32) : (u32)val;
-}
-
-/*
- * pch pic register is 64-bit, but it is accessed by 32-bit,
- * so we use high to get whether low or high 32 bits we want
- * to write.
- */
-static u32 pch_pic_write_reg(u64 *s, int high, u32 v)
-{
- u64 val = *s, data = v;
-
- if (high) {
- /*
- * Clear val high 32 bits
- * Write the high 32 bits when the high is 1
- */
- *s = (val << 32 >> 32) | (data << 32);
- val >>= 32;
- } else
- /*
- * Clear val low 32 bits
- * Write the low 32 bits when the high is 0
- */
- *s = (val >> 32 << 32) | v;
-
- return (u32)val;
-}
-
static int loongarch_pch_pic_read(struct loongarch_pch_pic *s, gpa_t addr, int len, void *val)
{
int offset, ret = 0;
@@ -201,80 +162,68 @@ static int loongarch_pch_pic_write(struct loongarch_pch_pic *s, gpa_t addr,
int len, const void *val)
{
int ret;
- u32 old, data, offset, index;
- u64 irq;
+ u32 offset;
+ u64 old, data, mask;
+ void *ptemp;
- ret = 0;
- data = *(u32 *)val;
- offset = addr - s->pch_pic_base;
+ switch (len) {
+ case 1:
+ data = *(u8 *)val;
+ mask = 0xFF;
+ break;
+ case 2:
+ data = *(u16 *)val;
+ mask = USHRT_MAX;
+ break;
+ case 4:
+ data = *(u32 *)val;
+ mask = UINT_MAX;
+ break;
+ default:
+ data = *(u64 *)val;
+ mask = ULONG_MAX;
+ break;
+ }
+ offset = (addr - s->pch_pic_base) & 7;
+ mask = mask << (offset * 8);
+ data = data << (offset * 8);
+ ret = 0;
+ offset = (addr - s->pch_pic_base) - offset;
spin_lock(&s->lock);
switch (offset) {
- case PCH_PIC_MASK_START ... PCH_PIC_MASK_END:
- offset -= PCH_PIC_MASK_START;
- /* get whether high or low 32 bits we want to write */
- index = offset >> 2;
- old = pch_pic_write_reg(&s->mask, index, data);
- /* enable irq when mask value change to 0 */
- irq = (old & ~data) << (32 * index);
- pch_pic_update_batch_irqs(s, irq, 1);
- /* disable irq when mask value change to 1 */
- irq = (~old & data) << (32 * index);
- pch_pic_update_batch_irqs(s, irq, 0);
- break;
- case PCH_PIC_HTMSI_EN_START ... PCH_PIC_HTMSI_EN_END:
- offset -= PCH_PIC_HTMSI_EN_START;
- index = offset >> 2;
- pch_pic_write_reg(&s->htmsi_en, index, data);
+ case PCH_PIC_MASK_START:
+ old = s->mask;
+ s->mask = (old & ~mask) | data;
+ if (old & ~data)
+ pch_pic_update_batch_irqs(s, old & ~data, 1);
+ if (~old & data)
+ pch_pic_update_batch_irqs(s, ~old & data, 0);
break;
- case PCH_PIC_EDGE_START ... PCH_PIC_EDGE_END:
- offset -= PCH_PIC_EDGE_START;
- index = offset >> 2;
- /* 1: edge triggered, 0: level triggered */
- pch_pic_write_reg(&s->edge, index, data);
- break;
- case PCH_PIC_CLEAR_START ... PCH_PIC_CLEAR_END:
- offset -= PCH_PIC_CLEAR_START;
- index = offset >> 2;
- /* write 1 to clear edge irq */
- old = pch_pic_read_reg(&s->irr, index);
- /*
- * get the irq bitmap which is edge triggered and
- * already set and to be cleared
- */
- irq = old & pch_pic_read_reg(&s->edge, index) & data;
- /* write irr to the new state where irqs have been cleared */
- pch_pic_write_reg(&s->irr, index, old & ~irq);
- /* update cleared irqs */
- pch_pic_update_batch_irqs(s, irq, 0);
+ case PCH_PIC_HTMSI_EN_START:
+ s->htmsi_en = (s->htmsi_en & ~mask) | data;
break;
- case PCH_PIC_AUTO_CTRL0_START ... PCH_PIC_AUTO_CTRL0_END:
- offset -= PCH_PIC_AUTO_CTRL0_START;
- index = offset >> 2;
- /* we only use default mode: fixed interrupt distribution mode */
- pch_pic_write_reg(&s->auto_ctrl0, index, 0);
+ case PCH_PIC_EDGE_START:
+ s->edge = (s->edge & ~mask) | data;
break;
- case PCH_PIC_AUTO_CTRL1_START ... PCH_PIC_AUTO_CTRL1_END:
- offset -= PCH_PIC_AUTO_CTRL1_START;
- index = offset >> 2;
- /* we only use default mode: fixed interrupt distribution mode */
- pch_pic_write_reg(&s->auto_ctrl1, index, 0);
+ case PCH_PIC_POLARITY_START:
+ s->polarity = (s->polarity & ~mask) | data;
break;
- case PCH_PIC_ROUTE_ENTRY_START ... PCH_PIC_ROUTE_ENTRY_END:
- offset -= PCH_PIC_ROUTE_ENTRY_START;
- /* only route to int0: eiointc */
- s->route_entry[offset] = 1;
+ case PCH_PIC_CLEAR_START:
+ old = s->irr & s->edge & data;
+ if (old) {
+ s->irr &= ~old;
+ pch_pic_update_batch_irqs(s, old, 0);
+ }
break;
case PCH_PIC_HTMSI_VEC_START ... PCH_PIC_HTMSI_VEC_END:
- /* route table to eiointc */
- offset -= PCH_PIC_HTMSI_VEC_START;
- s->htmsi_vector[offset] = (u8)data;
+ ptemp = s->htmsi_vector + (offset - PCH_PIC_HTMSI_VEC_START);
+ *(u64 *)ptemp = (*(u64 *)ptemp & ~mask) | data;
break;
- case PCH_PIC_POLARITY_START ... PCH_PIC_POLARITY_END:
- offset -= PCH_PIC_POLARITY_START;
- index = offset >> 2;
- /* we only use defalut value 0: high level triggered */
- pch_pic_write_reg(&s->polarity, index, 0);
+ /* Not implemented */
+ case PCH_PIC_AUTO_CTRL0_START:
+ case PCH_PIC_AUTO_CTRL1_START:
+ case PCH_PIC_ROUTE_ENTRY_START ... PCH_PIC_ROUTE_ENTRY_END:
break;
default:
ret = -EINVAL;
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
` (3 preceding siblings ...)
2025-08-11 2:13 ` [PATCH 4/5] LoongArch: KVM: Add different length support in loongarch_pch_pic_write() Bibo Mao
@ 2025-08-11 2:13 ` Bibo Mao
2025-08-17 3:45 ` Huacai Chen
2025-08-29 10:13 ` [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Huacai Chen
5 siblings, 1 reply; 8+ messages in thread
From: Bibo Mao @ 2025-08-11 2:13 UTC (permalink / raw)
To: Tianrui Zhao, Huacai Chen, Xianglai Li; +Cc: kvm, loongarch, linux-kernel
With pch_pic device, its register is based on MMIO address space,
different access size 1/2/4/8 is supported. And base address should
be naturally aligned with its access size, here add alignment check
in its register access emulation function.
Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
arch/loongarch/kvm/intc/pch_pic.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
index 0710b5ab286e..5ee24dbf3c4c 100644
--- a/arch/loongarch/kvm/intc/pch_pic.c
+++ b/arch/loongarch/kvm/intc/pch_pic.c
@@ -151,6 +151,11 @@ static int kvm_pch_pic_read(struct kvm_vcpu *vcpu,
return -EINVAL;
}
+ if (addr & (len - 1)) {
+ kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
+ return -EINVAL;
+ }
+
/* statistics of pch pic reading */
vcpu->stat.pch_pic_read_exits++;
ret = loongarch_pch_pic_read(s, addr, len, val);
@@ -246,6 +251,11 @@ static int kvm_pch_pic_write(struct kvm_vcpu *vcpu,
return -EINVAL;
}
+ if (addr & (len - 1)) {
+ kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
+ return -EINVAL;
+ }
+
/* statistics of pch pic writing */
vcpu->stat.pch_pic_write_exits++;
ret = loongarch_pch_pic_write(s, addr, len, val);
--
2.39.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access
2025-08-11 2:13 ` [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access Bibo Mao
@ 2025-08-17 3:45 ` Huacai Chen
0 siblings, 0 replies; 8+ messages in thread
From: Huacai Chen @ 2025-08-17 3:45 UTC (permalink / raw)
To: Bibo Mao; +Cc: Tianrui Zhao, Xianglai Li, kvm, loongarch, linux-kernel
This one is applied for loongarch-fixes.
Huacai
On Mon, Aug 11, 2025 at 10:15 AM Bibo Mao <maobibo@loongson.cn> wrote:
>
> With pch_pic device, its register is based on MMIO address space,
> different access size 1/2/4/8 is supported. And base address should
> be naturally aligned with its access size, here add alignment check
> in its register access emulation function.
>
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
> arch/loongarch/kvm/intc/pch_pic.c | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/arch/loongarch/kvm/intc/pch_pic.c b/arch/loongarch/kvm/intc/pch_pic.c
> index 0710b5ab286e..5ee24dbf3c4c 100644
> --- a/arch/loongarch/kvm/intc/pch_pic.c
> +++ b/arch/loongarch/kvm/intc/pch_pic.c
> @@ -151,6 +151,11 @@ static int kvm_pch_pic_read(struct kvm_vcpu *vcpu,
> return -EINVAL;
> }
>
> + if (addr & (len - 1)) {
> + kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
> + return -EINVAL;
> + }
> +
> /* statistics of pch pic reading */
> vcpu->stat.pch_pic_read_exits++;
> ret = loongarch_pch_pic_read(s, addr, len, val);
> @@ -246,6 +251,11 @@ static int kvm_pch_pic_write(struct kvm_vcpu *vcpu,
> return -EINVAL;
> }
>
> + if (addr & (len - 1)) {
> + kvm_err("%s: pch pic not aligned addr %llx len %d\n", __func__, addr, len);
> + return -EINVAL;
> + }
> +
> /* statistics of pch pic writing */
> vcpu->stat.pch_pic_write_exits++;
> ret = loongarch_pch_pic_write(s, addr, len, val);
> --
> 2.39.3
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
` (4 preceding siblings ...)
2025-08-11 2:13 ` [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access Bibo Mao
@ 2025-08-29 10:13 ` Huacai Chen
5 siblings, 0 replies; 8+ messages in thread
From: Huacai Chen @ 2025-08-29 10:13 UTC (permalink / raw)
To: Bibo Mao; +Cc: Tianrui Zhao, Xianglai Li, kvm, loongarch, linux-kernel
Applied with some modifications (e.g. rename LoongArchPIC_ID to
pch_pic_id for kernel coding style), so you'd better test it [1].
[1] https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson.git/log/?h=loongarch-kvm
Huacai
On Mon, Aug 11, 2025 at 10:13 AM Bibo Mao <maobibo@loongson.cn> wrote:
>
> With PCH PIC interrupt controller emulation driver, its access size is
> hardcoded now. Instead the MMIO register can be accessed with different
> size such 1/2/4/8.
>
> This patchset adds various read/write size support with emulation
> function loongarch_pch_pic_read() and loongarch_pch_pic_write().
>
> Bibo Mao (5):
> LoongArch: KVM: Set version information at initial stage
> LoongArch: KVM: Add read length support in loongarch_pch_pic_read()
> LoongArch: KVM: Add IRR and ISR register read emulation
> LoongArch: KVM: Add different length support in
> loongarch_pch_pic_write()
> LoongArch: KVM: Add address alignment check in pch_pic register access
>
> arch/loongarch/include/asm/kvm_pch_pic.h | 15 +-
> arch/loongarch/kvm/intc/pch_pic.c | 239 ++++++++++-------------
> 2 files changed, 120 insertions(+), 134 deletions(-)
>
>
> base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
> --
> 2.39.3
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-08-29 10:13 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-11 2:13 [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Bibo Mao
2025-08-11 2:13 ` [PATCH 1/5] LoongArch: KVM: Set version information at initial stage Bibo Mao
2025-08-11 2:13 ` [PATCH 2/5] LoongArch: KVM: Add read length support in loongarch_pch_pic_read() Bibo Mao
2025-08-11 2:13 ` [PATCH 3/5] LoongArch: KVM: Add IRR and ISR register read emulation Bibo Mao
2025-08-11 2:13 ` [PATCH 4/5] LoongArch: KVM: Add different length support in loongarch_pch_pic_write() Bibo Mao
2025-08-11 2:13 ` [PATCH 5/5] LoongArch: KVM: Add address alignment check in pch_pic register access Bibo Mao
2025-08-17 3:45 ` Huacai Chen
2025-08-29 10:13 ` [PATCH 0/5] LoongArch: KVM: Support various access size with pch_pic emulation Huacai Chen
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).