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: <CAAhV-H4umT=NYa45EuywN_L6fR_vNUZKtPB5RR-GuD67Tpbf0A@mail.gmail.com>
Date: Wed, 24 Dec 2025 16:30:26 +0800
From: Huacai Chen <chenhuacai@...nel.org>
To: gaosong <gaosong@...ngson.cn>
Cc: maobibo@...ngson.cn, kvm@...r.kernel.org, loongarch@...ts.linux.dev, 
	kernel@...0n.name, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v4 2/3] LongArch: KVM: Add irqfd set dmsintc msg irq

On Wed, Dec 24, 2025 at 3:25 PM gaosong <gaosong@...ngson.cn> wrote:
>
> Hi,
>
> 在 2025/12/19 下午8:55, Huacai Chen 写道:
> > Hi, Song,
> >
> > On Thu, Dec 18, 2025 at 7:43 PM Song Gao <gaosong@...ngson.cn> wrote:
> >> Add irqfd choice dmsintc to set msi irq by the msg_addr and
> >> implement dmsintc set msi irq.
> >>
> >> Reviewed-by: Bibo Mao <maobibo@...ngson.cn>
> >> Signed-off-by: Song Gao <gaosong@...ngson.cn>
> >> ---
> >>   arch/loongarch/include/asm/kvm_dmsintc.h |  1 +
> >>   arch/loongarch/kvm/intc/dmsintc.c        |  6 ++++
> >>   arch/loongarch/kvm/irqfd.c               | 45 ++++++++++++++++++++----
> >>   3 files changed, 45 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/arch/loongarch/include/asm/kvm_dmsintc.h b/arch/loongarch/include/asm/kvm_dmsintc.h
> >> index 1d4f66996f3c..9b5436a2fcbe 100644
> >> --- a/arch/loongarch/include/asm/kvm_dmsintc.h
> >> +++ b/arch/loongarch/include/asm/kvm_dmsintc.h
> >> @@ -11,6 +11,7 @@ struct loongarch_dmsintc  {
> >>          struct kvm *kvm;
> >>          uint64_t msg_addr_base;
> >>          uint64_t msg_addr_size;
> >> +       uint32_t cpu_mask;
> >>   };
> >>
> >>   struct dmsintc_state {
> >> diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
> >> index 3fdea81a08c8..9ecb2e3e352d 100644
> >> --- a/arch/loongarch/kvm/intc/dmsintc.c
> >> +++ b/arch/loongarch/kvm/intc/dmsintc.c
> >> @@ -15,6 +15,7 @@ static int kvm_dmsintc_ctrl_access(struct kvm_device *dev,
> >>          void __user *data;
> >>          struct loongarch_dmsintc *s = dev->kvm->arch.dmsintc;
> >>          u64 tmp;
> >> +       u32 cpu_bit;
> >>
> >>          data = (void __user *)attr->addr;
> >>          switch (addr) {
> >> @@ -30,6 +31,11 @@ static int kvm_dmsintc_ctrl_access(struct kvm_device *dev,
> >>                                  s->msg_addr_base = tmp;
> >>                          else
> >>                                  return  -EFAULT;
> >> +                       s->msg_addr_base = tmp;
> >> +                       cpu_bit = find_first_bit((unsigned long *)&(s->msg_addr_base), 64)
> >> +                                               - AVEC_CPU_SHIFT;
> >> +                       cpu_bit = min(cpu_bit, AVEC_CPU_BIT);
> >> +                       s->cpu_mask = GENMASK(cpu_bit - 1, 0) & AVEC_CPU_MASK;
> >>                  }
> >>                  break;
> >>          case KVM_DEV_LOONGARCH_DMSINTC_MSG_ADDR_SIZE:
> >> diff --git a/arch/loongarch/kvm/irqfd.c b/arch/loongarch/kvm/irqfd.c
> >> index 9a39627aecf0..11f980474552 100644
> >> --- a/arch/loongarch/kvm/irqfd.c
> >> +++ b/arch/loongarch/kvm/irqfd.c
> >> @@ -6,6 +6,7 @@
> >>   #include <linux/kvm_host.h>
> >>   #include <trace/events/kvm.h>
> >>   #include <asm/kvm_pch_pic.h>
> >> +#include <asm/kvm_vcpu.h>
> >>
> >>   static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e,
> >>                  struct kvm *kvm, int irq_source_id, int level, bool line_status)
> >> @@ -16,6 +17,41 @@ static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e,
> >>          return 0;
> >>   }
> >>
> >> +static int kvm_dmsintc_set_msi_irq(struct kvm *kvm, u32 addr, int data, int level)
> >> +{
> >> +       unsigned int virq, dest;
> >> +       struct kvm_vcpu *vcpu;
> >> +
> >> +       virq = (addr >> AVEC_IRQ_SHIFT) & AVEC_IRQ_MASK;
> >> +       dest = (addr >> AVEC_CPU_SHIFT) & kvm->arch.dmsintc->cpu_mask;
> >> +       if (dest > KVM_MAX_VCPUS)
> >> +               return -EINVAL;
> >> +       vcpu = kvm_get_vcpu_by_cpuid(kvm, dest);
> >> +       if (!vcpu)
> >> +               return -EINVAL;
> >> +       return kvm_loongarch_deliver_msi_to_vcpu(kvm, vcpu, virq, level);
> > kvm_loongarch_deliver_msi_to_vcpu() is used in this patch but defined
> > in the last patch, this is not acceptable, you can consider to combine
> > these two, and I don't know whether vcpu.c is the best place for it.
> how about just change patch3 before patch 2?  and  deined them in
> kvm/interrupt.c ?
I think combining them is better, and the dmsintc.c part in this patch
seems should go to Patch-1.

Huacai

> >> +}
> >> +
> >> +static int loongarch_set_msi(struct kvm_kernel_irq_routing_entry *e,
> >> +                       struct kvm *kvm, int level)
> >> +{
> >> +       u64 msg_addr;
> >> +
> >> +       if (!level)
> >> +               return -1;
> > Before this patch, this check is in the caller, with this patch it is
> > in the callee, is this suitable? This will add a check in
> > kvm_arch_set_irq_inatomic().
> if check in the caller, like kvm_set_msi,  we also need a check in
> kvm_arch_set_irq_inatomic(), like arm64 or riscv.
I don't know whether it is better to check in the caller or the
callee, I just point out that the logic is changed by this patch.
You can choose the best way with your own knowledge.


Huacai

>
> I will correct it on v5.
>
> Thanks
> Song Gao
>
> > Huacai
> >
> >> +
> >> +       msg_addr = (((u64)e->msi.address_hi) << 32) | e->msi.address_lo;
> >> +       if (cpu_has_msgint && kvm->arch.dmsintc &&
> >> +               msg_addr >= kvm->arch.dmsintc->msg_addr_base &&
> >> +               msg_addr < (kvm->arch.dmsintc->msg_addr_base  + kvm->arch.dmsintc->msg_addr_size)) {
> >> +               return kvm_dmsintc_set_msi_irq(kvm, msg_addr, e->msi.data, level);
> >> +       } else {
> >> +               pch_msi_set_irq(kvm, e->msi.data, level);
> >> +       }
> >> +
> >> +       return 0;
> >> +}
> >> +
> >>   /*
> >>    * kvm_set_msi: inject the MSI corresponding to the
> >>    * MSI routing entry
> >> @@ -26,12 +62,7 @@ static int kvm_set_pic_irq(struct kvm_kernel_irq_routing_entry *e,
> >>   int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
> >>                  struct kvm *kvm, int irq_source_id, int level, bool line_status)
> >>   {
> >> -       if (!level)
> >> -               return -1;
> >> -
> >> -       pch_msi_set_irq(kvm, e->msi.data, level);
> >> -
> >> -       return 0;
> >> +       return loongarch_set_msi(e, kvm, level);
> >>   }
> >>
> >>   /*
> >> @@ -76,7 +107,7 @@ int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e,
> >>                  pch_pic_set_irq(kvm->arch.pch_pic, e->irqchip.pin, level);
> >>                  return 0;
> >>          case KVM_IRQ_ROUTING_MSI:
> >> -               pch_msi_set_irq(kvm, e->msi.data, level);
> >> +               loongarch_set_msi(e, kvm, level);
> >>                  return 0;
> >>          default:
> >>                  return -EWOULDBLOCK;
> >> --
> >> 2.39.3
> >>
> >>
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ