From patchwork Fri Aug 16 12:59:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Mostafa Saleh X-Patchwork-Id: 13766257 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 101BAC52D7D for ; Fri, 16 Aug 2024 13:00:10 +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-Transfer-Encoding: Content-Type:Cc:To:From:Subject:Message-ID:Mime-Version:Date: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=jUuRruggY6sGV8WBcDN0bfpHup5Gn81C3NBKfiCKxF8=; b=q3j2mV3o00hCNJmzkJXT+lVZK2 4LjWyA5qaYcaZHbaSVCjCBnewuG2Ur+LLeGEPtL8gR+WI5JB91WmwdRaDNTQJIJ+RBK1ktM9tms1V oYqFvm2DsnLLE2h/jCMbJQu8Yq9myLp2tseOOdZxQT0SfcLPvE1OyJ1X5tICu6REdrRAyDltsmFE1 riXf4u+tdbSs6ovHjCrRwbO8E6NYMLb+fYXDcg7whyBbMlbR7yCukHIg/0gwEgTpjrXKSC2l0FAcd 25FIlDdrQ53ZQFMmB8Gtx7A6dzF1S4BfLCxR+q/PUy6UHo9qSRAUiXUPONL8C0z3otQoZuYl9fXTf wwH45QIw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewYf-0000000Cyp0-3Ywk; Fri, 16 Aug 2024 12:59:57 +0000 Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sewXs-0000000Cyid-25Xz for linux-arm-kernel@lists.infradead.org; Fri, 16 Aug 2024 12:59:19 +0000 Received: by mail-wm1-x349.google.com with SMTP id 5b1f17b1804b1-428ea5b1479so14212145e9.0 for ; Fri, 16 Aug 2024 05:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723813146; x=1724417946; darn=lists.infradead.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:from:to:cc:subject:date:message-id:reply-to; bh=jUuRruggY6sGV8WBcDN0bfpHup5Gn81C3NBKfiCKxF8=; b=DQxc71T5i3UiZWKSqSeX4dvlEyyIhcTqJD/5D+XQdR2H+QdQhUMgEnUiEeGD+NhaLS lZFrPT+b50A1SVmY9N37A27FghrXTgZZdOTwzVblkrLsXA0KSglusSjdgGRRCOKZD5RJ GwiEiAkwpF6nOZQDIFNfAvVU/5X8CBXDM4vGYpVlKJRstRU5p5ms0+DOAz5/b5lD8+jb e8Q1uLy6BIHpD5LBVdC5aQptmg3usUK7lM5cEFtXfObY5hUaZvC6K7/OYjOqjv35KrGb ThraxArZYIf5T8h7hOIAmJ8Vb0eYBrMcoYvDMvV3pPp+PPNRNIf5G0dpC0X7gPmnE5C2 C2Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723813146; x=1724417946; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jUuRruggY6sGV8WBcDN0bfpHup5Gn81C3NBKfiCKxF8=; b=NSrMvo4kz+437Edc2NOSg/vJBvwq4fjMbtPUEFRdm29x4L3I94qvRss+474xiXFunB QNRFbyJcJQL4ARLvmhPWT4L8m/RJBxQvlAYJ/Dd40h+jCiafM94WKZjXUmo3NErWw8pJ 7sgMxwZu9VMA5zTycesjqR3XTHYOOSYBsVyvPtpPfPLPOug6/rnMEwdUnWkRBUYJ3FfA BnBzJxZ0lqf3Tfqe1n7ROPSHVlNYTe8YY1Ef8l45FFKH+2dm0JzepXo6Q+mHzV40525j DN+rvgtx1aHWxLpzQSjOmdbPK9glDz2o5FQMvi8wWVUkfYr3p7HDAnYRaL34edk59jkl BEgA== X-Forwarded-Encrypted: i=1; AJvYcCVwQ9uAWB29pIwVyoKqnx2DcRZRK3Cd4Fef9fosROwxR4R0XGE4LItfahi4beDxtQL45eIr8IxcdnsONgdPFVgVV5byg+3gAEh8zb/o2Je0qB9tN1o= X-Gm-Message-State: AOJu0YycfRN3dU0QsuASeX+3/W14j06Ip8BqNFcg5hCsZS6DVtzZoBge EunM7GVZZ//wR2JBkmjgDU5yzMWO6wBvuwrI+IwCJQ/Vvjr1kGaxV1b5fNdJPsy7pfKXem9AksZ jANDD1hM0tw== X-Google-Smtp-Source: AGHT+IF3c31cZ4DPn0r2ni2UeKQVM2zXgvvKXtpEYOooEILBNhmH81y68JJGWiAdVf4AXsSFddC/hPe/MlToXA== X-Received: from mostafa.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:333c]) (user=smostafa job=sendgmr) by 2002:a05:600c:6b08:b0:426:5c35:ffce with SMTP id 5b1f17b1804b1-429ed7d68bfmr186365e9.6.1723813145790; Fri, 16 Aug 2024 05:59:05 -0700 (PDT) Date: Fri, 16 Aug 2024 12:59:01 +0000 Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.184.g6999bdac58-goog Message-ID: <20240816125901.3773388-1-smostafa@google.com> Subject: [PATCH v3] iommu/arm-smmu-v3: Match Stall behaviour for S2 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: jean-philippe@linaro.org, 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-20240816_055908_560353_F3DE3931 X-CRM114-Status: GOOD ( 16.17 ) 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 According to the spec (ARM IHI 0070 F.b), in "5.5 Fault configuration (A, R, S bits)": A STE with stage 2 translation enabled and STE.S2S == 0 is considered ILLEGAL if SMMU_IDR0.STALL_MODEL == 0b10. Also described in the pseudocode “SteIllegal()” if STE.Config == '11x' then [..] if eff_idr0_stall_model == '10' && STE.S2S == '0' then // stall_model forcing stall, but S2S == 0 return TRUE; Which means, S2S must be set when stall model is "ARM_SMMU_FEAT_STALL_FORCE", but at the moment the driver ignores that. Although, the driver can do the minimum and only set S2S for “ARM_SMMU_FEAT_STALL_FORCE”, it is more consistent to match S1 behaviour, which also sets it for “ARM_SMMU_FEAT_STALL” if the master has requested stalls. Also, since S2 stalls are enabled now, report them to the IOMMU layer and for VFIO devices it will fail anyway as VFIO doesn’t register an iopf handler. Signed-off-by: Mostafa Saleh Reviewed-by: Jason Gunthorpe --- v3: - Set S2S for s2 and not s1 domain - Ignore ats check v2: - Fix index of the STE - Fix conflict with ATS - Squash the 2 patches and drop enable_nesting --- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c | 5 +---- drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h | 1 + 2 files changed, 2 insertions(+), 4 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 a31460f9f3d4..d8fe16901afb 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c @@ -1646,6 +1646,7 @@ void arm_smmu_make_s2_domain_ste(struct arm_smmu_ste *target, STRTAB_STE_2_S2ENDI | #endif STRTAB_STE_2_S2PTW | + (master->stall_enabled ? STRTAB_STE_2_S2S : 0) | STRTAB_STE_2_S2R); target->data[3] = cpu_to_le64(pgtbl_cfg->arm_lpae_s2_cfg.vttbr & @@ -1739,10 +1740,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; 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 14bca41a981b..0dc7ad43c64c 100644 --- a/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h +++ b/drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.h @@ -267,6 +267,7 @@ struct arm_smmu_ste { #define STRTAB_STE_2_S2AA64 (1UL << 51) #define STRTAB_STE_2_S2ENDI (1UL << 52) #define STRTAB_STE_2_S2PTW (1UL << 54) +#define STRTAB_STE_2_S2S (1UL << 57) #define STRTAB_STE_2_S2R (1UL << 58) #define STRTAB_STE_3_S2TTB_MASK GENMASK_ULL(51, 4)