Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1406235rwr; Fri, 5 May 2023 13:42:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7A5EM7xFv+onYSK5qasGiB2rX9OolJqSo4wv63euashakWA3uNnhrXfkeTCd1bNRj+Bcyj X-Received: by 2002:a05:6a20:431f:b0:dd:b941:5d99 with SMTP id h31-20020a056a20431f00b000ddb9415d99mr3643833pzk.51.1683319325116; Fri, 05 May 2023 13:42:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683319325; cv=none; d=google.com; s=arc-20160816; b=uCE/80hiQo7tEpsUPNzKqUe8JOsupLjMHuQP/X3n6WxXUiUtBKmFugc+/VMcGXZAM3 aC0/vqb6sqBxlr0U9GYAkRrmLf8xxTZ1x3xgFsrmEhXUAe9kxFVz8qSXa5q7KNcA8gqv uGMbRYZl6klaFwVPbKy5y2EVMU++tEudkqFQ16O5kqIyn4RPrqvACHloinm0OWHIhEXR 7V1xbDCLUoK8iL20/RdZG8/+YmERYVW/Ok9LoFEAxgm9bg/QxsUf0hOrQ8dzr2A2K/Ft DVa++78XaAv2gpHgsieFCEPBfoTcUerlT6DgaSR6TWAKwyP0XfqKamU1oW2Ka7IUM7wY spdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=nwzFrImbQK3EDK93U5fGxBepQdy1vpwEfTMe4k7z9i8=; b=acgUsm+lVEW4JHHhaGSKSqZ/qXs6J6psF1EJBEnnPihl2JUD7ozw8N/rZY1EHTLepG Fnf5MBNy40Qcymjsl+rGcKMGxNkHUEK7BTXtIA1zZQJ+kDzJIkUA0uXiVb9JwnAgAHgP SjnHWOKSSW3QwVWcMrUjAlkuvkk5MWRTrZLdyY76/Hbmqa11lEwOdYpHiVVnOQJzhnU5 YCfbQRbGIvrcmhMc2W2F7ys0oDqcGud64exuI3HktzoAq+gqvoPVxJoupLdAQ+tiMG6a m1Fu1a/kJ8ERWcqjw19sJcvfUJEmDl1h/ILdnxoz4kcIPhnUpf8zbOJxSQ4s6zUbWpe8 /yzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S0BIIfpS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv130-20020a632e88000000b0052c40645e07si2862036pgb.57.2023.05.05.13.41.52; Fri, 05 May 2023 13:42:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=S0BIIfpS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232887AbjEEU2C (ORCPT + 99 others); Fri, 5 May 2023 16:28:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230144AbjEEU2B (ORCPT ); Fri, 5 May 2023 16:28:01 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDE6A40FB; Fri, 5 May 2023 13:27:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1683318479; x=1714854479; h=date:from:to:cc:subject:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=attubp1Y5SHGM2s6fxrjpGYDxEhvZVo+MggS/87KNmo=; b=S0BIIfpSuK978Q+FSEQb84SjBLw4FRB/sdbeE0ywaWOmYS8b9kDlGDKy Dxe1H/3odER7prUYg/cTQS1xpK4gcf0IjV23DyiyLM36fEqeuHpg/+vbg 64u0zIk1+YR0DUxCDQtxrUx2HnbSJxXe818iIMlvFqkFvkV+HJA5gWtAv tKIC5OLs5Ck50m/q4BL69ePOHIMLzliIx5frb8UoNcnbTMCyR8ZaSSZWe fc+lsPfddsgOG2vcZj/imvOm4/byvxizkFjfN3a1CT0DKj2lHrfHzL+e7 sSkFpQyyMHpyrg59YnsaOprVSL/XnvTkDrEKfuXZzEb4p4lTjz+0elaeT w==; X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="338495577" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="338495577" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 13:27:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10701"; a="767259577" X-IronPort-AV: E=Sophos;i="5.99,253,1677571200"; d="scan'208";a="767259577" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.24.100.114]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2023 13:27:39 -0700 Date: Fri, 5 May 2023 13:32:02 -0700 From: Jacob Pan To: Baolu Lu Cc: LKML , iommu@lists.linux.dev, Robin Murphy , Jason Gunthorpe , Joerg Roedel , dmaengine@vger.kernel.org, vkoul@kernel.org, Will Deacon , David Woodhouse , Raj Ashok , "Tian, Kevin" , Yi Liu , "Yu, Fenghua" , Dave Jiang , Tony Luck , "Zanussi, Tom" , narayan.ranganathan@intel.com, jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v5 6/7] iommu/vt-d: Implement set_dev_pasid domain op Message-ID: <20230505133202.094bf8be@jacob-builder> In-Reply-To: <35ceffc2-e306-6215-e90a-43548f6feca6@linux.intel.com> References: <20230427174937.471668-1-jacob.jun.pan@linux.intel.com> <20230427174937.471668-7-jacob.jun.pan@linux.intel.com> <76c98e62-1cac-2ab6-7721-08ec2c1fceb8@linux.intel.com> <20230504160334.496085db@jacob-builder> <35ceffc2-e306-6215-e90a-43548f6feca6@linux.intel.com> Organization: OTC X-Mailer: Claws Mail 3.17.5 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Baolu, On Fri, 5 May 2023 10:58:38 +0800, Baolu Lu wrote: > On 5/5/23 7:03 AM, Jacob Pan wrote: > >>> +static int intel_iommu_attach_device_pasid(struct iommu_domain > >>> *domain, > >>> + struct device *dev, > >>> ioasid_t pasid) +{ > >>> + struct device_domain_info *info = dev_iommu_priv_get(dev); > >>> + struct dmar_domain *dmar_domain = to_dmar_domain(domain); > >>> + struct intel_iommu *iommu = info->iommu; > >>> + int ret; > >>> + > >>> + if (!pasid_supported(iommu)) > >>> + return -ENODEV; > >>> + > >>> + ret = prepare_domain_attach_device(domain, dev); > >>> + if (ret) > >>> + return ret; > >>> + > >>> + /* > >>> + * Most likely the device context has already been set up, > >>> will only > >>> + * take a domain ID reference. Otherwise, device context will > >>> be set > >>> + * up here. > >> The "otherwise" case is only default domain deferred attaching case, > >> right? > > it might be the only case so far, but my intention is to be general. > > i.e. no ordering requirements. I believe it is more future proof in case > > device_attach_pasid called before device_attach. > > Let's put aside deferred attach and talk about it later. > > The device's context entry is configured when the default domain is > being attached to the device. And, the default domain attaching is in > the iommu probe_device path. It always happens before set_device_pasid > which is designed to be called by the device driver. So the real > situation is that when the device driver calls set_device_pasid, the > context entry should already have been configured. > > Then let's pick up the deferred attach case. It is a workaround for > kdump (Documentation/admin-guide/kdump/kdump.rst). I don't think PASID > feature is functionally required by any kdump capture kernel as its > main purpose is to dump the memory of a panic kernel. > > In summary, it seems to be reasonable for the vt-d driver to return > -EBUSY when a device's context was copied. The idxd driver should > continue to work without kernel DMA with PASID support. > > if (context_copied(iommu, bus, devfn)) > return -EBUSY; > > Make things general is always good, but this doesn't mean that we need > to make the code complex to support cases that do not exist or are not > used. Thoughts? > Good point, it is better not put dead code in. Let me also document this behavior for future change that may affect the ordering requirement. Thanks, Jacob