From patchwork Thu Dec 5 22:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Cooper X-Patchwork-Id: 11275467 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 ED24D1805 for ; Thu, 5 Dec 2019 22:31:40 +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 C9CEC2245C for ; Thu, 5 Dec 2019 22:31:40 +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="B8+jNZwa" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C9CEC2245C 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 1iczdc-0002ll-Lb; Thu, 05 Dec 2019 22:30:20 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iczdb-0002lc-G3 for xen-devel@lists.xenproject.org; Thu, 05 Dec 2019 22:30:19 +0000 X-Inumbo-ID: cdda68a6-17ae-11ea-b4e9-bc764e2007e4 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id cdda68a6-17ae-11ea-b4e9-bc764e2007e4; Thu, 05 Dec 2019 22:30:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1575585013; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lpIOhYimmVKJ2BQvcE8WFnG5aSU4yCKnAe+zqmqTB10=; b=B8+jNZwawspah8E/tFZ9fjYQ1G3GjSdAERy4q6MgA9JoOeqCvMeLwZur 8aO0lx0Q0nEdEgFrWksp46GtEv0aBmjoSFWjTLilLAGLiyKBWgHinIw9K FIY2evFRondgq/Q40a+3btay8DqhLgcAZ+rSTdCwYOJW5+RpqQpHWczfn 4=; Authentication-Results: esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="andrew.cooper3@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa6.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=esa6.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 (esa6.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=esa6.hc3370-68.iphmx.com; envelope-from="Andrew.Cooper3@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: FrxmuZyQPc6PdAqELH3XtLZm57rIrO+k0nuJORln7n9hF92sjvwcv6JIwHI2Jb2Ucaj8yBDB++ vHbNiMLkFvrwjXJwQSSIraPE4cGFAunAfdbZyJsZSbV18pjAz0aL6tYLdhNArytRkvMo8R+22g gCl66KN9zkhA4EigbaLxM45nBikX4rHMwoXWMPdlu2miZskuXyICRHQW8sd2yAsgMLNxcsKIK4 VZ0bFkgPHNdIjKe3TwZ+CM09mV+yWZ0f+ayvxiYXYj9g3FYieRx+OlR1lWxz0FHKOcxV7RVQ/i IRs= X-SBRS: 2.7 X-MesageID: 9693364 X-Ironport-Server: esa6.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="9693364" From: Andrew Cooper To: Xen-devel Date: Thu, 5 Dec 2019 22:30:03 +0000 Message-ID: <20191205223008.8623-2-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 1/6] xen/tasklet: Fix return value truncation on arm64 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" The use of return_reg() assumes ARM's 32bit ABI. Therefore, a failure such as -EINVAL will appear as a large positive number near 4 billion to a 64bit ARM guest which happens to use continue_hypercall_on_cpu(). Introduce a new arch_hypercall_tasklet_result() hook which is implemented by both architectures, and drop the return_reg() macros. This logic will be extended in a later change to make continuations out of the tasklet work. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich Reviewed-by: Julien Grall --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monné CC: Stefano Stabellini CC: Julien Grall CC: Volodymyr Babchuk This was posted on its own previously, but is reset back to v1 now it is in its series. This can't be made static inline due to header constraints, but there is no inherent issue with doing so if the headers become less tangled. Failing the call with -EINVAL for missing the correct CPU is very rude, and addressed in a later patch. --- xen/arch/arm/traps.c | 7 +++++++ xen/arch/x86/hypercall.c | 7 +++++++ xen/common/domain.c | 9 +++++++-- xen/include/asm-arm/regs.h | 2 -- xen/include/asm-x86/regs.h | 2 -- xen/include/xen/domain.h | 6 ++++++ 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index d028ec9224..a20474f87c 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1485,6 +1485,13 @@ static void do_trap_hypercall(struct cpu_user_regs *regs, register_t *nr, regs->pc -= 4; /* re-execute 'hvc #XEN_HYPERCALL_TAG' */ } +void arch_hypercall_tasklet_result(struct vcpu *v, long res) +{ + struct cpu_user_regs *regs = &v->arch.cpu_info->guest_cpu_user_regs; + + HYPERCALL_RESULT_REG(regs) = res; +} + static bool check_multicall_32bit_clean(struct multicall_entry *multi) { int i; diff --git a/xen/arch/x86/hypercall.c b/xen/arch/x86/hypercall.c index 1d42702c6a..7f299d45c6 100644 --- a/xen/arch/x86/hypercall.c +++ b/xen/arch/x86/hypercall.c @@ -166,6 +166,13 @@ unsigned long hypercall_create_continuation( #undef NEXT_ARG +void arch_hypercall_tasklet_result(struct vcpu *v, long res) +{ + struct cpu_user_regs *regs = &v->arch.user_regs; + + regs->rax = res; +} + int hypercall_xlat_continuation(unsigned int *id, unsigned int nr, unsigned int mask, ...) { diff --git a/xen/common/domain.c b/xen/common/domain.c index 611116c7fc..ccf689fcbe 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1665,13 +1665,18 @@ static void continue_hypercall_tasklet_handler(unsigned long _info) { struct migrate_info *info = (struct migrate_info *)_info; struct vcpu *v = info->vcpu; + long res = -EINVAL; /* Wait for vcpu to sleep so that we can access its register state. */ vcpu_sleep_sync(v); this_cpu(continue_info) = info; - return_reg(v) = (info->cpu == smp_processor_id()) - ? info->func(info->data) : -EINVAL; + + if ( likely(info->cpu == smp_processor_id()) ) + res = info->func(info->data); + + arch_hypercall_tasklet_result(v, res); + this_cpu(continue_info) = NULL; if ( info->nest-- == 0 ) diff --git a/xen/include/asm-arm/regs.h b/xen/include/asm-arm/regs.h index 0e3e56b452..ec091a28a2 100644 --- a/xen/include/asm-arm/regs.h +++ b/xen/include/asm-arm/regs.h @@ -57,8 +57,6 @@ static inline bool guest_mode(const struct cpu_user_regs *r) return (diff == 0); } -#define return_reg(v) ((v)->arch.cpu_info->guest_cpu_user_regs.r0) - register_t get_user_reg(struct cpu_user_regs *regs, int reg); void set_user_reg(struct cpu_user_regs *regs, int reg, register_t val); diff --git a/xen/include/asm-x86/regs.h b/xen/include/asm-x86/regs.h index 725a664e0a..dc00b854e3 100644 --- a/xen/include/asm-x86/regs.h +++ b/xen/include/asm-x86/regs.h @@ -15,6 +15,4 @@ (diff == 0); \ }) -#define return_reg(v) ((v)->arch.user_regs.rax) - #endif /* __X86_REGS_H__ */ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 769302057b..1cb205d977 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -103,6 +103,12 @@ void domctl_lock_release(void); int continue_hypercall_on_cpu( unsigned int cpu, long (*func)(void *data), void *data); +/* + * Companion to continue_hypercall_on_cpu(), to feed func()'s result back into + * vcpu regsiter state. + */ +void arch_hypercall_tasklet_result(struct vcpu *v, long res); + extern unsigned int xen_processor_pmbits; extern bool_t opt_dom0_vcpus_pin;