Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp862373rwl; Thu, 10 Aug 2023 02:50:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG7KkAFNqm3GUFwBN5NYNLSuu0YrCrYYT60O10qcDDU9OXF1WKM9RcKMLrNyZGJOmGkXxk9 X-Received: by 2002:a17:907:2e0b:b0:99b:d0dc:7e68 with SMTP id ig11-20020a1709072e0b00b0099bd0dc7e68mr1527061ejc.72.1691661034491; Thu, 10 Aug 2023 02:50:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691661034; cv=none; d=google.com; s=arc-20160816; b=EE9mMhZqotCU1i40Jrcn+LfDxlrrL4/7f2mRyVaLYrJJzcDWa3jskW3wxDuHdoQXp/ yqBY5Pn/+UR2l+EOdsdwmwFi2UXcDvFvJWaN411XHb79nATeu5WqzBcEPqACIzexmJ5l y39c7w+YBK9v4UnnJfR2zLz9dD1gYVhDNldpDFRWVReklAch3OztHb9L6ZOoQwYtKsUi o/iwYTCv6Kos1e4T/GXWJ0YyRi0grIp0/Vu7Jr3TAoNSZU/EqEdSYpId7Gci1swDLKE8 3BmxSgNi7Nvz9SLHO5oy3i6JSCHF3mrmiysixtMeMW3DhUQmrniOFpXoL1D54D1wljm8 WBEA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=gpw3JUEGHiq/LD/RXRvZX688rUhVSeJWU4czgkKu7KI=; fh=t+8wUyKcQrCdL1Lrmfctd/7P6zFzoKI1W4CBYAN/NYQ=; b=AOnrj7S1OI+lYmL9+7P1zu1AW94NuoeVhzpJ58bzNG0paqmhdb0tLPVF+2WsP52ygr TWtNZRgTbMyMr8hX84Ne1YqTTjVfbzYUCaTz1fSXe3l9RNGuH9XnVnQm7eZQqSBoHwpp ydAuXZuyoJKmzNbV41gS8flT1YZ68rv+zA4roZ3liPzcrS5iHkBnNQ35FWLIY+HNDVyj Z1Mj0JC4fzsa/IrymOngCj6Sw5oG6aNk5PVxdxSJ5bjnf7Qo0b8/npD7uoPkXX6dccsB 1ET6sRHfVKrrYJFUnADr5tN3hgyg9j9AEYgUwP5eQfMzxuwkGKOS5DwTqt7UVJ63ugqf b3DQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=sJDe+JlW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a170906149800b0098859d239dfsi1227687ejc.796.2023.08.10.02.50.10; Thu, 10 Aug 2023 02:50:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=sJDe+JlW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234782AbjHJJSW (ORCPT + 99 others); Thu, 10 Aug 2023 05:18:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234778AbjHJJRq (ORCPT ); Thu, 10 Aug 2023 05:17:46 -0400 Received: from mail-qt1-x836.google.com (mail-qt1-x836.google.com [IPv6:2607:f8b0:4864:20::836]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1158C4693 for ; Thu, 10 Aug 2023 02:16:28 -0700 (PDT) Received: by mail-qt1-x836.google.com with SMTP id d75a77b69052e-40a47e8e38dso160891cf.1 for ; Thu, 10 Aug 2023 02:16:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691658987; x=1692263787; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=gpw3JUEGHiq/LD/RXRvZX688rUhVSeJWU4czgkKu7KI=; b=sJDe+JlWehpzvzJFhdHgLdsv4qfNjhJHHqrvk3Ge58DXQB5dIZAKWuWn4foxIlGqZF t0tP4a+Oab6l+4dNONjMXerEKJ4OqecQfXrINVusn4qmVI/IG4OIOuv2BZ0UBsYt8ZHv OcRbptiBTseTqranLSqqtQ2nzjK18Tq5+TFW1wuBMfelzEnCOZNPINLUBvygt7p7pdvP PvfuOwQ1h2FJVrmK898Lk1WAcowZi5/XocNQSaVAwkbfpyG7e+sFN7LZ8NAXR9paewUr nYiN8yuXrV+77fIEV4xXziGUX6iMOpo3sxTDMVT2AV2kUM7XwvDpvhpXrHIORuQwmlb1 Sytg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691658987; x=1692263787; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gpw3JUEGHiq/LD/RXRvZX688rUhVSeJWU4czgkKu7KI=; b=ika4XEYpqu/3S8HXoP+VY/QndGPYIjGCG7ZwBivhQxzH0HngWcRNFlBJcn1wNTbpEN 80UadGnr+NnjQdRfk+BcWQSt1xvpbB7XIrZPD8nkpWZyzkusahLcfCe9Uj0j2qn1EtzJ Ul1hUJhSlT4uY4/uojdNWeE+Czth6sv68bATBqox2T5W/Yr6spOQFpr0SZS6daFemT/n gno59/a64cj89v/Sd4Grg/D1lGKPQ+2Bdq7lWeScm8P7sw3Rb4uHN7mbZIVSZGa465x3 TT1Iti/iv08esoTq69P3iLWXP7hng6eJT036oyVBNQJ4lNi7GGZAWNnuIwnovUYlHsK0 swng== X-Gm-Message-State: AOJu0YwCg22fLOhRcLZbYfaF09v/4KzfP+HQBrjvC4XBvlKRf4Ei7EcS /RkXEFVC9pja9OZCtUiQ9HRGhTmN12vx2/RHNA27UQ== X-Received: by 2002:a05:622a:1802:b0:3f0:af20:1a37 with SMTP id t2-20020a05622a180200b003f0af201a37mr340765qtc.15.1691658986946; Thu, 10 Aug 2023 02:16:26 -0700 (PDT) MIME-Version: 1.0 References: <20230808171446.2187795-1-mshavit@google.com> <20230809011204.v5.5.I219054a6cf538df5bb22f4ada2d9933155d6058c@changeid> <20230809134959.GB4226@willie-the-truck> In-Reply-To: <20230809134959.GB4226@willie-the-truck> From: Michael Shavit Date: Thu, 10 Aug 2023 17:15:50 +0800 Message-ID: Subject: Re: [PATCH v5 5/9] iommu/arm-smmu-v3: Refactor write_ctx_desc To: Will Deacon Cc: iommu@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, robin.murphy@arm.com, nicolinc@nvidia.com, jgg@nvidia.com, jean-philippe@linaro.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 9, 2023 at 9:50=E2=80=AFPM Will Deacon wrote: > > > - ret =3D arm_smmu_write_ctx_desc(smmu_domain, mm->pasid, cd); > > - if (ret) > > + ret =3D arm_smmu_write_ctx_desc_devices(smmu_domain, mm->pasid, c= d); > > + if (ret) { > > + arm_smmu_write_ctx_desc_devices(smmu_domain, mm->pasid, N= ULL); > > Why is it safe to drop the lock between these two calls? Hmmm this is a tricky question. Tracing through the SVA flow, it seems like there's a scenario where multiple masters (with the same upstream SMMU device) can be attached to the same primary/non-sva domain, in which case calling iommu_attach_device_pasid on one device will write the CD entry for both masters. This is still the case even with this patch series, and changing this behavior will be the subject of a separate follow-up. This is weird, especially since the second master need not even have the sva_enabled bit set. This also means that the list of attached masters can indeed change between these two calls if that second master (not the one used on the iommu_attach_device_pasid call leading to this code) is detached/attached at the same time. It's hard for me to reason about whether this is safe or not, since this is already weird behavior... > > Since you're dropping this and relying on the lock being taken higher up > callstack, can we add a lockdep assertion that we do actually hold the > devices_lock, please? Will do!