From nobody Tue Feb 10 05:10:11 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 ARC-Seal: i=1; a=rsa-sha256; t=1606244896; cv=none; d=zohomail.com; s=zohoarc; b=LXQlNa8q5z7xOp+/VFnpyHf3zC0IdWqNCE4PR/K6ovcpxcCPg2r1RpZAkDSbbGzyhwH1Soa440Y5mBEChGNLtQkCjWBzu6KNUTw1rAhfKH+VcwYYDxXb+AcFic65+xcCZwHgyO+wJz7zMyXM+YHeiVfWJzRowVEX80msp6pm77I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606244896; h=Content-Type: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=qCj+b7kUEK5qNRXOsdjbFaxQEVZq3bySvvwQ+49gYL8=; b=YhzwSOTujNV3kg7J1wnBDvLJX7n6hLl1lpidD7OQLSbgh/sBFlQ7tmGerTTZ7+k9VbMzluokaxKjnHfOTBtUKHeoyULHMEuub3LvOHjHcC0Ewid4eTF1nZ+J25YGvhxojr9OoT1EMJLlWgWmqsAs2Qh/lUSrwJZu6hiaOWyaYyQ= 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1606244896654750.0196769220137; Tue, 24 Nov 2020 11:08:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.36806.68854 (Exim 4.92) (envelope-from ) id 1khdfK-0001K3-Ce; Tue, 24 Nov 2020 19:07:50 +0000 Received: by outflank-mailman (output) from mailman id 36806.68854; Tue, 24 Nov 2020 19:07: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 1khdfK-0001Jr-5R; Tue, 24 Nov 2020 19:07:50 +0000 Received: by outflank-mailman (input) for mailman id 36806; Tue, 24 Nov 2020 19:07:49 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfJ-0001JB-G5 for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 19:07:49 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfJ-0003sp-9L; Tue, 24 Nov 2020 19:07:49 +0000 Received: from host86-183-162-145.range86-183.btcentralplus.com ([86.183.162.145] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khdfJ-0000r4-1K; Tue, 24 Nov 2020 19:07:49 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfJ-0001JB-G5 for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 19:07:49 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfJ-0003sp-9L; Tue, 24 Nov 2020 19:07:49 +0000 Received: from host86-183-162-145.range86-183.btcentralplus.com ([86.183.162.145] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khdfJ-0000r4-1K; Tue, 24 Nov 2020 19:07:49 +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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=qCj+b7kUEK5qNRXOsdjbFaxQEVZq3bySvvwQ+49gYL8=; b=02yqj8nobdlLzlDyZKi2MzK9PP dr1swJrJjZh2KVx5d+CdyqQoUfLVUmAlRSU16JvxRGDECvT63AEd//s/5VLjxnggcqa5roYrdomqF PUdMZBN//YQ7Zdd9hJCIBvGeefXv+L5Zh1maMizBgppKjN+7lPHqbzUwwyqyn4qfUnLk=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 03/13] viridian: move IPI hypercall implementation into separate function Date: Tue, 24 Nov 2020 19:07:34 +0000 Message-Id: <20201124190744.11343-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201124190744.11343-1-paul@xen.org> References: <20201124190744.11343-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @xen.org) From: Paul Durrant This patch moves the implementation of HVCALL_SEND_IPI that is currently inline in viridian_hypercall() into a new hvcall_ipi() function. The new function returns Xen errno values similarly to hvcall_flush(). Hence the errno translation code in viridial_hypercall() is generalized, removing the need for the local 'status' variable. NOTE: The formatting of the switch statement at the top of viridial_hypercall() is also adjusted as per CODING_STYLE. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monn=C3=A9" v3: - Adjust prototype of new function v2: - Different formatting adjustment --- xen/arch/x86/hvm/viridian/viridian.c | 168 ++++++++++++++------------- 1 file changed, 87 insertions(+), 81 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridi= an/viridian.c index 7871e425cbfe..8ac1b32565a8 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -581,13 +581,72 @@ static int hvcall_flush(const union hypercall_input *= input, return 0; } =20 +static int hvcall_ipi(const union hypercall_input *input, + union hypercall_output *output, + paddr_t input_params_gpa, + paddr_t output_params_gpa) +{ + struct domain *currd =3D current->domain; + struct vcpu *v; + uint32_t vector; + uint64_t vcpu_mask; + + /* Get input parameters. */ + if ( input->fast ) + { + if ( input_params_gpa >> 32 ) + return -EINVAL; + + vector =3D input_params_gpa; + vcpu_mask =3D output_params_gpa; + } + else + { + struct { + uint32_t vector; + uint8_t target_vtl; + uint8_t reserved_zero[3]; + uint64_t vcpu_mask; + } input_params; + + if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, + sizeof(input_params)) !=3D HVMTRANS_= okay ) + return -EINVAL; + + if ( input_params.target_vtl || + input_params.reserved_zero[0] || + input_params.reserved_zero[1] || + input_params.reserved_zero[2] ) + return -EINVAL; + + vector =3D input_params.vector; + vcpu_mask =3D input_params.vcpu_mask; + } + + if ( vector < 0x10 || vector > 0xff ) + return -EINVAL; + + for_each_vcpu ( currd, v ) + { + if ( v->vcpu_id >=3D (sizeof(vcpu_mask) * 8) ) + return -EINVAL; + + if ( !(vcpu_mask & (1ul << v->vcpu_id)) ) + continue; + + vlapic_set_irq(vcpu_vlapic(v), vector, 0); + } + + return 0; +} + int viridian_hypercall(struct cpu_user_regs *regs) { struct vcpu *curr =3D current; struct domain *currd =3D curr->domain; int mode =3D hvm_guest_x86_mode(curr); unsigned long input_params_gpa, output_params_gpa; - uint16_t status =3D HV_STATUS_SUCCESS; + int rc =3D 0; union hypercall_input input; union hypercall_output output =3D {}; =20 @@ -600,11 +659,13 @@ int viridian_hypercall(struct cpu_user_regs *regs) input_params_gpa =3D regs->rdx; output_params_gpa =3D regs->r8; break; + case 4: input.raw =3D (regs->rdx << 32) | regs->eax; input_params_gpa =3D (regs->rbx << 32) | regs->ecx; output_params_gpa =3D (regs->rdi << 32) | regs->esi; break; + default: goto out; } @@ -616,92 +677,18 @@ int viridian_hypercall(struct cpu_user_regs *regs) * See section 14.5.1 of the specification. */ do_sched_op(SCHEDOP_yield, guest_handle_from_ptr(NULL, void)); - status =3D HV_STATUS_SUCCESS; break; =20 case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: - { - int rc =3D hvcall_flush(&input, &output, input_params_gpa, - output_params_gpa); - - switch ( rc ) - { - case 0: - break; - - case -ERESTART: - return HVM_HCALL_preempted; - - default: - ASSERT_UNREACHABLE(); - /* Fallthrough */ - case -EINVAL: - status =3D HV_STATUS_INVALID_PARAMETER; - break; - } - + rc =3D hvcall_flush(&input, &output, input_params_gpa, + output_params_gpa); break; - } =20 case HVCALL_SEND_IPI: - { - struct vcpu *v; - uint32_t vector; - uint64_t vcpu_mask; - - status =3D HV_STATUS_INVALID_PARAMETER; - - /* Get input parameters. */ - if ( input.fast ) - { - if ( input_params_gpa >> 32 ) - break; - - vector =3D input_params_gpa; - vcpu_mask =3D output_params_gpa; - } - else - { - struct { - uint32_t vector; - uint8_t target_vtl; - uint8_t reserved_zero[3]; - uint64_t vcpu_mask; - } input_params; - - if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, - sizeof(input_params)) !=3D - HVMTRANS_okay ) - break; - - if ( input_params.target_vtl || - input_params.reserved_zero[0] || - input_params.reserved_zero[1] || - input_params.reserved_zero[2] ) - break; - - vector =3D input_params.vector; - vcpu_mask =3D input_params.vcpu_mask; - } - - if ( vector < 0x10 || vector > 0xff ) - break; - - for_each_vcpu ( currd, v ) - { - if ( v->vcpu_id >=3D (sizeof(vcpu_mask) * 8) ) - break; - - if ( !(vcpu_mask & (1ul << v->vcpu_id)) ) - continue; - - vlapic_set_irq(vcpu_vlapic(v), vector, 0); - } - - status =3D HV_STATUS_SUCCESS; + rc =3D hvcall_ipi(&input, &output, input_params_gpa, + output_params_gpa); break; - } =20 default: gprintk(XENLOG_WARNING, "unimplemented hypercall %04x\n", @@ -714,12 +701,31 @@ int viridian_hypercall(struct cpu_user_regs *regs) * Given that return a status of 'invalid code' has not so far * caused any problems it's not worth logging. */ - status =3D HV_STATUS_INVALID_HYPERCALL_CODE; + rc =3D -EOPNOTSUPP; break; } =20 out: - output.result =3D status; + switch ( rc ) + { + case 0: + break; + + case -ERESTART: + return HVM_HCALL_preempted; + + case -EOPNOTSUPP: + output.result =3D HV_STATUS_INVALID_HYPERCALL_CODE; + break; + + default: + ASSERT_UNREACHABLE(); + /* Fallthrough */ + case -EINVAL: + output.result =3D HV_STATUS_INVALID_PARAMETER; + break; + } + switch (mode) { case 8: regs->rax =3D output.raw; --=20 2.20.1