From nobody Wed Apr 24 09:31:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1641914447; cv=none; d=zohomail.com; s=zohoarc; b=aKSD4I1ICcTPZsCFDJp9KZn7BoVhcmbR1Wy8kOQmg2LWYffBQJVqdbzRQfR9lHDK5YQq7bYnzUL/nrBSOP7H7rflDcUoyMWD+8nJsAzC/zl0qwyxGzlwiU+EpHJHwp5SGADys+6+D4SsvrnoCRMxwfQW96Flc1WCdWvnOmisxgI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641914447; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5MnAj8jgvGSVnTnQHkjtzzsrohe+jN87xvuOdqS22Ok=; b=QuA6Lo+nbL8jInZVJKY8MyDHq5g1nnulOqFUqc3Uqf5yzkNA5gcpaS45jzkQo8k4VYXZ20VdFfNBtECZdIOQzj7OJvzTJ7GevS1BbdfcSoAElLCEArj4a436t18WJx6eqkoY/8zRQY9sNATshw5PEA9cts//UJYyEHjVylrUHwk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1641914447753165.71070730483348; Tue, 11 Jan 2022 07:20:47 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.255906.438905 (Exim 4.92) (envelope-from ) id 1n7IwZ-0003QX-RL; Tue, 11 Jan 2022 15:20:15 +0000 Received: by outflank-mailman (output) from mailman id 255906.438905; Tue, 11 Jan 2022 15:20:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7IwZ-0003QQ-NK; Tue, 11 Jan 2022 15:20:15 +0000 Received: by outflank-mailman (input) for mailman id 255906; Tue, 11 Jan 2022 15:20:14 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7Ip3-0002Fw-EO for xen-devel@lists.xenproject.org; Tue, 11 Jan 2022 15:12:29 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id de12afa8-72f0-11ec-81c1-a30af7de8005; Tue, 11 Jan 2022 16:12:18 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 7E4B521112; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 46D881404B; Tue, 11 Jan 2022 15:12:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id oA8dEFKe3WG8AwAAMHmgww (envelope-from ); Tue, 11 Jan 2022 15:12:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: de12afa8-72f0-11ec-81c1-a30af7de8005 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641913938; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5MnAj8jgvGSVnTnQHkjtzzsrohe+jN87xvuOdqS22Ok=; b=KcLdTKRrhcktZcEEJ6Esn2gpSF88MuhbhNCD6QM3AustEX6MZ7SEVx4suCWZ3nVunF2TwJ lxSkdKdsjnuM5NTc9Zgmuhr9S0Rhgc05Q5hLhJr7xTTLOyvHJNM6p5tOqwd8dtMKnbXjwr /ARKUb/i+ujsZCsXg4NZTT7DQITZ2YM= From: Juergen Gross To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, wl@xen.org, Juergen Gross Subject: [PATCH v2 08/12] mini-os: use alloc_file_type() and get_file_from_fd() in fbfront Date: Tue, 11 Jan 2022 16:12:11 +0100 Message-Id: <20220111151215.22955-9-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220111151215.22955-1-jgross@suse.com> References: <20220111151215.22955-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1641914451973100001 Content-Type: text/plain; charset="utf-8" Allocate file types dynamically via alloc_file_type(). Instead of directly accessing the files[] array use get_file_from_fd(). Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- fbfront.c | 125 ++++++++++++++++++++++++++++++++++++++++++-------- include/lib.h | 4 +- lib/sys.c | 47 ------------------- 3 files changed, 106 insertions(+), 70 deletions(-) diff --git a/fbfront.c b/fbfront.c index 1e055fb..9c96963 100644 --- a/fbfront.c +++ b/fbfront.c @@ -14,6 +14,9 @@ #include #include #include +#ifdef HAVE_LIBC +#include +#endif =20 DECLARE_WAIT_QUEUE_HEAD(kbdfront_queue); =20 @@ -42,10 +45,10 @@ void kbdfront_handler(evtchn_port_t port, struct pt_reg= s *regs, void *data) { #ifdef HAVE_LIBC struct kbdfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; #endif wake_up(&kbdfront_queue); } @@ -204,10 +207,12 @@ int kbdfront_receive(struct kbdfront_dev *dev, union = xenkbd_in_event *buf, int n struct xenkbd_page *page =3D dev->page; uint32_t prod, cons; int i; - #ifdef HAVE_LIBC - if (dev->fd !=3D -1) { - files[dev->fd].read =3D false; + struct file *file =3D get_file_from_fd(dev->fd); + + if ( file ) + { + file->read =3D false; mb(); /* Make sure to let the handler set read to 1 before we star= t looking at the ring */ } #endif @@ -227,9 +232,9 @@ int kbdfront_receive(struct kbdfront_dev *dev, union xe= nkbd_in_event *buf, int n notify_remote_via_evtchn(dev->evtchn); =20 #ifdef HAVE_LIBC - if (cons !=3D prod && dev->fd !=3D -1) + if ( cons !=3D prod && file ) /* still some events to read */ - files[dev->fd].read =3D true; + file->read =3D true; #endif =20 return i; @@ -298,11 +303,50 @@ close_kbdfront: } =20 #ifdef HAVE_LIBC +static int kbd_read(int fd, void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + int ret, n; + + n =3D nbytes / sizeof(union xenkbd_in_event); + ret =3D kbdfront_receive(file->dev, buf, n); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret * sizeof(union xenkbd_in_event); +} + +static int kbd_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_kbdfront(file->dev); + + return 0; +} + +static struct file_ops kbd_ops =3D { + .name =3D "kbd", + .read =3D kbd_read, + .close =3D kbd_close_fd, + .select_rd =3D select_read_flag, +}; + int kbdfront_open(struct kbdfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_KBD); + struct file *file; + static unsigned int ftype_kbd; + + if ( !ftype_kbd ) + ftype_kbd =3D alloc_file_type(&kbd_ops); + + dev->fd =3D alloc_fd(ftype_kbd); printk("kbd_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; return dev->fd; } #endif @@ -346,10 +390,10 @@ void fbfront_handler(evtchn_port_t port, struct pt_re= gs *regs, void *data) { #ifdef HAVE_LIBC struct fbfront_dev *dev =3D data; - int fd =3D dev->fd; + struct file *file =3D get_file_from_fd(dev->fd); =20 - if (fd !=3D -1) - files[fd].read =3D true; + if ( file ) + file->read =3D true; #endif wake_up(&fbfront_queue); } @@ -373,10 +417,12 @@ int fbfront_receive(struct fbfront_dev *dev, union xe= nfb_in_event *buf, int n) struct xenfb_page *page =3D dev->page; uint32_t prod, cons; int i; - #ifdef HAVE_LIBC - if (dev->fd !=3D -1) { - files[dev->fd].read =3D false; + struct file *file =3D get_file_from_fd(dev->fd); + + if ( file ) + { + file->read =3D false; mb(); /* Make sure to let the handler set read to 1 before we star= t looking at the ring */ } #endif @@ -396,9 +442,9 @@ int fbfront_receive(struct fbfront_dev *dev, union xenf= b_in_event *buf, int n) notify_remote_via_evtchn(dev->evtchn); =20 #ifdef HAVE_LIBC - if (cons !=3D prod && dev->fd !=3D -1) + if ( cons !=3D prod && file ) /* still some events to read */ - files[dev->fd].read =3D true; + file->read =3D true; #endif =20 return i; @@ -699,11 +745,50 @@ close_fbfront: } =20 #ifdef HAVE_LIBC +static int fbfront_read(int fd, void *buf, size_t nbytes) +{ + struct file *file =3D get_file_from_fd(fd); + int ret, n; + + n =3D nbytes / sizeof(union xenfb_in_event); + ret =3D fbfront_receive(file->dev, buf, n); + if ( ret <=3D 0 ) + { + errno =3D EAGAIN; + return -1; + } + + return ret * sizeof(union xenfb_in_event); +} + +static int fbfront_close_fd(int fd) +{ + struct file *file =3D get_file_from_fd(fd); + + shutdown_fbfront(file->dev); + + return 0; +} + +static struct file_ops fb_ops =3D { + .name =3D ".fb", + .read =3D fbfront_read, + .close =3D fbfront_close_fd, + .select_rd =3D select_read_flag, +}; + int fbfront_open(struct fbfront_dev *dev) { - dev->fd =3D alloc_fd(FTYPE_FB); + struct file *file; + static unsigned int ftype_fb; + + if ( !ftype_fb ) + ftype_fb =3D alloc_file_type(&fb_ops); + + dev->fd =3D alloc_fd(ftype_fb); printk("fb_open(%s) -> %d\n", dev->nodename, dev->fd); - files[dev->fd].dev =3D dev; + file =3D get_file_from_fd(dev->fd); + file->dev =3D dev; return dev->fd; } #endif diff --git a/include/lib.h b/include/lib.h index aa8036e..653a16e 100644 --- a/include/lib.h +++ b/include/lib.h @@ -161,9 +161,7 @@ void sanity_check(void); #define FTYPE_SOCKET 3 #define FTYPE_MEM 4 #define FTYPE_SAVEFILE 5 -#define FTYPE_FB 6 -#define FTYPE_KBD 7 -#define FTYPE_N 8 +#define FTYPE_N 6 #define FTYPE_SPARE 16 =20 typedef int file_read_func(int fd, void *buf, size_t nbytes); diff --git a/lib/sys.c b/lib/sys.c index 7f2e11f..4fb844f 100644 --- a/lib/sys.c +++ b/lib/sys.c @@ -302,30 +302,6 @@ int read(int fd, void *buf, size_t nbytes) #ifdef HAVE_LWIP case FTYPE_SOCKET: return lwip_read(files[fd].fd, buf, nbytes); -#endif -#ifdef CONFIG_KBDFRONT - case FTYPE_KBD: { - int ret, n; - n =3D nbytes / sizeof(union xenkbd_in_event); - ret =3D kbdfront_receive(files[fd].dev, buf, n); - if (ret <=3D 0) { - errno =3D EAGAIN; - return -1; - } - return ret * sizeof(union xenkbd_in_event); - } -#endif -#ifdef CONFIG_FBFRONT - case FTYPE_FB: { - int ret, n; - n =3D nbytes / sizeof(union xenfb_in_event); - ret =3D fbfront_receive(files[fd].dev, buf, n); - if (ret <=3D 0) { - errno =3D EAGAIN; - return -1; - } - return ret * sizeof(union xenfb_in_event); - } #endif default: break; @@ -443,16 +419,6 @@ int close(int fd) res =3D lwip_close(files[fd].fd); break; #endif -#ifdef CONFIG_KBDFRONT - case FTYPE_KBD: - shutdown_kbdfront(files[fd].dev); - break; -#endif -#ifdef CONFIG_FBFRONT - case FTYPE_FB: - shutdown_fbfront(files[fd].dev); - break; -#endif #ifdef CONFIG_CONSFRONT case FTYPE_SAVEFILE: case FTYPE_CONSOLE: @@ -619,8 +585,6 @@ static const char *file_types[] =3D { [FTYPE_NONE] =3D "none", [FTYPE_CONSOLE] =3D "console", [FTYPE_SOCKET] =3D "socket", - [FTYPE_KBD] =3D "kbd", - [FTYPE_FB] =3D "fb", }; =20 static char *get_type_name(unsigned int type) @@ -795,17 +759,6 @@ static int select_poll(int nfds, fd_set *readfds, fd_s= et *writefds, fd_set *exce n++; FD_CLR(i, exceptfds); break; - case FTYPE_KBD: - case FTYPE_FB: - if (FD_ISSET(i, readfds)) { - if (files[i].read) - n++; - else - FD_CLR(i, readfds); - } - FD_CLR(i, writefds); - FD_CLR(i, exceptfds); - break; #ifdef HAVE_LWIP case FTYPE_SOCKET: if (FD_ISSET(i, readfds)) { --=20 2.26.2