Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp1080084rdb; Fri, 1 Dec 2023 06:38:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHV7ITW9VbsUigVA2F7MVx6VWOH16LUmUUeLerbBX5YNNxjcDsQIUkTRrVtWOTaZlQzwRGs X-Received: by 2002:a17:902:dac7:b0:1cf:c397:8f09 with SMTP id q7-20020a170902dac700b001cfc3978f09mr23058359plx.55.1701441505576; Fri, 01 Dec 2023 06:38:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701441505; cv=none; d=google.com; s=arc-20160816; b=MJqIDyZ6MIkmmGhe9dDI1SDc46xhKfOpXGn/2qnHL4tKD3gkAu7wYVaLdwhsRm60no i8QVQPnES2FUJaDVNsjO5O3cFwqW14pj8PmNR6+TvXETSxuEyrlrX+U5arztpyQgdKMS L1PD66Xs6Dslvtlc+Qc5nBfeifEKylJmwYxx47fjeR3gTILsDNvv7KbFBcvR5pSKdg3B Fm8TFc3NZk4imvGc77sufyqp3pL+N/ukxm78KO87qr8DbJVcjZlFBuSSIBOP4Jxwt6VA 2IjqS3JS6rznL5L1YiOrOULJu46jsCx2CWh1wqMMYNidvq3M8iFnGv6M3USdOL8p88QI YxbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=hXr7TXa/tMpuDEqpeATCPHGX6v9H50ZNaBHg4Hp0sUA=; fh=5XdFYx0/HmG08bd9P4gu2I6eqksyBIVTm667dkE3lh4=; b=FI3P0CmvxL1PH1Kuv5mOEZYwab+uRcn52F1C7qwJH9pBmr9MDjkfl43TZov5doQOkc pKeKZTRmhMTPeKxfcwkbb8KDPxFX+MdzCGIx4F1PCmdZ7YTpiz4xx39CWwqY3CM4MYWd iqGf0g769QBTzmWZiuMucw6u780juOkO9aJ9wByA0f4dA2JMI5uzTqVchnGoLfzjI8oS Qu1e48VPqBn+X5iZUi8hhTXBc2AuIgYQX0sPSpu+tPg+9jI+7AQ2PPRZtPbhS8HW5lHI QI77FxRmh67DaFNLP9p9p/w9j+2BSYnOtBtwt7gFnMc06Ok4yoLOLCyaqVMLyb1N9RDJ PQwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=RydNWY3S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id jf11-20020a170903268b00b001d04d35a88bsi1732659plb.187.2023.12.01.06.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 06:38:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=RydNWY3S; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id BB59D810D660; Fri, 1 Dec 2023 06:38:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379181AbjLAOiG (ORCPT + 99 others); Fri, 1 Dec 2023 09:38:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379169AbjLAOiF (ORCPT ); Fri, 1 Dec 2023 09:38:05 -0500 Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40609F3 for ; Fri, 1 Dec 2023 06:38:12 -0800 (PST) Received: by mail-qk1-x730.google.com with SMTP id af79cd13be357-77d8c38ea78so111522485a.0 for ; Fri, 01 Dec 2023 06:38:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1701441491; x=1702046291; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=hXr7TXa/tMpuDEqpeATCPHGX6v9H50ZNaBHg4Hp0sUA=; b=RydNWY3ShdLBfiklNm8Dqxqb+OQBGaFWZ8FG3cLe3fqBHCVohiDx0CCou5GDZgR7aQ DBcxY8pR6jXv2HvO1+mACu1KTgp72zLeGKfFy/qCqgp5y3ajSHuEPDFTyzxZ+kALlyw1 F0aiTsAeMCque0+Ng4k/oSNE9fq37XeGa6U84VG3kOVHR/JgGphNdo/69LmgtcE7EaaV zmYEWMlpU2xQ2I2ei0xxqXDg0o5accz1wWpGoBi8kbkoLItVWd+HxiLB3JM3tuZ6RWKI z0y0aZe+cOU/sRQqdruVei9EDRDd+8TOFd+2/sk27Y6OyqSzd/jAZ5aKNSqn6M6aNoyw Jh7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701441491; x=1702046291; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=hXr7TXa/tMpuDEqpeATCPHGX6v9H50ZNaBHg4Hp0sUA=; b=HePCxkfgnuZIkTu3RP9gpY6ZB6bNdnKJltqDspolQS/f0wf/K/Ekv5gM4uDCo/d1A5 jytw0zuOxEaD4eSA+2nquxJaJhiv27GJ4meNg+7GjFseLix5EZVbCnqd2ZGAeA0HoRbV yO2bwqNm3ArubLHDSdBFJXrHh/MqiLq8/vUxTWjpwzAXYwgIC08TPVHpT6vf/L0BGuA/ p3tIs4gvOSi3vAaF1WZi7wnS/prp4YUuCzCg3EkW+eMaSfAkkIMiN4wgaCtF2Ks9g9dG Tn58prhshxdb+rzS11ayjLagl3SRsE8rJpLg2V3hbJLZntvwE78tu3c9QlXl0PvN3z4v 6mYw== X-Gm-Message-State: AOJu0YxahjfbyTlznLdL1UL/OK9pspGRJdlMufponBju2rH/U1sulHxq BKy5I959sGlL+uYgiD3qgijlcw== X-Received: by 2002:a05:620a:c0d:b0:778:ba89:2fbd with SMTP id l13-20020a05620a0c0d00b00778ba892fbdmr22271407qki.36.1701441491386; Fri, 01 Dec 2023 06:38:11 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-142-134-23-187.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.134.23.187]) by smtp.gmail.com with ESMTPSA id o1-20020a05620a110100b0077dd463da60sm1533049qkk.126.2023.12.01.06.38.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 06:38:10 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1r94eg-006FYA-Dl; Fri, 01 Dec 2023 10:38:10 -0400 Date: Fri, 1 Dec 2023 10:38:10 -0400 From: Jason Gunthorpe To: Lu Baolu Cc: Kevin Tian , Joerg Roedel , Will Deacon , Robin Murphy , Jean-Philippe Brucker , Nicolin Chen , Yi Liu , Jacob Pan , iommu@lists.linux.dev, linux-kselftest@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] iommu: Add iommu page fault cookie helpers Message-ID: <20231201143810.GK1394392@ziepe.ca> References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-2-baolu.lu@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231026024930.382898-2-baolu.lu@linux.intel.com> X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 01 Dec 2023 06:38:22 -0800 (PST) On Thu, Oct 26, 2023 at 10:49:25AM +0800, Lu Baolu wrote: > +void *iopf_pasid_cookie_get(struct device *dev, ioasid_t pasid) > +{ > + struct iommu_fault_param *iopf_param = iopf_get_dev_fault_param(dev); > + void *curr; > + > + if (!iopf_param) > + return ERR_PTR(-ENODEV); > + > + xa_lock(&iopf_param->pasid_cookie); > + curr = xa_load(&iopf_param->pasid_cookie, pasid); > + xa_unlock(&iopf_param->pasid_cookie); No need for this locking, the caller has to provide some kind of locking to protect the returned pointer. I'm not sure how this can work really.. What iommfd wants is to increment the device object refcount under this xa_lock. I'm not sure this is the right arrangement: Basically you want to have a cookie per domain attachment for iopf domains that is forwarded to the handler. So maybe this entire thing is not quite right, instead of having a generic iopf attached to the domain the iopf should be supplied at domain attach time? Something like: iommu_domain_attach_iopf(struct iommu_domain *, struct device *, ioasid_t pasid, struct iopf *, void *cookie); The per-attach cookie would be passed to the iopf function automatically by the infrastructure. Detach would have the necessary locking to ensure that no handler is running across detach Then the cookie is logically placed in the API and properly protected with natural locking we already need. Jason