linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Nicholas Piggin <npiggin@gmail.com>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Cc: "Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	Anju T Sudhakar <anju@linux.vnet.ibm.com>,
	Madhavan Srinivasan <maddy@linux.vnet.ibm.com>,
	Reza Arbab <arbab@linux.vnet.ibm.com>
Subject: Re: [PATCH 4/5] powerpc/64: Add VIRTUAL_BUG_ON checks for __va and __pa addresses
Date: Sun, 26 Dec 2021 17:20:05 +0000	[thread overview]
Message-ID: <2797b924-25d5-eb9d-3be7-bc0f99601d8f@csgroup.eu> (raw)
In-Reply-To: <1640426616.sx4j7ru11d.astroid@bobo.none>



Le 25/12/2021 à 11:10, Nicholas Piggin a écrit :
> Excerpts from Christophe Leroy's message of December 24, 2021 11:24 pm:
>> Hi Nic,
>>
>> Le 24/07/2019 à 10:46, Nicholas Piggin a écrit :
>>> Ensure __va is given a physical address below PAGE_OFFSET, and __pa is
>>> given a virtual address above PAGE_OFFSET.
>>>
>>> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
>>> ---
>>>    arch/powerpc/include/asm/page.h | 14 ++++++++++++--
>>>    1 file changed, 12 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
>>> index 0d52f57fca04..c8bb14ff4713 100644
>>> --- a/arch/powerpc/include/asm/page.h
>>> +++ b/arch/powerpc/include/asm/page.h
>>> @@ -215,9 +215,19 @@ static inline bool pfn_valid(unsigned long pfn)
>>>    /*
>>>     * gcc miscompiles (unsigned long)(&static_var) - PAGE_OFFSET
>>>     * with -mcmodel=medium, so we use & and | instead of - and + on 64-bit.
>>> + * This also results in better code generation.
>>>     */
>>> -#define __va(x) ((void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET))
>>> -#define __pa(x) ((unsigned long)(x) & 0x0fffffffffffffffUL)
>>> +#define __va(x)								\
>>> +({									\
>>> +	VIRTUAL_BUG_ON((unsigned long)(x) >= PAGE_OFFSET);		\
>>> +	(void *)(unsigned long)((phys_addr_t)(x) | PAGE_OFFSET);	\
>>> +})
>>> +
>>> +#define __pa(x)								\
>>> +({									\
>>> +	VIRTUAL_BUG_ON((unsigned long)(x) < PAGE_OFFSET);		\
>>
>> With this, it is likely that virt_addr_valid() BUGs on a non valid address.
>>
>> I think the purpose of virt_addr_valid() is to check addresses
>> seamlessly, see check_heap_object()
> 
> Looks like you're right. How did you catch that?

I caught that while looking at the problem reported by Kefeng where he 
says that virt_addr_valid() reports true on vmalloced memory on book3e/64


> 
> We could change virt_addr_valid() to make that test first. x86 and arm64
> both do checking rather than relying on !pfn_valid for < PAGE_OFFSET
> addresses.

That should work.

Maybe also we should implement a __pa_nodebug() like x86 and arm64 ?

Christophe

  reply	other threads:[~2021-12-26 17:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  8:46 [PATCH 1/5] powerpc/64s/radix: Fix memory hotplug section page table creation Nicholas Piggin
2019-07-24  8:46 ` [PATCH 2/5] powerpc/64s/radix: Fix memory hot-unplug page table split Nicholas Piggin
2019-07-24  9:55   ` Aneesh Kumar K.V
2019-07-24  8:46 ` [PATCH 3/5] powerpc/perf: fix imc allocation failure handling Nicholas Piggin
2019-07-24  9:58   ` Aneesh Kumar K.V
2019-07-24  8:46 ` [PATCH 4/5] powerpc/64: Add VIRTUAL_BUG_ON checks for __va and __pa addresses Nicholas Piggin
2019-07-24  9:59   ` Aneesh Kumar K.V
2019-07-29 11:57   ` Christophe Leroy
2021-12-24 13:24   ` Christophe Leroy
2021-12-25 10:10     ` Nicholas Piggin
2021-12-26 17:20       ` Christophe Leroy [this message]
2019-07-24  8:46 ` [PATCH 5/5] powerpc/64s/radix: Remove redundant pfn_pte bitop, add VM_BUG_ON Nicholas Piggin
2019-07-24  9:59   ` Aneesh Kumar K.V
2019-07-24  9:54 ` [PATCH 1/5] powerpc/64s/radix: Fix memory hotplug section page table creation Aneesh Kumar K.V
2019-08-22 13:08 ` Michael Ellerman

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=2797b924-25d5-eb9d-3be7-bc0f99601d8f@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=anju@linux.vnet.ibm.com \
    --cc=arbab@linux.vnet.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=npiggin@gmail.com \
    /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).