* [PATCH] target/riscv: Check PMP rules num before propagation
@ 2021-11-16 15:11 LIU Zhiwei
2021-11-17 0:03 ` Alistair Francis
0 siblings, 1 reply; 4+ messages in thread
From: LIU Zhiwei @ 2021-11-16 15:11 UTC (permalink / raw)
To: qemu-devel, qemu-riscv; +Cc: palmer, bin.meng, Alistair.Francis, LIU Zhiwei
If PMP rules number is zero, it should not influence the TLB entry for
M-mode program.
Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
---
target/riscv/cpu_helper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
index 9eeed38c7e..48da872d39 100644
--- a/target/riscv/cpu_helper.c
+++ b/target/riscv/cpu_helper.c
@@ -376,7 +376,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
}
*prot = pmp_priv_to_page_prot(pmp_priv);
- if (tlb_size != NULL) {
+ if ((tlb_size != NULL) && pmp_get_num_rules(env)) {
if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
*tlb_size = tlb_size_pmp;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] target/riscv: Check PMP rules num before propagation
2021-11-16 15:11 [PATCH] target/riscv: Check PMP rules num before propagation LIU Zhiwei
@ 2021-11-17 0:03 ` Alistair Francis
2021-11-17 0:42 ` LIU Zhiwei
0 siblings, 1 reply; 4+ messages in thread
From: Alistair Francis @ 2021-11-17 0:03 UTC (permalink / raw)
To: LIU Zhiwei
Cc: Palmer Dabbelt, Alistair Francis, Bin Meng, open list:RISC-V,
qemu-devel@nongnu.org Developers
On Wed, Nov 17, 2021 at 1:12 AM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
>
> If PMP rules number is zero, it should not influence the TLB entry for
> M-mode program.
This doesn't sound right. From what I can tell if we have no rules
pmp_is_range_in_tlb() shouldn't have an effect on the tlb_size. What
error are you seeing?
Alistair
>
> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
> ---
> target/riscv/cpu_helper.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> index 9eeed38c7e..48da872d39 100644
> --- a/target/riscv/cpu_helper.c
> +++ b/target/riscv/cpu_helper.c
> @@ -376,7 +376,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
> }
>
> *prot = pmp_priv_to_page_prot(pmp_priv);
> - if (tlb_size != NULL) {
> + if ((tlb_size != NULL) && pmp_get_num_rules(env)) {
> if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
> *tlb_size = tlb_size_pmp;
> }
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] target/riscv: Check PMP rules num before propagation
2021-11-17 0:03 ` Alistair Francis
@ 2021-11-17 0:42 ` LIU Zhiwei
2021-11-19 12:59 ` Alistair Francis
0 siblings, 1 reply; 4+ messages in thread
From: LIU Zhiwei @ 2021-11-17 0:42 UTC (permalink / raw)
To: Alistair Francis
Cc: Palmer Dabbelt, Alistair Francis, Bin Meng, open list:RISC-V,
qemu-devel@nongnu.org Developers
0
On 2021/11/17 上午8:03, Alistair Francis wrote:
> On Wed, Nov 17, 2021 at 1:12 AM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
>> If PMP rules number is zero, it should not influence the TLB entry for
>> M-mode program.
> This doesn't sound right. From what I can tell if we have no rules
> pmp_is_range_in_tlb() shouldn't have an effect on the tlb_size. What
> error are you seeing?
When address is in [0-4K] and no pmp rule configured, the tlb_size will
be set to 1.
This is caused by pmp_get_tlb_size return a value 1.
if (pmp_sa >= tlb_sa && pmp_ea <= tlb_ea) {
return pmp_ea - pmp_sa + 1;
}
Here pmp_sa == 0 and pmp_ea == 0.
Thanks,
Zhiwei
> Alistair
>
>> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
>> ---
>> target/riscv/cpu_helper.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
>> index 9eeed38c7e..48da872d39 100644
>> --- a/target/riscv/cpu_helper.c
>> +++ b/target/riscv/cpu_helper.c
>> @@ -376,7 +376,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
>> }
>>
>> *prot = pmp_priv_to_page_prot(pmp_priv);
>> - if (tlb_size != NULL) {
>> + if ((tlb_size != NULL) && pmp_get_num_rules(env)) {
>> if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
>> *tlb_size = tlb_size_pmp;
>> }
>> --
>> 2.25.1
>>
>>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] target/riscv: Check PMP rules num before propagation
2021-11-17 0:42 ` LIU Zhiwei
@ 2021-11-19 12:59 ` Alistair Francis
0 siblings, 0 replies; 4+ messages in thread
From: Alistair Francis @ 2021-11-19 12:59 UTC (permalink / raw)
To: LIU Zhiwei
Cc: Palmer Dabbelt, Alistair Francis, Bin Meng, open list:RISC-V,
qemu-devel@nongnu.org Developers
On Wed, Nov 17, 2021 at 10:42 AM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
>
> 0
>
> On 2021/11/17 上午8:03, Alistair Francis wrote:
> > On Wed, Nov 17, 2021 at 1:12 AM LIU Zhiwei <zhiwei_liu@c-sky.com> wrote:
> >> If PMP rules number is zero, it should not influence the TLB entry for
> >> M-mode program.
> > This doesn't sound right. From what I can tell if we have no rules
> > pmp_is_range_in_tlb() shouldn't have an effect on the tlb_size. What
> > error are you seeing?
>
> When address is in [0-4K] and no pmp rule configured, the tlb_size will
> be set to 1.
>
> This is caused by pmp_get_tlb_size return a value 1.
>
> if (pmp_sa >= tlb_sa && pmp_ea <= tlb_ea) {
> return pmp_ea - pmp_sa + 1;
>
> }
>
> Here pmp_sa == 0 and pmp_ea == 0.
Ah ok. Do you mind adding that to the commit message.
Also, do you think it would be better to add the check to
pmp_is_range_in_tlb() instead?
Alistair
>
> Thanks,
> Zhiwei
>
> > Alistair
> >
> >> Signed-off-by: LIU Zhiwei <zhiwei_liu@c-sky.com>
> >> ---
> >> target/riscv/cpu_helper.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
> >> index 9eeed38c7e..48da872d39 100644
> >> --- a/target/riscv/cpu_helper.c
> >> +++ b/target/riscv/cpu_helper.c
> >> @@ -376,7 +376,7 @@ static int get_physical_address_pmp(CPURISCVState *env, int *prot,
> >> }
> >>
> >> *prot = pmp_priv_to_page_prot(pmp_priv);
> >> - if (tlb_size != NULL) {
> >> + if ((tlb_size != NULL) && pmp_get_num_rules(env)) {
> >> if (pmp_is_range_in_tlb(env, addr & ~(*tlb_size - 1), &tlb_size_pmp)) {
> >> *tlb_size = tlb_size_pmp;
> >> }
> >> --
> >> 2.25.1
> >>
> >>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-19 13:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-16 15:11 [PATCH] target/riscv: Check PMP rules num before propagation LIU Zhiwei
2021-11-17 0:03 ` Alistair Francis
2021-11-17 0:42 ` LIU Zhiwei
2021-11-19 12:59 ` Alistair Francis
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).