linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Peter Xu <peterx@redhat.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Andrew Morton <akpm@linux-foundation.org>,
	Yang Shi <shy828301@gmail.com>, Hugh Dickins <hughd@google.com>,
	Andrea Arcangeli <aarcange@redhat.com>
Subject: Re: [PATCH v1] mm/swap: fix SWP_PFN_BITS with CONFIG_PHYS_ADDR_T_64BIT on 32bit
Date: Tue, 6 Dec 2022 10:16:08 +0100	[thread overview]
Message-ID: <0b122e73-22c3-e3a3-3aaf-d2b8361c196d@redhat.com> (raw)
In-Reply-To: <Y45u+0c4Hu2snEO2@x1n>

> 
> Thanks for debugging this one.

Sure!

> 
>> ---
>>
>> This makes my x86 PAE case work as expected again. Only cross compiled
>> on other architectures.
> 
> IIUC it's not about PAE but !SPARSEMEM, as PAE actually has it defined when
> with sparsemem:
> 
> #ifdef CONFIG_X86_32
> # ifdef CONFIG_X86_PAE
> #  define SECTION_SIZE_BITS	29
> #  define MAX_PHYSMEM_BITS	36
> # else
> #  define SECTION_SIZE_BITS	26
> #  define MAX_PHYSMEM_BITS	32
> # endif
> #else /* CONFIG_X86_32 */
> # define SECTION_SIZE_BITS	27 /* matt - 128 is convenient right now */
> # define MAX_PHYSMEM_BITS	(pgtable_l5_enabled() ? 52 : 46)
> #endif

Indeed, I'll extend the description accordingly.

> 
> One trivial comment below.
> 
>>
>> ---
>>   include/linux/swapops.h | 8 +++++---
>>   1 file changed, 5 insertions(+), 3 deletions(-)
>>
>> diff --git a/include/linux/swapops.h b/include/linux/swapops.h
>> index 86b95ccb81bb..4bb7a20f3fa5 100644
>> --- a/include/linux/swapops.h
>> +++ b/include/linux/swapops.h
>> @@ -32,11 +32,13 @@
>>    * store PFN, we only need SWP_PFN_BITS bits.  Each of the pfn swap entries
>>    * can use the extra bits to store other information besides PFN.
>>    */
>> -#ifdef MAX_PHYSMEM_BITS
>> +#if defined(MAX_PHYSMEM_BITS)
>>   #define SWP_PFN_BITS			(MAX_PHYSMEM_BITS - PAGE_SHIFT)
>> -#else  /* MAX_PHYSMEM_BITS */
>> +#elif !defined(CONFIG_64BIT) && defined(CONFIG_PHYS_ADDR_T_64BIT)
>> +#define SWP_PFN_BITS			SWP_TYPE_SHIFT
> 
> Can we add a comment showing where SWP_TYPE_SHIFT comes from?  It should be
> a min value comes from either the limitation of phys address width, or from
> definition of swp_entry_t (which is unsigned long).
> 
> Or I'd rather make this then the code explains better on itself, and the
> change should be smaller too:
> 
>   #ifdef MAX_PHYSMEM_BITS
>   #define SWP_PFN_BITS                   (MAX_PHYSMEM_BITS - PAGE_SHIFT)
>   #else  /* MAX_PHYSMEM_BITS */
> -#define SWP_PFN_BITS                   (BITS_PER_LONG - PAGE_SHIFT)
> +#define SWP_PFN_BITS                   MIN((sizeof(phys_addr_t) * 8) - \
> +                                           PAGE_SHIFT, SWP_TYPE_SHIFT)
>   #endif /* MAX_PHYSMEM_BITS */
>   #define SWP_PFN_MASK                   (BIT(SWP_PFN_BITS) - 1)
>                                   
> What do you think?

Sure, if we can make the compiler happy:

./include/linux/swapops.h: In function 'swp_offset_pfn':
./include/linux/swapops.h:38:41: error: implicit declaration of function 
'MIN' [-Werror=implicit-function-declaration]
    38 | #define SWP_PFN_BITS 
MIN((sizeof(phys_addr_t) * 8) - \
       |                                         ^~~
./include/vdso/bits.h:7:44: note: in definition of macro 'BIT'
     7 | #define BIT(nr)                 (UL(1) << (nr))
       |                                            ^~
./include/linux/swapops.h:41:46: note: in expansion of macro 'SWP_PFN_BITS'
    41 | #define SWP_PFN_MASK                    (BIT(SWP_PFN_BITS) - 1)
       |                                              ^~~~~~~~~~~~
./include/linux/swapops.h:119:36: note: in expansion of macro 'SWP_PFN_MASK'
   119 |         return swp_offset(entry) & SWP_PFN_MASK;
       |                                    ^~~~~~~~~~~~


using "min" instead gives plenty of warnings. min_t() seems to work:

diff --git a/include/linux/swapops.h b/include/linux/swapops.h
index 27ade4f22abb..088f25aa0e98 100644
--- a/include/linux/swapops.h
+++ b/include/linux/swapops.h
@@ -34,8 +34,10 @@
   */
  #ifdef MAX_PHYSMEM_BITS
  #define SWP_PFN_BITS                   (MAX_PHYSMEM_BITS - PAGE_SHIFT)
-#else  /* MAX_PHYSMEM_BITS */
-#define SWP_PFN_BITS                   (BITS_PER_LONG - PAGE_SHIFT)
+#else /* MAX_PHYSMEM_BITS */
+#define SWP_PFN_BITS                   min_t(phys_addr_t, \
+                                             (sizeof(phys_addr_t) * 8) - \
+                                             PAGE_SHIFT, SWP_TYPE_SHIFT)
  #endif /* MAX_PHYSMEM_BITS */
  #define SWP_PFN_MASK                   (BIT(SWP_PFN_BITS) - 1)



I'm currently cross-compiling that and will give it a churn.

Thanks!

-- 
Thanks,

David / dhildenb



      reply	other threads:[~2022-12-06  9:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-05 15:08 David Hildenbrand
2022-12-05 22:21 ` Peter Xu
2022-12-06  9:16   ` David Hildenbrand [this message]

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=0b122e73-22c3-e3a3-3aaf-d2b8361c196d@redhat.com \
    --to=david@redhat.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hughd@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=peterx@redhat.com \
    --cc=shy828301@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