* [PATCH] kvm: Map PFN-type memory regions as writable (if possible)
@ 2018-01-17 17:26 KarimAllah Ahmed
2018-01-17 17:56 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: KarimAllah Ahmed @ 2018-01-17 17:26 UTC (permalink / raw)
To: kvm
Cc: KarimAllah Ahmed, Paolo Bonzini, Radim Krčmář,
linux-kernel
For EPT-violations that are triggered by a read, the pages are also mapped with
write permissions (if their memory region is also writable). That would avoid
getting yet another fault on the same page when a write occurs.
This optimization only happens when you have a "struct page" backing the memory
region. So also enable it for memory regions that do not have a "struct page".
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
---
virt/kvm/kvm_main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 97da45e..0efb089 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1534,6 +1534,8 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
goto retry;
if (r < 0)
pfn = KVM_PFN_ERR_FAULT;
+ if (writable)
+ *writable = true;
} else {
if (async && vma_is_valid(vma, write_fault))
*async = true;
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] kvm: Map PFN-type memory regions as writable (if possible)
2018-01-17 17:26 [PATCH] kvm: Map PFN-type memory regions as writable (if possible) KarimAllah Ahmed
@ 2018-01-17 17:56 ` Paolo Bonzini
2018-01-17 18:18 ` [PATCH v2] " KarimAllah Ahmed
0 siblings, 1 reply; 4+ messages in thread
From: Paolo Bonzini @ 2018-01-17 17:56 UTC (permalink / raw)
To: KarimAllah Ahmed, kvm; +Cc: Radim Krčmář, linux-kernel
On 17/01/2018 18:26, KarimAllah Ahmed wrote:
> For EPT-violations that are triggered by a read, the pages are also mapped with
> write permissions (if their memory region is also writable). That would avoid
> getting yet another fault on the same page when a write occurs.
>
> This optimization only happens when you have a "struct page" backing the memory
> region. So also enable it for memory regions that do not have a "struct page".
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
> ---
> virt/kvm/kvm_main.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 97da45e..0efb089 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1534,6 +1534,8 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
> goto retry;
> if (r < 0)
> pfn = KVM_PFN_ERR_FAULT;
> + if (writable)
> + *writable = true;
> } else {
> if (async && vma_is_valid(vma, write_fault))
> *async = true;
>
Looks good, but it should be in hva_to_pfn_remapped.
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] kvm: Map PFN-type memory regions as writable (if possible)
2018-01-17 17:56 ` Paolo Bonzini
@ 2018-01-17 18:18 ` KarimAllah Ahmed
2018-01-18 8:36 ` Paolo Bonzini
0 siblings, 1 reply; 4+ messages in thread
From: KarimAllah Ahmed @ 2018-01-17 18:18 UTC (permalink / raw)
To: kvm
Cc: KarimAllah Ahmed, Paolo Bonzini, Radim Krčmář,
linux-kernel
For EPT-violations that are triggered by a read, the pages are also mapped with
write permissions (if their memory region is also writable). That would avoid
getting yet another fault on the same page when a write occurs.
This optimization only happens when you have a "struct page" backing the memory
region. So also enable it for memory regions that do not have a "struct page".
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Radim Krčmář <rkrcmar@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
---
v2:
- Move setting writable to hva_to_pfn_remapped
- Extend hva_to_pfn_remapped interface to accept writable as a parameter
---
virt/kvm/kvm_main.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 97da45e..88702d5 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1438,7 +1438,8 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault)
static int hva_to_pfn_remapped(struct vm_area_struct *vma,
unsigned long addr, bool *async,
- bool write_fault, kvm_pfn_t *p_pfn)
+ bool write_fault, bool *writable,
+ kvm_pfn_t *p_pfn)
{
unsigned long pfn;
int r;
@@ -1464,6 +1465,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma,
}
+ if (writable)
+ *writable = true;
/*
* Get a reference here because callers of *hva_to_pfn* and
@@ -1529,7 +1532,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
if (vma == NULL)
pfn = KVM_PFN_ERR_FAULT;
else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
- r = hva_to_pfn_remapped(vma, addr, async, write_fault, &pfn);
+ r = hva_to_pfn_remapped(vma, addr, async, write_fault, writable, &pfn);
if (r == -EAGAIN)
goto retry;
if (r < 0)
--
2.7.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] kvm: Map PFN-type memory regions as writable (if possible)
2018-01-17 18:18 ` [PATCH v2] " KarimAllah Ahmed
@ 2018-01-18 8:36 ` Paolo Bonzini
0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2018-01-18 8:36 UTC (permalink / raw)
To: KarimAllah Ahmed, kvm; +Cc: Radim Krčmář, linux-kernel
On 17/01/2018 19:18, KarimAllah Ahmed wrote:
> For EPT-violations that are triggered by a read, the pages are also mapped with
> write permissions (if their memory region is also writable). That would avoid
> getting yet another fault on the same page when a write occurs.
>
> This optimization only happens when you have a "struct page" backing the memory
> region. So also enable it for memory regions that do not have a "struct page".
>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Radim Krčmář <rkrcmar@redhat.com>
> Cc: kvm@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> Signed-off-by: KarimAllah Ahmed <karahmed@amazon.de>
>
> ---
> v2:
> - Move setting writable to hva_to_pfn_remapped
> - Extend hva_to_pfn_remapped interface to accept writable as a parameter
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> virt/kvm/kvm_main.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 97da45e..88702d5 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1438,7 +1438,8 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault)
>
> static int hva_to_pfn_remapped(struct vm_area_struct *vma,
> unsigned long addr, bool *async,
> - bool write_fault, kvm_pfn_t *p_pfn)
> + bool write_fault, bool *writable,
> + kvm_pfn_t *p_pfn)
> {
> unsigned long pfn;
> int r;
> @@ -1464,6 +1465,8 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma,
>
> }
>
> + if (writable)
> + *writable = true;
>
> /*
> * Get a reference here because callers of *hva_to_pfn* and
> @@ -1529,7 +1532,7 @@ static kvm_pfn_t hva_to_pfn(unsigned long addr, bool atomic, bool *async,
> if (vma == NULL)
> pfn = KVM_PFN_ERR_FAULT;
> else if (vma->vm_flags & (VM_IO | VM_PFNMAP)) {
> - r = hva_to_pfn_remapped(vma, addr, async, write_fault, &pfn);
> + r = hva_to_pfn_remapped(vma, addr, async, write_fault, writable, &pfn);
> if (r == -EAGAIN)
> goto retry;
> if (r < 0)
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-01-18 8:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-17 17:26 [PATCH] kvm: Map PFN-type memory regions as writable (if possible) KarimAllah Ahmed
2018-01-17 17:56 ` Paolo Bonzini
2018-01-17 18:18 ` [PATCH v2] " KarimAllah Ahmed
2018-01-18 8:36 ` Paolo Bonzini
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).