Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752783AbdLLRib (ORCPT ); Tue, 12 Dec 2017 12:38:31 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:36164 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752728AbdLLRiV (ORCPT ); Tue, 12 Dec 2017 12:38:21 -0500 Subject: Re: [PATCH v9 0/5] Add the ability to do BPF directed error injection To: Josef Bacik , , , , , , , , , References: <1513010210-30594-1-git-send-email-josef@toxicpanda.com> From: Alexei Starovoitov Message-ID: <1366bd39-4862-2f75-851c-a96d8de9648c@fb.com> Date: Tue, 12 Dec 2017 09:37:50 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1513010210-30594-1-git-send-email-josef@toxicpanda.com> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [2620:10d:c090:200::6:b5fd] X-ClientProxiedBy: MWHPR14CA0037.namprd14.prod.outlook.com (2603:10b6:300:12b::23) To SN2PR15MB0975.namprd15.prod.outlook.com (2603:10b6:804:20::25) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 822fc0de-6103-43c3-35f3-08d541871495 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307);SRVR:SN2PR15MB0975; X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB0975;3:/IWVh0XzsbybZ8t55ODENds3HaaDTl6GuqyAnnDfGwvW8sRFBfWGHZLtrFDsaPfwrXGf4rZmvDu0Vyxe/qE8/62LvSZq0eEHbkyrCSSPQEMlrmyqH3naUwuPfdATzYNnJgZIttsw63bdCNwP8W5/xdNsw0LfGSvzuXW/NH7T4Y2l/GsH3w/YN7xp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AS/31Ot3pV7k6FWINTdxM8QZVDZ1Q9VJXObneg+qlmqpczz6w7NLSGxMsIiz6C70ouq1LuO1tI+v9oTT9n445xfJUEHxfjH5vU6ivTzmRJ1YwrX4kbFq/cfTBUO/TjgIUFBfB1Wgu/TMdJ5AvqQ2tutIbz0wwOdbZtVoqEoqL8R6;4:xsEt2wXWa1Hx5GEDCZ1WOtGYKbioHLSW/sUtrthdIDSyWCC4IVxZ2xNy5v5FSG7fgw18AQs0aLcOzs2VjDMWC0/6ww8yKCe65j7dXdA66Z8BhrBXnMNNzt6PeS4jbYBjMT6OWIMDDVFPPFAtpHf6QZQJUPaUxicwtZuI1mgs+l2trOmM7dz6izfT+kcIeDVgfjX2TcjiE7WVDwapDna5sbBN3MLcajubIe3qqtzokpMlvVlJjFLIlyfUIJdG1Hv7OKNXgca4OvE6GzoyQrcr0A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231023)(11241501184)(3002001)(6041248)(20161123558100)(20161123555025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(6072148)(201708071742011);SRVR:SN2PR15MB0975;BCL:0;PCL:0;RULEID:(100000803101)(100110400095);SRVR:SN2PR15MB0975; X-Forefront-PRVS: 051900244E X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(346002)(376002)(39860400002)(366004)(24454002)(199004)(189003)(83506002)(47776003)(97736004)(6246003)(7736002)(65956001)(1706002)(65826007)(23746002)(76176011)(6116002)(8676002)(2906002)(5660300001)(59450400001)(36756003)(65806001)(25786009)(53546010)(67846002)(5890100001)(81166006)(81156014)(6486002)(105586002)(305945005)(50466002)(31686004)(230700001)(58126008)(8936002)(2950100002)(229853002)(64126003)(316002)(86362001)(53936002)(52396003)(52116002)(478600001)(68736007)(106356001)(6666003)(31696002)(921003)(1121003)(42262002);DIR:OUT;SFP:1102;SCL:1;SRVR:SN2PR15MB0975;H:[IPv6:2620:10d:c082:1055:55f4:4b27:da65:d];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;SN2PR15MB0975;23:9QV8Sf2guIGMsxAShZUD36+NNQIEdFWfans5X?= =?Windows-1252?Q?FUU8OxFdVypGNZ4V4Bjxhrc6I0PTuDC2VQm+D4zUHc6jVNpObynhZ6bQ?= =?Windows-1252?Q?o7RkEyW1V7OFZb8KprAAnx68nFwWsKl2wxd8Y+EVh3NTr++lf515Z0pM?= =?Windows-1252?Q?k37FAG8HKRBIgkzejpJxDIGiDZcDHdlSLO7IJLKY2QSzCb9LnlmPzyBR?= =?Windows-1252?Q?AAdkRZdSc9XJ5pT8d1j0O4QhmMJlDNlwcvvNALkHgJ2K0mLe10frvqpG?= =?Windows-1252?Q?ZRkwq+3O19CPDZUadxQDmylcD4lWOE6OWlzGJGf3mOFbwaVFESjpElJc?= =?Windows-1252?Q?1BqAObdf342fcaFlaFAc+9vdSoGdSMxWC7A9kbkbuql4Ki2+wZ/oTJbj?= =?Windows-1252?Q?8V1nAJGfDJ18FEkYimW4WmF2coGtXwyYBERxrhM8mn7ijnMrfQ46slQS?= =?Windows-1252?Q?R9Sj4imBc/HlPXTjItPQFLQ4QsYGTML39q5Nh2+UbSpIUDZBw4rRDeEy?= =?Windows-1252?Q?1gaCGw0I7fk+4yGX/Lau+MTMDgjO8ycipA+dC7eEGo7Y+6sITZ/QIlvI?= =?Windows-1252?Q?nwV167eAsM262cR6GzzOx7og1RhxpVXJ8zZ07uIb7WPYRlFkTNqwPRg1?= =?Windows-1252?Q?6q3t/is3o7m+Doz3kMGrS47zzN9Xe9HIrRroJS4FBNTzWH1uOqOVv8YG?= =?Windows-1252?Q?9LCj3XzttrnJMQIZYFB0/73NaKqpyLurH/KwaG1t5vXruKqKAlieSBwq?= =?Windows-1252?Q?gaWt2JEcHWgiEDCrCtd3NouhpcqfYrkakYdvMhxTsIq947K95/GMhgFq?= =?Windows-1252?Q?0YBeQLsVlHAA9Cx3dbRgnA7OSIhxD+j6PLc4WEgrhKJJ+VZ8ESKazXrd?= =?Windows-1252?Q?WOJ+VGkH2h9fzZmNOAnhn3WoW2W2BVZ6EaxjMmSmL7C+4hcN4p3w0LBu?= =?Windows-1252?Q?dOg0tkvc/bgw9KD1KXOUeP0WXEpky+ptXz80XIPqdW+bFb5MPrVe7m8q?= =?Windows-1252?Q?Hwp+jnvSzsqOavH22VqRi1KeS6YfPGFtsA0bo3kzxqtio2iRT+UatAG7?= =?Windows-1252?Q?BKuwXPjRyK+H+7/bgHH+L8AA7LwBVhWxVYRjDgRyvOSUEORszexULNdA?= =?Windows-1252?Q?ITxfo5KROUQ7cEy1JWqsu0nzxCEARbNYMR0pJF6HuCd4IJ3/6+Wmbttg?= =?Windows-1252?Q?f2nk41sJvJqYwnTp9dq2MaOvhhSVnJboInhrin6eSfVxI5JzIrZaEyCp?= =?Windows-1252?Q?TwmoRPdEoj/CMmycyMXIOoLlR7X3HEUtrGKHlU03QDiLLYmUuvUIzZOP?= =?Windows-1252?Q?rmW5jTJ/gUuByJ0z7LuDqKvmHOwPJ+tmbZmjBF/YTzzXA1ylBeHFdm7U?= =?Windows-1252?Q?rYdqCjNtk/Q?= X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB0975;6:NcWTLURLaIcXlWWFJuyTsEY4Igi+sMA45oQ+6HiYUGlXbWJcXCtAW3qYmWy1gsbta9hyWU2hkCyEwlxdxxRgoi+FuVlVCsg73eT0mVLggzuDewTlsCYYT+sqDQp0KCI5q+/62vaxuzHxVfN+7eWLdsV0cX1Gm8+gp9MXPKyenpblu1OITEg2rdezPAAll7rENEhKSU76u3YCsAmHtON56ykJ7NF7hGjdM1QUQXjAFyTgLNdopDuKCcjgOwFoaR8otg5J8S1Yvq4+7c0phNzs4H3u5/uiR8FRIt6zlrRqEDTgLhV/S1RHXZaXSXUnVArmi7gqrhET5V+QsrZQWGc3JHpJlMBP2Yb1HqMZ+QMcrG4=;5:BIDcbJqkxsMf+CW4IoiNhEutez3DugEBKhOYZgif8IyCkHqTkbR3rdi0Cgp81jAxQIBCCUPViAOZzIUHyY8baKlDcGCHwuLVrsolBXBt++EBp498aKFCn6Wsc3ke0YqUuXXpE4L86pXjYgruZ3RhTYlV4A+xRDmQah4iaRWlGKg=;24:rVebCZHT+GMzIzz0gilxD3lX51E7yra+UmA7K+5Eud8nzpvhgHN/WQ/u/lv2FhPqTday426NxMcVQidTmA1geUM2LWCr3NxwvHu6SBzLXF8=;7:ZCb5EJbmA7p338FXY/Ozs6+DgyaTkYPTaJpBTViSK48YBx3v2yX1i14s3YbCSUVK9aGKPmBtp1qjTXgFjnEl3v8My6+4tEBaV6+vHPmq0ljPnHK71E//Js4QqGHd7/wEfxtMlAmJIWa0DkApIn3dpEzvQ9CYPpMulW/Ozub+rKbEsmQ+F5vflhX8GOgHA+k7nwpZGYeEHwOHuhL2jat71GxPibfdOCg5d41ldU9QSg5QIyD/P+rLHgw9du1C6TsP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;SN2PR15MB0975;20:6s9narM/lpTUx//w1LJxdgx2+NXXi7aPuX0RK6tDNAWFJ2Gnl8N+HGd2KpNdiSGgESF2bnMf+Af+jhbzJ/tmtij9Dr5bGm9Ixsh1oMWekhJpXSckDm3N1t3PO8yv+L2pE8zb37XhyNtyMKexxgGQb6Wdestv9ktGxw2dj3nd9Ro= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Dec 2017 17:37:55.4662 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 822fc0de-6103-43c3-35f3-08d541871495 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR15MB0975 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-12-12_10:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3036 Lines: 74 On 12/11/17 8:36 AM, Josef Bacik wrote: > This is the same as v8, just rebased onto the bpf tree. > > v8->v9: > - rebased onto the bpf tree. > > v7->v8: > - removed the _ASM_KPROBE_ERROR_INJECT since it was not needed. > > v6->v7: > - moved the opt-in macro to bpf.h out of kprobes.h. > > v5->v6: > - add BPF_ALLOW_ERROR_INJECTION() tagging for functions that will support this > feature. This way only functions that opt-in will be allowed to be > overridden. > - added a btrfs patch to allow error injection for open_ctree() so that the bpf > sample actually works. > > v4->v5: > - disallow kprobe_override programs from being put in the prog map array so we > don't tail call into something we didn't check. This allows us to make the > normal path still fast without a bunch of percpu operations. > > v3->v4: > - fix a build error found by kbuild test bot (I didn't wait long enough > apparently.) > - Added a warning message as per Daniels suggestion. > > v2->v3: > - added a ->kprobe_override flag to bpf_prog. > - added some sanity checks to disallow attaching bpf progs that have > ->kprobe_override set that aren't for ftrace kprobes. > - added the trace_kprobe_ftrace helper to check if the trace_event_call is a > ftrace kprobe. > - renamed bpf_kprobe_state to bpf_kprobe_override, fixed it so we only read this > value in the kprobe path, and thus only write to it if we're overriding or > clearing the override. > > v1->v2: > - moved things around to make sure that bpf_override_return could really only be > used for an ftrace kprobe. > - killed the special return values from trace_call_bpf. > - renamed pc_modified to bpf_kprobe_state so bpf_override_return could tell if > it was being called from an ftrace kprobe context. > - reworked the logic in kprobe_perf_func to take advantage of bpf_kprobe_state. > - updated the test as per Alexei's review. > > - Original message - > > A lot of our error paths are not well tested because we have no good way of > injecting errors generically. Some subystems (block, memory) have ways to > inject errors, but they are random so it's hard to get reproduceable results. > > With BPF we can add determinism to our error injection. We can use kprobes and > other things to verify we are injecting errors at the exact case we are trying > to test. This patch gives us the tool to actual do the error injection part. > It is very simple, we just set the return value of the pt_regs we're given to > whatever we provide, and then override the PC with a dummy function that simply > returns. > > Right now this only works on x86, but it would be simple enough to expand to > other architectures. Thanks, Applied, thanks Josef! While applying in the patch "bpf: add a bpf_override_function helper" I moved ifdef CONFIG_BPF_KPROBE_OVERRIDE few lines, so when it's not set the program will fail at load time with error "unknown func bpf_override_return#58" instead of returning EINVAL at run-time. That's more standard way of adding new helpers. Thanks