qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: Dongjiu Geng <gengdongjiu@huawei.com>
Cc: pbonzini@redhat.com, mst@redhat.com, zhaoshenglong@huawei.com,
	peter.maydell@linaro.org, mtosatti@redhat.com, rth@twiddle.net,
	ehabkost@redhat.com, james.morse@arm.com,
	christoffer.dall@linaro.org, marc.zyngier@arm.com,
	kvm@vger.kernel.org, qemu-devel@nongnu.org, qemu-arm@nongnu.org,
	huangshaoyu@huawei.com, zhengqiang10@huawei.com,
	xuwei5@hisilicon.com
Subject: Re: [Qemu-devel] [PATCH v14 5/9] target-arm: kvm64: inject synchronous External Abort
Date: Thu, 28 Dec 2017 14:49:10 +0100	[thread overview]
Message-ID: <20171228144910.49fad2a9@igors-macbook-pro.local> (raw)
In-Reply-To: <1514440458-10515-6-git-send-email-gengdongjiu@huawei.com>

On Thu, 28 Dec 2017 13:54:14 +0800
Dongjiu Geng <gengdongjiu@huawei.com> wrote:

> Add synchronous external abort injection logic, setup
> exception type and syndrome value. When switch to guest,
> guest will jump to the synchronous external abort vector
> table entry.
> 
> The ESR_ELx.DFSC is set to synchronous external abort(0x10),
> and ESR_ELx.FnV is set to not valid(0x1), which will tell
> guest that FAR is not valid and holds an UNKNOWN value.
> These value will be set to KVM register structures through
> KVM_SET_ONE_REG IOCTL.
> 
> Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com>
> ---
> Marc is against that KVM inject the synchronous external abort(SEA) in [1],
> so user space how to inject it. The test result that injection SEA to guest by Qemu
> is shown in [2].
is it possible to inject SEA when running in TCG mode?

it would be useful from testing/verification point of view
(i.e. we could test logic on non ARM host during 'make check')


> [1]: https://lkml.org/lkml/2017/3/2/110
> [2]:
> Taking exception 4 [Data Abort]
> ...from EL0 to EL1
> ...with ESR 0x24/0x92000410
> ...with FAR 0x0
> ...with ELR 0x40cf04
> ...to EL1 PC 0xffffffc000084c00 PSTATE 0x3c5
> after kvm_inject_arm_sea
> Unhandled fault: synchronous external abort (0x92000410) at 0x0000007fa234c12c
> CPU: 0 PID: 536 Comm: devmem Not tainted 4.1.0+ #20
> Hardware name: linux,dummy-virt (DT)
> task: ffffffc019ab2b00 ti: ffffffc008134000 task.ti: ffffffc008134000
> PC is at 0x40cf04
> LR is at 0x40cdec
> pc : [<000000000040cf04>] lr : [<000000000040cdec>] pstate: 60000000
> sp : 0000007ff7b24130
> x29: 0000007ff7b24260 x28: 0000000000000000
> x27: 00000000000000ad x26: 000000000049c000
> x25: 000000000048904b x24: 000000000049c000
> x23: 0000000040600000 x22: 0000007ff7b243a0
> x21: 0000000000000002 x20: 0000000000000000
> x19: 0000000000000020 x18: 0000000000000000
> x17: 000000000049c6d0 x16: 0000007fa22c85c0
> x15: 0000000000005798 x14: 0000007fa2205f1c
> x13: 0000007fa241ccb0 x12: 0000000000000137
> x11: 0000000000000000 x10: 0000000000000000
> x9 : 0000000000000000 x8 : 00000000000000de
> x7 : 0000000000000000 x6 : 0000000000002000
> x5 : 0000000040600000 x4 : 0000000000000003
> x3 : 0000000000000001 x2 : 0000000000000000
> x1 : 0000000000000000 x0 : 0000007fa2418000
> ---
>  target/arm/kvm64.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
> 
> diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c
> index a16abc8..c00450d 100644
> --- a/target/arm/kvm64.c
> +++ b/target/arm/kvm64.c
> @@ -582,6 +582,71 @@ int kvm_arm_cpreg_level(uint64_t regidx)
>      return KVM_PUT_RUNTIME_STATE;
>  }
>  
> +static int kvm_arm_cpreg_value(ARMCPU *cpu, ptrdiff_t fieldoffset)
> +{
> +    int i;
> +
> +    for (i = 0; i < cpu->cpreg_array_len; i++) {
> +        uint32_t regidx = kvm_to_cpreg_id(cpu->cpreg_indexes[i]);
> +        const ARMCPRegInfo *ri;
> +        ri = get_arm_cp_reginfo(cpu->cp_regs, regidx);
> +        if (!ri) {
> +            continue;
> +        }
> +
> +        if (ri->type & ARM_CP_NO_RAW) {
> +            continue;
> +        }
> +
> +        if (ri->fieldoffset == fieldoffset) {
> +            cpu->cpreg_values[i] = read_raw_cp_reg(&cpu->env, ri);
> +            return 0;
> +        }
> +    }
> +    return -EINVAL;
> +}
> +
> +/* Inject synchronous external abort */
> +static void kvm_inject_arm_sea(CPUState *c)
> +{
> +    ARMCPU *cpu = ARM_CPU(c);
> +    CPUARMState *env = &cpu->env;
> +    unsigned long cpsr = pstate_read(env);
> +    uint32_t esr, ret;
> +
> +    /* This exception is synchronous data abort*/
> +    c->exception_index = EXCP_DATA_ABORT;
> +    /* Inject the exception to guest El1 */
> +    env->exception.target_el = 1;
> +    CPUClass *cc = CPU_GET_CLASS(c);
> +
> +    /* Set the DFSC to synchronous external abort and set FnV to not valid,
> +     * this will tell guest the FAR_ELx is UNKNOWN for this abort.
> +     */
> +    esr = (0x10 | (1 << 10));
> +
> +    /* This exception comes from lower or current exception level. */
> +    if ((cpsr & 0xf) == PSTATE_MODE_EL0t) {
> +        esr |= (EC_DATAABORT << ARM_EL_EC_SHIFT);
> +    } else {
> +        esr |= (EC_DATAABORT_SAME_EL << ARM_EL_EC_SHIFT);
> +    }
> +
> +    /* For the AArch64, instruction length is 32-bit */
> +    esr |= ARM_EL_IL;
> +    env->exception.syndrome = esr;
> +
> +    cc->do_interrupt(c);
> +
> +    /* set ESR_EL1 */
> +    ret = kvm_arm_cpreg_value(cpu, offsetof(CPUARMState, cp15.esr_el[1]));
> +
> +    if (ret) {
> +        fprintf(stderr, "<%s> failed to set esr_el1\n", __func__);
> +        abort();
> +    }
> +}
> +
>  #define AARCH64_CORE_REG(x)   (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \
>                   KVM_REG_ARM_CORE | KVM_REG_ARM_CORE_REG(x))
>  

  reply	other threads:[~2017-12-28 13:49 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-28  5:54 [Qemu-devel] [PATCH v14 0/9] Add ARMv8 RAS virtualization support in QEMU Dongjiu Geng
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 1/9] ACPI: add some GHES structures and macros definition Dongjiu Geng
2017-12-28 12:29   ` Igor Mammedov
2018-01-03 10:29     ` gengdongjiu
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 2/9] ACPI: Add APEI GHES table generation and CPER record support Dongjiu Geng
2017-12-28 14:18   ` Igor Mammedov
2017-12-29  6:33     ` gengdongjiu
2018-01-03  2:21     ` gengdongjiu
2018-01-03 13:31       ` Igor Mammedov
2018-01-04  4:21         ` gengdongjiu
2018-01-09 16:51       ` Peter Maydell
2018-01-10  5:22         ` gengdongjiu
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 3/9] docs: APEI GHES generation and CPER record description Dongjiu Geng
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 4/9] ACPI: enable APEI GHES in the configure file Dongjiu Geng
2018-01-09 17:16   ` Peter Maydell
2018-01-10 12:20     ` gengdongjiu
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 5/9] target-arm: kvm64: inject synchronous External Abort Dongjiu Geng
2017-12-28 13:49   ` Igor Mammedov [this message]
2017-12-29  6:27     ` gengdongjiu
2018-01-09 17:30   ` Peter Maydell
2018-01-11  5:59     ` gengdongjiu
2018-01-11  9:53       ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2018-01-11 10:33         ` gengdongjiu
2018-01-13  5:24     ` [Qemu-devel] " gengdongjiu
2018-01-13  8:27       ` gengdongjiu
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 6/9] Move related hwpoison page functions to accel/kvm/ folder Dongjiu Geng
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 7/9] ARM: ACPI: Add GPIO notification type for hardware RAS error Dongjiu Geng
2017-12-28 14:53   ` Igor Mammedov
2018-01-03  3:48     ` gengdongjiu
2018-01-03 13:36       ` Igor Mammedov
2018-01-04  4:55         ` gengdongjiu
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 8/9] hw/arm/virt: Add RAS platform version for migration Dongjiu Geng
2017-12-28 14:58   ` Igor Mammedov
2018-01-03  4:02     ` gengdongjiu
2018-01-09 15:42     ` Peter Maydell
2017-12-28  5:54 ` [Qemu-devel] [PATCH v14 9/9] target-arm: kvm64: handle SIGBUS signal from kernel or KVM Dongjiu Geng
2017-12-28 15:07   ` Igor Mammedov
2018-01-03  9:13     ` gengdongjiu
2018-01-03 13:44       ` Igor Mammedov
2018-01-04  6:31         ` gengdongjiu
2018-01-09 17:14   ` Peter Maydell
2018-01-10 11:56     ` gengdongjiu

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=20171228144910.49fad2a9@igors-macbook-pro.local \
    --to=imammedo@redhat.com \
    --cc=christoffer.dall@linaro.org \
    --cc=ehabkost@redhat.com \
    --cc=gengdongjiu@huawei.com \
    --cc=huangshaoyu@huawei.com \
    --cc=james.morse@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=marc.zyngier@arm.com \
    --cc=mst@redhat.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=xuwei5@hisilicon.com \
    --cc=zhaoshenglong@huawei.com \
    --cc=zhengqiang10@huawei.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 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).