Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2277878rdh; Tue, 26 Sep 2023 19:38:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOKpO/wPwRT+hYLFBuafrI7cgZxDE3Wq7FUUL1x96HffW+LNmSYocWK5MgxVc54kcXYjdc X-Received: by 2002:a05:6a20:4403:b0:15d:e68d:a855 with SMTP id ce3-20020a056a20440300b0015de68da855mr779487pzb.29.1695782300239; Tue, 26 Sep 2023 19:38:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695782300; cv=none; d=google.com; s=arc-20160816; b=ooMo9IYB+3jpHm1yTPe0R19gATgkf2PLb4sGkE4bcw8OTz2M6xGN9febzr0Pw4GvpU k+etre5C2lA5OPOYZ/81aNxkjlLud2UpiLXXCsayAqORzh33J+MlClgITQ9pcfH2nLV+ GbBcdK3rPbudkYfxndAHU/iPdeICeR7WIVIpQdUeXG4I95IUlJgSCD+rqkh5A9L7wNxs jgbuIvJKpx0QZxy5C8JibJ/g3dGf+rDPcSFgx0m5jM5q2tIdhV/4lPnDYi4RybfwNnrl WriLtPhAmvmVWe+i1UKY9z2Xd2JencrvBvd7MxkLyLQWdUFaR9SddiJyTNU8QHdJnzGI VslQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:references:mime-version:in-reply-to:date:dkim-signature; bh=m/X8tLTjtjB3zMNV0glwuPqbMP/KUOmrfpl18E6ncEQ=; fh=bxJWalZRVmzfqWyRLe6GnE+HwcvANyCGr1Mx4GBW9ZI=; b=Ju14nE6LIV/PkeUj/EXC7ZJ//V6x36skMaLbwT+Z/JtHHHzvP/U6JRzQ1AWugdemej t9yL7bUmNvm5dTvczpF6CEhsTEnuMb21uoCWAeA5ZHmmxdgSVI5RdAgHTwYaRF+oUJiP mF5Nmu4f5/ljOZ8IGDZx9yXkKQ7xATedGkRLHQ1gLxRuFdFwX17dqXNIaZEIe2o26PDL gnMOTv9TQ8izmWbNLNOUwTbHNnS44G1uOhS8hvZvnz940AyXscniRfhtus7m3FiUE/fV PTGRUA/KepysilCn19V3FaCAcKSIcuF7sEyOSN6rQsz2GcHb1I9J8+h24nhWQ3aozFvV iUXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F9KVq8iG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id u12-20020a170902e80c00b001bb9e2c38ecsi14899961plg.264.2023.09.26.19.38.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 19:38:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=F9KVq8iG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7CF39809ABFA; Tue, 26 Sep 2023 13:29:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235843AbjIZU3u (ORCPT + 99 others); Tue, 26 Sep 2023 16:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235537AbjIZU3q (ORCPT ); Tue, 26 Sep 2023 16:29:46 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82E04126 for ; Tue, 26 Sep 2023 13:29:38 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id d9443c01a7336-1c6147ea811so56796945ad.2 for ; Tue, 26 Sep 2023 13:29:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695760178; x=1696364978; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=m/X8tLTjtjB3zMNV0glwuPqbMP/KUOmrfpl18E6ncEQ=; b=F9KVq8iGQKR4tIqAutdWYEHZuqPPxOlwuiIGCJwnznybeEEXquVi2/qBneTmX0PQk9 TfLdYuLY8y85Cp8uLJpdSkDYN41waPuDXo/swEquqhBCa2tH2LEsRtxkk8q0r0Ovg+yw 5npTnlb9OTNfmGLdZI+g6HVbCbmeDO4NxzaRcrTcFfTOgVraDENnNfawCY3qzTWW4OzX Q/kP51ZVDuqm22suS25XpKGDtOh4N8+/tXXphRrufj3PLnpYbdPO2XhcdLzNIMqHCI0Q OFcYskufvSA+JtPMmVHgedOB/FeRHNdZvj97zQED2NX2kgzcjpFfH4ii0561GKjUlxre y3+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695760178; x=1696364978; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=m/X8tLTjtjB3zMNV0glwuPqbMP/KUOmrfpl18E6ncEQ=; b=gNISF7gE9OnYOiBVDtZk5ax3cxCmJn/TcaFCmnFU9oxL+QFcwWPt6A5TuDC9GEL4x3 35dspzpPbVKmVx/C2qPZ6ZZCNCfxlDfSiHW6zTShp+rQN+zD007iTQYDllAj4d/1nRZZ iviAWBVo2K/vf0RmTxSF/joGIhdcCYN5X6NdKwPz/Q0Q3zdvh6LvnbvOcWiiOqk1ut0s XDLrc+tDEXo1h4UYLYA2yBfYaQyqNHHRBnBQh5NAcVBq6VJWkEU5JY2pPjbGM2fc1PRH fpTmbon/hK9q2ejmmOwQCnjsPb7RVkNOcH5DlTGYMI2W55WtTzgXeDMGhJ9ilz/Ju7FZ OBAw== X-Gm-Message-State: AOJu0YxQc36I7Gr0/o+XzGmIW4a/5N2ML9XOXWH9uXXa/QemVx4AJRUh OhCZTBFGkEo0Piiflt9TbhrVwbFBfNU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:e74f:b0:1bd:dcdf:6179 with SMTP id p15-20020a170902e74f00b001bddcdf6179mr104882plf.2.1695760177767; Tue, 26 Sep 2023 13:29:37 -0700 (PDT) Date: Tue, 26 Sep 2023 13:29:36 -0700 In-Reply-To: <21C2A5D8-66D9-4EF0-A416-4B1049C91E83@infradead.org> Mime-Version: 1.0 References: <1b52b557beb6606007f7ec5672eab0adf1606a34.camel@infradead.org> <3dc66987-49c7-abda-eb70-1898181ef3fe@redhat.com> <21C2A5D8-66D9-4EF0-A416-4B1049C91E83@infradead.org> Message-ID: Subject: Re: [RFC] KVM: x86: Allow userspace exit on HLT and MWAIT, else yield on MWAIT From: Sean Christopherson To: David Woodhouse Cc: Paolo Bonzini , Alexander Graf , kvm@vger.kernel.org, Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Nicolas Saenz Julienne , Fred Griffoul Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 13:29:50 -0700 (PDT) On Tue, Sep 26, 2023, David Woodhouse wrote: >=20 >=20 > On 26 September 2023 19:20:24 CEST, Paolo Bonzini w= rote: > >On Sat, Sep 23, 2023 at 6:44=E2=80=AFPM Alexander Graf = wrote: > >> On 23.09.23 11:24, Paolo Bonzini wrote: > >> > Why do you need it? You can just use KVM_RUN to go to sleep, and if= you > >> > get another job you kick out the vCPU with pthread_kill. (I also di= dn't > >> > get the VSM reference). > >> > >> With the original VSM patches, we used to make a vCPU aware of the fac= t > >> that it can morph into one of many VTLs. That approach turned out to b= e > >> insanely intrusive and fragile and so we're currently reimplementing > >> everything as VTLs as vCPUs. That allows us to move the majority of VS= M > >> functionality to user space. Everything we've seen so far looks as if > >> there is no real performance loss with that approach. > > > >Yes, that was also what I remember, sharing the FPU somehow while > >having separate vCPU file descriptors. > > > >> One small problem with that is that now user space is responsible for > >> switching between VTLs: It determines which VTL is currently running a= nd > >> leaves all others (read: all other vCPUs) as stopped. That means if yo= u > >> are running happily in KVM_RUN in VTL0 and VTL1 gets an interrupt, use= r > >> space needs to stop VTL0 and unpause VTL1 until it triggers VTL_RETURN > >> at which point VTL1 stops execution and VTL0 runs again. > > > >That's with IPIs in VTL1, right? I understand now. My idea was, since > >we need a link from VTL1 to VTL0 for the FPU, to use the same link to > >trigger a vmexit to userspace if source VTL > destination VTL. I am > >not sure how you would handle the case where the destination vCPU is > >not running; probably by detecting the IPI when VTL0 restarts on the > >destination vCPU? > > > >In any case, making vCPUs poll()-able is sensible. >=20 > Thinking about this a bit more, even for HLT it probably isn't just as si= mple > as checking for mp_state changes. If there's a REQ_EVENT outstanding for > something like a timer delivery, that won't get handled and the IRQ actua= lly > delivered to the local APIC until the vCPU is actually *run*, will it? I haven't been following this conversation, just reacting to seeing "HLT" a= nd "mp_state", which is a bit of a mess: https://lore.kernel.org/all/ZMgIQ5m1jMSAogT4@google.com