All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Sullivan <sullivan.james.f@gmail.com>
To: kvm@vger.kernel.org
Cc: gleb@kernel.org, pbonzini@redhat.com,
	"Radim Krčmář" <rkrcmar@redhat.com>
Subject: [Patch v5] x86: irq_comm: Add check for RH bit in kvm_set_msi_irq
Date: Fri, 13 Mar 2015 09:14:35 -0600	[thread overview]
Message-ID: <5502FEDB.3030606@gmail.com> (raw)

This patch adds a check for RH=1 in kvm_set_msi_irq. Currently the
DM bit is the only thing used to decide irq->dest_mode (logical when DM
set, physical when unset). Documentation indicates that the DM bit will
be 'ignored' when the RH bit is unset, and physical destination mode is
used in this case.

Fixed this to set irq->dest_mode to APIC_DEST_LOGICAL just in case both
RH=1/DM=1.

This patch doesn't completely handle RH=1; if RH=1 then the delivery will behave
as in low priority mode (deliver the interrupt to only the lowest priority processor),
but the delivery mode may still used to specify the semantics of the delivery beyond
its destination.

I will be trying and comparing a few options to handle this fully (extension of
struct kvm_lapic_irq, introduction of MSI specific delivery functions or helpers,
etc) and hope to have some patches to show in the near future.


Signed-off-by: James Sullivan <sullivan.james.f@gmail.com>
---
Changes since v2:
    * Added one time warning message when RH=1
    * Documented conflict between RH=1 and delivery mode
    * Tidied code to check RH=1/DM=1 (remove bool phys, use if/else)
Changes since v3:
    * Fixed logical error in RH=1/DM=1 check
    * Aligned quotation blocks in multiline pr_warn_once argument
Changes since v4:
    * Put error message string on single line

 arch/x86/kvm/irq_comm.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
index 72298b3..f2887ea 100644
--- a/arch/x86/kvm/irq_comm.c
+++ b/arch/x86/kvm/irq_comm.c
@@ -103,12 +103,24 @@ static inline void kvm_set_msi_irq(struct kvm_kernel_irq_routing_entry *e,
 			MSI_ADDR_DEST_ID_MASK) >> MSI_ADDR_DEST_ID_SHIFT;
 	irq->vector = (e->msi.data &
 			MSI_DATA_VECTOR_MASK) >> MSI_DATA_VECTOR_SHIFT;
-	irq->dest_mode = (1 << MSI_ADDR_DEST_MODE_SHIFT) & e->msi.address_lo;
+	/*
+	 * TODO Deal with RH bit of MSI message address
+	 *  IF RH=1, then MSI delivers only to the processor with the
+	 *  lowest interrupt priority among processors that can receive
+	 *  the interrupt.
+	 */
+	if ((e->msi.address_lo & MSI_ADDR_REDIRECTION_LOWPRI) &&
+			(e->msi.address_lo & MSI_ADDR_DEST_MODE_LOGICAL))
+		irq->dest_mode = APIC_DEST_LOGICAL;
+	else
+		irq->dest_mode = APIC_DEST_PHYSICAL;
 	irq->trig_mode = (1 << MSI_DATA_TRIGGER_SHIFT) & e->msi.data;
 	irq->delivery_mode = e->msi.data & 0x700;
+	if (e->msi.address_lo & MSI_ADDR_REDIRECTION_LOWPRI)
+		pr_warn_once(
+			"kvm: MSIs may not be correctly delivered with RH set.\n");
 	irq->level = 1;
 	irq->shorthand = 0;
-	/* TODO Deal with RH bit of MSI message address */
 }

 int kvm_set_msi(struct kvm_kernel_irq_routing_entry *e,
-- 
2.3.1


             reply	other threads:[~2015-03-13 15:16 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-13 15:14 James Sullivan [this message]
2015-03-13 15:48 ` [Patch v5] x86: irq_comm: Add check for RH bit in kvm_set_msi_irq Radim Krčmář
2015-03-17 15:23 ` James Sullivan
2015-03-18 22:52 ` Marcelo Tosatti
2015-03-19  0:59   ` James Sullivan
2015-03-19  1:09     ` Marcelo Tosatti
2015-03-19 13:00       ` Radim Krčmář
2015-03-19 22:51         ` James Sullivan
2015-03-20 15:15           ` Radim Krčmář
2015-03-20 15:22             ` James Sullivan
2015-03-20 17:50               ` James Sullivan
2015-03-23 21:13                 ` Radim Krčmář
2015-03-23 22:46                   ` James Sullivan
2015-03-24 14:03                     ` Radim Krčmář
2015-03-24 14:17                       ` James Sullivan
2015-04-02 22:08                       ` James Sullivan
2015-04-03 10:11                         ` Radim Krčmář
2015-04-21 12:18           ` Paolo Bonzini
2015-04-21 12:44             ` Radim Krčmář
2015-03-19  1:11     ` Marcelo Tosatti

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=5502FEDB.3030606@gmail.com \
    --to=sullivan.james.f@gmail.com \
    --cc=gleb@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rkrcmar@redhat.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.