From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: [kvm-unit-tests PATCH 03/18] trivial: alloc: don't use 'top' outside spinlock Date: Tue, 10 Nov 2015 17:24:42 +0100 Message-ID: <56421A4A.3050606@redhat.com> References: <1446769483-21586-1-git-send-email-drjones@redhat.com> <1446769483-21586-4-git-send-email-drjones@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Cc: alex.bennee@linaro.org, cov@codeaurora.org To: Andrew Jones , kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:39660 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753938AbbKJQYv (ORCPT ); Tue, 10 Nov 2015 11:24:51 -0500 In-Reply-To: <1446769483-21586-4-git-send-email-drjones@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 06/11/2015 01:24, Andrew Jones wrote: > This is a fix just due to being too much of a type-A person. > I noticed the issue while reading over the function, and > decided to fix it, even though it's unlikely to be a problem > ever because top is read-mostly (like written once, then only > read, type of mostly). > > Signed-off-by: Andrew Jones > --- > lib/alloc.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/lib/alloc.c b/lib/alloc.c > index ad6761430c965..34f71a337d868 100644 > --- a/lib/alloc.c > +++ b/lib/alloc.c > @@ -61,15 +61,17 @@ static phys_addr_t phys_alloc_aligned_safe(phys_addr_t size, > { > static bool warned = false; > phys_addr_t addr, size_orig = size; > - u64 top_safe = top; > + u64 top_safe; > + > + spin_lock(&lock); > + > + top_safe = top; > > if (safe && sizeof(long) == 4) > top_safe = MIN(top, 1ULL << 32); > > align = MAX(align, align_min); > > - spin_lock(&lock); > - > addr = ALIGN(base, align); > size += addr - base; > > Applied, thanks. Paolo