[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v3] x86/oprofile: remove compat accessors usage from backtrace


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Tue, 27 Apr 2021 16:21:13 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ykm6C/DdorPDyWCv/5zxEwbKtGIhtsjujRU+lqObAZc=; b=ZRu9LvebRasUav4/cQJU9R04gAy1kJZ1bqrtaomKTxpmHP3+d4EmPtfES1Z67Xk3wpycZ8bstVZVvLBpRjeaWDpBffpmhjRXSucwdt/rNtC+BSWEjikj30q6ubPr/CZKFjyzMf2v4a6YGG05e78JnXuM2Gp5huIYYALqp2kumAvF5aTSFqVrUrulA6mMa+jI/ZbDitEysutipYlRUolJ/f98tnmqu2nThjMBZ0r+LtUgCB6+1OuCPfXA9n79ki47DiYd4rcTMoNeX6rbOwGUXFdFCZJg5O8kbhifQx4TOUsjRyBzi4ScrApmiu++d019OFsWMtFPgJcCi+rxUbDErg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ofgk/kMociav3X2u8Xgv/yi7dwvo6TBB34bHNzOlueiF2P+1D5LCFSEPDucQw2Gce+ZU63eaTo5I7FAWFluexDIgMEW2K+30yDl7XPJl1hUoWZGGXmsU2Wtph0wsoGOELUsq8LAQ9OWP/25JCLnEpHi4frNsln7ggwAxpC/hv+QLTUyWqhJYqprN9+otb/5XvgZWguBhAZuMSeGgEQ1BCeMIzLOQ2MoZKQ8GhEKL8VGmil5WyTooKD4YfnVlnJN3RPUKJjCkrq/iirrQT9+FE1zv7cbJNlJ4uXFJv78SYLTpad7LlrBYbKZtYor60XCWQr4X00hAE+YuoHh7Drj+Ow==
  • Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 27 Apr 2021 14:21:28 +0000
  • Ironport-hdrordr: A9a23:5iNmraG6MYLwcwCSpLqF6JHXdLJzesId70hD6mlYQxZYa9Hdss iokugS2xOcskd3ZFgLs7m7V5Woa3Xa6JJz/M01NbCtQAHptAKTXedfxKHlxCDtHDC7y/5F2c 5bAtVDIfD5EFQSt7eY3CCWCNAlqePrzImJgqPkw25pXUVWbchbnmNEIyK6NmEzewVcH5o+E/ Onl7Z6jh6tY24eYMj+JlRtZZmgm/TxmJjrYQELCnccgWHk5w+A07L0HwOV2R0TSVp0sNIf2F PIjhDj4eGbu+y7oyWsqFP71Yhcm9fq17J4avCkt8kPJj3gziauaYhxMofjgBkJofqi4Ftvrd /Uox1IBaVOwk7WF1vYnTLdny3blBcn8TvL1EKRi3qLm72BeBsKT+56wb9/XjScwUw6p9142L 9MxAuixuJqJAKFln/l/N7DWwtxmkezunRKq59os1VPFY0EaLFQqoQD/ERaVJcYdRiKk7waLA ==
  • Ironport-sdr: P7HVEKNakn6aPiMbHT1sQ9yisEkyxsdU1++FhbsVV9tq7UFllDsqjwYJntwrFOc4LNd1h8rTYm 9UX3I3hxZLNgkZSA/S/hlKHRgXa09mgwe/ifqgIvleCFdP7OA/76jf4ywW2kZ/3L+7xZb54x+U 74DwtyAeVyM4FBcZg2waRyMOKuJTJxvXncPhMRKGY83aQFUgizhr8iEpCV6zNWxkk7WQqmS8dQ ybszTG/lERsbePZrHljciOPyWq/Zt0PJUSAZVkIiP06xxGH9CbVNZQu2dwUlEM3inMYQi2SiIl rb4=
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Remove the unneeded usage of the compat layer to copy frame pointers
from guest address space. Instead just use raw_copy_from_guest.

While there change the accessibility check of one frame_head beyond to
be performed as part of the copy, like it's done in the Linux code.
Note it's unclear why this is needed.

Also drop the explicit truncation of the head pointer in the 32bit
case as all callers already pass a zero extended value. The first
value being rsp from the guest registers, and further calls will use
ebp from frame_head_32bit struct.

Reported-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
Changes since v2:
 - Keep accessibility check for one frame_head beyond.
 - Fix coding style.

Changes since v1:
 - Expand commit message.
---
 xen/arch/x86/oprofile/backtrace.c | 41 +++++++++----------------------
 1 file changed, 11 insertions(+), 30 deletions(-)

diff --git a/xen/arch/x86/oprofile/backtrace.c 
b/xen/arch/x86/oprofile/backtrace.c
index bd5d1b0f6ce..21b14f63bdb 100644
--- a/xen/arch/x86/oprofile/backtrace.c
+++ b/xen/arch/x86/oprofile/backtrace.c
@@ -20,7 +20,6 @@ struct __packed frame_head {
     unsigned long ret;
 };
 typedef struct frame_head frame_head_t;
-DEFINE_XEN_GUEST_HANDLE(frame_head_t);
 
 struct __packed frame_head_32bit {
     uint32_t ebp;
@@ -43,7 +42,6 @@ dump_hypervisor_backtrace(struct vcpu *vcpu, const struct 
frame_head *head,
     return head->ebp;
 }
 
-#ifdef CONFIG_COMPAT
 static inline int is_32bit_vcpu(struct vcpu *vcpu)
 {
     if (is_hvm_vcpu(vcpu))
@@ -51,52 +49,35 @@ static inline int is_32bit_vcpu(struct vcpu *vcpu)
     else
         return is_pv_32bit_vcpu(vcpu);
 }
-#endif
 
 static struct frame_head *
 dump_guest_backtrace(struct vcpu *vcpu, const struct frame_head *head,
                      int mode)
 {
-    frame_head_t bufhead;
+    /* Also check accessibility of one struct frame_head beyond. */
+    frame_head_t bufhead[2];
 
-#ifdef CONFIG_COMPAT
     if ( is_32bit_vcpu(vcpu) )
     {
-        DEFINE_COMPAT_HANDLE(frame_head32_t);
-        __compat_handle_const_frame_head32_t guest_head =
-            { .c = (unsigned long)head };
-        frame_head32_t bufhead32;
-
-        /* Also check accessibility of one struct frame_head beyond */
-        if (!compat_handle_okay(guest_head, 2))
-            return 0;
-        if (__copy_from_compat(&bufhead32, guest_head, 1))
-            return 0;
-        bufhead.ebp = (struct frame_head *)(unsigned long)bufhead32.ebp;
-        bufhead.ret = bufhead32.ret;
-    }
-    else
-#endif
-    {
-        XEN_GUEST_HANDLE_PARAM(const_frame_head_t) guest_head =
-            const_guest_handle_from_ptr(head, frame_head_t);
+        frame_head32_t bufhead32[2];
 
-        /* Also check accessibility of one struct frame_head beyond */
-        if (!guest_handle_okay(guest_head, 2))
-            return 0;
-        if (__copy_from_guest(&bufhead, guest_head, 1))
+        if ( raw_copy_from_guest(&bufhead32, head, sizeof(bufhead32)) )
             return 0;
+        bufhead[0].ebp = (struct frame_head *)(unsigned long)bufhead32[0].ebp;
+        bufhead[0].ret = bufhead32[0].ret;
     }
+    else if ( raw_copy_from_guest(&bufhead, head, sizeof(bufhead)) )
+        return 0;
     
-    if (!xenoprof_add_trace(vcpu, bufhead.ret, mode))
+    if ( !xenoprof_add_trace(vcpu, bufhead[0].ret, mode) )
         return 0;
     
     /* frame pointers should strictly progress back up the stack
      * (towards higher addresses) */
-    if (head >= bufhead.ebp)
+    if ( head >= bufhead[0].ebp )
         return NULL;
     
-    return bufhead.ebp;
+    return bufhead[0].ebp;
 }
 
 /*
-- 
2.30.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.