diff mbox series

[v2,21/27] docs: kvm: Convert locking.txt to ReST format

Message ID 1464d69fe780940cec6ecec4ac2505b9701a1e01.1581000481.git.mchehab+huawei@kernel.org (mailing list archive)
State New, archived
Headers show
Series docs: virt: manually convert text documents to ReST format | expand

Commit Message

Mauro Carvalho Chehab Feb. 6, 2020, 2:50 p.m. UTC
- Use document title and chapter markups;
- Add markups for literal blocks;
- use :field: for field descriptions;
- Add blank lines and adjust indentation.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 Documentation/virt/kvm/index.rst              |   1 +
 .../virt/kvm/{locking.txt => locking.rst}     | 111 ++++++++++--------
 2 files changed, 63 insertions(+), 49 deletions(-)
 rename Documentation/virt/kvm/{locking.txt => locking.rst} (78%)

Comments

Cornelia Huck Feb. 6, 2020, 4:11 p.m. UTC | #1
On Thu,  6 Feb 2020 15:50:18 +0100
Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:

> - Use document title and chapter markups;
> - Add markups for literal blocks;
> - use :field: for field descriptions;
> - Add blank lines and adjust indentation.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  Documentation/virt/kvm/index.rst              |   1 +
>  .../virt/kvm/{locking.txt => locking.rst}     | 111 ++++++++++--------
>  2 files changed, 63 insertions(+), 49 deletions(-)
>  rename Documentation/virt/kvm/{locking.txt => locking.rst} (78%)

(...)

> @@ -48,19 +52,23 @@ restore the saved R/X bits if VMX_EPT_TRACK_ACCESS mask is set, or both. This
>  is safe because whenever changing these bits can be detected by cmpxchg.
>  
>  But we need carefully check these cases:
> -1): The mapping from gfn to pfn
> +
> +1) The mapping from gfn to pfn
> +
>  The mapping from gfn to pfn may be changed since we can only ensure the pfn
>  is not changed during cmpxchg. This is a ABA problem, for example, below case
>  will happen:
>  
> -At the beginning:
> -gpte = gfn1
> -gfn1 is mapped to pfn1 on host
> -spte is the shadow page table entry corresponding with gpte and
> -spte = pfn1
> +At the beginning::
>  
> -   VCPU 0                           VCPU0
> -on fast page fault path:
> +	gpte = gfn1
> +	gfn1 is mapped to pfn1 on host
> +	spte is the shadow page table entry corresponding with gpte and
> +	spte = pfn1
> +
> +	   VCPU 0                           VCPU0
> +
> +on fast page fault path::
>  
>     old_spte = *spte;
>                                   pfn1 is swapped out:

I'm wondering if that should rather be converted to a proper table.

(...)

> @@ -99,12 +109,14 @@ Accessed bit and Dirty bit can not be lost.
>  But it is not true after fast page fault since the spte can be marked
>  writable between reading spte and updating spte. Like below case:
>  
> -At the beginning:
> -spte.W = 0
> -spte.Accessed = 1
> +At the beginning::
>  
> -   VCPU 0                                       VCPU0
> -In mmu_spte_clear_track_bits():
> +	spte.W = 0
> +	spte.Accessed = 1
> +
> +	   VCPU 0                                       VCPU0
> +
> +In mmu_spte_clear_track_bits()::
>  
>     old_spte = *spte;
>  

This one as well.
Paolo Bonzini Feb. 6, 2020, 9:57 p.m. UTC | #2
On 06/02/20 17:11, Cornelia Huck wrote:
> On Thu,  6 Feb 2020 15:50:18 +0100
> Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:
> 
>> - Use document title and chapter markups;
>> - Add markups for literal blocks;
>> - use :field: for field descriptions;
>> - Add blank lines and adjust indentation.
>>
>> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
>> ---
>>  Documentation/virt/kvm/index.rst              |   1 +
>>  .../virt/kvm/{locking.txt => locking.rst}     | 111 ++++++++++--------
>>  2 files changed, 63 insertions(+), 49 deletions(-)
>>  rename Documentation/virt/kvm/{locking.txt => locking.rst} (78%)
> 
> (...)
> 
>> @@ -48,19 +52,23 @@ restore the saved R/X bits if VMX_EPT_TRACK_ACCESS mask is set, or both. This
>>  is safe because whenever changing these bits can be detected by cmpxchg.
>>  
>>  But we need carefully check these cases:
>> -1): The mapping from gfn to pfn
>> +
>> +1) The mapping from gfn to pfn
>> +
>>  The mapping from gfn to pfn may be changed since we can only ensure the pfn
>>  is not changed during cmpxchg. This is a ABA problem, for example, below case
>>  will happen:
>>  
>> -At the beginning:
>> -gpte = gfn1
>> -gfn1 is mapped to pfn1 on host
>> -spte is the shadow page table entry corresponding with gpte and
>> -spte = pfn1
>> +At the beginning::
>>  
>> -   VCPU 0                           VCPU0
>> -on fast page fault path:
>> +	gpte = gfn1
>> +	gfn1 is mapped to pfn1 on host
>> +	spte is the shadow page table entry corresponding with gpte and
>> +	spte = pfn1
>> +
>> +	   VCPU 0                           VCPU0
>> +
>> +on fast page fault path::
>>  
>>     old_spte = *spte;
>>                                   pfn1 is swapped out:
> 
> I'm wondering if that should rather be converted to a proper table.

Would be nicer but this is acceptable too I think.  Especially, the
monospaced font allows breaking the table and keeping the parts aligned.

But the two headers should be "CPU 0" and "CPU 1", and it's worth
changing that while we're at it.  Same for the table below.

Paolo


> 
>> @@ -99,12 +109,14 @@ Accessed bit and Dirty bit can not be lost.
>>  But it is not true after fast page fault since the spte can be marked
>>  writable between reading spte and updating spte. Like below case:
>>  
>> -At the beginning:
>> -spte.W = 0
>> -spte.Accessed = 1
>> +At the beginning::
>>  
>> -   VCPU 0                                       VCPU0
>> -In mmu_spte_clear_track_bits():
>> +	spte.W = 0
>> +	spte.Accessed = 1
>> +
>> +	   VCPU 0                                       VCPU0
>> +
>> +In mmu_spte_clear_track_bits()::
>>  
>>     old_spte = *spte;
>>  
> 
> This one as well.
Mauro Carvalho Chehab Feb. 6, 2020, 10:47 p.m. UTC | #3
Em Thu, 6 Feb 2020 22:57:39 +0100
Paolo Bonzini <pbonzini@redhat.com> escreveu:

> On 06/02/20 17:11, Cornelia Huck wrote:
> > On Thu,  6 Feb 2020 15:50:18 +0100
> > Mauro Carvalho Chehab <mchehab+huawei@kernel.org> wrote:
> >   
> >> - Use document title and chapter markups;
> >> - Add markups for literal blocks;
> >> - use :field: for field descriptions;
> >> - Add blank lines and adjust indentation.
> >>
> >> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> >> ---
> >>  Documentation/virt/kvm/index.rst              |   1 +
> >>  .../virt/kvm/{locking.txt => locking.rst}     | 111 ++++++++++--------
> >>  2 files changed, 63 insertions(+), 49 deletions(-)
> >>  rename Documentation/virt/kvm/{locking.txt => locking.rst} (78%)  
> > 
> > (...)
> >   
> >> @@ -48,19 +52,23 @@ restore the saved R/X bits if VMX_EPT_TRACK_ACCESS mask is set, or both. This
> >>  is safe because whenever changing these bits can be detected by cmpxchg.
> >>  
> >>  But we need carefully check these cases:
> >> -1): The mapping from gfn to pfn
> >> +
> >> +1) The mapping from gfn to pfn
> >> +
> >>  The mapping from gfn to pfn may be changed since we can only ensure the pfn
> >>  is not changed during cmpxchg. This is a ABA problem, for example, below case
> >>  will happen:
> >>  
> >> -At the beginning:
> >> -gpte = gfn1
> >> -gfn1 is mapped to pfn1 on host
> >> -spte is the shadow page table entry corresponding with gpte and
> >> -spte = pfn1
> >> +At the beginning::
> >>  
> >> -   VCPU 0                           VCPU0
> >> -on fast page fault path:
> >> +	gpte = gfn1
> >> +	gfn1 is mapped to pfn1 on host
> >> +	spte is the shadow page table entry corresponding with gpte and
> >> +	spte = pfn1
> >> +
> >> +	   VCPU 0                           VCPU0
> >> +
> >> +on fast page fault path::
> >>  
> >>     old_spte = *spte;
> >>                                   pfn1 is swapped out:  
> > 
> > I'm wondering if that should rather be converted to a proper table.  

Converting into a table would require to escape the asterisk, e. g.:

	old_spte = \*spte;

or:

	``old_spte = *spte;``

	(and, for consistency, for all other stuff there)
	

So, yeah, the html/pdf output could be nicer, but it would be worse for those
who read the .rst file.

> 
> Would be nicer but this is acceptable too I think.  Especially, the
> monospaced font allows breaking the table and keeping the parts aligned.

FYI, there's a way to setup monospaced font on a table by using a template.

As I pointed a while ago, it would require to add something to the
Sphinx theme:

	diff --git a/Documentation/sphinx-static/theme_overrides.css b/Documentation/sphinx-static/theme_overrides.css
	index e21e36cd6761..0948de6651f8 100644
	--- a/Documentation/sphinx-static/theme_overrides.css
	+++ b/Documentation/sphinx-static/theme_overrides.css
	@@ -125,3 +125,7 @@ div[class^="highlight"] pre {
	         color: inherit;
	     }
	 }
	+
	+table.monospaced {
	+	font-family: monospace, monospace;
	+}

Then use, at locking.rst (or anywhere when a monospaced font is desired):

	+.. cssclass:: monospaced

	+ ==== ====== =====
	+ Some Random Table
	+ ==== ====== =====

For completeness, a similar template class should also be needed at 
latex_prefix setting at Documentation/conf.py, implementing the same
feature for LaTeX and PDF output.

IMHO, this would be too complex for not much gain.

> 
> But the two headers should be "CPU 0" and "CPU 1", and it's worth
> changing that while we're at it.  Same for the table below.

Ok.

Maybe we could append the enclosed patch to this one. I suspect it would
visually be better.

Cheers,
Mauro

---

diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst
index 428cb3412ecc..82322a4c9fde 100644
--- a/Documentation/virt/kvm/locking.rst
+++ b/Documentation/virt/kvm/locking.rst
@@ -57,18 +57,18 @@ But we need carefully check these cases:
 
 The mapping from gfn to pfn may be changed since we can only ensure the pfn
 is not changed during cmpxchg. This is a ABA problem, for example, below case
-will happen:
+will happen::
 
-At the beginning::
+  At the beginning:
 
 	gpte = gfn1
 	gfn1 is mapped to pfn1 on host
 	spte is the shadow page table entry corresponding with gpte and
 	spte = pfn1
 
-	   VCPU 0                           VCPU0
+  On fast page fault path:
 
-on fast page fault path::
+	   CPU 0                           CPU 1
 
    old_spte = *spte;
                                  pfn1 is swapped out:
@@ -80,6 +80,7 @@ on fast page fault path::
                                  gfn2 by the guest:
                                     spte = pfn1;
 
+
    if (cmpxchg(spte, old_spte, old_spte+W)
 	mark_page_dirty(vcpu->kvm, gfn1)
              OOPS!!!
@@ -107,16 +108,16 @@ spte is read-only and the Accessed bit has already been set since the
 Accessed bit and Dirty bit can not be lost.
 
 But it is not true after fast page fault since the spte can be marked
-writable between reading spte and updating spte. Like below case:
+writable between reading spte and updating spte. Like below case::
 
-At the beginning::
+  At the beginning:
 
 	spte.W = 0
 	spte.Accessed = 1
 
-	   VCPU 0                                       VCPU0
+	   CPU 0                                       CPU 1
 
-In mmu_spte_clear_track_bits()::
+  In mmu_spte_clear_track_bits():
 
    old_spte = *spte;
Paolo Bonzini Feb. 6, 2020, 11:13 p.m. UTC | #4
On 06/02/20 23:47, Mauro Carvalho Chehab wrote:
>>
>> But the two headers should be "CPU 0" and "CPU 1", and it's worth
>> changing that while we're at it.  Same for the table below.
> 
> Ok.
> 
> Maybe we could append the enclosed patch to this one. I suspect it would
> visually be better.

Looks good to me, thanks.

Paolo

> 
> Cheers,
> Mauro
> 
> ---
> 
> diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst
> index 428cb3412ecc..82322a4c9fde 100644
> --- a/Documentation/virt/kvm/locking.rst
> +++ b/Documentation/virt/kvm/locking.rst
> @@ -57,18 +57,18 @@ But we need carefully check these cases:
>  
>  The mapping from gfn to pfn may be changed since we can only ensure the pfn
>  is not changed during cmpxchg. This is a ABA problem, for example, below case
> -will happen:
> +will happen::
>  
> -At the beginning::
> +  At the beginning:
>  
>  	gpte = gfn1
>  	gfn1 is mapped to pfn1 on host
>  	spte is the shadow page table entry corresponding with gpte and
>  	spte = pfn1
>  
> -	   VCPU 0                           VCPU0
> +  On fast page fault path:
>  
> -on fast page fault path::
> +	   CPU 0                           CPU 1
>  
>     old_spte = *spte;
>                                   pfn1 is swapped out:
> @@ -80,6 +80,7 @@ on fast page fault path::
>                                   gfn2 by the guest:
>                                      spte = pfn1;
>  
> +
>     if (cmpxchg(spte, old_spte, old_spte+W)
>  	mark_page_dirty(vcpu->kvm, gfn1)
>               OOPS!!!
> @@ -107,16 +108,16 @@ spte is read-only and the Accessed bit has already been set since the
>  Accessed bit and Dirty bit can not be lost.
>  
>  But it is not true after fast page fault since the spte can be marked
> -writable between reading spte and updating spte. Like below case:
> +writable between reading spte and updating spte. Like below case::
>  
> -At the beginning::
> +  At the beginning:
>  
>  	spte.W = 0
>  	spte.Accessed = 1
>  
> -	   VCPU 0                                       VCPU0
> +	   CPU 0                                       CPU 1
>  
> -In mmu_spte_clear_track_bits()::
> +  In mmu_spte_clear_track_bits():
>  
>     old_spte = *spte;
>  
>
Mauro Carvalho Chehab Feb. 7, 2020, 6:24 a.m. UTC | #5
> 
> > 
> > Would be nicer but this is acceptable too I think.  Especially, the
> > monospaced font allows breaking the table and keeping the parts aligned.  

I couldn't resist trying to use a table ;-)

The following patch does that. IMO, it looks nice on both text and html
outputs.

Cheers,
Mauro

diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst
index 428cb3412ecc..c02291beac3f 100644
--- a/Documentation/virt/kvm/locking.rst
+++ b/Documentation/virt/kvm/locking.rst
@@ -59,30 +59,39 @@ The mapping from gfn to pfn may be changed since we can only ensure the pfn
 is not changed during cmpxchg. This is a ABA problem, for example, below case
 will happen:
 
-At the beginning::
-
-	gpte = gfn1
-	gfn1 is mapped to pfn1 on host
-	spte is the shadow page table entry corresponding with gpte and
-	spte = pfn1
-
-	   VCPU 0                           VCPU0
-
-on fast page fault path::
-
-   old_spte = *spte;
-                                 pfn1 is swapped out:
-                                    spte = 0;
-
-                                 pfn1 is re-alloced for gfn2.
-
-                                 gpte is changed to point to
-                                 gfn2 by the guest:
-                                    spte = pfn1;
-
-   if (cmpxchg(spte, old_spte, old_spte+W)
-	mark_page_dirty(vcpu->kvm, gfn1)
-             OOPS!!!
++------------------------------------------------------------------------+
+| At the beginning::                                                     |
+|                                                                        |
+|	gpte = gfn1                                                      |
+|	gfn1 is mapped to pfn1 on host                                   |
+|	spte is the shadow page table entry corresponding with gpte and  |
+|	spte = pfn1                                                      |
++------------------------------------------------------------------------+
+| On fast page fault path:                                               |
++------------------------------------+-----------------------------------+
+| CPU 0:                             | CPU 1:                            |
++------------------------------------+-----------------------------------+
+| ::                                 |                                   |
+|                                    |                                   |
+|   old_spte = *spte;                |                                   |
++------------------------------------+-----------------------------------+
+|                                    | pfn1 is swapped out::             |
+|                                    |                                   |
+|                                    |    spte = 0;                      |
+|                                    |                                   |
+|                                    | pfn1 is re-alloced for gfn2.      |
+|                                    |                                   |
+|                                    | gpte is changed to point to       |
+|                                    | gfn2 by the guest::               |
+|                                    |                                   |
+|                                    |    spte = pfn1;                   |
++------------------------------------+-----------------------------------+
+| ::                                                                     |
+|                                                                        |
+|   if (cmpxchg(spte, old_spte, old_spte+W)                              |
+|	mark_page_dirty(vcpu->kvm, gfn1)                                 |
+|            OOPS!!!                                                     |
++------------------------------------------------------------------------+
 
 We dirty-log for gfn1, that means gfn2 is lost in dirty-bitmap.
 
@@ -109,36 +118,42 @@ Accessed bit and Dirty bit can not be lost.
 But it is not true after fast page fault since the spte can be marked
 writable between reading spte and updating spte. Like below case:
 
-At the beginning::
-
-	spte.W = 0
-	spte.Accessed = 1
-
-	   VCPU 0                                       VCPU0
-
-In mmu_spte_clear_track_bits()::
-
-   old_spte = *spte;
-
-   /* 'if' condition is satisfied. */
-   if (old_spte.Accessed == 1 &&
-        old_spte.W == 0)
-      spte = 0ull;
-                                         on fast page fault path:
-                                             spte.W = 1
-                                         memory write on the spte:
-                                             spte.Dirty = 1
-
-
-   else
-      old_spte = xchg(spte, 0ull)
-
-
-   if (old_spte.Accessed == 1)
-      kvm_set_pfn_accessed(spte.pfn);
-   if (old_spte.Dirty == 1)
-      kvm_set_pfn_dirty(spte.pfn);
-      OOPS!!!
++------------------------------------------------------------------------+
+| At the beginning::                                                     |
+|                                                                        |
+|	spte.W = 0                                                       |
+|	spte.Accessed = 1                                                |
++------------------------------------+-----------------------------------+
+| CPU 0:                             | CPU 1:                            |
++------------------------------------+-----------------------------------+
+| In mmu_spte_clear_track_bits()::   |                                   |
+|                                    |                                   |
+|  old_spte = *spte;                 |                                   |
+|                                    |                                   |
+|                                    |                                   |
+|  /* 'if' condition is satisfied. */|                                   |
+|  if (old_spte.Accessed == 1 &&     |                                   |
+|       old_spte.W == 0)             |                                   |
+|     spte = 0ull;                   |                                   |
++------------------------------------+-----------------------------------+
+|                                    | on fast page fault path::         |
+|                                    |                                   |
+|                                    |    spte.W = 1                     |
+|                                    |                                   |
+|                                    | memory write on the spte::        |
+|                                    |                                   |
+|                                    |    spte.Dirty = 1                 |
++------------------------------------+-----------------------------------+
+|  ::                                |                                   |
+|                                    |                                   |
+|   else                             |                                   |
+|     old_spte = xchg(spte, 0ull)    |                                   |
+|   if (old_spte.Accessed == 1)      |                                   |
+|     kvm_set_pfn_accessed(spte.pfn);|                                   |
+|   if (old_spte.Dirty == 1)         |                                   |
+|     kvm_set_pfn_dirty(spte.pfn);   |                                   |
+|     OOPS!!!                        |                                   |
++------------------------------------+-----------------------------------+
 
 The Dirty bit is lost in this case.
Cornelia Huck Feb. 7, 2020, 8:48 a.m. UTC | #6
On Fri, 7 Feb 2020 07:24:09 +0100
Mauro Carvalho Chehab <mchehab@infradead.org> wrote:

> >   
> > > 
> > > Would be nicer but this is acceptable too I think.  Especially, the
> > > monospaced font allows breaking the table and keeping the parts aligned.    
> 
> I couldn't resist trying to use a table ;-)
> 
> The following patch does that. IMO, it looks nice on both text and html
> outputs.

Now that I see this, I think this version is actually more readable
than the existing text.

> 
> Cheers,
> Mauro
> 
> diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst
> index 428cb3412ecc..c02291beac3f 100644
> --- a/Documentation/virt/kvm/locking.rst
> +++ b/Documentation/virt/kvm/locking.rst
> @@ -59,30 +59,39 @@ The mapping from gfn to pfn may be changed since we can only ensure the pfn
>  is not changed during cmpxchg. This is a ABA problem, for example, below case
>  will happen:
>  
> -At the beginning::
> -
> -	gpte = gfn1
> -	gfn1 is mapped to pfn1 on host
> -	spte is the shadow page table entry corresponding with gpte and
> -	spte = pfn1
> -
> -	   VCPU 0                           VCPU0
> -
> -on fast page fault path::
> -
> -   old_spte = *spte;
> -                                 pfn1 is swapped out:
> -                                    spte = 0;
> -
> -                                 pfn1 is re-alloced for gfn2.
> -
> -                                 gpte is changed to point to
> -                                 gfn2 by the guest:
> -                                    spte = pfn1;
> -
> -   if (cmpxchg(spte, old_spte, old_spte+W)
> -	mark_page_dirty(vcpu->kvm, gfn1)
> -             OOPS!!!
> ++------------------------------------------------------------------------+
> +| At the beginning::                                                     |
> +|                                                                        |
> +|	gpte = gfn1                                                      |
> +|	gfn1 is mapped to pfn1 on host                                   |
> +|	spte is the shadow page table entry corresponding with gpte and  |
> +|	spte = pfn1                                                      |
> ++------------------------------------------------------------------------+
> +| On fast page fault path:                                               |
> ++------------------------------------+-----------------------------------+
> +| CPU 0:                             | CPU 1:                            |
> ++------------------------------------+-----------------------------------+
> +| ::                                 |                                   |

The '::' directives look a bit like leftover christmas decorations,
but it's not really distracting, and on the plus side, we'll get nice
html formatting.

> +|                                    |                                   |
> +|   old_spte = *spte;                |                                   |
> ++------------------------------------+-----------------------------------+
> +|                                    | pfn1 is swapped out::             |
> +|                                    |                                   |
> +|                                    |    spte = 0;                      |
> +|                                    |                                   |
> +|                                    | pfn1 is re-alloced for gfn2.      |
> +|                                    |                                   |
> +|                                    | gpte is changed to point to       |
> +|                                    | gfn2 by the guest::               |
> +|                                    |                                   |
> +|                                    |    spte = pfn1;                   |
> ++------------------------------------+-----------------------------------+
> +| ::                                                                     |
> +|                                                                        |
> +|   if (cmpxchg(spte, old_spte, old_spte+W)                              |
> +|	mark_page_dirty(vcpu->kvm, gfn1)                                 |
> +|            OOPS!!!                                                     |
> ++------------------------------------------------------------------------+
>  
>  We dirty-log for gfn1, that means gfn2 is lost in dirty-bitmap.
>  

So I'd like to cast my vote for this version :)
Mauro Carvalho Chehab Feb. 10, 2020, 5:58 a.m. UTC | #7
Em Fri, 7 Feb 2020 09:48:03 +0100
Cornelia Huck <cohuck@redhat.com> escreveu:

> On Fri, 7 Feb 2020 07:24:09 +0100
> Mauro Carvalho Chehab <mchehab@infradead.org> wrote:
> 
> > >     
> > > > 
> > > > Would be nicer but this is acceptable too I think.  Especially, the
> > > > monospaced font allows breaking the table and keeping the parts aligned.      
> > 
> > I couldn't resist trying to use a table ;-)
> > 
> > The following patch does that. IMO, it looks nice on both text and html
> > outputs.  
> 
> Now that I see this, I think this version is actually more readable
> than the existing text.

Yes, that was my feeling too: even for one reading the text version,
it looked clearer on my eyes.

> 
> > 
> > Cheers,
> > Mauro
> > 
> > diff --git a/Documentation/virt/kvm/locking.rst b/Documentation/virt/kvm/locking.rst
> > index 428cb3412ecc..c02291beac3f 100644
> > --- a/Documentation/virt/kvm/locking.rst
> > +++ b/Documentation/virt/kvm/locking.rst
> > @@ -59,30 +59,39 @@ The mapping from gfn to pfn may be changed since we can only ensure the pfn
> >  is not changed during cmpxchg. This is a ABA problem, for example, below case
> >  will happen:
> >  
> > -At the beginning::
> > -
> > -	gpte = gfn1
> > -	gfn1 is mapped to pfn1 on host
> > -	spte is the shadow page table entry corresponding with gpte and
> > -	spte = pfn1
> > -
> > -	   VCPU 0                           VCPU0
> > -
> > -on fast page fault path::
> > -
> > -   old_spte = *spte;
> > -                                 pfn1 is swapped out:
> > -                                    spte = 0;
> > -
> > -                                 pfn1 is re-alloced for gfn2.
> > -
> > -                                 gpte is changed to point to
> > -                                 gfn2 by the guest:
> > -                                    spte = pfn1;
> > -
> > -   if (cmpxchg(spte, old_spte, old_spte+W)
> > -	mark_page_dirty(vcpu->kvm, gfn1)
> > -             OOPS!!!
> > ++------------------------------------------------------------------------+
> > +| At the beginning::                                                     |
> > +|                                                                        |
> > +|	gpte = gfn1                                                      |
> > +|	gfn1 is mapped to pfn1 on host                                   |
> > +|	spte is the shadow page table entry corresponding with gpte and  |
> > +|	spte = pfn1                                                      |
> > ++------------------------------------------------------------------------+
> > +| On fast page fault path:                                               |
> > ++------------------------------------+-----------------------------------+
> > +| CPU 0:                             | CPU 1:                            |
> > ++------------------------------------+-----------------------------------+
> > +| ::                                 |                                   |  
> 
> The '::' directives look a bit like leftover christmas decorations,
> but it's not really distracting, and on the plus side, we'll get nice
> html formatting.

Yes the only downside are those extra "::". The alternatives to it that
would produce a similar look and feel would be a lot worse.

> 
> > +|                                    |                                   |
> > +|   old_spte = *spte;                |                                   |
> > ++------------------------------------+-----------------------------------+
> > +|                                    | pfn1 is swapped out::             |
> > +|                                    |                                   |
> > +|                                    |    spte = 0;                      |
> > +|                                    |                                   |
> > +|                                    | pfn1 is re-alloced for gfn2.      |
> > +|                                    |                                   |
> > +|                                    | gpte is changed to point to       |
> > +|                                    | gfn2 by the guest::               |
> > +|                                    |                                   |
> > +|                                    |    spte = pfn1;                   |
> > ++------------------------------------+-----------------------------------+
> > +| ::                                                                     |
> > +|                                                                        |
> > +|   if (cmpxchg(spte, old_spte, old_spte+W)                              |
> > +|	mark_page_dirty(vcpu->kvm, gfn1)                                 |
> > +|            OOPS!!!                                                     |
> > ++------------------------------------------------------------------------+
> >  
> >  We dirty-log for gfn1, that means gfn2 is lost in dirty-bitmap.
> >    
> 
> So I'd like to cast my vote for this version :)
> 

Ok. I'm submitting version 3 with this version.

Regards,
Mauro

Cheers,
Mauro
diff mbox series

Patch

diff --git a/Documentation/virt/kvm/index.rst b/Documentation/virt/kvm/index.rst
index ac83bc588f7e..9be8f53b729d 100644
--- a/Documentation/virt/kvm/index.rst
+++ b/Documentation/virt/kvm/index.rst
@@ -12,6 +12,7 @@  KVM
    cpuid
    halt-polling
    hypercalls
+   locking
    msr
    vcpu-requests
 
diff --git a/Documentation/virt/kvm/locking.txt b/Documentation/virt/kvm/locking.rst
similarity index 78%
rename from Documentation/virt/kvm/locking.txt
rename to Documentation/virt/kvm/locking.rst
index 635cd6eaf714..428cb3412ecc 100644
--- a/Documentation/virt/kvm/locking.txt
+++ b/Documentation/virt/kvm/locking.rst
@@ -1,3 +1,6 @@ 
+.. SPDX-License-Identifier: GPL-2.0
+
+=================
 KVM Lock Overview
 =================
 
@@ -18,7 +21,7 @@  On x86, vcpu->mutex is taken outside kvm->arch.hyperv.hv_lock.
 Everything else is a leaf: no other lock is taken inside the critical
 sections.
 
-2: Exception
+2. Exception
 ------------
 
 Fast page fault:
@@ -28,15 +31,16 @@  the mmu-lock on x86. Currently, the page fault can be fast in one of the
 following two cases:
 
 1. Access Tracking: The SPTE is not present, but it is marked for access
-tracking i.e. the SPTE_SPECIAL_MASK is set. That means we need to
-restore the saved R/X bits. This is described in more detail later below.
+   tracking i.e. the SPTE_SPECIAL_MASK is set. That means we need to
+   restore the saved R/X bits. This is described in more detail later below.
 
 2. Write-Protection: The SPTE is present and the fault is
-caused by write-protect. That means we just need to change the W bit of the 
-spte.
+   caused by write-protect. That means we just need to change the W bit of
+   the spte.
 
 What we use to avoid all the race is the SPTE_HOST_WRITEABLE bit and
 SPTE_MMU_WRITEABLE bit on the spte:
+
 - SPTE_HOST_WRITEABLE means the gfn is writable on host.
 - SPTE_MMU_WRITEABLE means the gfn is writable on mmu. The bit is set when
   the gfn is writable on guest mmu and it is not write-protected by shadow
@@ -48,19 +52,23 @@  restore the saved R/X bits if VMX_EPT_TRACK_ACCESS mask is set, or both. This
 is safe because whenever changing these bits can be detected by cmpxchg.
 
 But we need carefully check these cases:
-1): The mapping from gfn to pfn
+
+1) The mapping from gfn to pfn
+
 The mapping from gfn to pfn may be changed since we can only ensure the pfn
 is not changed during cmpxchg. This is a ABA problem, for example, below case
 will happen:
 
-At the beginning:
-gpte = gfn1
-gfn1 is mapped to pfn1 on host
-spte is the shadow page table entry corresponding with gpte and
-spte = pfn1
+At the beginning::
 
-   VCPU 0                           VCPU0
-on fast page fault path:
+	gpte = gfn1
+	gfn1 is mapped to pfn1 on host
+	spte is the shadow page table entry corresponding with gpte and
+	spte = pfn1
+
+	   VCPU 0                           VCPU0
+
+on fast page fault path::
 
    old_spte = *spte;
                                  pfn1 is swapped out:
@@ -81,6 +89,7 @@  We dirty-log for gfn1, that means gfn2 is lost in dirty-bitmap.
 For direct sp, we can easily avoid it since the spte of direct sp is fixed
 to gfn. For indirect sp, before we do cmpxchg, we call gfn_to_pfn_atomic()
 to pin gfn to pfn, because after gfn_to_pfn_atomic():
+
 - We have held the refcount of pfn that means the pfn can not be freed and
   be reused for another gfn.
 - The pfn is writable that means it can not be shared between different gfns
@@ -91,7 +100,8 @@  Then, we can ensure the dirty bitmaps is correctly set for a gfn.
 Currently, to simplify the whole things, we disable fast page fault for
 indirect shadow page.
 
-2): Dirty bit tracking
+2) Dirty bit tracking
+
 In the origin code, the spte can be fast updated (non-atomically) if the
 spte is read-only and the Accessed bit has already been set since the
 Accessed bit and Dirty bit can not be lost.
@@ -99,12 +109,14 @@  Accessed bit and Dirty bit can not be lost.
 But it is not true after fast page fault since the spte can be marked
 writable between reading spte and updating spte. Like below case:
 
-At the beginning:
-spte.W = 0
-spte.Accessed = 1
+At the beginning::
 
-   VCPU 0                                       VCPU0
-In mmu_spte_clear_track_bits():
+	spte.W = 0
+	spte.Accessed = 1
+
+	   VCPU 0                                       VCPU0
+
+In mmu_spte_clear_track_bits()::
 
    old_spte = *spte;
 
@@ -134,7 +146,8 @@  In order to avoid this kind of issue, we always treat the spte as "volatile"
 if it can be updated out of mmu-lock, see spte_has_volatile_bits(), it means,
 the spte is always atomically updated in this case.
 
-3): flush tlbs due to spte updated
+3) flush tlbs due to spte updated
+
 If the spte is updated from writable to readonly, we should flush all TLBs,
 otherwise rmap_write_protect will find a read-only spte, even though the
 writable spte might be cached on a CPU's TLB.
@@ -166,47 +179,47 @@  which time it will be set using the Dirty tracking mechanism described above.
 3. Reference
 ------------
 
-Name:		kvm_lock
-Type:		mutex
-Arch:		any
-Protects:	- vm_list
+:Name:		kvm_lock
+:Type:		mutex
+:Arch:		any
+:Protects:	- vm_list
 
-Name:		kvm_count_lock
-Type:		raw_spinlock_t
-Arch:		any
-Protects:	- hardware virtualization enable/disable
-Comment:	'raw' because hardware enabling/disabling must be atomic /wrt
+:Name:		kvm_count_lock
+:Type:		raw_spinlock_t
+:Arch:		any
+:Protects:	- hardware virtualization enable/disable
+:Comment:	'raw' because hardware enabling/disabling must be atomic /wrt
 		migration.
 
-Name:		kvm_arch::tsc_write_lock
-Type:		raw_spinlock
-Arch:		x86
-Protects:	- kvm_arch::{last_tsc_write,last_tsc_nsec,last_tsc_offset}
+:Name:		kvm_arch::tsc_write_lock
+:Type:		raw_spinlock
+:Arch:		x86
+:Protects:	- kvm_arch::{last_tsc_write,last_tsc_nsec,last_tsc_offset}
 		- tsc offset in vmcb
-Comment:	'raw' because updating the tsc offsets must not be preempted.
+:Comment:	'raw' because updating the tsc offsets must not be preempted.
 
-Name:		kvm->mmu_lock
-Type:		spinlock_t
-Arch:		any
-Protects:	-shadow page/shadow tlb entry
-Comment:	it is a spinlock since it is used in mmu notifier.
+:Name:		kvm->mmu_lock
+:Type:		spinlock_t
+:Arch:		any
+:Protects:	-shadow page/shadow tlb entry
+:Comment:	it is a spinlock since it is used in mmu notifier.
 
-Name:		kvm->srcu
-Type:		srcu lock
-Arch:		any
-Protects:	- kvm->memslots
+:Name:		kvm->srcu
+:Type:		srcu lock
+:Arch:		any
+:Protects:	- kvm->memslots
 		- kvm->buses
-Comment:	The srcu read lock must be held while accessing memslots (e.g.
+:Comment:	The srcu read lock must be held while accessing memslots (e.g.
 		when using gfn_to_* functions) and while accessing in-kernel
 		MMIO/PIO address->device structure mapping (kvm->buses).
 		The srcu index can be stored in kvm_vcpu->srcu_idx per vcpu
 		if it is needed by multiple functions.
 
-Name:		blocked_vcpu_on_cpu_lock
-Type:		spinlock_t
-Arch:		x86
-Protects:	blocked_vcpu_on_cpu
-Comment:	This is a per-CPU lock and it is used for VT-d posted-interrupts.
+:Name:		blocked_vcpu_on_cpu_lock
+:Type:		spinlock_t
+:Arch:		x86
+:Protects:	blocked_vcpu_on_cpu
+:Comment:	This is a per-CPU lock and it is used for VT-d posted-interrupts.
 		When VT-d posted-interrupts is supported and the VM has assigned
 		devices, we put the blocked vCPU on the list blocked_vcpu_on_cpu
 		protected by blocked_vcpu_on_cpu_lock, when VT-d hardware issues