Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp668971lqg; Fri, 1 Mar 2024 18:36:42 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW4rFnW5QeOOS8KFMBUrhV4UfmUtxN+T8n76ZbXl4Q3GZxoMrBq9Xf37THBTwwS/jc1P6DVOXoNWVngDQe+RMouT4019X1GWyvxJ28dwQ== X-Google-Smtp-Source: AGHT+IEhtdxk2toz3/gXeiT8ZLn8rNYBCzeyISGyoThCYnncxrjFMYWyZms8k1BLmzXEjqtZ8xYA X-Received: by 2002:a05:6e02:1ca5:b0:365:b8f9:6a36 with SMTP id x5-20020a056e021ca500b00365b8f96a36mr3832531ill.32.1709347001872; Fri, 01 Mar 2024 18:36:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709347001; cv=pass; d=google.com; s=arc-20160816; b=hr2J4nInry0nXvn4GdP/CKCpCxm9d6hvSrEIaacsFlZGskU+6aKW95Haq/tfkYOwZV OHTp/gOfjQO1hbXe9DZe2aHegED+yVc5GgfFpACbw7H5iR2ONBgr1dLdqbwLPeedaUIR YodbCIexQ/EGlpNMpgu1W35RnaOpzKdVxZyP6KcfP9ehw55JDZZXq09VvkyBuWIOgizR IIJNKlFLpBvuy2ErUKq2b9+ndvU/OMbFVSXL5HWQEtUP8QBhJT81mB6s54zk8de6lvJi eIOj1baue9lV7fRKVCPpXMRJwBJmEQmep3VvMU1L6KlfQtZDlNwbQ9dHxOQiQBWNaWDf /Org== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=5POyl/4677bPTPLA6iBYKpbwNy+pWBIIcesnixttt5A=; fh=nK40U3nu8ngGdYF2O+8sQrcSdOL2khJbA9cPGy4TBAs=; b=NXvwqurCnG9ZhlF36cNw1rPPjoo2WpRvYPktyI7cGINhoPno/hQpHF6yTSHZ2/P9mu U0L/BVSEG1+uVibNROI9shVUOFLzUscqQO2VrrWcYMnRxoL8tZ6pFWnFSKNW4JEgyvJ0 HWXNnzp37DmrQ5KHiJjMOC7fyO5cIeDbSL8omrxkZ6RHZk3jdRGV1yA8m7oHdkHruuDy jaYfp0D9FxfmfJCw6NJBjpoFERh3N/jZUyPnKoFSnABs7+FWHNwt9FE2Ebkp3gkQBQMG /hz4DZ5VX4fkRREKn3nfwZP9yY4mF9R+TV1QkPgfG+KfDsmjLaH4lWfC1bEgwv5jbmFb y4ag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AEQVqEC5; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-89312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k12-20020a63ff0c000000b005dc90546100si4514833pgi.295.2024.03.01.18.36.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 18:36:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-89312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AEQVqEC5; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-89312-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-89312-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 26D0D287443 for ; Sat, 2 Mar 2024 02:36:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0E0EB16FF2E; Sat, 2 Mar 2024 02:36:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="AEQVqEC5" Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F1531384 for ; Sat, 2 Mar 2024 02:36:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709346992; cv=none; b=IKJKHcsCqlifxfMMN0ByFIUFfaI7SwODlEj2pg9d7QQ8ZIQFfWpkt1R8oG7eVY8CA9cBux8TzMl6VlN21gtAc2Ym1RRS3/+sT+KKrtoe98Q3pSAhwS2cxqWaOANMav08PqlEgpsNuI3Ppwr4mPQYU/cIlcDL/NML5WQ/FiQpLBw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709346992; c=relaxed/simple; bh=h85jpT5VMKAmcwx8xjty1pBSWn4rm7EQTJbenc1Kkn0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=KMP91d4ZzsOhQ235gglkZXWa2oZVz6NLCvnvJongM/SoEf2fRS2bdnUaLEksKPWRQC5676wNcys7pUGDM3IOJ9hQvzzXaamFzsyXXi8TvgbFJJc1CeBC/qtKB0680fkWqvgWGBYmd00N9UrSB3fpWDhKPl5zxxQEXc6x42AhpZ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=AEQVqEC5; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-513298d6859so2420749e87.3 for ; Fri, 01 Mar 2024 18:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1709346989; x=1709951789; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5POyl/4677bPTPLA6iBYKpbwNy+pWBIIcesnixttt5A=; b=AEQVqEC5nf1iFueyyhc+O04VZuj1elvrxJeWGCkza2zAoM3MiztoDLOPi5f/n/2wR6 hC9efIkyjB7iv4lLdIcGLLvROmqid3hM6rZ6RCcyPwhGgRxY8dQwHbxHRCHsYEeYSPGQ cHxmNXWZp1W12cv1ddVUHBrTg50IrObQdpxXcy4pSVkK4Pdv0jmex+I85mwhpv11wiKe qqe883ElcA/L3lNJeCwknscbzUHOiyviS0yslp3Z/flE8or51RrQJ45RVoEExzgtVU72 rwnx87KlApWEeGBzfrkVZm3ADStVPpujkAThgSmdzKcc9/8inwGY1WKRsvcUP2Cmqk0R UbTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709346989; x=1709951789; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5POyl/4677bPTPLA6iBYKpbwNy+pWBIIcesnixttt5A=; b=SIwGDbHXpRryhqtAop7IRnW+uchArp2cTeNslNH59t1Q1BIngeIt8bkEivSnpyVpKi lc+2H7AGWmoGEHMGJlfA01S+rhoAFUKj5WRnEEsGaV/rEZ2dFkse9NKsGnmxVctVQ54C ZR4p0gSYFHxh5YPXpUxGF6v+kpZZAf0OQOFNs08NvpcPs2bliYer9Ba/arehSeb9seg1 /WkFrJ+gkWO6ahQvDUCCTpKX+Mpysnp4DWYNddIe5A4HP033tu/3+wTgzCJ+6xBjn9by YxzaoHxFJEAb8TvBSArXe53YYDY9LREo7vumhp+YnAFb9cz6UA8Py3h8+4ucjkzLwQIb wlcA== X-Forwarded-Encrypted: i=1; AJvYcCXH7ZaycuCNnTS5nI+sr7R3Kj+3dIDpmFT5LjAkOR2tyvlreHYUcypUKasrhSpA5FG9s+4lv0v4z4NucbO1NymXFHOFxQZ2MlHxDY2F X-Gm-Message-State: AOJu0Yw9W5z7ZrAN9tcyOncGQ+VUe1lF7E7lehhcI7/e9OMBsjOvNnKk UlWBXfckRvv9MeaXwMui9Ki/Dwn4+NrJ94AWfuwZm0ablNz5tLLanbBRra3rvVQE9hM0jX6WA0B pj9fPEF+zhhUuDQTSF+ClZUattcekaeC5wqAing== X-Received: by 2002:a05:6512:78d:b0:512:d575:4745 with SMTP id x13-20020a056512078d00b00512d5754745mr2199873lfr.1.1709346988970; Fri, 01 Mar 2024 18:36:28 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240122073903.24406-1-baolu.lu@linux.intel.com> <20240122073903.24406-6-baolu.lu@linux.intel.com> In-Reply-To: <20240122073903.24406-6-baolu.lu@linux.intel.com> From: Zhangfei Gao Date: Sat, 2 Mar 2024 10:36:17 +0800 Message-ID: Subject: Re: [PATCH v3 5/8] iommufd: Associate fault object with iommufd_hw_pgtable To: Lu Baolu Cc: Jason Gunthorpe , Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , Joel Granados , iommu@lists.linux.dev, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Mon, 22 Jan 2024 at 15:46, Lu Baolu wrote: > > When allocating a user iommufd_hw_pagetable, the user space is allowed to > associate a fault object with the hw_pagetable by specifying the fault > object ID in the page table allocation data and setting the > IOMMU_HWPT_FAULT_ID_VALID flag bit. > > On a successful return of hwpt allocation, the user can retrieve and > respond to page faults by reading and writing the file interface of the > fault object. > > Once a fault object has been associated with a hwpt, the hwpt is > iopf-capable, indicated by fault_capable set to true. Attaching, > detaching, or replacing an iopf-capable hwpt to an RID or PASID will > differ from those that are not iopf-capable. The implementation of these > will be introduced in the next patch. > > Signed-off-by: Lu Baolu > --- > drivers/iommu/iommufd/iommufd_private.h | 11 ++++++++ > include/uapi/linux/iommufd.h | 6 +++++ > drivers/iommu/iommufd/fault.c | 14 ++++++++++ > drivers/iommu/iommufd/hw_pagetable.c | 36 +++++++++++++++++++------ > 4 files changed, 59 insertions(+), 8 deletions(-) > > diff --git a/drivers/iommu/iommufd/iommufd_private.h b/drivers/iommu/iommufd/iommufd_private.h > index 52d83e888bd0..2780bed0c6b1 100644 > --- a/drivers/iommu/iommufd/iommufd_private.h > +++ b/drivers/iommu/iommufd/iommufd_private.h > @@ -293,6 +293,8 @@ int iommufd_check_iova_range(struct io_pagetable *iopt, > struct iommufd_hw_pagetable { > struct iommufd_object obj; > struct iommu_domain *domain; > + struct iommufd_fault *fault; > + bool fault_capable : 1; > }; > > struct iommufd_hwpt_paging { > @@ -446,8 +448,17 @@ struct iommufd_fault { > struct wait_queue_head wait_queue; > }; > > +static inline struct iommufd_fault * > +iommufd_get_fault(struct iommufd_ucmd *ucmd, u32 id) > +{ > + return container_of(iommufd_get_object(ucmd->ictx, id, > + IOMMUFD_OBJ_FAULT), > + struct iommufd_fault, obj); > +} > + > int iommufd_fault_alloc(struct iommufd_ucmd *ucmd); > void iommufd_fault_destroy(struct iommufd_object *obj); > +int iommufd_fault_iopf_handler(struct iopf_group *group); > > #ifdef CONFIG_IOMMUFD_TEST > int iommufd_test(struct iommufd_ucmd *ucmd); > diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h > index c32d62b02306..7481cdd57027 100644 > --- a/include/uapi/linux/iommufd.h > +++ b/include/uapi/linux/iommufd.h > @@ -357,10 +357,13 @@ struct iommu_vfio_ioas { > * the parent HWPT in a nesting configuration. > * @IOMMU_HWPT_ALLOC_DIRTY_TRACKING: Dirty tracking support for device IOMMU is > * enforced on device attachment > + * @IOMMU_HWPT_FAULT_ID_VALID: The fault_id field of hwpt allocation data is > + * valid. > */ > enum iommufd_hwpt_alloc_flags { > IOMMU_HWPT_ALLOC_NEST_PARENT = 1 << 0, > IOMMU_HWPT_ALLOC_DIRTY_TRACKING = 1 << 1, > + IOMMU_HWPT_FAULT_ID_VALID = 1 << 2, > }; > > /** > @@ -411,6 +414,8 @@ enum iommu_hwpt_data_type { > * @__reserved: Must be 0 > * @data_type: One of enum iommu_hwpt_data_type > * @data_len: Length of the type specific data > + * @fault_id: The ID of IOMMUFD_FAULT object. Valid only if flags field of > + * IOMMU_HWPT_FAULT_ID_VALID is set. > * @data_uptr: User pointer to the type specific data > * > * Explicitly allocate a hardware page table object. This is the same object > @@ -441,6 +446,7 @@ struct iommu_hwpt_alloc { > __u32 __reserved; > __u32 data_type; > __u32 data_len; > + __u32 fault_id; > __aligned_u64 data_uptr; > }; > #define IOMMU_HWPT_ALLOC _IO(IOMMUFD_TYPE, IOMMUFD_CMD_HWPT_ALLOC) > diff --git a/drivers/iommu/iommufd/fault.c b/drivers/iommu/iommufd/fault.c > index 9844a85feeb2..e752d1c49dde 100644 > --- a/drivers/iommu/iommufd/fault.c > +++ b/drivers/iommu/iommufd/fault.c > @@ -253,3 +253,17 @@ int iommufd_fault_alloc(struct iommufd_ucmd *ucmd) > > return rc; > } > + > +int iommufd_fault_iopf_handler(struct iopf_group *group) > +{ > + struct iommufd_hw_pagetable *hwpt = group->cookie->domain->fault_data; > + struct iommufd_fault *fault = hwpt->fault; > + > + mutex_lock(&fault->mutex); > + list_add_tail(&group->node, &fault->deliver); > + mutex_unlock(&fault->mutex); > + > + wake_up_interruptible(&fault->wait_queue); > + > + return 0; > +} > diff --git a/drivers/iommu/iommufd/hw_pagetable.c b/drivers/iommu/iommufd/hw_pagetable.c > index 3f3f1fa1a0a9..2703d5aea4f5 100644 > --- a/drivers/iommu/iommufd/hw_pagetable.c > +++ b/drivers/iommu/iommufd/hw_pagetable.c > @@ -8,6 +8,15 @@ > #include "../iommu-priv.h" > #include "iommufd_private.h" > > +static void __iommufd_hwpt_destroy(struct iommufd_hw_pagetable *hwpt) > +{ > + if (hwpt->domain) > + iommu_domain_free(hwpt->domain); > + > + if (hwpt->fault) > + iommufd_put_object(hwpt->fault->ictx, &hwpt->fault->obj); > +} > + > void iommufd_hwpt_paging_destroy(struct iommufd_object *obj) > { > struct iommufd_hwpt_paging *hwpt_paging = > @@ -22,9 +31,7 @@ void iommufd_hwpt_paging_destroy(struct iommufd_object *obj) > hwpt_paging->common.domain); > } > > - if (hwpt_paging->common.domain) > - iommu_domain_free(hwpt_paging->common.domain); > - > + __iommufd_hwpt_destroy(&hwpt_paging->common); > refcount_dec(&hwpt_paging->ioas->obj.users); > } > > @@ -49,9 +56,7 @@ void iommufd_hwpt_nested_destroy(struct iommufd_object *obj) > struct iommufd_hwpt_nested *hwpt_nested = > container_of(obj, struct iommufd_hwpt_nested, common.obj); > > - if (hwpt_nested->common.domain) > - iommu_domain_free(hwpt_nested->common.domain); > - > + __iommufd_hwpt_destroy(&hwpt_nested->common); > refcount_dec(&hwpt_nested->parent->common.obj.users); > } > > @@ -213,7 +218,8 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, > struct iommufd_hw_pagetable *hwpt; > int rc; > > - if (flags || !user_data->len || !ops->domain_alloc_user) > + if ((flags & ~IOMMU_HWPT_FAULT_ID_VALID) || > + !user_data->len || !ops->domain_alloc_user) > return ERR_PTR(-EOPNOTSUPP); > if (parent->auto_domain || !parent->nest_parent) > return ERR_PTR(-EINVAL); > @@ -227,7 +233,7 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx, > refcount_inc(&parent->common.obj.users); > hwpt_nested->parent = parent; > > - hwpt->domain = ops->domain_alloc_user(idev->dev, flags, > + hwpt->domain = ops->domain_alloc_user(idev->dev, 0, > parent->common.domain, user_data); Why remove flags? typo or any reason? arm_smmu_domain_alloc_user can not get flags from the user app. User should set IOMMU_HWPT_FAULT_ID_VALID, right? Thanks