Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1415068lqa; Mon, 29 Apr 2024 07:56:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUO8CYVlRebFvw/XA2WZa6z2DGK2TZcEfk2WUU9fz2hw+1cuZPvabFrvMuXgIMhKmnd3cPVCEX3RxzXtCTGKMzwYT5Bf1eCHw+IkiW2Zw== X-Google-Smtp-Source: AGHT+IHqZFmgEy0yuAx1V7yr6zPuDTOB/nccYzl4M497tVWU8h9ylWCqkJWpLPrJ3PsUcyJWFl+l X-Received: by 2002:a05:622a:2a16:b0:436:5f58:84d5 with SMTP id hc22-20020a05622a2a1600b004365f5884d5mr13873067qtb.21.1714402603088; Mon, 29 Apr 2024 07:56:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714402603; cv=pass; d=google.com; s=arc-20160816; b=Y2ngoUc7/MGMSchLh8S2YVLEomHi7OVNrG375S1E9Flgpt/1HjEsi4ph2eqyQWUjFL fjpueBKRqgTEgaGcyUnBcMghX9JusVpmQUTzLiZrnfo1znKnGVtjbjrHZHwhFyfH+0R/ tk9/YjREH1V5y6yfUeuwFkImiXOY/Js2Je5IAwHxOKmqnSczqiwRV8DFutpexE5z2bwy K85Hi6tISkloxuSkKQW0CSw2tlTQvoU3uP3yHHPnkVdPhjEKrZGcvE+p20pJJ4dZFkhT fj9ASajg7/QWRLGjvpqhASbVQsltwaS6VfS9KVsaJ63kkUh3IMgcWGhwSgY53wALbyc9 jAPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WyfECjGT2cPe5HE/2z0fDQqdazh8yGo98dGumX8os9Y=; fh=uPvpAI2pVzV+ZQGBw40vELJWPrY6oHVb3txpgjO/weo=; b=D42vktX+f3hr0jwOXF1TX3iZ8H0BAraRNzYhdYteyEUBrH5zc+U9aMgZPXHf/10UME 5HMFIb85IrCx9zW+eTayijDC7+JCcUFvwG6ySUHKNauyqW7oWQLi+6+zVLEMjIwuvpxH M/6ugdHkowDF2gmoBu6ppceYnYAqJq8Ol56bqsF+9goVtUjYb+eYFHUiDM1M4Hot5png HJMbYswuFqDzhmAwGIXfYQ31q1vELMr9uudd4vikhP+lRTmONPdhYd9e5IGSb0UoTbQo 2rk42nCwg2ROP/moKf0ItgDZ2alHOfpAJVmLq3+D4DnXe0sNqMBsZ3zNXWwGshctiOLi se0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=R+8Z798H; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-162501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162501-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id cm5-20020a05622a250500b00439d0c8bbdfsi18301330qtb.739.2024.04.29.07.56.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 07:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=R+8Z798H; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-162501-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162501-linux.lists.archive=gmail.com@vger.kernel.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CC2491C21F17 for ; Mon, 29 Apr 2024 14:56:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4081480624; Mon, 29 Apr 2024 14:56:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="R+8Z798H" Received: from mail-qk1-f177.google.com (mail-qk1-f177.google.com [209.85.222.177]) (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 7352777F10 for ; Mon, 29 Apr 2024 14:56:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714402594; cv=none; b=JhuzrBhdEaNPdVWWn6qCbvM1GJNRJCWINCooWIKCCtMH5f3L5wDs2j5Aa8+tEvWvaLAZc8BuhutP8dKa2BRtz1psLep6el7XD8CLd+EdRFZhWFt6DisVyRIRQBrjhM4qJgTohNOpWPBZPZYb2s5soiFF5/8JEF7T/8wzE9QEZmA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714402594; c=relaxed/simple; bh=DaJQZCDIDOH7FlCCzFmzVcn1pnb5oiVg8UdCJ06JAo8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=AedOhejGRXxHmM3NWlvkRqBxVv8rxubjxx3a/tl2aziFDMpowWmPkjFgw+OU1+x6vrfunPsOpfCPpIZYraXb+SLMsNpL0V+GV8ySK2gvL6sloJ0oCUc/IYW+Q9cfzbM27jR/qlmtn54RtZwR+LXhMdMAiGbwtz03hBt5Za2OfaA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=R+8Z798H; arc=none smtp.client-ip=209.85.222.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-qk1-f177.google.com with SMTP id af79cd13be357-790f4650f93so114217585a.2 for ; Mon, 29 Apr 2024 07:56:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1714402590; x=1715007390; 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=WyfECjGT2cPe5HE/2z0fDQqdazh8yGo98dGumX8os9Y=; b=R+8Z798HatwnIzy4kNxr6v+xygvR3lCftmADUUFSbwDy57KRD+6xyzBN562GJNHOgl w8x1Y80uasv/PbtCy/fS2rmXibv6wzPgZf6X8BpUu2fHheyAuAcXJLfj4ZtkRZ1LG/Yt FTJ9D++q8nzRFutLte4Bp1MtKevBraFEXItGT7S2vXxn8UL03IEUjzqDMdIPr2liZAP0 Vu6+PJ04sr9pnmlA8UcQJUknPEgo52OjH9lhOA8nkgggMPWmUoiR3DBXPmnf35lEcPlY Ei0fkg1QUedndRI6WCra+OZv7Oj6GX2oF19F/KRGXpb9+hHZNpX8b+6ThPhz2r4iOXo/ ER5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714402590; x=1715007390; 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=WyfECjGT2cPe5HE/2z0fDQqdazh8yGo98dGumX8os9Y=; b=qRFKUxNtpcFlD8hHpypxY4XfP0aTm9RP7hKUi8wi2fYAFm2bGLcYGOHR+9JRLYjrKY rpBq4cXd3GyCdDgXqwnjEU/Cz1P6w9nj9UAOGCtebLR4u2raFNtsJtjepBnGBvCqEXXd lnDXR0LbvHsQcam/pfGgm1yYuP6hCvkPusGSlPVTv/kJO7B2rAgWYiDGLf+PjaUWjmvR IFZYVxwhBorxLDDj+jboWRQbMPgrBl/rZD4D7RXBX0cDIA2sXMMmwJC9G2iCxtHtwj4Z i+pxRT3yeQxKznCJiyoelCfxJeGmfETNcMS8xqdzR2MYN3cyfiI/l03rv5Q1wll29GZs riqA== X-Forwarded-Encrypted: i=1; AJvYcCU7NAWhI6coObpDrNw2q962E9AOXTg4OKUXIs/WrnrsU6ReK/pGSSrbLGLPevNvWmkre4t8a1lWt0GrsYavCJjjmrJ/rlCNwwqTDhYM X-Gm-Message-State: AOJu0YyyuuN7rA2RgTxeOmMlEngtGUG/gN5HWWgvPGsI39xLiaIuW3Xy 8/cbdMnFunwDDWG1/65+CFpTfQq7jmGaIwn6l9IBhpOj3gGNGHUUWFzOFuDKljM= X-Received: by 2002:a05:620a:47c2:b0:788:31a1:4a16 with SMTP id du2-20020a05620a47c200b0078831a14a16mr12178748qkb.43.1714402590105; Mon, 29 Apr 2024 07:56:30 -0700 (PDT) Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id op53-20020a05620a537500b0078d67d40c49sm10499522qkn.70.2024.04.29.07.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 07:56:29 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1s1SQf-001WJH-1Y; Mon, 29 Apr 2024 11:56:29 -0300 Date: Mon, 29 Apr 2024 11:56:29 -0300 From: Jason Gunthorpe To: Pasha Tatashin Cc: akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, rientjes@google.com, dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, iommu@lists.linux.dev Subject: Re: [RFC v2 2/3] iommu/intel: synchronize page table map and unmap operations Message-ID: <20240429145629.GO231144@ziepe.ca> References: <20240426034323.417219-1-pasha.tatashin@soleen.com> <20240426034323.417219-3-pasha.tatashin@soleen.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240426034323.417219-3-pasha.tatashin@soleen.com> On Fri, Apr 26, 2024 at 03:43:22AM +0000, Pasha Tatashin wrote: > Since, we are going to update parent page table entries when lower > level page tables become emtpy and we add them to the free list. > We need a way to synchronize the operation. > > Use domain->pgd_lock to protect all map and unmap operations. > This is reader/writer lock. At the beginning everything is going to be > read only mode, however, later, when free page table on unmap is added > we will add a writer section as well. > > Signed-off-by: Pasha Tatashin > --- > drivers/iommu/intel/iommu.c | 21 +++++++++++++++++++-- > drivers/iommu/intel/iommu.h | 3 +++ > 2 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c > index 1bfb6eccad05..8c7e596728b5 100644 > --- a/drivers/iommu/intel/iommu.c > +++ b/drivers/iommu/intel/iommu.c > @@ -995,11 +995,13 @@ static void dma_pte_free_pagetable(struct dmar_domain *domain, > unsigned long last_pfn, > int retain_level) > { > + read_lock(&domain->pgd_lock); I think no to this. This is a very performance sensitive path for the DMA API, we really do want to see a lockless RCU scheme to manage this overhead here. This would be fine for a VFIO user, which I guess is your use case. IMHO it is not a good idea to fiddle around the edges like this. We need to get the iommu code to having shared algorithms for the radix tree so we can actually implement something good here and share it. Every driver has the same problem and needs the same complicated fix. I keep threatening to work on that but have yet to start.. Jason