2019-10-30 09:02:49

by zhong jiang

[permalink] [raw]
Subject: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

WARN_ONCE is more clear and simpler. Just replace it.

Signed-off-by: zhong jiang <[email protected]>
---
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


2019-10-31 11:37:57

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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 <[email protected]>
>> ---
>> 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.

2019-10-31 11:56:00

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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 <[email protected]>
>> ---
>> 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

2019-10-31 12:01:20

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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.


2019-10-31 12:44:21

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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


2019-10-31 15:51:47

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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

2019-10-31 15:58:37

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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*
>


2019-11-01 08:46:26

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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

2019-11-01 15:59:28

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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


2019-11-01 16:04:20

by zhong jiang

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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

2019-11-01 16:21:40

by Borislav Petkov

[permalink] [raw]
Subject: Re: [PATCH] mm/ioremap: Use WARN_ONCE instead of printk() + WARN_ON_ONCE()

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