From nobody Tue May 7 04:21:28 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=1642321479; cv=none; d=zohomail.com; s=zohoarc; b=Q9yjq4YB4U2KPyprcAP2bHX6D2CNhd9h7kKT8uuer7AlGznpSwW4J11q3QhHHzLI/JtgiurbdEZVtHVIlgkd5d4DLtDDZtaT2dk7gnPSEeZbYpPdFYXwzzhiQh2IGlXo5+e1loyEaD06mmfl6aTaGMCV/A8+GvMm3zRXCLxDi3k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642321479; 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=Lwv7UrthbYq5rR8LCXaRM2cQQusBd2qxNothm7VTMRM=; b=FtmCKEg8cQeXz6xxb5fp24LxSPSAu9d76m9ywxAh9O+6fGTk4liFLGX5AidKp718qPqt9usPpB2Hg2WavSCvgrhtOOIBCgjNACP9orV1MC7tmbUjIAH68RjNurloFg99Av1rPbD0hTJAc4eHQ1BRBcCLyYCGy44HRuEgLOQhvgo= 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 1642321479679953.1870931145961; Sun, 16 Jan 2022 00:24:39 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257805.443123 (Exim 4.92) (envelope-from ) id 1n90pU-00052j-NQ; Sun, 16 Jan 2022 08:24:00 +0000 Received: by outflank-mailman (output) from mailman id 257805.443123; Sun, 16 Jan 2022 08:24:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90pU-00052b-Jx; Sun, 16 Jan 2022 08:24:00 +0000 Received: by outflank-mailman (input) for mailman id 257805; Sun, 16 Jan 2022 08:23:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90pT-00052L-OI for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:23:59 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a68da50a-76a5-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:23:57 +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 E6BA4218E0; Sun, 16 Jan 2022 08:23:57 +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 B9E5C13AB5; Sun, 16 Jan 2022 08:23:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id gOc+LB3W42FLEwAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:23:57 +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: a68da50a-76a5-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642321437; 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=Lwv7UrthbYq5rR8LCXaRM2cQQusBd2qxNothm7VTMRM=; b=i/swlC09deGKUbaLLq7DYynecLl3fzdLBbG2O0RlWQ6zyqAUfifOP36WTfGofSDJ6IaH8B 4/VRqL0arxU6Qvfu8dwOhHQWz30VF7muA1i7Ih/69z6cJLCz6EYYkftt05Jhghe+7R0u8M OpGYZPXelqRpMAVGICcNuJdkY1BD7Rs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v3 1/3] tools/libs/evtchn: decouple more from mini-os Date: Sun, 16 Jan 2022 09:23:44 +0100 Message-Id: <20220116082346.26194-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116082346.26194-1-jgross@suse.com> References: <20220116082346.26194-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642321481672100001 Content-Type: text/plain; charset="utf-8" Mini-OS and libevtchn are using implementation details of each other. Change that by letting libevtchn use the new alloc_file_type() and get_file_from_fd() function and the generic dev pointer of struct file from Mini-OS. By using private struct declarations Mini-OS will be able to drop the libevtchn specific definitions of struct evtchn_port_info and evtchn_port_list in future. While at it use bool for "pending" and "bound". Switch to use xce as function parameter instead of fd where possible. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - use xce instead of fd as parameter internally (Andrew Cooper) - add alloc_file_type() support V3: - switch callback to use struct file * as a parameter (Andrew Cooper) - use __attribute__((constructor)) (Andrew Cooper) --- tools/libs/evtchn/minios.c | 143 +++++++++++++++++++++++++------------ 1 file changed, 96 insertions(+), 47 deletions(-) diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index 8f84048b11..ee3da9f8fe 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -38,29 +38,40 @@ =20 #include "private.h" =20 -extern void minios_evtchn_close_fd(int fd); +LIST_HEAD(port_list, port_info); + +struct port_info { + LIST_ENTRY(port_info) list; + evtchn_port_t port; + bool pending; + bool bound; +}; =20 extern struct wait_queue_head event_queue; =20 +void minios_evtchn_close_fd(int fd); + /* XXX Note: This is not threadsafe */ -static struct evtchn_port_info *port_alloc(int fd) +static struct port_info *port_alloc(xenevtchn_handle *xce) { - struct evtchn_port_info *port_info; + struct port_info *port_info; + struct file *file =3D get_file_from_fd(xce->fd); + struct port_list *port_list =3D file->dev; =20 - port_info =3D malloc(sizeof(struct evtchn_port_info)); + port_info =3D malloc(sizeof(struct port_info)); if ( port_info =3D=3D NULL ) return NULL; =20 - port_info->pending =3D 0; + port_info->pending =3D false; port_info->port =3D -1; - port_info->bound =3D 0; + port_info->bound =3D false; =20 - LIST_INSERT_HEAD(&files[fd].evtchn.ports, port_info, list); + LIST_INSERT_HEAD(port_list, port_info, list); =20 return port_info; } =20 -static void port_dealloc(struct evtchn_port_info *port_info) +static void port_dealloc(struct port_info *port_info) { if ( port_info->bound ) unbind_evtchn(port_info->port); @@ -69,18 +80,57 @@ static void port_dealloc(struct evtchn_port_info *port_= info) free(port_info); } =20 +static int evtchn_close_fd(struct file *file) +{ + struct port_info *port_info, *tmp; + struct port_list *port_list =3D file->dev; + + LIST_FOREACH_SAFE(port_info, port_list, list, tmp) + port_dealloc(port_info); + free(port_list); + + return 0; +} + +static const struct file_ops evtchn_ops =3D { + .name =3D "evtchn", + .close =3D evtchn_close_fd, + .select_rd =3D select_read_flag, +}; + +static unsigned int ftype_evtchn; + +__attribute__((constructor)) +static void evtchn_initialize(void) +{ + ftype_evtchn =3D alloc_file_type(&evtchn_ops); +} + /* * XENEVTCHN_NO_CLOEXEC is being ignored, as there is no exec() call suppo= rted * in Mini-OS. */ int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { - int fd =3D alloc_fd(FTYPE_EVTCHN); + int fd; + struct file *file; + struct port_list *list; =20 - if ( fd =3D=3D -1 ) + list =3D malloc(sizeof(*list)); + if ( !list ) return -1; =20 - LIST_INIT(&files[fd].evtchn.ports); + fd =3D alloc_fd(ftype_evtchn); + file =3D get_file_from_fd(fd); + + if ( !file ) + { + free(list); + return -1; + } + + file->dev =3D list; + LIST_INIT(list); xce->fd =3D fd; printf("evtchn_open() -> %d\n", fd); =20 @@ -104,12 +154,9 @@ int osdep_evtchn_restrict(xenevtchn_handle *xce, domid= _t domid) =20 void minios_evtchn_close_fd(int fd) { - struct evtchn_port_info *port_info, *tmp; + struct file *file =3D get_file_from_fd(fd); =20 - LIST_FOREACH_SAFE(port_info, &files[fd].evtchn.ports, list, tmp) - port_dealloc(port_info); - - files[fd].type =3D FTYPE_NONE; + evtchn_close_fd(file); } =20 int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port) @@ -129,42 +176,43 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_po= rt_t port) =20 static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void = *data) { - int fd =3D (int)(intptr_t)data; - struct evtchn_port_info *port_info; + xenevtchn_handle *xce =3D data; + struct file *file =3D get_file_from_fd(xce->fd); + struct port_info *port_info; + struct port_list *port_list; =20 - assert(files[fd].type =3D=3D FTYPE_EVTCHN); + assert(file); + port_list =3D file->dev; mask_evtchn(port); - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port =3D=3D port ) goto found; } =20 - printk("Unknown port for handle %d\n", fd); + printk("Unknown port %d for handle %d\n", port, xce->fd); return; =20 found: - port_info->pending =3D 1; - files[fd].read =3D 1; + port_info->pending =3D true; + file->read =3D true; wake_up(&event_queue); } =20 xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xc= e, uint32_t domid) { - int fd =3D xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; int ret; evtchn_port_t port; =20 assert(get_current() =3D=3D main_thread); - port_info =3D port_alloc(fd); + port_info =3D port_alloc(xce); if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_unbound_port(%d)", domid); - ret =3D evtchn_alloc_unbound(domid, evtchn_handler, - (void *)(intptr_t)fd, &port); + ret =3D evtchn_alloc_unbound(domid, evtchn_handler, xce, &port); printf(" =3D %d\n", ret); =20 if ( ret < 0 ) @@ -174,7 +222,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(x= enevtchn_handle *xce, return -1; } =20 - port_info->bound =3D 1; + port_info->bound =3D true; port_info->port =3D port; unmask_evtchn(port); =20 @@ -185,19 +233,18 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(= xenevtchn_handle *xce, uint32_t domid, evtchn_port_t remote_= port) { - int fd =3D xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; evtchn_port_t local_port; int ret; =20 assert(get_current() =3D=3D main_thread); - port_info =3D port_alloc(fd); + port_info =3D port_alloc(xce); if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_interdomain(%d, %"PRId32")", domid, remote_port= ); ret =3D evtchn_bind_interdomain(domid, remote_port, evtchn_handler, - (void *)(intptr_t)fd, &local_port); + xce, &local_port); printf(" =3D %d\n", ret); =20 if ( ret < 0 ) @@ -207,7 +254,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xe= nevtchn_handle *xce, return -1; } =20 - port_info->bound =3D 1; + port_info->bound =3D true; port_info->port =3D local_port; unmask_evtchn(local_port); =20 @@ -217,9 +264,11 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(x= enevtchn_handle *xce, int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port) { int fd =3D xce->fd; - struct evtchn_port_info *port_info; + struct file *file =3D get_file_from_fd(fd); + struct port_info *port_info; + struct port_list *port_list =3D file->dev; =20 - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port =3D=3D port ) { @@ -238,17 +287,16 @@ int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_po= rt_t port) xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int virq) { - int fd =3D xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; evtchn_port_t port; =20 assert(get_current() =3D=3D main_thread); - port_info =3D port_alloc(fd); + port_info =3D port_alloc(xce); if ( port_info =3D=3D NULL ) return -1; =20 printf("xenevtchn_bind_virq(%d)", virq); - port =3D bind_virq(virq, evtchn_handler, (void *)(intptr_t)fd); + port =3D bind_virq(virq, evtchn_handler, xce); printf(" =3D %d\n", port); =20 if ( port < 0 ) @@ -258,7 +306,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn= _handle *xce, return -1; } =20 - port_info->bound =3D 1; + port_info->bound =3D true; port_info->port =3D port; unmask_evtchn(port); =20 @@ -267,27 +315,28 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtc= hn_handle *xce, =20 xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce) { - int fd =3D xce->fd; - struct evtchn_port_info *port_info; + struct file *file =3D get_file_from_fd(xce->fd); + struct port_info *port_info; + struct port_list *port_list =3D file->dev; unsigned long flags; evtchn_port_t ret =3D -1; =20 local_irq_save(flags); =20 - files[fd].read =3D 0; + file->read =3D false; =20 - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port !=3D -1 && port_info->pending ) { if ( ret =3D=3D -1 ) { ret =3D port_info->port; - port_info->pending =3D 0; + port_info->pending =3D false; } else { - files[fd].read =3D 1; + file->read =3D true; break; } } --=20 2.26.2 From nobody Tue May 7 04:21:28 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=1642321477; cv=none; d=zohomail.com; s=zohoarc; b=fjdeo+pXafTLyWmVU3cRwQDuZS6fCY/CvKIoBgjUrXRLR1NhlpoRvccf3WiCvFaCG7wUmoBlHyzGAFxLW3JanSNPlJQYztQ4Xy15yuC8Uchz2vtlLuFUo2lVOfFJNJdaX2A0iNQBQVhFK57j/VkRajDpTU/pq9yrthjVpf6rHEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642321477; 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=f1HwqdB0og38hxRC3NF5Sj5Z62lBBi+hprIOlOt5nJI=; b=KiydBDCzRpHoXiawKa8GSUSSg1KNMI4yDoI9WxnMQcRKcIqtEaewUFzFFMmww0DTf75VaUMrrw954PhhBB6+Bh3DuXM035xvVh3VnS3ym3rf2bcgxe6a+ERjWuB78Q6VllS8QwNA3OaBmsTUt3PCo1uoyFZwqeqptJvZpft/UtE= 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 1642321477188824.6866407174647; Sun, 16 Jan 2022 00:24:37 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257808.443144 (Exim 4.92) (envelope-from ) id 1n90pW-0005SZ-LV; Sun, 16 Jan 2022 08:24:02 +0000 Received: by outflank-mailman (output) from mailman id 257808.443144; Sun, 16 Jan 2022 08:24:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90pW-0005Pr-EW; Sun, 16 Jan 2022 08:24:02 +0000 Received: by outflank-mailman (input) for mailman id 257808; Sun, 16 Jan 2022 08:24:00 +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 1n90pU-00052M-R7 for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:24:00 +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 a6dba1ac-76a5-11ec-a115-11989b9578b4; Sun, 16 Jan 2022 09:23:58 +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 215E2219B1; Sun, 16 Jan 2022 08:23:58 +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 ED8151346A; Sun, 16 Jan 2022 08:23:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sJuoOB3W42FLEwAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:23:57 +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: a6dba1ac-76a5-11ec-a115-11989b9578b4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642321438; 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=f1HwqdB0og38hxRC3NF5Sj5Z62lBBi+hprIOlOt5nJI=; b=cQkYDjrLP0RFyWIY77t56C04kSbYgX/Bijg+Wb2o3uyWnmam473HX2br75JOa9gtnnb+im BNYa1VdwpVKjYKRj1RJO5nUwATzzSf4Nmbw0PNEEkpRTo2TlaVbDGomqN6tdqJnIb4DEdm 3f6o7X+ukWj3A+iJVXisc0dZuuQ7HDk= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, Juergen Gross , Wei Liu , Anthony PERARD Subject: [PATCH v3 2/3] tools/libs/gnttab: decouple more from mini-os Date: Sun, 16 Jan 2022 09:23:45 +0100 Message-Id: <20220116082346.26194-3-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116082346.26194-1-jgross@suse.com> References: <20220116082346.26194-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642321479480100001 Content-Type: text/plain; charset="utf-8" libgnttab is using implementation details of Mini-OS. Change that by letting libgnttab use the new alloc_file_type() and get_file_from_fd() functions and the generic dev pointer of struct file from Mini-OS. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- V2: - add alloc_file_type() support V3: - switch callback to use struct file * as a parameter (Andrew Cooper) - use __attribute__((constructor)) (Andrew Cooper) --- tools/libs/gnttab/minios.c | 67 +++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/tools/libs/gnttab/minios.c b/tools/libs/gnttab/minios.c index f78caadd30..f59fad3577 100644 --- a/tools/libs/gnttab/minios.c +++ b/tools/libs/gnttab/minios.c @@ -28,18 +28,55 @@ #include =20 #include +#include #include =20 #include "private.h" =20 void minios_gnttab_close_fd(int fd); =20 +static int gnttab_close_fd(struct file *file) +{ + gntmap_fini(file->dev); + free(file->dev); + + return 0; +} + +static const struct file_ops gnttab_ops =3D { + .name =3D "gnttab", + .close =3D gnttab_close_fd, +}; + +static unsigned int ftype_gnttab; + +__attribute__((constructor)) +static void gnttab_initialize(void) +{ + ftype_gnttab =3D alloc_file_type(&gnttab_ops); +} + int osdep_gnttab_open(xengnttab_handle *xgt) { - int fd =3D alloc_fd(FTYPE_GNTMAP); - if ( fd =3D=3D -1 ) + int fd; + struct file *file; + struct gntmap *gntmap; + + gntmap =3D malloc(sizeof(*gntmap)); + if ( !gntmap ) return -1; - gntmap_init(&files[fd].gntmap); + + fd =3D alloc_fd(ftype_gnttab); + file =3D get_file_from_fd(fd); + + if ( !file ) + { + free(gntmap); + return -1; + } + + file->dev =3D gntmap; + gntmap_init(gntmap); xgt->fd =3D fd; return 0; } @@ -54,8 +91,9 @@ int osdep_gnttab_close(xengnttab_handle *xgt) =20 void minios_gnttab_close_fd(int fd) { - gntmap_fini(&files[fd].gntmap); - files[fd].type =3D FTYPE_NONE; + struct file *file =3D get_file_from_fd(fd); + + gnttab_close_fd(file); } =20 void *osdep_gnttab_grant_map(xengnttab_handle *xgt, @@ -64,16 +102,16 @@ void *osdep_gnttab_grant_map(xengnttab_handle *xgt, uint32_t notify_offset, evtchn_port_t notify_port) { - int fd =3D xgt->fd; + struct file *file =3D get_file_from_fd(xgt->fd); int stride =3D 1; + if (flags & XENGNTTAB_GRANT_MAP_SINGLE_DOMAIN) stride =3D 0; if (notify_offset !=3D -1 || notify_port !=3D -1) { errno =3D ENOSYS; return NULL; } - return gntmap_map_grant_refs(&files[fd].gntmap, - count, domids, stride, + return gntmap_map_grant_refs(file->dev, count, domids, stride, refs, prot & PROT_WRITE); } =20 @@ -81,11 +119,10 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, void *start_address, uint32_t count) { - int fd =3D xgt->fd; + struct file *file =3D get_file_from_fd(xgt->fd); int ret; - ret =3D gntmap_munmap(&files[fd].gntmap, - (unsigned long) start_address, - count); + + ret =3D gntmap_munmap(file->dev, (unsigned long) start_address, count); if (ret < 0) { errno =3D -ret; return -1; @@ -95,10 +132,10 @@ int osdep_gnttab_unmap(xengnttab_handle *xgt, =20 int osdep_gnttab_set_max_grants(xengnttab_handle *xgt, uint32_t count) { - int fd =3D xgt->fd; + struct file *file =3D get_file_from_fd(xgt->fd); int ret; - ret =3D gntmap_set_max_grants(&files[fd].gntmap, - count); + + ret =3D gntmap_set_max_grants(file->dev, count); if (ret < 0) { errno =3D -ret; return -1; --=20 2.26.2 From nobody Tue May 7 04:21:28 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=1642321478; cv=none; d=zohomail.com; s=zohoarc; b=CFyc0jCMWfzo7T1DDVLfDWCe+lowI+z6xVaqb+I9Dg10KigPlzw/GEr+bKNUbNDVNGML73nYWUwQaH0E11Jot5zfKKAvHLUij9mdZqwBHk6qzeap3FJnpX897CnbvnHbe4YyhSGX5eqTRlTkTmkLeyE+xf8hyqZfUydxBn1c+rs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642321478; 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=ErBw94A7NHEtLBOjGVvrvddf8O/VaQ+sffKi2esB83Q=; b=OMJWbHKyW2NeEM9e/wUJtAllLcMLKEoUMJpLh1SaJj6lO1dfvkV/E+UAAZcKJ6qk8za3kWLsbW0ziCjFb8u55O4Z38DOERg+3TwI81b2eo3r0AN5By7wXIGOpnEpnwZdQz6e4/wCepzuM9zMkdSjhdTrqOxCMxIz9sdltfkiVIg= 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 1642321478410939.8807939495325; Sun, 16 Jan 2022 00:24:38 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.257807.443139 (Exim 4.92) (envelope-from ) id 1n90pW-0005Lt-AL; Sun, 16 Jan 2022 08:24:02 +0000 Received: by outflank-mailman (output) from mailman id 257807.443139; Sun, 16 Jan 2022 08:24:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90pW-0005KY-4s; Sun, 16 Jan 2022 08:24:02 +0000 Received: by outflank-mailman (input) for mailman id 257807; Sun, 16 Jan 2022 08:24:00 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n90pU-00052L-FH for xen-devel@lists.xenproject.org; Sun, 16 Jan 2022 08:24:00 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id a6b1d4c6-76a5-11ec-9bbc-9dff3e4ee8c5; Sun, 16 Jan 2022 09:23:58 +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 5389D219B7; Sun, 16 Jan 2022 08:23:58 +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 2649013AB5; Sun, 16 Jan 2022 08:23:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 0DIxCB7W42FLEwAAMHmgww (envelope-from ); Sun, 16 Jan 2022 08:23:58 +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: a6b1d4c6-76a5-11ec-9bbc-9dff3e4ee8c5 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642321438; 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=ErBw94A7NHEtLBOjGVvrvddf8O/VaQ+sffKi2esB83Q=; b=uUKXOYpzHeVUejGUQWZzyzoW7MX7yrbQOlfPg9+rBQrRlWeuP8Rh7AgUVg4cFj+C2RmVsk 5SJvOirABifng/bv88zJYH1rtKs0mCet97sEoTzSSnr7R3IpxUHnoYgiLAtB0gQXy5m4Yd W0V0hyY+cNp9Gv5ZOBbqX4dllybQCNo= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: samuel.thibault@ens-lyon.org, Juergen Gross , Wei Liu , Anthony PERARD , Andrew Cooper Subject: [PATCH v3 3/3] tools/libs/ctrl: remove file related handling Date: Sun, 16 Jan 2022 09:23:46 +0100 Message-Id: <20220116082346.26194-4-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20220116082346.26194-1-jgross@suse.com> References: <20220116082346.26194-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642321479516100002 Content-Type: text/plain; charset="utf-8" There is no special file handling related to libxenctrl in Mini-OS any longer, so the close hook can be removed. Signed-off-by: Juergen Gross Acked-by: Andrew Cooper Reviewed-by: Samuel Thibault --- V2: - new patch --- tools/libs/ctrl/xc_minios.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tools/libs/ctrl/xc_minios.c b/tools/libs/ctrl/xc_minios.c index 1799daafdc..3dea7a78a5 100644 --- a/tools/libs/ctrl/xc_minios.c +++ b/tools/libs/ctrl/xc_minios.c @@ -35,15 +35,6 @@ =20 #include "xc_private.h" =20 -void minios_interface_close_fd(int fd); - -extern void minios_interface_close_fd(int fd); - -void minios_interface_close_fd(int fd) -{ - files[fd].type =3D FTYPE_NONE; -} - /* Optionally flush file to disk and discard page cache */ void discard_file_cache(xc_interface *xch, int fd, int flush) { --=20 2.26.2