From nobody Mon Feb 9 19:29:54 2026 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=1648130549; cv=none; d=zohomail.com; s=zohoarc; b=fkUNEvCpgAKsSVH9UMSI698CW3uGpBW8uwfs5vrSPCwWHLHAl6IV3vdy20fthHd8Zhs9SbnioVfsgq9jvO+IO3xsVUrsue0fAETNs03SwOZTckTUiZf51jL/UOy/6WfSvBl6XA7cttbQKL7g/7E+UANBrxHatkyiseI7VVxN/wU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1648130549; 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=vOwyucqhO02iXYzENDU2+6ofz8QyJyQuet+mXWldfyU=; b=OTlq1Q+sq3cqF8wdsZB/+xIuFIdMYG0Qf1BUeeMh8PCcllrpJOhKMWGdhvQSolSGgWTTSJdxtk3gd/NcvQo5F5ahbZ86f9gQPW2McJ+dTKzmIF8uFrXbkGNi2FpkUOmMHk7JI2ggEaV+xjPMtEsbgRYUTJr63UfOUnepJT/Vn0Q= 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 1648130549927365.79986158409315; Thu, 24 Mar 2022 07:02:29 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.294333.500454 (Exim 4.92) (envelope-from ) id 1nXO2A-0000hA-79; Thu, 24 Mar 2022 14:01:50 +0000 Received: by outflank-mailman (output) from mailman id 294333.500454; Thu, 24 Mar 2022 14:01:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nXO29-0000eU-OW; Thu, 24 Mar 2022 14:01:49 +0000 Received: by outflank-mailman (input) for mailman id 294333; Thu, 24 Mar 2022 14:01:47 +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 1nXO27-0008Hr-Iy for xen-devel@lists.xenproject.org; Thu, 24 Mar 2022 14:01:47 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f0b9dc12-ab7a-11ec-8fbc-03012f2f19d4; Thu, 24 Mar 2022 15:01:45 +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-out2.suse.de (Postfix) with ESMTPS id 61B921F7AE; Thu, 24 Mar 2022 14:01:45 +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 2A1D013B2F; Thu, 24 Mar 2022 14:01:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QDoECcl5PGKeegAAMHmgww (envelope-from ); Thu, 24 Mar 2022 14:01:45 +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: f0b9dc12-ab7a-11ec-8fbc-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1648130505; 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=vOwyucqhO02iXYzENDU2+6ofz8QyJyQuet+mXWldfyU=; b=WhsYoUg9FoIZCd50MFSFBQBS70vpU5llDfFENWsNA1Ps+aJKs5x6vE4VL368hvzXeMT5HD LQROdFF9fymajXEselI48opR04mGqUvx7hLyVdhKs21p+9JeW1yqF9shG6C+hSDZgyKlVG mImulPL8ozmeUusoteUfZ5Lo/ckb0jM= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Julien Grall , Michal Orzel Subject: [PATCH v6 8/9] xen/arm: call hypercall handlers via generated macro Date: Thu, 24 Mar 2022 15:01:38 +0100 Message-Id: <20220324140139.5899-9-jgross@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220324140139.5899-1-jgross@suse.com> References: <20220324140139.5899-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1648130552219100011 Content-Type: text/plain; charset="utf-8" Instead of using a function table use the generated macros for calling the appropriate hypercall handlers. This makes the calls of the handlers type safe. For deprecated hypercalls define stub functions. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall Tested-by: Michal Orzel --- V2: - make hypercall_args[] const (Jan Beulich) V5: - move out-of-bounds check (Julien Grall) --- xen/arch/arm/traps.c | 117 +++++++++---------------------------------- 1 file changed, 24 insertions(+), 93 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index e906bb4a89..e0fca3b4d8 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1331,67 +1331,20 @@ static register_t do_deprecated_hypercall(void) return -ENOSYS; } =20 -typedef register_t (*arm_hypercall_fn_t)( - register_t, register_t, register_t, register_t, register_t); - -typedef struct { - arm_hypercall_fn_t fn; - int nr_args; -} arm_hypercall_t; - -#define HYPERCALL(_name, _nr_args) \ - [ __HYPERVISOR_ ## _name ] =3D { \ - .fn =3D (arm_hypercall_fn_t) &do_ ## _name, \ - .nr_args =3D _nr_args, \ - } +long dep_sched_op_compat(int cmd, unsigned long arg) +{ + return do_deprecated_hypercall(); +} =20 -#define HYPERCALL_ARM(_name, _nr_args) \ - [ __HYPERVISOR_ ## _name ] =3D { \ - .fn =3D (arm_hypercall_fn_t) &do_arm_ ## _name, \ - .nr_args =3D _nr_args, \ - } -/* - * Only use this for hypercalls which were deprecated (i.e. replaced - * by something else) before Xen on ARM was created, i.e. *not* for - * hypercalls which are simply not yet used on ARM. - */ -#define HYPERCALL_DEPRECATED(_name, _nr_args) \ - [ __HYPERVISOR_##_name ] =3D { \ - .fn =3D (arm_hypercall_fn_t) &do_deprecated_hypercall, \ - .nr_args =3D _nr_args, \ - } +long dep_event_channel_op_compat(XEN_GUEST_HANDLE_PARAM(evtchn_op_t) uop) +{ + return do_deprecated_hypercall(); +} =20 -static arm_hypercall_t arm_hypercall_table[] =3D { - HYPERCALL(memory_op, 2), - HYPERCALL(domctl, 1), - HYPERCALL(sched_op, 2), - HYPERCALL_DEPRECATED(sched_op_compat, 2), - HYPERCALL(console_io, 3), - HYPERCALL(xen_version, 2), - HYPERCALL(xsm_op, 1), - HYPERCALL(event_channel_op, 2), - HYPERCALL_DEPRECATED(event_channel_op_compat, 1), - HYPERCALL_ARM(physdev_op, 2), - HYPERCALL_DEPRECATED(physdev_op_compat, 1), - HYPERCALL(sysctl, 2), - HYPERCALL(hvm_op, 2), -#ifdef CONFIG_GRANT_TABLE - HYPERCALL(grant_table_op, 3), -#endif - HYPERCALL(multicall, 2), - HYPERCALL(platform_op, 1), - HYPERCALL(vcpu_op, 3), - HYPERCALL(vm_assist, 2), -#ifdef CONFIG_ARGO - HYPERCALL(argo_op, 5), -#endif -#ifdef CONFIG_HYPFS - HYPERCALL(hypfs_op, 5), -#endif -#ifdef CONFIG_IOREQ_SERVER - HYPERCALL(dm_op, 3), -#endif -}; +long dep_physdev_op_compat(XEN_GUEST_HANDLE_PARAM(physdev_op_t) uop) +{ + return do_deprecated_hypercall(); +} =20 #ifndef NDEBUG static void do_debug_trap(struct cpu_user_regs *regs, unsigned int code) @@ -1430,7 +1383,6 @@ static void do_debug_trap(struct cpu_user_regs *regs,= unsigned int code) #define HYPERCALL_ARG3(r) (r)->x2 #define HYPERCALL_ARG4(r) (r)->x3 #define HYPERCALL_ARG5(r) (r)->x4 -#define HYPERCALL_ARGS(r) (r)->x0, (r)->x1, (r)->x2, (r)->x3, (r)->x4 #else #define HYPERCALL_RESULT_REG(r) (r)->r0 #define HYPERCALL_ARG1(r) (r)->r0 @@ -1438,52 +1390,40 @@ static void do_debug_trap(struct cpu_user_regs *reg= s, unsigned int code) #define HYPERCALL_ARG3(r) (r)->r2 #define HYPERCALL_ARG4(r) (r)->r3 #define HYPERCALL_ARG5(r) (r)->r4 -#define HYPERCALL_ARGS(r) (r)->r0, (r)->r1, (r)->r2, (r)->r3, (r)->r4 #endif =20 +static const unsigned char hypercall_args[] =3D hypercall_args_arm; + static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, const union hsr hsr) { - arm_hypercall_fn_t call =3D NULL; struct vcpu *curr =3D current; =20 - BUILD_BUG_ON(NR_hypercalls < ARRAY_SIZE(arm_hypercall_table) ); - if ( hsr.iss !=3D XEN_HYPERCALL_TAG ) { gprintk(XENLOG_WARNING, "Invalid HVC imm 0x%x\n", hsr.iss); return inject_undef_exception(regs, hsr); } =20 - if ( *nr >=3D ARRAY_SIZE(arm_hypercall_table) ) - { - perfc_incr(invalid_hypercalls); - HYPERCALL_RESULT_REG(regs) =3D -ENOSYS; - return; - } - curr->hcall_preempted =3D false; =20 perfc_incra(hypercalls, *nr); - call =3D arm_hypercall_table[*nr].fn; - if ( call =3D=3D NULL ) - { - HYPERCALL_RESULT_REG(regs) =3D -ENOSYS; - return; - } =20 - HYPERCALL_RESULT_REG(regs) =3D call(HYPERCALL_ARGS(regs)); + call_handlers_arm(*nr, HYPERCALL_RESULT_REG(regs), HYPERCALL_ARG1(regs= ), + HYPERCALL_ARG2(regs), HYPERCALL_ARG3(regs), + HYPERCALL_ARG4(regs), HYPERCALL_ARG5(regs)); =20 #ifndef NDEBUG - if ( !curr->hcall_preempted ) + if ( !curr->hcall_preempted && HYPERCALL_RESULT_REG(regs) !=3D -ENOSYS= ) { /* Deliberately corrupt parameter regs used by this hypercall. */ - switch ( arm_hypercall_table[*nr].nr_args ) { + switch ( hypercall_args[*nr] ) { case 5: HYPERCALL_ARG5(regs) =3D 0xDEADBEEF; case 4: HYPERCALL_ARG4(regs) =3D 0xDEADBEEF; case 3: HYPERCALL_ARG3(regs) =3D 0xDEADBEEF; case 2: HYPERCALL_ARG2(regs) =3D 0xDEADBEEF; case 1: /* Don't clobber x0/r0 -- it's the return value */ + case 0: /* -ENOSYS case */ break; default: BUG(); } @@ -1520,7 +1460,7 @@ static bool check_multicall_32bit_clean(struct multic= all_entry *multi) { int i; =20 - for ( i =3D 0; i < arm_hypercall_table[multi->op].nr_args; i++ ) + for ( i =3D 0; i < hypercall_args[multi->op]; i++ ) { if ( unlikely(multi->args[i] & 0xffffffff00000000ULL) ) { @@ -1537,16 +1477,8 @@ static bool check_multicall_32bit_clean(struct multi= call_entry *multi) enum mc_disposition arch_do_multicall_call(struct mc_state *state) { struct multicall_entry *multi =3D &state->call; - arm_hypercall_fn_t call =3D NULL; - - if ( multi->op >=3D ARRAY_SIZE(arm_hypercall_table) ) - { - multi->result =3D -ENOSYS; - return mc_continue; - } =20 - call =3D arm_hypercall_table[multi->op].fn; - if ( call =3D=3D NULL ) + if ( multi->op >=3D ARRAY_SIZE(hypercall_args) ) { multi->result =3D -ENOSYS; return mc_continue; @@ -1556,9 +1488,8 @@ enum mc_disposition arch_do_multicall_call(struct mc_= state *state) !check_multicall_32bit_clean(multi) ) return mc_continue; =20 - multi->result =3D call(multi->args[0], multi->args[1], - multi->args[2], multi->args[3], - multi->args[4]); + call_handlers_arm(multi->op, multi->result, multi->args[0], multi->arg= s[1], + multi->args[2], multi->args[3], multi->args[4]); =20 return likely(!regs_mode_is_user(guest_cpu_user_regs())) ? mc_continue : mc_preempt; --=20 2.34.1