From patchwork Wed Aug 23 11:58:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Woodhouse X-Patchwork-Id: 13362215 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D110EE4993 for ; Wed, 23 Aug 2023 11:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234616AbjHWL6d (ORCPT ); Wed, 23 Aug 2023 07:58:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232284AbjHWL6c (ORCPT ); Wed, 23 Aug 2023 07:58:32 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA4B8E5D for ; Wed, 23 Aug 2023 04:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=MIME-Version:Content-Type:Date:Cc:To: From:Subject:Message-ID:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:In-Reply-To:References; bh=gJy8F+Lt6z2CPN7PCJA/wQVQf2b8kgzRE4CLZadhLaI=; b=QIxS/ARETWS4fSFQaxNTNF/9OQ R+655rOGOfBWFUZAkKJArm2fPPCr1blijF531Yvb+z4uUoRocoRBHMxWtje5xNnV2nN1RB+lDwuMN FwXdR/ymYuNPNcwW+TeYELJwK0MykQN1KmenmSctilfr9iQidS6AVUssqePmj3sWlLNAeLxqVUIPw 8Fjv9kSH+4c56Uhw1tjw0KA5+pEaXpJ2mcST9d8VzZB4gYfjtGYWr5iaLefhQSahL4OimQQfUHemd ajtaJxnhhcROcGb1pcg040mzrDKBKQoeVffzs9ZlUQIJx16PVuuSwmuIHufmTuXLkAvT/PWxsWkIP ovBBJaMw==; Received: from 54-240-197-239.amazon.com ([54.240.197.239] helo=edge-infra-2.e-lhr50.amazon.com) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1qYmV3-004fo9-Rr; Wed, 23 Aug 2023 11:58:14 +0000 Message-ID: <5b30b245ba7714eb1420da43da979f9e8cb7e02c.camel@infradead.org> Subject: [PATCH] i386/xen: Ignore VCPU_SSHOTTMR_future flag in set_singleshot_timer() From: David Woodhouse To: qemu-devel Cc: Paul Durrant , Paolo Bonzini , Marcelo Tosatti , kvm , Roger Pau =?iso-8859-1?q?Monn=E9?= , Jan Beulich Date: Wed, 23 Aug 2023 12:58:11 +0100 User-Agent: Evolution 3.44.4-0ubuntu2 MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: David Woodhouse Upstream Xen now ignores this flag¹, since the only guest kernel ever to use it was buggy. ¹ https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=19c6cbd909 Signed-off-by: David Woodhouse Reviewed-by: Paul Durrant --- We do take an argument to emulate a specific Xen version, and *theoretically* we could ignore the VCPU_SSHOTTMR_future flag only if we're emulating Xen 4.17 or newer? But I don't think it's worth doing that (and QEMU won't be the only instance of Xen emulation or even real older Xen versions patched to ignore the flag). target/i386/kvm/xen-emu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/target/i386/kvm/xen-emu.c b/target/i386/kvm/xen-emu.c index b307c75713..3810dc7d70 100644 --- a/target/i386/kvm/xen-emu.c +++ b/target/i386/kvm/xen-emu.c @@ -1070,17 +1070,13 @@ static int vcpuop_stop_periodic_timer(CPUState *target) * Must always be called with xen_timers_lock held. */ static int do_set_singleshot_timer(CPUState *cs, uint64_t timeout_abs, - bool future, bool linux_wa) + bool linux_wa) { CPUX86State *env = &X86_CPU(cs)->env; int64_t now = kvm_get_current_ns(); int64_t qemu_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); int64_t delta = timeout_abs - now; - if (future && timeout_abs < now) { - return -ETIME; - } - if (linux_wa && unlikely((int64_t)timeout_abs < 0 || (delta > 0 && (uint32_t)(delta >> 50) != 0))) { /* @@ -1122,9 +1118,13 @@ static int vcpuop_set_singleshot_timer(CPUState *cs, uint64_t arg) } QEMU_LOCK_GUARD(&X86_CPU(cs)->env.xen_timers_lock); - return do_set_singleshot_timer(cs, sst.timeout_abs_ns, - !!(sst.flags & VCPU_SSHOTTMR_future), - false); + + /* + * We ignore the VCPU_SSHOTTMR_future flag, just as Xen now does. + * The only guest that ever used it, got it wrong. + * https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=19c6cbd909 + */ + return do_set_singleshot_timer(cs, sst.timeout_abs_ns, false); } static int vcpuop_stop_singleshot_timer(CPUState *cs) @@ -1149,7 +1149,7 @@ static bool kvm_xen_hcall_set_timer_op(struct kvm_xen_exit *exit, X86CPU *cpu, err = vcpuop_stop_singleshot_timer(CPU(cpu)); } else { QEMU_LOCK_GUARD(&X86_CPU(cpu)->env.xen_timers_lock); - err = do_set_singleshot_timer(CPU(cpu), timeout, false, true); + err = do_set_singleshot_timer(CPU(cpu), timeout, true); } exit->u.hcall.result = err; return true; @@ -1837,7 +1837,7 @@ int kvm_put_xen_state(CPUState *cs) QEMU_LOCK_GUARD(&env->xen_timers_lock); if (env->xen_singleshot_timer_ns) { ret = do_set_singleshot_timer(cs, env->xen_singleshot_timer_ns, - false, false); + false); if (ret < 0) { return ret; }