From nobody Sat Feb 7 17:40:52 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 D0562283C89 for ; Fri, 23 Jan 2026 22:45:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769208333; cv=none; b=tlaWWbw0X1y4+FCFvIEqSJ/b3xq0F+5oFBPfjnbrzOkb/dj/TPBylP4u8dgqHP243OxRjxYzZcyQJMmHyyMn2uJVUGpOEl9sQ2XeaqA8AUu0qcD90gxGTGaAVFAzC6DfoKAA44AA1QKpHfjk2J8yDf8eDrywBbB9JQ2OURhBwr4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769208333; c=relaxed/simple; bh=Ccvg+AYwTTpgd358fTNaOhaa4kNk7pNmtPUuSx54YI8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=R90j4sNFMV6E/DiltFPGNgYqwbzDYbXtUK4BShQLEAseGR/ts7puSC/FCsha0bRj98/d3cc6vyXpmzdmS6lvZLQRvIod8KrNJlItzguQ/FMYLb4XMyvK1WSqNX00/lUqEYRhc9nOygO/BgYVFVLn4uLpYcx4ReF7D1vaWohhDu4= 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=CplhEJpb; arc=none smtp.client-ip=209.85.214.202 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="CplhEJpb" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2a7d7b87977so21671495ad.0 for ; Fri, 23 Jan 2026 14:45:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1769208326; x=1769813126; 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=Na3qF+OZinsVySntYS5W+c40/G1z3qAxcjUlnhMcrIQ=; b=CplhEJpbs/vQQlqQIyhUpnxr/sWGsnF57+S3Yf4J1PaY9tvkfn3IixgRPqZ5kn+XeK bGXJ7hmLfkyr9Ft4eyVk89ZApPujIkD3KsEvVAGvpjwM66bVLlx/CA2h3nCsdURA9XiU qjMbqj43xa6ed0K7P+ZwOWYcN/OxG0NMyP/FSBTZ2tO1741DI5eBt2XJdghcWA+QonHC YIt5dsXP+UNjwQnKADFw6HVGycj7X1TquVd81eIfrGw50547C3rGJ7T0mBapVt25u4L0 cMK9PieDGU6ExXGuehcbpIkN/L9FvP+Gwm9h0uko8tUmKqscQ7O5a3TOYN9chLfIspt4 3PBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769208326; x=1769813126; 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=Na3qF+OZinsVySntYS5W+c40/G1z3qAxcjUlnhMcrIQ=; b=NJXpZltNMUogzQy0Hc77hE6uXZ1EFrP7yKL4gY4fv5jNzjVpsXGf1uTkDmwA+md+wW +8/4y4CgAKu9et19Rb9WycfEFhsyY6GV2/WyqHj35FtecmIp9AcFN2eGX5YCDeYwOQPL naXWUs4YrTyZFDTKdblxEnbeXHq+kDNcQ2b4qpnUL3K0uv9yLcGMrQV4HcRX+BbkuNgK 1Ae+/761+Pj5V2JwIMAVdTkyIxfGCin5lmJWxCo+giqgPyk9zbvBCekGxuP4ZjZ8JFO2 gld57Rxb4iTU3gONjaj054Ezy4zT+S9BUWIlph/p20UG57SDZwUCr1ozxaTtaoXc9V5v q0TQ== X-Forwarded-Encrypted: i=1; AJvYcCU/ta29Y4O+Y+5xSEhwdHhtz6d5ZWn5Ar6R4endi/P76EV7VSnzy5qX4ImoulXqGQZyFtOAVEfzQDHv0SY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9Px8YoHi/hu4HeSWUCuB2I2qF5tFALokmmLbYrOh1RCdUXkO4 RvGT8NxNRmvLj+FMsu29wFAlfY9ZRbPEOzCwVabE1QMHFkrRETUUOlrmGzc0LyEcidRlX2kZJRI 2G7HtfQ== X-Received: from plhy12.prod.google.com ([2002:a17:902:d64c:b0:29f:26e9:4ade]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:98b:b0:295:b46f:a6c2 with SMTP id d9443c01a7336-2a7fe625074mr37894025ad.37.1769208325807; Fri, 23 Jan 2026 14:45:25 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 23 Jan 2026 14:45:14 -0800 In-Reply-To: <20260123224514.2509129-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: <20260123224514.2509129-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.457.g6b5491de43-goog Message-ID: <20260123224514.2509129-5-seanjc@google.com> Subject: [PATCH v2 4/4] KVM: Isolate apicv_update_lock and apicv_nr_irq_window_req in a cacheline From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Naveen N Rao Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Force apicv_update_lock and apicv_nr_irq_window_req to reside in their own cacheline to avoid generating significant contention due to false sharing when KVM is contantly creating IRQ windows. E.g. apicv_inhibit_reasons is read on every VM-Enter; disabled_exits is read on page faults, on PAUSE exits, if a vCPU is scheduled out, etc.; kvmclock_offset is read every time a vCPU needs to refresh kvmclock, and so on and so forth. Isolating the write-mostly fields from all other (read-mostly) fields improves performance by 7-8% when running netperf TCP_RR between two guests on the same physical host when using an in-kernel PIT in re-inject mode. Reported-by: Naveen N Rao (AMD) Closes: https://lore.kernel.org/all/yrxhngndj37edud6tj5y3vunaf7nirwor4n63yf= 4275wdocnd3@c77ujgialc6r Tested-by: Naveen N Rao (AMD) Signed-off-by: Sean Christopherson --- arch/x86/include/asm/kvm_host.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index b08baeff98b2..8a9f797b6a68 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1435,13 +1435,23 @@ struct kvm_arch { bool apic_access_memslot_enabled; bool apic_access_memslot_inhibited; =20 + /* + * Force apicv_update_lock and apicv_nr_irq_window_req to reside in a + * dedicated cacheline. They are write-mostly, whereas most everything + * else in kvm_arch is read-mostly. Note that apicv_inhibit_reasons is + * read-mostly: toggling VM-wide inhibits is rare; _checking_ for + * inhibits is common. + */ + ____cacheline_aligned /* * Protects apicv_inhibit_reasons and apicv_nr_irq_window_req (with an * asterisk, see kvm_inc_or_dec_irq_window_inhibit() for details). */ struct rw_semaphore apicv_update_lock; - unsigned long apicv_inhibit_reasons; atomic_t apicv_nr_irq_window_req; + ____cacheline_aligned + + unsigned long apicv_inhibit_reasons; =20 gpa_t wall_clock; =20 --=20 2.52.0.457.g6b5491de43-goog