Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5116359yba; Wed, 8 May 2019 08:08:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqwuwjhaKnS7FhifSj8IYjmLBIK8Uk8TFaUR+od9Ehk/FlV9y22/DuTLpxp3fSYxjx0yEJiA X-Received: by 2002:a65:44cb:: with SMTP id g11mr47755308pgs.193.1557328113032; Wed, 08 May 2019 08:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557328113; cv=none; d=google.com; s=arc-20160816; b=aynySXB9Sjt0Uq5GVxZaRIhPRSRCJ4whohWY7xr2gNqrIzg6ob0TD0QoyFLgCDwzKk jpPyMmFDxJUzqhTVpW0g8/TGHNVymyvL0iBj+ldcXteBOozPLyvbBzvYC6bgJn7Ybd7h oEF6Gjbu1pPMmC5Utsvgui8+0/WrSKzHt4QoDoVr9DMYFuc2UCI3gcbFYqWCarUNKsNG 7qJvgcHSdvPWzlsDWfXwVWdek7KpZNMoPGOvpKGoiRgt0IYHopZm3c0DHNQnJY5PEVeh HV6K5qx3xs4O9ZUBQZCO7xopdhq1SbsV8E0e7iYILYSXb8QGo5vqT5YyI+Tkw47izS7U m5Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Nr3d5k4WSKWseMzvDDhU1Emc8BT0ZCcyIeHyWpK3OqM=; b=YBDYuTf2lIGAdmtiYUbiZ8RJsNpWDGgcCs3KcU5AU+7LFPYB4t+q976BtJ8sCYhoSM QkoTZ5XcpClw6T8wzqQ/oMkqVxOuFT0MNE+YwT2ccbUPZ11p41rMnFfCCD0OFze9SUmq rC/HzxI1SpCgfXwolqXLMGJW1VouHuq84fEnWAKKsv8iZuhqcmHG1NnggC3Ifbxv448d TXLJj3moIZ6sVirHfPNgJe+BsTtmhawzkBx/c3JPy86EMLoJ2+Drc8UKM1WJys/+ZcH1 lY8UYPVPBCw7jGMBbGMKhrdgXcmZToOS91DQ3nXQH4yqU4t76pnarvGCrkytVIUav0qI dZmg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s2si22798475plr.110.2019.05.08.08.08.08; Wed, 08 May 2019 08:08:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbfEHPFf (ORCPT + 99 others); Wed, 8 May 2019 11:05:35 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:7734 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726543AbfEHPFf (ORCPT ); Wed, 8 May 2019 11:05:35 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 8C7C87885B1C5FA26FE; Wed, 8 May 2019 23:05:32 +0800 (CST) Received: from [127.0.0.1] (10.184.38.59) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Wed, 8 May 2019 23:05:26 +0800 Subject: Re: [PATCH] ftrace: enable trampoline when rec count decrement to one To: Steven Rostedt CC: , , , , "chengjian (D)" , References: <1556969979-111047-1-git-send-email-cj.chengjian@huawei.com> <20190505153447.594d4eab@oasis.local.home> From: "chengjian (D)" Message-ID: Date: Wed, 8 May 2019 23:02:33 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.2 MIME-Version: 1.0 In-Reply-To: <20190505153447.594d4eab@oasis.local.home> Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.184.38.59] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Steven On 2019/5/6 3:34, Steven Rostedt wrote: > > Thanks for the patch. There was some race condition that prevented me > from doing this in the first place, but unfortunately, I don't remember > what that was :-/ > > I'll have to think about this before applying this patch. > > Maybe there isn't a race condition, and I was just playing it safe, as > there was a race condition between switching from regs caller back to > non regs caller. > > -- Steve > . function tracer uses ftrace_caller() and livepatch uses ftrace_regs_caller(). I can modify my testcase to trigger this race condition. #enable livepatch insmod klp_unshare_files.ko cat /sys/kernel/debug/tracing/enabled_functions unshare_files (1) R I tramp: 0xffffffffc0008000 (klp_ftrace_handler+0x0/0xa0) ->ftrace_ops_assist_func+0x0/0xf0 [NOW, the rec caller is ftracer_regs_caller TRAMPOLINE] #function tracer echo unshare_files > /sys/kernel/debug/tracing/set_ftrace_filter echo function > /sys/kernel/debug/tracing/current_tracer cat /sys/kernel/debug/tracing/enabled_functions unshare_files (2) R I ->ftrace_ops_list_func+0x0/0x170 [NOW, the rec caller is ftracer_regs_caller] # disable livepatch echo 0 > /sys/kernel/livepatch/klp_unshare_files/enabled rmmod klp_unshare_files cat /sys/kernel/debug/tracing/enabled_functions unshare_files (1) tramp: 0xffffffffc0005000 (function_trace_call+0x0/0x120) ->function_trace_call+0x0/0x120 [NOW, the rec caller is ftrace_caller TRAMPOLINE] So, the caller switch from regs caller back to non regs caller when disable the livepatch. Could this testcase cause the race condition ? BUT, Nothing happened here. What will happen when the race triggers ? What can I do. Thanks. Cheng Jian.