From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B0E4353A61 for ; Wed, 26 Aug 2026 08:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787734468; cv=none; b=UkrkGLRc1UeR90l/NitWDkqaRe+vwGDbCqhjy2RGbiGmzsB+5ZuXHV4HHN34FAv+5TO1o3RiRI5IQ5J+/VgYkNC7jthXv50PepffR6JhvYflSWAgHsJYeUxSF8vXQWtNvNTLkNCo9hhhA8IEQROcn+3e1FROUdUxfaAFTmWKE0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787734468; c=relaxed/simple; bh=bl/YMALd3mQ/g2M3kVKZpJBRcUl71G7E1PaFpoMCpTE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=D0OHXXHJfR1LHEBzuaPG5hOIy81J4SpmHOLwjvqK11JnUjjQTm4nYsn+ebXjkCMwVtLWBuDQLqxTzO7SiNWohpQTDqbxvo6q1jawmqB1Vpmicld//KpdTwjZbkG5JLXh8b4FLunPHV/DlPlkO1D3PoMGO6eayCSvIMwVoFEqCCs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AszLo4H4; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AszLo4H4" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-499b1409a75so31875e9.1 for ; Wed, 26 Aug 2026 01:54:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1787734465; x=1788339265; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=GC7HaV6ubG2A4QN/tpZz7iru0oh8bNIqfpSQwQL8lBA=; b=AszLo4H4a2tW1E7zPUOV5HKXFcqa4Qg2uUoV7WktvOIhbTNeADQ5My//v6zUARx68F Six1tf6X8Pg4Eb/Z7E2q3I2TdYPYHJajohMUJ9oW2SPFEY+fsK8wwp0HCIAe0A/kYf1L E82KmquyZ2kHIhHle1srjlOgtEtCfQsjOtPfQjTA1UdxU4+1xTEqtVeAKuCBAHDDWSiT OU8moiF1k9U7G0k8UtD6l2xsUWxgXnsVyRTtco+KmMs05BvHfQwJDAZATf4+uDZAS4kI YTbUuAkSUcCnJ/brZZ2DVaSeIlPxxoH4jTjR/oj3oq3G8pPYJvn7Fiwymi00pgYr9YFe AhVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787734465; x=1788339265; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GC7HaV6ubG2A4QN/tpZz7iru0oh8bNIqfpSQwQL8lBA=; b=DbREoKwmP5wKE7EGjG3FVhbSZuDCKQYLBgsm6dEo01UE1UWKWxDXyH+NkZxVKP9Rw7 HT1ry/6GP2ncGNIOFXUK4roC1RRf3amoxQVEZF1+1QBxR80S6QuPeA1413MOcWN4bowT Pnu+exlMZcosPFpZE6J9IRAA2e8g2l7QlDtYgDFxHpIINgDdFI+pLWmzMnoVEQDxP9i7 jj46KoPA12TpYzlaQ0kN/9jY9XkALrW3bBi0vGT2Uz/JRmS4LXMsJ2BmiagBjj5PB1H2 BaXA0xsVnNCwH+8rf0nY+RQMEuWngLqGDfmDbaEpKJa0KuZNxOPQnMtmJIkYS5YFK9YS xLTA== X-Forwarded-Encrypted: i=1; AHgh+Rpq03Z+ROvHtT1O8CwKsHU7GBISBgxjp+pnfs6lyugokscwjm1S/mbSkWQ2rs51/OuZ/+KF5+FMdq31PaM=@vger.kernel.org X-Gm-Message-State: AFuF++kY/lfPvRk70veVsiAvL+A5ApYig7k3wSwemQotnQEgMjDGy81i hPsPORwOc+MWAVzRhUm/CrHTaS/U3LbKVAq9kv+FxDssOjuW/05OpINrPWk8idLIgA== X-Gm-Gg: AR+sD12xXROxM0jGrjnVkIegrvYsyqx/N4b+/dMFrciSOT8im3YFMZlJ1rw9OaP6GVO 8q5lSlquiovnDNob0sp6qZllzUoLRfYO92cj2xFfTyDSVXW7i556RN26sIbUrRLIixePmH9uNun CeUevhDPB8n83hKaPYyPk5v1pzmRxWPhO9Q0Fm5fyCJcM2gqYg/cBTpKbzBw78zasVZByhQDjrV LK0sJqBhUP8ABg1dS0s9Py7rW6WWsoWrcj3EFAXi2HQHG3kOTC0wruENGJ6A+cGMRt1GJkMZOj6 1WLzr051C2HvYJPNbeYt5vTDbSKzL3sCKzp9oj8a4Q+u0Yx0HpNttG8RaWFjFzOIQEEkkHrF4sc zjqJ1D67WLnxUOuBQHMdXdEf1jr/XgwpZFBzCdk1ubiAlBC3ex7PYjfvs8O7IYqAQZ9BwfthWuM EM2TF1lL+As8XrX83VxR7miSEN4XAODj0HLpXtSha9fctUDBriB2yYMvawk8NY9ISvbIy1ZDt7A Wx7vXbTutl2wTKLc63hvLGiz4OoCl2ZnvU6QbUj X-Received: by 2002:a05:600c:c0d3:b0:499:cfeb:4f17 with SMTP id 5b1f17b1804b1-499dda22aedmr502865e9.5.1787734464271; Wed, 26 Aug 2026 01:54:24 -0700 (PDT) Received: from google.com (250.192.189.35.bc.googleusercontent.com. [35.189.192.250]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499dcad2532sm19052725e9.11.2026.08.26.01.54.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Aug 2026 01:54:23 -0700 (PDT) Date: Wed, 26 Aug 2026 08:54:19 +0000 From: Mostafa Saleh To: Jason Gunthorpe Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, iommu@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, joro@8bytes.org, jgg@ziepe.ca, mark.rutland@arm.com, qperret@google.com, tabba@google.com, vdonnefort@google.com, sebastianene@google.com, keirf@google.com Subject: Re: [PATCH v7 23/24] iommu/arm-smmu-v3-kvm: Enable nesting Message-ID: References: <20260715115906.2664882-1-smostafa@google.com> <20260715115906.2664882-24-smostafa@google.com> <178769159057.3356902.13161185498161727294.b4-review@b4> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <178769159057.3356902.13161185498161727294.b4-review@b4> On Tue, Aug 25, 2026 at 05:59:50PM -0300, Jason Gunthorpe wrote: > > [ ... 129 lines skipped ... ] > > + ret = smmu_attach_stage_2(&target); > > + if (ret) > > + return ret; > > + hyp_spin_lock(&smmu->hw_lock); > > + cur_valid = FIELD_GET(STRTAB_STE_0_V, le64_to_cpu(hyp_ste_ptr->data[0])); > > + target_cfg = FIELD_GET(STRTAB_STE_0_CFG, le64_to_cpu(target.data[0])); > > + target_valid = FIELD_GET(STRTAB_STE_0_V, le64_to_cpu(target.data[0])); > > + if ((cur_valid && !target_valid) || > > + (target_cfg == STRTAB_STE_0_CFG_ABORT)) { > > + WRITE_ONCE(hyp_ste_ptr->data[0], target.data[0]); > > + WARN_ON(smmu_send_cmd(smmu, &cfgi_cmd)); > > + for (i = 1; i < STRTAB_STE_DWORDS; i++) > > + WRITE_ONCE(hyp_ste_ptr->data[i], target.data[i]); > > + } else { > > + for (i = 1; i < STRTAB_STE_DWORDS; i++) > > + WRITE_ONCE(hyp_ste_ptr->data[i], target.data[i]); > > + WARN_ON(smmu_send_cmd(smmu, &cfgi_cmd)); > > + WRITE_ONCE(hyp_ste_ptr->data[0], target.data[0]); > > + } > > This doesn't look good enough, a driver can't safe writely to a valid > STE in any order like this, and it can't make it non-valid or risk > breaking guests. We had this bug in linux already, the hitless STE > update in the hypervisor is mandatory for linux guests using PASID. This piggy-backs on the kernel algorithm, as described in the comment in this patch: + /* + * Summary of each host emulated state vs real HW. + * | Host | HW | + * ============================== + * | V=0 | V=0 | + * | Abort | Abort | + * | Bypass | S2 | + * | S1 | S1+S2 | + * + * For the host, any V=0 transition is not hitless, all other permutations of + * (abort, bypass, S1) transitions are hitless. + * For the HW state, any V=0 transition is not hitless, as all the S2 config is + * always the same (ttbr, vtcr...), all other transitions should be hitless too. + * However, the host is not trusted, which means that any V=0 <=> V=1 transitions + * or any transition to an abort STE we need to enforce writing order of the STE + * dword 0 and add CFGI. + * Otherwise, we write the STE in the opposite order to cover cases from abort + * to S2 or nested. + */ So this way, the hypervisor doesn't break the STE and keeps the host STE transitions hitless. Or there is an example that I missed and is broken by this? Thanks, Mostafa > > You should use the STE programmer logic from the main driver which > gets this right for every scenario a linux guest can trigger. I don't > think there is anything about it that would be difficult for pkvm. > > -- > Jason