public inbox for systemtap@sourceware.org
 help / color / mirror / Atom feed
From: Arkady <arkady.miasnikov@gmail.com>
To: David Smith <dsmith@redhat.com>
Cc: systemtap@sourceware.org
Subject: Re: Failure in syscall.open probe
Date: Mon, 28 Aug 2017 05:51:00 -0000	[thread overview]
Message-ID: <CANA-60pDmqGx8+tmPNw_OzBQ0Q7pBbbhZCePwMg-iAsy8ugrvw@mail.gmail.com> (raw)
In-Reply-To: <CANA-60qLBg4Pze+VFOnHS7J8zQUBaVwaWZpQ77AH1JZ1PyX43w@mail.gmail.com>

The following patch solves the problem, or, at least, makes it
significantly less probable

diff --git a/runtime/linux/copy.c b/runtime/linux/copy.c
index c5022b5..2da01f1 100644
--- a/runtime/linux/copy.c
+++ b/runtime/linux/copy.c
@@ -39,6 +39,28 @@
  * <i>count</i> bytes and returns <i>count</i>.
  */

+static long _stp_copy_from_user_inatomic(char *dst, const char __user
*src, long count)
+{
+       int res;
+       long bytes = 0;
+       while (count)
+       {
+               res = __copy_from_user_inatomic(dst, src, 1);
+               if (unlikely(res != 1))
+               {
+                       return res;
+               }
+               if (unlikely((*dst == 0)))
+               {
+                       break;
+               }
+               bytes++;
+               count--;
+       }
+
+       return bytes;
+}
+
 /* XXX: see also kread/uread in loc2c-runtime.h */
 static long _stp_strncpy_from_user(char *dst, const char __user *src,
long count)
 {
@@ -46,14 +68,8 @@ static long _stp_strncpy_from_user(char *dst, const
char __user *src, long count
         mm_segment_t _oldfs = get_fs();
         set_fs(USER_DS);
         pagefault_disable();
-        /* XXX: The following preempt() manipulations should be
-           redundant with probe entry/exit code, but for unknown
-           reasons on RHEL5/6 conversions.exp intermittently fails
-           without this.  */
-        preempt_disable();
        if (!lookup_bad_addr(VERIFY_READ, (const unsigned long)src, count))
-               res = strncpy_from_user(dst, src, count);
-        preempt_enable_no_resched();
+               res = _stp_copy_from_user_inatomic(dst, src, count);
         pagefault_enable();
         set_fs(_oldfs);
        return res;

On Sun, Aug 27, 2017 at 3:38 PM, Arkady <arkady.miasnikov@gmail.com> wrote:
> The following comment is probably relevant:
> /*
>  * On some kernels (e.g. 2.6.39), even with preemption disabled, the
> strncpy_from_user,
>  * instead of returning -1 after a page fault, schedules the process,
> so we drop events
>  * because of the preemption. This function reads the user buffer in
> atomic chunks, and
>  * returns when there's an error or the terminator is found
>  */
>
> https://github.com/draios/sysdig/blob/dev/driver/ppm_events.c#L108
>
>> On Fri, Aug 25, 2017 at 10:52 PM, David Smith <dsmith@redhat.com> wrote:
>>> Arkady,
>>>
>>> The "good" news is that I've duplicated your problem. I went ahead and
>>> filed PR22012 (<https://sourceware.org/bugzilla/show_bug.cgi?id=22012>)
>>> on this issue so I won't forget it.
>>>
>>> I'm looking into it.
>>>
>>>
>>> On Fri, Aug 25, 2017 at 12:25 PM, Arkady <arkady.miasnikov@gmail.com> wrote:
>>>> Reproduce the problem
>>>>
>>>> Run the following one liner on CentOS 6.9
>>>>
>>>> stap -e "global AF%;probe syscall.open {tid = tid();AF[tid] =
>>>> filename;}probe syscall.open.return{tid = tid();delete AF[tid];}"
>>>>
>>>> Run a bash loop
>>>> touch test.txt;while [ 1 ];do cat test.txt;done;
>>>>
>>>> Monitor the kernel log
>>>> tail -f /var/log/messages
>>>>
>>>> After a couple of minutes you shall see
>>>>
>>>> BUG: scheduling while atomic: cat/87764/0x10000001
>>>> Modules linked in: test_open(U) fuse rfcomm sco bridge bnep l2cap
>>>> autofs4 bnx2fc cnic uio fcoe libfcoe libfc 8021q scsi_transport_fc
>>>> garp stp scsi_tgt llc ipt_REJECT nf_conntrack_ipv4 nf_defrag_ipv4
>>>> iptable_filter ip_tables ip6t_REJECT nf_conntrack_ipv6 nf_defrag_ipv6
>>>> xt_state nf_conntrack ip6table_filter ip6_tables ib_ipoib rdma_ucm
>>>> ib_ucm ib_uverbs ib_umad rdma_cm ib_cm iw_cm ib_sa ib_mad ib_core
>>>> ib_addr ipv6 uinput microcode vmware_balloon uvcvideo videodev
>>>> v4l2_compat_ioctl32 btusb bluetooth rfkill snd_seq_midi e1000
>>>> snd_seq_midi_event snd_ens1371 snd_rawmidi snd_ac97_codec ac97_bus
>>>> snd_seq snd_seq_device snd_pcm snd_timer snd soundcore snd_page_alloc
>>>> sg i2c_piix4 shpchp ext4 jbd2 mbcache sd_mod crc_t10dif sr_mod cdrom
>>>> mptspi mptscsih mptbase scsi_transport_spi pata_acpi ata_generic
>>>> ata_piix vmwgfx ttm drm_kms_helper drm i2c_core dm_mirror
>>>> dm_region_hash dm_log dm_mod [last unloaded: speedstep_lib]
>>>> Pid: 87764, comm: cat Not tainted 2.6.32-696.10.1.el6.x86_64 #1
>>>> Call Trace:
>>>> <#DB>  [<ffffffff81068244>] ? __schedule_bug+0x44/0x50
>>>> [<ffffffff8154ae0c>] ? schedule+0xa4c/0xb70
>>>> [<ffffffff812a6216>] ? vsnprintf+0x336/0x5e0
>>>> [<ffffffff810740aa>] ? __cond_resched+0x2a/0x40
>>>> [<ffffffff8154b200>] ? _cond_resched+0x30/0x40
>>>> [<ffffffff812a8b9a>] ? strncpy_from_user+0x4a/0x90
>>>> [<ffffffffa0705ff9>] ? probe_3602+0x5f9/0x1220 [test_open]
>>>> [<ffffffff81196c31>] ? sys_open+0x1/0x30
>>>> [<ffffffffa0707fed>] ? enter_kprobe_probe+0x1ed/0x3a0 [test_open]
>>>> [<ffffffff815512bb>] ? aggr_pre_handler+0x5b/0xb0
>>>> [<ffffffff81196c30>] ? sys_open+0x0/0x30
>>>> [<ffffffff81196c31>] ? sys_open+0x1/0x30
>>>> [<ffffffff81550cd5>] ? kprobe_exceptions_notify+0x3d5/0x430
>>>> [<ffffffff81550f45>] ? notifier_call_chain+0x55/0x80
>>>> [<ffffffff81550faa>] ? atomic_notifier_call_chain+0x1a/0x20
>>>> [<ffffffff810acd0e>] ? notify_die+0x2e/0x30
>>>> [<ffffffff8154e815>] ? do_int3+0x35/0xb0
>>>> [<ffffffff8154e083>] ? int3+0x33/0x40
>>>> [<ffffffff81196c30>] ? sys_open+0x0/0x30
>>>
>>>
>>>
>>> --
>>> David Smith
>>> Principal Software Engineer
>>> Red Hat

  reply	other threads:[~2017-08-28  5:51 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 14:26 Arkady
2017-08-24 14:35 ` Arkady
2017-08-24 16:28   ` Arkady
2017-08-25  3:56     ` Arkady
2017-08-25  4:36       ` Arkady
2017-08-25 17:25         ` Arkady
2017-08-25 19:52           ` David Smith
2017-08-27  6:13             ` Daniel Doron
2017-08-27 12:22             ` Arkady
2017-08-27 12:38               ` Arkady
2017-08-28  5:51                 ` Arkady [this message]
2017-08-28  6:28                   ` Arkady
2017-08-28 17:19                     ` David Smith
2017-08-29 16:06                       ` David Smith
2017-08-29 16:44                         ` Arkady
2017-08-30 14:18                           ` David Smith

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=CANA-60pDmqGx8+tmPNw_OzBQ0Q7pBbbhZCePwMg-iAsy8ugrvw@mail.gmail.com \
    --to=arkady.miasnikov@gmail.com \
    --cc=dsmith@redhat.com \
    --cc=systemtap@sourceware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).