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 7C3CF262FF8 for ; Sat, 18 Jul 2026 17:27:21 +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=1784395643; cv=none; b=eEn5lWD1bOdkDMBVLHHXYtWY7KJ4T/Kp+GEPqFouxQwZepXa4H3G8/rRzGzw/Crk7wMXfQtbSTEitDqvUrsAuMUXpkxHuGHFpEgUG+9m0a8b96Yw98WkaLyZdvKSUrgzwk4Wt3idvQwPBY2Pbosz7njzX4SH7Pi65dp/8IqOz80= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784395643; c=relaxed/simple; bh=6rSrZyCWXJlF3I3FaDITfDYsoSwgsFAnSZw5FPIkPTo=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=VA9OhXGS7cYzOidtbs5jSAnq2I3vutrIIICMVmy1isYtLOYoUyZS2URUHXQ2UyCNg3ytcBAQWa5rA1tBtMq2l8Q2aOK966bzRlbpRfb5RrrhpU6gH1tIKyzGZDVUj33p1SBrnT9/U+KbGZsoLK7uA2yCJXcP/8xFsD657S0422Y= 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=RXHAl5Ck; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=kN0GmuFI; 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="RXHAl5Ck"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="kN0GmuFI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1784395640; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y4SYB/B+bDlxilXL6idtvWKAFgvw269dvYm2IM94meE=; b=RXHAl5CkJjhxByewgfYD/fmRB4bOmgGmxbsMe1W0qVAgQEm503VL2JGeYPpLGFmXNWcELO H4ecT5piIaU/UQK8Ax2QIrfJ8x5xQVKtlLsJiN9FE34vcmM1bE4I5pe2ZwLRvLDhZagwU0 2fGBjz5CUtxRFUhNrCTVddZyy2yq23o= 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-623-Ezij7LKRNv2tAiB81NSmsg-1; Sat, 18 Jul 2026 13:27:16 -0400 X-MC-Unique: Ezij7LKRNv2tAiB81NSmsg-1 X-Mimecast-MFC-AGG-ID: Ezij7LKRNv2tAiB81NSmsg_1784395635 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-49545755b03so21258015e9.0 for ; Sat, 18 Jul 2026 10:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1784395635; x=1785000435; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Y4SYB/B+bDlxilXL6idtvWKAFgvw269dvYm2IM94meE=; b=kN0GmuFIilQKzHzT6GyKQ/+Hgj8l3V6mTaah8JHz/MeA/JCK6CyNw/3oZQ/Cj+wjQh JrIMuy01RoNxJdf041ZLWsRgqNYQxB+/kLM4vR1x3Et6acbAeYzGU38gZ8LAw7QFd0tk oXK4o4dqQfppQ3oQuvisbIJwDuRHNlXQfoDZgAmwlza9GqkoV5zh1BR3jB1O/aUXGJNj fNgxR/41AioNwcd55V5dB8DlmLMr8Ty7ZWv9ul6rVNmvpgDcA3ck+ipEJrbp/lzq0tsz t0k4lJMJ5oZaUJXXIU14tH9kFQxYD11WrAaX75BowJbysPPJI1gzQuBUiVhsX30KE5zV y3Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784395635; x=1785000435; h=in-reply-to:content-transfer-encoding:content-disposition :content-type: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:content-type; bh=Y4SYB/B+bDlxilXL6idtvWKAFgvw269dvYm2IM94meE=; b=Ic+bzDlakFGr+fOi5/xhRkxITGnnnPP0gQoE6AY+Oa6S82SCLfqqSRQsAfaRo5E/RK jnai5ar+cJILfP6CsNBed+lYFq0J3w4sXgQV0zIAL6+NmWHIMc9TxZXGCJNSBu5poPVd FOUg9UFShgwVFqav55a2/61xeqe//Rh2gWdCKmL+nrWpZN0GTBS8021qWW/7dewcSnTO 8IeCY44BsZNlsiDqc8ouNGS2gHsXGVHbaDZMHGYNIJWm3UUfxS1BePbOkQDz9XrpKy+W 6kEwV3n4/Tpn3f919JDHx/BM2wzu4/x0V19O38hypO1AiHNkFE/H01+ak7t9QZ49Ifdr iUGA== X-Forwarded-Encrypted: i=1; AHgh+Rrb3TMxRG9ebyuXtiLO6q+ZWEaN9CTHpo0T7MggnFp2d3ndH9Yk6LsqqS5Ei+kBmqFAJlho1gSZJrFp4nI=@vger.kernel.org X-Gm-Message-State: AOJu0YxqV7wyrHSL0au+HltgY/dv7iZEsAxPTbH2FXj3bblUsfhrq0ap H0uHYsuMPwgs+aIr/GlaE1qcoDx7jBb8JeD1dQGgr0XkJvSS9Y+CfBbmh7w41/dMVv3aOP0cuJk 1yBSvrLly2zi3MdcAPnN5GGp9fEb9V8hmI5DUbvvKdoTscnWYfIZgcFSNezAErU9LUw== X-Gm-Gg: AfdE7clhDn8/Lc+eEoVY/xMK2A8HBNtYCJS9wd32Rl4WleOagPi6HfYW49SESxaV5iL Gfp7U/3Ku/OhW2RxLbATOrxzrQ17QZOQKvPFzxfPVmQyXpCBCT7h4S6XJ2xxQypdCbYJ/zIEPhc 8oI14EqHBwRLzflfL+Y2F5B+1Xf5Bk6MDp9bwyaiG982ItnnMzqOBK7EXcieQopALMxctFhTA6C 11tiggLb8/vgKMlGr1J7tUJIBqycHXEQmpJtQupgi4URIuN+4j/Da3y8aYuUl8wia+R/bwLL/xW r9yABfsfSw4GvcNZ6L4BPs9ri3MK1yyJ2uyiNjokoBnQv6GGrjmnGGSjjPzYIlGZHzd0qvcTEq6 PP595MXq15POLGR3UxgpwjbHN1MEKe7Y= X-Received: by 2002:a05:600c:1c0b:b0:495:46dd:e238 with SMTP id 5b1f17b1804b1-4954a50ea30mr92150535e9.30.1784395634907; Sat, 18 Jul 2026 10:27:14 -0700 (PDT) X-Received: by 2002:a05:600c:1c0b:b0:495:46dd:e238 with SMTP id 5b1f17b1804b1-4954a50ea30mr92150045e9.30.1784395634331; Sat, 18 Jul 2026 10:27:14 -0700 (PDT) Received: from redhat.com (bzq-79-177-145-168.red.bezeqint.net. [79.177.145.168]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f6b85970esm7812651f8f.15.2026.07.18.10.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jul 2026 10:27:12 -0700 (PDT) Date: Sat, 18 Jul 2026 13:27:09 -0400 From: "Michael S. Tsirkin" To: Brian Daniels Cc: Mauro Carvalho Chehab , acourbot@google.com, adelva@google.com, aesteve@redhat.com, changyeon@google.com, daniel.almeida@collabora.com, eperezma@redhat.com, gnurou@gmail.com, gurchetansingh@google.com, hverkuil@xs4all.nl, jasowang@redhat.com, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, nicolas.dufresne@collabora.com, virtualization@lists.linux.dev, xuanzhuo@linux.alibaba.com Subject: Re: [PATCH v4 2/8] media: virtio: Add virtio-media driver structs and function declarations Message-ID: <20260718132340-mutt-send-email-mst@kernel.org> References: <20260622204343.1994418-1-briandaniels@google.com> <20260622204343.1994418-3-briandaniels@google.com> <20260622170708-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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, Jul 17, 2026 at 03:46:36PM -0400, Brian Daniels wrote: > On Mon, Jun 22, 2026 at 5:08 PM Michael S. Tsirkin wrote: > > > > On Mon, Jun 22, 2026 at 04:43:37PM -0400, Brian Daniels wrote: > > > From: Alexandre Courbot > > > > > > Add the structs and function declarations for the new virtio-media drvier. > > > > > > Signed-off-by: Alexandre Courbot > > > Co-developed-by: Brian Daniels > > > Signed-off-by: Brian Daniels > > > --- > > > drivers/media/virtio/virtio_media.h | 95 +++++++++++++++++++++++++++++ > > > 1 file changed, 95 insertions(+) > > > create mode 100644 drivers/media/virtio/virtio_media.h > > > > > > diff --git a/drivers/media/virtio/virtio_media.h b/drivers/media/virtio/virtio_media.h > > > new file mode 100644 > > > index 000000000..52809d4e9 > > > --- /dev/null > > > +++ b/drivers/media/virtio/virtio_media.h > > > @@ -0,0 +1,95 @@ > > > +/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0+ */ > > > + > > > +/* > > > + * Virtio-media structures & functions declarations. > > > + * > > > + * Copyright (c) 2024-2025 Google LLC. > > > + */ > > > + > > > +#ifndef __VIRTIO_MEDIA_H > > > +#define __VIRTIO_MEDIA_H > > > + > > > +#include > > > +#include > > > + > > > +#include "protocol.h" > > > + > > > +#define DESC_CHAIN_MAX_LEN SG_MAX_SINGLE_ALLOC > > > + > > > +#define VIRTIO_MEDIA_DEFAULT_DRIVER_NAME "virtio-media" > > > + > > > +extern char *virtio_media_driver_name; > > > +extern bool virtio_media_allow_userptr; > > > + > > > +/** > > > + * struct virtio_media - Virtio-media device. > > > + * @v4l2_dev: v4l2_device for the media device. > > > + * @video_dev: video_device for the media device. > > > + * @virtio_dev: virtio device for the media device. > > > + * @commandq: virtio command queue. > > > + * @eventq: virtio event queue. > > > + * @eventq_work: work to run when events are received on @eventq. > > > + * @mmap_region: region into which MMAP buffers are mapped by the host. > > > + * @event_buffer: buffer for event descriptors. > > > + * @sessions: list of active sessions on the device. > > > + * @sessions_lock: protects @sessions and ``virtio_media_session::list``. > > > + * @events_lock: prevents concurrent processing of events. > > > + * @cmd: union of the device commands "open" and "munmap". The other > > > + * commands are handled by @struct virtio_media_session > > > + * @resp: union of responses.to device commands "open" and "munmap". The > > > + * other responses are handled by @struct virtio_media_session > > > + * @vlock: serializes access to the command queue. > > > + * @wq: waitqueue for host responses on the command queue. > > > + */ > > > +struct virtio_media { > > > + struct v4l2_device v4l2_dev; > > > + struct video_device video_dev; > > > + > > > + struct virtio_device *virtio_dev; > > > + struct virtqueue *commandq; > > > + struct virtqueue *eventq; > > > + struct work_struct eventq_work; > > > + > > > + struct virtio_shm_region mmap_region; > > > + > > > + void *event_buffer; > > > + > > > + struct list_head sessions; > > > + struct mutex sessions_lock; /* protects sessions list */ > > > + > > > + struct mutex events_lock; /* prevents concurrent event processing */ > > > + > > > + union { > > > + struct virtio_media_cmd_open open; > > > + struct virtio_media_cmd_munmap munmap; > > > + } cmd; > > > + > > > + union { > > > + struct virtio_media_resp_open open; > > > + struct virtio_media_resp_munmap munmap; > > > + } resp; > > > > > > You need DMA alignment padding for these things. > > Each member of the above unions is already padded to 64-bit alignment, > is that sufficient? > > If not, could you tell me what else is necessary? Read up "What memory is DMA'able?" and following chapters in Documentation/core-api/dma-api-howto.rst > > Which one can only see when I reads the actual driver 8 patches down. > > Which is why it's not a sensible way to split patches. > > > > A sensible way is to have a driver then add functionality > > in logical pieces gradually. > > > > Appreciate the feedback. There was a previous comment requesting to > split the patch into c/h file pairs, but I can try reformatting it as > you suggest for v5. > > > > + > > > + struct mutex vlock; /* serializes command queue access */ > > > + wait_queue_head_t wq; > > > +}; > > > + > > > +static inline struct virtio_media * > > > +to_virtio_media(struct video_device *video_dev) > > > +{ > > > + return container_of(video_dev, struct virtio_media, video_dev); > > > +} > > > + > > > +/* virtio_media_driver.c */ > > > + > > > +int virtio_media_send_command(struct virtio_media *vv, struct scatterlist **sgs, > > > + const size_t out_sgs, const size_t in_sgs, > > > + size_t minimum_resp_len, size_t *resp_len); > > > +void virtio_media_process_events(struct virtio_media *vv); > > > + > > > +/* virtio_media_ioctls.c */ > > > + > > > +long virtio_media_device_ioctl(struct file *file, unsigned int cmd, > > > + unsigned long arg); > > > +extern const struct v4l2_ioctl_ops virtio_media_ioctl_ops; > > > + > > > +#endif // __VIRTIO_MEDIA_H > > > -- > > > 2.55.0.rc0.799.gd6f94ed593-goog > >