From mboxrd@z Thu Jan 1 00:00:00 1970 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 B495532938E for ; Mon, 5 Jan 2026 08:23:36 +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=1767601418; cv=none; b=UNcu/95DscjSV4d7us+T1rkmAfmp4Ko+X4IpjG6QcMdJhIRhFq6KJM0QYBSgV9CT9grEl7EggMbI5BcyLKdZwcshj72GfNq9f9owAoYVQyPphUyLF5ddsfjq+N2nN9M7y3zwBWiep+Gdlo5JhDnMLRNanRARFqemPq8lnoE5jYs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767601418; c=relaxed/simple; bh=S9cU9rMSKLAHqC3C9VUi030/VnGNztyhDP4UPj+0Vaw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MnAfe0MA4aiB/Du08m4v7UvNSuyMbUUUn+9d59OAppoiCDFrxSLO8s/IUitU4R5lsrun+zm3SkOhDH0HEr5CcvLjM7/x5xQ+K2BHCz2EX06lUcnCIuqXr0bEd/k5LjQvnx0HR/BjjKbRzTzaWg9vFbf02YK41mQIohZTWVDUJHQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=fail smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DObQ1Wju; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=J5VSpuzC; 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=fail 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="DObQ1Wju"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="J5VSpuzC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1767601416; 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=TvLvTQPEJKAtkqGovGo2GHeF0+EOLKvEuwFpv+PiquM=; b=DObQ1WjuRpWScNuAi70c6Z3ZI7/IJ6pT2ZpVxF3/1L61WkR06wT1jZm/Gqxd7H+oKYbLNX OA65CF2Vm33IyQKdUPGB7kbjn3c7f3yB7w4gU1Y0PGrJxnL72+8bMin9bLRtuiGjYPf09j SQP1SEuKoIw7EFLI1a/9i3QfoFU5eKA= 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-549-bZYbLHooNPaBwvwZ1q6Qqw-1; Mon, 05 Jan 2026 03:23:34 -0500 X-MC-Unique: bZYbLHooNPaBwvwZ1q6Qqw-1 X-Mimecast-MFC-AGG-ID: bZYbLHooNPaBwvwZ1q6Qqw_1767601413 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-431026b6252so12388476f8f.1 for ; Mon, 05 Jan 2026 00:23:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1767601413; x=1768206213; 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=TvLvTQPEJKAtkqGovGo2GHeF0+EOLKvEuwFpv+PiquM=; b=J5VSpuzCfEHaaV0PfngwJ/PAHynoUlG+tVufyQ1It+kh+BWnkL/pDXkLquPvP8PhaE RTkkg+5x8fqgihaCUpJZpFJAgqYL8ICnp+FRHSEDIQLIBoTaVdSxtFHlzGdXIjRLvKiI LOw9l3ILo5anD1bPQovJIXG3YH8o2P0bPOoK0hsSplrw49jxfi5FpRHrZHiCVfRMNwBi bhgwMNhrGDrYP7Q37rAK8EfOwEfopGXHftivLnRz67hPRVFHp/LlhvCihl50f1fsorSk rbPD/iAw1E//M4PMcKsOljyg/HT+Z+5LJXzBzFwgUXasV50sdG6MMsj8Yz+vjiVysoUX D6Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767601413; x=1768206213; 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=TvLvTQPEJKAtkqGovGo2GHeF0+EOLKvEuwFpv+PiquM=; b=l5A0n2ZmSrdseOX3Qo65TkNgJeCBJiEdfpEZXAtW0oLvDK4GK2VjFvPk1LgY6wMutQ Fs5lNf9jPug4z1sTFN7pHyhgNt9Ycxw+O4zDhE9mTfTBeWxpQ1TwGaKMqBy/fiSNrvRo lgCR6J/+4HEEXuz4uuJkCXB7UktL/nq0oVSp+ioJO5PgNqItqgxG4Z6qMKUuDRbDNtAf FXbZynxq7RN0KPWFrF1Xn8GqZphv+XLpVvgvpx4SgqXgrQN91uNP50qKwnY88UQFuq+r gS0AgvTYHA1izeAP1ZdcKxODA4Pi1mmg7cnquwRno0a0+7/y9Nj/gpHe/cAVh5mYZrUo 5CSQ== X-Forwarded-Encrypted: i=1; AJvYcCXxWklwzxSwFE9xP+wjLvX7jDgSjuAwl5QiB0Ko9iKnRt+v7c2lYryJ4zFxTtC85fhczt3rc0w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5YvKLty7bsiJnKxPSC3omXP/xdQJHcQFWHoOfv5O9zNsZjWzl Jcka3z+dpkWdHxirqWPQIB6PGhg7CYqTYlj8zCbbn/fDUszzKrG0l2K3xqnVo8wLv8g5oBMayHT E+xrVz2ag6ifnJGVJtNpvqIUahAndY+mseh6kUdWwiVbygBGh6nHv5Sqrxg== X-Gm-Gg: AY/fxX7vLkwlRBvD/Q76dA4unSIHT/h7hbHg20ZVGoCAatnEpZKLWcR4e3tdSUpnoUs HWcAjcWhJ+HEJ37DLgXAgm6fM1+udSVipUgmkQ6tBl5GgvYUxd/qIzdHmZ9NRP9fX7aVr7WBnUZ NEHtPAPsN+fsqEO9plqn+k69LmdWUHTK/Alvxg8FDLX9eTonVIZmSliiVM+vP1DeartinK83GC1 HR3D2wGdtKfNgnJD0+HXJ8yKegd8cKaMXg1Wp5DLFZ4PqhA9/1rEDpPETst5FhJvTpH/K+DIfid MeAJnwryII9ajpb/IN/vqzUFP8WSmFMuGaim8X0+M2r7TmuFrCpqxhL/UL9E3e8GeJWYPo3jtum 90cHIJ5ckaGYq+BtMj/2rGwD7/90PJD4EXQ== X-Received: by 2002:adf:eb04:0:b0:432:84ef:841f with SMTP id ffacd0b85a97d-43284ef8d0cmr31362899f8f.38.1767601413470; Mon, 05 Jan 2026 00:23:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IFx7eWbROO38mdjmsXsZ8eTRhzoo1KnfbPFeP9XiXzVU5+PKMGQRYrz1a7izR0YG2kvu7gW1Q== X-Received: by 2002:adf:eb04:0:b0:432:84ef:841f with SMTP id ffacd0b85a97d-43284ef8d0cmr31362856f8f.38.1767601412963; Mon, 05 Jan 2026 00:23: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-4324eaa2beasm98160481f8f.33.2026.01.05.00.23.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 05 Jan 2026 00:23:32 -0800 (PST) Date: Mon, 5 Jan 2026 03:23:29 -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 Subject: [PATCH v2 10/15] virtio_scsi: fix DMA cacheline issues for events Message-ID: <8801aeef7576a155299f19b6887682dd3a272aba.1767601130.git.mst@redhat.com> References: Precedence: bulk X-Mailing-List: netdev@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: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Current struct virtio_scsi_event_node layout has two problems: The event (DMA_FROM_DEVICE) and work (CPU-written via INIT_WORK/queue_work) fields share a cacheline. On non-cache-coherent platforms, CPU writes to work can corrupt device-written event data. If ARCH_DMA_MINALIGN is large enough, the 8 events in event_list share cachelines, triggering CONFIG_DMA_API_DEBUG warnings. Fix the corruption by moving event buffers to a separate array and aligning using __dma_from_device_group_begin()/end(). Suppress the (now spurious) DMA debug warnings using virtqueue_add_inbuf_cache_clean(). Signed-off-by: Michael S. Tsirkin --- drivers/scsi/virtio_scsi.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/scsi/virtio_scsi.c b/drivers/scsi/virtio_scsi.c index 96a69edddbe5..6ff53fc8adb0 100644 --- a/drivers/scsi/virtio_scsi.c +++ b/drivers/scsi/virtio_scsi.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "sd.h" @@ -61,7 +62,7 @@ struct virtio_scsi_cmd { struct virtio_scsi_event_node { struct virtio_scsi *vscsi; - struct virtio_scsi_event event; + struct virtio_scsi_event *event; struct work_struct work; }; @@ -89,6 +90,11 @@ struct virtio_scsi { struct virtio_scsi_vq ctrl_vq; struct virtio_scsi_vq event_vq; + + __dma_from_device_group_begin(); + struct virtio_scsi_event events[VIRTIO_SCSI_EVENT_LEN]; + __dma_from_device_group_end(); + struct virtio_scsi_vq req_vqs[]; }; @@ -237,12 +243,12 @@ static int virtscsi_kick_event(struct virtio_scsi *vscsi, unsigned long flags; INIT_WORK(&event_node->work, virtscsi_handle_event); - sg_init_one(&sg, &event_node->event, sizeof(struct virtio_scsi_event)); + sg_init_one(&sg, event_node->event, sizeof(struct virtio_scsi_event)); spin_lock_irqsave(&vscsi->event_vq.vq_lock, flags); - err = virtqueue_add_inbuf(vscsi->event_vq.vq, &sg, 1, event_node, - GFP_ATOMIC); + err = virtqueue_add_inbuf_cache_clean(vscsi->event_vq.vq, &sg, 1, event_node, + GFP_ATOMIC); if (!err) virtqueue_kick(vscsi->event_vq.vq); @@ -257,6 +263,7 @@ static int virtscsi_kick_event_all(struct virtio_scsi *vscsi) for (i = 0; i < VIRTIO_SCSI_EVENT_LEN; i++) { vscsi->event_list[i].vscsi = vscsi; + vscsi->event_list[i].event = &vscsi->events[i]; virtscsi_kick_event(vscsi, &vscsi->event_list[i]); } @@ -380,7 +387,7 @@ static void virtscsi_handle_event(struct work_struct *work) struct virtio_scsi_event_node *event_node = container_of(work, struct virtio_scsi_event_node, work); struct virtio_scsi *vscsi = event_node->vscsi; - struct virtio_scsi_event *event = &event_node->event; + struct virtio_scsi_event *event = event_node->event; if (event->event & cpu_to_virtio32(vscsi->vdev, VIRTIO_SCSI_T_EVENTS_MISSED)) { -- MST