Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2704272rwb; Fri, 9 Dec 2022 05:30:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf7tIK6B8ysZ26Z5r58s6RsBggz4H5j6KFGFGa22+csJsbOStyPNemTR+Ilf0f8JudIoVRWG X-Received: by 2002:a17:906:a099:b0:78d:f459:7176 with SMTP id q25-20020a170906a09900b0078df4597176mr7280956ejy.33.1670592649095; Fri, 09 Dec 2022 05:30:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670592649; cv=none; d=google.com; s=arc-20160816; b=JiwY2cZJT7yx3twOePswCrUS0AelnwJI4GNelHQ0NJBrZ2HnYQQ+XljWh7ywpn16h4 yhBUqMftyi72U0/Qfum9zWl7LsJPCSUqi3FMXse7YKeMC1TgVtWWg6iD5ebfyvCSKRtm I6nZZwWheYT/D3Kj5OK5TjLyjEbLBziaZT2lg1mjsAir1I/ZimIX9igPoZ+j9+TopOF0 /ISb0b+0pekvWPLwAJ+TIb30LfCdEqr6p0/LQj3QVwPq1rEino0tUv++itCF1iR9j8zv hqAAn2NiWmFKUJtsDyB4oc8Kz5QXyR+Iw/q7FcX8EjQVarUPCxphCxrB6MsFvq17XcJ/ 1KUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XhaJ4AMLCZEgETruIyMo/c72wUMpujHKYsj5J9PetEI=; b=Vmt7CFmpTsykjfcEDNixe5ucolHBMrLOi/XpJ8+xXHOF49MKqoTpz9OOg4uD3ZVNJ5 6O6gDuJDNAN7Uwc1hijQuAJzwaIoUzl5Dblg4TRV3QJt7jmKq40EJp47M3FQFzwC9hhu s4LHPX8QELbrqjc7yRIrKrho9DHdsN5eXb0+PSCAWvi7VedAPD1aM/ZlBebQleVNPhMN sa+Cq/4KaPYimtYRFrB5TStmgKBxxiW0aygglfLiLY73LFGwzb/GoLCi6HWCGwwx9W3R CrrxQ8WT6309zPl/TIXubrcnO11N1MiW/LolyiL5S9D6OxxZfPsi2wOkVFABfAoUgQ/T zZzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=lj1aIbaO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gb33-20020a170907962100b007c10f6a46c7si1255280ejc.355.2022.12.09.05.30.26; Fri, 09 Dec 2022 05:30:49 -0800 (PST) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b=lj1aIbaO; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229840AbiLIMgY (ORCPT + 75 others); Fri, 9 Dec 2022 07:36:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbiLIMgX (ORCPT ); Fri, 9 Dec 2022 07:36:23 -0500 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 763D4663F6; Fri, 9 Dec 2022 04:36:22 -0800 (PST) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 3304B1FDD3; Fri, 9 Dec 2022 12:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1670589381; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=XhaJ4AMLCZEgETruIyMo/c72wUMpujHKYsj5J9PetEI=; b=lj1aIbaOrUSW/4IH3P9xvkmt4sS+Vua3KVOSLWW/4ZaVjpZXUf9PCF+2AwJBYEoH8Ueq+T l1+VZhtJg3kaqSfdImLzMaVFZi0C0SAPfITWqkfevOBbkkFhYn9WKW6g/6rao/X8/xjDI9 bRjyq6IBZlNlaPWlMUzXxToftLaK8Og= Received: from suse.cz (unknown [10.100.201.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 0EA7A2C141; Fri, 9 Dec 2022 12:36:21 +0000 (UTC) Date: Fri, 9 Dec 2022 13:36:17 +0100 From: Petr Mladek To: Song Liu Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, jpoimboe@kernel.org, jikos@kernel.org, mbenes@suse.cz, x86@kernel.org, joe.lawrence@redhat.com, linuxppc-dev@lists.ozlabs.org, Josh Poimboeuf Subject: x86 part: was: Re: [PATCH v6] livepatch: Clear relocation targets on a module removal Message-ID: References: <20220901171252.2148348-1-song@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 On Mon 2022-11-28 17:57:06, Song Liu wrote: > On Fri, Nov 18, 2022 at 8:24 AM Petr Mladek wrote: > --- a/arch/x86/kernel/module.c > +++ b/arch/x86/kernel/module.c > > This duplicates a lot of code. Please, rename apply_relocate_add() the > > same way as __apply_clear_relocate_add() and add the "apply" parameter. > > Then add the wrappers for this: > > > > int write_relocate_add(Elf64_Shdr *sechdrs, > > const char *strtab, > > unsigned int symindex, > > unsigned int relsec, > > struct module *me, > > bool apply) > > { > > int ret; > > bool early = me->state == MODULE_STATE_UNFORMED; > > void *(*write)(void *, const void *, size_t) = memcpy; > > > > if (!early) { > > write = text_poke; > > mutex_lock(&text_mutex); > > } > > How about we move the "early" logic into __write_relocate_add()? If I get it correctly then __write_relocate_add() has three different return paths. I am not sure if this could be moved there a reasonable way. Anyway, I do not resist on the above proposal. Feel free to find another solution that reduces the duplicated code and looks reasonable. I am sure that there are more possibilities. Best Regards, Petr