diff mbox series

[v2] riscv: mm: don't advertise 1 num_asid for 0 asid bits

Message ID 20210908173029.1104897-1-vgupta@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v2] riscv: mm: don't advertise 1 num_asid for 0 asid bits | expand

Commit Message

Vineet Gupta Sept. 8, 2021, 5:30 p.m. UTC
Even if mmu doesn't support ASID, current code calculates @num_asids=1
which is misleading, so avoid setting any asid related variables in such
case.

Also while here, print the number of asid bits discovered even for the
disabled case.

Verified this on Hifive Unmatched.

Reviewed-by: Anup Patel <anup@brainfault.org>
Signed-off-by: Vineet Gupta <vgupta@kernel.org>
---
 arch/riscv/mm/context.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Palmer Dabbelt Oct. 3, 2021, 5:10 p.m. UTC | #1
On Wed, 08 Sep 2021 10:30:29 PDT (-0700), vgupta@kernel.org wrote:
> Even if mmu doesn't support ASID, current code calculates @num_asids=1
> which is misleading, so avoid setting any asid related variables in such
> case.
>
> Also while here, print the number of asid bits discovered even for the
> disabled case.
>
> Verified this on Hifive Unmatched.
>
> Reviewed-by: Anup Patel <anup@brainfault.org>
> Signed-off-by: Vineet Gupta <vgupta@kernel.org>
> ---
>  arch/riscv/mm/context.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
> index ee3459cb6750..ea54cc0c9106 100644
> --- a/arch/riscv/mm/context.c
> +++ b/arch/riscv/mm/context.c
> @@ -233,8 +233,10 @@ static int __init asids_init(void)
>  	local_flush_tlb_all();
>
>  	/* Pre-compute ASID details */
> -	num_asids = 1 << asid_bits;
> -	asid_mask = num_asids - 1;
> +	if (asid_bits) {
> +		num_asids = 1 << asid_bits;
> +		asid_mask = num_asids - 1;
> +	}
>
>  	/*
>  	 * Use ASID allocator only if number of HW ASIDs are
> @@ -255,7 +257,7 @@ static int __init asids_init(void)
>  		pr_info("ASID allocator using %lu bits (%lu entries)\n",
>  			asid_bits, num_asids);
>  	} else {
> -		pr_info("ASID allocator disabled\n");
> +		pr_info("ASID allocator disabled (%lu bits)\n", asid_bits);
>  	}
>
>  	return 0;

Thanks, this is on for-next.
diff mbox series

Patch

diff --git a/arch/riscv/mm/context.c b/arch/riscv/mm/context.c
index ee3459cb6750..ea54cc0c9106 100644
--- a/arch/riscv/mm/context.c
+++ b/arch/riscv/mm/context.c
@@ -233,8 +233,10 @@  static int __init asids_init(void)
 	local_flush_tlb_all();
 
 	/* Pre-compute ASID details */
-	num_asids = 1 << asid_bits;
-	asid_mask = num_asids - 1;
+	if (asid_bits) {
+		num_asids = 1 << asid_bits;
+		asid_mask = num_asids - 1;
+	}
 
 	/*
 	 * Use ASID allocator only if number of HW ASIDs are
@@ -255,7 +257,7 @@  static int __init asids_init(void)
 		pr_info("ASID allocator using %lu bits (%lu entries)\n",
 			asid_bits, num_asids);
 	} else {
-		pr_info("ASID allocator disabled\n");
+		pr_info("ASID allocator disabled (%lu bits)\n", asid_bits);
 	}
 
 	return 0;