All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Tyshchenko <olekstysh@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Julien Grall <julien@xen.org>,
	Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
	Paul Durrant <paul@xen.org>, Julien Grall <julien.grall@arm.com>
Subject: [PATCH V5 17/22] xen/ioreq: Introduce domain_has_ioreq_server()
Date: Mon, 25 Jan 2021 21:08:24 +0200	[thread overview]
Message-ID: <1611601709-28361-18-git-send-email-olekstysh@gmail.com> (raw)
In-Reply-To: <1611601709-28361-1-git-send-email-olekstysh@gmail.com>

From: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>

This patch introduces a helper the main purpose of which is to check
if a domain is using IOREQ server(s).

On Arm the current benefit is to avoid calling vcpu_ioreq_handle_completion()
(which implies iterating over all possible IOREQ servers anyway)
on every return in leave_hypervisor_to_guest() if there is no active
servers for the particular domain.
Also this helper will be used by one of the subsequent patches on Arm.

Signed-off-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
CC: Julien Grall <julien.grall@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
Reviewed-by: Paul Durrant <paul@xen.org>
[On Arm only]
Tested-by: Wei Chen <Wei.Chen@arm.com>

---
Please note, this is a split/cleanup/hardening of Julien's PoC:
"Add support for Guest IO forwarding to a device emulator"

Changes RFC -> V1:
   - new patch

Changes V1 -> V2:
   - update patch description
   - guard helper with CONFIG_IOREQ_SERVER
   - remove "hvm" prefix
   - modify helper to just return d->arch.hvm.ioreq_server.nr_servers
   - put suitable ASSERT()s
   - use ASSERT(d->ioreq_server.server[id] ? !s : !!s) in set_ioreq_server()
   - remove d->ioreq_server.nr_servers = 0 from hvm_ioreq_init()

Changes V2 -> V3:
   - update patch description
   - remove ASSERT()s from the helper, add a comment
   - use #ifdef CONFIG_IOREQ_SERVER inside function body
   - use new ASSERT() construction in set_ioreq_server()

Changes V3 -> V4:
   - update patch description
   - drop per-domain variable "nr_servers"
   - reimplement a helper to count the non-NULL entries
   - make the helper out-of-line

Changes V4 -> V5:
   - add Stefano's and Paul's R-b

---
---
 xen/arch/arm/traps.c    | 15 +++++++++------
 xen/common/ioreq.c      | 16 ++++++++++++++++
 xen/include/xen/ioreq.h |  2 ++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c
index 2039ff5..4cdd343 100644
--- a/xen/arch/arm/traps.c
+++ b/xen/arch/arm/traps.c
@@ -2267,14 +2267,17 @@ static bool check_for_vcpu_work(void)
     struct vcpu *v = current;
 
 #ifdef CONFIG_IOREQ_SERVER
-    bool handled;
+    if ( domain_has_ioreq_server(v->domain) )
+    {
+        bool handled;
 
-    local_irq_enable();
-    handled = vcpu_ioreq_handle_completion(v);
-    local_irq_disable();
+        local_irq_enable();
+        handled = vcpu_ioreq_handle_completion(v);
+        local_irq_disable();
 
-    if ( !handled )
-        return true;
+        if ( !handled )
+            return true;
+    }
 #endif
 
     if ( likely(!v->arch.need_flush_to_ram) )
diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c
index 07572a5..5b0f03e 100644
--- a/xen/common/ioreq.c
+++ b/xen/common/ioreq.c
@@ -80,6 +80,22 @@ static ioreq_t *get_ioreq(struct ioreq_server *s, struct vcpu *v)
     return &p->vcpu_ioreq[v->vcpu_id];
 }
 
+/*
+ * This should only be used when d == current->domain or when they're
+ * distinct and d is paused. Otherwise the result is stale before
+ * the caller can inspect it.
+ */
+bool domain_has_ioreq_server(const struct domain *d)
+{
+    const struct ioreq_server *s;
+    unsigned int id;
+
+    FOR_EACH_IOREQ_SERVER(d, id, s)
+        return true;
+
+    return false;
+}
+
 static struct ioreq_vcpu *get_pending_vcpu(const struct vcpu *v,
                                            struct ioreq_server **srvp)
 {
diff --git a/xen/include/xen/ioreq.h b/xen/include/xen/ioreq.h
index 0b433e2..89ee171 100644
--- a/xen/include/xen/ioreq.h
+++ b/xen/include/xen/ioreq.h
@@ -83,6 +83,8 @@ static inline bool ioreq_needs_completion(const ioreq_t *ioreq)
 #define HANDLE_BUFIOREQ(s) \
     ((s)->bufioreq_handling != HVM_IOREQSRV_BUFIOREQ_OFF)
 
+bool domain_has_ioreq_server(const struct domain *d);
+
 bool vcpu_ioreq_pending(struct vcpu *v);
 bool vcpu_ioreq_handle_completion(struct vcpu *v);
 bool is_ioreq_server_page(struct domain *d, const struct page_info *page);
-- 
2.7.4



  parent reply	other threads:[~2021-01-25 19:20 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-25 19:08 [PATCH V5 00/22] IOREQ feature (+ virtio-mmio) on Arm Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 01/22] x86/ioreq: Prepare IOREQ feature for making it common Oleksandr Tyshchenko
2021-01-27 16:48   ` Jan Beulich
2021-01-25 19:08 ` [PATCH V5 02/22] x86/ioreq: Add IOREQ_STATUS_* #define-s and update code for moving Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 03/22] x86/ioreq: Provide out-of-line wrapper for the handle_mmio() Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 04/22] xen/ioreq: Make x86's IOREQ feature common Oleksandr Tyshchenko
2021-01-25 23:13   ` Julien Grall
2021-01-25 23:40     ` Oleksandr
2021-01-27 18:43       ` Julien Grall
2021-01-27 20:22         ` Oleksandr
2021-01-27 20:46           ` Stefano Stabellini
2021-01-28 11:01             ` Oleksandr
2021-01-28 11:21               ` Jan Beulich
2021-01-28 12:49                 ` Oleksandr
2021-01-28 17:13                   ` Stefano Stabellini
2021-01-27 16:58   ` Jan Beulich
2021-01-27 20:14     ` Oleksandr
2021-01-28  8:06       ` Jan Beulich
2021-01-28 11:16         ` Oleksandr
2021-01-28 11:24           ` Jan Beulich
2021-01-25 19:08 ` [PATCH V5 05/22] xen/ioreq: Make x86's hvm_ioreq_needs_completion() common Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 06/22] xen/ioreq: Make x86's hvm_mmio_first(last)_byte() common Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 07/22] xen/ioreq: Make x86's hvm_ioreq_(page/vcpu/server) structs common Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 08/22] xen/ioreq: Move x86's ioreq_server to struct domain Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 09/22] xen/ioreq: Make x86's IOREQ related dm-op handling common Oleksandr Tyshchenko
2021-01-26 13:31   ` Paul Durrant
2021-01-28 10:52   ` Jan Beulich
2021-01-28 12:06     ` Oleksandr
2021-01-28 13:18       ` Jan Beulich
2021-01-28 20:01         ` Oleksandr
2021-01-25 19:08 ` [PATCH V5 10/22] xen/ioreq: Move x86's io_completion/io_req fields to struct vcpu Oleksandr Tyshchenko
2021-01-28 13:41   ` Julien Grall
2021-01-28 13:53     ` Jan Beulich
2021-01-28 14:21       ` Julien Grall
2021-01-28 14:36         ` Jan Beulich
2021-01-28 14:49           ` Andrew Cooper
2021-01-28 14:51           ` Ian Jackson
2021-01-28 14:54             ` Jan Beulich
2021-01-28 16:15               ` Andrew Cooper
2021-01-28 15:01           ` Julien Grall
2021-01-28 14:05     ` Oleksandr
2021-01-25 19:08 ` [PATCH V5 11/22] xen/mm: Make x86's XENMEM_resource_ioreq_server handling common Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 12/22] xen/ioreq: Remove "hvm" prefixes from involved function names Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 13/22] xen/ioreq: Use guest_cmpxchg64() instead of cmpxchg() Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 14/22] arm/ioreq: Introduce arch specific bits for IOREQ/DM features Oleksandr Tyshchenko
2021-01-25 20:19   ` Stefano Stabellini
2021-01-26  9:15   ` Jan Beulich
2021-01-27  9:54     ` Oleksandr
2021-01-27 10:15       ` Jan Beulich
2021-01-27 17:01     ` Julien Grall
2021-01-27 17:04       ` Jan Beulich
2021-01-27 18:33   ` Julien Grall
2021-01-27 19:20     ` Oleksandr
2021-01-28  9:40       ` Julien Grall
2021-01-28 11:33         ` Oleksandr
2021-01-28 13:39           ` Oleksandr
2021-01-28 14:29             ` Oleksandr
2021-01-28 14:41               ` Julien Grall
2021-01-28 14:52                 ` Oleksandr
2021-01-28 15:08                   ` Julien Grall
2021-01-28 17:50                     ` Oleksandr
2021-01-25 19:08 ` [PATCH V5 15/22] xen/arm: Call vcpu_ioreq_handle_completion() in check_for_vcpu_work() Oleksandr Tyshchenko
2021-01-27 14:49   ` Julien Grall
2021-01-27 15:56     ` Oleksandr
2021-01-27 20:34       ` Stefano Stabellini
2021-01-25 19:08 ` [PATCH V5 16/22] xen/mm: Handle properly reference in set_foreign_p2m_entry() on Arm Oleksandr Tyshchenko
2021-01-25 19:08 ` Oleksandr Tyshchenko [this message]
2021-01-25 19:08 ` [PATCH V5 18/22] xen/dm: Introduce xendevicemodel_set_irq_level DM op Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 19/22] xen/arm: io: Abstract sign-extension Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 20/22] xen/arm: io: Harden sign extension check Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 21/22] xen/ioreq: Make x86's send_invalidate_req() common Oleksandr Tyshchenko
2021-01-25 19:08 ` [PATCH V5 22/22] xen/arm: Add mapcache invalidation handling Oleksandr Tyshchenko
2021-01-28  9:55   ` Julien Grall
2021-01-28 13:12     ` Oleksandr
2021-01-27 16:43 ` [PATCH V5 00/22] IOREQ feature (+ virtio-mmio) on Arm Julien Grall
2021-01-27 16:50   ` Oleksandr
2021-01-27 17:33     ` Julien Grall
2021-01-27 17:37       ` Oleksandr
2021-01-27 17:42         ` Julien Grall
2021-01-27 17:45           ` Oleksandr
2021-01-28 14:37             ` Oleksandr
2021-01-28 15:14               ` Julien Grall
2021-01-28 17:55                 ` Oleksandr
2021-01-28 16:11 ` Julien Grall
2021-01-28 17:24   ` Stefano Stabellini
2021-01-28 17:44     ` Julien Grall
2021-01-28 18:10       ` Andrew Cooper
2021-01-28 18:16         ` Julien Grall
2021-01-28 18:21           ` Julien Grall
2021-01-28 20:10           ` Andrew Cooper
2021-01-28 21:19             ` Julien Grall
2021-01-28 19:44         ` Oleksandr
2021-01-29  1:15           ` Oleksandr

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=1611601709-28361-18-git-send-email-olekstysh@gmail.com \
    --to=olekstysh@gmail.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=julien.grall@arm.com \
    --cc=julien@xen.org \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=paul@xen.org \
    --cc=sstabellini@kernel.org \
    --cc=xen-devel@lists.xenproject.org \
    /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.