From mboxrd@z Thu Jan 1 00:00:00 1970 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 43ECCC52D7B for ; Tue, 13 Aug 2024 13:44:18 +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:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From: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=9Cu6yfPujhw6fB1N8lInQ2Ql6fk98oC5gSkan91gIQ4=; b=wrPsEgKJ+Th+qXgZysQINq3rAT JOnLCmEyOVr/oJor8sxVXoT63P+hz8ZM24d2LQgJk4DIx8GpLzZck+/BHmYPr+tsduvUbysry16rU mxvR4VMvvus3Rno9b2VulRz/o9WOmSsGkNlJw5Hd0ifFYumWwtqnVjAJmfP/Ie6krEhemdRnQFal1 Br1zAbZhBbU95gdED5RuNHjkTwA/T9ftFheSuscuDCwUGGkdy480la6qdnNPnOn/OUx6UxwUAV6dQ au3XtC9q8nzkosPaORNrdrvbBeLgHRmZbJgDYkQIvbIcbeugIZb5Xh9xAywOisEIm42ceFU/4QRkP nHw+nzMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdrom-00000003vC6-2NRD; Tue, 13 Aug 2024 13:44:08 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sdro9-00000003v6o-1Npa for linux-arm-kernel@lists.infradead.org; Tue, 13 Aug 2024 13:43:30 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-42807cb6afdso26445e9.1 for ; Tue, 13 Aug 2024 06:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723556608; x=1724161408; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=9Cu6yfPujhw6fB1N8lInQ2Ql6fk98oC5gSkan91gIQ4=; b=vIk/o0SGZy0LEm/xrI0gp2rEQXfczUZGUq/Hy8x2Zsje3D36bAxZ0X/4wtlSUsDGFO 72cSWHNsDpg0W/K0nzLmUrQP39aW4oU8QQCBVdK+m8aD25iVYtHVvqNjXM87lE3So2DL mPP/PG/WOVe71aFr9VaYKirplZAcir+TtxMKy+P3Riv0XSRNo7Aq0rNO44eqwARtjAyI pNqHAJhjdnr2k83o2YWzaVek1gI5/zAf03sJ5jR8LpouZyM2illEfvahCmHcaG0xznFt rxOXOHcc+BVd3swEf5L2thLAoWlmp9QRXn5iTF70kcyxqNOk8XgjVzmR8WSoeWc8wmTL p/xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723556608; x=1724161408; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9Cu6yfPujhw6fB1N8lInQ2Ql6fk98oC5gSkan91gIQ4=; b=n+IkTAPjbMJ0CF6vSshlTHWCgMV++LGcnBBwgHsa/giriQ5hS9c6VHe7CE+gpoCz9h epLU/S87BIz2lKBkvRLZjmtcjtm83f70oF2IZlZbMri7CVl3rmtRSstXNqzMhO9iSCmz /CKV7kgNAA9rDDpFO4R6PZxpPWnQbhxRUgM7vt5mO51LMcpXUEp6uY3K0IEstSNkWiFp vCC9nRzC362opgqZWBfCRwNWfrgvq7l4xWWclUP+cubTadxiXhSd4RsAw/vkiB1Z1PMg n+NeRNQk834uwX/fmi1LzNp1AM31jVlZAPu+984Xa4CwIsTuJ7edqzHV4TUMGyrTp6PW 6uTg== X-Forwarded-Encrypted: i=1; AJvYcCWtZ6IZwq6ArFQ6V34obDGfNTqphsFyD+BN8lkG/JfZXEaufNkrDyoqdcD66CGx4LKYtfw/oRfBOpJfJ1mIvRwv@lists.infradead.org X-Gm-Message-State: AOJu0Yz0iyuQgWT/9CM/wyJjIGRtNveNr90ZnQX3SQDi4iF4g2QvMVHr AONYVF8ZCip4RceR/zY4e1JdXQuvhVWUIT4rjFvi91EkdhzvZadvxQocvR/7SQ== X-Google-Smtp-Source: AGHT+IElInwkbbsXFlvNFFwCJ3MNM6wm6OEDR1d2oK/QWIGbYtLpQJEx6Ik309H6zI76mem6/9tRTA== X-Received: by 2002:a05:600c:1d95:b0:426:8ee5:3e9c with SMTP id 5b1f17b1804b1-429d715b507mr570035e9.6.1723556607417; Tue, 13 Aug 2024 06:43:27 -0700 (PDT) Received: from google.com (203.75.199.104.bc.googleusercontent.com. [104.199.75.203]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36e4cfee71esm10255851f8f.50.2024.08.13.06.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Aug 2024 06:43:26 -0700 (PDT) Date: Tue, 13 Aug 2024 13:43:22 +0000 From: Mostafa Saleh To: Robin Murphy Cc: linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, will@kernel.org, joro@8bytes.org, jgg@ziepe.ca, nicolinc@nvidia.com, mshavit@google.com Subject: Re: [PATCH 2/2] iommu/arm-smmu-v3: Report stalled S2 events Message-ID: References: <20240812205255.97781-1-smostafa@google.com> <20240812205255.97781-3-smostafa@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240813_064329_392439_A6574993 X-CRM114-Status: GOOD ( 34.34 ) 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 Hi Robin, On Tue, Aug 13, 2024 at 12:57:02PM +0100, Robin Murphy wrote: > On 12/08/2024 9:52 pm, Mostafa Saleh wrote: > > 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) { > > Ugh, has the whole enable_nesting method still not gone away already? It should go away with Jason latest nesting patches: https://lore.kernel.org/linux-iommu/0-v1-54e734311a7f+14f72-smmuv3_nesting_jgg@nvidia.com/T/#mc5558cb88b10fcdc4b91076cf813123cac75f11d I can just ignore that here, and only remove the S2 check, and as VFIO anyway doesn't register a handler it shouldn't really matter. So, it's one line change, I can also squash with the previous patch, please let me know what you think. Thanks, Mostafa > > However, at least for now, isn't this functionally equivalent to just > testing !(smmu->features & ARM_SMMU_FEAT_TRANS_S1) anyway? We still won't be > able to differentiate a nominally-pinned non-nested VFIO domain from a > nominally-stallable non-VFIO domain on S2-only hardware. > > Thanks, > Robin. > > > + 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. */