Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4006085rdb; Thu, 14 Sep 2023 09:03:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvXeVcp8L9io5xJW0saL7Vd5qS8bkKyg9UPzxCVBBS72rdbvS9Z8VYvmFOgwlZVk3vbSG9 X-Received: by 2002:a05:6a00:1913:b0:68f:b3ed:7d56 with SMTP id y19-20020a056a00191300b0068fb3ed7d56mr6027533pfi.34.1694707380838; Thu, 14 Sep 2023 09:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694707380; cv=none; d=google.com; s=arc-20160816; b=dW9c+cBziNn3kfRKoPcd9N8pQsXOTnciE1lv9CNw0vC6knSimi+YrK8h+h4VWguGp6 8h+8jhrkZzMES8Es/pD+s/RfDGVUkvLRQLOQuYAPXYR7MtEt2Y0Kkhh8FYGeTuL75nb7 dsEN9stAfIL2htWAllbKXf18XttZ2p5L6pl/2621U86tt93YQvUYoB2KH8vdLU05eI85 DqvwsWO1yMNo4eXGEdwCT6dZvxY+TpPhffc27tWi1/FGW/9pYRAHymHrPMaTfVj8DRuu 7UAnxTBuFh6dFfecLuRpVAkY8CLRp/puFASt4hKwj/mDrneR7kHu6cZ3HRyns4LTGDHj UEbA== 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=SnEPBkMkaXDinvAUkMeqlZXQsRYbCJWbA29QgpfY/CA=; fh=4v6zqE/6yGNg4q8bfEg2ZbFdI13yFLzHn63mmcbxmHw=; b=0Xka/9DszQbDIF6LJkonQg9WQ+xnzX8ZgUDj4Eut35pLuorWFaAVdEohyY6D9qf+rF pSeaKlWJvuvpe5v8NyrkQL9D1+M5b1Rl7ipANffS6jEKNg3nW19VD1D5hxk3+NU8A+rJ yT/5BHCPNwDO+93Q4YsMejvCON1Lp4OTqhkjKPFetcgNF3Bg4Fof9aO3FJrTQZI6w2JS csJrF8YH8Y5rszqhhLf9x4t+kzGYTWQE3NY6SL/xAcf5BkLKKxc3QqcqKMDBhi2RVesX yDltFgQy8OVvU17QfpQanVb2J2HAe96ZAg8xc5LtQXG92tn03X8Q3/TQo8DzljLKmMDh 507Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GI6fa4YB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id bx21-20020a056a00429500b0068fc151fdd5si1001785pfb.177.2023.09.14.09.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 09:03:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=GI6fa4YB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 8D10B828D04A; Tue, 12 Sep 2023 21:27:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238262AbjIME0k (ORCPT + 99 others); Wed, 13 Sep 2023 00:26:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjIME0h (ORCPT ); Wed, 13 Sep 2023 00:26:37 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6159DA0; Tue, 12 Sep 2023 21:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1694579193; x=1726115193; h=message-id:date:mime-version:cc:subject:to:references: from:in-reply-to:content-transfer-encoding; bh=KgyPr+Cgj+GJvemhLB38JTJgS0QW58VqrqaihkXJdmU=; b=GI6fa4YBwV/BAfvErgHVVJF3B21JZg5lHtCKX2ujYbVVVa4Z7YFKfEKe 4f6vlAX7LOMSNKbrWwZQNNhrGhyoRxlRwWDyojzAvLO96O34Mgpj4FFYr 1BYIIhHyCoY4lowujZuDysC/6BDLbZJpPEDsqzwvroL6SYaR0gtmKM+1m /9HGbUYiOW5jST69BxG+sOkUJTWHY5hjIfgAfXA9t9ri/LNu/BFbX8Oi/ 3k9w8XciMnzt8wCtowrkRI3GLkW8rc73Lkde4rFPRidv8ZyZFq7MUzdjW CKWtkoibkbCB3OiHexrujL/Koz+GcGKimgAcPzfZXmNU5wu/o6r3RyhVM g==; X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="382368650" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="382368650" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Sep 2023 21:26:32 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10831"; a="743969821" X-IronPort-AV: E=Sophos;i="6.02,142,1688454000"; d="scan'208";a="743969821" Received: from allen-box.sh.intel.com (HELO [10.239.159.127]) ([10.239.159.127]) by orsmga002.jf.intel.com with ESMTP; 12 Sep 2023 21:26:29 -0700 Message-ID: Date: Wed, 13 Sep 2023 12:23:31 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Cc: baolu.lu@linux.intel.com, "Liu, Yi L" , Jacob Pan , "iommu@lists.linux.dev" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v4 09/10] iommu: Make iommu_queue_iopf() more generic Content-Language: en-US To: "Tian, Kevin" , Joerg Roedel , Will Deacon , Robin Murphy , Jason Gunthorpe , Jean-Philippe Brucker , Nicolin Chen References: <20230825023026.132919-1-baolu.lu@linux.intel.com> <20230825023026.132919-10-baolu.lu@linux.intel.com> From: Baolu Lu In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 (pete.vger.email [0.0.0.0]); Tue, 12 Sep 2023 21:27:35 -0700 (PDT) X-Spam-Status: No, score=-2.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email On 9/13/23 10:34 AM, Tian, Kevin wrote: >> From: Baolu Lu >> Sent: Monday, September 11, 2023 8:46 PM >> >> On 2023/9/11 14:57, Tian, Kevin wrote: >>>> From: Baolu Lu >>>> Sent: Tuesday, September 5, 2023 1:24 PM >>>> >>>> Hi Kevin, >>>> >>>> I am trying to address this issue in below patch. Does it looks sane to >>>> you? >>>> >>>> iommu: Consolidate per-device fault data management >>>> >>>> The per-device fault data is a data structure that is used to store >>>> information about faults that occur on a device. This data is allocated >>>> when IOPF is enabled on the device and freed when IOPF is disabled. The >>>> data is used in the paths of iopf reporting, handling, responding, and >>>> draining. >>>> >>>> The fault data is protected by two locks: >>>> >>>> - dev->iommu->lock: This lock is used to protect the allocation and >>>> freeing of the fault data. >>>> - dev->iommu->fault_parameter->lock: This lock is used to protect the >>>> fault data itself. >>>> >>>> Improve the iopf code to enforce this lock mechanism and add a >> reference >>>> counter in the fault data to avoid use-after-free issue. >>>> >>> >>> Can you elaborate the use-after-free issue and why a new user count >>> is required? >> >> I was concerned that when iommufd uses iopf, page fault report/response >> may occur simultaneously with enable/disable PRI. >> >> Currently, this is not an issue as the enable/disable PRI is in its own >> path. In the future, we may discard this interface and enable PRI when >> attaching the first PRI-capable domain, and disable it when detaching >> the last PRI-capable domain. > > Then let's not do it now until there is a real need after you have a > thorough design for iommufd. Okay, fair enough. > >> >>> >>> btw a Fix tag is required given this mislocking issue has been there for >>> quite some time... >> >> I don't see any real issue fixed by this change. It's only a lock >> refactoring after the code refactoring and preparing it for iommufd use. >> Perhaps I missed anything? >> > > mislocking already exists today for the partial list: > > - iommu_queue_iopf() uses dev->iommu->lock; > - iopf_queue_discard_partial() uses queue->lock; So, if it's worth it, let me try splitting a fix patch. Best regards, baolu