Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp4010577pxy; Tue, 4 May 2021 15:30:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvT5EIvGRH6q3wovf/yO8ll6B9P/mxhaHhCwsU3erc0tLWwuWUNOk5O0VcbJODf13NhNFj X-Received: by 2002:a17:906:3bc6:: with SMTP id v6mr24438469ejf.165.1620167457418; Tue, 04 May 2021 15:30:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620167457; cv=none; d=google.com; s=arc-20160816; b=eYhavCAJVVgqYqGKfbn9zT/8yCHzciw8Fz5kvEUHICCh9IrmwsCoJ1eoUwrS06DaSY 7uaiyEt5v/V8LbPLlWf0LaNX4H9LqG7KgYnMp0jCSMHWYPuYfazBUjPqNKOwtLEpumBQ vSdEuvJlcljqutG7smK6uADyUsmYZ+R5F3LfoNJBH1NSNV+cSp10nthLYBJjrudRIyFG KRRO6ttmgVZLio5w7mH61uROWY+bPA69zL7AhuqmpfOqUg06DTeaYSPxQwy4JJxpoUM3 56cj0yR4IZwvwHcz63Ry241RiYMiPEGhtdOD49oz+tkDJNYWqtI2iVKYaqkLFJE1bkjm hdQA== 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 :organization:references:in-reply-to:message-id:subject:cc:to:from :date:ironport-sdr:ironport-sdr; bh=fWMNeTe7mrf31TyqlfBFmnQB2m3eGW5tZF7eMU7rktI=; b=H+vSvbDbxhBNtE6/c20V9U8eASM+lVOZPRUgdJVl22UAt6XUl2o91cqzJCvwiPwlmC B8BzskRGrIPH6jsw2dIERz5gSRznGzVJFFHT1tpchrFQ/yAxRcNCZE3H9pntdEFlpD49 91VjDAeZufR/DjUeYfEjddEF2hERf5Gcd9c4uaWFJw4Yu6QsJn742rhsFm65HQCUL0xo FVUw/aR/gCv1fKi0K4jc/7+j4rM0FGDqR/RKXDbTnK/D5XcrFTwNDgJOTj5D6eaHtysj I79O27QaxCEvB2PJOYIsXDDoDMqe5xJ0dq9xHrLxMvIFtn8Ep9wGRYKEV3B+kXBazIi4 a9gQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j2si7165930edr.305.2021.05.04.15.30.32; Tue, 04 May 2021 15:30:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232803AbhEDWKB (ORCPT + 99 others); Tue, 4 May 2021 18:10:01 -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