lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <56ae2003-0eae-a877-0f64-85b7d956b951@loongson.cn>
Date: Thu, 25 Dec 2025 15:34:50 +0800
From: gaosong <gaosong@...ngson.cn>
To: Bibo Mao <maobibo@...ngson.cn>, chenhuacai@...nel.org
Cc: kvm@...r.kernel.org, loongarch@...ts.linux.dev, kernel@...0n.name,
 linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 1/3] LongArch: KVM: Add DMSINTC device support

在 2025/12/25 下午2:48, Bibo Mao 写道:
>
>
> On 2025/12/18 下午7:18, Song Gao wrote:
>> Add device model for DMSINTC interrupt controller, implement basic
>> create/destroy/set_attr interfaces, and register device model to kvm
>> device table.
>>
>> Reviewed-by: Bibo Mao <maobibo@...ngson.cn>
>> Signed-off-by: Song Gao <gaosong@...ngson.cn>
>> ---
>>   arch/loongarch/include/asm/kvm_dmsintc.h |  21 +++++
>>   arch/loongarch/include/asm/kvm_host.h    |   3 +
>>   arch/loongarch/include/uapi/asm/kvm.h    |   4 +
>>   arch/loongarch/kvm/Makefile              |   1 +
>>   arch/loongarch/kvm/intc/dmsintc.c        | 110 +++++++++++++++++++++++
>>   arch/loongarch/kvm/main.c                |   5 ++
>>   include/uapi/linux/kvm.h                 |   2 +
>>   7 files changed, 146 insertions(+)
>>   create mode 100644 arch/loongarch/include/asm/kvm_dmsintc.h
>>   create mode 100644 arch/loongarch/kvm/intc/dmsintc.c
>>
>> diff --git a/arch/loongarch/include/asm/kvm_dmsintc.h 
>> b/arch/loongarch/include/asm/kvm_dmsintc.h
>> new file mode 100644
>> index 000000000000..1d4f66996f3c
>> --- /dev/null
>> +++ b/arch/loongarch/include/asm/kvm_dmsintc.h
>> @@ -0,0 +1,21 @@
>> +/* SPDX-License-Identifier: GPL-2.0 */
>> +/*
>> + * Copyright (C) 2025 Loongson Technology Corporation Limited
>> + */
>> +
>> +#ifndef __ASM_KVM_DMSINTC_H
>> +#define __ASM_KVM_DMSINTC_H
>> +
>> +
>> +struct loongarch_dmsintc  {
>> +    struct kvm *kvm;
>> +    uint64_t msg_addr_base;
>> +    uint64_t msg_addr_size;
>> +};
>> +
>> +struct dmsintc_state {
>> +    atomic64_t  vector_map[4];
>> +};
>> +
>> +int kvm_loongarch_register_dmsintc_device(void);
>> +#endif
>> diff --git a/arch/loongarch/include/asm/kvm_host.h 
>> b/arch/loongarch/include/asm/kvm_host.h
>> index e4fe5b8e8149..5e9e2af7312f 100644
>> --- a/arch/loongarch/include/asm/kvm_host.h
>> +++ b/arch/loongarch/include/asm/kvm_host.h
>> @@ -22,6 +22,7 @@
>>   #include <asm/kvm_ipi.h>
>>   #include <asm/kvm_eiointc.h>
>>   #include <asm/kvm_pch_pic.h>
>> +#include <asm/kvm_dmsintc.h>
>>   #include <asm/loongarch.h>
>>     #define __KVM_HAVE_ARCH_INTC_INITIALIZED
>> @@ -134,6 +135,7 @@ struct kvm_arch {
>>       struct loongarch_ipi *ipi;
>>       struct loongarch_eiointc *eiointc;
>>       struct loongarch_pch_pic *pch_pic;
>> +    struct loongarch_dmsintc *dmsintc;
>>   };
>>     #define CSR_MAX_NUMS        0x800
>> @@ -244,6 +246,7 @@ struct kvm_vcpu_arch {
>>       struct kvm_mp_state mp_state;
>>       /* ipi state */
>>       struct ipi_state ipi_state;
>> +    struct dmsintc_state dmsintc_state;
>>       /* cpucfg */
>>       u32 cpucfg[KVM_MAX_CPUCFG_REGS];
>>   diff --git a/arch/loongarch/include/uapi/asm/kvm.h 
>> b/arch/loongarch/include/uapi/asm/kvm.h
>> index de6c3f18e40a..0a370d018b08 100644
>> --- a/arch/loongarch/include/uapi/asm/kvm.h
>> +++ b/arch/loongarch/include/uapi/asm/kvm.h
>> @@ -154,4 +154,8 @@ struct kvm_iocsr_entry {
>>   #define KVM_DEV_LOONGARCH_PCH_PIC_GRP_CTRL 0x40000006
>>   #define KVM_DEV_LOONGARCH_PCH_PIC_CTRL_INIT            0
>>   +#define KVM_DEV_LOONGARCH_DMSINTC_CTRL            0x40000007
>> +#define KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_BASE        0x0
>> +#define KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_SIZE        0x1
>> +
>>   #endif /* __UAPI_ASM_LOONGARCH_KVM_H */
>> diff --git a/arch/loongarch/kvm/Makefile b/arch/loongarch/kvm/Makefile
>> index cb41d9265662..6e184e24443c 100644
>> --- a/arch/loongarch/kvm/Makefile
>> +++ b/arch/loongarch/kvm/Makefile
>> @@ -19,6 +19,7 @@ kvm-y += vm.o
>>   kvm-y += intc/ipi.o
>>   kvm-y += intc/eiointc.o
>>   kvm-y += intc/pch_pic.o
>> +kvm-y += intc/dmsintc.o
>>   kvm-y += irqfd.o
>>     CFLAGS_exit.o    += $(call cc-disable-warning, override-init)
>> diff --git a/arch/loongarch/kvm/intc/dmsintc.c 
>> b/arch/loongarch/kvm/intc/dmsintc.c
>> new file mode 100644
>> index 000000000000..3fdea81a08c8
>> --- /dev/null
>> +++ b/arch/loongarch/kvm/intc/dmsintc.c
>> @@ -0,0 +1,110 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Copyright (C) 2025 Loongson Technology Corporation Limited
>> + */
>> +
>> +#include <linux/kvm_host.h>
>> +#include <asm/kvm_dmsintc.h>
>> +#include <asm/kvm_vcpu.h>
>> +
>> +static int kvm_dmsintc_ctrl_access(struct kvm_device *dev,
>> +                struct kvm_device_attr *attr,
>> +                bool is_write)
>> +{
>> +    int addr = attr->attr;
>> +    void __user *data;
>> +    struct loongarch_dmsintc *s = dev->kvm->arch.dmsintc;
>> +    u64 tmp;
>> +
>> +    data = (void __user *)attr->addr;
>> +    switch (addr) {
>> +    case KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_BASE:
>> +        if (is_write) {
>> +            if (copy_from_user(&tmp, data, sizeof(s->msg_addr_base)))
>> +                return -EFAULT;
>> +            if (s->msg_addr_base) {
>> +                /* Duplicate setting are not allowed. */
>> +                return -EFAULT;
>> +            }
>> +            if ((tmp & (BIT(AVEC_CPU_SHIFT) - 1)) == 0)
>> +                s->msg_addr_base = tmp;
>> +            else
>> +                return  -EFAULT;
>> +        }
>> +        break;
>> +    case KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_SIZE:
>> +        if (is_write) {
>> +            if (copy_from_user(&tmp, data, sizeof(s->msg_addr_size)))
>> +                return -EFAULT;
>> +            if (s->msg_addr_size) {
>> +                /*Duplicate setting are not allowed. */
>> +                return -EFAULT;
>> +            }
>> +            s->msg_addr_size = tmp;
>> +        }
>> +        break;
>> +    default:
>> +        kvm_err("%s: unknown dmsintc register, addr = %d\n", 
>> __func__, addr);
>> +        return -ENXIO;
>> +    }
>> +
>> +    return 0;
>> +}
>> +
>> +static int kvm_dmsintc_set_attr(struct kvm_device *dev,
>> +            struct kvm_device_attr *attr)
>> +{
>> +    switch (attr->group) {
>> +    case KVM_DEV_LOONGARCH_DMSINTC_CTRL:
>> +        return kvm_dmsintc_ctrl_access(dev, attr, true);
>> +    default:
>> +        kvm_err("%s: unknown group (%d)\n", __func__, attr->group);
>> +        return -EINVAL;
>> +    }
>> +}
>> +
>> +static int kvm_dmsintc_create(struct kvm_device *dev, u32 type)
>> +{
>> +    struct kvm *kvm;
>> +    struct loongarch_dmsintc *s;
>> +
>> +    if (!dev) {
>> +        kvm_err("%s: kvm_device ptr is invalid!\n", __func__);
>> +        return -EINVAL;
>> +    }
>> +
>> +    kvm = dev->kvm;
>> +    if (kvm->arch.dmsintc) {
>> +        kvm_err("%s: LoongArch DMSINTC has already been created!\n", 
>> __func__);
>> +        return -EINVAL;
>> +    }
>> +
>> +    s = kzalloc(sizeof(struct loongarch_dmsintc), GFP_KERNEL);
>> +    if (!s)
>> +        return -ENOMEM;
>> +
>> +    s->kvm = kvm;
>> +    kvm->arch.dmsintc = s;
>> +    return 0;
>> +}
>> +
>> +static void kvm_dmsintc_destroy(struct kvm_device *dev)
>> +{
>> +
>> +    if (!dev || !dev->kvm || !dev->kvm->arch.dmsintc)
>> +        return;
>> +
>> +    kfree(dev->kvm->arch.dmsintc);
>> +}
>> +
>> +static struct kvm_device_ops kvm_dmsintc_dev_ops = {
>> +    .name = "kvm-loongarch-dmsintc",
>> +    .create = kvm_dmsintc_create,
>> +    .destroy = kvm_dmsintc_destroy,
>> +    .set_attr = kvm_dmsintc_set_attr,
>> +};
>> +
>> +int kvm_loongarch_register_dmsintc_device(void)
>> +{
>> +    return kvm_register_device_ops(&kvm_dmsintc_dev_ops, 
>> KVM_DEV_TYPE_LOONGARCH_DMSINTC);
>> +}
>> diff --git a/arch/loongarch/kvm/main.c b/arch/loongarch/kvm/main.c
>> index 80ea63d465b8..2e26d4fd9000 100644
>> --- a/arch/loongarch/kvm/main.c
>> +++ b/arch/loongarch/kvm/main.c
>> @@ -408,6 +408,11 @@ static int kvm_loongarch_env_init(void)
>>         /* Register LoongArch PCH-PIC interrupt controller interface. */
>>       ret = kvm_loongarch_register_pch_pic_device();
>> +    if (ret)
>> +        return ret;
>> +
>> +    /* Register LoongArch DMSINTC interrupt contrroller interface */
>> +    ret = kvm_loongarch_register_dmsintc_device();
> I think it will be better if cpu_has_msgint() is added, in theory 
> dmsintc cannot be added on 3C5000 host machine, and KVM cannot prevent 
> VMM executing FUZZ ioctl commands.
>
I will add it on next version.

Thanks.
Song Gao
> Regards
> Bibo Mao
>>         return ret;
>>   }
>> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
>> index dddb781b0507..7c56e7e36265 100644
>> --- a/include/uapi/linux/kvm.h
>> +++ b/include/uapi/linux/kvm.h
>> @@ -1209,6 +1209,8 @@ enum kvm_device_type {
>>   #define KVM_DEV_TYPE_LOONGARCH_EIOINTC KVM_DEV_TYPE_LOONGARCH_EIOINTC
>>       KVM_DEV_TYPE_LOONGARCH_PCHPIC,
>>   #define KVM_DEV_TYPE_LOONGARCH_PCHPIC KVM_DEV_TYPE_LOONGARCH_PCHPIC
>> +    KVM_DEV_TYPE_LOONGARCH_DMSINTC,
>> +#define KVM_DEV_TYPE_LOONGARCH_DMSINTC KVM_DEV_TYPE_LOONGARCH_DMSINTC
>>         KVM_DEV_TYPE_MAX,
>>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ