Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1206795pxv; Fri, 25 Jun 2021 07:44:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyK8hh73HSqV79qruNCBK0pSf5V9kH1E+begSPkUFElsPvDeNMUzCXq5+Z8FCJh9RqF3Szf X-Received: by 2002:aa7:d74b:: with SMTP id a11mr15226707eds.40.1624632258838; Fri, 25 Jun 2021 07:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624632258; cv=none; d=google.com; s=arc-20160816; b=pXWJTw7aQoOyQmxtCx7vDi75u2YRflIvoDxVMkQPgHKzShdpeq7otCj6KPCegTLh1q IfuinLBZaPSVjVzGhEBQbO8vfGz70xY/MOXaiuQsTGA7v+PhKngWDZ8Lb6J/bDjNLB8g 5Tohh4Wt3F6vHjodwbc7mVkOOzX+Lx6+gmMGx7DYwEL6m9aIqYJaR301a+7kk2xDJ1+u YlYI+S7thCyoFsndkZR01cAuGHvDqkwbjJtFbA9sWm2+ZAvIG6plQ8U4uzPokhBTk2hT rwTCPnse2q3MjK7vrUPLnmvrRgLNvscCQsUOSUOi7Z1YpSR9ue4GqOGq88f2n+jO9EzK n+XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=j8m5Di25YEHezMhSM0CIBaRcSl+2cupixwUQS08gJpo=; b=sWp6P25kQuV+4K46iWXBgw7csKiFIoJDtvdl34xjZhy9BpFKlVd6ddeavnOs8V4sLT B50aUkVbtaUAZ7+l/K4zz4yh9OT36zPFEKqpEOlbj1BcCmSp8Cwem4UKiOSo6jK6ilDg Gy3MmQ+yhTIzOX/IjcMsA34v17FgpVBsP/GqYH/KVmtjbkvd32DR3GyNYV0eN97pJGRo 33k8l29k+2GdU42XgwIh4ABWgNgBQZyw/AQkJDMdW70EoYK4J2EUfbW8lyVq2phaYByG j4hwfVVg9zznYV3Z2KlU/2ehPjE5UsaLY4hiRqjPrptcfLnXvOfYjVIAOr+GFXxRZzbB 2prQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M6vw5n1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id h21si5920394ejt.172.2021.06.25.07.43.55; Fri, 25 Jun 2021 07:44:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=M6vw5n1m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S231524AbhFYOpC (ORCPT + 99 others); Fri, 25 Jun 2021 10:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbhFYOpA (ORCPT ); Fri, 25 Jun 2021 10:45:00 -0400 Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB69CC061574 for ; Fri, 25 Jun 2021 07:42:39 -0700 (PDT) Received: by mail-ot1-x329.google.com with SMTP id x17-20020a05683000d1b029045fb1889a9eso9032247oto.5 for ; Fri, 25 Jun 2021 07:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j8m5Di25YEHezMhSM0CIBaRcSl+2cupixwUQS08gJpo=; b=M6vw5n1mivkEmZrZaE7zieAlKLsTCL3sm9eT56bSI/8K31Go3QolQ35P0EOIUStr1i Ps9F1aHzu148M6CnpnCl479CYign0nk21Ld54dTETQxPeTlpC0v+vVMC1vqhwLBpIR1T 3JmEdCj0y7cmRGSI/pvihxB5MGkxE/h5jVHys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=j8m5Di25YEHezMhSM0CIBaRcSl+2cupixwUQS08gJpo=; b=Vf05O4gqK4a2MiWehj7iERxKQWdLh8juu8BhObPLbKGoNjZW5N3qCNgRjhL9DqxRk5 6gq20EVdirXnD63nLHSrs1dwbr2FJEKtHbuLVet3VNpBljpC/t/QjMgSlttGSE2/yFG4 McTpP0c1rsJftV1JUQOfvielb5n6SvEpsFWONEGtARIbI5vmhKJ/Ba2IOK+9zV0hMS8n izDhtKL4gba53yYjvEb4cAXKwEc0Wg4sF9W263SfZiuJo6V5NW+589WWmbGkerLU2O6x zeAr9AdEG6saGImS4mf5qxzB4K7wo+7QWIt1u8DSWyQsAoN6akNS6wF7tdJorla5facQ V31g== X-Gm-Message-State: AOAM532iK0wKATyJkpivZd/u8QkNCgmDRlTtbND97vSKiBVbwvL2JPuC nrLM2bl3m3MYd+Dze/Jt78vW3VNBSfm2Bg== X-Received: by 2002:a9d:2aa8:: with SMTP id e37mr10374071otb.220.1624632158864; Fri, 25 Jun 2021 07:42:38 -0700 (PDT) Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com. [209.85.161.53]) by smtp.gmail.com with ESMTPSA id m3sm365986otf.12.2021.06.25.07.42.38 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Jun 2021 07:42:38 -0700 (PDT) Received: by mail-oo1-f53.google.com with SMTP id 128-20020a4a11860000b029024b19a4d98eso2576887ooc.5 for ; Fri, 25 Jun 2021 07:42:38 -0700 (PDT) X-Received: by 2002:a25:ad60:: with SMTP id l32mr10591974ybe.276.1624632147433; Fri, 25 Jun 2021 07:42:27 -0700 (PDT) MIME-Version: 1.0 References: <20210624171759.4125094-1-dianders@chromium.org> In-Reply-To: From: Doug Anderson Date: Fri, 25 Jun 2021 07:42:15 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 0/3] iommu: Enable non-strict DMA on QCom SD/MMC To: Joerg Roedel Cc: Will Deacon , Robin Murphy , Bjorn Andersson , Ulf Hansson , Adrian Hunter , Bjorn Helgaas , John Garry , Rob Clark , quic_c_gdjako@quicinc.com, Saravana Kannan , Rajat Jain , Sai Prakash Ranjan , Veerabhadrarao Badiganti , Linux MMC List , linux-arm-msm , linux-pci@vger.kernel.org, "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , Sonny Rao , Joel Fernandes , Andrew Morton , Jonathan Corbet , Jordan Crouse , Konrad Dybcio , Krishna Reddy , "Maciej W. Rozycki" , Nicolin Chen , "Paul E. McKenney" , Peter Zijlstra , Randy Dunlap , Thierry Reding , Viresh Kumar , Vlastimil Babka , Linux ARM , Linux Doc Mailing List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Fri, Jun 25, 2021 at 6:19 AM Joerg Roedel wrote: > > Hi Douglas, > > On Thu, Jun 24, 2021 at 10:17:56AM -0700, Douglas Anderson wrote: > > The goal of this patch series is to get better SD/MMC performance on > > Qualcomm eMMC controllers and in generally nudge us forward on the > > path of allowing some devices to be in strict mode and others to be in > > non-strict mode. > > So if I understand it right, this patch-set wants a per-device decision > about setting dma-mode to strict vs. non-strict. > > I think we should get to the reason why strict mode is used by default > first. Is the default on ARM platforms to use iommu-strict mode by > default and if so, why? > > The x86 IOMMUs use non-strict mode by default (yes, it is a security > trade-off). It is certainly a good question. I will say that, as per usual, I'm fumbling around trying to solve problems in subsystems I'm not an expert at, so if something I'm saying sounds like nonsense it probably is. Please correct me. I guess I'd start out by thinking about what devices I think need to be in "strict" mode. Most of my thoughts on this are in the 3rd patch in the series. I think devices where it's important to be in strict mode fall into "Case 1" from that patch description, copied here: Case 1: IOMMUs prevent malicious code running on the peripheral (maybe a malicious peripheral or maybe someone exploited a benign peripheral) from turning into an exploit of the Linux kernel. This is particularly important if the peripheral has loadable / updatable firmware or if the peripheral has some type of general purpose processor and is processing untrusted inputs. It's also important if the device is something that can be easily plugged into the host and the device has direct DMA access itself, like a PCIe device. Using sc7180 as an example (searching for iommus in sc7180.dtsi), I'd expect these peripherals to be in strict mode: * WiFi / LTE - I'm almost certain we want this in "strict" mode. Both have loadable / updatable firmware and both do complex processing on untrusted inputs. Both have a history of being compromised over the air just by being near an attacker. Note that on sc7180 these are _not_ connected over PCI so we can't leverage any PCI mechanism for deciding strict / non-strict. * Video decode / encode - pretty sure we want this in strict. It's got loadable / updatable firmware and processing complex / untrusted inputs. * LPASS (low power audio subsystem) - I don't know a ton and I think we don't use this much on our designs, but I believe it meets the definitions for needing "strict". * The QUPs (handles UART, SPI, and i2c) - I'm not as sure here. These are much "smarter" than you'd expect. They have loadable / updatable firmware and certainly have a sort of general purpose processor in them. They also might be processing untrusted inputs, but presumably in a pretty simple way. At the moment we don't use a ton of DMA here anyway and these are pretty low speed, so I would tend to leave them as strict just to be on the safe side. I'd expect these to be non-strict: * SD/MMC - as described in this patch series. * USB - As far as I know firmware isn't updatable and has no history of being compromised. Special: * GPU - This already has a bunch of special cases, so we probably don't need to discuss here. As far as I can tell everything in sc7180.dtsi that has an "iommus" property is classified above. So, unless I'm wrong and it's totally fine to run LTE / WiFi / Video / LPASS in non-strict mode then: * We still need some way to pick strict vs. non-strict. * Since I've only identified two peripherals that I think should be non-strict, having "strict" the default seems like fewer special cases. It's also safer. In terms of thinking about x86 / AMD where the default is non-strict, I don't have any historical knowledge there. I guess the use of PCI for connecting WiFi is more common (so you can use the PCI special cases) and I'd sorta hope that WiFi is running in strict mode. For video encode / decode, perhaps x86 / AMD are just accepting the risk here because there was no kernel infrastructure for doing better? I'd also expect that x86/AMD don't have something quite as crazy as the QUPs for UART/I2C/SPI, but even if they do I wouldn't be terribly upset if they were in non-strict mode. ...so I guess maybe the super short answer to everything above is that I believe that at least WiFi ought to be in "strict" mode and it's not on PCI so we need to come up with some type of per-device solution. -Doug