From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.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 20D0F3BE644 for ; Thu, 25 Jun 2026 22:36:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782426998; cv=none; b=pdQsoSBWd/J3YmCAEPhdmnMYDpxfhtevaUEDGkXnr3G8GmRaLKVjr8ZCKNIhS2bStBHLZfxjes3X94ROiQKOpHTqhSeKPtW4ApP9y/Qi5Zi1S42MOo9JMIKA+brFm8s5xEyZTeC0hXrj9qx7Icr6Y0IVUKmsOb9ciquViEK+5eM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782426998; c=relaxed/simple; bh=tkgAWenidxTobeaXVYo+mMrBXgxtirWy7FTikA/UKtM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=m1fUzV6hNEnbNFVd2qUsBkaxiL6PslYLUD5GErhD7Io7/HU1qZhLxrtiYk3z5Gy2GMcKMkaxb+TfRlf3XigjvNqXOAKV2jy1gt2MYpRJLssYWq0ga7Jx6LvlSbYdORv5jbLlYIpaMhwYIhUdsfSJaf9bcWOW2pH0qcPcc5TCfSg= 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=fYLQh0Hc; arc=none smtp.client-ip=209.85.210.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="fYLQh0Hc" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-84534f17866so181006b3a.2 for ; Thu, 25 Jun 2026 15:36:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782426996; x=1783031796; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=rL8s0hiiR/lgasxkfz+QkDIPhc5NRPLZb5qejoLSFFI=; b=fYLQh0HcFp+E55JPi8S3Dp1/71wLuuLUErHF2wowyn4JhNIh+i167bVbTV8vpC9BYR 3mRccxtA6esn8ubuj6aPIWZ4TkzhZg8UgCEupHZtI4ZC9b6XCMEqiKnfS6zEPF4G+GDx 56sl0pGFO2kCi/wnaKu3Mrfr7YPEV5mRMkAGRGQicBjsZc/t78KVmtXREXnoTUYKF831 AVLAStZWrBd2ZpdMQdwiF7JpmAoaJBmkZ7W9la1NRuzEtlrHWQbzLbS8sr7hhbfd9F2X ZbUbPGAGlaDnNlY39wlSuCIwW7Wifn8RgUiEFv31rMlz+TsX5pg35f9sSOiTu51juRnC n7nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782426996; x=1783031796; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rL8s0hiiR/lgasxkfz+QkDIPhc5NRPLZb5qejoLSFFI=; b=VCY64i8MmPBf2b3UtE7Bn7hkv9OdD09GObtKuVzy1oDkRA6XQLm6TJMqo6+qxJdQxz lt+MqecG/V+rwYDwIJWh8Gx+6B9+KybkBa7bIHAn36i4didhIuWypv+U3HnBeBZyxIO9 PdUE7d/fU9o3QUsdqMXwYCXo5J9Z0Jm5cwVtTa0IDl/WfXJwg4Aw57RAdx4A4g7vLs1b ViTXh5FM2eFdz8YsiLdlZ8TXJc6x8HsKzvsF84hczx9jyOCfq/4jKzfFNxvAHZ8xzcjH KOVZVTkU9Ho7FfFK4wxwb4FpdfMxYSSvXALNhYnzlj15Cz4FouAz4yTx0PSxTBA6Bg2D l/9Q== X-Forwarded-Encrypted: i=1; AFNElJ9OenC24hQixRLRMUC7/IASUsoFmNQ5o4QCr3hANyLymTSc/Fhxi9po/WDhraVCZyO3SWz9DORA64sQxh4=@vger.kernel.org X-Gm-Message-State: AOJu0YylCWvpV75hphZpgr1YBy4ATHpprxgca1mh2Pt7t4daah0ROtpx rXgLYg/4IMJCke2XGRqRAl6fSTsOOE3zyzODTgrTnStulqwj9PB6BcgldudMBIzZjbNL+VQqW2r 2cgpNpw== X-Received: from pfnd17.prod.google.com ([2002:aa7:8151:0:b0:845:b6eb:1852]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:4c10:b0:842:4b88:20ee with SMTP id d2e1a72fcca58-845b3b0313fmr4805272b3a.44.1782426996227; Thu, 25 Jun 2026 15:36:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 25 Jun 2026 15:36:23 -0700 In-Reply-To: <20260625223623.3376478-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260625223623.3376478-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260625223623.3376478-11-seanjc@google.com> Subject: [PATCH v3 10/10] KVM: x86/hyperv: Use {READ,WRITE}_ONCE for cross-task synic->active accesses From: Sean Christopherson To: Vitaly Kuznetsov , Sean Christopherson , Paolo Bonzini , David Woodhouse , Paul Durrant Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+5b32c49cd8f005e65654@syzkaller.appspotmail.com, syzbot+5d2b94b77112148d1744@syzkaller.appspotmail.com Content-Type: text/plain; charset="UTF-8" When activating Hyper-V's Synthetic Interrupt Controller (SynIC), mark it active with WRITE_ONCE() and query it using READ_ONCE() in synic_get(), the only known cross-task reader, to document that the flag is accessed without holding the vCPU's mutex. Note, there are no data dependencies on the SynIC being marked active, e.g. the vector read by synic_set_irq() is set (usually in response to guest activity) long after the SynIC is initially activated, and a false negative on the SynIC being active would be benign (ignoring that such a race is likely to be problematic for the guest irrespective of what KVM does). Signed-off-by: Sean Christopherson --- arch/x86/kvm/hyperv.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index f765c3bb9b1f..9d38cb644668 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -219,7 +219,7 @@ static struct kvm_vcpu_hv_synic *synic_get(struct kvm *kvm, u32 vpidx) return NULL; synic = &hv_vcpu->synic; - return (synic->active) ? synic : NULL; + return READ_ONCE(synic->active) ? synic : NULL; } static void kvm_hv_notify_acked_sint(struct kvm_vcpu *vcpu, u32 sint) @@ -1013,7 +1013,7 @@ int kvm_hv_activate_synic(struct kvm_vcpu *vcpu, bool dont_zero_synic_pages) synic = to_hv_synic(vcpu); - synic->active = true; + WRITE_ONCE(synic->active, true); synic->dont_zero_synic_pages = dont_zero_synic_pages; synic->control = HV_SYNIC_CONTROL_ENABLE; return 0; -- 2.55.0.rc0.799.gd6f94ed593-goog