From: Alexander Graf <agraf@suse.de>
To: "Cédric Le Goater" <clg@fr.ibm.com>
Cc: paulus@samba.org, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH] KVM: PPC: Book3S HV: return htab entries in big endian
Date: Thu, 02 Oct 2014 19:06:40 +0200 [thread overview]
Message-ID: <542D8620.2060503@suse.de> (raw)
In-Reply-To: <1412269080-18510-1-git-send-email-clg@fr.ibm.com>
On 02.10.14 18:58, Cédric Le Goater wrote:
> Saving and restoring guests on a KVM little endian host is currently
> broken because qemu assumes that htabs are big endian.
>
> This patch modifies kvm_htab_read and kvm_htab_write to make sure
> that the endianness expected by qemu is enforced on big and little
> endian hosts.
>
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>
> Tested on 3.17-rc7 with LE and BE host.
>
> Looking at the code, it is not very clear what we are doing
> in terms of endianness. May be this needs more work on both
> side, KVM and qemu, to remove the big endian assumptions ?
>
> Thanks,
>
> arch/powerpc/kvm/book3s_64_mmu_hv.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/arch/powerpc/kvm/book3s_64_mmu_hv.c b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> index 79294c4c5015..51dbf772158b 100644
> --- a/arch/powerpc/kvm/book3s_64_mmu_hv.c
> +++ b/arch/powerpc/kvm/book3s_64_mmu_hv.c
> @@ -1463,6 +1463,9 @@ static ssize_t kvm_htab_read(struct file *file, char __user *buf,
> }
>
> if (hdr.n_valid || hdr.n_invalid) {
> + hdr.index = cpu_to_be32(hdr.index);
> + hdr.n_valid = cpu_to_be16(hdr.n_valid);
> + hdr.n_invalid = cpu_to_be16(hdr.n_invalid);
This breaks strict endianness checking. cpu_to_be16 returns a be16 and
takes a u16 as input. Same for the 32bit version.
I think we're best off to keep the user space API native endian. So
really we should only ever have to convert from big to native endian on
read and native to big on write.
With that QEMU should do the "right thing" already, no?
Alex
> /* write back the header */
> if (__copy_to_user(hptr, &hdr, sizeof(hdr)))
> return -EFAULT;
> @@ -1542,6 +1545,8 @@ static ssize_t kvm_htab_write(struct file *file, const char __user *buf,
> err = -EFAULT;
> if (__get_user(v, lbuf) || __get_user(r, lbuf + 1))
> goto out;
> + v = be64_to_cpu(v);
> + r = be64_to_cpu(r);
> err = -EINVAL;
> if (!(v & HPTE_V_VALID))
> goto out;
>
next prev parent reply other threads:[~2014-10-02 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-02 16:58 [PATCH] KVM: PPC: Book3S HV: return htab entries in big endian Cédric Le Goater
2014-10-02 17:06 ` Alexander Graf [this message]
2014-10-03 12:05 ` Paul Mackerras
2014-10-03 21:05 ` Alexander Graf
2014-10-04 3:42 ` Alexey Kardashevskiy
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=542D8620.2060503@suse.de \
--to=agraf@suse.de \
--cc=clg@fr.ibm.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=paulus@samba.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox