From patchwork Wed May 30 09:57:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vivek Gautam X-Patchwork-Id: 10438109 X-Patchwork-Delegate: agross@codeaurora.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 86E22602CC for ; Wed, 30 May 2018 09:57:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74A1F2888C for ; Wed, 30 May 2018 09:57:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68D21288ED; Wed, 30 May 2018 09:57:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A38162888C for ; Wed, 30 May 2018 09:57:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750710AbeE3J5Y (ORCPT ); Wed, 30 May 2018 05:57:24 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:38710 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750714AbeE3J5V (ORCPT ); Wed, 30 May 2018 05:57:21 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 56C1A60769; Wed, 30 May 2018 09:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527674240; bh=MYmcehZeyjwtl1gYrLpbCoMgTw5MaO6mRRDysH6mpZ4=; h=From:To:Cc:Subject:Date:From; b=LLmgKPYjkQMqVB9vpVc0qaWz7RFc6w7U7Oz18xRFZTXiD9ftDXPlEZqTEsZsVx/fH ypdrkhpoXnyCL9rtdqUtnbt4Dxd1MGXi834G3x8OAEZQZY8zjoYHdk5ZpACueQDmA0 vs1FmOw6pUBoHJL/Wp6E5qxDtfO+Pe8VWjYsCKgs= Received: from blr-ubuntu-41.ap.qualcomm.com (blr-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: vivek.gautam@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 58A6660251; Wed, 30 May 2018 09:57:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1527674239; bh=MYmcehZeyjwtl1gYrLpbCoMgTw5MaO6mRRDysH6mpZ4=; h=From:To:Cc:Subject:Date:From; b=JCUBLhkDQkzuEa2zoneQlF3OPdPFXLTlxGTR/3gZEh9F1mAxEq+08jrYv5ZOyYPSv 76aHDgV7fe6IXv0zLh1L5mD2cHTpWNs7VC1448oNicrrhzkDYcmyGqHLH1t0lKcest N5szhi2YBIhQqvzd9oIvNQcg1oywLpdGiT4DSpeM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 58A6660251 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=vivek.gautam@codeaurora.org From: Vivek Gautam To: gregkh@linuxfoundation.org, rafael.j.wysocki@intel.com, lukas@wunner.de Cc: dmitry.torokhov@gmail.com, aspriel@gmail.com, robin.murphy@arm.com, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Vivek Gautam Subject: [PATCH 1/1] device core: Add flag to autoremove device link on supplier unbind Date: Wed, 30 May 2018 15:27:04 +0530 Message-Id: <20180530095704.5788-1-vivek.gautam@codeaurora.org> X-Mailer: git-send-email 2.16.1.72.g5be1f00a9a70 Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When using the device links without the consumers or suppliers maintaining pointers to these links, a flag can help in autoremoving the links on supplier driver unbind. We remove these links only when the supplier's link to its consumers has gone in DL_STATE_SUPPLIER_UNBIND state. Signed-off-by: Vivek Gautam Suggested-by: Lukas Wunner --- Lukas, as suggested in the thread [1] this change adds additional flag to autoremove device links on supplier unbind. For arm-smmu, we want to _not_ keep references to the device links added between arm-smmu, and consumer devices. Robin also pointed to [2] the need to autoremove the device link on supplier unbind rather than consumer unbind. [1] https://lkml.org/lkml/2018/3/14/390 [2] https://lkml.org/lkml/2018/5/21/381 drivers/base/core.c | 10 ++++++++++ include/linux/device.h | 2 ++ 2 files changed, 12 insertions(+) diff --git a/drivers/base/core.c b/drivers/base/core.c index b610816eb887..52c7222bb3c4 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -490,6 +490,16 @@ void device_links_driver_cleanup(struct device *dev) WARN_ON(link->flags & DL_FLAG_AUTOREMOVE); WARN_ON(link->status != DL_STATE_SUPPLIER_UNBIND); + + /* + * autoremove the links between this @dev and its consumer + * devices that are not active, i.e. where the link state + * has moved to DL_STATE_SUPPLIER_UNBIND. + */ + if (link->status == DL_STATE_SUPPLIER_UNBIND && + link->flags & DL_FLAG_AUTOREMOVE_S) + kref_put(&link->kref, __device_link_del); + WRITE_ONCE(link->status, DL_STATE_DORMANT); } diff --git a/include/linux/device.h b/include/linux/device.h index 477956990f5e..6033bf58453d 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -779,11 +779,13 @@ enum device_link_state { * AUTOREMOVE: Remove this link automatically on consumer driver unbind. * PM_RUNTIME: If set, the runtime PM framework will use this link. * RPM_ACTIVE: Run pm_runtime_get_sync() on the supplier during link creation. + * AUTOREMOVE_S: Remove this link automatically on supplier driver unbind. */ #define DL_FLAG_STATELESS BIT(0) #define DL_FLAG_AUTOREMOVE BIT(1) #define DL_FLAG_PM_RUNTIME BIT(2) #define DL_FLAG_RPM_ACTIVE BIT(3) +#define DL_FLAG_AUTOREMOVE_S BIT(4) /** * struct device_link - Device link representation.