From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f201.google.com (mail-pg1-f201.google.com [209.85.215.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFB5C1DEFD7 for ; Wed, 6 Nov 2024 13:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730901263; cv=none; b=qkvYTVZuNDy+6wbcs4UKe00ZsACeHtzbkni1j7VSvqMJrdW0qlCB+HIjMPBeyXNQi+5Tyi6jcNkzJCQZZQzIXX1KKu5rR8BxHugvsGYWHokJ5+muXZL0Ck0G5nPf6+Ss7w6C/sd0jiEk37PRiPxvQYRr//wrbR6OrP3ZWHUoaU0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730901263; c=relaxed/simple; bh=JQBIHPmPJN2CvTRqnCyvMz01lP1GgryuaD6L7iVuScA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=TnZT9eODYmQRnx3GYn52rr0g5PMKr8joOh6QS0fqcvfB8GfF9vpe8nXghJmporrFNXx9NnOwlxMQy6rspbJQmcKqdUeUcQ45BNaR95wb1gnMfND/r2m+oWVVZxXDWxaad1x5DAoLKxgbDHTvRlvxtLz4t/OrS3lTikl6Rnq6wvI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=krTkBLMu; arc=none smtp.client-ip=209.85.215.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="krTkBLMu" Received: by mail-pg1-f201.google.com with SMTP id 41be03b00d2f7-7ed98536f95so734108a12.1 for ; Wed, 06 Nov 2024 05:54:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730901261; x=1731506061; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=J8Jp5664XXxvLT8kd1+cxeFbBOkGmXp2vl44rKC+LTM=; b=krTkBLMu5VD+mVajdNcTuK4by72bU2AaW6UXCjcZ+ZNAVHMakpSzasd6hYTkCVhUYo zumbBsZsddSehEOj3kY07orJt7r6UlK9gsadiKU/Rq4TZig0vWD2tR2NwK++i+dyWq8Z rU6cHZs0v2/DU8dMhmjUG+6pXqFgSKYW/DO3qN//dJ0taLI9hZE9HAGpIp0HAb1+Lwal Jne7CCqKKclzG+D6UVcnTjwZ1kk++rfTA/M4TWWhNM/YJPWuWt6V2rZw9l5VUU7XpEfS RSirZCVLWKLmmxbo3+ihC5VnzVL/2lzKI2C1QSUQX6EKvCp6rMR2qvkoqakD4j7kG97u IT/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730901261; x=1731506061; h=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=J8Jp5664XXxvLT8kd1+cxeFbBOkGmXp2vl44rKC+LTM=; b=tXrqCjeyF91FsWubqO4zTWxZQYh64PLUyHJ8H9vTK+tvHnbBO6c+4oDIIkN6oTNV7Q Zbc1pcKb9e8X5i2pMN5zSfkMr+HG5UoXd/6nf292AP3nmCy6GBsk6C5aCW+3rvhCnF3F +kJL8zNhyAnE1nY3i6YnnbX9+2g64a2cRRqtFCYxI75Sn+Ra1HvOD68ATkIIMVEyqosj 3LbaQBOkdA4KsFxDpAbLWMhJ4BHoMzoi7xAx9LcqU21uFzHwfR5RorIaoOLhhv8hFtH+ 5o1zRPuSHc+g1Z4q+lxrFAlhuwBrdetBZC4HOg7O2XgdKInGlpilY0a2B63LSLla6lDm hWew== X-Forwarded-Encrypted: i=1; AJvYcCXOifgVplFQR/QdkvNkIJMtWV7Uyf0eiHzkERTdNHDffli3qxmpv34gLW29qiCoTMYCcoWK6i9q1hrkbxM=@vger.kernel.org X-Gm-Message-State: AOJu0YzlfwMJ2SkB/ZlG4ANhn4ErlNqfmhsOx5onfk8j2zWoWSfTVdel xsOaFP0ayAOAY+NzByfOy9ZrnRhxBwpiCggzd53VX+8hwO9nkJOMlaN8zhgOxRIDH5duq8sfeqK 4XA== X-Google-Smtp-Source: AGHT+IG0dd6L1RqL0LIJscy8aKUpn6cXn5VoRBJhMyp2MBFEuW/dbIVRXe82qw1RNKHqa1lWIksmKSUAFHo= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a63:1641:0:b0:7ea:8c4c:d07c with SMTP id 41be03b00d2f7-7f40585a9cbmr26890a12.3.1730901260830; Wed, 06 Nov 2024 05:54:20 -0800 (PST) Date: Wed, 6 Nov 2024 05:54:19 -0800 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101193532.1817004-1-seanjc@google.com> Message-ID: Subject: Re: [PATCH] KVM: x86: Update irr_pending when setting APIC state with APICv disabled From: Sean Christopherson To: Chao Gao Cc: Paolo Bonzini , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yong He , Maxim Levitsky Content-Type: text/plain; charset="us-ascii" On Wed, Nov 06, 2024, Chao Gao wrote: > >Furthermore, in addition to introducing this issue, commit 755c2bf87860 also > >papered over the underlying bug: KVM doesn't ensure CPUs and devices see APICv > >as disabled prior to searching the IRR. Waiting until KVM emulates EOI to update > >irr_pending works because KVM won't emulate EOI until after refresh_apicv_exec_ctrl(), > >and because there are plenty of memory barries in between, but leaving irr_pending > >set is basically hacking around bad ordering, which I _think_ can be fixed by: > > > >diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > >index 83fe0a78146f..85d330b56c7e 100644 > >--- a/arch/x86/kvm/x86.c > >+++ b/arch/x86/kvm/x86.c > >@@ -10548,8 +10548,8 @@ void __kvm_vcpu_update_apicv(struct kvm_vcpu *vcpu) > > goto out; > > > > apic->apicv_active = activate; > >- kvm_apic_update_apicv(vcpu); > > kvm_x86_call(refresh_apicv_exec_ctrl)(vcpu); > >+ kvm_apic_update_apicv(vcpu); > > I may miss something important. how does this change ensure CPUs and devices see > APICv as disabled (thus won't manipulate the vCPU's IRR)? Other CPUs when > performing IPI virtualization just looks up the PID_table while IOMMU looks up > the IRTE table. ->refresh_apicv_exec_ctrl() doesn't change any of them. For Intel, which is a bug (one of many in this area). AMD does update both. The failure Maxim was addressing was on AMD (AVIC), which has many more scenarios where it needs to be inhibited/disabled.