All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: David Laight <David.Laight@ACULAB.COM>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: "linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v2] powerpc/32: Don't use a struct based type for pte_t
Date: Sat, 18 Sep 2021 10:47:13 +0200	[thread overview]
Message-ID: <07fea205-ffb2-dc32-a56d-1cce51d5f931@csgroup.eu> (raw)
In-Reply-To: <505920070e5f4bf8ad7ccaa12f346469@AcuMS.aculab.com>



Le 17/09/2021 à 16:32, David Laight a écrit :
> From: Christophe Leroy
>> Sent: 17 September 2021 14:58
>>
>> Long time ago we had a config item called STRICT_MM_TYPECHECKS
>> to build the kernel with pte_t defined as a structure in order
>> to perform additional build checks or build it with pte_t
>> defined as a simple type in order to get simpler generated code.
>>
> ...
>> diff --git a/arch/powerpc/include/asm/pgtable-types.h b/arch/powerpc/include/asm/pgtable-types.h
>> index d11b4c61d686..c60199fc6fa6 100644
>> --- a/arch/powerpc/include/asm/pgtable-types.h
>> +++ b/arch/powerpc/include/asm/pgtable-types.h
>> @@ -5,14 +5,26 @@
>>   /* PTE level */
>>   #if defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES)
>>   typedef struct { pte_basic_t pte, pte1, pte2, pte3; } pte_t;
>> -#else
>> +#elif defined(__CHECKER__) || !defined(CONFIG_PPC32)
>>   typedef struct { pte_basic_t pte; } pte_t;
>> +#else
>> +typedef pte_basic_t pte_t;
>>   #endif
>> +
>> +#if defined(__CHECKER__) || !defined(CONFIG_PPC32) || \
>> +    (defined(CONFIG_PPC_8xx) && defined(CONFIG_PPC_16K_PAGES))
>>   #define __pte(x)	((pte_t) { (x) })
>>   static inline pte_basic_t pte_val(pte_t x)
>>   {
>>   	return x.pte;
>>   }
>> +#else
>> +#define __pte(x)	((pte_t)(x))
>> +static inline pte_basic_t pte_val(pte_t x)
>> +{
>> +	return x;
>> +}
>> +#endif
> 
> Would it be better to define:
> static inline pte_basic_*pte_basic(pte_t *x)
> {
> #if xxx
> 	return x;
> #else
> 	return &x->pte;
> #endif
> }
> 
> Then pte_val(x) is always *pt_basic(x)
> and the casts like:
> 
>> -	pte_basic_t *entry = &ptep->pte;
>> +	pte_basic_t *entry = (pte_basic_t *)ptep;
> 
> can go away.
> 


I don't like that idea too much, because it means going through a 
pointer of something which is not in memory at the begining. Doing that 
forces GCC to put the pte_t object on stack. And that's exactly the 
purpose of this patch: avoid having to go via memory. Allthough recent 
versions of GCC optimise it away at the end, I don't like it in principle.

And the only two places (pte_update() and set_huge_pte_at() where this 
cast is required are really two places very special which deal with real 
page tables. So IMHO it makes sense to explicitely show that what we use 
is the address of the entry in the page table.

Christophe

  reply	other threads:[~2021-09-18  8:47 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 13:57 [PATCH v2] powerpc/32: Don't use a struct based type for pte_t Christophe Leroy
2021-09-17 13:57 ` Christophe Leroy
2021-09-17 14:32 ` David Laight
2021-09-18  8:47   ` Christophe Leroy [this message]
2021-09-18  3:26 ` Michael Ellerman
2021-09-18  3:26   ` Michael Ellerman
2021-09-18  8:37   ` Christophe Leroy
2021-09-18  8:37     ` Christophe Leroy
2021-11-02 10:11 ` Michael Ellerman
2021-11-02 10:11   ` 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=07fea205-ffb2-dc32-a56d-1cce51d5f931@csgroup.eu \
    --to=christophe.leroy@csgroup.eu \
    --cc=David.Laight@ACULAB.COM \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.