Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5653876rwl; Tue, 21 Mar 2023 23:51:53 -0700 (PDT) X-Google-Smtp-Source: AK7set9Y/jecv6uISSn0SBUJDTP9QFMwIchg9O8SPnKV6Zhp1BuH6Ud/fVY68reNLFF0nuFshaL9 X-Received: by 2002:a05:6402:4cf:b0:500:5627:a20a with SMTP id n15-20020a05640204cf00b005005627a20amr5493519edw.25.1679467913358; Tue, 21 Mar 2023 23:51:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679467913; cv=none; d=google.com; s=arc-20160816; b=vCoeuHX5GZ6qnpTijt1oPIyqsAyaidJKsFCbVyZmiDqmNplPvojJwJUSBm/u4TxLSx xr9Dnb7bKb/ONd89yWs4yY65miKjxd3ayc45IDhyhpQTurz8sVKKyPa1iIPUU0BcbjCZ 0Xuw5IHNvbRliln7G3PC8aHAP+afuDVBcGRkA8Yl/KhNuIJtDJ56pxHEm2YPyYA31MdT YvFr5FXxhb+0fSu8FU362Bk+20gTIIyevCQnhsYicOcnwZ9rsl56FFl8I4TIbtr8CDly i26/Q25/XaByZWBF+ULPcELuDEFzJ+t0mvxLeFyqDp4FAxwJT7K3D/5DaPYY1EbLhiz8 3f7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=soezcZGbrlFibjZCu0gwk+atehyIu3N18e2OSBae+80=; b=lkIavKEXqKuostpJ1t4X8I2tg3/jxXwbmKHtRd8zwCFW102BacRia5X14lk7B+RWAG XVY4806p/1IgPPyuJw6I6J5zxe0g/J152x2bUUmExCQCHgjavlqk4oIsoxOJ5OX9dl84 obGxpAUmbK8ZXOwVQA3WfI0g117ifOTDdqnNbb9uZMOcQmsI2Vw2fua/kEghk4OFchOs g3gCTaWtNjSTlcv5dcAhTXszUCzKffWvbQrS3zSrKcpH4oCbBBiI97hgPrEskoNKL4VH 8r5o6trZI4Q8AktDbe+mif/kt39rF9oP7h7sdzy02rkVAoco5crkkEOH+GPkflhAyhoE iowA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=G1AHZcJy; 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=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c13-20020a056402100d00b004c36e3d5147si14873939edu.209.2023.03.21.23.51.29; Tue, 21 Mar 2023 23:51:53 -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=@intel.com header.s=Intel header.b=G1AHZcJy; 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=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229657AbjCVGtk (ORCPT + 99 others); Wed, 22 Mar 2023 02:49:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbjCVGti (ORCPT ); Wed, 22 Mar 2023 02:49:38 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C86324BC1 for ; Tue, 21 Mar 2023 23:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679467777; x=1711003777; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gRhStfg9t6nkENeHZY+SE3iSs1PqWpgT2M5EEBCNGo8=; b=G1AHZcJy0sn+EKAZQlU0kRSGxby0PyYUZ3kglF8lFc4XU0eSAiJgd1BT MdhfsC2ktvJoFu/6iQhsdS0/PzUnIvZZfde+218UwVMAkTFtVQ5+lsWe1 SlVLTWQoH+M4NBvhyWK8wRsnMb/BjrTgwwM0UqQwvQohuGL38P5xWwZH3 Fzxg0RPMxOlg+Ljyn04HOkJT54ZmJQz8h5Vua6hPcBnRAxsba2aVT3f6J 6sw/BmWWcupRH8yT5WmzBtu7wan0CC17TPoLTQ/hleSrgjeZ3qbLfpQLF DvrtKpPGsS1KvOqBz9FBUXwzRJSR4viNPN+j8h68s1P9KmtnHhuNMKcXK g==; X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="337866717" X-IronPort-AV: E=Sophos;i="5.98,281,1673942400"; d="scan'208";a="337866717" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2023 23:49:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10656"; a="659080360" X-IronPort-AV: E=Sophos;i="5.98,281,1673942400"; d="scan'208";a="659080360" Received: from allen-box.sh.intel.com ([10.239.159.48]) by orsmga006.jf.intel.com with ESMTP; 21 Mar 2023 23:49:34 -0700 From: Lu Baolu To: Joerg Roedel Cc: Jason Gunthorpe , Robin Murphy , Christoph Hellwig , Kevin Tian , Will Deacon , iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH v4 0/6] iommu: Extend changing default domain to normal group Date: Wed, 22 Mar 2023 14:49:50 +0800 Message-Id: <20230322064956.263419-1-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.4 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=unavailable 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 The IOMMU group sysfs interface allows users to change the default domain of a group. The current implementation uses device_lock() to make sure that the devices in the group are not bound to any driver and won't be bound during the process of changing the default domain. In order to avoid a possible deadlock caused by lock order of device_lock and group->mutex, it limits the functionality to singleton groups only. The recently implemented DMA ownership framework can be applied here to replace device_lock(). In addition, use group->mutex to ensure that the iommu ops of the device are always valid during the process of changing default domain. With above replacement and enhancement, the device_lock() could be removed and the singleton-group-only limitation could be removed. This series is based on v6.3-rc3, and I also have it on github: https://github.com/LuBaolu/intel-iommu/commits/iommu-sysfs-default-domain-extension-v4 Change log: v4: - Whole series reviewed by Jason. - Robin suggested further simplification of using arm_iommu_release_mapping() directly. https://lore.kernel.org/linux-iommu/7b248ba1-3967-5cd8-82e9-0268c706d320@arm.com/ - Rebase the whole series to v6.3-rc3. v3: - https://lore.kernel.org/linux-iommu/20230306025804.13912-1-baolu.lu@linux.intel.com/ - "arm_iommu_detach_device() is a noop" is not entirely right. It is used to make the iommu driver stop using the domain that it is about to free. It cannot be a NOP or it is a UAF. [Jason] - Use Jason's new arm_iommu_release_device() proposal instead. v2: - https://lore.kernel.org/linux-iommu/20230217094736.159005-1-baolu.lu@linux.intel.com/ - Use group->mutex instead of an additional rw lock. v1: initial post - https://lore.kernel.org/linux-iommu/20230213074941.919324-1-baolu.lu@linux.intel.com/ Lu Baolu (6): iommu/ipmmu-vmsa: Call arm_iommu_release_mapping() in release path iommu: Split iommu_group_remove_device() into helpers iommu: Same critical region for device release and removal iommu: Move lock from iommu_change_dev_def_domain() to its caller iommu: Replace device_lock() with group->mutex iommu: Cleanup iommu_change_dev_def_domain() drivers/iommu/iommu.c | 273 ++++++++---------- drivers/iommu/ipmmu-vmsa.c | 14 +- .../ABI/testing/sysfs-kernel-iommu_groups | 1 - 3 files changed, 130 insertions(+), 158 deletions(-) -- 2.34.1