From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (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 DEA6D21ABBB for ; Sat, 11 Apr 2026 13:03:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775912639; cv=none; b=sxySngTIJZd4tMl+fXJ09EjKOPr2kvIGeStIkJCq10lL43QPFFlQEoYMXCF48cWlRE4+zbOkZxA6eIpQ+hl46mp5J/75Bi+IJ19TYmlqDet9oTsa0AXGJz3kiMZGVSASWQ7nbDU85u904TBv8QjLA3j+D0t+bkmlwSAVr4Z25oY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775912639; c=relaxed/simple; bh=y/qt8MI2GKVfjtqin7pQ3eEBqNJwX/jBHf4zRPl0wBY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DF1GpW9GM5u7rR2a93VvzaeOnBKWUAmGbsPsNzPhRR+uSFLobbL5uTRszGZQel1vPacZDf3PounwH4XTYImUUkyAie9eBCojVOjmW8JM1KNUquWFXt3H5JBQ9IkZDVqtLO/hy+C5hPu9XyLRBVRfGByxPZtw9PTOKCq3SStBK4M= 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=SE9q9lXW; arc=none smtp.client-ip=209.85.161.43 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="SE9q9lXW" Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-67c250805ccso1060254eaf.1 for ; Sat, 11 Apr 2026 06:03:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1775912636; x=1776517436; 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=EY4fUTZIeXO1WyqRzqIOr8UDzbQvgioLsd0oMdufTzI=; b=SE9q9lXWWFE1d8BSYGVracLCvr98643tsgIENyoA4DLZZW8zljpalktkTvnSf2VzVn BJ+nag3SvoSZOEXf8otcN2xQNM2okkErd/IIStEJK32aJERMzmodz6/cU7d2Bw6Sp4hX CGmoGkRiqXyneKWY3f6p85jlji2sASCYFjXwczzwyE2WlDDgInjK2zE75uEFhRdWujgq FvfdDz6UYeVuHXntBkHRt9tEGkIByp0vR6bsipJhhd1vaoQDcoePaMCRMtrziRwYepZy Pp6NWg9Xg7Fn3u13fwaYCaczp+33Nlu3dkYjGa4xKNL8gdpOwD8kvR+tLR6d0vvVWtNl ixlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775912636; x=1776517436; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EY4fUTZIeXO1WyqRzqIOr8UDzbQvgioLsd0oMdufTzI=; b=P0OmnMWlyucOH1syquFYHUBbtgY5iTqY+aSBYVI/i/AW9fy3WoUdSmRRsBYkGjDlxo gwbKVETfnhxMbdilu2CL/QmqWfQZXRJ8sQDfHzRWVNeYX3jLvfgtLKxHt6KnjNNpxItR Ob2TDGN18K0+O5nMyQa2yGR6HIlHq05DkWCIO9jj0Wwgu5b6BpJfIm3B807Uu30PbcwS VMuhHSd2ujkdD7MLQ6B7iVqOXDRYMws5pVAjJ77i6IWV4YgcliO3HsBGBhS0Gz7GjTCo 1sUjxYBiYkCcegoxxrehsCIf0fkx6VXdHZYVq0mIZbcGMwKGjtLhfbpPsTJUdaJIXKO+ G5zQ== X-Forwarded-Encrypted: i=1; AJvYcCX5b+HS8M7V/PtBW/81zKp2ypqDBE0d8z/qb9eaVzXJknT/ptEYhOGl/f54Rbo7nJ1xngfKrYykNF41/OA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7pdKRHUESrFWr3LaJwp+SRcA3ZatIdU4lMjI/EvOOz1khd+mC fpbWmreDT0t6aUZQ/Kg+A5PcsohDD4T6sfzqc4DffOXyqHHEcvOEPQpPkEDAERuVJug= X-Gm-Gg: AeBDiesDrvLsZD5FWU0+nqc79MTJ7nfHa0TvujCB5P3iMl4VEyNfaowm/ye3L9H/XRt 1sYe+dZERM9OpU02uICvKFzAu/N33FNXV6IrT2AduZaJlblwk3x7gMxMyftjhrR7V987cq0Sh+l wbEsjSVSXKyrydm0J3PwTb2caWMl4wNVEXAC1Yge7g+3RKY+9S+YJJ2k684VCYpHH/8p2LiXxjk Z6nAN4kUCM1Iw3BNrpXP3xkScIA9zRroDhT8fscLdB76ejMvd40h3R9lbBPClcfnvB92E+bSH4s gjgIICCf+V+fN0HDZiQkb6/OalW39dXYy1pNSZ9UFk4Uh3Sn9+eVA/I7bLcaH5h98T3Rdhg32j3 CFMAfhY3fHMYSzE1vOH5abwKiu1gkbhGKj0su2MB/hAULYgNxqyItwRE8y3UWATd2HOZKAukMp7 De8QDkJk6a6jJqGG61kPH5FIN8aaK1278OAfY+mTrS7548O/D8MymwrlecYm1hhVRaf6wFKuDwi lfuUA== X-Received: by 2002:a05:6820:611:b0:689:3c50:4952 with SMTP id 006d021491bc7-68be8fcb1d1mr3352283eaf.60.1775912635791; Sat, 11 Apr 2026 06:03:55 -0700 (PDT) Received: from ziepe.ca (crbknf0213w-47-54-130-67.pppoe-dynamic.high-speed.nl.bellaliant.net. [47.54.130.67]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50dd525fa23sm51017061cf.0.2026.04.11.06.03.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Apr 2026 06:03:55 -0700 (PDT) Received: from jgg by wakko with local (Exim 4.97) (envelope-from ) id 1wBY0A-00000002caD-2nEx; Sat, 11 Apr 2026 10:03:54 -0300 Date: Sat, 11 Apr 2026 10:03:54 -0300 From: Jason Gunthorpe To: Sina Hassani Cc: kevin.tian@intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, Aaron Wisner , stable@vger.kernel.org Subject: Re: [PATCH v4] Fixes a race in iopt_unmap_iova_range Message-ID: <20260411130354.GG3694781@ziepe.ca> References: 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: On Fri, Apr 10, 2026 at 11:32:44AM -0700, Sina Hassani wrote: > Bug: iopt_unmap_iova_range releases the lock on iova_rwsem inside the loop > body when getting to the more expensive unmap operations. This is fine on > its own except the loop condition is based on the first area that matches > the unmap address range. If a concurrent call to map picks an area that was > unmapped in the previous iterations, this loop will try to mistakenly unmap > them. > > How to reproduce: I was able to reproduce this by having one userspace > thread mapping buffers and passing them to another thread that unmaps > them. The problem easily shows up as ebusy errors if you use single page > mappings. > > The fix: A simple fix that I implemented here is to advance the start > pointer after we unmap an area. That way we are only looking at the > IOVA range that is mapped and hence guaranteed to not have any overlaps > in each iteration. > > Test: I tested this against the repro mentioned above and it works fine. > > Cc: stable@vger.kernel.org > Signed-off-by: Sina Hassani > --- > drivers/iommu/iommufd/io_pagetable.c | 6 ++++++ > 1 file changed, 6 insertions(+) The patch is corrupted but I fixed it up by hand and applied it Thanks, Jason