2020-04-23 15:30:13

by Janakarajan Natarajan

[permalink] [raw]
Subject: [PATCH] KVM: SVM: Change flag passed to GUP fast in sev_pin_memory()

When trying to lock read-only pages, sev_pin_memory() fails because FOLL_WRITE
is used as the flag for get_user_pages_fast().

Commit 73b0140bf0fe ("mm/gup: change GUP fast to use flags rather than a write
'bool'") updated the get_user_pages_fast() call sites to use flags, but
incorrectly updated the call in sev_pin_memory(). As the original coding of this
call was correct, revert the change made by that commit.

Fixes: 73b0140bf0fe ("mm/gup: change GUP fast to use flags rather than a write 'bool'")
Signed-off-by: Janakarajan Natarajan <[email protected]>
---
arch/x86/kvm/svm/sev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index cf912b4aaba8..89f7f3aebd31 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -345,7 +345,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
return NULL;

/* Pin the user virtual address. */
- npinned = get_user_pages_fast(uaddr, npages, FOLL_WRITE, pages);
+ npinned = get_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
if (npinned != npages) {
pr_err("SEV: Failure locking %lu pages.\n", npages);
goto err;
--
2.17.1


2020-04-23 20:36:21

by Ira Weiny

[permalink] [raw]
Subject: Re: [PATCH] KVM: SVM: Change flag passed to GUP fast in sev_pin_memory()

On Thu, Apr 23, 2020 at 10:24:19AM -0500, Janakarajan Natarajan wrote:
> When trying to lock read-only pages, sev_pin_memory() fails because FOLL_WRITE
> is used as the flag for get_user_pages_fast().
>
> Commit 73b0140bf0fe ("mm/gup: change GUP fast to use flags rather than a write
> 'bool'") updated the get_user_pages_fast() call sites to use flags, but
> incorrectly updated the call in sev_pin_memory(). As the original coding of this
> call was correct, revert the change made by that commit.
>
> Fixes: 73b0140bf0fe ("mm/gup: change GUP fast to use flags rather than a write 'bool'")
> Signed-off-by: Janakarajan Natarajan <[email protected]>

Reviewed-by: Ira Weiny <[email protected]>

> ---
> arch/x86/kvm/svm/sev.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index cf912b4aaba8..89f7f3aebd31 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -345,7 +345,7 @@ static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
> return NULL;
>
> /* Pin the user virtual address. */
> - npinned = get_user_pages_fast(uaddr, npages, FOLL_WRITE, pages);
> + npinned = get_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
> if (npinned != npages) {
> pr_err("SEV: Failure locking %lu pages.\n", npages);
> goto err;
> --
> 2.17.1
>