Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1006278ybn; Wed, 2 Oct 2019 09:26:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqUrDy1hC3oU2098k/d5PXCgN8oEJJGrQJkuKJMzTu8M+iaHQanlFgpifD4hIHMyFBB9Og X-Received: by 2002:a17:906:4e57:: with SMTP id g23mr3767205ejw.264.1570033586318; Wed, 02 Oct 2019 09:26:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570033586; cv=none; d=google.com; s=arc-20160816; b=JA11Pe8PJmvKOdCe/OFFwjRhS5WnZUe8d4+dl14bKCuzBvyQI/ot27bCt6mj8E1RMf Rj5jUYhjcy/MRISMqeuND17gwFtbNFq2pcehip0M7oXaR/OVlzaSH1gHRufqCpUA8jIv d5QnmcKYgq8VPW/2ayJNERLnDBw2aP6L2NGE0NC86ZP/fwgUWLCjgtqeMOGknFPWNkNd JthQOmNi20C7gbdASZ98AtBXceFrQopzJFbEymYg4n9PWIfoHYD+cOQLNTFd/quphQiQ O5RFeMQc5M/8kCT0jITCtkkrz2MRu8u0nfjEmyYYJLl6ooE6VXuUqJ+Xwzi+XmGFypKD tw+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=jpI6Yt4Aabzc1pU0Qm6BvfjugUkT+9WqSHu9chpa9jc=; b=nmr9E82TnkSvFH3vq7n+sVijK3I59Rr9pEmFXGjN7ihEJRB4QPJw1Hmk0UzhedYYME oQZ2/3fGasew+4hl5MjkG4OUaREnpCO0CXWi4qo25BK1o/UpvvG9YVmircyJ39P/wvXJ vNAHFdUaAPa9Pa/gSnhOvF0rIDr5CTOvM5NiSpS/dOrKll9fEnWQgoL+BBgYa655uot9 0Cs5QrX4SqRk3hXUW3GrweEtLdtX0T7LsLhorZAKZ3laLwquerNVPCV0bqdMISlPzPwh 2tLwbsMpvOKbQ0ccGwkqn4yvvtgu8Dl84ZoWDcmTBGGTDTyZdWqzenhzrAiEvbjIT3TW ghpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AaMiU9ll; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si12741032ede.126.2019.10.02.09.26.01; Wed, 02 Oct 2019 09:26:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AaMiU9ll; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbfJBQSb (ORCPT + 99 others); Wed, 2 Oct 2019 12:18:31 -0400 Received: from mail-ed1-f65.google.com ([209.85.208.65]:33330 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726669AbfJBQSa (ORCPT ); Wed, 2 Oct 2019 12:18:30 -0400 Received: by mail-ed1-f65.google.com with SMTP id c4so15822307edl.0 for ; Wed, 02 Oct 2019 09:18:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jpI6Yt4Aabzc1pU0Qm6BvfjugUkT+9WqSHu9chpa9jc=; b=AaMiU9llCOuOCzVuMCtvZZbyHXsxo9TXDVn+8kGS8EU77tztkNeDnD/r76KhQ6T2UA B9x258ao9jX1dvtqdDaXwAEHp9xU+K6N/T1MewJoh00PaYEvLUUPnqR6nWZ2jrMs8Ztu ArV+giXb/5jloKS4VQYdU1esA+mdjo3+Xcjd2OxR2JczcRdbhxHuPLH6qvVpo7xgsuUZ a7BpTFzvlCfdtyP/nzjITkOEHUWTJHvgaCpiwcOAAOzGDzm+oM8cCxmAz2r6WphYsaAE PuMNDrECbLFS5IKE23FKf+B6XpaNnFgAY6oZJAfUj5LaRh7mnhbfgppK0kYABa1Pg8FA +3KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=jpI6Yt4Aabzc1pU0Qm6BvfjugUkT+9WqSHu9chpa9jc=; b=a1pxfTyGobGxYsyYRbtC08N2hDXwxpKwCeGoNqFzHkPnA1o8o4TsxqAA8coUdjrmVD CFn3mSR+p8Hgu3NLMySTOYfW0ZH32FFRQqUK1t39VxrRuKI33R2BXZWfhnTmhKhVfBUd 0xNUK1EaSLne9HspPXG3Vg57VJtQmiThY4vHflN0OZMuRJchdcCJg+xjAnnmMuYtuDlQ wK/jn+22heI09y3bU+VF+f4Fm8wxwGxgWyzYlzsx9E4RoUPo7LYA6R2XEj7qyK9G/IW+ nIN++RObyz+PE+BCB+tYWb6nw9xMXRrD9AUujCevmNe62JaCPw+W7JGjqA5dPdF5b8lR 85Hw== X-Gm-Message-State: APjAAAXPyYP49B5933yYuIgMlkJSyfRoA5ln+WZyYq3cC2DzQ7+5obPk hL2tnnxaFAFjIygR18bpoqDrgpazBLlj6Q== X-Received: by 2002:a17:906:5c16:: with SMTP id e22mr3751787ejq.105.1570033108207; Wed, 02 Oct 2019 09:18:28 -0700 (PDT) Received: from lophozonia ([85.195.192.192]) by smtp.gmail.com with ESMTPSA id h1sm1567262ejb.86.2019.10.02.09.18.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Oct 2019 09:18:27 -0700 (PDT) Date: Wed, 2 Oct 2019 18:18:25 +0200 From: Jean-Philippe Brucker To: Jacob Pan Cc: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Alex Williamson , Jean-Philippe Brucker , Yi Liu , "Tian, Kevin" , Raj Ashok , Christoph Hellwig , Lu Baolu , Jonathan Cameron , Eric Auger Subject: Re: [PATCH v2 3/4] iommu/ioasid: Add custom allocators Message-ID: <20191002161825.GA626133@lophozonia> References: <1569110870-12603-1-git-send-email-jacob.jun.pan@linux.intel.com> <1569110870-12603-4-git-send-email-jacob.jun.pan@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1569110870-12603-4-git-send-email-jacob.jun.pan@linux.intel.com> User-Agent: Mutt/1.12.1 (2019-06-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacob, I have four tiny comments below but the patch looks great otherwise, no major concern from me. On Sat, Sep 21, 2019 at 05:07:49PM -0700, Jacob Pan wrote: > +/* > + * struct ioasid_allocator_data - Internal data structure to hold information > + * about an allocator. There are two types of allocators: > + * > + * - Default allocator always has its own XArray to track the IOASIDs allocated. > + * - Custom allocators may share allocation helpers with different private data. > + * Custom allocators that share the same helper functions also share the same > + * XArray. > + * Rules: > + * 1. Default allocator is always available, not dynamically registered. This is > + * to prevent race conditions with early boot code that want to register > + * custom allocators or allocate IOASIDs. > + * 2. Custom allocators take precedence over the default allocator. > + * 3. When all custom allocators sharing the same helper functions are > + * unregistered (e.g. due to hotplug), all outstanding IOASIDs must be > + * freed. Otherwise, outstand IOASIDs will be lost and orphaned. outstanding [...] > ioasid_t ioasid_alloc(struct ioasid_set *set, ioasid_t min, ioasid_t max, > void *private) > { > - ioasid_t id; > struct ioasid_data *data; > + void *adata; > + ioasid_t id; nit: changing the location of id could be in patch 2/4. > - data = kzalloc(sizeof(*data), GFP_KERNEL); > + data = kzalloc(sizeof(*data), GFP_ATOMIC); I don't think that one needs to be GFP_ATOMIC. Otherwise it should probably be done from the start, by patch 2/4. > if (!data) > return INVALID_IOASID; > > data->set = set; > data->private = private; > > - if (xa_alloc(&ioasid_xa, &id, data, XA_LIMIT(min, max), GFP_KERNEL)) { > - pr_err("Failed to alloc ioasid from %d to %d\n", min, max); > + /* > + * Custom allocator needs allocator data to perform platform specific > + * operations. > + */ > + spin_lock(&ioasid_allocator_lock); > + adata = active_allocator->flags & IOASID_ALLOCATOR_CUSTOM ? active_allocator->ops->pdata : data; > + id = active_allocator->ops->alloc(min, max, adata); > + if (id == INVALID_IOASID) { > + pr_err("Failed ASID allocation %lu\n", active_allocator->flags); > + goto exit_free; > + } > + > + if ((active_allocator->flags & IOASID_ALLOCATOR_CUSTOM) && > + xa_alloc(&active_allocator->xa, &id, data, XA_LIMIT(id, id), GFP_ATOMIC)) { nit: aligning at the "if (" would make this block more readable. > + /* Custom allocator needs framework to store and track allocation results */ > + pr_err("Failed to alloc ioasid from %d\n", id); > + active_allocator->ops->free(id, active_allocator->ops->pdata); > goto exit_free; > } Thanks, Jean