From: Jim Mattson <firstname.lastname@example.org> To: Sean Christopherson <email@example.com> Cc: Paolo Bonzini <firstname.lastname@example.org>, Vitaly Kuznetsov <email@example.com>, Wanpeng Li <firstname.lastname@example.org>, Joerg Roedel <email@example.com>, firstname.lastname@example.org, email@example.com, Ben Gardon <firstname.lastname@example.org> Subject: Re: [PATCH] KVM: x86/mmu: Fix per-cpu counter corruption on 32-bit builds Date: Wed, 4 Aug 2021 15:19:30 -0700 [thread overview] Message-ID: <CALMp9eSxuoLf4hopA_=y_FohCAnLRjQuQ_PeGKO325UJ5J+qLA@mail.gmail.com> (raw) In-Reply-To: <email@example.com> On Wed, Aug 4, 2021 at 2:46 PM Sean Christopherson <firstname.lastname@example.org> wrote: > > Take a signed 'long' instead of an 'unsigned long' for the number of > pages to add/subtract to the total number of pages used by the MMU. This > fixes a zero-extension bug on 32-bit kernels that effectively corrupts > the per-cpu counter used by the shrinker. > > Per-cpu counters take a signed 64-bit value on both 32-bit and 64-bit > kernels, whereas kvm_mod_used_mmu_pages() takes an unsigned long and thus > an unsigned 32-bit value on 32-bit kernels. As a result, the value used > to adjust the per-cpu counter is zero-extended (unsigned -> signed), not > sign-extended (signed -> signed), and so KVM's intended -1 gets morphed to > 4294967295 and effectively corrupts the counter. > > This was found by a staggering amount of sheer dumb luck when running > kvm-unit-tests on a 32-bit KVM build. The shrinker just happened to kick > in while running tests and do_shrink_slab() logged an error about trying > to free a negative number of objects. The truly lucky part is that the > kernel just happened to be a slightly stale build, as the shrinker no > longer yells about negative objects as of commit 18bb473e5031 ("mm: > vmscan: shrink deferred objects proportional to priority"). > > vmscan: shrink_slab: mmu_shrink_scan+0x0/0x210 [kvm] negative objects to delete nr=-858993460 > > Fixes: bc8a3d8925a8 ("kvm: mmu: Fix overflow on kvm mmu page limit calculation") > Cc: email@example.com > Cc: Ben Gardon <firstname.lastname@example.org> > Signed-off-by: Sean Christopherson <email@example.com> Ouch! Reviewed-by: Jim Mattson <firstname.lastname@example.org>
next prev parent reply other threads:[~2021-08-04 22:19 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-04 21:46 Sean Christopherson 2021-08-04 22:19 ` Jim Mattson [this message] 2021-08-05 7:33 ` Paolo Bonzini 2021-08-05 11:26 ` Maxim Levitsky
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to='CALMp9eSxuoLf4hopA_=y_FohCAnLRjQuQ_PeGKO325UJ5J+qLA@mail.gmail.com' \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH] KVM: x86/mmu: Fix per-cpu counter corruption on 32-bit builds' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).