Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp3254882rwb; Fri, 9 Dec 2022 11:59:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nyNOZ7OwU6WM9/JjCAU9VyzJlgYRHiXv21lHNIRAp1eo3bqrMbZdHR+sHyfq89b9Q1fuK X-Received: by 2002:a17:906:f102:b0:78d:f456:1ef2 with SMTP id gv2-20020a170906f10200b0078df4561ef2mr6274939ejb.67.1670615996897; Fri, 09 Dec 2022 11:59:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670615996; cv=none; d=google.com; s=arc-20160816; b=VzED/sO01DCvqAxPaiPatiKRYuDlLVip6HClweiyw77a4lqtzQDf0UepKIt6Gmr1dn JwODMeKWnUvkAPoHkn8U3BIv4wiBZOztIXgtqr4T+fc0Mj/v+msjg8ntg+8gT6yEVdDE 2LhVtzoJKK8BtvPRGn59DfAn0eB6lrIbJw7TYegqJ2S2FYxhNcKQy22+P7DVNxOalBaY wmmvl+LREbsZ1ZUP0E/xehmXnhvO0/nyOpaUKYm6QWnzMSy/MwlkSLHGddoeSt8wwvl8 /bACkVSkYmCJU04eEL+20Dzfc9Wz9XyB4LzGh3CyRnTFUlNXcUnZLxQGbtJrRP5/1GOG ughg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=vWxemY4/mB8zSUu5CYzlkGVEUsV+PV69OTrbtz4YXxk=; b=m++OKbYP4knPN/4trSieh2BIo9IskvOuMs71nrpc0/bVpFdFPg6gLQ/ne893KH6Djh tZtV+Tm9R4CIlykKxpGztoSvvJ8chGkFfLpn8wSUeOfWaa4SdgjSg48/EPFF4jH+LVYS K27x1l9gM2dtlA3wC5p4oZo6IBYtteABpmBl697hUso4Afl33SflIrHcTE90pgFXSLi6 +QpVBZcBTQ4grlS4oVcYeHDQ9RMcir98PZHBJtuiuYk4efPEwZ/fhJy4R7JaPdUzgLtE xgaOGNNRbDwMBAQjJwDE+XkS7eALhgQrzmz53dZTlsaEXPGWtN5DBiYzYeP4O2JP8Fr8 b4oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=o+uByTIM; 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 p10-20020a170906838a00b007b889a69895si391322ejx.589.2022.12.09.11.59.39; Fri, 09 Dec 2022 11:59:56 -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=@kernel.org header.s=k20201202 header.b=o+uByTIM; 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 S229656AbiLITYx (ORCPT + 74 others); Fri, 9 Dec 2022 14:24:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229538AbiLITYt (ORCPT ); Fri, 9 Dec 2022 14:24:49 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2021DA13E7; Fri, 9 Dec 2022 11:24:44 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 9F84762303; Fri, 9 Dec 2022 19:24:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0794CC43392; Fri, 9 Dec 2022 19:24:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670613883; bh=tOYtwqHozmknhMUKtwgTT6asrmy6Qi5D4CXEZwEJFvA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=o+uByTIMqF7RUXv3I6g1DZkmGKf30295zJ5Yy+usR/Yre92mgZ9FLZTDV0fUhIKRw eZOEwGalOjtsJ8vriXEbEhULwugKKKTADBg5k2x6qjBaXyFQwZN60klJR+0Codn8x8 VrGp/+MG9rFXv2O2FpFty7lTeENJPwPN3cqCmPe5uc815/F60KYufIR03ol5ug1M17 R6hLK2rR4J7hsdGPmEr5p58Oip8nGVrZS2L7MCdAA7i9atz1+TwKgutTr+6p/EM2nO 22ps+mD4Gl5n5uB6TjmH4rH/wf6okQF14H0WBnaHvLSLbRR7ZFdc9VfbuCgpktcK8C 1/+8WgligIhiA== Received: by mail-ej1-f44.google.com with SMTP id x22so13723955ejs.11; Fri, 09 Dec 2022 11:24:42 -0800 (PST) X-Gm-Message-State: ANoB5pniCgPuQzr8x7e2TsiKqtJj6IZCM8D9zy1u6+rqQkuxXagvGHBj JMiNXcBZ5SMZNN3yeSNhC/kJHUCJNZiT5eIXBlQ= X-Received: by 2002:a17:907:2c68:b0:7c0:999d:1767 with SMTP id ib8-20020a1709072c6800b007c0999d1767mr30991365ejc.301.1670613881161; Fri, 09 Dec 2022 11:24:41 -0800 (PST) MIME-Version: 1.0 References: <20220901171252.2148348-1-song@kernel.org> <7ddc326c-0c55-4901-16df-3e4e376e2570@csgroup.eu> In-Reply-To: <7ddc326c-0c55-4901-16df-3e4e376e2570@csgroup.eu> From: Song Liu Date: Fri, 9 Dec 2022 11:24:29 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6] livepatch: Clear relocation targets on a module removal To: Christophe Leroy Cc: Miroslav Benes , "pmladek@suse.com" , "jikos@kernel.org" , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , "joe.lawrence@redhat.com" , Josh Poimboeuf , "live-patching@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "jpoimboe@kernel.org" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Fri, Dec 9, 2022 at 10:52 AM Christophe Leroy wrote: > > > > Le 09/12/2022 =C3=A0 19:30, Song Liu a =C3=A9crit : > > On Fri, Dec 9, 2022 at 4:55 AM Miroslav Benes wrote: > >> > >> Hi, > >> > >> first thank you for taking over and I also appologize for not replying > >> much sooner. > >> > >> On Thu, 1 Sep 2022, Song Liu wrote: > >> > >>> From: Miroslav Benes > >>> > >>> Josh reported a bug: > >>> > >>> When the object to be patched is a module, and that module is > >>> rmmod'ed and reloaded, it fails to load with: > >>> > >>> module: x86/modules: Skipping invalid relocation target, existing = value is nonzero for type 2, loc 00000000ba0302e9, val ffffffffa03e293c > >>> livepatch: failed to initialize patch 'livepatch_nfsd' for module = 'nfsd' (-8) > >>> livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusi= ng to load module 'nfsd' > >>> > >>> The livepatch module has a relocation which references a symbol > >>> in the _previous_ loading of nfsd. When apply_relocate_add() > >>> tries to replace the old relocation with a new one, it sees that > >>> the previous one is nonzero and it errors out. > >>> > >>> On ppc64le, we have a similar issue: > >>> > >>> module_64: livepatch_nfsd: Expected nop after call, got e8410018 a= t e_show+0x60/0x548 [livepatch_nfsd] > >>> livepatch: failed to initialize patch 'livepatch_nfsd' for module = 'nfsd' (-8) > >>> livepatch: patch 'livepatch_nfsd' failed for module 'nfsd', refusi= ng to load module 'nfsd' > >>> > >>> He also proposed three different solutions. We could remove the error > >>> check in apply_relocate_add() introduced by commit eda9cec4c9a1 > >>> ("x86/module: Detect and skip invalid relocations"). However the chec= k > >>> is useful for detecting corrupted modules. > >>> > >>> We could also deny the patched modules to be removed. If it proved to= be > >>> a major drawback for users, we could still implement a different > >>> approach. The solution would also complicate the existing code a lot. > >>> > >>> We thus decided to reverse the relocation patching (clear all relocat= ion > >>> targets on x86_64). The solution is not > >>> universal and is too much arch-specific, but it may prove to be simpl= er > >>> in the end. > >>> > >>> Reported-by: Josh Poimboeuf > >>> Signed-off-by: Miroslav Benes > >>> Signed-off-by: Song Liu > >> > >> Petr has commented on the code aspects. I will just add that s390x was= not > >> dealt with at the time because there was no live patching support for > >> s390x back then if I remember correctly and my notes do not lie. The s= ame > >> applies to powerpc32. I think that both should be fixed as well with t= his > >> patch. It might also help to clean up the ifdeffery in the patch a bit= . > > > > I don't have test environments for s390 and powerpc, so I really don't = know > > whether I am doing something sane for them. > > > > Would you have time to finish these parts? (Or maybe the whole patch..) > > Setting up a powerpc test environment is fairly easy with QEMU. > > Some information below: > - https://github.com/linuxppc/wiki/wiki > - https://wiki.qemu.org/Documentation/Platforms/PowerPC Thanks for these pointers! I will give it a try. Song PS: Sometimes I am just lazy, you know..