From nobody Sun Feb 8 09:17:04 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7249732AACC for ; Mon, 5 Jan 2026 08:23:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767601439; cv=none; b=CCRqFveA0dQrc6t4vcI4zP7R+nMjyNSbULUg4+DPCT9tGGPgTPw3DQyX0PezzOB5qk8bt8MXS49JVxu1nLfup/zm+yTFWl++3DEz07V/KJdJasaqzmFvM4iHRmr4FOhEu45ziZgiybimWNVfDpVlV1KJCU4TbBpG0OLtBGq7n58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767601439; c=relaxed/simple; bh=5+AqmnW4PA/6edyK6U8dTvigNJLqhC7cXNvV8IIXjTk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NkmtQTnV9leA0fmmA+Smti3TV/F+tZPtI5WzHZA8oBhzAWW6R412H452EoTyPACNP3K9uEId6dSg2n8nffaCp7NVSo7NtxdZYsgmlW0zJZcb4xo0zgrwxVDtAS9VEuHYtRo3Iry19ccIVC/G7DeyrM1kV1Z2Nk0dN14OH5rZBXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=JJQonVME; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=uMRMouiJ; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="JJQonVME"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="uMRMouiJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767601432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=F5gbCeCGdOPWPA7+HFhpRVcPZoxhZ6OosT4+6pGbwi0=; b=JJQonVMEcOItokzsUwiqnP3io1Vx/zxDy2HJhR7fArK7F+T3OQNYmTlxXz4tM7G93/kDfq n+05vl+jskjAaa+CurAeXka56F8nUW++06U8r1BCBQ0yiI2k1lsNwiEdpuwvYnqwA2HmdF VioRLxFYzzBETrM61V0Wrw1DRHt4XA4= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-609-zGoH0mEnOOGnQzQpDsD9Ng-1; Mon, 05 Jan 2026 03:23:51 -0500 X-MC-Unique: zGoH0mEnOOGnQzQpDsD9Ng-1 X-Mimecast-MFC-AGG-ID: zGoH0mEnOOGnQzQpDsD9Ng_1767601430 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-477a11d9e67so88358355e9.2 for ; Mon, 05 Jan 2026 00:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767601430; x=1768206230; 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=F5gbCeCGdOPWPA7+HFhpRVcPZoxhZ6OosT4+6pGbwi0=; b=uMRMouiJplEJw0f5B11uiIHSrH3LOhXawBmO9iJbtMCtXnX76GJLVIoCkShGK39nz3 yp/NJ7wiFbxpJw2CqA2z5GllV5j3v4RQodT9PE3uofpmD/LQL4+/+ePrrpw1yinD3uu8 XIxgLJ0DWDIUKFBxq5afHUXbvrWFgjVsEY80bWFw3F61Un3Tpu0pJG5jVHbyKeznPoC1 kivOJYvUuXJZkuX8nyKEn4HczMNlKVdhiVmQXmTptPA1XNeK/R3VbMXt8ZnWptwL4v2a tfGAc6lMpotFue6H+9pQit71eSYmLEbJa+KluiO5wx5Ofeip7XGSq9shXAFsF7BCYI6S 7Wsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767601430; x=1768206230; 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=F5gbCeCGdOPWPA7+HFhpRVcPZoxhZ6OosT4+6pGbwi0=; b=ZBktc268DKBWAcEP7R8yaopEvw9XUltVPvplyxZhMoDGaeTPxqQIrje/SMvHVX/z1a 2dQs3ui5OP8bA31NSsK+lg5zKuV39EGsoPN8cXtN+iE4TGX0gzdy868aOaDUWU4UwUEa eXY40HC6kF4nlWV2cphGnXIi3b88UemIbuTnNdYCIYhBZx3rQaWuasBnUhMbO2G3nPih IXaoHqLpJy7dRK2X0GcLi7MNPNkKQ470/RimtJBJ6tAlMhbXF5LXP4+fSJIUCOTPEa4p jQ+F727GUEelAvjac5T53YRrDAFs7d2pDpEHSMKHKh0Y1w65Ox9Bik3lNR9xK5cuq9Uo 9MEA== X-Gm-Message-State: AOJu0YxJetE2Y418pJEgX8pWf6lV19Z+jyPkziUJNReT5A+7qkehcvQc 9dJiLYcvCols6TFCoC4QhoY4o0OHfPYCoO/ibtlKv02/mf5DFkZwoWJT07b6W9MFR1rRnUHeG2O aEe40akQ8Tjej+cv1uLo8eMHmDoYwCbAODWsgEh63gj+G3h7LJJ9AfMbltIqbpqd1IbXoHG9Tla qbM2Qxa0ucN8vhJrbt5/qhk82FnxCe1DIzP7QsinCdRyw= X-Gm-Gg: AY/fxX5I1zjRKliC9onKkSwGc8ZGDpYayHBdDYqUjkQ9o3dJp+klWLP1aDbakM0sY4/ 5BjxSl31UaJjpVpXBCNCbs5lRtTqLYXZKWKYqsjJlB5xi3XaTKKXx3sNw6ScGBs1lzjYKXXv492 5S5ETAxT96aCkmDDihKD6+sQN00240rsjh3k00+nHBqVoPeKzBALT4upN+n36eBU07WSoBS77Ce zI3D/2ZrlcuYmIGbKMtV1pTO0y6Qpq/IkHoaI3srCryEaq8s0JH7LP94B0ukOFXaVGUvVQk1tLE AlOBYwrXIm9PoT5eF7lOAKZiymIkuNxXCKlBU+bWO48JQBgd81Vhr1SSz2N6n8+L2Vt8s3x85ha 0rWmH8AxkoVP4nBdCeDvdhg4YyvIPMYy3hQ== X-Received: by 2002:a05:600c:45d3:b0:47d:4044:4ada with SMTP id 5b1f17b1804b1-47d40444b44mr461188395e9.13.1767601429901; Mon, 05 Jan 2026 00:23:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IEMwRI3MA2DTNX2WICs7qzlXbxMYmhW2AMGnc8lzpwkl8AC0h1+xs4bbHr0vh3wAjjaNt43Dw== X-Received: by 2002:a05:600c:45d3:b0:47d:4044:4ada with SMTP id 5b1f17b1804b1-47d40444b44mr461187535e9.13.1767601429208; Mon, 05 Jan 2026 00:23:49 -0800 (PST) Received: from redhat.com (IGLD-80-230-31-118.inter.net.il. [80.230.31.118]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47d6ce21fcdsm154121375e9.0.2026.01.05.00.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 00:23:48 -0800 (PST) Date: Mon, 5 Jan 2026 03:23:45 -0500 From: "Michael S. Tsirkin" To: linux-kernel@vger.kernel.org Cc: Cong Wang , Jonathan Corbet , Olivia Mackall , Herbert Xu , Jason Wang , Paolo Bonzini , Stefan Hajnoczi , Eugenio =?utf-8?B?UMOpcmV6?= , "James E.J. Bottomley" , "Martin K. Petersen" , Gerd Hoffmann , Xuan Zhuo , Marek Szyprowski , Robin Murphy , Stefano Garzarella , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Petr Tesarik , Leon Romanovsky , Jason Gunthorpe , Bartosz Golaszewski , linux-doc@vger.kernel.org, linux-crypto@vger.kernel.org, virtualization@lists.linux.dev, linux-scsi@vger.kernel.org, iommu@lists.linux.dev, kvm@vger.kernel.org, netdev@vger.kernel.org, Viresh Kumar , "Enrico Weigelt, metux IT consult" , Viresh Kumar , Linus Walleij , linux-gpio@vger.kernel.org Subject: [PATCH v2 14/15] gpio: virtio: fix DMA alignment Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The res and ires buffers in struct virtio_gpio_line and struct vgpio_irq_line respectively are used for DMA_FROM_DEVICE via virtqueue_add_sgs(). However, within these structs, even though these elements are tagged as ____cacheline_aligned, adjacent struct elements can share DMA cachelines on platforms where ARCH_DMA_MINALIGN > L1_CACHE_BYTES (e.g., arm64 with 128-byte DMA alignment but 64-byte cache lines). The existing ____cacheline_aligned annotation aligns to L1_CACHE_BYTES which is not always sufficient for DMA alignment. For example, with L1_CACHE_BYTES =3D 32 and ARCH_DMA_MINALIGN =3D 128 - irq_lines[0].ires at offset 128 - irq_lines[1].type at offset 192 both in same 128-byte DMA cacheline [128-256) When the device writes to irq_lines[0].ires and the CPU concurrently modifies one of irq_lines[1].type/disabled/masked/queued flags, corruption can occur on non-cache-coherent platforms. Fix by using __dma_from_device_group_begin()/end() annotations on the DMA buffers. Drop ____cacheline_aligned - it's not required to isolate request and response, and keeping them would increase the memory cost. Acked-by: Viresh Kumar Signed-off-by: Michael S. Tsirkin Acked-by: Bartosz Golaszewski --- drivers/gpio/gpio-virtio.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-virtio.c b/drivers/gpio/gpio-virtio.c index 17e040991e46..b70294626770 100644 --- a/drivers/gpio/gpio-virtio.c +++ b/drivers/gpio/gpio-virtio.c @@ -10,6 +10,7 @@ */ =20 #include +#include #include #include #include @@ -24,8 +25,11 @@ struct virtio_gpio_line { struct mutex lock; /* Protects line operation */ struct completion completion; - struct virtio_gpio_request req ____cacheline_aligned; - struct virtio_gpio_response res ____cacheline_aligned; + + __dma_from_device_group_begin(); + struct virtio_gpio_request req; + struct virtio_gpio_response res; + __dma_from_device_group_end(); unsigned int rxlen; }; =20 @@ -37,8 +41,10 @@ struct vgpio_irq_line { bool update_pending; bool queue_pending; =20 - struct virtio_gpio_irq_request ireq ____cacheline_aligned; - struct virtio_gpio_irq_response ires ____cacheline_aligned; + __dma_from_device_group_begin(); + struct virtio_gpio_irq_request ireq; + struct virtio_gpio_irq_response ires; + __dma_from_device_group_end(); }; =20 struct virtio_gpio { --=20 MST