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 X-Spam-Level: X-Spam-Status: No, score=-5.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_2 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C353C433B4 for ; Tue, 4 May 2021 22:09:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA5AF6139A for ; Tue, 4 May 2021 22:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232943AbhEDWKC (ORCPT ); Tue, 4 May 2021 18:10:02 -0400 Received: from mga01.intel.com ([192.55.52.88]:47393 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231733AbhEDWKA (ORCPT ); Tue, 4 May 2021 18:10:00 -0400 IronPort-SDR: pao5c3IY1dlRQQYM51UZQ+j5zh6ey7F6jWyCu5K2/ZRO8bHhqraFxurFxpXV5WgTLKLFcBz9RG oRlPlSJnt5/w== X-IronPort-AV: E=McAfee;i="6200,9189,9974"; a="218918606" X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="218918606" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 15:09:04 -0700 IronPort-SDR: SuLTDiqHXM8cd3yT7FXZf7uhVJgQJ2nTgf8+4zbG2ekswyEiVikeXRe1aAw3rFb3TKUSyGk+eU uKLTEkKkso9g== X-IronPort-AV: E=Sophos;i="5.82,272,1613462400"; d="scan'208";a="433492852" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 May 2021 15:09:04 -0700 Date: Tue, 4 May 2021 15:11:54 -0700 From: Jacob Pan To: Jason Gunthorpe Cc: "Tian, Kevin" , Alex Williamson , "Liu, Yi L" , Auger Eric , Jean-Philippe Brucker , LKML , Joerg Roedel , Lu Baolu , David Woodhouse , "iommu@lists.linux-foundation.org" , "cgroups@vger.kernel.org" , Tejun Heo , Li Zefan , Johannes Weiner , Jean-Philippe Brucker , Jonathan Corbet , "Raj, Ashok" , "Wu, Hao" , "Jiang, Dave" , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH V4 05/18] iommu/ioasid: Redefine IOASID set and allocation APIs Message-ID: <20210504151154.02908c63@jacob-builder> In-Reply-To: <20210504180050.GB1370958@nvidia.com> References: <20210421133312.15307c44@redhat.com> <20210421230301.GP1370958@nvidia.com> <20210422121020.GT1370958@nvidia.com> <20210423114944.GF1370958@nvidia.com> <20210426123817.GQ1370958@nvidia.com> <20210504084148.4f61d0b5@jacob-builder> <20210504180050.GB1370958@nvidia.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jason, On Tue, 4 May 2021 15:00:50 -0300, Jason Gunthorpe wrote: > On Tue, May 04, 2021 at 08:41:48AM -0700, Jacob Pan wrote: > > > > > > > > (also looking at ioasid.c, why do we need such a thin and odd > > > > wrapper around xarray?) > > > > > > > > > > I'll leave it to Jean and Jacob. > > > Could you elaborate? > > I mean stuff like this: > > int ioasid_set_data(ioasid_t ioasid, void *data) > { > struct ioasid_data *ioasid_data; > int ret = 0; > > spin_lock(&ioasid_allocator_lock); > ioasid_data = xa_load(&active_allocator->xa, ioasid); > if (ioasid_data) > rcu_assign_pointer(ioasid_data->private, data); > else > ret = -ENOENT; > spin_unlock(&ioasid_allocator_lock); > > /* > * Wait for readers to stop accessing the old private data, so the > * caller can free it. > */ > if (!ret) > synchronize_rcu(); > > return ret; > } > EXPORT_SYMBOL_GPL(ioasid_set_data); > > It is a weird way to use xarray to have a structure which > itself is just a wrapper around another RCU protected structure. > > Make the caller supply the ioasid_data memory, embedded in its own > element, get rid of the void * and rely on XA_ZERO_ENTRY to hold > allocated but not active entries. > Let me try to paraphrase to make sure I understand. Currently struct ioasid_data is private to the iasid core, its memory is allocated by the ioasid core. You are suggesting the following: 1. make struct ioasid_data public 2. caller allocates memory for ioasid_data, initialize it then pass it to ioasid_alloc to store in the xarray 3. caller will be responsible for setting private data inside ioasid_data and do call_rcu after update if needed. Correct? > Make the synchronize_rcu() the caller responsiblity, and callers > should really be able to use call_rcu() > > Jason Thanks, Jacob