Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp8112427ybc; Fri, 29 Nov 2019 05:48:05 -0800 (PST) X-Google-Smtp-Source: APXvYqxQPI+hM+S+UZClkABuRphnRVVkg4pQYHkqcClCLP9iTB5m2nnVVUMF8nOIaGdh+vMipCIt X-Received: by 2002:a17:906:cc98:: with SMTP id oq24mr17147665ejb.170.1575035285043; Fri, 29 Nov 2019 05:48:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575035285; cv=none; d=google.com; s=arc-20160816; b=hfcQwgv0F6oozuyxS/2pAN1UcuK7RBu8MPOP3SCvoef2E35IdOz2yk7B/c4Jm8BxFy R6TSu44dMUIg7mVkmYrM/A9/8CtcSMcvt3bTVOASmYv+Ai2rqFN6ecFYTzPfwo5klOJs RO/GHCeVIFH6xsNGV0qgGS7PXj/vevpnhZrG2DWTBfmlGfq4hflRn8PrLXAd9yV1H1FA tUi8PQP/rtiz6N9bDnR7UiFkBfHGqSPrv12110Gr/qo9rrzIoxDnJCW1X86rKqyv2aSh LSXkbyUYSgYqX3nBiIXOmRl18/7EtVamITf5hqChiTAsv/mK2sf59XhnwpaXmqTNylXM rEUg== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:dkim-signature; bh=c6kyduALUMlhgXr7+NWpnW7lYxje+66n8zte1sjHPtQ=; b=C7DsgkeIXCfZMbESxakYCUh2+VF/bfrgciDVELEPr+kA6by3t/yPunPeEdTid4/Jjc ftJyOCUlGM4IBFuEtVzhEWWLfRqaDLLBqrjrYPtlHvLOplQb9UqZn8kSGActR5vFVjPF Cbq3Vgr2aWIka5XPVmOM72V2QXnf7ilZJcJjq+EWh70XQtHHqX54KB8gygjBP7/PFZ1B 4LXKD2FYWUcCwo6r0G0RGH1jImDcZ15yAWnkqNTEahHWe03JgAxnPnNKqV0wXno3vQDa NqbiLh/BL2njStwpvr8uFvIvg0ma7CYZsU1cfl3ZkQ+VyTTKdJI6u9T4Dlor1i+84ewV voAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=jZI1p2tQ; 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=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3si533423ejc.405.2019.11.29.05.47.40; Fri, 29 Nov 2019 05:48:05 -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=@amazon.com header.s=amazon201209 header.b=jZI1p2tQ; 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=QUARANTINE dis=NONE) header.from=amazon.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726879AbfK2Nna (ORCPT + 99 others); Fri, 29 Nov 2019 08:43:30 -0500 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:43721 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbfK2Nna (ORCPT ); Fri, 29 Nov 2019 08:43:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1575035010; x=1606571010; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c6kyduALUMlhgXr7+NWpnW7lYxje+66n8zte1sjHPtQ=; b=jZI1p2tQm84hhNT9kA2BsYkOEJDBN+dzu2478xJfVE/S9A0hamYq8xyH p+wcMwnN2YZZYftb9/OfqNI/Ex0DFZjfV5Ff9RUltO8xz+hKMM2dzJf64 GaPPS8Y8no1TFC2rKpKDQO4LHWvXDRWV3dxrNQiqefHU+1itoRrgYvN11 A=; IronPort-SDR: e313tRJFZvKq/8QfO6v7WwPLs4wfemBryy0e4hKh5dmdkHBgrPoM/p7KJ6uTkCfaGL2Pd6S3K8 aRuogK46WYNw== X-IronPort-AV: E=Sophos;i="5.69,257,1571702400"; d="scan'208";a="10582565" Received: from sea32-co-svc-lb4-vlan3.sea.corp.amazon.com (HELO email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com) ([10.47.23.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP; 29 Nov 2019 13:43:18 +0000 Received: from EX13MTAUEA001.ant.amazon.com (iad55-ws-svc-p15-lb9-vlan2.iad.amazon.com [10.40.159.162]) by email-inbound-relay-1d-37fd6b3d.us-east-1.amazon.com (Postfix) with ESMTPS id 04DBE282697; Fri, 29 Nov 2019 13:43:15 +0000 (UTC) Received: from EX13D32EUB003.ant.amazon.com (10.43.166.165) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 29 Nov 2019 13:43:15 +0000 Received: from EX13MTAUEE001.ant.amazon.com (10.43.62.200) by EX13D32EUB003.ant.amazon.com (10.43.166.165) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Fri, 29 Nov 2019 13:43:14 +0000 Received: from u2f063a87eabd5f.cbg10.amazon.com (10.125.106.135) by mail-relay.amazon.com (10.43.62.226) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Fri, 29 Nov 2019 13:43:12 +0000 From: Paul Durrant To: , , CC: Paul Durrant , Jan Beulich , "Boris Ostrovsky" , Juergen Gross , Stefano Stabellini Subject: [PATCH v2 1/2] xen/xenbus: reference count registered modules Date: Fri, 29 Nov 2019 13:43:05 +0000 Message-ID: <20191129134306.2738-2-pdurrant@amazon.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191129134306.2738-1-pdurrant@amazon.com> References: <20191129134306.2738-1-pdurrant@amazon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To prevent a module being removed whilst attached to a frontend, and hence xenbus calling into potentially invalid text, take a reference on the module before calling the probe() method (dropping it if unsuccessful) and drop the reference after returning from the remove() method. NOTE: This allows the ad-hoc reference counting in xen-netback to be removed. This will be done in a subsequent patch. Suggested-by: Jan Beulich Signed-off-by: Paul Durrant --- Cc: Boris Ostrovsky Cc: Juergen Gross Cc: Stefano Stabellini v2: - New in v2 --- drivers/xen/xenbus/xenbus_probe.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c index 5b471889d723..5a4947690500 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -232,9 +232,11 @@ int xenbus_dev_probe(struct device *_dev) return err; } + __module_get(drv->driver.owner); + err = drv->probe(dev, id); if (err) - goto fail; + goto fail_put; err = watch_otherend(dev); if (err) { @@ -244,6 +246,8 @@ int xenbus_dev_probe(struct device *_dev) } return 0; +fail_put: + module_put(drv->driver.owner); fail: xenbus_dev_error(dev, err, "xenbus_dev_probe on %s", dev->nodename); xenbus_switch_state(dev, XenbusStateClosed); @@ -263,6 +267,8 @@ int xenbus_dev_remove(struct device *_dev) if (drv->remove) drv->remove(dev); + module_put(drv->driver.owner); + free_otherend_details(dev); xenbus_switch_state(dev, XenbusStateClosed); -- 2.20.1