From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 E1A2D385D76 for ; Wed, 3 Jun 2026 14:26:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496799; cv=none; b=GGDc32by+Z4Kk/4gy638E3BM/Irp4CdumJ74lPznoSP+YP6jEU5naGuEOT7V2MByZ6l8cY20d3lWVOdMqeuFgE2cOUXcBSEfL4stWG2Hrf8549bueL2U1uoLUZuLOcbZYMZtTb3KNeQEvSxE/bP5f4PdVH3I2Gj6d0BR/1vZJWg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780496799; c=relaxed/simple; bh=W2KgLfIMUq9nYm3lPVNNRuC+rhvj0c5Ysm7uBo7Ldm4=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Eu/0peIi5B7Pgonehgg/itLdNPPSV28KHYEoY4KDiRfp11hiF7wAwNQTrApb1u4CUCOKDNWc8uec461i9Tk7JcaTwa+Ly4vqiqbNfqDLDYMG8Gsy7bqPBQrcyGaWi3CDRlzl82NiseI66prExVkRhL8tkX8OnWOloAZC582tq6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=lfjoIpEp; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="lfjoIpEp" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2bf2d865383so72455ad.1 for ; Wed, 03 Jun 2026 07:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780496797; x=1781101597; 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=mSsx/HNJMSWT4+DTHx2JEcyU4YhDU3KCMcSKr9Fho38=; b=lfjoIpEpvOxQf7b0pzoV61H41r7luLFBo/8j4ukE/1cP82vkmB/vEi0lX8J30PrJy7 xub1ZDCvr1wA+64qIjTJXmGMPNHnN4pkdObh9qf0WtL0Do0jg5yts3G0fnVnhbFA9phE 1vTS/YhMeWLESWIv22hSqKWtGSOnjQqk1wWbwiFf4F6fQRz2GWXt93sYhcuOuT80u2vX 60zIm+dnBEuTkqPvRsTRp4UyxWaHBbxdc8Prlg+zRMXZ73IAaHQ8o8RDqhRbaZ64nSBx phJrveUPrMHYiBp8FtXqW44ZtazJv4B/k9Mk7OVROn9WXAArbhlUQ1Zov2n/IKi/mm68 Pprg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780496797; x=1781101597; 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=mSsx/HNJMSWT4+DTHx2JEcyU4YhDU3KCMcSKr9Fho38=; b=rQv5fpoXIquiwqxrjfxfWjKOXCYG83EyzIBZgtjCyowHQZtLpV5WvlCL0ida8SLA16 m75Br71GDSgkZnsiyrOLmH8PAOSfQTjjOVcwJK9YNafdNqaHW3fF0IY/4ca5GO+tL3Jt I+9xPd4VEhRv9Q6LMtaHwOr6TCRRKa5OdwrdBACNAb+3YxQJtaeQeuv9D49w+WLRqWrl Ve9k2hLMiCHh1Gk2m4gV3VDY1aJOW2+0hn5jPemqTGpPzjPu3WzVQr9KxX5zxxGt1Dd4 W+3aorOQW8fgfJ9dSuJYuCWuxTsZST/Yt1kjN3Qd2Gq00A/yr19SH/xpJJo0unNtMgPM ismA== X-Forwarded-Encrypted: i=1; AFNElJ//c0aTgcvnO2bn5rcWb8OxIg0foiHXRoZRrO3eTl2JWDatoQwMfNOzRh/16Rt9c9cE3YCoORzhzaKG5YM=@vger.kernel.org X-Gm-Message-State: AOJu0YxrsotJr3YpAx76Mly/Ft2J89opBTzFhFApQZ3CNd4UtH0MZxMP a3PM3iKl0sqQgISCQ5gH7Ic7wsnwrJE0RTOwycTeqLYOs1L34li2wEeq/ps3Vxm8hg== X-Gm-Gg: Acq92OGJXbksFyqndTqoSGzEL1109g+OEcO0XQcX30BlBZ31mxktssj5EAQaHoT0VhI dfz9eXFuhrqlMq5UDGDojbWdUUDkgkc3OGSF1c/0kO/OkLD41XTw/LAq49or/OnUpAAvoyLUSjn 6vkqYxWTKLTiSs0Vs3TVZ4r7giZWoPyvQZzKV2jdLu+1909Fwn5m9SY/yV9JPBo+Rzk4xZKI+cc V7tNi3V3A29ELjtoX9uI5gs+42SFynCwvUaPxI6e0UPw0oi/6ywDuopSIBPntzrOk484mqNiRwl QSP69CuMgMb4+Uj1lSE0wDlzeZ1Gr/WEmijErFvo0U1lxbm2vOizk7YM1kupoyWZS2NDCqh1MUL RO7YJ88O9i1UfwyCY/lm0tZM0bXCOt6PpObwZ6q0sWfwqC42LyVzgS5ji0Sc59lIcG3Krq+VVUT y1irl34Amtp3Fg8feB49ghTC1ZylTvz5VG8CodTZDv1x2PQW+vBrmXUjNhQZ/KQp6SwCQ7KE8= X-Received: by 2002:a17:902:f712:b0:2bd:63cb:c5be with SMTP id d9443c01a7336-2c16fa7339amr1648965ad.5.1780496796592; Wed, 03 Jun 2026 07:26:36 -0700 (PDT) Received: from google.com (199.255.142.34.bc.googleusercontent.com. [34.142.255.199]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2c16629d240sm29068465ad.58.2026.06.03.07.26.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jun 2026 07:26:35 -0700 (PDT) Date: Wed, 3 Jun 2026 14:26:30 +0000 From: Pranjal Shrivastava To: Nicolin Chen Cc: jgg@nvidia.com, kevin.tian@intel.com, joro@8bytes.org, baolu.lu@linux.intel.com, iommu@lists.linux.dev, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v1 6/7] iommufd: Avoid partial fault group delivery in iommufd_fault_fops_read() Message-ID: References: <360cab4d4aeccb0bae275a970e2b3c340a71e0e0.1780343944.git.nicolinc@nvidia.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: <360cab4d4aeccb0bae275a970e2b3c340a71e0e0.1780343944.git.nicolinc@nvidia.com> On Mon, Jun 01, 2026 at 01:42:37PM -0700, Nicolin Chen wrote: > The cookie returned by xa_alloc() in iommufd_fault_fops_read() is per fault > group, but the inner copy_to_user() runs per fault inside the group. If a > copy fails mid-group, xa_erase clears the cookie and the group is restored > to the deliver list, yet done is not rolled back. The function returns the > partial byte count, with the successfully copied faults sitting at offsets > below done carrying the now-erased cookie. The next read() then re-fetches > the group, allocates a fresh cookie, and re-delivers every fault including > the ones already copied; userspace sees duplicates carrying the new cookie, > and a stale cookie that can never be responded to. > > Use a local group_done variable that tracks the per-group progress inside > the inner loop, and only commit done = group_done after the inner loop has > finished successfully. On a copy_to_user failure the outer break skips the > commit, so done remains at its prior start-of-group baseline; the partial > bytes already written past done are undefined to userspace per the read(2) > contract, and the next read re-delivers the whole group atomically. > > Fixes: 07838f7fd529 ("iommufd: Add iommufd fault object") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-4-7 > Signed-off-by: Nicolin Chen Reviewed-by: Pranjal Shrivastava Thanks, Praan