Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp6431img; Wed, 20 Mar 2019 12:38:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqw8jycVq8iyXwHtd60IUeDRwB+TL3/gbYZfCa/fhFx0Gbky3tzZqy3r9QYEmbSTRYxUQKFH X-Received: by 2002:a63:5c43:: with SMTP id n3mr1916833pgm.163.1553110703837; Wed, 20 Mar 2019 12:38:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553110703; cv=none; d=google.com; s=arc-20160816; b=X4iaxSdLo75rLlO9lHWW2xojupLxL+OHQHXZ9jeXQ0gHnutq83XC1GkXIcrN1TioBF ixqpUM9KuS2wc8olVZEZICtFjXhYbpt8m1DOJgL+4Y3KrYi22waqVB0SP0PH5ficb33N YRGudTOMnr/kgu9n96emypbKAIDLdqH4HNaseis31hVgGr3yr9XBFqJEnpBkDF/zVLb9 VjlYVVUuUEeW66I59JkHkGrbpFRVHK5sZX/UTskyXg3RRVp349AlgL8adXH4/X9LyJp3 7R0F2mVcoHG86jOce+z5NycKx3xn6madBoit1zMqwiiJXO3m78oyUKq7GMvwuRomy3Rz aftQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=xVfynJgyYHLJ26DNhZG35tgjYa/nYXWzjtCLDFN9Gv0=; b=HFSS5pl9AjLpbvXRnxmE+1+q1rkhNhBcyIBca+cBJ/+/oi1YU0IokUr0deitr1EgHD ivQnAvz7r1ph7HMgBoVetR4db1pHVwml2hQMXfCpai3Gj/lbqHSYVpFIUH9AyVbY/njw hiRu3BL6zIkM9UD0Ver1igbzknrP/go0NV2tVTA7CLK21menUzhmSl8EFBPvT/BImvAE vyHS4C0Q4oTbEiXHT/Lk+Pj7iKD5K0/w3uCUMGzapokDSegMtEZOqNq+OYWGq03mc4Ft rTcC/J+zGYUgF3WBnQzdgK6FH9EPOqTwmK0jwviqqLjhLXU6Ch++zTNPickQjdE9VVQM UIaQ== 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 d198si2282276pga.74.2019.03.20.12.37.40; Wed, 20 Mar 2019 12:38:23 -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 S1726742AbfCTThD (ORCPT + 99 others); Wed, 20 Mar 2019 15:37:03 -0400 Received: from mx2.suse.de ([195.135.220.15]:55856 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726006AbfCTThC (ORCPT ); Wed, 20 Mar 2019 15:37:02 -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 8CABDAD88; Wed, 20 Mar 2019 19:37:00 +0000 (UTC) Date: Wed, 20 Mar 2019 20:36:59 +0100 (CET) From: Miroslav Benes To: Joe Lawrence cc: Joao Moreira , 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 Subject: Re: [PATCH v2 3/8] livepatch: Add klp-convert tool In-Reply-To: <20190318192011.GA23157@redhat.com> Message-ID: References: <20190301141313.15057-1-jmoreira@suse.de> <20190301141313.15057-4-jmoreira@suse.de> <20190318192011.GA23157@redhat.com> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > [ ... 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. 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. > > [ ... 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. Miroslav