Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp4626616img; Tue, 26 Mar 2019 13:15:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwo0udlrp+RCRopma7wRYTzNDJUv0rWTChUqCEi9w++dpho18QY36CGoMUIOASd7nF8/V5X X-Received: by 2002:a62:5797:: with SMTP id i23mr31484644pfj.12.1553631307075; Tue, 26 Mar 2019 13:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553631307; cv=none; d=google.com; s=arc-20160816; b=uTppUKgkQWI3YmIv6eCUF91HhPohxQ3S2nEMi3vu/CYQYVCUMf7TbpV53yAcH+0Aeh xC9FBJYhHrwgFifkczb3yVAOAy7P3s+u0osUs9QGupLj3GQq/iY1vm2mYBx7vnVZyuIF +xvJkfhpz9HYhnTHHDA8LCw3QSthenuNdBmcM7RcPVTZYsAHtAsQhuWByT07+lBCZD6f 8CSu/GTaqLnYblMnuFIeecFhtea1UZfNjN+pQeXmdztbAN0ZxkraNDkt5Mm9yVbvv93e XgD6xdrsHHjxlkR349MydtPf5GrsYf7B3LzhbY+KVy5VSgT3YKceRDZ5nG7vlcoYPflR sYAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=nikpzUFvwptJbEk+gLFI870C9VoiKUHS6c/SqNTCMHE=; b=ZzUHAfAs8f7tASI/Xn9cz+ir9nE4jbaIdkKFNu2qhbA7IgPuPi35I4itqWahlf77EB swAfS3AwQOVLfkXSFUXMP/YeVs56SNap9yF3dtdjpRbgoR7ZnnmiRzp2RnMn22NGT1Ku Q/bPFqcSuqRnPwKiyOVpDeYWFsYOY3Yuk/s+ZcoEsw3e5Tl8b7uxKv2p+RP5B94na+x2 N/4ocWhbbUaWxDiCARsLnPhb7Cid3vMPbtxHf1ivi2S5tgvxhnctHJhQbJPAAcqIUYL9 a5zHy20bbPMAN623moyjd1MMuSSyhdYJVAQd1/TQ9sXtPVO8wcpnG76ic9v67i47q/sc MvzQ== 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 j12si7691054pgk.95.2019.03.26.13.14.49; Tue, 26 Mar 2019 13:15:07 -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 S1732521AbfCZUOI (ORCPT + 99 others); Tue, 26 Mar 2019 16:14:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:47302 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726207AbfCZUOH (ORCPT ); Tue, 26 Mar 2019 16:14:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 5D3FDAAC4; Tue, 26 Mar 2019 20:14:05 +0000 (UTC) Subject: Re: [PATCH v2 3/8] livepatch: Add klp-convert tool To: Miroslav Benes , Joe Lawrence Cc: live-patching@vger.kernel.org, pmladek@suse.cz, jikos@suse.cz, nstange@suse.de, jpoimboe@redhat.com, khlebnikov@yandex-team.ru, jeyu@kernel.org, matz@suse.de, linux-kernel@vger.kernel.org, yamada.masahiro@socionext.com, linux-kbuild@vger.kernel.org, michal.lkml@markovi.net References: <20190301141313.15057-1-jmoreira@suse.de> <20190301141313.15057-4-jmoreira@suse.de> <20190318192011.GA23157@redhat.com> From: Joao Moreira Message-ID: <04f6c9c4-88c6-41b3-fbf8-2409b3822e0b@suse.de> Date: Tue, 26 Mar 2019 17:13:57 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/20/19 4:36 PM, Miroslav Benes wrote: >>> [ ... snip ... ] >>> + >>> +/* Checks if sympos is valid, otherwise prints valid sympos list */ >>> +static bool valid_sympos(struct sympos *sp) >>> +{ >>> + struct symbol_entry *e; >>> + int counter = 0; >>> + >>> + list_for_each_entry(e, &symbols, list) { >>> + if ((strcmp(e->symbol_name, sp->symbol_name) == 0) && >>> + (strcmp(e->object_name, sp->object_name) == 0)) { >>> + if (counter == sp->pos) >>> + return true; >>> + counter++; >>> + } >>> + } >>> + >>> + WARN("Provided KLP_SYMPOS does not match a symbol: %s.%s,%d", >>> + sp->object_name, sp->symbol_name, sp->pos); >>> + print_valid_module_relocs(sp->symbol_name); >>> + >>> + return false; >>> +} >> >> I believe there is an off-by-one error condition either here, or in >> livepatch kernel core sympos disambiguator code (in which case, external >> tools like kpatch-build would also need to be adjusted). >> >> The scenarios that I've observed using klp-convert and kpatch-build: >> >> sympos == 0, uniquely named symbol >> sympos == 1, non-unique symbol name, first instance >> sympos == 2, non-unique symbol name, second instance >> ... > > Yes, that is exactly how we defined it back then. > >> When I built a klp-convert selftest, I made sure that the target module >> contained multiple symbols of the same name across two .o files. >> However, when I tried to use a KLP_MODULE_RELOC annotation in the >> livepatch to resolve to the second (ie, last) symbol, using a sympos=2, >> klp-convert kept telling me that the only valid KLP_SYMPOS were 0 and 1. >> >> The following code adjusts klp-convert to match the sympos logic, as I >> understand it in livepatch/core.c and kpatch-build; >> >> [squash] livepatch/klp-convert: fix klp-convert off-by-one sympos >> https://github.com/torvalds/linux/commit/1ed8e5baa98f7920bbbaa562278b3ed44552e01f >> >> This change also adds a check that sympos == 0 is in fact a uniquely >> named symbol. > Nice catch, thanks for it. All looks good to me. > Looks good to me. Maybe we can even make it simpler and use similar > approach as in klp_find_callback() and klp_find_object_symbol() from > kernel/livepatch/core.c. On the other hand, given that we want to print > useful output in all cases, the code might happen to be more complicated > and definitely ugly. I don't have an opinion here. > >>> [ ... snip ... ] >>> + >>> +int main(int argc, const char **argv) >>> +{ >>> + const char *klp_in_module, *klp_out_module, *symbols_list; >>> + struct rela *rela, *tmprela; >>> + struct section *sec, *aux; >>> + struct sympos sp; >>> + struct elf *klp_elf; >>> + >>> + if (argc != 4) { >>> + WARN("Usage: %s ", argv[0]); >>> + return -1; >>> + } >>> + >>> + symbols_list = argv[1]; >>> + klp_in_module = argv[2]; >>> + klp_out_module = argv[3]; >>> + >>> + klp_elf = elf_open(klp_in_module); >>> + if (!klp_elf) { >>> + WARN("Unable to read elf file %s\n", klp_in_module); >>> + return -1; >>> + } >>> + >>> + if (!load_syms_lists(symbols_list)) >>> + return -1; >>> + >>> + if (!load_usr_symbols(klp_elf)) { >>> + WARN("Unable to load user-provided sympos"); >>> + return -1; >>> + } >>> + >>> + list_for_each_entry_safe(sec, aux, &klp_elf->sections, list) { >>> + if (!is_rela_section(sec)) >>> + continue; >>> + >>> + list_for_each_entry_safe(rela, tmprela, &sec->relas, list) { >>> + if (!must_convert(rela->sym)) >>> + continue; >>> + >>> + if (!find_missing_position(rela->sym, &sp)) { >>> + WARN("Unable to find missing symbol"); >> >> A really minor suggestion, but I found it useful to tell the user >> exactly which symbol was missing: >> >> [squash] livepatch/klp-convert: add missing symbol name to warning >> https://github.com/torvalds/linux/commit/7a41a8f3d9b9e11f0c75914cb925af1486c1ecc6 > > I think that Joao has exactly the same hunk staged somewhere > already. You are right. The message is not much informative. > Yes, someone had the same idea for the klp-convert which we use inside SUSE. But it did not make it to this patch-set. Nice that Joe added it here :) > Miroslav >