From patchwork Tue Mar 2 09:26:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 12111307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD431C433E6 for ; Tue, 2 Mar 2021 09:37:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F49964EEB for ; Tue, 2 Mar 2021 09:37:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F49964EEB Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=2sJKMRvsyBptNSjzN6ka8j8Exp5JDB9XG2TdgAls/SU=; b=UPwEGPYKiVNCgA73TDVJsyZcyp UJCvz3FXdx7z58GC/PyjvpKFO0mxMM7dgMiF1ECmIM2fR2iPSurd//o74MqDNezpyfx1rqFMjTb35 KPwi0EREmXlUl60ywISDTWlSko5EeOzAvj+YVgKFw4EVYxRPtIii9vlNgXsWbOeBsHaIXlr5ayQd8 JNR0aeLFAU5NcZG4oaEvuGYIrRflXE4d4vTKOTv7wQy18Qlod7gLGWXqenNBJhwjQ8fV+QpHjNu2P p/ZL5doAxvNmNh0bm3Kv2xrDJiMM0wv2AwGqM5tuQWxMcJjrP6DMMUGIfWtOdAo5j3byP8RhWrNwR zTwelqQg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lH1RJ-0003AK-51; Tue, 02 Mar 2021 09:35:37 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lH1RF-000385-Px for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 09:35:35 +0000 Received: by mail-wr1-x42b.google.com with SMTP id 7so19109117wrz.0 for ; Tue, 02 Mar 2021 01:35:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cEvh5d2SHvxkSF+1irchEvrHiYiFzIPFtl5KjBbhkiY=; b=e0QdvPzBHHsEWw8yEUV63Abhpos9MC8ghOLDX4KpBWQHX7ucYQLT1YohHplRdd1zWv MsXtxpCExw1/mrCBDAuhbSb0Ki8sJDYCXMYOlfkPnS1TSu+HOTMXh+yBivoQUwNrMJ8L x3uhIY9nhxSRtqRnBJ+Fz7azE098RqmzW+feKSdcNSMY0Rb+J/B+sbXlblnOwArExQ3Q OTnGY6UWnuczU+CPWx9NZyIBzqwmumm2H9sLU8YvwZ9l3OBEewLY8qAVSXfZKnkF0UwU nT8CMx0ljrIjGklCr2zkJ2uHjWXnXJTEUgnp6WQMmNp4lSPQHnUsuus8J0kxsBGoSeub cuRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=cEvh5d2SHvxkSF+1irchEvrHiYiFzIPFtl5KjBbhkiY=; b=lqjDVv36z1xc/DztlQq35XX3RnslSHjUYxdMyGn41SYFOevVmihlSEm1+DuQXp4v+n EPwkJaVLScMndffQix4q8w9SzphVpwT22AIXyCFOOAyz80NhjftQSUhvtysTyozRp7Fn z2/dxCsbzxWwquHJczKiJaGzX0dK446sRuJqofT/a4Q778grs/aVmKVOUMDsU9huw/Di q5/Kef6DIrOgOWmtvFO2vLKcUHY7yqiaW88Rl4TL+piCTo36gsxdhmHByLQqw1sq41MN v6udi2lUWzstPUR+g1VWbrSWp52f42BZsn+cLbcAlNh0SIoYC4oca3EogQcmaiffW+c1 SI4A== X-Gm-Message-State: AOAM531+V+JLi8Qx+C/fVqT478qJAHIX5bLfbg1oHr38d+f8FTW2AqXF OEALIdjtCqyoHZolbhMdVoZQpw== X-Google-Smtp-Source: ABdhPJzwD2G5q6rP9T+vUtD3KyAyfU1qRsMeo52c3TFT0pOxMNOJrhtlwKkPcLVRuwoKj88VYCWBtg== X-Received: by 2002:adf:ef08:: with SMTP id e8mr22098078wro.200.1614677730353; Tue, 02 Mar 2021 01:35:30 -0800 (PST) Received: from localhost.localdomain ([2001:1715:4e26:a7e0:116c:c27a:3e7f:5eaf]) by smtp.gmail.com with ESMTPSA id w131sm1963818wmb.8.2021.03.02.01.35.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Mar 2021 01:35:29 -0800 (PST) From: Jean-Philippe Brucker To: joro@8bytes.org, will@kernel.org Subject: [PATCH v13 00/10] iommu: I/O page faults for SMMUv3 Date: Tue, 2 Mar 2021 10:26:36 +0100 Message-Id: <20210302092644.2553014-1-jean-philippe@linaro.org> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_043534_036210_7C3488D1 X-CRM114-Status: GOOD ( 11.13 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vivek.gautam@arm.com, guohanjun@huawei.com, zhukeqian1@huawei.com, Jean-Philippe Brucker , lorenzo.pieralisi@arm.com, wangzhou1@hisilicon.com, linux-acpi@vger.kernel.org, zhangfei.gao@linaro.org, lenb@kernel.org, devicetree@vger.kernel.org, kevin.tian@intel.com, jacob.jun.pan@linux.intel.com, eric.auger@redhat.com, robh+dt@kernel.org, Jonathan.Cameron@huawei.com, linux-arm-kernel@lists.infradead.org, rjw@rjwysocki.net, shameerali.kolothum.thodi@huawei.com, iommu@lists.linux-foundation.org, sudeep.holla@arm.com, robin.murphy@arm.com, linux-accelerators@lists.ozlabs.org, baolu.lu@linux.intel.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add stall support to the SMMUv3 driver, along with a common I/O Page Fault handler. Since v12 [1]: * Fixed failure path of arm_smmu_insert_master(), in patch 07 (Keqian Zhu) * In arm_smmu_handle_evt(), patch 10, don't report IPA field on stage-1 faults, and report accurate fault reason (Eric Auger) * Fix possible use-after-free in arm_smmu_handle_evt(), patch 10: if a master is removed while we handle its events, we could in theory dereference a freed master struct. Hold streams_mutex while using a master struct obtained with arm_smmu_find_master(). Future work regarding IOPF: * Keep stall disabled by default, only enable it per CD when drivers request it [2][3]. * Add PRI support to SMMUv3. * Route all recoverable faults through io-pgfault.c, so we can track partial faults better [4]. * Nested IOPF [5]. [1] https://lore.kernel.org/linux-iommu/20210127154322.3959196-1-jean-philippe@linaro.org/ [2] https://lore.kernel.org/linux-iommu/22fa4120-eadf-20d5-0d0a-9935aa0f1fb5@hisilicon.com/ [3] https://lore.kernel.org/linux-iommu/YAhui7UOw7743shI@myrica/ [4] https://lore.kernel.org/kvm/YB0f5Yno9frihQq4@myrica/ [5] https://lore.kernel.org/linux-acpi/MWHPR11MB188653AF6EFA0E55DE17815F8CA40@MWHPR11MB1886.namprd11.prod.outlook.com/ Jean-Philippe Brucker (10): iommu: Fix comment for struct iommu_fwspec iommu/arm-smmu-v3: Use device properties for pasid-num-bits iommu: Separate IOMMU_DEV_FEAT_IOPF from IOMMU_DEV_FEAT_SVA iommu/vt-d: Support IOMMU_DEV_FEAT_IOPF uacce: Enable IOMMU_DEV_FEAT_IOPF iommu: Add a page fault handler iommu/arm-smmu-v3: Maintain a SID->device structure dt-bindings: document stall property for IOMMU masters ACPI/IORT: Enable stall support for platform devices iommu/arm-smmu-v3: Add stall support for platform devices drivers/iommu/Makefile | 1 + .../devicetree/bindings/iommu/iommu.txt | 18 + drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 56 ++- drivers/iommu/iommu-sva-lib.h | 53 ++ include/linux/iommu.h | 26 +- drivers/acpi/arm64/iort.c | 15 +- .../iommu/arm/arm-smmu-v3/arm-smmu-v3-sva.c | 59 ++- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 354 ++++++++++++-- drivers/iommu/intel/iommu.c | 11 +- drivers/iommu/io-pgfault.c | 461 ++++++++++++++++++ drivers/iommu/of_iommu.c | 5 - drivers/misc/uacce/uacce.c | 39 +- 12 files changed, 1024 insertions(+), 74 deletions(-) create mode 100644 drivers/iommu/io-pgfault.c Tested-by: Krishna Reddy