Received: by 10.223.185.116 with SMTP id b49csp997039wrg; Fri, 16 Feb 2018 10:31:07 -0800 (PST) X-Google-Smtp-Source: AH8x225cEb4odnVZuVlD1zD4iU01tl8fYOD1dwQ00/OayRc0FmJ/hzOqyf6neZjOCh8frI16YJOx X-Received: by 10.99.4.197 with SMTP id 188mr5698935pge.359.1518805867294; Fri, 16 Feb 2018 10:31:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518805867; cv=none; d=google.com; s=arc-20160816; b=h2+toGEwSFSlUCikUPgtwHi+JRjmKrGPPw2OFVXFNEkJmEg4dUZVBOEU8qF4twRmLU rFZyFHsjPdxi0TrUCYumYvP4LHUYaFBiVgufN0oaxDbPCS8Ua2U3CiFLzPk0D0h0OQYH YU+N+x1JWvAZdw70BZES1kBxysPruAhtSblvM+scEF/C6wqGlTRgtUfrP9Xz8H3bLIPb KYo3gv+mWYbYLut3cyy/GEvfMfV3/ZuqfUeq7MFU7sFwfNTs8Gq3kq/G9ahkqvQFNgaW vL0KfaBVJrZJX3aopZqc92F1oA0YCs5d0oBjVDImKK/hBm4p9IpFu1lFokkEeofzFBAD 4lfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=3iwGQ+YCglKALHoird8t+GuQaLlnMdFI5CwSxgmgWyo=; b=X46/zrsfnkY6a8QbXVOA4jr7eA6qMYs8gWpmQQsL5iZrm7ucj2f+TkXLX3lsob0Izx c2T5vpEEo7EcA5TGHvgpGewp1hXd2ZmaH51dlg5nXIPsSozlHmYf2vZEss16Q4Y3ECny NgNW+7gc9SypXx5cP21Q3CzYievAB2qHQCZDejqr/pE5ZpV5zsfyH+qMmsiRuDEc63sA r/PLPZXH0fPePmM8EtC7w+ZLsUnyiDGK8fHjxcSEGZ5U3WGJ3eKgSUI3+V8lgbhB+JAr hukSwzqG9oRSNRQRI/L+L+BFrZESW8KSJ00UW3fUaz/ClbbZ4F7kj5PRmQeaycwbTElP rmZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=h73dtpNY; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v1si7998889pfg.288.2018.02.16.10.30.52; Fri, 16 Feb 2018 10:31:07 -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=@chromium.org header.s=google header.b=h73dtpNY; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1422940AbeBPAOT (ORCPT + 99 others); Thu, 15 Feb 2018 19:14:19 -0500 Received: from mail-vk0-f47.google.com ([209.85.213.47]:41281 "EHLO mail-vk0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1422695AbeBPAOP (ORCPT ); Thu, 15 Feb 2018 19:14:15 -0500 Received: by mail-vk0-f47.google.com with SMTP id t201so932010vke.8 for ; Thu, 15 Feb 2018 16:14:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3iwGQ+YCglKALHoird8t+GuQaLlnMdFI5CwSxgmgWyo=; b=h73dtpNYMyoyX+dtLtj4HgTt2pnNCz9D69Om0IIkN7PdwZYqdX3dMqM2DWYyyD8N+V c4POG0MOXlwJGtzvqZV5OGgr6Hl6ddd/qHqS4RGVHjqHU6u3q9eaf+6E02kHb6NH28M/ xQqor9VhONUQRPk7Og1seUawjua/5jhxPlX9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3iwGQ+YCglKALHoird8t+GuQaLlnMdFI5CwSxgmgWyo=; b=MjcmJocNMQRvVCKpY7XfhJgYKmi61J3jx/JjgOg15aKJEBv6ZMly14tspENwIG65pc NvSifuSPgOPls2KiidfyRwlfOlOq+U/7yJIg2qW6ANizek0IzIiLeWqPK+D78TrL2dkg mWPuNUBKIer6diY46ptli7nAuowJ72OHagrRaIBFue32HixrekeLdR3btejkFe6OyUOc ulGJsK1MP8SIQfBC3sZiPQXL917ZfGIdAUg9RNH3B0SfMnwH/M7tXGbq0wer83X68OS3 TD1tEJyu2GyAMtG9vF9RKsTcuxUqe/4e10FE2bQpywdrdUOtPCQJB7AE1jzAJLHV7bmo SBFw== X-Gm-Message-State: APf1xPBImYVPNdsExbql3p3ZnLkLrM3KFbMMhuj1r3ken+wXJSmEe02Y JWf5j6yp9GOMmskYOGYHT5Vkd30GgSA= X-Received: by 10.31.231.3 with SMTP id e3mr3358406vkh.183.1518740054674; Thu, 15 Feb 2018 16:14:14 -0800 (PST) Received: from mail-vk0-f53.google.com (mail-vk0-f53.google.com. [209.85.213.53]) by smtp.gmail.com with ESMTPSA id u76sm1200804uau.0.2018.02.15.16.14.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 16:14:13 -0800 (PST) Received: by mail-vk0-f53.google.com with SMTP id p74so944746vkd.1 for ; Thu, 15 Feb 2018 16:14:13 -0800 (PST) X-Received: by 10.31.188.72 with SMTP id m69mr3510208vkf.86.1518740052344; Thu, 15 Feb 2018 16:14:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.37.12 with HTTP; Thu, 15 Feb 2018 16:13:50 -0800 (PST) In-Reply-To: <7406f1ce-c2c9-a6bd-2886-5a34de45add6@arm.com> References: <1517999482-17317-1-git-send-email-vivek.gautam@codeaurora.org> <7406f1ce-c2c9-a6bd-2886-5a34de45add6@arm.com> From: Tomasz Figa Date: Fri, 16 Feb 2018 09:13:50 +0900 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7 6/6] drm/msm: iommu: Replace runtime calls with runtime suppliers To: Robin Murphy Cc: Vivek Gautam , Will Deacon , Rob Clark , "list@263.net:IOMMU DRIVERS" , Joerg Roedel , Rob Herring , Mark Rutland , "Rafael J. Wysocki" , devicetree@vger.kernel.org, Linux Kernel Mailing List , Linux PM , dri-devel , freedreno , David Airlie , Greg KH , Stephen Boyd , linux-arm-msm , jcrouse@codeaurora.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 16, 2018 at 2:14 AM, Robin Murphy wrote: > On 15/02/18 04:17, Tomasz Figa wrote: > [...] >>> >>> Could you elaborate on what kind of locking you are concerned about? >>> As I explained before, the normally happening fast path would lock >>> dev->power_lock only for the brief moment of incrementing the runtime >>> PM usage counter. >> >> >> My bad, that's not even it. >> >> The atomic usage counter is incremented beforehands, without any >> locking [1] and the spinlock is acquired only for the sake of >> validating that device's runtime PM state remained valid indeed [2], >> which would be the case in the fast path of the same driver doing two >> mappings in parallel, with the master powered on (and so the SMMU, >> through device links; if master was not powered on already, powering >> on the SMMU is unavoidable anyway and it would add much more latency >> than the spinlock itself). > > > We now have no locking at all in the map path, and only a per-domain lock > around TLB sync in unmap which is unfortunately necessary for correctness; > the latter isn't too terrible, since in "serious" hardware it should only be > serialising a few cpus serving the same device against each other (e.g. for > multiple queues on a single NIC). > > Putting in a global lock which serialises *all* concurrent map and unmap > calls for *all* unrelated devices makes things worse. Period. Even if the > lock itself were held for the minimum possible time, i.e. trivially > "spin_lock(&lock); spin_unlock(&lock)", the cost of repeatedly bouncing that > one cache line around between 96 CPUs across two sockets is not negligible. Fair enough. Note that we're in a quite interesting situation now: a) We need to have runtime PM enabled on Qualcomm SoC to have power properly managed, b) We need to have lock-free map/unmap on such distributed systems, c) If runtime PM is enabled, we need to call into runtime PM from any code that does hardware accesses, otherwise the IOMMU API (and so DMA API and then any V4L2 driver) becomes unusable. I can see one more way that could potentially let us have all the three. How about enabling runtime PM only on selected implementations (e.g. qcom,smmu) and then having all the runtime PM calls surrounded with if (pm_runtime_enabled()), which is lockless? > >> [1] >> http://elixir.free-electrons.com/linux/v4.16-rc1/source/drivers/base/power/runtime.c#L1028 >> [2] >> http://elixir.free-electrons.com/linux/v4.16-rc1/source/drivers/base/power/runtime.c#L613 >> >> In any case, I can't imagine this working with V4L2 or anything else >> relying on any memory management more generic than calling IOMMU API >> directly from the driver, with the IOMMU device having runtime PM >> enabled, but without managing the runtime PM from the IOMMU driver's >> callbacks that need access to the hardware. As I mentioned before, >> only the IOMMU driver knows when exactly the real hardware access >> needs to be done (e.g. Rockchip/Exynos don't need to do that for >> map/unmap if the power is down, but some implementations of SMMU with >> TLB powered separately might need to do so). > > > It's worth noting that Exynos and Rockchip are relatively small > self-contained IP blocks integrated closely with the interfaces of their > relevant master devices; SMMU is an architecture, implementations of which > may be large, distributed, and have complex and wildly differing internal > topologies. As such, it's a lot harder to make hardware-specific assumptions > and/or be correct for all possible cases. > > Don't get me wrong, I do ultimately agree that the IOMMU driver is the only > agent who ultimately knows what calls are going to be necessary for whatever > operation it's performing on its own hardware*; it's just that for SMMU it > needs to be implemented in a way that has zero impact on the cases where it > doesn't matter, because it's not viable to specialise that driver for any > particular IP implementation/use-case. Still, exactly the same holds for the low power embedded use cases, where we strive for the lowest possible power consumption, while maintaining performance levels high as well. And so the SMMU code is expected to also work with our use cases, such as V4L2 or DRM drivers. Since these points don't hold for current SMMU code, I could say that the it has been already specialized for large, distributed implementations. Best regards, Tomasz