From nobody Sat Feb 7 23:33:54 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 443EF26C3BD for ; Tue, 30 Dec 2025 16:40:37 +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=1767112839; cv=none; b=YD+8SUcTjedR7Ydj0yOft9cHjAaULb9SocMO2Tr66XkaljZ71cbkNhjegaRJOIVUUASDVkrBS/FvpmRMkg8D8sC6d4HsBxm7iNvHcdpOe6jd5/Xx0tpAQPX06knVQNDjqrBJJtaHZ7yfSjttbOLYdCfAONeEZLMaH9Vpm3tSxlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767112839; c=relaxed/simple; bh=R3ssxNR/IfKvvzigNkiBKuIwzZmdFCE30Vek2VE5a/c=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=IMBE9Wexaz9DEiH9YdrB+vmLT1Ex+H0lVkfR8/V65Hp0Wk6HlBeGK2BNyRGlZdhYzuoCuw+igQFwa/e1ASQvxs6mzj5bfFMYf7+6SgU9nEP2cuACmTmvagUhXWT9xmZJzvnzc5+7uZeqqOjX1onF59UgazB4vCglVkJPrIZtb+E= 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=CDo8618x; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=tGsVd1OR; 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="CDo8618x"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="tGsVd1OR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767112836; 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=7J8z1fD7DSMGZ6iKBx0OqXIx7XfW+ZYePKweShXuH2A=; b=CDo8618xqajMYlrIganDweT8AiGYtCkoWL2waz6M6UJJ78xULg6Xf2r37MrUCzU18evdkK YPMeCIqdnKCMkyIKoc9m3X1R86c2sn8+7/6qBkCYPvCl68I17EVe+Rpai7To6YzRaVdRAF 9xDz/cUdBFkP/auH7HPtWHP0TFdclfw= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-695-z0WdWdkTMlW48qvYh7DvMQ-1; Tue, 30 Dec 2025 11:40:35 -0500 X-MC-Unique: z0WdWdkTMlW48qvYh7DvMQ-1 X-Mimecast-MFC-AGG-ID: z0WdWdkTMlW48qvYh7DvMQ_1767112834 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-430fcf10287so7069975f8f.0 for ; Tue, 30 Dec 2025 08:40:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767112833; x=1767717633; 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=7J8z1fD7DSMGZ6iKBx0OqXIx7XfW+ZYePKweShXuH2A=; b=tGsVd1ORU0Eh9v8efXZT1lh+FgCYbl5O7LiFefA28EVmRKhFwjKIK+BkIFPA+HquNW I/iCySQ/Hi/bFw5TujZNT95fbDuwnDGI5r2pHqghiLDrfJvQvWAK2OtX6kVUYKSdDHP5 MzILer/dNKCGfsj9rQs5AUI4Y6CUNV8J6pMAB2WE94zrFEkLHx9rWvO9YDwfm5VrO+VR Kl3R35DSLBsN9u6Q9JLMx2Ew0qnQqn4QpfMGN6a9DbosJnFKLKUNTjaoDhXVO+Oh0812 dSSgXSlQks9mbZxqnSW/569qUnJLt2nbu1hdPQdOW8Hob/Bsg2dhVoSViq+DAHYiHGpJ 1LGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767112833; x=1767717633; 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=7J8z1fD7DSMGZ6iKBx0OqXIx7XfW+ZYePKweShXuH2A=; b=uo/I3VyE972djlOpSAjR6Vo6I1dkwbFilqSFcIck8KhHFKmGhcfdOxkmFQku4eYjP3 Wr1V5riMzS2H/srQAjHizaP8p68FWwOvICgqph7OQgCmN+68sILllt8LRiHw0+tM2/1F RXnu2teiWmOB0o6eH36zf6f/iaC+GbXCLxPjDVJi12fPTPW+c8b4/CGQ1fo62G/p+bxq JlxFjp0eq42VOJhEbSSR3m8zxx6C3rBZEpS79K/D0lpn29ppggMzIjfFEy5V2DY19+cC DdnfiFj8BH5d1hpeeMvFt/WsI73FdBDyUAxKDf+4g/zRHr4lB+WJpqLwKFhc2Dfuurbx D31g== X-Gm-Message-State: AOJu0YxQ73fS2Kt9OYnTX8SGGeaiUZYkRzzzSh/owU7ODqHIZVyuXa1r AWfg3O2Hj96UmAKPAjwTJo8XfWjFa6qDIHv23PHeuO5Tc1AVqynZMEIKXGt7TnOogSZ5Hiw/O1y FupesHspMELnX3OPRfUENwJZVNnhkh9h0VcKapG4no4voSkYbAN4R81Wf+M0/iKozO8pkbZioxp IZNP2rlatJDaBPZwuBxh89My/xGwhOfAALSSGD1gDzShE= X-Gm-Gg: AY/fxX5G8FrLQh9Rh2YgdctjwjuhITlPLNzabcOE64uJBA9ma+Bi+Q/+DcxAkIkoL/0 XW6LE7ZxMsbiryT+6tHZpXz4CrjnYL1Ih1wjdKaABYMhLZ2BtYpZ2hM0lmGbNLc8+2A6E0f3uMT iEC2ZRGVMHpDlHLnF4GKHSOBWcvJ7Bee1OlUrQ1d9u7DYBBMzLFnEYaYzTNwcjxyue/bpqgVZy9 mwRBJnofOCkuRniA8NI/LzKwZk4tcmcU1nwDoK2O+Q+ZTZ22J13kVAhH4n9Ge3k8XD1YTE6JSzt /c1GoCv8elPwJ3DFUnOmMr3+GtO0mf4oDa5gBlhiDFndkO4+Hi+165AO9ZG1nMo379NpAM62ik6 gSPfgw8+UMyVeY7bbd3eLc/gE4o0cfWZ9Ww== X-Received: by 2002:adf:f144:0:b0:431:855:c791 with SMTP id ffacd0b85a97d-4324e4c1501mr32588464f8f.3.1767112833463; Tue, 30 Dec 2025 08:40:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IECVSdNBMTG9k8N96cOa931b+MOajxv263SWbXaTmkKbkTS3ub+IC9yjT+L/YMFbjvC3biqWw== X-Received: by 2002:adf:f144:0:b0:431:855:c791 with SMTP id ffacd0b85a97d-4324e4c1501mr32588393f8f.3.1767112832791; Tue, 30 Dec 2025 08:40:32 -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 ffacd0b85a97d-4324ea1aef7sm69573295f8f.7.2025.12.30.08.40.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 08:40:32 -0800 (PST) Date: Tue, 30 Dec 2025 11:40:28 -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 , 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, "Enrico Weigelt, metux IT consult" , Viresh Kumar , Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org Subject: [PATCH RFC 14/13] gpio: virtio: fix DMA alignment Message-ID: <6f2f2a7a74141fa3ad92e001ee276c01ffe9ae49.1767112757.git.mst@redhat.com> 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 now 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 platform. Fix by using __dma_from_device_aligned_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. Signed-off-by: Michael S. Tsirkin Acked-by: Bartosz Golaszewski Acked-by: Viresh Kumar --- 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..32b578b46df8 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,12 @@ 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_aligned_begin + struct virtio_gpio_request req; + struct virtio_gpio_response res; + + __dma_from_device_aligned_end unsigned int rxlen; }; =20 @@ -37,8 +42,9 @@ 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_aligned_begin + struct virtio_gpio_irq_request ireq; + struct virtio_gpio_irq_response ires; }; =20 struct virtio_gpio { --=20 MST