From patchwork Mon Aug 12 20:52:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mostafa Saleh X-Patchwork-Id: 13761047 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 55F93C52D7C for ; Mon, 12 Aug 2024 21:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DuUqrCWF/xHWcFuXKlPjIWucc9/NhZLN0OsUooYWUjg=; b=H/eEnHlO97PA0mOtLFaAvoUNt2 jhFPFOwJGf07mvQNLw610cL3KDkMuXtQYKIbmr1ZyIEwz92OgI0FRZ9C3w76XOtMu8ih6FUWxICYU GzoaGoBrUmoYFD98UJUvaVYKe8SUrl2tCE+vp96aZZW/nnF5yAkbaPylOKcHUo3zt2HwZrPlBXrnF gka7RE+Fp/AufxJAyk2LNjmj4uudwihULqlNH202qvtG+kIanpxYcFxF16T33eQ4qqY+yFwRFzuLv 5sGIvk6M0oqMD2f7JrRPagZ4biMs5YySn2r1chp6DMontO9CM3YeHyKLojwWDN38W/EI/FBiM8rwK lf3eDzIQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdcGz-00000001a0D-25E1; Mon, 12 Aug 2024 21:08:13 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdc2W-00000001WMp-1ZJi for linux-arm-kernel@lists.infradead.org; Mon, 12 Aug 2024 20:53:17 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-665a6dd38c8so103124837b3.1 for ; Mon, 12 Aug 2024 13:53:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723495994; x=1724100794; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=DuUqrCWF/xHWcFuXKlPjIWucc9/NhZLN0OsUooYWUjg=; b=bdMfrft1MAfsZdyvOXKw5oZ3L+PtgLqNW5b+5wfzbZ3kYHZArGiyRQmolI74RPDNAl 4gN7cF2M+pWsZBJOyTnH278BzmKR8pOWtMGspersr5gK2Mmw7qIeprtnj4FFA4dlsUHk Qp6IPtknuPRDRuSmuCggAXJCatXFPCjvJB9DLenVAfDlCN/5ZRBcnHr3Dzt8+zRZAjJq x1uYPHc6W/DkAswkHpvN1WydSmtnij0zR7aUOPYuVpS6IQyIsEtFW9FTDEwg9wDeVECF bs3xZsnrUJr7yQT16Dq+XnOhSObeLYxYgeMeE7qXpDKaVVoYdbyuEveGHF2PYdPgUHvh PnaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723495994; x=1724100794; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DuUqrCWF/xHWcFuXKlPjIWucc9/NhZLN0OsUooYWUjg=; b=ZcTiAvs4+PuOzxgobj7JDq5AbGu+m+41yIlgazm+AbAy7M36nfSkabQ2zCQ7iwc0r9 Bx5DZK8Ez2Y5yXJvn71fPRI0BpymQPZqfoYNg9XubdKuw8Md8GgU1YOTweg1a75RovPE WbqWS4qm7YVOBpq+bIB4QE2NSqzp8y1fEY7Opi/wAqAfI7KsC2XMKTxtqhHFNw1EA5Hl H7piBVwgw78sBEw53nrvhiEd8NPqhdk1i2W21RJz8bxvGQMzIgriofQUhfRyg/WfNyuY 1PcvnIisO7YMtA7eC5Vh3NmC/fvYqAUZ5bxeE91yCGZpamg1VHWIH23FGmW09x5AxYQD CANQ== X-Forwarded-Encrypted: i=1; AJvYcCVYNczobS5Uk1WFYL1+p0tTaDv16Dqn1TBpDmHyP3Hfera0xTSqHZJCxNEXYPI7/qvGZV2o0g3m78rVoP9XI89Ue3yJO8m3WVcNFyvOy9uaeRe0hic= X-Gm-Message-State: AOJu0YwXCy85Yysv/MOcDywSJ7axvhQ9+JiM+nJZKrg7x5t99YOnKssI Sp/it+q43z/6U2ZJAgueLoB2cSJow+8MSBKuI4ALAjrqGXckws1usj/FcIf8M3yHiVYGnd0qViA 6dE9BlowCKw== X-Google-Smtp-Source: AGHT+IENy8kvftAeMsPnXaFLGnElxbpTX8pP3lf5fKRnJiwZqy3MmYbMOT7IN0Eau0daUlvYKEg/llpPkpn9+g== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a25:aa46:0:b0:e0b:d229:af01 with SMTP id 3f1490d57ef6-e113ce919bdmr1758276.6.1723495994572; Mon, 12 Aug 2024 13:53:14 -0700 (PDT) Date: Mon, 12 Aug 2024 20:52:55 +0000 In-Reply-To: <20240812205255.97781-1-smostafa@google.com> Mime-Version: 1.0 References: <20240812205255.97781-1-smostafa@google.com> X-Mailer: git-send-email 2.46.0.76.ge559c4bf1a-goog Message-ID: <20240812205255.97781-3-smostafa@google.com> Subject: [PATCH 2/2] iommu/arm-smmu-v3: Report stalled S2 events From: Mostafa Saleh To: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, will@kernel.org, robin.murphy@arm.com, joro@8bytes.org Cc: jgg@ziepe.ca, nicolinc@nvidia.com, mshavit@google.com, Mostafa Saleh X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240812_135316_466936_11038688 X-CRM114-Status: GOOD ( 20.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Previously, S2 stall was disabled and in case there was an event it wouldn't be reported on the assumption that it's always pinned by VFIO. However, now since we can enable stall, devices that use S2 outside VFIO should be able to report the stalls similar to S1. Also, to keep the old behaviour were S2 events from nested domains were not reported as they are pinned (from VFIO) add a new flag to track this. Signed-off-by: Mostafa Saleh --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 18 +++++++++++++----- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 2 ++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c index 8d573d9ca93c..ffa865529d73 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1733,6 +1733,7 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) u32 sid = FIELD_GET(EVTQ_0_SID, evt[0]); struct iopf_fault fault_evt = { }; struct iommu_fault *flt = &fault_evt.fault; + struct arm_smmu_domain *smmu_domain; switch (FIELD_GET(EVTQ_0_ID, evt[0])) { case EVT_ID_TRANSLATION_FAULT: @@ -1744,10 +1745,6 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) return -EOPNOTSUPP; } - /* Stage-2 is always pinned at the moment */ - if (evt[1] & EVTQ_1_S2) - return -EFAULT; - if (!(evt[1] & EVTQ_1_STALL)) return -EOPNOTSUPP; @@ -1782,6 +1779,15 @@ static int arm_smmu_handle_evt(struct arm_smmu_device *smmu, u64 *evt) goto out_unlock; } + /* It is guaranteed that smmu_domain exists as EVTQ_1_STALL is checked. */ + smmu_domain = to_smmu_domain(iommu_get_domain_for_dev(master->dev)); + + /* nesting domain is always pinned at the moment */ + if (smmu_domain->enable_nesting) { + ret = -EINVAL; + goto out_unlock; + } + iommu_report_device_fault(master->dev, &fault_evt); out_unlock: mutex_unlock(&smmu->streams_mutex); @@ -3373,8 +3379,10 @@ static int arm_smmu_enable_nesting(struct iommu_domain *domain) mutex_lock(&smmu_domain->init_mutex); if (smmu_domain->smmu) ret = -EPERM; - else + else { smmu_domain->stage = ARM_SMMU_DOMAIN_S2; + smmu_domain->enable_nesting = true; + } mutex_unlock(&smmu_domain->init_mutex); return ret; diff --git a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h index 0dc7ad43c64c..f66efeec2cf8 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -745,6 +745,8 @@ struct arm_smmu_domain { spinlock_t devices_lock; struct mmu_notifier mmu_notifier; + + bool enable_nesting; }; /* The following are exposed for testing purposes. */