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 58E4D19C546 for ; Wed, 28 Jan 2026 10:49:04 +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=1769597345; cv=none; b=p+z4SDdCkba0tXsSyvpo7T7iZN7pdpyFMJ3uwhrDQ5OnyhJRxjElsu2z1c7NudFb28niUdIMYZT3Q6IibsQfOGTgJcUYwzckKWEd+gXFx/s3+5G1Osurpew/itVqDvK3gqAk0te1jqVF5M1Va0kKTuS6g/yyf7oDwQGGwDYikZI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769597345; c=relaxed/simple; bh=WC/kp/3pb+xjmgQjdWs4L2k/DJqsjynrUsgVTKZyg4U=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ZMmQShVhW7AEg0igGR5BHXtUKBoPgTiSOuE/8LB1SwPSEK8uUJTgsuwaBdlQ/SJBPSvkcZVgjYkQyNv1vs9EJU6GBBI7imEGCNNHLzKyx71wBUgfPqZEZoQ2q87huYZoD3gHcWzb+SfNc3jSdD9VDGum57QWF6d2wcfEw5CnufE= 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=WSJ4tEyi; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=d4K7rglQ; 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="WSJ4tEyi"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="d4K7rglQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1769597343; 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=akES2HBrjOOJMcYlD7o6JMYnRn/dV8UGPZwe32MKvI8=; b=WSJ4tEyiXEEXNl+xtY2fZLh6Li6pVIvcZAgUs+g2Y+nAR8Q82AtgWHdVPZWyuaiWvj69i5 GMwRIhvjod+gvzPM/1uq/kLIMLv2w83dlbp4nsAroTgmxu6YWVcGuEBduZA/tD3OnoLZOJ NoiLsDhtniZZcZeZPljKHzYYE9YxKuI= 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-528-9Ddx00tLO--y-ghYKb5x2w-1; Wed, 28 Jan 2026 05:49:02 -0500 X-MC-Unique: 9Ddx00tLO--y-ghYKb5x2w-1 X-Mimecast-MFC-AGG-ID: 9Ddx00tLO--y-ghYKb5x2w_1769597341 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-4325b182e3cso4764702f8f.2 for ; Wed, 28 Jan 2026 02:49:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1769597341; x=1770202141; 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=akES2HBrjOOJMcYlD7o6JMYnRn/dV8UGPZwe32MKvI8=; b=d4K7rglQNKug1nWZbw21wn8e2x1fRN4irbIjIpH4vGd/mLt+7FVM69viZjVUMJ6NG0 21IQtxB0+zO7Cgu9x9VyItMtuC68x4Ww9eV7gByHKMn68GDQUG6Jyze6dOyv6TmJgR/k 7xRiBqc5UxAV8XqmP/guYAUGeGSvciUzD8/TfYG8X/2qGykvb4YqTKv8caZZSnmqkPaT M2S6d8jCvIdZpmMRAyH+XgKYGO+h/X0DtgGi6mNOMO7FBfEOnNV74YjnlugSB9Mddfw1 ZNyH+KGHTNpTrBMAAZ4q6vLSITKZyfex0ifO9bfhkthQdL+oyWxlFeYzBqOYibnTjhA+ 94gA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769597341; x=1770202141; 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=akES2HBrjOOJMcYlD7o6JMYnRn/dV8UGPZwe32MKvI8=; b=jiysVXk6Ri1My5DBg8L4ix0uzEICiWemfzgvCewT1ae5n725smhCHOvIvNsjLZ3yoj ox3v88TD5zSntnLXk4HTQHFdXocsYT1AZFNdGBJ7aKpI/nA4sXOHNDFy7mDSTn+67M87 KE0Q5R4hZZzQPJRE5cmC8KUE1KaSaryGB7SLuyCQycHLFq1rqa7IlIp1fqayu9/cSHGj DG2iZL45aQxum8UMpnA2PafIVGUxEtivSY+9wMhSjYi5/Z40AGpFwENR0k6s/p4oHHat t9E4+XfHEI5RvqzSW8lO2u5RgGsm+o3pd7AfzpRvWSKuyq2pZokSY5nw8y6QJQye0+eW 0+mA== X-Forwarded-Encrypted: i=1; AJvYcCU6CWcYhlAMBvzQuyQFGL6L2AC2dO0UXHvykpqh0AUqhf16cgDNP42VL+ftu1iXWNQ5VjolCaSK65J1DWE=@vger.kernel.org X-Gm-Message-State: AOJu0Yxzy1UZfBarINrwQnHM7obmfFHi+Rhhl6OINKbyeOZhA+SIgFXS va6SmLjJW2S3BDXwT+4MZHt73/U6v9jejk3o4cJF0LVLNDSPKklDeggXidTjAFNJvg030ecViij 0X6BXyRtbW0U9yxjVhvW1IsEeTRLvapzFSz11hTqtw7LKDOXmMqbN9NRPDHwyEY9OfQ== X-Gm-Gg: AZuq6aJlpRzEY+vHivt1cAjKIIgWvhp2N4x7nsDLv04WnmCR5UgYxfMwTufAWWJw5Eg qOfvUgDlsnSXmcPM61Ufwlywj8YK91alIgyKA9+v23RbUvK/wSnFZA9fxq2V48CCri+ZQITUzkq 3gc0x9kDb0YzTyhzlzhF80ZugXB1U5FZqbq8es3O05ROMR9QA211HtqoobSI2Pd3hx4oJGlbaFQ jBOtJ6AqElS6FY8vyFCZsmhoge+Vzt/57faYFNtrNvHVb/R+fCXVN0nac1xBq87fXCgpxXzr/w1 1hoE+a8LpzWvUXFZgxJ/7EY4VHKnDBt1eYRM9mHnhQywDWkaevyLZUvfmkAhJo08aeAv4a1Hnex iytxdnI16KQ7x1Qla3Pys5N6AKKZY0ZbXWw== X-Received: by 2002:a5d:588f:0:b0:42f:bbc6:edaf with SMTP id ffacd0b85a97d-435dd0baf9fmr6455490f8f.37.1769597340681; Wed, 28 Jan 2026 02:49:00 -0800 (PST) X-Received: by 2002:a5d:588f:0:b0:42f:bbc6:edaf with SMTP id ffacd0b85a97d-435dd0baf9fmr6455460f8f.37.1769597340217; Wed, 28 Jan 2026 02:49:00 -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 ffacd0b85a97d-435e1322eefsm5993981f8f.30.2026.01.28.02.48.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 02:48:59 -0800 (PST) Date: Wed, 28 Jan 2026 05:48:57 -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: <20260128054415-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> <20260128053356-mutt-send-email-mst@kernel.org> 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: On Wed, Jan 28, 2026 at 11:38:48AM +0100, Alexander Graf wrote: > > On 28.01.26 11:34, Michael S. Tsirkin wrote: > > 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)); > > > Yes, which is on the verge of getting unreadable. Well we can wrap virtio16_to_cpu and READ_ONCE in a single macro if you like. VIRTIO16_READ ? > I'll work with Johannes on > v3. We'll play with ways to make it a bit more maintainable. Please discard > the current patches for now. Sure. > > Alex > > > > > 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