From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 89BB7390601 for ; Tue, 12 May 2026 13:17:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778591836; cv=none; b=OYUi3cC4GlDNCNJZCHFIQVsK0LQRhqHkvtvnUGCnPthO6+Bs6z3YmHvaBpL/UpBSas/DMq9TSb44iaGt1mKHA/S8QxmFpu7C5VGWv8zFYxlUMPcCOfW857vkDFEdNzYANS+cVxkNtmjs4YnFppW6WwSM9EnpoxgxhWeU9gTHTc4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778591836; c=relaxed/simple; bh=wwNRLIF1JFp5xt9HeapzPaIKxk407Y01fVL/BIECwnY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uBSVy53B7mgogURQxvGJlXOR80Oc+bVjT9SLN7SytQVd/MMlZCpVJ0e5e5uNYrGDwOJILritqYZ/ckja8goUHiubFLrLr0RQsuSvN2A0AV/hPIaS9nQttilX1YfGbfUU14cFupoMC8F0DXY4NyYasb8xGAM2f7w8uQ1d7mggtlw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KqGiBWlv; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KqGiBWlv" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-488a88aeec9so61723945e9.2 for ; Tue, 12 May 2026 06:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778591833; x=1779196633; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=qSTTjErtCCV7PDluuTX4InQQCaNvPmqczetdbYZrylo=; b=KqGiBWlvJ97L0+fCiJN2zFlQUEtHbxwmSSaIiI9BZw0QSZZdWxwf6xfhEoGYFtFqvJ MluAmPRVS4y1+rbAk9nlVmf5byTvQHLYsr1+cTlywgRFgfyUQV5Ak4z4ylIQElAkAfbA iZkJHoMVX5RgJXfXDI990SZo1g1Lzz5zjCIbV+CDrisEegNQCHuqveQq58KwzrJLWAig 1ouhNbypuJKjFscYnw0iMAWbAWZ4KIdYBYaBIdJvwDd1L+1bIrF3e+Bt++4QZ5mr6B95 iBlU0oSzui1Xc2rFJ0J4fCIuYE4mu9+lVbgpbtiJHKCHC2hZv/v54uuiMff9t2lnc27n 1nww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778591833; x=1779196633; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=qSTTjErtCCV7PDluuTX4InQQCaNvPmqczetdbYZrylo=; b=GWqPNPTsuekroRe0Uy0LqlPHThfA0q6xMLGX0nBvlsGRncy91WPIyzhOwuuV9ft5AD nl3Tu84IBAlJolKxyB05OHlE18Dpp3YLTencMjXiAnxT7AxsOajRmZj2EL2+Yt3WU+GI BEymYLz5XPcrUMaDvdjZKRKj3AdyK4FdV9PkUh7dZ/t13J/rjx5AaGOzDa0lZBqfr1qH 0OsLEXjVojJO2BRCeOdIJb4LbITFTdOdmBULs/qVfMyK+FFzAayYQvroHuy37n4yfAbr nqkXbRtHswXK/+aq0wEfdDYmikjIy6G/V+YjnmMFpy2zIGekkhVmMgl6x1kD197sZSQq vYGA== X-Forwarded-Encrypted: i=1; AFNElJ+x2O19Jf1biTXYffnP1W4JwURQYH9clFdRtgdAlr6pRzJE474VMsHrj7l2RW+s/51b+9+LohcHwybAt3w=@vger.kernel.org X-Gm-Message-State: AOJu0YwkzLeo26Fx1v//mwz4TCPpWYZOzhwlRjtR3kEwg9Ugr2jGbHhW RZy84R3XEMtyZbHtCxDnpSvw3acmQLTOU9yJ5NdmDgVVUoVlwTuZ5Ihc X-Gm-Gg: Acq92OGMxeu2nqZQbLOODGITRxpa4CemW9YnqeAclwdb+mg22OKmqtuPPXCoDBZ+k9P CtgBuqmRVLt7aakeWxm5YPQZBkBrtNs0j13Bvvw6JLXc7QqE/Zcr4DiWNKkUuXlXj+3lQI046c4 /wZ+v4jxLlQ5ZRAknNJUVTCVelIt3Z3bqcqH8qqvPzQIgu2wTNBgLkYea9RL6JX7ZmVnxn4fbJz u3oyw59PwZ/i7onu/HfvbsOqLU1rQlSDlBSS+9jjmJFZVxUB5J5yohUc6jaHQrlCrc2QDXEfHFH ZCOSFQt/ZrN8LCaGGuavvG/38OKZqMqeVnC0Tqg/g8lYApS+SLMIxfOBH25ReHdyyf6iYsuB2NV 8COscHVAGpjuxJMSMyPWLvBTWYcWQhlInZ8UjeT7Go2F+nM4m3EpS8nGfURKdNZIL+B4Ggg9xt/ ZXoNkiF4lUjRcYdBX8KfbC6f+Kbk0VpGjWViretM/wRfPYu9QSBkmoCWOHm3A4 X-Received: by 2002:a05:600c:6299:b0:486:d76c:fa57 with SMTP id 5b1f17b1804b1-48e706f11d0mr232288505e9.17.1778591832718; Tue, 12 May 2026 06:17:12 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48e8f42a845sm17282245e9.20.2026.05.12.06.17.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 May 2026 06:17:12 -0700 (PDT) Date: Tue, 12 May 2026 14:17:11 +0100 From: David Laight To: Alex Williamson Cc: Alex Williamson , kvm , Jason Gunthorpe , Kevin Tian , linux-kernel , Yishai Hadas , rananta@google.com, stable@vger.kernel.org Subject: Re: [PATCH v2 1/2] vfio/pci: Fix racy bitfields and tighten struct layout Message-ID: <20260512141711.70c49471@pumpkin> In-Reply-To: <20260511221609.3837652-2-alex.williamson@nvidia.com> References: <20260511221609.3837652-1-alex.williamson@nvidia.com> <20260511221609.3837652-2-alex.williamson@nvidia.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) 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-Transfer-Encoding: 7bit On Mon, 11 May 2026 16:16:02 -0600 Alex Williamson wrote: > Bitfield operations are not atomic, they use a read-modify-write > pattern, therefore we should be careful not to pack bitfields that > can be concurrently updated into the same storage unit. > > The split fields (virq_disabled, bardirty, pm_intx_masked, > pm_runtime_engaged, sriov_pwr_active) are mutated post-init from > contexts that don't serialize against the other writers in the same > storage unit, so a bitfield RMW could drop an adjacent field's > update. The remaining bitfields are touched only during probe or > close where no concurrent writer exists, so they stay packed. > > While reordering, place virq_disabled and bardirty earlier to fill > an existing alignment hole. > > Fixes: 9cd0f6d5cbb6 ("vfio/pci: Use bitfield for struct vfio_pci_core_device flags") > Cc: stable@vger.kernel.org > Assisted-by: Claude:claude-opus-4-7 > Signed-off-by: Alex Williamson > --- > include/linux/vfio_pci_core.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h > index 2ebba746c18f..24e8db5b1c0d 100644 > --- a/include/linux/vfio_pci_core.h > +++ b/include/linux/vfio_pci_core.h > @@ -101,6 +101,8 @@ struct vfio_pci_core_device { > const struct vfio_pci_device_ops *pci_ops; > void __iomem *barmap[PCI_STD_NUM_BARS]; > bool bar_mmap_supported[PCI_STD_NUM_BARS]; > + bool virq_disabled; > + bool bardirty; I'd put those two after the :1 fields to avoid an extra hole. -- David > u8 *pci_config_map; > u8 *vconfig; > struct perm_bits *msi_perm; > @@ -117,16 +119,14 @@ struct vfio_pci_core_device { > u32 rbar[7]; > bool has_dyn_msix:1; > bool pci_2_3:1; > - bool virq_disabled:1; > bool reset_works:1; > bool extended_caps:1; > - bool bardirty:1; > bool has_vga:1; > bool needs_reset:1; > bool nointx:1; > bool needs_pm_restore:1; > - bool pm_intx_masked:1; > - bool pm_runtime_engaged:1; > + bool pm_intx_masked; > + bool pm_runtime_engaged; > struct pci_saved_state *pci_saved_state; > struct pci_saved_state *pm_save; > int ioeventfds_nr;