Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp581271iog; Wed, 15 Jun 2022 08:07:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vBQLXHp4qZNCro4HJnU3kyNnmajX7TQQjauSGYvTB+/uXl/7JcLWwvmcQu0kadk7Q4wxku X-Received: by 2002:a05:6402:1449:b0:42d:d250:e504 with SMTP id d9-20020a056402144900b0042dd250e504mr187441edx.213.1655305666622; Wed, 15 Jun 2022 08:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655305666; cv=none; d=google.com; s=arc-20160816; b=zhnwjYeehPh5wb5iaDXKG/qmhbsqHSBhcAkA8MNte3nD+6rjs1Z9dCt4cY4Zfv3yBx m5MmwwGjF/KReTVzd5M/3pNBQGjfLRSq8sKipJeHdvmTBGf4SNh1MHbRMb6tIzqGu001 dNVmshxwJkwduDsVnm4XbGPFblQQpyYBxmsKExUdkwCXw+gTCWZYDU2aukiEDV38OC2N bzrg1mAT3WsMTDemqYQ2Iuye0RChKdQE8erb5kIsjP5tQ+hOSa1lARm12aZ7MsUx5+3R khixs1dtTXUf/ra2nWILiLpQOcRL1kPnLYejvDRcuiNRgOoo0jdqSO82Oohcoag4pwBa GacQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=aoMDtHtTQLo9Hcq1dT+XWeUHhZY2P5SZpdzuA1mTFwI=; b=kfyeA3vWEUr3js9SYAMqI8ZWHSJTQe+K4vRjav2t1lO9v9JbgYUypOqRXV/nmTyHep R5beHWVSXjd7RjAQ5CbLwobhFZtaKhlSzUhWY/hcYpKJYegpQv0oi+3iKRwivSHmDeHo UDNXyrFgfrOrJzjTPwXNYiDXS4c/g/V5BbelM5yQrc5ZrtXGVP5PQ0WgmLCSyD1i5FZz 17+TWF5CIwMHHj2v+Pe58ePpxta9xUicn2dqX5xZ/vSXKDdJFvo8F+ZRO3oq8OCxqUUB vwivMOyZrq7IsfY8zoWKrngJIU9QnoYGE6pgyS2kvQYUrzXbUDWE11ysk82kkcCI2Vsx qRBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mZaSSuMa; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b7-20020a056402278700b0042ddc352f85si16406408ede.107.2022.06.15.08.07.15; Wed, 15 Jun 2022 08:07:46 -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=@google.com header.s=20210112 header.b=mZaSSuMa; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345175AbiFOOyd (ORCPT + 99 others); Wed, 15 Jun 2022 10:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345953AbiFOOy1 (ORCPT ); Wed, 15 Jun 2022 10:54:27 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3C152FE66 for ; Wed, 15 Jun 2022 07:54:22 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id h23so19347904lfe.4 for ; Wed, 15 Jun 2022 07:54:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=aoMDtHtTQLo9Hcq1dT+XWeUHhZY2P5SZpdzuA1mTFwI=; b=mZaSSuMapl6ZdG640VcUpFw3YExNCMsY53STmUB0Q4FpEKMAjgqnBpLtkLKXRQtM8O Iazav9Ncviujq+pFGcNdcrTMbBwnfJoZB6QJ2kQNofoTtiNN4fOK6hQPI5tDnHcFiwwx 5VGQIdQMn6HSb2HaEiMFnO6nSB1UtLq1BALXqVewg/s9uxIkTbdFpXe3LwEwWVgc90Y9 cJ66J/SwV55xg//85NUUjFTFVM6Kwy8X/PGmH0T61WzGj2AhkP2RBbYwXl3ETZCX2O/e DgIt3x6vHILIok+ouydxTujxJORpRehqWxvB7t94SBYrxkXNfaskOQGbY/zfEw3piXe4 CPBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=aoMDtHtTQLo9Hcq1dT+XWeUHhZY2P5SZpdzuA1mTFwI=; b=XDbK9//KHFPiGPAiMnyL1vCwkUWirebsNTNUDbF1fYBXxnZp1Xh/Q6Nx7lJxmWIYUt hiOsfFSqgFKz3yUadC8SiRY76cW38LbdDWWc1r3twUvdhWFGhPKzScton3FHvC3crWXc 6QHwwWaA4+LABZkC/csjWDg5VGDSIGOkueU5ebEV9ZfxicePYaMGzW2VDC9y8SCXfF2B MnCZer1hIixMROQhhVePmT5IGEWOpD00ld9mT67BB4Lq5s7fQcC9GC2SIhRRT1n+ZAIt PfVhLjH5lon9sXqOXi2ocTu5cMDSWYe9bYzMUBFZshHNjaPU/NQNmGEbPXhVdoYAxyOM lvLw== X-Gm-Message-State: AJIora/WDLQ24TBPPdv1Lef7iGGHYiLQZAGuHx/P9UrD+KPYndpQTNQU 9Rn5Z+ZuszUym47ISx1ymLCD6bByZCJSgByvxv49Cw== X-Received: by 2002:a19:5059:0:b0:479:4739:3768 with SMTP id z25-20020a195059000000b0047947393768mr6468219lfj.315.1655304860454; Wed, 15 Jun 2022 07:54:20 -0700 (PDT) MIME-Version: 1.0 References: <20220614021141.1101486-1-sashal@kernel.org> In-Reply-To: <20220614021141.1101486-1-sashal@kernel.org> From: Jann Horn Date: Wed, 15 Jun 2022 16:53:44 +0200 Message-ID: Subject: Re: [PATCH MANUALSEL 5.15 1/4] KVM: x86: do not report a vCPU as preempted outside instruction boundaries To: Sasha Levin , Paolo Bonzini Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, kvm@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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, Jun 14, 2022 at 4:11 AM Sasha Levin wrote: > > From: Paolo Bonzini > > [ Upstream commit 6cd88243c7e03845a450795e134b488fc2afb736 ] > > If a vCPU is outside guest mode and is scheduled out, it might be in the > process of making a memory access. A problem occurs if another vCPU uses > the PV TLB flush feature during the period when the vCPU is scheduled > out, and a virtual address has already been translated but has not yet > been accessed, because this is equivalent to using a stale TLB entry. > > To avoid this, only report a vCPU as preempted if sure that the guest > is at an instruction boundary. A rescheduling request will be delivered > to the host physical CPU as an external interrupt, so for simplicity > consider any vmexit *not* instruction boundary except for external > interrupts. > > It would in principle be okay to report the vCPU as preempted also > if it is sleeping in kvm_vcpu_block(): a TLB flush IPI will incur the > vmentry/vmexit overhead unnecessarily, and optimistic spinning is > also unlikely to succeed. However, leave it for later because right > now kvm_vcpu_check_block() is doing memory accesses. Even > though the TLB flush issue only applies to virtual memory address, > it's very much preferrable to be conservative. > > Reported-by: Jann Horn > Signed-off-by: Paolo Bonzini > Signed-off-by: Sasha Levin This feature was introduced in commit f38a7b75267f1f (first in 4.16). I think the fix has to be applied all the way back to there (so additionally to what you already did, it'd have to be added to 4.19, 5.4 and 5.10)? But it doesn't seem to apply cleanly to those older branches. Paolo, are you going to send stable backports of this?