All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Christoffer Dall <cdall@cs.columbia.edu>
Cc: kvm@vger.kernel.org, catalin.marinas@arm.com,
	tech@virtualopensystems.com, android-virt@lists.cs.columbia.edu
Subject: Re: [PATCH v4 09/10] ARM: KVM: Handle I/O aborts
Date: Tue, 09 Aug 2011 14:34:57 +0300	[thread overview]
Message-ID: <4E411B61.5020601@redhat.com> (raw)
In-Reply-To: <20110806104007.27198.63426.stgit@localhost6.localdomain6>

On 08/06/2011 01:40 PM, Christoffer Dall wrote:
> When the guest accesses I/O memory this will create data abort
> exceptions and they are handled by decoding the HSR information
> (physical address, read/write, length, register) and forwarding reads
> and writes to QEMU which performs the device emulation.
>
> Certain classes of load/store operations do not support the syndrome
> information provided in the HSR and we therefore must be able to fetch
> the offending instruction from guest memory and decode it manually.
>
> This requires changing the general flow somewhat since new calls to run
> the VCPU must check if there's a pending MMIO load and perform the write
> after userspace has made the data available.

We need to move this to arch independent code.  Outside the scope of 
these patches, of course.

>   /******************************************************************************
> - * Co-processor emulation
> + * Utility functions common for all emulation code
> + *****************************************************************************/
> +
> +/*
> + * This one accepts a matrix where the first element is the
> + * bits as they must be, and the second element is the bitmask.
>    */
> +#define INSTR_NONE	-1
> +static int kvm_instr_index(u32 instr, u32 table[][2], int table_entries)
> +{
> +	int i;
> +	u32 mask;
> +
> +	for (i = 0; i<  table_entries; i++) {
> +		mask = table[i][1];
> +		if ((table[i][0]&  mask) == (instr&  mask))
> +			return i;
> +	}
> +	return INSTR_NONE;
> +}

Seems somewhat inefficient to do this for insn emulation.  Is there not 
a common prefix that can be used to determine the mask?

> +
> +/*
> + * Must be ordered with LOADS first and WRITES afterwards
> + * for easy distinction when doing MMIO.
> + */
> +#define NUM_LD_INSTR  9
> +enum INSTR_LS_INDEXES {
> +	INSTR_LS_LDRBT, INSTR_LS_LDRT, INSTR_LS_LDR, INSTR_LS_LDRB,
> +	INSTR_LS_LDRD, INSTR_LS_LDREX, INSTR_LS_LDRH, INSTR_LS_LDRSB,
> +	INSTR_LS_LDRSH,
> +	INSTR_LS_STRBT, INSTR_LS_STRT, INSTR_LS_STR, INSTR_LS_STRB,
> +	INSTR_LS_STRD, INSTR_LS_STREX, INSTR_LS_STRH,
> +	NUM_LS_INSTR
> +};
> +
> +static u32 ls_instr[NUM_LS_INSTR][2] = {
> +	{0x04700000, 0x0d700000}, /* LDRBT */
> +	{0x04300000, 0x0d700000}, /* LDRT  */
> +	{0x04100000, 0x0c500000}, /* LDR   */
> +	{0x04500000, 0x0c500000}, /* LDRB  */
> +	{0x000000d0, 0x0e1000f0}, /* LDRD  */
> +	{0x01900090, 0x0ff000f0}, /* LDREX */
> +	{0x001000b0, 0x0e1000f0}, /* LDRH  */
> +	{0x001000d0, 0x0e1000f0}, /* LDRSB */
> +	{0x001000f0, 0x0e1000f0}, /* LDRSH */
> +	{0x04600000, 0x0d700000}, /* STRBT */
> +	{0x04200000, 0x0d700000}, /* STRT  */
> +	{0x04000000, 0x0c500000}, /* STR   */
> +	{0x04400000, 0x0c500000}, /* STRB  */
> +	{0x000000f0, 0x0e1000f0}, /* STRD  */
> +	{0x01800090, 0x0ff000f0}, /* STREX */
> +	{0x000000b0, 0x0e1000f0}  /* STRH  */
> +};
> +

Okay, maybe not.  But surely there's some clever arithmetic the cpu uses 
to decode this.

> diff --git a/arch/arm/kvm/trace.h b/arch/arm/kvm/trace.h
> index 381ea4a..4f20d75 100644
> --- a/arch/arm/kvm/trace.h
> +++ b/arch/arm/kvm/trace.h
> @@ -39,6 +39,21 @@ TRACE_EVENT(kvm_exit,
>   	TP_printk("PC: 0x%08lx", __entry->vcpu_pc)
>   );
>
> +TRACE_EVENT(kvm_mmio_emulate,
> +	TP_PROTO(unsigned long vcpu_pc),
> +	TP_ARGS(vcpu_pc),

Please add the instruction bytes and any other information needed to 
decode the opcode (e.g. thumb mode).  Forx86 we have a trace-cmd plugin 
that disassembles guest instructions into the trace; it's very useful.

> +
> +	TP_STRUCT__entry(
> +		__field(	unsigned long,	vcpu_pc		)
> +	),
> +
> +	TP_fast_assign(
> +		__entry->vcpu_pc		= vcpu_pc;
> +	),
> +
> +	TP_printk("Emulate MMIO at: 0x%08lx", __entry->vcpu_pc)
> +);
> +
>   TRACE_EVENT(kvm_emulate_cp15_imp,
>   	TP_PROTO(unsigned long Op1, unsigned long Rt1, unsigned long CRn,
>   		 unsigned long CRm, unsigned long Op2, bool is_write),
>
>

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2011-08-09 11:35 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-06 10:38 [PATCH v4 00/10] KVM/ARM Implementation Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 01/10] ARM: KVM: Initial skeleton to compile KVM support Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 02/10] ARM: KVM: Hypervisor identity mapping Christoffer Dall
2011-08-09  9:20   ` Avi Kivity
2011-08-09  9:29     ` Catalin Marinas
2011-08-09  9:29     ` Christoffer Dall
2011-08-09 10:23       ` [Android-virt] " Alexey Smirnov
2011-08-09 11:23         ` Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 03/10] ARM: KVM: Add hypervisor inititalization Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 04/10] ARM: KVM: Memory virtualization setup Christoffer Dall
2011-08-09  9:57   ` Avi Kivity
2011-08-09 11:24     ` [Android-virt] " Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 05/10] ARM: KVM: Inject IRQs and FIQs from userspace Christoffer Dall
2011-08-09 10:07   ` Avi Kivity
2011-08-09 11:27     ` [Android-virt] " Christoffer Dall
2011-08-09 11:37       ` Avi Kivity
2011-08-09 11:40         ` Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 06/10] ARM: KVM: World-switch implementation Christoffer Dall
2011-08-09 11:09   ` Avi Kivity
2011-08-09 11:29     ` Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 07/10] ARM: KVM: Emulation framework and CP15 emulation Christoffer Dall
2011-08-09 11:17   ` Avi Kivity
2011-08-09 11:34     ` Christoffer Dall
2011-08-09 11:39       ` Avi Kivity
2011-08-09 11:40         ` Christoffer Dall
2011-08-06 10:39 ` [PATCH v4 08/10] ARM: KVM: Handle guest faults in KVM Christoffer Dall
2011-08-09 11:24   ` Avi Kivity
2011-08-09 11:35     ` Christoffer Dall
2011-08-06 10:40 ` [PATCH v4 09/10] ARM: KVM: Handle I/O aborts Christoffer Dall
2011-08-09 11:34   ` Avi Kivity [this message]
2011-08-09 11:39     ` Christoffer Dall
2011-08-09 11:46       ` Avi Kivity
2011-08-06 10:40 ` [PATCH v4 10/10] ARM: KVM: Guest wait-for-interrupts (WFI) support Christoffer Dall
2011-08-09 11:43 ` [PATCH v4 00/10] KVM/ARM Implementation Avi Kivity

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=4E411B61.5020601@redhat.com \
    --to=avi@redhat.com \
    --cc=android-virt@lists.cs.columbia.edu \
    --cc=catalin.marinas@arm.com \
    --cc=cdall@cs.columbia.edu \
    --cc=kvm@vger.kernel.org \
    --cc=tech@virtualopensystems.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.