From patchwork Thu Dec 5 22:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11275469 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 88090112B for ; Thu, 5 Dec 2019 22:31:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 64B252245C for ; Thu, 5 Dec 2019 22:31:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="CfYEtc0O" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64B252245C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iczdw-0002tJ-5D; Thu, 05 Dec 2019 22:30:40 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iczdv-0002sy-HK for xen-devel@lists.xenproject.org; Thu, 05 Dec 2019 22:30:39 +0000 X-Inumbo-ID: d05222c2-17ae-11ea-a4fd-bc764e2007e4 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d05222c2-17ae-11ea-a4fd-bc764e2007e4; Thu, 05 Dec 2019 22:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1575585018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=joi+VZd3mz5B32uwmuHcitbgODO0/CfV0/+okJBJSME=; b=CfYEtc0OC6apiJjqxUMWklFsFnGytxBAUU6tgoG42tkbEG3H/drh8Qjd veQOL80gRsyj0j1iscrI5shDbMdwti5x5+rPdUC0SlwVDrf+b5GWQ8Nuw FdfwuYmt09YxVO3FIKxKzP0gnDbhYj0HnKIgaLP2spKyK8fEu78IUuT7n U=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=andrew.cooper3@citrix.com; spf=Pass smtp.mailfrom=Andrew.Cooper3@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of andrew.cooper3@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Andrew.Cooper3@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="Andrew.Cooper3@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: sgFanSAODiDFXas1xU1JiqRKoM5HlSpicKQgquHrZ86mRJRa2iWXNKxb97m74net1STy0p3WbX x0Qump4ICp5Tggs52I4BfU+Cn+xOyXDZ6B6R5oFgb/4AIvZbVw4DotjCLV3ktPc186sVmbHlgn cVqptJr7P93ldzG9q5PiNFwND9nxu36ZS9Uu8zhYSd824udA5X53J4m49Z0uM9VAuFsboJYoXw 0dgu4217FJIMFVOlfX4+Uxu4EX0X6YN52VU8BFWr8PdaveNo6RqsxHxZIWU+9i1ptA9ePH4mDU y9Q= X-SBRS: 2.7 X-MesageID: 9407209 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,282,1571716800"; d="scan'208";a="9407209" From: Andrew Cooper To: Xen-devel Date: Thu, 5 Dec 2019 22:30:07 +0000 Message-ID: <20191205223008.8623-6-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191205223008.8623-1-andrew.cooper3@citrix.com> References: <20191205223008.8623-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 5/6] xen/tasklet: Return -ERESTART from continue_hypercall_on_cpu() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Jan Beulich , Volodymyr Babchuk , =?utf-8?q?Roger_Pau_Monn?= =?utf-8?q?=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Some hypercalls tasklets want to create a continuation, rather than fail the hypercall with a hard error. By the time the tasklet is executing, it is too late to create the continuation, and even continue_hypercall_on_cpu() doesn't have enough state to do it correctly. All callers of continue_hypercall_on_cpu() have been updated to turn -ERESTART into a continuation, where appropriate modifications can be made to register and/or memory parameters. This changes the continue_hypercall_on_cpu() behaviour to unconditionally create a hypercall continuation, in case the tasklet wants to use it, and then to have arch_hypercall_tasklet_result() cancel the continuation when a result is available. None of these hypercalls are fast paths. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk There is one RFC point. The statement in the header file of "If this function returns 0 then the function is guaranteed to run at some point in the future." was never true. In the case of a CPU miss, the hypercall would be blindly failed with -EINVAL. The current behaviour with this patch is to not cancel the continuation, which I think is less bad, but still not great. Thoughts? --- xen/arch/arm/traps.c | 1 + xen/arch/x86/hypercall.c | 7 +++++++ xen/common/domain.c | 9 +++++---- xen/include/xen/domain.h | 11 ++++++++--- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index a20474f87c..5d35d2b7e9 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1489,6 +1489,7 @@ void arch_hypercall_tasklet_result(struct vcpu *v, long res) { struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs; + regs->pc += 4; /* Skip over 'hvc #XEN_HYPERCALL_TAG' */ HYPERCALL_RESULT_REG(regs) = res; } diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c index 7f299d45c6..42d95f9b9a 100644 --- a/xen/arch/x86/hypercall.c +++ b/xen/arch/x86/hypercall.c @@ -170,6 +170,13 @@ void arch_hypercall_tasklet_result(struct vcpu *v, long res) { struct cpu_user_regs *regs = &v->arch.user_regs; + /* + * PV hypercalls are all 2-byte instructions (INT $0x82, SYSCALL). HVM + * hypercalls are all 3-byte instructions (VMCALL, VMMCALL). + * + * Move %rip forwards to complete the continuation. + */ + regs->rip += 2 + is_hvm_vcpu(v); regs->rax = res; } diff --git a/xen/common/domain.c b/xen/common/domain.c index ab7e4d09c0..eb69db3078 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1665,7 +1665,7 @@ static void continue_hypercall_tasklet_handler(void *data) { struct migrate_info *info = data; struct vcpu *v = info->vcpu; - long res = -EINVAL; + long res = -ERESTART; /* Wait for vcpu to sleep so that we can access its register state. */ vcpu_sleep_sync(v); @@ -1675,7 +1675,8 @@ static void continue_hypercall_tasklet_handler(void *data) if ( likely(info->cpu == smp_processor_id()) ) res = info->func(info->data); - arch_hypercall_tasklet_result(v, res); + if ( res != -ERESTART ) + arch_hypercall_tasklet_result(v, res); this_cpu(continue_info) = NULL; @@ -1726,8 +1727,8 @@ int continue_hypercall_on_cpu( tasklet_schedule_on_cpu(&info->vcpu->continue_hypercall_tasklet, cpu); - /* Dummy return value will be overwritten by tasklet. */ - return 0; + /* Start a continuation. Value will be overwritten by the tasklet. */ + return -ERESTART; } /* diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 1cb205d977..83c737bca4 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -96,9 +96,11 @@ void domctl_lock_release(void); /* * Continue the current hypercall via func(data) on specified cpu. - * If this function returns 0 then the function is guaranteed to run at some - * point in the future. If this function returns an error code then the - * function has not been and will not be executed. + * + * This function returns -ERESTART in the success case, and a higher level + * caller is required to set up a hypercall continuation. func() will be run + * at some point in the future. If this function returns any other error code + * then func() has not, and will not be executed. */ int continue_hypercall_on_cpu( unsigned int cpu, long (*func)(void *data), void *data); @@ -106,6 +108,9 @@ int continue_hypercall_on_cpu( /* * Companion to continue_hypercall_on_cpu(), to feed func()'s result back into * vcpu regsiter state. + * + * Must undo the effects of the hypercall continuation created by + * continue_hypercall_on_cpu()'s caller. */ void arch_hypercall_tasklet_result(struct vcpu *v, long res);