From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E560C433EF for ; Thu, 27 Jan 2022 11:45:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240774AbiA0Lpn (ORCPT ); Thu, 27 Jan 2022 06:45:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:29332 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240729AbiA0Lpn (ORCPT ); Thu, 27 Jan 2022 06:45:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643283942; 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=AD61UJefV4ldqNZTeQa0Q6Eqd5G/BKYwphalJ1/v8lg=; b=EBAKaANeACV+8EOEF0kf9fR+r5mEbqwc8vdI0FKhDxPr0/FkAQonxbWXGpg5lzwlLuX6k+ 6t+8KffZ6CxZCA47X43oQL5Sqrwz8Xr+yWa/ds6TK+3t6Db1WNf1YfkWrGzszSluiBFjjK a9Qj4NURhOod31gfylOyg074q/oyxvc= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-538-v1UNgN-FNFqF5haCXOjLLQ-1; Thu, 27 Jan 2022 06:45:41 -0500 X-MC-Unique: v1UNgN-FNFqF5haCXOjLLQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3EEFE180E48E; Thu, 27 Jan 2022 11:45:40 +0000 (UTC) Received: from queeg.tpb.lab.eng.brq.redhat.com (unknown [10.43.135.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6A9D6E4AC; Thu, 27 Jan 2022 11:45:38 +0000 (UTC) From: Miroslav Lichvar To: netdev@vger.kernel.org Cc: Miroslav Lichvar , Yangbo Lu , Yang Yingliang , Richard Cochran Subject: [PATCH net-next 1/5] ptp: unregister virtual clocks when unregistering physical clock. Date: Thu, 27 Jan 2022 12:45:32 +0100 Message-Id: <20220127114536.1121765-2-mlichvar@redhat.com> In-Reply-To: <20220127114536.1121765-1-mlichvar@redhat.com> References: <20220127114536.1121765-1-mlichvar@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When unregistering a physical clock which has some virtual clocks, unregister the virtual clocks with it. This fixes the following oops, which can be triggered by unloading a driver providing a PTP clock when it has enabled virtual clocks: BUG: unable to handle page fault for address: ffffffffc04fc4d8 Oops: 0000 [#1] PREEMPT SMP NOPTI RIP: 0010:ptp_vclock_read+0x31/0xb0 Call Trace: timecounter_read+0xf/0x50 ptp_vclock_refresh+0x2c/0x50 ? ptp_clock_release+0x40/0x40 ptp_aux_kworker+0x17/0x30 kthread_worker_fn+0x9b/0x240 ? kthread_should_park+0x30/0x30 kthread+0xe2/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x22/0x30 Fixes: 73f37068d540 ("ptp: support ptp physical/virtual clocks conversion") Signed-off-by: Miroslav Lichvar Cc: Yangbo Lu Cc: Yang Yingliang Cc: Richard Cochran --- drivers/ptp/ptp_clock.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c index 0e4bc8b9329d..b6f2cfd15dd2 100644 --- a/drivers/ptp/ptp_clock.c +++ b/drivers/ptp/ptp_clock.c @@ -317,11 +317,18 @@ struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info, } EXPORT_SYMBOL(ptp_clock_register); +static int unregister_vclock(struct device *dev, void *data) +{ + struct ptp_clock *ptp = dev_get_drvdata(dev); + + ptp_vclock_unregister(info_to_vclock(ptp->info)); + return 0; +} + int ptp_clock_unregister(struct ptp_clock *ptp) { if (ptp_vclock_in_use(ptp)) { - pr_err("ptp: virtual clock in use\n"); - return -EBUSY; + device_for_each_child(&ptp->dev, NULL, unregister_vclock); } ptp->defunct = 1; -- 2.34.1