Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1554621pxb; Thu, 28 Oct 2021 06:01:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlGQ319tcKgaX2r56JDSrI49vmqCnKPTEaQQ6Fp83LLqDlg/NtFbDiWCY+Wgoucu/1Zzfg X-Received: by 2002:a17:906:538f:: with SMTP id g15mr1851519ejo.348.1635426104782; Thu, 28 Oct 2021 06:01:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635426104; cv=none; d=google.com; s=arc-20160816; b=iHhUP7mviYzEzUXq3oTBlIPKr0rtWV+DRlqIBJBHWdjaeXdTv7EOaqNq7RjR4ds8jy 0+C9Ew04+7dmkF4zvkrhGPur1J28A209HDMNJNn9eRpiKngnnQslt4ONfGiKPaVzjvwm BqhMahzYg6Ih0MviSbIewvoQpkAUEIj6DKuTK78X6SKGu+sZlZHNd4hIjperqE/JoJ1Q PKp0kYRRbGjj9GdjFmNazdrQxpYzTOhVvM2q6i7L51SSJjPitQsmy+pfva3MTy0SfJrt JtdU2mXHyza1y4WVVsVbWj7nsUg2zz4j25iltx/5ndSF4JR8Y7efP9NagjpYJCO0R7TX OhKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=PirYheqr6FLOoxWAxVnOPTHVHjvSWygKUIkBvNKqlsc=; b=Eim2eQxVvJwxASuWaHHY5PDosuHiS2XsrZrPBMF88CLOedtESVJQXBKbfiQgqIYdZJ NAmGMx5TjKmz1MJHHwym15gXYNe7AlbgSvr2oAposKhCz6IRGDPWwVDAIRzOFE+J2QwF +aKW2vNy+KpJvBzojftloxhbDWm2NAFUYlLBPKAKrZlrhaOZWl0lTraF/TUxiVwyWttB UKJIBaM+cFLEnDagrEB4t13//ykLBcrmH0Z8QzZMG5OCpZP/5/Gq6f4XbINlmRR1oaaf As/qfDSRzv5zyETAC7rtCdoCIYtI0kuSW37IAlVufcwrAjlKJYHvs/tVMK15G20e9ITz YScQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IbglBOwo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hq16si4935001ejc.29.2021.10.28.06.01.19; Thu, 28 Oct 2021 06:01:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IbglBOwo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230297AbhJ1NAm (ORCPT + 99 others); Thu, 28 Oct 2021 09:00:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47179 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230240AbhJ1NAi (ORCPT ); Thu, 28 Oct 2021 09:00:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635425891; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PirYheqr6FLOoxWAxVnOPTHVHjvSWygKUIkBvNKqlsc=; b=IbglBOwoQoQCWV7qUN8SBR1CMWLe2ovfacS85hrg4GRiuZArNgLxA5hnQreswTZJC1HFFw oY0+EKA+sPCUFWDOXqTVyOD5e92pkiWVMPacH2onZg4FM3Esz4TCoe3G9L+7U2/O1fnV0L SQXw72HiDUNidatBt29rTlpBWXa8ZoI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-czxcAYfcOaKKVYjfPOqrjQ-1; Thu, 28 Oct 2021 08:58:08 -0400 X-MC-Unique: czxcAYfcOaKKVYjfPOqrjQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 043E1101F014; Thu, 28 Oct 2021 12:57:48 +0000 (UTC) Received: from localhost (ovpn-8-40.pek2.redhat.com [10.72.8.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 435755D9DE; Thu, 28 Oct 2021 12:57:46 +0000 (UTC) From: Ming Lei To: Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , live-patching@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Luis Chamberlain , Ming Lei Subject: [PATCH 1/3] livepatch: remove 'struct completion finish' from klp_patch Date: Thu, 28 Oct 2021 20:57:32 +0800 Message-Id: <20211028125734.3134176-2-ming.lei@redhat.com> In-Reply-To: <20211028125734.3134176-1-ming.lei@redhat.com> References: <20211028125734.3134176-1-ming.lei@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The completion finish is just for waiting release of the klp_patch object, then releases module refcnt. We can simply drop the module refcnt in the kobject release handler of klp_patch. This way also helps to support allocating klp_patch from heap. Signed-off-by: Ming Lei --- include/linux/livepatch.h | 1 - kernel/livepatch/core.c | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/linux/livepatch.h b/include/linux/livepatch.h index 2614247a9781..9712818997c5 100644 --- a/include/linux/livepatch.h +++ b/include/linux/livepatch.h @@ -170,7 +170,6 @@ struct klp_patch { bool enabled; bool forced; struct work_struct free_work; - struct completion finish; }; #define klp_for_each_object_static(patch, obj) \ diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c index 335d988bd811..b967b4b0071b 100644 --- a/kernel/livepatch/core.c +++ b/kernel/livepatch/core.c @@ -551,10 +551,10 @@ static int klp_add_nops(struct klp_patch *patch) static void klp_kobj_release_patch(struct kobject *kobj) { - struct klp_patch *patch; + struct klp_patch *patch = container_of(kobj, struct klp_patch, kobj); - patch = container_of(kobj, struct klp_patch, kobj); - complete(&patch->finish); + if (!patch->forced) + module_put(patch->mod); } static struct kobj_type klp_ktype_patch = { @@ -678,11 +678,6 @@ static void klp_free_patch_finish(struct klp_patch *patch) * cannot get enabled again. */ kobject_put(&patch->kobj); - wait_for_completion(&patch->finish); - - /* Put the module after the last access to struct klp_patch. */ - if (!patch->forced) - module_put(patch->mod); } /* @@ -876,7 +871,6 @@ static int klp_init_patch_early(struct klp_patch *patch) patch->enabled = false; patch->forced = false; INIT_WORK(&patch->free_work, klp_free_patch_work_fn); - init_completion(&patch->finish); klp_for_each_object_static(patch, obj) { if (!obj->funcs) -- 2.31.1