From patchwork Mon Dec 11 13:48:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13487227 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E75C2C10F05 for ; Mon, 11 Dec 2023 13:48:58 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.651887.1017733 (Exim 4.92) (envelope-from ) id 1rCgeG-0004H1-64; Mon, 11 Dec 2023 13:48:40 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 651887.1017733; Mon, 11 Dec 2023 13:48:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCgeG-0004Fv-2w; Mon, 11 Dec 2023 13:48:40 +0000 Received: by outflank-mailman (input) for mailman id 651887; Mon, 11 Dec 2023 13:48:39 +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 1rCgeF-0003yP-B7 for xen-devel@lists.xenproject.org; Mon, 11 Dec 2023 13:48:39 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fb1afd6d-982b-11ee-9b0f-b553b5be7939; Mon, 11 Dec 2023 14:48:36 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8FF881FB93; Mon, 11 Dec 2023 13:48:35 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 65196138FF; Mon, 11 Dec 2023 13:48:35 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id Cix6FzMTd2WCXAAAn2gu4w (envelope-from ); Mon, 11 Dec 2023 13:48:35 +0000 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: fb1afd6d-982b-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302515; 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=tZcEXwjYXRWfbXp2N679W+w4cg8R77K0ZFxZJnPRIZs=; b=WRpSXFQ9FVNVwQ4Gv9mzKwHRuP8lYig0iT/QgXwELUy4IRdf75Sws37Kg5l2bzbkbPVfLA WMBUxHcJvyApC2z3LkE6QJTd1xyDrLdBc7JD9MDIoIqPJQgeRVnjasIwVDpXg1r1JoWV1p sJNI/vj7XrILGeSKQot3aHBi97E+7m8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302515; 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=tZcEXwjYXRWfbXp2N679W+w4cg8R77K0ZFxZJnPRIZs=; b=WRpSXFQ9FVNVwQ4Gv9mzKwHRuP8lYig0iT/QgXwELUy4IRdf75Sws37Kg5l2bzbkbPVfLA WMBUxHcJvyApC2z3LkE6QJTd1xyDrLdBc7JD9MDIoIqPJQgeRVnjasIwVDpXg1r1JoWV1p sJNI/vj7XrILGeSKQot3aHBi97E+7m8= 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 1/3] Mini-OS: call event handlers always with interrupts off Date: Mon, 11 Dec 2023 14:48:25 +0100 Message-Id: <20231211134827.7130-2-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231211134827.7130-1-jgross@suse.com> References: <20231211134827.7130-1-jgross@suse.com> MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spamd-Result: default: False [3.70 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] When unmasking an event channel the associated event handler can be called with interrupts enabled when not running as a PV guest. This can result in hard to debug races in case e.g. a handler is registered for multiple events or when the handler is not using a lock as it assumes to have interrupts disabled. Instead of using the PV interrupt disabling points just before calling the handler, do the disabling once at the very start of force_evtchn_callback(). Replace the evtchn_upcall_mask test in unmask_evtchn() with the more appropriate irqs_disabled() test. As a precaution add a test to do_hypervisor_callback() that interrupts are really disabled and crash in case this is not true. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- hypervisor.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/hypervisor.c b/hypervisor.c index f2cbbc1c..5309daa3 100644 --- a/hypervisor.c +++ b/hypervisor.c @@ -102,6 +102,8 @@ void do_hypervisor_callback(struct pt_regs *regs) shared_info_t *s = HYPERVISOR_shared_info; vcpu_info_t *vcpu_info = &s->vcpu_info[cpu]; + BUG_ON(!irqs_disabled()); + in_callback = 1; vcpu_info->evtchn_upcall_pending = 0; @@ -131,27 +133,19 @@ void do_hypervisor_callback(struct pt_regs *regs) void force_evtchn_callback(void) { -#ifdef XEN_HAVE_PV_UPCALL_MASK - int save; -#endif vcpu_info_t *vcpu; + unsigned long flags; + + local_irq_save(flags); + vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; -#ifdef XEN_HAVE_PV_UPCALL_MASK - save = vcpu->evtchn_upcall_mask; -#endif while (vcpu->evtchn_upcall_pending) { -#ifdef XEN_HAVE_PV_UPCALL_MASK - vcpu->evtchn_upcall_mask = 1; -#endif - barrier(); do_hypervisor_callback(NULL); barrier(); -#ifdef XEN_HAVE_PV_UPCALL_MASK - vcpu->evtchn_upcall_mask = save; - barrier(); -#endif }; + + local_irq_restore(flags); } inline void mask_evtchn(uint32_t port) @@ -177,9 +171,7 @@ inline void unmask_evtchn(uint32_t port) &vcpu_info->evtchn_pending_sel) ) { vcpu_info->evtchn_upcall_pending = 1; -#ifdef XEN_HAVE_PV_UPCALL_MASK - if ( !vcpu_info->evtchn_upcall_mask ) -#endif + if ( !irqs_disabled() ) force_evtchn_callback(); } } From patchwork Mon Dec 11 13:48:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13487226 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C5F4DC4167B for ; Mon, 11 Dec 2023 13:48:57 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.651889.1017747 (Exim 4.92) (envelope-from ) id 1rCgeM-0004cB-F8; Mon, 11 Dec 2023 13:48:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 651889.1017747; Mon, 11 Dec 2023 13:48:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCgeM-0004c4-CD; Mon, 11 Dec 2023 13:48:46 +0000 Received: by outflank-mailman (input) for mailman id 651889; Mon, 11 Dec 2023 13:48:45 +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 1rCgeL-0003yP-79 for xen-devel@lists.xenproject.org; Mon, 11 Dec 2023 13:48:45 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fe5c72c7-982b-11ee-9b0f-b553b5be7939; Mon, 11 Dec 2023 14:48:41 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 15DB3223E4; Mon, 11 Dec 2023 13:48:41 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id DFE44138FF; Mon, 11 Dec 2023 13:48:40 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id vD5/NTgTd2WGXAAAn2gu4w (envelope-from ); Mon, 11 Dec 2023 13:48:40 +0000 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: fe5c72c7-982b-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302521; 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=mptyI+2MUmEUOVgsCKUKUDyQ+zkn0mcu28+VmTFAif0=; b=Uf4SIDrL22ohW4Mkmsi4Ikkh3CzK5tb4BCBkjt1devyV/GC9K/gWaJiBQPRzyiqOIn5pDI tl3dckYrZRG2pe+4zQggVq0ehIgKqXSildsiEqFetSqDQgl79rKfpN0YmoZqfFpiLLKZyt 9xw0xfTxARtzV0ufGg0VGc7q6RnAUFk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302521; 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=mptyI+2MUmEUOVgsCKUKUDyQ+zkn0mcu28+VmTFAif0=; b=Uf4SIDrL22ohW4Mkmsi4Ikkh3CzK5tb4BCBkjt1devyV/GC9K/gWaJiBQPRzyiqOIn5pDI tl3dckYrZRG2pe+4zQggVq0ehIgKqXSildsiEqFetSqDQgl79rKfpN0YmoZqfFpiLLKZyt 9xw0xfTxARtzV0ufGg0VGc7q6RnAUFk= 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 2/3] Mini-OS: drop in_callback variable Date: Mon, 11 Dec 2023 14:48:26 +0100 Message-Id: <20231211134827.7130-3-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231211134827.7130-1-jgross@suse.com> References: <20231211134827.7130-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Bar: / Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b=Uf4SIDrL; dmarc=pass (policy=quarantine) header.from=suse.com; spf=fail (smtp-out1.suse.de: domain of jgross@suse.com does not designate 2a07:de40:b281:104:10:150:64:98 as permitted sender) smtp.mailfrom=jgross@suse.com X-Rspamd-Server: rspamd2 X-Spamd-Result: default: False [0.99 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.com:+]; MX_GOOD(-0.01)[]; DMARC_POLICY_ALLOW(0.00)[suse.com,quarantine]; NEURAL_HAM_SHORT(-0.20)[-1.000]; DMARC_POLICY_ALLOW_WITH_FAILURES(-0.50)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; R_SPF_FAIL(0.00)[-all]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; SPAM_FLAG(5.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; WHITELIST_DMARC(-7.00)[suse.com:D:+]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[] X-Rspamd-Queue-Id: 15DB3223E4 Now that do_hypervisor_callback() is always called with interrupts off the in_callback variable meant to handle recursive calls of do_hypervisor_callback() can be dropped. As a precaution add a test to do_hypervisor_callback() that interrupts are really disabled and crash in case this is not true. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- hypervisor.c | 6 ------ include/hypervisor.h | 2 -- sched.c | 11 ----------- 3 files changed, 19 deletions(-) diff --git a/hypervisor.c b/hypervisor.c index 5309daa3..6facce3e 100644 --- a/hypervisor.c +++ b/hypervisor.c @@ -37,8 +37,6 @@ EXPORT_SYMBOL(hypercall_page); ((sh)->evtchn_pending[idx] & \ ~(sh)->evtchn_mask[idx]) -int in_callback; - #ifndef CONFIG_PARAVIRT extern shared_info_t shared_info; @@ -104,8 +102,6 @@ void do_hypervisor_callback(struct pt_regs *regs) BUG_ON(!irqs_disabled()); - in_callback = 1; - vcpu_info->evtchn_upcall_pending = 0; /* NB x86. No need for a barrier here -- XCHG is a barrier on x86. */ #if !defined(__i386__) && !defined(__x86_64__) @@ -127,8 +123,6 @@ void do_hypervisor_callback(struct pt_regs *regs) do_event(port, regs); } } - - in_callback = 0; } void force_evtchn_callback(void) diff --git a/include/hypervisor.h b/include/hypervisor.h index 1d092719..b852a42a 100644 --- a/include/hypervisor.h +++ b/include/hypervisor.h @@ -50,6 +50,4 @@ void mask_evtchn(uint32_t port); void unmask_evtchn(uint32_t port); void clear_evtchn(uint32_t port); -extern int in_callback; - #endif /* __HYPERVISOR_H__ */ diff --git a/sched.c b/sched.c index e162cb60..3335efa0 100644 --- a/sched.c +++ b/sched.c @@ -76,11 +76,6 @@ void schedule(void) prev = current; local_irq_save(flags); - if (in_callback) { - printk("Must not call schedule() from a callback\n"); - BUG(); - } - do { /* Examine all threads. Find a runnable thread, but also wake up expired ones and find the @@ -151,15 +146,12 @@ struct thread* create_thread(char *name, void (*function)(void *), void *data) EXPORT_SYMBOL(create_thread); #ifdef HAVE_LIBC -static struct _reent callback_reent; struct _reent *__getreent(void) { struct _reent *_reent; if (!threads_started) _reent = _impure_ptr; - else if (in_callback) - _reent = &callback_reent; else _reent = &get_current()->reent; @@ -246,9 +238,6 @@ void init_sched(void) { printk("Initialising scheduler\n"); -#ifdef HAVE_LIBC - _REENT_INIT_PTR((&callback_reent)) -#endif idle_thread = create_thread("Idle", idle_thread_fn, NULL); } From patchwork Mon Dec 11 13:48:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 13487228 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F00EC4167B for ; Mon, 11 Dec 2023 13:49:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.651891.1017761 (Exim 4.92) (envelope-from ) id 1rCgeS-00052Y-UV; Mon, 11 Dec 2023 13:48:52 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 651891.1017761; Mon, 11 Dec 2023 13:48:52 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rCgeS-00052N-QF; Mon, 11 Dec 2023 13:48:52 +0000 Received: by outflank-mailman (input) for mailman id 651891; Mon, 11 Dec 2023 13:48:50 +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 1rCgeQ-0003yP-SB for xen-devel@lists.xenproject.org; Mon, 11 Dec 2023 13:48:50 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [2a07:de40:b251:101:10:150:64:1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 01acbb79-982c-11ee-9b0f-b553b5be7939; Mon, 11 Dec 2023 14:48:47 +0100 (CET) Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9E5AF223E4; Mon, 11 Dec 2023 13:48:46 +0000 (UTC) Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id 69AD9138FF; Mon, 11 Dec 2023 13:48:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap2.dmz-prg2.suse.org with ESMTPSA id G652GD4Td2WLXAAAn2gu4w (envelope-from ); Mon, 11 Dec 2023 13:48:46 +0000 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: 01acbb79-982c-11ee-9b0f-b553b5be7939 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302526; 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=OA3eqJkLhrJF95nie+tSJNJgPrb6XVcu2lYX465lxis=; b=RxgiYQryzIXbg3BaZ/Bl6v1l/TrDP5b5pWFFxcoIArAeoYL9jxLTuBGyi8iUwRh8Eh79nB PODVSfrpRVihpzTam7Qb630g2hYlngNXQL81km0fHbmYrzIvhrr/AcoOiyKJFVqaWYsH9K dzXjGo9Ikl5789VVNcNZ5aUSIEqeqF8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1702302526; 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=OA3eqJkLhrJF95nie+tSJNJgPrb6XVcu2lYX465lxis=; b=RxgiYQryzIXbg3BaZ/Bl6v1l/TrDP5b5pWFFxcoIArAeoYL9jxLTuBGyi8iUwRh8Eh79nB PODVSfrpRVihpzTam7Qb630g2hYlngNXQL81km0fHbmYrzIvhrr/AcoOiyKJFVqaWYsH9K dzXjGo9Ikl5789VVNcNZ5aUSIEqeqF8= 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 3/3] Mini-OS: cleanup hypervisor.c Date: Mon, 11 Dec 2023 14:48:27 +0100 Message-Id: <20231211134827.7130-4-jgross@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20231211134827.7130-1-jgross@suse.com> References: <20231211134827.7130-1-jgross@suse.com> MIME-Version: 1.0 X-Spamd-Result: default: False [8.80 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; BAYES_SPAM(5.10)[100.00%]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; R_MISSING_CHARSET(2.50)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; BROKEN_CONTENT_TYPE(1.50)[]; RCPT_COUNT_FIVE(0.00)[5]; NEURAL_HAM_LONG(-1.00)[-1.000]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MID_CONTAINS_FROM(1.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[] Authentication-Results: smtp-out1.suse.de; none Do the following cleanups in hypervisor.c: - Let hypervisor.c conform to the coding style. - Drop the bogus "inline" attributes of exported functions. - Replace a always zero cpu variable with smp_processor_id() as elsewhere in the code. - Replace "if () BUG()" with BUG_ON() in case the condition has no side effects. - Drop the unused cpu parameter from the active_evtchns() macro. Signed-off-by: Juergen Gross Reviewed-by: Samuel Thibault --- hypervisor.c | 62 ++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/hypervisor.c b/hypervisor.c index 6facce3e..ba535556 100644 --- a/hypervisor.c +++ b/hypervisor.c @@ -1,27 +1,27 @@ /****************************************************************************** * hypervisor.c - * + * * Communication to/from hypervisor. - * + * * Copyright (c) 2002-2003, K A Fraser * Copyright (c) 2005, Grzegorz Milos, gm281@cam.ac.uk,Intel Research Cambridge - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to * deal in the Software without restriction, including without limitation the * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ @@ -33,9 +33,8 @@ EXPORT_SYMBOL(hypercall_page); -#define active_evtchns(cpu,sh,idx) \ - ((sh)->evtchn_pending[idx] & \ - ~(sh)->evtchn_mask[idx]) +#define active_evtchns(sh, idx) \ + ((sh)->evtchn_pending[idx] & ~(sh)->evtchn_mask[idx]) #ifndef CONFIG_PARAVIRT extern shared_info_t shared_info; @@ -48,10 +47,10 @@ int hvm_get_parameter(int idx, uint64_t *value) xhv.domid = DOMID_SELF; xhv.index = idx; ret = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv); - if ( ret < 0 ) - BUG(); + BUG_ON(ret < 0); *value = xhv.value; + return ret; } @@ -62,6 +61,7 @@ int hvm_set_parameter(int idx, uint64_t value) xhv.domid = DOMID_SELF; xhv.index = idx; xhv.value = value; + return HYPERVISOR_hvm_op(HVMOP_set_param, &xhv); } @@ -87,18 +87,15 @@ void unmap_shared_info(void) xrtp.gpfn = virt_to_pfn(&shared_info); if ( HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrtp) != 0 ) BUG(); - - return; } #endif void do_hypervisor_callback(struct pt_regs *regs) { - unsigned long l1, l2, l1i, l2i; - unsigned int port; - int cpu = 0; + unsigned long l1, l2, l1i, l2i; + unsigned int port; shared_info_t *s = HYPERVISOR_shared_info; - vcpu_info_t *vcpu_info = &s->vcpu_info[cpu]; + vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()]; BUG_ON(!irqs_disabled()); @@ -113,13 +110,13 @@ void do_hypervisor_callback(struct pt_regs *regs) { l1i = __ffs(l1); l1 &= ~(1UL << l1i); - - while ( (l2 = active_evtchns(cpu, s, l1i)) != 0 ) + + while ( (l2 = active_evtchns(s, l1i)) != 0 ) { l2i = __ffs(l2); l2 &= ~(1UL << l2i); - port = (l1i * (sizeof(unsigned long) * 8)) + l2i; + port = l1i * sizeof(unsigned long) * 8 + l2i; do_event(port, regs); } } @@ -134,7 +131,8 @@ void force_evtchn_callback(void) vcpu = &HYPERVISOR_shared_info->vcpu_info[smp_processor_id()]; - while (vcpu->evtchn_upcall_pending) { + while ( vcpu->evtchn_upcall_pending ) + { do_hypervisor_callback(NULL); barrier(); }; @@ -142,14 +140,15 @@ void force_evtchn_callback(void) local_irq_restore(flags); } -inline void mask_evtchn(uint32_t port) +void mask_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; + synch_set_bit(port, &s->evtchn_mask[0]); } EXPORT_SYMBOL(mask_evtchn); -inline void unmask_evtchn(uint32_t port) +void unmask_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; vcpu_info_t *vcpu_info = &s->vcpu_info[smp_processor_id()]; @@ -160,9 +159,9 @@ inline void unmask_evtchn(uint32_t port) * The following is basically the equivalent of 'hw_resend_irq'. Just like * a real IO-APIC we 'lose the interrupt edge' if the channel is masked. */ - if ( synch_test_bit (port, &s->evtchn_pending[0]) && + if ( synch_test_bit(port, &s->evtchn_pending[0]) && !synch_test_and_set_bit(port / (sizeof(unsigned long) * 8), - &vcpu_info->evtchn_pending_sel) ) + &vcpu_info->evtchn_pending_sel) ) { vcpu_info->evtchn_upcall_pending = 1; if ( !irqs_disabled() ) @@ -171,9 +170,10 @@ inline void unmask_evtchn(uint32_t port) } EXPORT_SYMBOL(unmask_evtchn); -inline void clear_evtchn(uint32_t port) +void clear_evtchn(uint32_t port) { shared_info_t *s = HYPERVISOR_shared_info; + synch_clear_bit(port, &s->evtchn_pending[0]); } EXPORT_SYMBOL(clear_evtchn);