Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp585939rdb; Tue, 16 Jan 2024 09:20:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IF/hzWDJvmYPo/pDCktmCLehVhGJb8dw5we494HdvvRgffY2Kkr1rvKqingJ+yfWP0GCFfn X-Received: by 2002:a05:6402:2ce:b0:559:c4a7:36f9 with SMTP id b14-20020a05640202ce00b00559c4a736f9mr241025edx.76.1705425651803; Tue, 16 Jan 2024 09:20:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705425651; cv=pass; d=google.com; s=arc-20160816; b=Hh/2BgJOTFqb7mSu3TfPa0tCkkpX5ol53BQ6bypu3Nrfg13f1trgr5oI4E27O95V/c geDfLm4iqWzmcUaGwwxT9GJ4fWb+XN+Ulx+ulHoAxo2fEEnbrNniIsfl1RqF4tHHTarS g96tcaj+ClGcoButin9CjHfETz4fBTaCdCviOy/K7EEAE0EO+pAsv4b9u2xe7nT61Uza vLmpkAhSF7MYhl+elrVajO6+RwGeV7GZ3Pgtc2BP3w1d3Hr6rj/Kv4eUlU4S+qQJbQxE R2aCM/FxqYCyoRUypQP4t5SQvPTk7j2Xhx0teEE8qMn/1T2H56jZE/+4jfuSauW18acR rxIg== 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=clNdxL3spBiROjgCSpV36akIqm7jAf49yzjKH1UtjfE=; fh=FNQjdZUi2IQLjpDVki0yMVkN9uY7qMEsFAUHGOVORVM=; b=QPwQxj6klJmBzCZmmMdwYt+Ukh1Y8ZslFCYltUMRh7ftoxjutrenK4SHXRN0QpekN4 HytsvsptQykDS0ryNpKxKWlRbkc/OjfG6/Ofco0fjN2//qRSbzHClsiQ7ZXH4pa1u5Cu BEjBMMTy80IV7D92b9dFiavuvYD0KXYjzbONhYa3JOUTYt0B+ZnKKXk4HFYdr8Tw+D2q vulA30GMIyrxGw+gAQ/NDmwsP6/UqFmAZjtBa/tDW23MLRfmNlSagJE5BISKZmctHIW7 ozspriLE9QhsgvVg7YIAq/gNw2d56sKnPUHSWLVLy6JIfGnz+DYzuW3vFriy32zPL819 wqFQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=grBawxMW; arc=pass (i=1 dkim=pass dkdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-27619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id c10-20020a0564021f8a00b0055995bb6933si728938edc.549.2024.01.16.09.20.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 09:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=grBawxMW; arc=pass (i=1 dkim=pass dkdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-27619-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27619-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8BFC11F23375 for ; Tue, 16 Jan 2024 17:20:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4C87C1CAA8; Tue, 16 Jan 2024 17:20:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="grBawxMW" 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 116F61C6A4 for ; Tue, 16 Jan 2024 17:20:41 +0000 (UTC) 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; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705425643; cv=none; b=MrsyxbG5wxcA+QdPuyIUIL7325RdcFWhCpQwWryVIRgAR63r5+t+jM77U/ONWW4WZ8PmgRXn5D8GN0IeepP+b3YqQoJVp27WV4Ec3Dz32hm17IT8NQyznzFRsqe+V4julM7HpmEldNatoNJ260EfKaU4uwYjklqa6x3VPNSEcEI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705425643; c=relaxed/simple; bh=tnRy3jWG4+OwIbi8OFvCp/HqFPWFwcstEM2fzjh9K0E=; h=Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Google-Smtp-Source:X-Received:Date: In-Reply-To:Mime-Version:References:Message-ID:Subject:From:To:Cc: Content-Type; b=pR7Hk99g0gYAgOVpAcgq+ZCy4zTF9tix0wXKcndbCfPuYny1/idD/ZkumUV9SCqWbPfTBQ9J9+kO3eEvPay95Su3kQ7A68kKtpl3/T+OEFsPhNyvS/wzWUUUg6FWSxE7Ci+1kaX4GPVfbxwWR+5m1d+oxW7mEk87tpqt3XqhrAo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=grBawxMW; arc=none smtp.client-ip=209.85.219.201 Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc22c1bc534so962535276.0 for ; Tue, 16 Jan 2024 09:20:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1705425641; x=1706030441; 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=clNdxL3spBiROjgCSpV36akIqm7jAf49yzjKH1UtjfE=; b=grBawxMWJiqgfnZmk0IxICqeOhfuMbvdhweSYKny+6e2nUK2KbssCihhckAkhMqZEd t+ikpkvzKqnNpp1ECzKCtujPhxawZYDoWZVlqRQSDWlh5OgV2d9qtX3GWTv7IKMGe+dh uIsVw//Qx0RD50BtbiaATKfyeocjJZBy/RMEPXaNEgO4PuddfM568X/TpNDEkUlrYMEO KzBP9Auszx7fiqpQfUuHpPMejdo7q/i+OrQxUW9x1dzVtO33K5x1S4JKrGb8eV3EINGF IBFq/nJFB8jl/rEQob+zOmJ82oPvQgMTc3Akg+hyHBWMO6+PW8TtGKGNN2ue9M8SytvO SpMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705425641; x=1706030441; 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=clNdxL3spBiROjgCSpV36akIqm7jAf49yzjKH1UtjfE=; b=fovC28XstaR8D2OzjSgngEddrxuMZIE8fbKyJA6AVIYyJP9u/Ld4pYsVpCpEx17mlT m/FEduf0eOTY2GGOKPuriPX/spXkTo9klkwprLIryOr0/Yon+AEXULCYMF4f8giaX1eJ /tWwfeOCMtpnbHw/7YZNn14tEmekOEHX0jYwoS6chzfqiF5MBmh1Ojjdf5/i4CibahkB uCj+icvuBSjA6gR4p5aj7fRRuMLZOVQ8pzsPJnbX8kXrq4usY/lwVCLZ55tHGLtpz8ZK B3370cLIlohdKBW2jKJHRv/2IKITfr+YWxteKkJA6rmPxvL78a2ipCYvdAzfdNb1knhD 6dIA== X-Gm-Message-State: AOJu0Yzzp12che7za+x/AAd1kF9XIqgNz5Xybos2PPmmJRGLHaxPzpfv z9+U7ayDs+2D96cSsSoLhPbopyPi3UNKQ9oSQQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:564:b0:dc2:26f8:91f with SMTP id a4-20020a056902056400b00dc226f8091fmr479444ybt.8.1705425641075; Tue, 16 Jan 2024 09:20:41 -0800 (PST) Date: Tue, 16 Jan 2024 09:20:39 -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: <832697b9-3652-422d-a019-8c0574a188ac@proxmox.com> Message-ID: Subject: Re: Temporary KVM guest hangs connected to KSM and NUMA balancer From: Sean Christopherson To: Friedrich Weber Cc: kvm@vger.kernel.org, Paolo Bonzini , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org Content-Type: text/plain; charset="us-ascii" On Tue, Jan 16, 2024, Friedrich Weber wrote: > Hi Sean, > > On 11/01/2024 17:00, Sean Christopherson wrote: > > This is a known issue. It's mostly a KVM bug[...] (fix posted[...]), but I suspect > > that a bug in the dynamic preemption model logic[...] is also contributing to the > > behavior by causing KVM to yield on preempt models where it really shouldn't. > > I tried the following variants now, each applied on top of 6.7 (0dd3ee31): > > * [1], the initial patch series mentioned in the bugreport ("[PATCH 0/2] > KVM: Pre-check mmu_notifier retry on x86") > * [2], its v2 that you linked above ("[PATCH v2] KVM: x86/mmu: Retry > fault before acquiring mmu_lock if mapping is changing") > * [3], the scheduler patch you linked above ("[PATCH] sched/core: Drop > spinlocks on contention iff kernel is preemptible") > * both [2] & [3] > > My kernel is PREEMPT_DYNAMIC and, according to > /sys/kernel/debug/sched/preempt, defaults to preempt=voluntary. For case > [3], I additionally tried manually switching to preempt=full. > > Provided I did not mess up, I get the following results for the > reproducer I posted: > > * [1] (the initial patch series): no hangs > * [2] (its v2): hangs > * [3] (the scheduler patch) with preempt=voluntary: no hangs > * [3] (the scheduler patch) with preempt=full: hangs > * [2] & [3]: no hangs > > So it seems like: > > * [1] (the initial patch series) fixes the hangs, which is consistent > with the feedback in the bugreport [4]. > * But weirdly, its v2 [2] does not fix the hangs. > * As long as I stay with preempt=voluntary, [3] (the scheduler patch) > alone is already enough to fix the hangs in my case -- this I did not > expect :) > > Does this make sense to you? Happy to double-check or run more tests if > anything seems off. Ha! It too me a few minutes to realize what went sideways with v2. KVM has an in-flight change that switches from host virtual addresses (HVA) to guest physical frame numbers (GFN) for the retry check, commit 8569992d64b8 ("KVM: Use gfn instead of hva for mmu_notifier_retry"). That commit is in the KVM pull request for 6.8, and so v2 is based on top of a branch that contains said commit. But for better or worse (probably worse), the switch from HVA=GFN didn't change the _names_ of mmu_invalidate_range_{start,end}, only the type. So v2 applies and compiles cleanly on 6.7, but it's subtly broken because checking for a GFN match against an HVA range is all but guaranteed to get false negatives. If you can try v2 on top of `git://git.kernel.org/pub/scm/virt/kvm/kvm.git next`, that would be helpful to confirm that I didn't screw up something else. Thanks very much for reporting back! I'm pretty sure we would have missed the semantic conflict when backporting the fix to 6.7 and earlier, i.e. you likely saved us from another round of bug reports for various stable trees.