All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: drjones@redhat.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Cc: andre.przywara@arm.com, Eric Auger <eric.auger@redhat.com>
Subject: [kvm-unit-tests PATCH v3 07/11] arm/arm64: gic: Wait for writes to acked or spurious to complete
Date: Fri, 29 Jan 2021 16:36:43 +0000	[thread overview]
Message-ID: <20210129163647.91564-8-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20210129163647.91564-1-alexandru.elisei@arm.com>

The IPI test has two parts: in the first part, it tests that the sender CPU
can send an IPI to itself (ipi_test_self()), and in the second part it
sends interrupts to even-numbered CPUs (ipi_test_smp()). When acknowledging
an interrupt, if we read back a spurious interrupt ID (1023), the handler
increments the index in the static array spurious corresponding to the CPU
ID that the handler is running on; if we get the expected interrupt ID, we
increment the same index in the acked array.

Reads of the spurious and acked arrays are synchronized with writes
performed before sending the IPI. The synchronization is done either in the
IPI sender function (GICv3), either by creating a data dependency (GICv2).

At the end of the test, the sender CPU reads from the acked and spurious
arrays to check against the expected behaviour. We need to make sure the
that writes in ipi_handler() are observable by the sender CPU. Use a DSB
ISHST to make sure that the writes have completed.

One might rightfully argue that there are no guarantees regarding when the
DSB instruction completes, just like there are no guarantees regarding when
the value is observed by the other CPUs. However, let's do our best and
instruct the CPU to complete the memory access when we know that it will be
needed.

We still need to follow the message passing pattern for the acked,
respectively bad_irq and bad_sender, because DSB guarantees that all memory
accesses that come before the barrier have completed, not that they have
completed in program order.

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/gic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arm/gic.c b/arm/gic.c
index 982c96681cf9..af4d4645c0ae 100644
--- a/arm/gic.c
+++ b/arm/gic.c
@@ -117,7 +117,6 @@ static void check_spurious(void)
 {
 	int cpu;
 
-	smp_rmb();
 	for_each_present_cpu(cpu) {
 		if (spurious[cpu])
 			report_info("WARN: cpu%d got %d spurious interrupts",
@@ -154,8 +153,10 @@ static void ipi_handler(struct pt_regs *regs __unused)
 		++acked[smp_processor_id()];
 	} else {
 		++spurious[smp_processor_id()];
-		smp_wmb();
 	}
+
+	/* Wait for writes to acked/spurious to complete */
+	dsb(ishst);
 }
 
 static void setup_irq(irq_handler_fn handler)
-- 
2.30.0


WARNING: multiple messages have this Message-ID (diff)
From: Alexandru Elisei <alexandru.elisei@arm.com>
To: drjones@redhat.com, kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu
Cc: andre.przywara@arm.com
Subject: [kvm-unit-tests PATCH v3 07/11] arm/arm64: gic: Wait for writes to acked or spurious to complete
Date: Fri, 29 Jan 2021 16:36:43 +0000	[thread overview]
Message-ID: <20210129163647.91564-8-alexandru.elisei@arm.com> (raw)
In-Reply-To: <20210129163647.91564-1-alexandru.elisei@arm.com>

The IPI test has two parts: in the first part, it tests that the sender CPU
can send an IPI to itself (ipi_test_self()), and in the second part it
sends interrupts to even-numbered CPUs (ipi_test_smp()). When acknowledging
an interrupt, if we read back a spurious interrupt ID (1023), the handler
increments the index in the static array spurious corresponding to the CPU
ID that the handler is running on; if we get the expected interrupt ID, we
increment the same index in the acked array.

Reads of the spurious and acked arrays are synchronized with writes
performed before sending the IPI. The synchronization is done either in the
IPI sender function (GICv3), either by creating a data dependency (GICv2).

At the end of the test, the sender CPU reads from the acked and spurious
arrays to check against the expected behaviour. We need to make sure the
that writes in ipi_handler() are observable by the sender CPU. Use a DSB
ISHST to make sure that the writes have completed.

One might rightfully argue that there are no guarantees regarding when the
DSB instruction completes, just like there are no guarantees regarding when
the value is observed by the other CPUs. However, let's do our best and
instruct the CPU to complete the memory access when we know that it will be
needed.

We still need to follow the message passing pattern for the acked,
respectively bad_irq and bad_sender, because DSB guarantees that all memory
accesses that come before the barrier have completed, not that they have
completed in program order.

Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 arm/gic.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/arm/gic.c b/arm/gic.c
index 982c96681cf9..af4d4645c0ae 100644
--- a/arm/gic.c
+++ b/arm/gic.c
@@ -117,7 +117,6 @@ static void check_spurious(void)
 {
 	int cpu;
 
-	smp_rmb();
 	for_each_present_cpu(cpu) {
 		if (spurious[cpu])
 			report_info("WARN: cpu%d got %d spurious interrupts",
@@ -154,8 +153,10 @@ static void ipi_handler(struct pt_regs *regs __unused)
 		++acked[smp_processor_id()];
 	} else {
 		++spurious[smp_processor_id()];
-		smp_wmb();
 	}
+
+	/* Wait for writes to acked/spurious to complete */
+	dsb(ishst);
 }
 
 static void setup_irq(irq_handler_fn handler)
-- 
2.30.0

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

  parent reply	other threads:[~2021-01-29 16:39 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-29 16:36 [kvm-unit-tests PATCH v3 00/11] GIC fixes and improvements Alexandru Elisei
2021-01-29 16:36 ` Alexandru Elisei
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 01/11] lib: arm/arm64: gicv3: Add missing barrier when sending IPIs Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 02/11] lib: arm/arm64: gicv2: Document existing barriers " Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-03 12:59   ` Auger Eric
2021-02-03 12:59     ` Auger Eric
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 03/11] arm/arm64: gic: Remove SMP synchronization from ipi_clear_active_handler() Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 04/11] arm/arm64: gic: Remove unnecessary synchronization with stats_reset() Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-03 12:59   ` Auger Eric
2021-02-03 12:59     ` Auger Eric
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 05/11] arm/arm64: gic: Use correct memory ordering for the IPI test Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-03 12:59   ` Auger Eric
2021-02-03 12:59     ` Auger Eric
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 06/11] arm/arm64: gic: Check spurious and bad_sender in the active test Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-01-29 16:36 ` Alexandru Elisei [this message]
2021-01-29 16:36   ` [kvm-unit-tests PATCH v3 07/11] arm/arm64: gic: Wait for writes to acked or spurious to complete Alexandru Elisei
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 08/11] arm/arm64: gic: Split check_acked() into two functions Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-05 11:23   ` Auger Eric
2021-02-05 11:23     ` Auger Eric
2021-02-16 18:33   ` Andre Przywara
2021-02-16 18:33     ` Andre Przywara
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 09/11] arm/arm64: gic: Make check_acked() more generic Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 10/11] arm64: gic: its-trigger: Don't trigger the LPI while it is pending Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-05 11:23   ` Auger Eric
2021-02-05 11:23     ` Auger Eric
2021-01-29 16:36 ` [kvm-unit-tests PATCH v3 11/11] arm64: gic: Use IPI test checking for the LPI tests Alexandru Elisei
2021-01-29 16:36   ` Alexandru Elisei
2021-02-05 13:30   ` Auger Eric
2021-02-05 13:30     ` Auger Eric
2021-02-08 12:02     ` Alexandru Elisei
2021-02-08 12:02       ` Alexandru Elisei
2021-01-29 16:53 ` [kvm-unit-tests PATCH v3 00/11] GIC fixes and improvements Alexandru Elisei
2021-01-29 16:53   ` Alexandru Elisei

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=20210129163647.91564-8-alexandru.elisei@arm.com \
    --to=alexandru.elisei@arm.com \
    --cc=andre.przywara@arm.com \
    --cc=drjones@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    /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.