linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
@ 2019-10-30  8:57 zhong jiang
  2019-10-31 11:03 ` Borislav Petkov
  0 siblings, 1 reply; 12+ messages in thread
From: zhong jiang @ 2019-10-30  8:57 UTC (permalink / raw)
  To: peterz, tglx, mingo; +Cc: dave.hansen, bp, hpa, zhongjiang, x86, linux-kernel

WARN_ONCE is more clear and simpler. Just replace it.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 arch/x86/mm/ioremap.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index a39dcdb..3b74599 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
 		return NULL;
 
 	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
+			  (unsigned long long)phys_addr);
 		return NULL;
 	}
 
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-30  8:57 [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE() zhong jiang
@ 2019-10-31 11:03 ` Borislav Petkov
  2019-10-31 11:36   ` zhong jiang
  2019-10-31 11:54   ` zhong jiang
  0 siblings, 2 replies; 12+ messages in thread
From: Borislav Petkov @ 2019-10-31 11:03 UTC (permalink / raw)
  To: zhong jiang; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
> WARN_ONCE is more clear and simpler. Just replace it.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  arch/x86/mm/ioremap.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> index a39dcdb..3b74599 100644
> --- a/arch/x86/mm/ioremap.c
> +++ b/arch/x86/mm/ioremap.c
> @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
>  		return NULL;
>  
>  	if (!phys_addr_valid(phys_addr)) {
> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
> -		       (unsigned long long)phys_addr);
> -		WARN_ON_ONCE(1);
> +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
> +			  (unsigned long long)phys_addr);

Does
	WARN_ONCE(!phys_addr_valid(phys_addr),
		  "ioremap: invalid physical address %llx\n",
		  (unsigned long long)phys_addr);

work too?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 11:03 ` Borislav Petkov
@ 2019-10-31 11:36   ` zhong jiang
  2019-10-31 12:00     ` Joe Perches
  2019-10-31 11:54   ` zhong jiang
  1 sibling, 1 reply; 12+ messages in thread
From: zhong jiang @ 2019-10-31 11:36 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On 2019/10/31 19:03, Borislav Petkov wrote:
> On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
>> WARN_ONCE is more clear and simpler. Just replace it.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  arch/x86/mm/ioremap.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>> index a39dcdb..3b74599 100644
>> --- a/arch/x86/mm/ioremap.c
>> +++ b/arch/x86/mm/ioremap.c
>> @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
>>  		return NULL;
>>  
>>  	if (!phys_addr_valid(phys_addr)) {
>> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
>> -		       (unsigned long long)phys_addr);
>> -		WARN_ON_ONCE(1);
>> +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
>> +			  (unsigned long long)phys_addr);
> Does
> 	WARN_ONCE(!phys_addr_valid(phys_addr),
> 		  "ioremap: invalid physical address %llx\n",
> 		  (unsigned long long)phys_addr);
>
> work too?
>
Thanks, That is better. Will repost.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 11:03 ` Borislav Petkov
  2019-10-31 11:36   ` zhong jiang
@ 2019-10-31 11:54   ` zhong jiang
  2019-10-31 15:49     ` Borislav Petkov
  1 sibling, 1 reply; 12+ messages in thread
From: zhong jiang @ 2019-10-31 11:54 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On 2019/10/31 19:03, Borislav Petkov wrote:
> On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
>> WARN_ONCE is more clear and simpler. Just replace it.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  arch/x86/mm/ioremap.c | 5 ++---
>>  1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
>> index a39dcdb..3b74599 100644
>> --- a/arch/x86/mm/ioremap.c
>> +++ b/arch/x86/mm/ioremap.c
>> @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
>>  		return NULL;
>>  
>>  	if (!phys_addr_valid(phys_addr)) {
>> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
>> -		       (unsigned long long)phys_addr);
>> -		WARN_ON_ONCE(1);
>> +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
>> +			  (unsigned long long)phys_addr);
> Does
> 	WARN_ONCE(!phys_addr_valid(phys_addr),
> 		  "ioremap: invalid physical address %llx\n",
> 		  (unsigned long long)phys_addr);
>
> work too?
>
Look at this again, It should not works. Because that will change the logical.
if phys_addr_valid is false, we should drop out in time.

WARN_ONCE should be just visible for user not should to handle with address.

Thanks,
zhong jiang


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 11:36   ` zhong jiang
@ 2019-10-31 12:00     ` Joe Perches
  2019-10-31 12:40       ` zhong jiang
  2019-11-01 15:18       ` zhong jiang
  0 siblings, 2 replies; 12+ messages in thread
From: Joe Perches @ 2019-10-31 12:00 UTC (permalink / raw)
  To: zhong jiang, Borislav Petkov
  Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On Thu, 2019-10-31 at 19:36 +0800, zhong jiang wrote:
> On 2019/10/31 19:03, Borislav Petkov wrote:
> > On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
> > > WARN_ONCE is more clear and simpler. Just replace it.
[]
> > > diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
[]
> > > @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
> > >  		return NULL;
> > >  
> > >  	if (!phys_addr_valid(phys_addr)) {
> > > -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
> > > -		       (unsigned long long)phys_addr);
> > > -		WARN_ON_ONCE(1);
> > > +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
> > > +			  (unsigned long long)phys_addr);
> > Does
> > 	WARN_ONCE(!phys_addr_valid(phys_addr),
> > 		  "ioremap: invalid physical address %llx\n",
> > 		  (unsigned long long)phys_addr);
> > 
> > work too?
> > 
> Thanks, That is better. Will repost.

Perhaps this is not good patch concept as now each
invalid physical address will not be emitted.

Before:
	each invalid physical address printed
	one stack dump

After:
	one stck dump with first invalid physical address.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 12:00     ` Joe Perches
@ 2019-10-31 12:40       ` zhong jiang
  2019-11-01 15:18       ` zhong jiang
  1 sibling, 0 replies; 12+ messages in thread
From: zhong jiang @ 2019-10-31 12:40 UTC (permalink / raw)
  To: Joe Perches
  Cc: Borislav Petkov, peterz, tglx, mingo, dave.hansen, hpa, x86,
	linux-kernel

On 2019/10/31 20:00, Joe Perches wrote:
> On Thu, 2019-10-31 at 19:36 +0800, zhong jiang wrote:
>> On 2019/10/31 19:03, Borislav Petkov wrote:
>>> On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
>>>> WARN_ONCE is more clear and simpler. Just replace it.
> []
>>>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> []
>>>> @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
>>>>  		return NULL;
>>>>  
>>>>  	if (!phys_addr_valid(phys_addr)) {
>>>> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
>>>> -		       (unsigned long long)phys_addr);
>>>> -		WARN_ON_ONCE(1);
>>>> +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
>>>> +			  (unsigned long long)phys_addr);
>>> Does
>>> 	WARN_ONCE(!phys_addr_valid(phys_addr),
>>> 		  "ioremap: invalid physical address %llx\n",
>>> 		  (unsigned long long)phys_addr);
>>>
>>> work too?
>>>
>> Thanks, That is better. Will repost.
> Perhaps this is not good patch concept as now each
> invalid physical address will not be emitted.
>
> Before:
> 	each invalid physical address printed
> 	one stack dump
>
> After:
> 	one stck dump with first invalid physical address.
>
Yes,  I  has told that. 

How you think my above patch in the mail.  Thanks
>
> .
>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 11:54   ` zhong jiang
@ 2019-10-31 15:49     ` Borislav Petkov
  2019-10-31 15:54       ` zhong jiang
  0 siblings, 1 reply; 12+ messages in thread
From: Borislav Petkov @ 2019-10-31 15:49 UTC (permalink / raw)
  To: zhong jiang; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On Thu, Oct 31, 2019 at 07:54:09PM +0800, zhong jiang wrote:
> Look at this again, It should not works. Because that will change the logical.
> if phys_addr_valid is false, we should drop out in time.

That you can do too:

diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index a39dcdb5ae34..13f44cc064af 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -171,12 +171,10 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
 	if (!size || last_addr < phys_addr)
 		return NULL;
 
-	if (!phys_addr_valid(phys_addr)) {
-		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
-		       (unsigned long long)phys_addr);
-		WARN_ON_ONCE(1);
+	if (WARN_ONCE(!phys_addr_valid(phys_addr),
+	    "ioremap: invalid physical address %llx\n",
+	    (unsigned long long)phys_addr))
 		return NULL;
-	}
 
 	__ioremap_check_mem(phys_addr, size, &io_desc);
 
---

I'm not sure whether we care about printing every invalid address, as
Joe points out. Maybe we do... *shrug*

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 15:49     ` Borislav Petkov
@ 2019-10-31 15:54       ` zhong jiang
  2019-11-01  8:45         ` Borislav Petkov
  0 siblings, 1 reply; 12+ messages in thread
From: zhong jiang @ 2019-10-31 15:54 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On 2019/10/31 23:49, Borislav Petkov wrote:
> On Thu, Oct 31, 2019 at 07:54:09PM +0800, zhong jiang wrote:
>> Look at this again, It should not works. Because that will change the logical.
>> if phys_addr_valid is false, we should drop out in time.
> That you can do too:
>
> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> index a39dcdb5ae34..13f44cc064af 100644
> --- a/arch/x86/mm/ioremap.c
> +++ b/arch/x86/mm/ioremap.c
> @@ -171,12 +171,10 @@ __ioremap_caller(resource_size_t phys_addr, unsigned long size,
>  	if (!size || last_addr < phys_addr)
>  		return NULL;
>  
> -	if (!phys_addr_valid(phys_addr)) {
> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
> -		       (unsigned long long)phys_addr);
> -		WARN_ON_ONCE(1);
> +	if (WARN_ONCE(!phys_addr_valid(phys_addr),
> +	    "ioremap: invalid physical address %llx\n",
> +	    (unsigned long long)phys_addr))
>  		return NULL;
> -	}
>  
Yep,  WARN_ONCE alway return true in that case.

Thanks,
zhong jiang
>  	__ioremap_check_mem(phys_addr, size, &io_desc);
>  
> ---
>
> I'm not sure whether we care about printing every invalid address, as
> Joe points out. Maybe we do... *shrug*
>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 15:54       ` zhong jiang
@ 2019-11-01  8:45         ` Borislav Petkov
  2019-11-01 15:32           ` zhong jiang
  0 siblings, 1 reply; 12+ messages in thread
From: Borislav Petkov @ 2019-11-01  8:45 UTC (permalink / raw)
  To: zhong jiang; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On Thu, Oct 31, 2019 at 11:54:24PM +0800, zhong jiang wrote:
> Yep,  WARN_ONCE alway return true in that case.

Are you sure it does that always?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-10-31 12:00     ` Joe Perches
  2019-10-31 12:40       ` zhong jiang
@ 2019-11-01 15:18       ` zhong jiang
  1 sibling, 0 replies; 12+ messages in thread
From: zhong jiang @ 2019-11-01 15:18 UTC (permalink / raw)
  To: Joe Perches
  Cc: Borislav Petkov, peterz, tglx, mingo, dave.hansen, hpa, x86,
	linux-kernel

On 2019/10/31 20:00, Joe Perches wrote:
> On Thu, 2019-10-31 at 19:36 +0800, zhong jiang wrote:
>> On 2019/10/31 19:03, Borislav Petkov wrote:
>>> On Wed, Oct 30, 2019 at 04:57:18PM +0800, zhong jiang wrote:
>>>> WARN_ONCE is more clear and simpler. Just replace it.
> []
>>>> diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
> []
>>>> @@ -172,9 +172,8 @@ static void __ioremap_check_mem(resource_size_t addr, unsigned long size,
>>>>  		return NULL;
>>>>  
>>>>  	if (!phys_addr_valid(phys_addr)) {
>>>> -		printk(KERN_WARNING "ioremap: invalid physical address %llx\n",
>>>> -		       (unsigned long long)phys_addr);
>>>> -		WARN_ON_ONCE(1);
>>>> +		WARN_ONCE(1, "ioremap: invalid physical address %llx\n",
>>>> +			  (unsigned long long)phys_addr);
>>> Does
>>> 	WARN_ONCE(!phys_addr_valid(phys_addr),
>>> 		  "ioremap: invalid physical address %llx\n",
>>> 		  (unsigned long long)phys_addr);
>>>
>>> work too?
>>>
>> Thanks, That is better. Will repost.
> Perhaps this is not good patch concept as now each
> invalid physical address will not be emitted.
>
> Before:
> 	each invalid physical address printed
> 	one stack dump
>
> After:
> 	one stck dump with first invalid physical address.
>
I misunderstand your meaning.  You're right.  My patch change its logical.
Thanks for your reminder.

Sincerely,
zhong jiang
>
> .
>



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-11-01  8:45         ` Borislav Petkov
@ 2019-11-01 15:32           ` zhong jiang
  2019-11-01 16:03             ` Borislav Petkov
  0 siblings, 1 reply; 12+ messages in thread
From: zhong jiang @ 2019-11-01 15:32 UTC (permalink / raw)
  To: Borislav Petkov; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On 2019/11/1 16:45, Borislav Petkov wrote:
> On Thu, Oct 31, 2019 at 11:54:24PM +0800, zhong jiang wrote:
>> Yep,  WARN_ONCE alway return true in that case.
> Are you sure it does that always?
>
WARN_ONCE will alway return true if its condition is true.:-)


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()
  2019-11-01 15:32           ` zhong jiang
@ 2019-11-01 16:03             ` Borislav Petkov
  0 siblings, 0 replies; 12+ messages in thread
From: Borislav Petkov @ 2019-11-01 16:03 UTC (permalink / raw)
  To: zhong jiang; +Cc: peterz, tglx, mingo, dave.hansen, hpa, x86, linux-kernel

On Fri, Nov 01, 2019 at 11:32:11PM +0800, zhong jiang wrote:
> WARN_ONCE will alway return true if its condition is true.:-)

And if its condition is false?

Lemme save you some time: WARN_ONCE() returns the @condition value so
constructs like

	if (WARN_ONCE(condition,...))

are possible. Grep the code for examples.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-11-01 16:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-30  8:57 [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE() zhong jiang
2019-10-31 11:03 ` Borislav Petkov
2019-10-31 11:36   ` zhong jiang
2019-10-31 12:00     ` Joe Perches
2019-10-31 12:40       ` zhong jiang
2019-11-01 15:18       ` zhong jiang
2019-10-31 11:54   ` zhong jiang
2019-10-31 15:49     ` Borislav Petkov
2019-10-31 15:54       ` zhong jiang
2019-11-01  8:45         ` Borislav Petkov
2019-11-01 15:32           ` zhong jiang
2019-11-01 16:03             ` Borislav Petkov

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).