linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] s390x/mm: avoid taking the table lock in gmap_pmd_op_walk()
@ 2018-08-06 15:54 David Hildenbrand
  2018-08-07  7:26 ` Janosch Frank
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand @ 2018-08-06 15:54 UTC (permalink / raw)
  To: linux-kernel
  Cc: linux-s390, Heiko Carstens, Martin Schwidefsky, Cornelia Huck,
	David Hildenbrand, Janosch Frank, Christian Borntraeger

Right now we temporarily take the page table lock in gmap_pmd_op_walk()
even though we know we won't need it (if we can never have 1mb pages
mapped into the gmap).

So let's special case this, so
gmap_protect_range()/gmap_sync_dirty_log_pmd() will not take the lock in
case huge pages are not allowed.

gmap_protect_range() is called quite frequently for managing shadow
page tables in vSIE environments.

Signed-off-by: David Hildenbrand <david@redhat.com>
---
 arch/s390/mm/gmap.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
index bb44990c8212..d4fa0a4514e0 100644
--- a/arch/s390/mm/gmap.c
+++ b/arch/s390/mm/gmap.c
@@ -905,10 +905,16 @@ static inline pmd_t *gmap_pmd_op_walk(struct gmap *gmap, unsigned long gaddr)
 	pmd_t *pmdp;
 
 	BUG_ON(gmap_is_shadow(gmap));
-	spin_lock(&gmap->guest_table_lock);
 	pmdp = (pmd_t *) gmap_table_walk(gmap, gaddr, 1);
+	if (!pmdp)
+		return NULL;
 
-	if (!pmdp || pmd_none(*pmdp)) {
+	/* without huge pages, there is no need to take the table lock */
+	if (!gmap->mm->context.allow_gmap_hpage_1m)
+		return pmd_none(*pmdp) ? NULL : pmdp;
+
+	spin_lock(&gmap->guest_table_lock);
+	if (pmd_none(*pmdp)) {
 		spin_unlock(&gmap->guest_table_lock);
 		return NULL;
 	}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] s390x/mm: avoid taking the table lock in gmap_pmd_op_walk()
  2018-08-06 15:54 [PATCH] s390x/mm: avoid taking the table lock in gmap_pmd_op_walk() David Hildenbrand
@ 2018-08-07  7:26 ` Janosch Frank
  2018-08-07  8:35   ` David Hildenbrand
  0 siblings, 1 reply; 3+ messages in thread
From: Janosch Frank @ 2018-08-07  7:26 UTC (permalink / raw)
  To: David Hildenbrand, linux-kernel
  Cc: linux-s390, Heiko Carstens, Martin Schwidefsky, Cornelia Huck,
	Christian Borntraeger


[-- Attachment #1.1: Type: text/plain, Size: 1811 bytes --]

On 06.08.2018 17:54, David Hildenbrand wrote:
> Right now we temporarily take the page table lock in gmap_pmd_op_walk()
> even though we know we won't need it (if we can never have 1mb pages
> mapped into the gmap).
> 
> So let's special case this, so
> gmap_protect_range()/gmap_sync_dirty_log_pmd() will not take the lock in
> case huge pages are not allowed.

So, let's make this a special case

> 
> gmap_protect_range() is called quite frequently for managing shadow
> page tables in vSIE environments.
> 
> Signed-off-by: David Hildenbrand <david@redhat.com>

If you make the patch title more specific:
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>

I considered getting rid of the last unlock with the !large check, but
in theory somebody could run a VM with the HPAGE CAP and 4k pages which
would then result in havoc if we wouldn't also adapt gmap_pmd_op_end.

> ---
>  arch/s390/mm/gmap.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/s390/mm/gmap.c b/arch/s390/mm/gmap.c
> index bb44990c8212..d4fa0a4514e0 100644
> --- a/arch/s390/mm/gmap.c
> +++ b/arch/s390/mm/gmap.c
> @@ -905,10 +905,16 @@ static inline pmd_t *gmap_pmd_op_walk(struct gmap *gmap, unsigned long gaddr)
>  	pmd_t *pmdp;
>  
>  	BUG_ON(gmap_is_shadow(gmap));
> -	spin_lock(&gmap->guest_table_lock);
>  	pmdp = (pmd_t *) gmap_table_walk(gmap, gaddr, 1);
> +	if (!pmdp)
> +		return NULL;
>  
> -	if (!pmdp || pmd_none(*pmdp)) {
> +	/* without huge pages, there is no need to take the table lock */
> +	if (!gmap->mm->context.allow_gmap_hpage_1m)
> +		return pmd_none(*pmdp) ? NULL : pmdp;
> +
> +	spin_lock(&gmap->guest_table_lock);
> +	if (pmd_none(*pmdp)) {
>  		spin_unlock(&gmap->guest_table_lock);
>  		return NULL;
>  	}
> 



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] s390x/mm: avoid taking the table lock in gmap_pmd_op_walk()
  2018-08-07  7:26 ` Janosch Frank
@ 2018-08-07  8:35   ` David Hildenbrand
  0 siblings, 0 replies; 3+ messages in thread
From: David Hildenbrand @ 2018-08-07  8:35 UTC (permalink / raw)
  To: Janosch Frank, linux-kernel
  Cc: linux-s390, Heiko Carstens, Martin Schwidefsky, Cornelia Huck,
	Christian Borntraeger

On 07.08.2018 09:26, Janosch Frank wrote:
> On 06.08.2018 17:54, David Hildenbrand wrote:
>> Right now we temporarily take the page table lock in gmap_pmd_op_walk()
>> even though we know we won't need it (if we can never have 1mb pages
>> mapped into the gmap).
>>
>> So let's special case this, so
>> gmap_protect_range()/gmap_sync_dirty_log_pmd() will not take the lock in
>> case huge pages are not allowed.
> 
> So, let's make this a special case
> 
>>
>> gmap_protect_range() is called quite frequently for managing shadow
>> page tables in vSIE environments.
>>
>> Signed-off-by: David Hildenbrand <david@redhat.com>
> 
> If you make the patch title more specific:
> Reviewed-by: Janosch Frank <frankja@linux.ibm.com>


"s390/mm: optimize locking without huge pages in gmap_pmd_op_walk()"

Thanks!

-- 

Thanks,

David / dhildenb

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-08-07  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-06 15:54 [PATCH] s390x/mm: avoid taking the table lock in gmap_pmd_op_walk() David Hildenbrand
2018-08-07  7:26 ` Janosch Frank
2018-08-07  8:35   ` David Hildenbrand

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