From: Heiko Carstens <hca@linux.ibm.com>
To: Nico Boehr <nrb@linux.ibm.com>
Cc: borntraeger@linux.ibm.com, frankja@linux.ibm.com,
imbrenda@linux.ibm.com, david@redhat.com, kvm@vger.kernel.org,
linux-s390@vger.kernel.org
Subject: Re: [PATCH v1 1/2] KVM: s390: gaccess: check if guest address is in memslot
Date: Wed, 18 Sep 2024 12:55:57 +0200 [thread overview]
Message-ID: <20240918105557.6794-B-hca@linux.ibm.com> (raw)
In-Reply-To: <20240917151904.74314-2-nrb@linux.ibm.com>
On Tue, Sep 17, 2024 at 05:18:33PM +0200, Nico Boehr wrote:
> Previously, access_guest_page() did not check whether the given guest
> address is inside of a memslot. This is not a problem, since
> kvm_write_guest_page/kvm_read_guest_page return -EFAULT in this case.
...
> To be able to distinguish these two cases, return PGM_ADDRESSING in
> access_guest_page() when the guest address is outside guest memory. In
> access_guest_real(), populate vcpu->arch.pgm.code such that
> kvm_s390_inject_prog_cond() can be used in the caller for injecting into
> the guest (if applicable).
>
> Since this adds a new return value to access_guest_page(), we need to make
> sure that other callers are not confused by the new positive return value.
>
> There are the following users of access_guest_page():
> - access_guest_with_key() does the checking itself (in
> guest_range_to_gpas()), so this case should never happen. Even if, the
> handling is set up properly.
> - access_guest_real() just passes the return code to its callers, which
> are:
> - read_guest_real() - see below
> - write_guest_real() - see below
>
> There are the following users of read_guest_real():
> - ar_translation() in gaccess.c which already returns PGM_*
With this patch you actually fix a bug in ar_translation(), where two
read_guest_real() invocations might have returned -EFAULT instead of
the correct PGM_ADDRESSING.
Looks like the author assumed read_guest_real() would do the right
thing. See commit 664b49735370 ("KVM: s390: Add access register mode").
> Fixes: 2293897805c2 ("KVM: s390: add architecture compliant guest access functions")
> Cc: stable@vger.kernel.org
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
> ---
> arch/s390/kvm/gaccess.c | 7 +++++++
> arch/s390/kvm/gaccess.h | 14 ++++++++------
> 2 files changed, 15 insertions(+), 6 deletions(-)
> diff --git a/arch/s390/kvm/gaccess.c b/arch/s390/kvm/gaccess.c
> index e65f597e3044..004047578729 100644
> --- a/arch/s390/kvm/gaccess.c
> +++ b/arch/s390/kvm/gaccess.c
> @@ -828,6 +828,9 @@ static int access_guest_page(struct kvm *kvm, enum gacc_mode mode, gpa_t gpa,
> const gfn_t gfn = gpa_to_gfn(gpa);
> int rc;
>
> + if (!gfn_to_memslot(kvm, gfn))
> + return PGM_ADDRESSING;
> +
> if (mode == GACC_STORE)
> rc = kvm_write_guest_page(kvm, gfn, data, offset, len);
It would be nice to not add random empty lines to stay consistent with the
existing coding style.
> }
> +
> + if (rc > 0)
> + vcpu->arch.pgm.code = rc;
> +
> return rc;
> }
Same here.
But whoever applies this can change this, or not.
In any case:
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
next prev parent reply other threads:[~2024-09-18 10:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-17 15:18 [PATCH v1 0/2] KVM: s390: fix diag258 virtual-physical confusion Nico Boehr
2024-09-17 15:18 ` [PATCH v1 1/2] KVM: s390: gaccess: check if guest address is in memslot Nico Boehr
2024-09-18 10:55 ` Heiko Carstens [this message]
2024-09-18 11:03 ` Christian Borntraeger
2024-09-17 15:18 ` [PATCH v1 2/2] KVM: s390: Change virtual to physical address access in diag 0x258 handler Nico Boehr
2024-09-18 10:46 ` Christian Borntraeger
2024-09-18 10:58 ` Heiko Carstens
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=20240918105557.6794-B-hca@linux.ibm.com \
--to=hca@linux.ibm.com \
--cc=borntraeger@linux.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=nrb@linux.ibm.com \
/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.