Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp41043ybz; Tue, 21 Apr 2020 14:49:15 -0700 (PDT) X-Google-Smtp-Source: APiQypLncjPyFTWdqRTyfrYZrM2fi0sc60lsjel4Bc6Ig5TKIP0jPyu2grWgJwqcR0okCX7lpGtx X-Received: by 2002:a17:907:262b:: with SMTP id aq11mr16607005ejc.277.1587505755499; Tue, 21 Apr 2020 14:49:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587505755; cv=none; d=google.com; s=arc-20160816; b=tsc281hw2S17ho9Yi/3jI6LiafjFaVGF7XDWDvg0sLSeQnnJ1ijuTRtMrRq5Y5eJTj AJyQ4vz28LCwEYkonGrPHtG4tTzE2wctMruOhmQ/jTMv0BWDnyPqNYpwyab0YO0JW1aV TKfy+NcmvNT0IAj4Lzg4y2wn/kY9MDj9oYPV0OjVjoIgZ9ArQGLtoXjkcKbdrIDjICLC 1l7m+0U1OyhB1F1TGKbkz7B98gLFrRvua6ouwder7r0jy8hS7ne/xYEAzignbq0MLpNy 8JhUD5D+yiSrXiVCt0mYuSloJyBr9ZJ8qB0FnU0k+RzxbsjTwBRaWIO2EitcNVO+DXZ1 qBwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:ironport-sdr:ironport-sdr; bh=K6G4Ew2fCOhSSCe+j/vNOTn/kBibodRFbw36n8wkerU=; b=CZP/AHPW+HekNtyQtfvqvLtWSmQfad6TfpjVq6vVm+ppQOwjy5kOWZQCmmA2tIw78z q+7ayTJPExNuNIOK1lUjPdGj518EkzUAwJLgjNDHxdTbHZP8VnlYV8cp9EnUhCBPP3Ab HHoKZlMhgj3js0t81mpO/GbUmqCiMuzARaMrW3fhgiR79TAO/oUlzDJKrh/TofcQ6dxz 5d/c7F41oghlG8tJldwPm3MTJXkoIN4owz6QnFwrB31jCTWHnTeoAE6rN3l0DmWglnvW Ns8tfpowU3EV/2c4N92/G+f13NSB6cgVPP0B5tjw/S5QnWkpKp492L/CBL1ZTVlMHhn/ JJ1A== 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 i12si1484640edx.421.2020.04.21.14.48.52; Tue, 21 Apr 2020 14:49:15 -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 S1726287AbgDUVpR (ORCPT + 99 others); Tue, 21 Apr 2020 17:45:17 -0400 Received: from mga03.intel.com ([134.134.136.65]:26604 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725850AbgDUVpQ (ORCPT ); Tue, 21 Apr 2020 17:45:16 -0400 IronPort-SDR: wMs3zuSSGIbZUN5ycGOZbicEm00WWT+MwNlXFq8m4CJXVW/iTYqcDs6A4/3+85/r/RnBTOs1O/ 8sUj3C2O5Wgg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2020 14:45:16 -0700 IronPort-SDR: MwvvF2uOE0/rXubMe0J7rP2SBZ7NPzFjCQFRpdgTxUXhT+1BkCZkaaUflxP8D0Ma8PrKuUH+uN o6C6CID10IyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.72,411,1580803200"; d="scan'208";a="244305142" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by orsmga007.jf.intel.com with ESMTP; 21 Apr 2020 14:45:16 -0700 Date: Tue, 21 Apr 2020 14:51:14 -0700 From: Jacob Pan To: Jean-Philippe Brucker Cc: Joerg Roedel , Alex Williamson , Lu Baolu , iommu@lists.linux-foundation.org, LKML , David Woodhouse , Jean-Philippe Brucker , Yi Liu , "Tian, Kevin" , Raj Ashok , Christoph Hellwig , Jonathan Cameron , Eric Auger , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH 03/10] iommu/ioasid: Introduce per set allocation APIs Message-ID: <20200421145114.49e05059@jacob-builder> In-Reply-To: <20200407110107.GA285264@myrica> References: <1585158931-1825-1-git-send-email-jacob.jun.pan@linux.intel.com> <1585158931-1825-4-git-send-email-jacob.jun.pan@linux.intel.com> <20200401134745.GE882512@myrica> <20200406130245.690cfe15@jacob-builder> <20200407110107.GA285264@myrica> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jean, Sorry for the late reply, been trying to redesign the notification part. On Tue, 7 Apr 2020 13:01:07 +0200 Jean-Philippe Brucker wrote: > On Mon, Apr 06, 2020 at 01:02:45PM -0700, Jacob Pan wrote: > > > > + sdata = kzalloc(sizeof(*sdata), GFP_KERNEL); > > > > + if (!sdata) > > > > + return -ENOMEM; > > > > > > I don't understand why we need this structure at all, nor why we > > > need the SID. Users have already allocated an ioasid_set, so why > > > not just stick the content of ioasid_set_data in there, and pass > > > the ioasid_set pointer to ioasid_alloc()? > > > > > > > My thinking was that ioasid_set is an opaque user token, e.g. we > > use mm to identify a common set belong to a VM. > > > > This sdata is an IOASID internal structure for managing & servicing > > per set data. If we let user fill in the content, some of the > > entries need to be managed by the IOASID code under a lock. > > We don't have to let users fill the content. A bit like iommu_domain: > device drivers don't modify it, they pass it to iommu_map() rather > than passing a domain ID. > much better. > > IMO, not suitable to let user allocate and manage. > > > > Perhaps we should rename struct ioasid_set to ioasid_set_token? > > Is the token actually used anywhere? As far as I can tell VFIO does > its own uniqueness check before calling ioasid_alloc_set(), and > consumers of notifications don't read the token. > for vt-d, the per vm token (preferrably mm) will be used by kvm to manage its PASID translation table. when kvm receives a notification about a new guest-host PASID mapping, it needs to know which vm it belongs to. So if mm is used as token, both vfio and kvm can identify PASID ownership. > > > > /** > > * struct ioasid_set_data - Meta data about ioasid_set > > * > > * @token: Unique to identify an IOASID set > > * @xa: XArray to store ioasid_set private ID to > > system-wide IOASID > > * mapping > > * @max_id: Max number of IOASIDs can be allocated within > > the set > > * @nr_id Number of IOASIDs allocated in the set > > * @sid ID of the set > > */ > > struct ioasid_set_data { > > struct ioasid_set *token; > > struct xarray xa; > > int size; > > int nr_ioasids; > > int sid; > > struct rcu_head rcu; > > }; > > How about we remove the current ioasid_set, call this structure > ioasid_set instead of ioasid_set_data, and have ioasid_alloc_set() > return it, rather than requiring users to allocate the ioasid_set > themselves? > > struct ioasid_set *ioasid_alloc_set(ioasid_t quota): > > This way ioasid_set is opaque to users (we could have the definition > in ioasid.c), but it can be passed to ioasid_alloc() and avoids the > lookup by SID. Could also add the unique token as a void * argument to > ioasid_alloc_set(), if needed. > Sounds good. still pass a token. Thanks for the idea. > Thanks, > Jean [Jacob Pan]