Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2151276rdb; Thu, 7 Dec 2023 22:29:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJpa15PWSoD4CkCb8fgzCaLK6pzfB14BiYDOm/9kGyXtP0rIWAp98d9oUFwMxoArgRN+pS X-Received: by 2002:a9d:6a13:0:b0:6d9:ea13:5231 with SMTP id g19-20020a9d6a13000000b006d9ea135231mr460173otn.67.1702016951471; Thu, 07 Dec 2023 22:29:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702016951; cv=none; d=google.com; s=arc-20160816; b=yoE/3Zx0U6Y2JUI5TtyTXcJwMl988KJMkv3jJyTp1rF0fCwRlQh2/a+q4ZU8HHqrNS y1wexT8nbcFdUCZ55VHufVF7ioi2l6Vj1sTOv06rPhSyNLEsiIU0yeVQ5mghut9sLBEM hOIvvrY+1/Vs9Xowr56y5fDDyIy4tESRp2ZzSsmEU7ORjXalsQfm6JrrGiSh39KGRrFq gv779GAeyW733VX2Y1HMmZWhWWP9/t5GcM3WEJxKnI1iAjJ60xLEg883CP4KAUQjyfsW pMUepQGNZipgkKzdz3vEx24oqL2FEc7QlL0RNTL/KYMOhtY6R119/79GUN42j3N4yDcu QbHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:to:content-language:subject:cc:user-agent:mime-version :date:message-id:dkim-signature; bh=6YfIorLjmGBOrx0kz0bhpmF3twNJmgW59ekjYcJ92i0=; fh=CHF6icUB8BkFux9PDqkpqFGX84EaHzyqwt6q0oBm+fk=; b=Ex2MLD0QMZazNMOcN9o7RYyxECkoY8Sq7/FSfRp/aw21bKemNpwm1XAWALvqspYH8s YA/BLd1uBCCsTpMjQ0vLH4X/al7AerrfGXqrbP8pyYbFWJYuEIXcg+TpZJxm72CtBb5y jzCOEs0nuRRqngAoSdK8H5DeuR1ZZDRklLLJcqgUDQntI78dabSJSVPXPQmO2V6FNF/A pA4DNUGfYHaC19SU4IwPP2W2NBD5WoKMyh8S7wazzyZH2NCrwnP4n/cLP4h+BNmgzNho GLns5UdeLWwHh/KIGuo+hMGbg+VGqqhnVeZ5hVT9kSi5OKJuG47nbe3g+gmJVPHjjLgw OFxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=crvhoox5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id s66-20020a632c45000000b005b881cc9498si1035842pgs.339.2023.12.07.22.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Dec 2023 22:29:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=crvhoox5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id D4233836C00F; Thu, 7 Dec 2023 22:29:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbjLHG2z (ORCPT + 99 others); Fri, 8 Dec 2023 01:28:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjLHG2x (ORCPT ); Fri, 8 Dec 2023 01:28:53 -0500 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A8D2C6; Thu, 7 Dec 2023 22:29:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1702016940; x=1733552940; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=hhwvQW5d3F0DRDnekXHWCaEI+t4hV1ugkZDv0LKCQdU=; b=crvhoox5rHZLQXO10RzD5AVUbatXkyDvL3YNGvso9OGnWRBTC58yS92g TXnDrbRlxSLFTC3Ea7Yxg2BIfvvxTpzqqqXnlEz4eM6/OAOywEJS697kI Tfdxy0bgjBHsh3HG+GoTfw2p0FHvddYzvt+fVsvG6p8NOHGQaFmWfSHUg 3vmv5tnqgjC0oCLcouYkv4ir5cQT/gIcn1J1lbnejiuPDFoEfokRs7qu1 IFzygk0QrwWEFsx0GGMRpWS4bsJzHv5bPpbaTtGxjN/e0Izca1OuORGum iybyNiqQd/C6/9+AeBcPoccRFfm1Asz6LZ+n7epoCBNhHZI/z1pjgHkBd A==; X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="394103554" X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="394103554" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Dec 2023 22:28:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10917"; a="862757803" X-IronPort-AV: E=Sophos;i="6.04,260,1695711600"; d="scan'208";a="862757803" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by FMSMGA003.fm.intel.com with ESMTP; 07 Dec 2023 22:28:56 -0800 Message-ID: Date: Fri, 8 Dec 2023 14:24:19 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: baolu.lu@linux.intel.com, 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 Content-Language: en-US To: Jason Gunthorpe References: <20231026024930.382898-1-baolu.lu@linux.intel.com> <20231026024930.382898-2-baolu.lu@linux.intel.com> <20231201143810.GK1394392@ziepe.ca> From: Baolu Lu In-Reply-To: <20231201143810.GK1394392@ziepe.ca> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,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 morse.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 (morse.vger.email [0.0.0.0]); Thu, 07 Dec 2023 22:29:09 -0800 (PST) On 12/1/23 10:38 PM, Jason Gunthorpe wrote: > 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. Great idea! In a subsequent series, we could arrange the enabling and disabling of IOPF in this API, thereby eliminating the calling of iommu_dev_enable/disable_feature(dev, IOMMU_DEV_FEAT_IOPF) from the device drivers. Best regards, baolu