Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp2528346rwb; Sun, 4 Sep 2022 18:38:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR6M+r01nwIQJEl3/QGcjgo06uExW69nh2CetWe0zqjlH71FhoSpUPktgRHObA4BRwhLqW51 X-Received: by 2002:a17:903:518:b0:176:b7e9:d9da with SMTP id jn24-20020a170903051800b00176b7e9d9damr480839plb.48.1662341921514; Sun, 04 Sep 2022 18:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662341921; cv=none; d=google.com; s=arc-20160816; b=dmZTELmm1pYJtc+Ba4vurNDGH46y5TC9ryn35pY6DGMVuZ1i6SPx6fOkLkgMn+jKRS d0GVZUa4E70RVYA0byoNuoBYJFV8i/Arm6uivXGxX2z32Q/epJJQQfLX0jqTAP9FocsX mYM+lMRCUdL/LGZvJFh6A/V4iz+0sin41Uf/Ys3508kCZ4LiNwBfSM1NG/bIEVgKm471 uooeMwm57H0yhSoRgym+7g030FDyWBJiqALGVXXaU7IkVO3DaD5nE/lrBRiOzE9S6m2N 4zDsF8n5A2SP3q1THOXBwxKtZdI9q4QtoAXJ15VwH+7YwIqTX5unVlIhzP0+PFKrTpqr emqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ntxas6xAsoqB4FdtMvAlR7HuK7Kj/xdxPguo6PSwEcE=; b=0plFunZ6dEGuGFcdGQxmenlw5eWp0P/DdjpchJPiFMBOk+kWMWoh0rlBk2CHULNkSZ D6fozIv3PGJRP5SGcoagUM7QJhFamna2cOFM/V8R/+PyCaBfScit5mXfhynz0amMAe20 h+Wdl/H02CQ9MhKmo8VzBf6fvznYhZRzoBamNk6LvxCtaMDCwRCYv8hXP5HfpswcGuOE /nPkOORwnqg9LGLQXiuWUVQML6jcCQM4kbOGpgjF/YZB3Ts5sLMCM+AiHT0CtQ7I5of8 XSI1QDQaONYo/QS6v9cy+QRZkjqSi5lQhK+7ZP/KGgohuFRC6tXaFLI+SKsM1mRkk3Hd 4W+g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id pj6-20020a17090b4f4600b001f021b4f1d5si1368871pjb.1.2022.09.04.18.38.29; Sun, 04 Sep 2022 18:38:41 -0700 (PDT) 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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbiIEBUJ (ORCPT + 99 others); Sun, 4 Sep 2022 21:20:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbiIEBUH (ORCPT ); Sun, 4 Sep 2022 21:20:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCF98E55; Sun, 4 Sep 2022 18:20:04 -0700 (PDT) Received: from dggpemm500022.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MLVv96XGZzZc9x; Mon, 5 Sep 2022 09:15:33 +0800 (CST) Received: from dggpemm500006.china.huawei.com (7.185.36.236) by dggpemm500022.china.huawei.com (7.185.36.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 09:20:01 +0800 Received: from [10.174.178.55] (10.174.178.55) by dggpemm500006.china.huawei.com (7.185.36.236) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 5 Sep 2022 09:20:01 +0800 Subject: Re: [PATCH] livepatch: Move error print out of lock protection in klp_enable_patch() To: Petr Mladek CC: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Joe Lawrence , , References: <20220901022706.813-1-thunder.leizhen@huawei.com> <20220902133628.GA29761@pathway.suse.cz> From: "Leizhen (ThunderTown)" Message-ID: Date: Mon, 5 Sep 2022 09:20:00 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20220902133628.GA29761@pathway.suse.cz> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.178.55] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500006.china.huawei.com (7.185.36.236) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 2022/9/2 21:36, Petr Mladek wrote: > On Fri 2022-09-02 09:28:59, Leizhen (ThunderTown) wrote: >>>> diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c >>>> index 42f7e716d56bf72..cb7abc821a50584 100644 >>>> --- a/kernel/livepatch/core.c >>>> +++ b/kernel/livepatch/core.c >>>> @@ -1041,9 +1041,9 @@ int klp_enable_patch(struct klp_patch *patch) >>>> mutex_lock(&klp_mutex); >>>> >>>> if (!klp_is_patch_compatible(patch)) { >>>> + mutex_unlock(&klp_mutex); >>>> pr_err("Livepatch patch (%s) is not compatible with the already installed livepatches.\n", >>>> patch->mod->name); >>>> - mutex_unlock(&klp_mutex); >>> >>> I do not see how this change could reliably reduce the code size. >>> >>> As Joe wrote, it looks like a random effect that is specific to a >>> particular compiler version, compilation options, and architecture. >>> >>> I am against these kind of random microptimizations. It is just a call >>> for problems. If you move printk() outside of a lock, you need to make >>> sure that the information is not racy. >> >> OK. >> >> mutex_lock(&klp_mutex); >> if (!klp_is_patch_compatible(patch)) { >> mutex_unlock(&klp_mutex); >> <--------- Do you mean the incompatible patches maybe disabled at this point? > > This particular change is safe in the current design. > klp_enable_patch() is called from the module_init() callback > where patch->mod->name is defined. So it can't change. > > The problem is that it is not obvious that it is safe. One has to > think about it. Also it might become dangerous when someone > tries to call klp_enable_livepatch() for another livepatch module. OK, I got it, thanks. > >> pr_err("Livepatch patch (%s) ...\n", patch->mod->name); >> return -EINVAL; >> } >> >>> >>> It might be safe in this particular case. But it is a bad practice. >>> It adds an extra work. It is error-prone with questionable gain. >>> >>> I am sorry but I NACK this patch. There must be better ways to >> >> OK > > Thanks for understanding. > > Best Regards, > Petr > . > -- Regards, Zhen Lei