Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1465251lqm; Thu, 2 May 2024 16:21:57 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUEnQG+DirK4cfW6VfYWJRLl1gB9zPHFATLhZf/GJ8pJhLRDGhUWZxayzVac5BShEqtEpjgEUkT2X0WiVp+nhy69fLq4oe6PEfGzj3dBg== X-Google-Smtp-Source: AGHT+IEABG0cIFEPy4UCtWsR+xl9b3e4DJFTgmFKAaIwMboF5SPVpBz+ywEdJmSlVRD+0dTVTwXV X-Received: by 2002:a17:90a:634b:b0:2a2:71c7:7e26 with SMTP id v11-20020a17090a634b00b002a271c77e26mr1132120pjs.28.1714692117611; Thu, 02 May 2024 16:21:57 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714692117; cv=pass; d=google.com; s=arc-20160816; b=dJHq1zEZCivYQmmL+jHp6XiPNmBJlKnLM5ujZSlz7kow5B5BNFMbNuO94qxU1P1/AA aUMhJnm5oxKWv9YeLs9oXjiKKYsPL3lBIMRkd0H9tZMgAvq9M+9wQw/c2N+tafJ5/t97 NHZsFAIxqJg5tc3sjCODfatgbP5GZccftNaTZqynMrjQ4tjMox/4P8qkl5hp46dUruYn 1ugYgwhIN0lUXkQi+vIbuWQwfc13EZcPZWypkOo7HeKD+ibPf0XP6oIknDy5rdkY9B5f DKEYJyyGVRkvQR7UOWhu97Ni3MfDnAz3Vnt9/05onn2msgHWBRtCg8giPjMCDGo049hG nvAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=s0bl+EXjP+FAcnnealSKe+UO8h20s3Bb2rwaSYi0ocI=; fh=3uQAs7aa2TjxO0IfLZsQg50iYb0QYW2gGXTVGfos9DU=; b=fSVQ5EaAOaOxZwunFgDpBXaE7qgTkZNxqmh37Xz8pW+FVujlOH39mX/QmBPMfiu+ro dC3I4DPVkbbN8wwQmpUtsG2QuFehb2JxsQrYQVAW52PE5zaYZI6FLGrUSucMRp5kYIpI dASW4tdHMYiPM6oGD5oh1mex5ilgJ1mgEptOH97NgkovF2d5+fvNThmCkbAd7jshRcxc pIqb9c3g0V0OvKu48gF5WZO3hfyCpvI0LXEnD5qfmpVzr1E0jjSGg5FBKNgl2zdXoHLr S5EqF5LuBP9PkD0nKC3KNHmDYW/qYQjfDlXPr+VVwK30JWlV0fNk71zytwGQdCxt8JpI Kt0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=EMJVd0MR; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-167053-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167053-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q6-20020a17090a304600b002a79ba0f002si1838587pjl.189.2024.05.02.16.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 16:21:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167053-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=EMJVd0MR; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-167053-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167053-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3B791285282 for ; Thu, 2 May 2024 23:21:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2754141C87; Thu, 2 May 2024 23:21:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="EMJVd0MR" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 1CB821CD0C for ; Thu, 2 May 2024 23:21:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692104; cv=none; b=XqKaT9U4nW96KCzTxlJAnKkohIwBJwwS1TUJr6IENtDwjdOa2aGKIGSWdG06qvN8sfSYAyfuTu8ToSa3WwOplQEtBoEhx1AlS2AAlAqaO9CNdlX14yYXVY2DYecD0Yqk0utotBbBrUII495QCLagotKtrqGE1x+JmrBFlId4hJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714692104; c=relaxed/simple; bh=t0ocJHvY73hrUFCV06uFlb3wGHL2RVlZU9n1KTZ7hPY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=jgMmtPzl816wY9wj3Lw1Rt5gCP0g8BS7I/dkmrU3/KmB3UlUPL19Xl4L/FLn1xNSh6gkBFECaMMBPsTKFwonhay7j07MHNNbHRfJzWmGrzH/yUiQ0nMq4BrR97ujrNM8ruwAOBtQDRinapZkU5aumOO0SSkszBX1j3wPk9J1u+o= 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=EMJVd0MR; arc=none smtp.client-ip=209.85.219.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 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-de603db5d6aso8337492276.2 for ; Thu, 02 May 2024 16:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714692101; x=1715296901; 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=s0bl+EXjP+FAcnnealSKe+UO8h20s3Bb2rwaSYi0ocI=; b=EMJVd0MRiJqm3UnPJGEkLl6LrggKvvFrfdAGX8rmY3ImBqu474OjktOA/hjEjlrmCX fmrBXGeIY2skkftEbxpfawAbf/qosKiXfyPX647e79Rokt/VDVig5oMnYAtx0DIBbmiq MAYNy63TJwTdOY/scvKX/Bdvb1imxiSiSVESqh18pD0oH2u8yVUjjFTHA+FXRO3dW7Et vjGPn4NKb3kblBfRW+R80b6viy+KWjyQ6GeRa/tgxL5WATN0l7C+m+BHHS4XHonnPKDX LnFxrp9LNrzPsERkfVyIvpbL0v4qGpL5O7qsjGnu++R9octd9DZ/21MQUrdEsmveCjMs s9yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714692101; x=1715296901; 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=s0bl+EXjP+FAcnnealSKe+UO8h20s3Bb2rwaSYi0ocI=; b=cXAn9MIDGuq/Yg0i7M7KZUAg1phcOOOlGh782LNkDtfSKlVrlVGZvoWUb5MvSuiKrB fsYLmgpENNFE8Ef6QO4CQW+J8+sL16Dtwv+1YY+HLVYi5GYQO6BaYumOm5dbKKn8Ouv6 XfDo4itRFdALORhl5DZcUJ7ilQZOPC1mW1EYV4mU96rPltv2RomlStgNjwdGcersFuHs uNN6ao0dFv3qXQ5G3V2KC2ZihQyXAiVedVrJV3KWn8AC0y41tXi/R2jK/rd+Hpei4LS1 Fys21x/tot7JU+jsC9WK7Op5RHnCXyFFHHyNJleqixuekM2qLeLPWJfiewnNTr/5yWV1 oB+w== X-Forwarded-Encrypted: i=1; AJvYcCXkPMdjlGUVz5GeOJIDmMazKoPvUc8AQITy5oNy1rfrNaY9LrAmTY/lJm3efL8g3mxXY13Cw6SZwwKcJQt92R+HvSa0AGiZkm0TRwbS X-Gm-Message-State: AOJu0YxxiBX1HZ0bkrVhDX8BPmq6CEuFivbH/G9pmSU7O0iCboRl0clh yXV9dCbfIUcVgPccxtveaOkTAmNn5cUf4SGqV0r9fOJCf1nEyAoEnklofz2vjO8E/VebVkosXcu 2aw== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:2b83:b0:dd1:390a:51e8 with SMTP id fj3-20020a0569022b8300b00dd1390a51e8mr368460ybb.10.1714692101128; Thu, 02 May 2024 16:21:41 -0700 (PDT) Date: Thu, 2 May 2024 16:21:39 -0700 In-Reply-To: <20240418021823.1275276-2-alejandro.j.jimenez@oracle.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240418021823.1275276-1-alejandro.j.jimenez@oracle.com> <20240418021823.1275276-2-alejandro.j.jimenez@oracle.com> Message-ID: Subject: Re: [PATCH v2 1/2] KVM: x86: Only set APICV_INHIBIT_REASON_ABSENT if APICv is enabled From: Sean Christopherson To: Alejandro Jimenez Cc: kvm@vger.kernel.org, pbonzini@redhat.com, linux-kernel@vger.kernel.org, joao.m.martins@oracle.com, boris.ostrovsky@oracle.com, suravee.suthikulpanit@amd.com, mlevitsk@redhat.com Content-Type: text/plain; charset="us-ascii" On Thu, Apr 18, 2024, Alejandro Jimenez wrote: > Use the APICv enablement status to determine if APICV_INHIBIT_REASON_ABSENT > needs to be set, instead of unconditionally setting the reason during > initialization. > > Specifically, in cases where AVIC is disabled via module parameter or lack > of hardware support, unconditionally setting an inhibit reason due to the > absence of an in-kernel local APIC can lead to a scenario where the reason > incorrectly remains set after a local APIC has been created by either > KVM_CREATE_IRQCHIP or the enabling of KVM_CAP_IRQCHIP_SPLIT. This is > because the helpers in charge of removing the inhibit return early if > enable_apicv is not true, and therefore the bit remains set. > > This leads to confusion as to the cause why APICv is not active, since an > incorrect reason will be reported by tracepoints and/or a debugging tool > that examines the currently set inhibit reasons. > > Fixes: ef8b4b720368 ("KVM: ensure APICv is considered inactive if there is no APIC") > Co-developed-by: Sean Christopherson Heh, no need, I just provided review feedback. > Signed-off-by: Alejandro Jimenez > --- > arch/x86/kvm/x86.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 26288ca05364..09052ff5a9a0 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -9995,15 +9995,14 @@ static void set_or_clear_apicv_inhibit(unsigned long *inhibits, > > static void kvm_apicv_init(struct kvm *kvm) > { > - unsigned long *inhibits = &kvm->arch.apicv_inhibit_reasons; > + enum kvm_apicv_inhibit reason = enable_apicv ? > + APICV_INHIBIT_REASON_ABSENT : > + APICV_INHIBIT_REASON_DISABLE; Just let this poke out, the 80 char limit is a soft limit, where "soft" is fairly "hard" in KVM", but there are still legitimate situations where running past 80 is yields more readable code, and IMO this is one of them. > - init_rwsem(&kvm->arch.apicv_update_lock); > - > - set_or_clear_apicv_inhibit(inhibits, APICV_INHIBIT_REASON_ABSENT, true); > + set_or_clear_apicv_inhibit(&kvm->arch.apicv_inhibit_reasons, reason, > + true); Same here. No need for a v3, I'll fixup when applying. > > - if (!enable_apicv) > - set_or_clear_apicv_inhibit(inhibits, > - APICV_INHIBIT_REASON_DISABLE, true); > + init_rwsem(&kvm->arch.apicv_update_lock); > } > > static void kvm_sched_yield(struct kvm_vcpu *vcpu, unsigned long dest_id) > -- > 2.39.3 >