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.133.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 42B1629D273 for ; Wed, 28 Jan 2026 10:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769596488; cv=none; b=SuuqEEDHuw2fm1Nsr9Opx2asnTnmTmt6Yn1h1VePisi2J26Y33Gyn2gMvzoGYNxFKmeEs+1N6sbr66NiA9IEXzK66Pn28r1PVuLQJClWOse9jBBx2X0S7MGKqeRuk3nidpOs0LM5kViatBMfnMpSaYRZdiqyCK+meoCMepnIMuw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769596488; c=relaxed/simple; bh=DIMHnVfDXB1z87w9DSCt0QqFUkafjlD58pI3jDxUdKM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=YBEkfkyxX9kracGbIAHH/mbOJC8Sqy8CkCKCZN+MTj7MbhN0YA6oN0wrdWBy5w5rBjUhMe2nbORhInwK5s8TtWXW5TEW8r0noPZzuOdkIy3ai1Q/NqmLkHGngKat9gGDiktxgr6vlSU+YBbHaiPbNur2Nzh1F6xZqOJhJRghBNk= 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=MhbI5Xib; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=oW+n9KHA; arc=none smtp.client-ip=170.10.133.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="MhbI5Xib"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="oW+n9KHA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769596486; 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=N6ko7Ld3Ll9plNmeAWA79rDhRWMcWQUQkhGqrz2ITcY=; b=MhbI5Xib5vMbjQ2Tuv+JPB5VmlaAIPBOeUV/jFLOtd/ukhPHqnL56TfLwDelbA33jruaJA Hj4EyfyV6RI4l/hZr2rFPi8qTYIxGOoAGCu+gJ6Xwq9FC6QAZcykOki+IWyaiuQy1HjBn4 OdcZuiaZnFbaTVZxy36R4XQcoXNiYKI= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-A0NOOaPGOvqjvvdP2KDPNA-1; Wed, 28 Jan 2026 05:34:44 -0500 X-MC-Unique: A0NOOaPGOvqjvvdP2KDPNA-1 X-Mimecast-MFC-AGG-ID: A0NOOaPGOvqjvvdP2KDPNA_1769596483 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4806fc58fa5so3965175e9.2 for ; Wed, 28 Jan 2026 02:34:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1769596483; x=1770201283; 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=N6ko7Ld3Ll9plNmeAWA79rDhRWMcWQUQkhGqrz2ITcY=; b=oW+n9KHAVOAB19mYSPufbkisI2bM9mtcFkY6nMN5yL0EJKoUPXydCx3ywEAuOCIOdH qrTVXyorVHmlDvOekNf0FZuO4VJve/3/uLNQk1kBWVJt2FlGv+eecSHCXdmDwW9GDbFv nrjBYyORmdcoEc7oLD3MieVF6IBgoX+NIy1Fkzk/De0BOInmlf8LhP68oQVr6UdUqndD 4ULf/Peq9HVSH+noIOFbNjUPW4j19zpPETYs33LsJg9mpPEz1x+c6MpnVL2IJApaD8PF 7BzNkZH6EjvShBtpiWI1WVfR4EJJGB5eLMPMFbfDojbinwPy5Nb/4YVVVxZ3Te1MuJ2F dn8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769596483; x=1770201283; 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=N6ko7Ld3Ll9plNmeAWA79rDhRWMcWQUQkhGqrz2ITcY=; b=Wcku7mxq4hwQ3dGeZVepQ+LfM5Fxn3sbeHVV7uJdKzSN/R0uSocWMqO2dzJ5C74muM mXO6eTZszmoCZ3YRyfako3rKluUEVajUgmGQ+3upjKTqHoaO3dZLtwLvBbv0NShjHUGr 0OOO43drHhbhsrpcYAyYKOMxeY16CHv1m40WoFvs0zJGCCkWAJE/PDo7sI1MvaUwxOHc 9h5M9uFjZKORBdcWoPqF+9chwPROqSKTfwbXG6nVNFiOi/8ZaAOpX8+BQtF3vBvDBXOL xVF5VQPg+LVk7WRtoDOfJZYHuoIMBL+o02cupP2HG/fXT4mlkVrhWvPOAs0dKqZlJm1+ QvHw== X-Forwarded-Encrypted: i=1; AJvYcCVzKv//AgR2rIscFvgiGT7MyP1EB/FNoxYk7QPiNNGamy/jg1+OaGZqWo22isWM3NC8L3pCbqJt2SGYsII=@vger.kernel.org X-Gm-Message-State: AOJu0YyHA5DzhWv4u2HtNQNnp3zOoulmtti96Y0kPPl64hTeJy5MOFC7 UXKQxbKcwx7icOqb/56f7uX1ny28fccMv+BuZfPXi03+9uwG1DBY+mVLI12DUyv/iwu7gx0R0Pu XXLQz2hGgU0MSiCav76U/bayIs8IxfG1GtnLpi00fObbD/XKCOdominQnB2T5jbGdBw== X-Gm-Gg: AZuq6aLxAiYt2sQBZN4dV6myFeG0/YbhwDcF3DYaXhNqKtilIrwB+YQan1Hyk+EpJzg T6w+ZXF/UcyYWZfLTTm2l6Vzufq6WWCw5ZWcR/KZ2ya03ra+k6XkRty13eSxmX97xCgr8tXFSx1 FfJibSZ8UuQktoJTTAbtMokkHSYeBXGVHtPNalWugmw/WHnTCmmsJE6CyWfMioMmgCYkToSkdHK KFulOT4usbHnBgnZ3MI5V7mBNdC1H0phNXl7hVOnJEuxguCLL12P1TkCKh4LD1STF/kPEHqaAmu KKmWEaUn2Iy6k79U/fLZTF3UgqiyIgHT7Nsv2M4QTBKRNuhmslFv/O2MI8Oox+lpj0WOhzc7oa4 izkqkRTiJ++Fy+b1lUOpxBYoCcumirdbGIA== X-Received: by 2002:a05:600c:8b63:b0:480:4be7:4f53 with SMTP id 5b1f17b1804b1-48069c5fad8mr69793915e9.31.1769596482790; Wed, 28 Jan 2026 02:34:42 -0800 (PST) X-Received: by 2002:a05:600c:8b63:b0:480:4be7:4f53 with SMTP id 5b1f17b1804b1-48069c5fad8mr69793595e9.31.1769596482380; Wed, 28 Jan 2026 02:34:42 -0800 (PST) Received: from redhat.com (IGLD-80-230-34-155.inter.net.il. [80.230.34.155]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4806e0f6dacsm18275365e9.0.2026.01.28.02.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 02:34:41 -0800 (PST) Date: Wed, 28 Jan 2026 05:34:39 -0500 From: "Michael S. Tsirkin" To: Alexander Graf Cc: Johannes Thumshirn , "virtualization@lists.linux.dev" , Jason Wang , Xuan Zhuo , Eugenio =?iso-8859-1?Q?P=E9rez?= , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v2 1/2] virtio: silence KCSAN warning in virtqueue_get_buf_ctx_split Message-ID: <20260128053356-mutt-send-email-mst@kernel.org> References: <20260127152524.200465-1-johannes.thumshirn@wdc.com> <20260127152524.200465-2-johannes.thumshirn@wdc.com> <184ced70-f3ec-49c0-9b18-96f0ad044a78@amazon.com> <42d57017-88b6-4ab6-8fa9-10658d268fb6@wdc.com> <4fde2f6e-d272-4aa8-9701-63bc6b7e7d16@amazon.com> <9004e3b6-fbd0-42a8-b722-bf6d25833dd7@wdc.com> <87ee6ad5-7c58-4e40-92fe-57305ce2b00a@amazon.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: <87ee6ad5-7c58-4e40-92fe-57305ce2b00a@amazon.com> On Wed, Jan 28, 2026 at 11:30:20AM +0100, Alexander Graf wrote: > > On 28.01.26 10:13, Johannes Thumshirn wrote: > > On 1/28/26 10:03 AM, Alexander Graf wrote: > > > On 28.01.26 09:47, Johannes Thumshirn wrote: > > > > On 1/27/26 5:30 PM, Alexander Graf wrote: > > > > > This patches the split vring format, but does not touch the packed one. > > > > > What happens if you run the same test with the packed format? You can do > > > > > so by passing "packed=on" as argument to your -device parameter. > > > > This opened up a whole new can of worms... :( > > > That's what I expected :). > > > > > > How do other DMA based devices handle this? Is the real problem that > > > virtio by default does not use the DMA API and so it confuses generic > > > KCSAN logic that would otherwise track DMA regions as "can be modified > > > by DMA at any time"? > > > > > > If that is the case, maybe what we really want is to force enable use of > > > the DMA API when KCSAN is active. Does something like the (whitespace > > > broken) patch below work? > > > > > > Alex > > > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > > index ddab68959671..b1dd790ce622 100644 > > > --- a/drivers/virtio/virtio_ring.c > > > +++ b/drivers/virtio/virtio_ring.c > > > @@ -284,6 +284,13 @@ static bool vring_use_map_api(const struct > > > virtio_device *vdev) > > > if (xen_domain()) > > > return true; > > > > > > + /* > > > + * KCSAN needs to track who can modify memory. DMA API gets > > > + * us that, so always use it. > > > + */ > > > + if (IS_ENABLED(CONFIG_KCSAN)) > > > + return true; > > > + > > > return false; > > > } > > > > Unfortunately this doesn't get us any further (I'd love though, it looks > > way cleaner!) > > > > I still see the KCSAN messages even on boot. > > > Ah, looks like the important bit for KCSAN is not the mapping mechanism, > it's the actual compiler annotation for the read. So these virtio ring reads > should all be annotated as READ_ONCE() to make sure KCSAN knows the read > itself is atomic. > > Alex > so then: return vq->last_used_idx != virtio16_to_cpu(vq->vq.vdev, READ_ONCE(vq->split.vring.used->idx)); ? > > > Amazon Web Services Development Center Germany GmbH > Tamara-Danz-Str. 13 > 10243 Berlin > Geschaeftsfuehrung: Christof Hellmis, Andreas Stieger > Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B > Sitz: Berlin > Ust-ID: DE 365 538 597