Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp118879iob; Tue, 3 May 2022 12:58:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+d4jf1leE5Bnwy70n4ogA2d6p2raLszOiqjjgYvPE+kKfJ+SRejE5ihybDkZ3Qd7dxw11 X-Received: by 2002:a17:907:6ea3:b0:6f4:ac50:3346 with SMTP id sh35-20020a1709076ea300b006f4ac503346mr1765846ejc.457.1651607900910; Tue, 03 May 2022 12:58:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607900; cv=none; d=google.com; s=arc-20160816; b=h+myFsjxuFHqTQR9YP82EA6xZU6l8ijLmfcE0iOFAeUarltZYcIisnD73DG6ZfsO/O TlJPEzLyVedrqjp1Y7nThHvWQpQl5I9rBxNFNCom3qsqYIyogyXg1+evFHce2MfD0DmU RH8qd0AJ58gG/SdxA18Lnj4A8RxT9J8hii2UMpccUwjoAoTgebGheZVzhuRMOKFxM8JN XTfYV57h/39QJRRzsJwcvR+BAtzLgwCkSOsgw2R3Btqo+OhmkPE5mBQHOp4NayrZ7BRK uTnPs0S0fAKxu3+rwd7AaTmmf5y4YdQGn9ouYMcLNHMSnpEmP4/bLiOhm/zlsNxrLLYR B+ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=Q51Ia3tetkXHUbkcfKD8S+gdtewHxa7+IUzoOiuzmQM=; b=egGleO/utPm+1kC3p6WEhdxdQ7cvbGuxpnEkN6241l5u289Bef04NhKe0Ng7fWHv4n 1QNFciIJGQFFXrwtqtm0yrNjBvIvj7TPKOYCpi1YwJw2hPDskcbW/DfFvOSyxCpvUNG8 tl6w9ZEFAFzL8DIUn/0XQ51okqMQkbO1s0J0GtccHYLus6FT/CcpCZtocjPg2ypQN65N kWxAUNBszygvAkeM4TaL3pF8sfr4G2RE9dB0tKJcDm7v/L4fFZCY6dd8nRyy6t2iBgAv nMM9H0rZq1hmCSDe/XTJMvYt+YVIuznbPU6KrVrtdZcXL9KWVvXUKcXxbpcSPqjj/3Le g/rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@digitalocean.com header.s=google header.b=DXNemHdA; 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=REJECT sp=REJECT dis=NONE) header.from=digitalocean.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z6-20020a170906270600b006f3c5c57309si14541670ejc.389.2022.05.03.12.57.57; Tue, 03 May 2022 12:58:20 -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=@digitalocean.com header.s=google header.b=DXNemHdA; 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=REJECT sp=REJECT dis=NONE) header.from=digitalocean.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239174AbiECQVj (ORCPT + 99 others); Tue, 3 May 2022 12:21:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239196AbiECQVh (ORCPT ); Tue, 3 May 2022 12:21:37 -0400 Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B29752F3AF for ; Tue, 3 May 2022 09:18:04 -0700 (PDT) Received: by mail-oi1-x232.google.com with SMTP id a10so18645688oif.9 for ; Tue, 03 May 2022 09:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digitalocean.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=Q51Ia3tetkXHUbkcfKD8S+gdtewHxa7+IUzoOiuzmQM=; b=DXNemHdAsSJnzRfAFmFJDu7rxBi3j2CgdmhDiTTYFUQVZd81cb6Uc+goqkxzhoaGaE rc1WCcIRmRkCpMkO0bJFB3uqZkeysudG4ESGLjj/ionJPTbCH6O/8VdViXZbrD2f4QEs 3SJHX2OkoKRviER0B91sBk/C0juHWnWJQLLHU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Q51Ia3tetkXHUbkcfKD8S+gdtewHxa7+IUzoOiuzmQM=; b=vSoprdLYWHUkA+URUmUy7/nIaWEReZIPFWjsB1g/eu/eWnpkTUypBLzPIrsb/WhyTz vnmO7DWH5uGtWB7Mvs84mPP5nUcP7Yp08geOnRMSSG00EBaLFyPk/kYvjY7wnMB6Qc3A amjzx9KdN7EdiYAoOKXsW67UQMRWHL4gAjQIIlWYVFb93rfFEuntBxogu1FxdQbBHatM ZMsE0sPN7tCIkpbn4kS5OGWE/GsIHQB8wksIC/YI1FCPjlIbgnC3O4E/QciCxkJkjFdH MtEmjnkFvNWOFavBWyNF+1tFebzw2LcRf2fD5gABu30+ClOO8CtEOK3E6w/ysX/vDNE/ nOcA== X-Gm-Message-State: AOAM530loEwqlBoZGWzaXNBi1ZxJsgR60VtaYdVfEtPP9dBxIgzfEzGX punen2SR8Jb3JZzaeLP7vAxh0w== X-Received: by 2002:a05:6808:1202:b0:322:dc37:2c3b with SMTP id a2-20020a056808120200b00322dc372c3bmr2217794oil.298.1651594683941; Tue, 03 May 2022 09:18:03 -0700 (PDT) Received: from localhost ([2605:a601:ac0f:820:80d8:f53c:c84d:deaa]) by smtp.gmail.com with ESMTPSA id 8-20020a056870124800b000e686d13888sm7369543oao.34.2022.05.03.09.18.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 09:18:03 -0700 (PDT) Date: Tue, 3 May 2022 11:18:02 -0500 From: Seth Forshee To: Sean Christopherson Cc: Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Paolo Bonzini , linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] entry/kvm: Make vCPU tasks exit to userspace when a livepatch is pending Message-ID: References: <20220503125729.2556498-1-sforshee@digitalocean.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,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 Tue, May 03, 2022 at 02:17:53PM +0000, Sean Christopherson wrote: > On Tue, May 03, 2022, Seth Forshee wrote: > > A livepatch migration for a task can only happen when the task is > > sleeping or it exits to userspace. This may happen infrequently for a > > heavily loaded vCPU task, leading to livepatch transition failures. > > > > Fake signals will be sent to tasks which fail to migrate via stack > > checking. This will cause running vCPU tasks to exit guest mode, but > > since no signal is pending they return to guest execution without > > exiting to userspace. Fix this by treating a pending livepatch migration > > like a pending signal, exiting to userspace with EINTR. This allows the > > migration to complete, and userspace should re-excecute KVM_RUN to > > resume guest execution. > > > > In my testing, systems where livepatching would timeout after 60 seconds > > were able to load livepatches within a couple of seconds with this > > change. > > > > Signed-off-by: Seth Forshee > > --- > > kernel/entry/kvm.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > > diff --git a/kernel/entry/kvm.c b/kernel/entry/kvm.c > > index 9d09f489b60e..efe4b791c253 100644 > > --- a/kernel/entry/kvm.c > > +++ b/kernel/entry/kvm.c > > @@ -14,7 +14,12 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work) > > task_work_run(); > > } > > > > - if (ti_work & _TIF_SIGPENDING) { > > + /* > > + * When a livepatch migration is pending, force an exit to > > Can the changelog and comment use terminology other than migration? Maybe "transition"? > That seems to be prevelant through the livepatch code and docs. There are already > too many meanings for "migration" in KVM, e.g. live migration, page migration, task/vCPU > migration, etc... "Transition" is used a lot, but afaict it refers to the overall state of the livepatch. "Migrate" is used a lot less, but it always seems to refer to patching a single task, which is why I used that term. But I can see the opportunity for confusion, so I'll reword it. > > > + * userspace as though a signal is pending to allow the > > + * migration to complete. > > + */ > > + if (ti_work & (_TIF_SIGPENDING | _TIF_PATCH_PENDING)) { > > _TIF_PATCH_PENDING needs to be in XFER_TO_GUEST_MODE_WORK too, otherwise there's > no guarantee KVM will see the flag and invoke xfer_to_guest_mode_handle_work(). Yes, you are right. I was relying on the livepatch code setting _TIF_NOTIFY_SIGNAL for vCPU tasks which were running, but it would be better to have _TIF_PATCH_PENDING in XFER_TO_GUEST_MODE_WORK too. Thanks, Seth > > > kvm_handle_signal_exit(vcpu); > > return -EINTR; > > } > > -- > > 2.32.0 > >