Changes in 4.9.277 ARM: dts: rockchip: fix pinctrl sleep nodename for rk3036-kylin and rk3288 ARM: dts: rockchip: Fix power-controller node names for rk3288 reset: ti-syscon: fix to_ti_syscon_reset_data macro ARM: brcmstb: dts: fix NAND nodes names ARM: dts: BCM63xx: Fix NAND nodes names ARM: dts: imx6: phyFLEX: Fix UART hardware flow control ARM: imx: pm-imx5: Fix references to imx5_cpu_suspend_info ARM: dts: stm32: fix RCC node name on stm32f429 MCU arm64: dts: juno: Update SCPI nodes as per the YAML schema thermal/core: Correct function name thermal_zone_device_unregister() kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set rtc: max77686: Do not enforce (incorrect) interrupt trigger type scsi: aic7xxx: Fix unintentional sign extension issue on left shift of u8 sched/fair: Fix CFS bandwidth hrtimer expiry type net: ipv6: fix return value of ip6_skb_dst_mtu net: bridge: sync fdb to new unicast-filtering ports net: bcmgenet: Ensure all TX/RX queues DMAs are disabled net: moxa: fix UAF in moxart_mac_probe net: qcom/emac: fix UAF in emac_remove net: ti: fix UAF in tlan_remove_one net: validate lwtstate->data before returning from skb_tunnel_info() tcp: annotate data races around tp->mtu_info ipv6: tcp: drop silly ICMPv6 packet too big messages ixgbe: Fix an error handling path in 'ixgbe_probe()' igb: Fix an error handling path in 'igb_probe()' fm10k: Fix an error handling path in 'fm10k_probe()' e1000e: Fix an error handling path in 'e1000_probe()' iavf: Fix an error handling path in 'iavf_probe()' igb: Check if num of q_vectors is smaller than max before array access perf lzma: Close lzma stream on exit perf test bpf: Free obj_buf perf probe-file: Delete namelist in del_events() on the error path spi: mediatek: fix fifo rx mode s390/bpf: Perform r1 range checking before accessing jit->seen_reg[r1] net: fix uninit-value in caif_seqpkt_sendmsg net: decnet: Fix sleeping inside in af_decnet netrom: Decrease sock refcount when sock timers expire scsi: iscsi: Fix iface sysfs attr detection scsi: target: Fix protect handling in WRITE SAME(32) Revert "USB: quirks: ignore remote wake-up on Fibocom L850-GL LTE modem" proc: Avoid mixing integer types in mem_rw() Revert "MIPS: add PMD table accounting into MIPS'pmd_alloc_one" s390/ftrace: fix ftrace_update_ftrace_func implementation ALSA: sb: Fix potential ABBA deadlock in CSP driver xhci: Fix lost USB 2 remote wake KVM: PPC: Book3S: Fix H_RTAS rets buffer overflow usb: hub: Disable USB 3 device initiated lpm if exit latency is too high USB: usb-storage: Add LaCie Rugged USB3-FW to IGNORE_UAS usb: max-3421: Prevent corruption of freed memory usb: renesas_usbhs: Fix superfluous irqs happen after usb_pkt_pop() USB: serial: option: add support for u-blox LARA-R6 family USB: serial: cp210x: fix comments for GE CS1000 USB: serial: cp210x: add ID for CEL EM3588 USB ZigBee stick tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop. media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() net: bcmgenet: ensure EXT_ENERGY_DET_MASK is clear iio: accel: bma180: Use explicit member assignment iio: accel: bma180: Fix BMA25x bandwidth register values btrfs: compression: don't try to compress if we don't have enough pages Linux 4.9.277 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: Ibb9aa2b6a757b06f50f0e77ef193df58dc813646
296 lines
6.6 KiB
C
296 lines
6.6 KiB
C
/*
|
|
* Copyright 2012 Michael Ellerman, IBM Corporation.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License, version 2, as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/kvm_host.h>
|
|
#include <linux/kvm.h>
|
|
#include <linux/err.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
#include <asm/kvm_book3s.h>
|
|
#include <asm/kvm_ppc.h>
|
|
#include <asm/hvcall.h>
|
|
#include <asm/rtas.h>
|
|
|
|
#ifdef CONFIG_KVM_XICS
|
|
static void kvm_rtas_set_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
|
|
{
|
|
u32 irq, server, priority;
|
|
int rc;
|
|
|
|
if (be32_to_cpu(args->nargs) != 3 || be32_to_cpu(args->nret) != 1) {
|
|
rc = -3;
|
|
goto out;
|
|
}
|
|
|
|
irq = be32_to_cpu(args->args[0]);
|
|
server = be32_to_cpu(args->args[1]);
|
|
priority = be32_to_cpu(args->args[2]);
|
|
|
|
rc = kvmppc_xics_set_xive(vcpu->kvm, irq, server, priority);
|
|
if (rc)
|
|
rc = -3;
|
|
out:
|
|
args->rets[0] = cpu_to_be32(rc);
|
|
}
|
|
|
|
static void kvm_rtas_get_xive(struct kvm_vcpu *vcpu, struct rtas_args *args)
|
|
{
|
|
u32 irq, server, priority;
|
|
int rc;
|
|
|
|
if (be32_to_cpu(args->nargs) != 1 || be32_to_cpu(args->nret) != 3) {
|
|
rc = -3;
|
|
goto out;
|
|
}
|
|
|
|
irq = be32_to_cpu(args->args[0]);
|
|
|
|
server = priority = 0;
|
|
rc = kvmppc_xics_get_xive(vcpu->kvm, irq, &server, &priority);
|
|
if (rc) {
|
|
rc = -3;
|
|
goto out;
|
|
}
|
|
|
|
args->rets[1] = cpu_to_be32(server);
|
|
args->rets[2] = cpu_to_be32(priority);
|
|
out:
|
|
args->rets[0] = cpu_to_be32(rc);
|
|
}
|
|
|
|
static void kvm_rtas_int_off(struct kvm_vcpu *vcpu, struct rtas_args *args)
|
|
{
|
|
u32 irq;
|
|
int rc;
|
|
|
|
if (be32_to_cpu(args->nargs) != 1 || be32_to_cpu(args->nret) != 1) {
|
|
rc = -3;
|
|
goto out;
|
|
}
|
|
|
|
irq = be32_to_cpu(args->args[0]);
|
|
|
|
rc = kvmppc_xics_int_off(vcpu->kvm, irq);
|
|
if (rc)
|
|
rc = -3;
|
|
out:
|
|
args->rets[0] = cpu_to_be32(rc);
|
|
}
|
|
|
|
static void kvm_rtas_int_on(struct kvm_vcpu *vcpu, struct rtas_args *args)
|
|
{
|
|
u32 irq;
|
|
int rc;
|
|
|
|
if (be32_to_cpu(args->nargs) != 1 || be32_to_cpu(args->nret) != 1) {
|
|
rc = -3;
|
|
goto out;
|
|
}
|
|
|
|
irq = be32_to_cpu(args->args[0]);
|
|
|
|
rc = kvmppc_xics_int_on(vcpu->kvm, irq);
|
|
if (rc)
|
|
rc = -3;
|
|
out:
|
|
args->rets[0] = cpu_to_be32(rc);
|
|
}
|
|
#endif /* CONFIG_KVM_XICS */
|
|
|
|
struct rtas_handler {
|
|
void (*handler)(struct kvm_vcpu *vcpu, struct rtas_args *args);
|
|
char *name;
|
|
};
|
|
|
|
static struct rtas_handler rtas_handlers[] = {
|
|
#ifdef CONFIG_KVM_XICS
|
|
{ .name = "ibm,set-xive", .handler = kvm_rtas_set_xive },
|
|
{ .name = "ibm,get-xive", .handler = kvm_rtas_get_xive },
|
|
{ .name = "ibm,int-off", .handler = kvm_rtas_int_off },
|
|
{ .name = "ibm,int-on", .handler = kvm_rtas_int_on },
|
|
#endif
|
|
};
|
|
|
|
struct rtas_token_definition {
|
|
struct list_head list;
|
|
struct rtas_handler *handler;
|
|
u64 token;
|
|
};
|
|
|
|
static int rtas_name_matches(char *s1, char *s2)
|
|
{
|
|
struct kvm_rtas_token_args args;
|
|
return !strncmp(s1, s2, sizeof(args.name));
|
|
}
|
|
|
|
static int rtas_token_undefine(struct kvm *kvm, char *name)
|
|
{
|
|
struct rtas_token_definition *d, *tmp;
|
|
|
|
lockdep_assert_held(&kvm->arch.rtas_token_lock);
|
|
|
|
list_for_each_entry_safe(d, tmp, &kvm->arch.rtas_tokens, list) {
|
|
if (rtas_name_matches(d->handler->name, name)) {
|
|
list_del(&d->list);
|
|
kfree(d);
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/* It's not an error to undefine an undefined token */
|
|
return 0;
|
|
}
|
|
|
|
static int rtas_token_define(struct kvm *kvm, char *name, u64 token)
|
|
{
|
|
struct rtas_token_definition *d;
|
|
struct rtas_handler *h = NULL;
|
|
bool found;
|
|
int i;
|
|
|
|
lockdep_assert_held(&kvm->arch.rtas_token_lock);
|
|
|
|
list_for_each_entry(d, &kvm->arch.rtas_tokens, list) {
|
|
if (d->token == token)
|
|
return -EEXIST;
|
|
}
|
|
|
|
found = false;
|
|
for (i = 0; i < ARRAY_SIZE(rtas_handlers); i++) {
|
|
h = &rtas_handlers[i];
|
|
if (rtas_name_matches(h->name, name)) {
|
|
found = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!found)
|
|
return -ENOENT;
|
|
|
|
d = kzalloc(sizeof(*d), GFP_KERNEL);
|
|
if (!d)
|
|
return -ENOMEM;
|
|
|
|
d->handler = h;
|
|
d->token = token;
|
|
|
|
list_add_tail(&d->list, &kvm->arch.rtas_tokens);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int kvm_vm_ioctl_rtas_define_token(struct kvm *kvm, void __user *argp)
|
|
{
|
|
struct kvm_rtas_token_args args;
|
|
int rc;
|
|
|
|
if (copy_from_user(&args, argp, sizeof(args)))
|
|
return -EFAULT;
|
|
|
|
mutex_lock(&kvm->arch.rtas_token_lock);
|
|
|
|
if (args.token)
|
|
rc = rtas_token_define(kvm, args.name, args.token);
|
|
else
|
|
rc = rtas_token_undefine(kvm, args.name);
|
|
|
|
mutex_unlock(&kvm->arch.rtas_token_lock);
|
|
|
|
return rc;
|
|
}
|
|
|
|
int kvmppc_rtas_hcall(struct kvm_vcpu *vcpu)
|
|
{
|
|
struct rtas_token_definition *d;
|
|
struct rtas_args args;
|
|
rtas_arg_t *orig_rets;
|
|
gpa_t args_phys;
|
|
int rc;
|
|
|
|
/*
|
|
* r4 contains the guest physical address of the RTAS args
|
|
* Mask off the top 4 bits since this is a guest real address
|
|
*/
|
|
args_phys = kvmppc_get_gpr(vcpu, 4) & KVM_PAM;
|
|
|
|
rc = kvm_read_guest(vcpu->kvm, args_phys, &args, sizeof(args));
|
|
if (rc)
|
|
goto fail;
|
|
|
|
/*
|
|
* args->rets is a pointer into args->args. Now that we've
|
|
* copied args we need to fix it up to point into our copy,
|
|
* not the guest args. We also need to save the original
|
|
* value so we can restore it on the way out.
|
|
*/
|
|
orig_rets = args.rets;
|
|
if (be32_to_cpu(args.nargs) >= ARRAY_SIZE(args.args)) {
|
|
/*
|
|
* Don't overflow our args array: ensure there is room for
|
|
* at least rets[0] (even if the call specifies 0 nret).
|
|
*
|
|
* Each handler must then check for the correct nargs and nret
|
|
* values, but they may always return failure in rets[0].
|
|
*/
|
|
rc = -EINVAL;
|
|
goto fail;
|
|
}
|
|
args.rets = &args.args[be32_to_cpu(args.nargs)];
|
|
|
|
mutex_lock(&vcpu->kvm->arch.rtas_token_lock);
|
|
|
|
rc = -ENOENT;
|
|
list_for_each_entry(d, &vcpu->kvm->arch.rtas_tokens, list) {
|
|
if (d->token == be32_to_cpu(args.token)) {
|
|
d->handler->handler(vcpu, &args);
|
|
rc = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
mutex_unlock(&vcpu->kvm->arch.rtas_token_lock);
|
|
|
|
if (rc == 0) {
|
|
args.rets = orig_rets;
|
|
rc = kvm_write_guest(vcpu->kvm, args_phys, &args, sizeof(args));
|
|
if (rc)
|
|
goto fail;
|
|
}
|
|
|
|
return rc;
|
|
|
|
fail:
|
|
/*
|
|
* We only get here if the guest has called RTAS with a bogus
|
|
* args pointer or nargs/nret values that would overflow the
|
|
* array. That means we can't get to the args, and so we can't
|
|
* fail the RTAS call. So fail right out to userspace, which
|
|
* should kill the guest.
|
|
*
|
|
* SLOF should actually pass the hcall return value from the
|
|
* rtas handler call in r3, so enter_rtas could be modified to
|
|
* return a failure indication in r3 and we could return such
|
|
* errors to the guest rather than failing to host userspace.
|
|
* However old guests that don't test for failure could then
|
|
* continue silently after errors, so for now we won't do this.
|
|
*/
|
|
return rc;
|
|
}
|
|
EXPORT_SYMBOL_GPL(kvmppc_rtas_hcall);
|
|
|
|
void kvmppc_rtas_tokens_free(struct kvm *kvm)
|
|
{
|
|
struct rtas_token_definition *d, *tmp;
|
|
|
|
list_for_each_entry_safe(d, tmp, &kvm->arch.rtas_tokens, list) {
|
|
list_del(&d->list);
|
|
kfree(d);
|
|
}
|
|
}
|