Received: by 10.223.185.116 with SMTP id b49csp1970212wrg; Thu, 22 Feb 2018 06:14:01 -0800 (PST) X-Google-Smtp-Source: AH8x227U7obfFi0qbmHbF/PWNM5TGB1gDRN0lQdl87MWo7n3XivdUYzORlToqMZianoFNa+2bRv5 X-Received: by 2002:a17:902:bc85:: with SMTP id bb5-v6mr6900827plb.425.1519308841790; Thu, 22 Feb 2018 06:14:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519308841; cv=none; d=google.com; s=arc-20160816; b=mFFydENp2ADbUZIYgmsDdyeKbsbdJaO003T9Q2eYrNAxNvUaZOL1cswanHPb11UUwL ncbxxfMvzmfUnoXiIQF4hLO39ZU52RlBrIIcXAtUa3J8H8Sl4L/+8o0YZRzdYTP1yfpi OHmexoAv9vlYO5Hzhg73LW+z+cduGJyeG+aqVsNqZE1BsQ6B+TEGlWbAvvxW7fCrc+Q2 OHY+BtXk2lquFdcm7BQoUZgVJ5i1p3P4Z6OL9/kgDKeYYYYpX65UxuqBQyceM08nswkJ bC3IjGn62XEaJuf/hQm7M6jLCv1XT2SitFvy1P2gfUFUPUMUGi7+l0fzLt+zR15eRJIJ 4DLw== 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=aKJFfG4wsMng7qV6luft7LTn0ZuMm6S+gP/CavxQMb4=; b=oW+oAE4LXmkRcX8JbnjdYZ45JgvCQ8BaxPyCeCaTzFRV5zXzg8IYA3Wb2iNW5leYMI aRkh4M3O07RaEqEctZ6LGJfN2HJQZGMZR+WwyxjbsHueIAttCOK/X4BB96YaM/7/jTQ7 ia3dOLHIgI+ebeXOIlvk/bqx/MggJmtDlvCCtolwZ1JLnx/IoOPTxvF78IYGKzKDFOXj Nl5UbGYEMTt3RwN6ZNtPxyoHHE3eIVjvNg7tDXNmBzBw85fXQAiUQLJncIAOizRHWftU CDuCTJEUdmZw+4CUv8/RtoNeGNAFbuT7tJ/z+/hfwszlhfztXPt7ndnDA++h93fKiU+9 9bEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=PuvprHqF; 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 r9si112370pfg.165.2018.02.22.06.13.47; Thu, 22 Feb 2018 06:14:01 -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=PuvprHqF; 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 S932759AbeBVOMq (ORCPT + 99 others); Thu, 22 Feb 2018 09:12:46 -0500 Received: from mail-ua0-f171.google.com ([209.85.217.171]:41022 "EHLO mail-ua0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932664AbeBVOMo (ORCPT ); Thu, 22 Feb 2018 09:12:44 -0500 Received: by mail-ua0-f171.google.com with SMTP id u99so3371295uau.8 for ; Thu, 22 Feb 2018 06:12:43 -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=aKJFfG4wsMng7qV6luft7LTn0ZuMm6S+gP/CavxQMb4=; b=PuvprHqFoasjl3Xs9+ViWN2kBHnAifNUQsbf24z9uBfkyHQHWqabQV3nHjQ5FILNQF EanQ6iI2gKt1BxP8jP/f18osf5e+LEzengV2+YZtHKEEbEITveP+rrf3aTF2h2JyFOKs WOWUQ09srmbk057baESxCnh9H8/0Wt7Qk3F9M= 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=aKJFfG4wsMng7qV6luft7LTn0ZuMm6S+gP/CavxQMb4=; b=DBhAITwwh6EiJy9WxzmCL87B0lI5jaD2rlLaa55rfueuyyRwtqxn4gkG6B66A5j3wH 6B3RKVI0a7uzmGhc0TumXDCw/Fq07U8wB+3EUbIi4byu7TK4YdXxBxy3FGwaZKDiGskv DoAXQKLgsuSsnjYgctzaco3r0lvbX9/M0XVbWet0S63tff0D8h6EhUr0RTYmfjnPfKce ryXW1cidWoPgXKsgBEED67ysAhdhccwLZGbfq3irEpt7yKqK3Xjmm8YfvSOZFirLnRYn R7kdVarH8wfo1rEQKKblACCjnYL0TbheDU5R/vQSStvl9LAnL8fAh5BSH8SabzS1kM0Y eeyw== X-Gm-Message-State: APf1xPBNQVQS7qnkXZDqAFBCb7LqVakrjsUpW/3WVjhDcCNw2QJMwDuH NWVHaN8K4k9qvAg6M+u2PZFHuR/juMA= X-Received: by 10.176.4.73 with SMTP id 67mr5568498uav.163.1519308763267; Thu, 22 Feb 2018 06:12:43 -0800 (PST) Received: from mail-ua0-f182.google.com (mail-ua0-f182.google.com. [209.85.217.182]) by smtp.gmail.com with ESMTPSA id 131sm59541vkg.12.2018.02.22.06.12.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Feb 2018 06:12:41 -0800 (PST) Received: by mail-ua0-f182.google.com with SMTP id i15so3370700uak.3 for ; Thu, 22 Feb 2018 06:12:40 -0800 (PST) X-Received: by 10.176.71.234 with SMTP id w42mr5320505uac.132.1519308759695; Thu, 22 Feb 2018 06:12:39 -0800 (PST) MIME-Version: 1.0 Received: by 10.176.0.99 with HTTP; Thu, 22 Feb 2018 06:12:19 -0800 (PST) In-Reply-To: <28466b36-b5d3-4f60-a45e-b75d79c2a3cb@arm.com> References: <1517999482-17317-1-git-send-email-vivek.gautam@codeaurora.org> <7406f1ce-c2c9-a6bd-2886-5a34de45add6@arm.com> <28466b36-b5d3-4f60-a45e-b75d79c2a3cb@arm.com> From: Tomasz Figa Date: Thu, 22 Feb 2018 23:12:19 +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 , Vivek Gautam Cc: Will Deacon , "list@263.net:IOMMU DRIVERS" , Joerg Roedel , Rob Herring , Mark Rutland , "Rafael J. Wysocki" , Rob Clark , 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 Thu, Feb 22, 2018 at 10:45 PM, Robin Murphy wrote: > [sorry, I had intended to reply sooner but clearly forgot] > > > On 16/02/18 00:13, Tomasz Figa wrote: >> >> 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? > > > Yes, that's the kind of thing I was gravitating towards - my vague thought > was adding some flag to the smmu_domain, but pm_runtime_enabled() does look > conceptually a lot cleaner. Great, thanks. Looks like we're in agreement now. \o/ Vivek, does this sound reasonable to you? Best regards, Tomasz