Received: by 10.223.176.46 with SMTP id f43csp27307wra; Fri, 19 Jan 2018 13:14:17 -0800 (PST) X-Google-Smtp-Source: ACJfBotXucpIqUJeztvFhlQUl1lOccEha3nSphK1RlJlzU8c0bR9SQLIlrPK6Z6PRQ1vCDlaWoP0 X-Received: by 2002:a17:902:20c8:: with SMTP id v8-v6mr2214567plg.226.1516396457821; Fri, 19 Jan 2018 13:14:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516396457; cv=none; d=google.com; s=arc-20160816; b=D9zS9oksl9njnAzPXH6uOjlPj3SZqxzudeoe+DBASeTCNrQf2VKmT0GheOOUNdEEHn gn/73v1QiJsbU78Q7Paw7dqDjyONxVrwiZ7QqzgsqA8zRXBXh/jxGLwoQyx1yl+naOTr dpLYbx2zzP6qReU7gf+pY+xFZJnhdplM/eQdlSvM0WTZrcbZfscuAlta8DKv3xJeNUlD ZIAtJ1JrZyDWIT7jUBizRgXhSW1ngCH7Nj0ANa+Wt0ucNxXnVS6q0LkPOVcK2M7WqtB4 8cFsBX6JCgDNcMP6XAwlsPB34wt6S2fbIcl6+Rf3dESBVK8jOOGa934x5X0LDtEJjNnZ h+ew== 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:dkim-signature :arc-authentication-results; bh=/xmDIiTMoaRaWYux1z5CvSiUgALTjsTQbSJ+OPDWfLg=; b=uU5GqOYUMIznn99kUvSrzkIou2Xc118TD6D/z+JZqHWEjBlaLBsSrIhG0gSH5gGZ8k CcYgmudhNRckcuv2C5p3ICUhKPxKKnIOR1oshXN7z3SWzZJsR4XyUVSbyrvs92wiyijB x2C8NkjUeEqBOIwZlmx7mc2YOTxHSbHhlhnwKyFH37s/2dKTTv12N2fXbDQpkCD7piGV xVvtdgu5uF2i9lpe2+VoZOGRcQQAGBZWtzRRkRqhBMlrYLIPfuusWlcTxmuTiwbfH7Pv g00O432dzNSvJjkoSpBj0H/P9NBM1yGMmUo2Mt/H+c9svgC4eDhfp/iccp1w0A5tUC0b pELQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=oJfA78bG; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u6si8702145pgv.586.2018.01.19.13.13.53; Fri, 19 Jan 2018 13:14:17 -0800 (PST) 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; dkim=pass header.i=@akamai.com header.s=jan2016.eng header.b=oJfA78bG; 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; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=akamai.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932535AbeASVL3 (ORCPT + 99 others); Fri, 19 Jan 2018 16:11:29 -0500 Received: from mx0b-00190b01.pphosted.com ([67.231.157.127]:45054 "EHLO mx0b-00190b01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754118AbeASVLX (ORCPT ); Fri, 19 Jan 2018 16:11:23 -0500 Received: from pps.filterd (m0122331.ppops.net [127.0.0.1]) by mx0b-00190b01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w0JL7CDa007311; Fri, 19 Jan 2018 21:10:44 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akamai.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=jan2016.eng; bh=/xmDIiTMoaRaWYux1z5CvSiUgALTjsTQbSJ+OPDWfLg=; b=oJfA78bGvohWBIbzMoa3HFLcwPF+DcsGCtufMWwUt0NNdFLwkISyam9vwjhnhaLsEQEY x53cSUlycjBp+LYqYy/yiA6VMA7W60PYmlycOLWLtkefgmNskYpx+mtfAakbx1Z7DJoe e1USAg0zOUpvPX6G/CRroVYFICp6Go9VnZdqygt04t5Vqz0nCpXFvN8N3ksRgPBRuwAo 7zn7/35txsKo/Lan936EXMedMb8OAcFc3AiS8F8GwyD2VbgHFk1Ok8aHsJYwVRXFGuDT 2rDXA2Z/xj+/PQvumNh49/jrS2ASS0yGiTml0rh7jCNokDCaRdhPMjMMsOz7rnTPSRr+ ZQ== Received: from prod-mail-ppoint3 ([96.6.114.86]) by mx0b-00190b01.pphosted.com with ESMTP id 2fkmw3gyab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 19 Jan 2018 21:10:44 +0000 Received: from pps.filterd (prod-mail-ppoint3.akamai.com [127.0.0.1]) by prod-mail-ppoint3.akamai.com (8.16.0.21/8.16.0.21) with SMTP id w0JLAb5x012267; Fri, 19 Jan 2018 16:10:43 -0500 Received: from prod-mail-relay14.akamai.com ([172.27.17.39]) by prod-mail-ppoint3.akamai.com with ESMTP id 2ffebfhv9k-1; Fri, 19 Jan 2018 16:10:43 -0500 Received: from [172.28.12.191] (bos-lpjec.kendall.corp.akamai.com [172.28.12.191]) by prod-mail-relay14.akamai.com (Postfix) with ESMTP id BD91581866; Fri, 19 Jan 2018 14:10:42 -0700 (MST) Subject: Re: [PATCH v5 0/3] livepatch: introduce atomic replace To: Evgenii Shatokhin , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Cc: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org, mbenes@suse.cz, pmladek@suse.com, joe.lawrence@redhat.com References: From: Jason Baron Message-ID: <86cac2eb-0de4-bae7-f633-5ad03297880d@akamai.com> Date: Fri, 19 Jan 2018 16:10:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-19_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801190273 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-01-19_09:,, signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1801190272 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 01/19/2018 02:20 PM, Evgenii Shatokhin wrote: > On 12.01.2018 22:55, Jason Baron wrote: >> Hi, >>   While using livepatch, I found that when doing cumulative patches, >> if a patched >> function is completed reverted by a subsequent patch (back to its >> original state) >> livepatch does not revert the funtion to its original state. >> Specifically, if >> patch A introduces a change to function 1, and patch B reverts the >> change to >> function 1 and introduces changes to say function 2 and 3 as well, the >> change >> that patch A introduced to function 1 is still present. This could be >> addressed >> by first completely removing patch A (disable and then rmmod) and then >> inserting >> patch B (insmod and enable), but this leaves an unpatched window. In >> discussing >> this issue with Josh on the kpatch mailing list, he mentioned that we >> could get >> 'atomic replace working properly', and that is the direction of this >> patchset: >> https://www.redhat.com/archives/kpatch/2017-June/msg00005.html >> >> Thanks, >> >> -Jason > > Thanks a lot! Atomic replace is really crucial when using cumulative > patches. > > There is one more thing that might need attention here. In my > experiments with this patch series, I saw that unpatch callbacks are not > called for the older binary patch (the one being replaced). Thanks for testing and pointing this out. > > That is, I have prepared 2 binary patches, each has all 4 patch/unpatch > callbacks. > > When I load the first patch, its pre-patch and post-patch callbacks are > called as expected. > > Then I replace it with the second patch. Replacement is successful, the > pre-patch and post-patch callbacks are called for the second patch, > However, pre-unpatch and post-unpatch callbacks do not run for the first > one. This makes it more difficult to clean up what its pre/post-patch > callbacks have done. > > It would be nice if pre-/post- unpatch callbacks were called for the > first patch, perhaps, before/after the patch is actually disabled during > replacement. I cannot see right now though, which way is the best to > implement that. So I think the pre_unpatch() can be called for any prior livepatch modules from __klp_enable_patch(). Perhaps in reverse order of loading (if there is more than one), and *before* the pre_patch() for the livepatch module being loaded. Then, if it sucessfully patches in klp_complete_transition() the post_unpatch() can be called for any prior livepatch modules as well. I think again it makes sense to call the post_unpatch() for prior modules *before* the post_patch() for the current livepatch modules. Thanks, -Jason >>>> v4-v5 >> -re-base onto remove-immediate branch (removing immediate dependencies) >> -replaced modules can be re-enabled by doing rmmod and then insmod >> >> v3-v4: >> -add static patch, objects, funcs to linked lists to simplify iterator >> -break-out pure function movement as patch 2/3 >>   v2-v3: >> -refactor how the dynamic nops are calculated (Petr Mladek) >> -move the creation of dynamic nops to enable/disable paths >> -add klp_replaced_patches list to indicate patches that can be re-enabled >> -dropped 'replaced' field >> -renamed dynamic fields in klp_func, object and patch >> -moved iterator implementation to kernel/livepatch/core.c >> -'inherit' nop immediate flag >> -update kobject_put free'ing logic (Petr Mladek) >> >> v1-v2: >> -removed the func_iter and obj_iter (Petr Mladek) >> -initialiing kobject structure for no_op functions using: >>   klp_init_object() and klp_init_func() >> -added a 'replace' field to klp_patch, similar to the immediate field >> -a 'replace' patch now disables all previous patches >> -tried to shorten klp_init_patch_no_ops()... >> -Simplified logic klp_complete_transition (Petr Mladek) >> >> Jason Baron (3): >>    livepatch: use lists to manage patches, objects and functions >>    livepatch: shuffle core.c function order >>    livepatch: add atomic replace >> >>   include/linux/livepatch.h     |  25 +- >>   kernel/livepatch/core.c       | 626 >> ++++++++++++++++++++++++++++++------------ >>   kernel/livepatch/core.h       |   6 + >>   kernel/livepatch/patch.c      |  22 +- >>   kernel/livepatch/patch.h      |   4 +- >>   kernel/livepatch/transition.c |  49 +++- >>   6 files changed, 537 insertions(+), 195 deletions(-) >> > > Regards, > Evgenii