From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Song Gao <gaosong@loongson.cn>, qemu-devel@nongnu.org
Cc: richard.henderson@linaro.org, maobibo@loongson.cn,
yangxiaojuan@loongson.cn
Subject: Re: [PATCH 2/3] hw/intc: Add NULL pointer check on LoongArch ipi device
Date: Fri, 12 May 2023 05:45:55 +0200 [thread overview]
Message-ID: <d7f544e1-abf2-1f77-00a8-b3c09852fd0c@linaro.org> (raw)
In-Reply-To: <255a9693-3660-35b4-8213-a609018bbb2c@loongson.cn>
On 12/5/23 05:01, Song Gao wrote:
> Hi, Philippe
>
> 在 2023/5/12 上午3:03, Philippe Mathieu-Daudé 写道:
>> On 6/4/23 12:00, Song Gao wrote:
>>> When ipi mailbox is used, cpu index is decoded from iocsr register.
>>> cpu maybe does not exist. This patch adss NULL pointer check on
>>> ipi device.
>>
>> How can that happens from a guest vcpu context?
>>
> cpuid(cs->cpu_index) is decoded from iocsr register.
>
> cpuid = (val >> 16) & 0x3ff; // ipi_sned [25:16]
>
> The value maybe invalid. qemu only support 4 vcpu.
What about something like this?
-- >8 --
-static void ipi_send(uint64_t val)
+static void ipi_send(uint32_t val)
{
- int cpuid, data;
+ uint32_t cpuid;
+ uint8_t vector;
CPULoongArchState *env;
CPUState *cs;
LoongArchCPU *cpu;
- cpuid = (val >> 16) & 0x3ff;
+ cpuid = extract32(val, 16, 10);
+ if (cpuid >= MAX_IPI_CORE_NUM) {
+ trace_loongarch_ipi_unsupported_cpuid("IOCSR_IPI_SEND", cpuid);
+ return;
+ }
/* IPI status vector */
- data = 1 << (val & 0x1f);
+ vector = extract8(val, 0, 5);
+
cs = qemu_get_cpu(cpuid);
cpu = LOONGARCH_CPU(cs);
env = &cpu->env;
address_space_stl(&env->address_space_iocsr, 0x1008,
- data, MEMTXATTRS_UNSPECIFIED, NULL);
+ BIT(vector), MEMTXATTRS_UNSPECIFIED, NULL);
}
---
> you can find more about ipi_send registers at:
> https://github.com/loongson/LoongArch-Documentation/releases/download/2023.04.20/Loongson-3A5000-usermanual-v1.03-EN.pdf
> Table 63. Processor core inter-processor communication registers
>
>>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>>> ---
>>> hw/intc/loongarch_ipi.c | 31 +++++++++++++++++++------------
>>> 1 file changed, 19 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/hw/intc/loongarch_ipi.c b/hw/intc/loongarch_ipi.c
>>> index 0563d83a35..39e899df46 100644
>>> --- a/hw/intc/loongarch_ipi.c
>>> +++ b/hw/intc/loongarch_ipi.c
>>> @@ -86,11 +86,12 @@ static void ipi_send(uint64_t val)
>>> /* IPI status vector */
>>> data = 1 << (val & 0x1f);
>>> cs = qemu_get_cpu(cpuid);
>>> - cpu = LOONGARCH_CPU(cs);
>>> - env = &cpu->env;
>>> - address_space_stl(&env->address_space_iocsr, 0x1008,
>>> - data, MEMTXATTRS_UNSPECIFIED, NULL);
>>> -
>>> + if (cs) {
>>> + cpu = LOONGARCH_CPU(cs);
>>> + env = &cpu->env;
>>> + address_space_stl(&env->address_space_iocsr, 0x1008,
>>> + data, MEMTXATTRS_UNSPECIFIED, NULL);
>>> + }
>>
>> Is that the hardware behavior?
>>
> Yes.
>> Could logging the invalid cpuid request be useful?
>>
> Sure.
>
> Thanks.
> Song Gao
>
next prev parent reply other threads:[~2023-05-12 3:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-06 10:00 [PATCH 1/3] hw/loongarch/virt: Modify ipi as percpu device Song Gao
2023-04-06 10:00 ` [PATCH 2/3] hw/intc: Add NULL pointer check on LoongArch ipi device Song Gao
2023-04-26 1:37 ` Song Gao
2023-05-11 19:03 ` Philippe Mathieu-Daudé
2023-05-12 3:01 ` Song Gao
2023-05-12 3:45 ` Philippe Mathieu-Daudé [this message]
2023-05-12 6:29 ` Song Gao
2023-04-06 10:00 ` [PATCH 3/3] hw/loongarch/virt: Set max 256 cpus support on loongarch virt machine Song Gao
2023-04-26 1:37 ` Song Gao
2023-05-08 2:11 ` Song Gao
2023-05-10 10:12 ` Richard Henderson
2023-05-11 12:22 ` Song Gao
2023-05-11 19:07 ` Philippe Mathieu-Daudé
2023-04-26 1:38 ` [PATCH 1/3] hw/loongarch/virt: Modify ipi as percpu device Song Gao
2023-05-11 19:11 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d7f544e1-abf2-1f77-00a8-b3c09852fd0c@linaro.org \
--to=philmd@linaro.org \
--cc=gaosong@loongson.cn \
--cc=maobibo@loongson.cn \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=yangxiaojuan@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).