Received: by 10.192.165.156 with SMTP id m28csp482334imm; Wed, 11 Apr 2018 02:21:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx49PQhCkWrnmKKUIr6b/W0lm6AHOozdW5iaR7/FQuWcqjHBQ+n0j+6Ut99Cl5MhYKRj+Zg0F X-Received: by 2002:a17:902:a70f:: with SMTP id w15-v6mr4261039plq.344.1523438486093; Wed, 11 Apr 2018 02:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523438486; cv=none; d=google.com; s=arc-20160816; b=tK0wFMlKHbTpL1ay6MqZyNBB5ItAKevhbIjs7q2lYeu8ndVLUsyEdLP5MKKxt16xh7 CtOLsJ82+0z8CFMoLL+ibqPuJKOCBka8dnUaRmZi+4GTCKRMn7afQ4L1gpWICzHd0iZN 5zGDurP49isOSMwQaBxCwU1a/UBwnshzI3/F+Na7oNS60A1A6yWpfpCN4oIsQYjqn91+ Sl0ChSa3voAZ9CFUzgC5irz/O8h50WSiyJzNc5VbsKUVYwuUEl5EZKcymEmmnUK9zm+5 VpeqQUjQS+vv0Ly/2gE8E06EaKjGXePN7+tpUxT5QMCEcCQh22xvTHcHlhthCBC2M62e xtyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Nd9jmdw/cW6yycnocZmfcsUXo5X2DUu/OxNtvt4fQhY=; b=IDPNMlo8oTDg0ACvboVJ4Z+Z/6bEW5lcBmSNSUkz4TTzv+IkjRI5lsUxt2x1l8gwxC QQ9hxPvpiy4R7tn46OITJNlmokoPjWuJx9tIm0U6DCEZn8M3EvFsjLiCGleN4ewf0c9A wTbO/XQOcqO1/wcbweVXRSKh1FKIWmsTzKGNtaeMxeFQMAxboLpXMTAJIkOuFFPjOu/D 73s9+LbIaiYUsGikyhsH21RBodlv7iY+BcZsZPQYpSlFZ5LUmUbAbDrKBL46B1PFEvgM I5cfJgQqoiCnqNfnIgHVjb1hStBpTE4xx3G4Jdw8VLTr616hxFNwoAQj1Ilh5OHJ1YU9 X+1g== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9-v6si712917plr.64.2018.04.11.02.20.49; Wed, 11 Apr 2018 02:21:26 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752746AbeDKJQz (ORCPT + 99 others); Wed, 11 Apr 2018 05:16:55 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:39598 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752291AbeDKJPy (ORCPT ); Wed, 11 Apr 2018 05:15:54 -0400 Received: from ayla.of.borg ([84.194.111.163]) by baptiste.telenet-ops.be with bizsmtp id YxFs1x00T3XaVaC01xFsfz; Wed, 11 Apr 2018 11:15:52 +0200 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1f6Br6-0002Cq-85; Wed, 11 Apr 2018 11:15:52 +0200 Received: from geert by ramsan with local (Exim 4.86_2) (envelope-from ) id 1f6Br6-0004I4-5m; Wed, 11 Apr 2018 11:15:52 +0200 From: Geert Uytterhoeven To: Baptiste Reynal , Alex Williamson Cc: Philipp Zabel , Rob Herring , Mark Rutland , kvm@vger.kernel.org, devicetree@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] vfio: platform: Fix using devices in PM Domains Date: Wed, 11 Apr 2018 11:15:46 +0200 Message-Id: <1523438149-16433-1-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a device is part of a PM Domain (e.g. power and/or clock domain), its power state is managed using Runtime PM. Without Runtime PM, the device may not be powered up, causing subtle failures, crashes, or system lock-ups when the device is accessed by the guest. Fix this by adding Runtime PM support, powering the device when the VFIO device is opened by the guest. Note that while more fine-grained power management could be implemented on the guest side, if exported, this would be inherently unsafe, as abusing it may kill the whole system. Signed-off-by: Geert Uytterhoeven --- drivers/vfio/platform/vfio_platform_common.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/platform/vfio_platform_common.c index 3c13327b2777f8ec..9d46fce2446daebe 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -255,6 +256,8 @@ static void vfio_platform_release(void *device_data) const char *extra_dbg = NULL; int ret; + pm_runtime_put(vdev->device); + ret = vfio_platform_call_reset(vdev, &extra_dbg); if (ret && vdev->reset_required) { dev_warn(vdev->device, "reset driver is required and reset call failed in release (%d) %s\n", @@ -297,6 +300,10 @@ static int vfio_platform_open(void *device_data) ret, extra_dbg ? extra_dbg : ""); goto err_rst; } + + ret = pm_runtime_get_sync(vdev->device); + if (ret < 0) + goto err_rst; } vdev->refcnt++; @@ -712,6 +719,7 @@ int vfio_platform_probe_common(struct vfio_platform_device *vdev, mutex_init(&vdev->igate); + pm_runtime_enable(vdev->device); return 0; put_iommu: @@ -729,6 +737,7 @@ struct vfio_platform_device *vfio_platform_remove_common(struct device *dev) vdev = vfio_del_group_dev(dev); if (vdev) { + pm_runtime_disable(vdev->device); vfio_platform_put_reset(vdev); vfio_iommu_group_put(dev->iommu_group, dev); } -- 2.7.4