Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp11187817rwd; Thu, 22 Jun 2023 09:47:39 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6BVVXPFoJDCr/VSCv9/jUVAYIUpKYPaDRLJvscaJCdMVlVM0fSTpdvSRwpHDvwUVKU6/8E X-Received: by 2002:a05:6359:67a0:b0:132:962d:b5d1 with SMTP id sq32-20020a05635967a000b00132962db5d1mr3493767rwb.22.1687452459148; Thu, 22 Jun 2023 09:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687452459; cv=none; d=google.com; s=arc-20160816; b=KoNCNFZnqF4JuXOKYoGQZlox8Go4pmcSQOlXT0oQZMO1X/RFHauZunyaNLwqIbiJuh ++3fQmIvj7I5jksysz6CWdPkBO/XoHUBxCMRyzLsR4q/qws1M4Yls4/Fltwa+zlIJ+ro yiJU3kOFT5vb5Nr9rtsUv5zUPLZd6RZIqdTkUIpUZCilBoHW9gqreU8lA1C3NJ5nnWoS AZa5YeIpHtMMbdXuuJnsrwdV6TrP84q6VloyFCsbYHQHsNGCYxOBmRLpZPHOikSoa8UO Mu34if/HUBdYSZ2qT3A7g8A2MU8kqRhOrI4DLuTqSnK/EA5VT6fbFIncPPOXjexhnwk3 XWsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:cc:to:from:date:references:in-reply-to :message-id:mime-version:user-agent:feedback-id:dkim-signature; bh=MsXq8lFn5P2SEys2TymR4KVd3g06U0kEfxBrPKA2tns=; b=ho80FiFSVj4GUi3dn3Ts/wrHoO6L5ZHINCvOBoy3kdig/UFp1OIoOx0Hxi4izcdug7 rn6FVhnSnYrkIYwFfTLQESSBrGlbtYqJM9yvEXw8g9l8yUK69coOOMGZN1GbjPF5ixXA 1DUHmAQlQ+quiAoyjf6wgQrnI/LUZIDBn5ER5RayGu6vRIXkR6nmJ2+kDBwwApDSgaWs 02m9faSX+AycVNsCGS5KPjDwDhLVNca+P8d3vkhSThP6IvjBkblX0XGla260jLTc99W+ hiXUIqoV7b9mCxLWgxJGgfcQgADoVFrsXIZfXUeXF5jvk+MUrbYsJBaaOeNPpkZqt+Wh vNsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CBD26+tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k63-20020a633d42000000b00553d7157e83si844790pga.134.2023.06.22.09.47.24; Thu, 22 Jun 2023 09:47:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CBD26+tl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbjFVQkK (ORCPT + 99 others); Thu, 22 Jun 2023 12:40:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbjFVQkI (ORCPT ); Thu, 22 Jun 2023 12:40:08 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A28C41FCB for ; Thu, 22 Jun 2023 09:40:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2656E61857 for ; Thu, 22 Jun 2023 16:40:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D64CC433C8; Thu, 22 Jun 2023 16:40:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687452006; bh=jN4aPtLwfFDashrtaZYc4JG/gemsFBwistd11UaUU2g=; h=In-Reply-To:References:Date:From:To:Cc:Subject:From; b=CBD26+tlkCJobJd6pFepFdSvV3kafkq2dt8jF/YC9bIxw7VtpfmVt2Dql7+aUsgHG Ewl/7tpVFUyGVRy6/b+BtQo/hWGzof58E72vWk59tC8D5CKcwOB5FmGhNbUbvkATEl fEgeR95A88oWJM2ckCT2Jj8VaG9n6lD6Si6hFBWFfygg+vlTRVr+wf4BcNrFrExAkk 5DUptH/AWnzc9vNMIaUaEcgTvv+88w81ii+KanxgVS2W10b2KKfAKdOqJM4oYmuXxR HnN3biYWbx7EOv9MURqTuOpSLQklvL4xNSawiTsmdLlXoGxAMbe7KAcu8JRwd5LPb1 vppLRc9fDnNKA== Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailauth.nyi.internal (Postfix) with ESMTP id EB8B527C0054; Thu, 22 Jun 2023 12:40:04 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute3.internal (MEProxy); Thu, 22 Jun 2023 12:40:04 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrgeeguddguddtvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefofgggkfgjfhffhffvvefutgesthdtredtreertdenucfhrhhomhepfdet nhguhicunfhuthhomhhirhhskhhifdcuoehluhhtoheskhgvrhhnvghlrdhorhhgqeenuc ggtffrrghtthgvrhhnpedvhfeuvddthfdufffhkeekffetgffhledtleegffetheeugeej ffduhefgteeihfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegrnhguhidomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudduiedu keehieefvddqvdeifeduieeitdekqdhluhhtoheppehkvghrnhgvlhdrohhrgheslhhinh hugidrlhhuthhordhush X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 7294531A0063; Thu, 22 Jun 2023 12:40:03 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.9.0-alpha0-499-gf27bbf33e2-fm-20230619.001-gf27bbf33 Mime-Version: 1.0 Message-Id: <8a5b8e4a-d238-4f35-b4c7-fb9e34650a14@app.fastmail.com> In-Reply-To: <4d29bfe0-975a-c97f-3e79-5b77d95d3494@suse.com> References: <20230621151442.2152425-1-per.bilse@citrix.com> <20230621164038.GM2053369@hirez.programming.kicks-ass.net> <6523f3e2-8dfc-c2dd-6d14-9e0c3ac93cc8@citrix.com> <20230621200409.GC4253@hirez.programming.kicks-ass.net> <20230622082607.GD4253@hirez.programming.kicks-ass.net> <4d29bfe0-975a-c97f-3e79-5b77d95d3494@suse.com> Date: Thu, 22 Jun 2023 09:39:43 -0700 From: "Andy Lutomirski" To: "Juergen Gross" , "Peter Zijlstra (Intel)" Cc: "Per Bilse" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , "the arch/x86 maintainers" , "H. Peter Anvin" , "Stefano Stabellini" , "Oleksandr Tyshchenko" , "Linux Kernel Mailing List" , "moderated list:XEN HYPERVISOR INTERFACE" Subject: Re: [PATCH] Updates to Xen hypercall preemption Content-Type: text/plain X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 22, 2023, at 3:33 AM, Juergen Gross wrote: > On 22.06.23 10:26, Peter Zijlstra wrote: >> On Thu, Jun 22, 2023 at 07:22:53AM +0200, Juergen Gross wrote: >> >>> The hypercalls we are talking of are synchronous ones. They are running >>> in the context of the vcpu doing the call (like a syscall from userland is >>> running in the process context). >> >> (so time actually passes from the guest's pov?) > > Correct. > >> >>> The hypervisor will return to guest context from time to time by modifying >>> the registers such that the guest will do the hypercall again with different >>> input values for the hypervisor, resulting in a proper continuation of the >>> hypercall processing. >> >> Eeeuw.. that's pretty terrible. And changing this isn't in the cards, >> like at all? > > In the long run this should be possible, but not for already existing Xen > versions. > >> >> That is, why isn't this whole thing written like: >> >> for (;;) { >> ret = hypercall(foo); >> if (ret == -EAGAIN) { >> cond_resched(); >> continue; >> } >> break; >> } > > The hypervisor doesn't return -EAGAIN for hysterical reasons. > > This would be one of the options to change the interface. OTOH there are cases > where already existing hypercalls need to be modified in the hypervisor to do > preemption in the middle due to e.g. security reasons (avoiding cpu hogging in > special cases). > > Additionally some of the hypercalls being subject to preemption are allowed in > unprivileged guests, too. Those are mostly hypercalls allowed for PV guests > only, but some are usable by all guests. > >> >>> It is an awful interface and I agree that switching to full preemption in >>> dom0 seems to be the route which we should try to take. >> >> Well, I would very strongly suggest the route to take is to scrap the >> whole thing and invest in doing something saner so we don't have to jump >> through hoops like this. >> >> This is quite possibly the worst possible interface for this Xen could >> have come up with -- awards material for sure. > > Yes. > >> >>> The downside would be that some workloads might see worse performance >>> due to backend I/O handling might get preempted. >> >> Is that an actual concern? Mark this a legaxy inteface and anybody who >> wants to get away from it updates. > > It isn't that easy. See above. > >> >>> Just thinking - can full preemption be enabled per process? >> >> Nope, that's a system wide thing. Preemption is something that's driven >> by the requirements of the tasks that preempt, not something by the >> tasks that get preempted. > > Depends. If a task in a non-preempt system could switch itself to be > preemptable, we could do so around hypercalls without compromising the > general preemption setting. Disabling preemption in a preemptable system > should continue to be possible for short code paths only, of course. > >> Andy's idea of having that thing intercepted as an exception (EXTABLE >> like) and relocating the IP to a place that does cond_resched() before >> going back is an option.. gross, but possibly better, dunno. >> >> Quite the mess indeed :/ > > Yeah. Having one implementation of interrupt handlers that schedule when they interrupt kernel code (the normal full preempt path) is one thing. Having two of them (full preempt and super-special-Xen) is IMO quite a bit worse. Especially since no one tests the latter very well. Having a horrible Xen-specific extable-like thingy seems honestly rather less bad. It could even have a little self-contained test that runs at boot, I bet. But I'll bite on the performance impact issue. What, exactly, is wrong with full preemption? Full preemption has two sources of overhead, I think. One is a bit of bookkeeping. The other is the overhead inherent in actually rescheduling -- context switch cost, losing things from cache, etc. The bookkeeping part should have quite low overhead. The scheduling part sounds like it might just need some scheduler tuning if it's really a problem. In any case, for backend IO, full preemption sounds like it should be a win, not a loss. If I'm asking dom0 to do backend IO for me, I don't want it delayed because dom0 was busy doing something else boring. IO is faster when the latency between requesting it and actually submitting it to hardware is lower. Can anyone actually demonstrate full preemption being a loss on a real Xen PV workload? --Andy