Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1676677rdb; Sun, 8 Oct 2023 21:13:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGpuV+PPor8E/qD9qXieO04y6u9uFHGiTT74y1PIQ27KEmKlin0b9gbhneDYjx4xP3/leOc X-Received: by 2002:a9d:6d03:0:b0:6bf:3f4:3edc with SMTP id o3-20020a9d6d03000000b006bf03f43edcmr14767054otp.22.1696824833276; Sun, 08 Oct 2023 21:13:53 -0700 (PDT) Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id v185-20020a6389c2000000b0055c7eb53d7fsi9185428pgd.584.2023.10.08.21.13.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 21:13:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XCeoyQUR; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id BB1628046CB6; Sun, 8 Oct 2023 21:13:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbjJIELo (ORCPT + 99 others); Mon, 9 Oct 2023 00:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjJIELm (ORCPT ); Mon, 9 Oct 2023 00:11:42 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 639BFA4; Sun, 8 Oct 2023 21:11:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696824701; x=1728360701; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=nvhuzyNdwLc5+D4oED4GJfr2ND5Kg70Tbyyr4BYBz3g=; b=XCeoyQURQ1JE/Y+c3BFCGadcdTTyI2tb8BVe18xAuNTdVLOL1VQnJvk0 bQaO/mXBpjuE/Qlw9as79Ye0qXI8fn/ao9UFZQM1Qm1RHZ0uAf9i+R3YV X5Sdf6yTJbhvuL5sYGejcKxrXu2eGp6V9DYRKcgdCKiehwhgWvXbsAgjB Dpdfwz4I9dIJztLeKU3v+hGy/YJC/dm48+p4v0Ke0Vp4IoAkVOBEEL3sP zp7SI3RmaVOwA1CdKx6XfTkot3kD1UfJ6CK+06oyqZTCZ/T4ENJ9+pRmf BctO/IJm3u79l0t70zTyKUrAS7ujNzHHAzE12NPqNL0RVWb7GHK8b6pe6 Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="415055706" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="415055706" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Oct 2023 21:11:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10857"; a="729526838" X-IronPort-AV: E=Sophos;i="6.03,209,1694761200"; d="scan'208";a="729526838" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga006.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 08 Oct 2023 21:11:39 -0700 Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Sun, 8 Oct 2023 21:11:38 -0700 Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Sun, 8 Oct 2023 21:11:38 -0700 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (104.47.58.101) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Sun, 8 Oct 2023 21:11:38 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=csQwXQQ1vwUjN5sshNubVMBKgtl6utVwfkKgfQQt3yHqZtsNmdQ6FjoBZbcuVycWa6Lxv+mr61twiP+ff29sBj5b1zK7Zw4XwzR1T/3KiqS3M+uI7dCuGcib4p8ibZhOtoSH3dkKh1L9DMglOeEOlBZeepw8JN1uKv9/rrSeOiL1FZd+dpwymZ3oH8R1PIw2Kb92GtSX7KRCfevXr1+d9hybM/UKcclswQYWGiF2GHljGMcPgKX5Ap545DDr7ROaBYIXJMcGnZ21Ba7lIEcLIFC7WMn4//E2zWKnaW56Yo1gG7MYHGPbCBpkJH/mnpwqpLa/9fT9d85g47G23KhF0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=pAEQHxUi/2UxlqSB4rRADu/SE+uqf5jAi94tCW/+lh8=; b=fI0Yx8c9vA8zj769CSFzIUyj/u7nL5urr81DN1biK1n1/VnzqG9mragfDZ+JOqU+Z7AqW5ToDSKQAi/ewJuo2RcdtQTqaCdTDqRRfcL1SPUHDDOXksYTWq4UEQ6+4coWc1hxfD+DH8BY2kyL7hnHJqW3N/xTXVy/QM4fNMTOAP9SppCX8fWcg14cRyoQmu90uf9L3EfLUhxN9jKPHwOFvo8GVULOHucLbl93voACPimsYP+bsEKpOp77HXzZEHXrF6c5E0ey7PVeQyg3GgoeZL3T+c7eqNIoBOMm9CyAyp1cs0HazhPTjLV6csc90WHnVaV8+wf+YSctMswzrp5etw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS0PR11MB7529.namprd11.prod.outlook.com (2603:10b6:8:141::20) by SN7PR11MB7114.namprd11.prod.outlook.com (2603:10b6:806:299::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.38; Mon, 9 Oct 2023 04:11:36 +0000 Received: from DS0PR11MB7529.namprd11.prod.outlook.com ([fe80::f8f4:bed2:b2f8:cb6b]) by DS0PR11MB7529.namprd11.prod.outlook.com ([fe80::f8f4:bed2:b2f8:cb6b%3]) with mapi id 15.20.6863.032; Mon, 9 Oct 2023 04:11:36 +0000 Message-ID: Date: Mon, 9 Oct 2023 12:13:52 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0 Thunderbird/102.13.0 Subject: Re: [PATCH v4 03/17] iommufd: Unite all kernel-managed members into a struct Content-Language: en-US To: Yan Zhao CC: , , , , , , , , , , , , , , , , , , , , , , References: <20230921075138.124099-1-yi.l.liu@intel.com> <20230921075138.124099-4-yi.l.liu@intel.com> From: Yi Liu In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: SG2PR03CA0102.apcprd03.prod.outlook.com (2603:1096:4:7c::30) To DS0PR11MB7529.namprd11.prod.outlook.com (2603:10b6:8:141::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR11MB7529:EE_|SN7PR11MB7114:EE_ X-MS-Office365-Filtering-Correlation-Id: b35ab208-835c-4390-9b1a-08dbc87dd42e X-LD-Processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x9I51Pn8Ntf0kgvdAGkmUNOIS8wg3aG8WH7oMR5BsCpiJSL4gTMF/LfFBpa4fw5TpqEpM92N+tcF/4xaRdAHppWuYAWhj2OwRCZ0EKuW/KfeDyVdwvVdAA07y76KaNMeoERIzu6G4UEph8llcHFSNmwT0lF9G8NhYfPectkZYPcbEWWx8JNCAN8C+skbMis5lf0v4lP8ihxwuJ3DbZkSZcCSIBFbBCXqpPGCLNDSGcqwe/8a7x1KH0vjKf1jFELF1j9q3lWOLYYXvvcqVSUiC4PvRdjSJtHJrINSOzTgZ23ZnpYJgR6VxoWeStLT8tT87krAsB4MTt+bC3L0+JxUhnXbNRn3bXaOuQ9kZIEwBBJCl3MHLk5y3uclhCHPXNsG36m0M5/ry52t4bPm6yd6MZ4gyVIGsfHNUiK0DQ29+QHbXgfaQAd50pvGUrjavDfbsU1++EcEqNGDUYfb9Pj2SQjgItaVuVpvA41CR1VLgHvRNPlnnzkJCLkGRgBIQyfwOWBBCyJKUmiwgjWUhBClvzIX4HnaXFj3EU3ul02jqoao0oexHVgkpohl8FNa9KDLus7Koimtt5reEabvN6tctvNdSPakBBQFHbLBEt1syqGoSiyZPOOceuNuaRIHtPB4X7M7abcBJ9X9l1llXHOZ5A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR11MB7529.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(376002)(39860400002)(346002)(366004)(136003)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(31686004)(36756003)(6862004)(82960400001)(6506007)(6512007)(7416002)(41300700001)(38100700002)(86362001)(2906002)(31696002)(53546011)(5660300002)(83380400001)(4326008)(8676002)(478600001)(6486002)(2616005)(26005)(8936002)(6666004)(66476007)(66946007)(66556008)(37006003)(6636002)(316002)(45980500001)(43740500002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aCtDL3BEMUxCYlJYSHh1cy9GaDN4S05TYmdBTmtNMElqYTgrRC9ac0Y3S2ZQ?= =?utf-8?B?UGpVVVk1WGN0ZXZCQWVXV0tIMHRuRzlPNTR0U29BSGJETm14N1dwZ0FBMmJZ?= =?utf-8?B?b3VzYjlzZGlva0dWWUx0RHBuUEc5bDlzY1pmNzE3d3hIN3FLVUJNRGdibEJ0?= =?utf-8?B?VU9IME1XM1FaWUZqVDVaR21WOFh5NWIwLzNLSk44aXltak0wY0xmR2xNYlFR?= =?utf-8?B?WHkvekttTTNRYjdDejFLMVYxNGplRHo2bU1wMWtmb2dxb09pU09ycEdWV3Nq?= =?utf-8?B?L2lVYThaV2JiazBsampxQ01sckNvdmE2WHgxd3Z6V1NuSmZUMHZIZjNQRUow?= =?utf-8?B?bnVqNmc4UHhIS3ZWTzg3R083Qno2SjMyYjdwcHBzbUplMHpGRHljUS91OXlo?= =?utf-8?B?bHlhU0lRaDZrMkZOL1VDMDJudmw3YytOb3NxY1YxNmhKbGV2dXVScU52Y2xn?= =?utf-8?B?TmJIMUt5M3J6SG4xeG5rVVUxQkkvTWgrWGdHZmZvQ0NhdUV1M0dvTi9RczJx?= =?utf-8?B?RDMyVkMrVjlyQTlBTzFVZHdLNG9k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4bGpzU1o0TC83S1BzQlFnWlVndGtJUHk0QkdRM3ZPNnB2bm5BZElw?= =?utf-8?B?SGtuWkdkdnQ0L3QxenFUSkZJbHo4Qm1DZUxXTVpqNVNKT0RnNCtIYmVBWG1X?= =?utf-8?B?V3FuRElXVEtWd1hqRjdPOXJidmUvTWZxdWJnbkE0L3J4SHZSZUdXMVV0OUFt?= =?utf-8?B?LzlmUDZQbWIwcmQrZGN0UWVQQ0RBdkVhdHdvUkxEcDJkb21WWHQzdVZ4SWVn?= =?utf-8?B?TjRmeWNwYkc4Qnp0TlR6YjB2YVdINVpkOFczbUtuZ3NrblpyY2dST2VNbFA0?= =?utf-8?B?S0c5VVpwQUp1ay8zZWlqUy9LZ0ViZk1VZVdTRkxyVld1SEg4SEpNb0JSa0g1?= =?utf-8?B?WUFPTGpXQ0h2eHRlTFNtTGJnOGUyNjJOMU9SRTZMOFdta0tERHVjWUpiREFm?= =?utf-8?B?bkMrVVFXY3R4U0plS2svUzlXeGR3a0ZkMEplRk9lbVhMcGZWd3prWUJOeVlr?= =?utf-8?B?eGpTd2wvOHlwdDlWSEJjMk84WnZqQlBDZFIrY09maDZ0ZlZzeDUwTzUvRUZ0?= =?utf-8?B?K3JLZ2VXbEJWazRSMDJCTnlRTzBqUU9qR1VETGdwaHVjSHZFSnFxelRQemgx?= =?utf-8?B?MGNiN2NpbURGbUwvYnYzR2xkY0tlWVZxSzEvY1lURTkxZjhCQkMybFo2UUda?= =?utf-8?Q?2PQnfI1nJ0tEhLQogTMsEfwI5?= X-MS-Exchange-CrossTenant-Network-Message-Id: b35ab208-835c-4390-9b1a-08dbc87dd42e X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7529.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Oct 2023 04:11:36.7137 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: At4GbO5D1x1++53nIPbmJUcz0HzGkFcVHnsPR99S1w9Qp4icPdXm9r1IpiFSEUtHg9/VupHy0tkVPAmk35Do0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN7PR11MB7114 X-OriginatorOrg: intel.com X-Spam-Status: No, score=0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Sun, 08 Oct 2023 21:13:51 -0700 (PDT) On 2023/10/7 18:08, Yan Zhao wrote: > On Thu, Sep 21, 2023 at 12:51:24AM -0700, Yi Liu wrote: >> From: Nicolin Chen >> >> The struct iommufd_hw_pagetable has been representing a kernel-managed >> HWPT, yet soon will be reused to represent a user-managed HWPT. These >> two types of HWPTs has the same IOMMUFD object type and an iommu_domain >> object, but have quite different attributes/members. >> >> Add a union in struct iommufd_hw_pagetable and group all the existing >> kernel-managed members. One of the following patches will add another >> struct for user-managed members. >> >> Signed-off-by: Nicolin Chen >> Signed-off-by: Yi Liu >> --- >> drivers/iommu/iommufd/iommufd_private.h | 17 +++++++++++------ >> 1 file changed, 11 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h >> index 3064997a0181..947a797536e3 100644 >> --- a/drivers/iommu/iommufd/iommufd_private.h >> +++ b/drivers/iommu/iommufd/iommufd_private.h >> @@ -231,13 +231,18 @@ int iommufd_vfio_ioas(struct iommufd_ucmd *ucmd); >> */ >> struct iommufd_hw_pagetable { >> struct iommufd_object obj; >> - struct iommufd_ioas *ioas; >> struct iommu_domain *domain; >> - bool auto_domain : 1; >> - bool enforce_cache_coherency : 1; >> - bool msi_cookie : 1; >> - /* Head at iommufd_ioas::hwpt_list */ >> - struct list_head hwpt_item; >> + >> + union { >> + struct { /* kernel-managed */ >> + struct iommufd_ioas *ioas; >> + bool auto_domain : 1; > Will iommufd_hw_pagetable_put() also be called on non-kernel-managed domain? yes. > If yes, hwpt->user_managed needs to be checked in iommufd_hw_pagetable_put(), > (e.g. as below). > Otherwise, this union will lead to hwpt->ioas and hwpt->auto_domain still being > accessible though invalid. not quite get this sentence. > > static inline void iommufd_hw_pagetable_put(struct iommufd_ctx *ictx, > struct iommufd_hw_pagetable *hwpt) > { > - lockdep_assert_not_held(&hwpt->ioas->mutex); > - if (hwpt->auto_domain) > + if (!hwpt->user_managed) > + lockdep_assert_not_held(&hwpt->ioas->mutex); this is true. this assert is not needed when hwpt is not kernel managed domain. > + > + if (!hwpt->user_managed && hwpt->auto_domain) actually, checking auto_domain is more precise. There is hwpt which is neither user managed nor auto. > iommufd_object_deref_user(ictx, &hwpt->obj); > else > refcount_dec(&hwpt->obj.users); > } > >> + bool enforce_cache_coherency : 1; >> + bool msi_cookie : 1; >> + /* Head at iommufd_ioas::hwpt_list */ >> + struct list_head hwpt_item; >> + }; >> + }; >> }; >> >> struct iommufd_hw_pagetable * >> -- >> 2.34.1 >> -- Regards, Yi Liu