lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 14 Aug 2023 14:29:22 +0000
From:   Christophe Leroy <christophe.leroy@...roup.eu>
To:     Michael Ellerman <mpe@...erman.id.au>,
        Linus Walleij <linus.walleij@...aro.org>,
        Nicholas Piggin <npiggin@...il.com>
CC:     "linuxppc-dev@...ts.ozlabs.org" <linuxppc-dev@...ts.ozlabs.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "kvm@...r.kernel.org" <kvm@...r.kernel.org>
Subject: Re: [PATCH] powerpc: Make virt_to_pfn() a static inline



Le 14/08/2023 à 14:37, Michael Ellerman a écrit :
> Linus Walleij <linus.walleij@...aro.org> writes:
>> Making virt_to_pfn() a static inline taking a strongly typed
>> (const void *) makes the contract of a passing a pointer of that
>> type to the function explicit and exposes any misuse of the
>> macro virt_to_pfn() acting polymorphic and accepting many types
>> such as (void *), (unitptr_t) or (unsigned long) as arguments
>> without warnings.
> ...
>> diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
>> index f2b6bf5687d0..9ee4b6d4a82a 100644
>> --- a/arch/powerpc/include/asm/page.h
>> +++ b/arch/powerpc/include/asm/page.h
>> @@ -9,6 +9,7 @@
>>   #ifndef __ASSEMBLY__
>>   #include <linux/types.h>
>>   #include <linux/kernel.h>
>> +#include <linux/bug.h>
>>   #else
>>   #include <asm/types.h>
>>   #endif
>> @@ -119,16 +120,6 @@ extern long long virt_phys_offset;
>>   #define ARCH_PFN_OFFSET		((unsigned long)(MEMORY_START >> PAGE_SHIFT))
>>   #endif
>>   
>> -#define virt_to_pfn(kaddr)	(__pa(kaddr) >> PAGE_SHIFT)
>> -#define virt_to_page(kaddr)	pfn_to_page(virt_to_pfn(kaddr))
>> -#define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
>> -
>> -#define virt_addr_valid(vaddr)	({					\
>> -	unsigned long _addr = (unsigned long)vaddr;			\
>> -	_addr >= PAGE_OFFSET && _addr < (unsigned long)high_memory &&	\
>> -	pfn_valid(virt_to_pfn(_addr));					\
>> -})
>> -
>>   /*
>>    * On Book-E parts we need __va to parse the device tree and we can't
>>    * determine MEMORY_START until then.  However we can determine PHYSICAL_START
>> @@ -233,6 +224,25 @@ extern long long virt_phys_offset;
>>   #endif
>>   #endif
>>   
>> +#ifndef __ASSEMBLY__
>> +static inline unsigned long virt_to_pfn(const void *kaddr)
>> +{
>> +	return __pa(kaddr) >> PAGE_SHIFT;
>> +}
>> +
>> +static inline const void *pfn_to_kaddr(unsigned long pfn)
>> +{
>> +	return (const void *)(((unsigned long)__va(pfn)) << PAGE_SHIFT);
> 
> Any reason to do it this way rather than:
> 
> +       return __va(pfn << PAGE_SHIFT);

Even cleaner:

	return __va(PFN_PHYS(pfn));

> 
> Seems to be equivalent and much cleaner?
> 
> cheers

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ