Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2989086imw; Sun, 17 Jul 2022 22:56:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u/LW2ybnur0oeZ+l96CR5NFPsxNv305Ypy8tw/Ocvc92u8Ktw1Do7CqZ+YNQkWgu39K8VW X-Received: by 2002:a17:906:93ef:b0:72b:44e2:bdd8 with SMTP id yl15-20020a17090693ef00b0072b44e2bdd8mr24330240ejb.192.1658123793864; Sun, 17 Jul 2022 22:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658123793; cv=none; d=google.com; s=arc-20160816; b=VSwgza6jDRTBRYG+EEWWOWDtEJp57R/a8iYXWehbkQyRzVDCyDWo6ZHVRv+rgNDwW5 TJor86jbJSd7HF7Bypjrse1wijk9PkyeBREhfc2wHsdqYanTNDhkXmprr++lq76yYhrI /Fx8j80VD87fvj3LuacND8PG5qjy1T3Q+DbvSw0LR6wr9YGdXNbPHBPfR+50VC1lLWUg V3NumDFZOVNfcVXabWu7L09aZ5eL1hvZPIlG7yXG8oDrbQ8Qu9fS+RnLuKclfoZVvIlv rwKJ7gtU0ldHg8YfSu2PCdQ5NwiFo3LrC6quEgkg5mAOxyGTOuJHlJNiqtmgLreir7d/ T+pQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from; bh=qgIFuEAnSF1tl86tvYzlBchm3DLpC00w+fOdoDycuI8=; b=jjI5m9mzbsdL6mUV2NUba+lcdYyKz+vPCB7sVYUL5kMZQPRl0uC4Y8iG5HpZhQbw+c 9EhNpBW7utiL4cLTXro3x5ZRl1QHpExaadmdmLV5Lk3FxTXgwirs2RWQC58/1ovXq3kX hV8mh0jU/PYhLSD82p3PnkViyUSKu5BzTp/nzR0HgYf+rtoIAFCGublHuqo7+7KOe+x2 U/2R2YhDMJ9AuRfsNvVq5Kwe6Ocd8m0fghKdPQUXPoe4zMP2vS6fBfK7i4eH+9CQUqjj LxPKsXZVf5utH0m2luv0XzaFKVyx1jSYnwb1H7MIfEqL5E48BnAuB5mjASChRg3oKwnW VbrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a05640226cf00b0043a739de8c1si10131829edd.428.2022.07.17.22.56.08; Sun, 17 Jul 2022 22:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233400AbiGRFzN convert rfc822-to-8bit (ORCPT + 99 others); Mon, 18 Jul 2022 01:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233354AbiGRFzI (ORCPT ); Mon, 18 Jul 2022 01:55:08 -0400 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2475614094 for ; Sun, 17 Jul 2022 22:55:07 -0700 (PDT) Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 26HNHKfs029337 for ; Sun, 17 Jul 2022 22:55:06 -0700 Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net (PPS) with ESMTPS id 3hbru775cm-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Sun, 17 Jul 2022 22:55:06 -0700 Received: from twshared34609.14.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Sun, 17 Jul 2022 22:55:04 -0700 Received: by devbig932.frc1.facebook.com (Postfix, from userid 4523) id E2605A4C01E0; Sun, 17 Jul 2022 22:54:51 -0700 (PDT) From: Song Liu To: , , CC: , , , , Song Liu Subject: [PATCH v4 bpf-next 0/4] ftrace: host klp and bpf trampoline together Date: Sun, 17 Jul 2022 22:54:45 -0700 Message-ID: <20220718055449.3960512-1-song@kernel.org> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: lYfrML3VQf79Bs888qjKaCwlAq7cOmTN X-Proofpoint-ORIG-GUID: lYfrML3VQf79Bs888qjKaCwlAq7cOmTN Content-Transfer-Encoding: 8BIT X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-07-18_04,2022-07-15_01,2022-06-22_01 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Changes v3 => v4: 1. Fix build errors for different config. (kernel test robot) Changes v2 => v3: 1. Major rewrite after discussions with Steven Rostedt. [1] 2. Remove SHARE_IPMODIFY flag from ftrace code. Instead use the callback function to communicate this information. (Steven) 3. Add cleanup_direct_functions_after_ipmodify() to clear SHARE_IPMODIFY on the DIRECT ops when the IPMODIFY ops is removed. Changes v1 => v2: 1. Fix build errors for different config. (kernel test robot) Kernel Live Patch (livepatch, or klp) and bpf trampoline are important features for modern systems. This set allows the two to work on the same kernel function as the same time. live patch uses ftrace with IPMODIFY, while bpf trampoline use direct ftrace. Existing policy does not allow the two to attach to the same kernel function. This is changed by fine tuning ftrace IPMODIFY policy, and allows one IPMODIFY ftrace_ops and one DIRECT ftrace_ops on the same kernel function at the same time. Please see patch 2 and 4 for more details. Note that, one of the constraint here is to let bpf trampoline use direct call when it is not working on the same function as live patch. This is achieved by allowing ftrace code to ask bpf trampoline to make changes. [1] https://lore.kernel.org/all/20220602193706.2607681-2-song@kernel.org/ Jiri Olsa (1): bpf, x64: Allow to use caller address from stack Song Liu (3): ftrace: add modify_ftrace_direct_multi_nolock ftrace: allow IPMODIFY and DIRECT ops on the same function bpf: support bpf_trampoline on functions with IPMODIFY (e.g. livepatch) arch/x86/net/bpf_jit_comp.c | 13 +- include/linux/bpf.h | 13 ++ include/linux/ftrace.h | 43 +++++ kernel/bpf/trampoline.c | 158 +++++++++++++++++-- kernel/trace/ftrace.c | 306 +++++++++++++++++++++++++++++++----- 5 files changed, 473 insertions(+), 60 deletions(-) -- 2.30.2