Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3793381pxj; Tue, 11 May 2021 11:59:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypfb2w1fYvyNuWz6/aN/4MEiBdahgTJi6cL6KleC2qyWZ6h4rDGflHsh21pR6CRJK1IhB2 X-Received: by 2002:a17:906:53d1:: with SMTP id p17mr32875432ejo.470.1620759569868; Tue, 11 May 2021 11:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620759569; cv=none; d=google.com; s=arc-20160816; b=rJWBdgFT2pGTEBWrrq2dZ2sA54VTM6UmiTcZ/hypsChrAhPd4MbXrgeEw5kWO5o8/f djLUaKB78YkqCJkOx+rSwRQqJun49tMzWqk6f2EnJNDpjkZmw0vf7bl0sk4NNqR/mlxg 5zUk0F/r0t7avMkXBTp9ULiP5k9W15CN+fWjmhl8eBZJKmDYG7ptgYeSsPrfIlU81zs1 veDsj/IS2YQ81FEYTQq0v4qaa0ErPKhIzHmh3PF/Oo5Si25wi8NeP4/oOdTWWMCHZXJo w9BZlepemTnNf3AZx1FCrOdvXqY8Cs/SrblJz0E2xfu89z244kNJdjp40VtKeedU5rDd eCJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=oLyk2sgqTL5Vn/TKBovsUc1DwhBNmb78942+z6JgkFk=; b=wdlC+X2pT7Ig4pGsVEJEj7UrQDbhwz5QSdCQ5co/5hgm5A4PgRZnB+uY02K/7KoTtY m/1yG+69NJVHG09QGhEY4sj1buArhE5UAOTG7XnLtamBAajz/Bj/LaHqrZfcdNRhNfmC hOzuWkMzytE9EDeSB9im1EIz67Czjztto2veZ+AhL9lL5HdW6j2FVWASbJ0IqD087kD9 SnYMiBgO4kSMMC+M+LpgjigEMpOJlCNRTMS8Rp3hilt6G82bstS2NwDbeenH5ZScGqdV Ny9gUodwvgsxlz+2kXQ3k8q0X2xbs+J9TDO9Ob/rsRc7UXr7pAy+8jvI/FiSQouXF/si dmHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VY6g8j2s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id af15si17364579ejc.400.2021.05.11.11.59.06; Tue, 11 May 2021 11:59:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=VY6g8j2s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231896AbhEKS7Q (ORCPT + 99 others); Tue, 11 May 2021 14:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbhEKS7H (ORCPT ); Tue, 11 May 2021 14:59:07 -0400 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8535CC06174A for ; Tue, 11 May 2021 11:58:00 -0700 (PDT) Received: by mail-pj1-x102f.google.com with SMTP id ge1so12193240pjb.2 for ; Tue, 11 May 2021 11:58:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=oLyk2sgqTL5Vn/TKBovsUc1DwhBNmb78942+z6JgkFk=; b=VY6g8j2sEMXzCcSYW74rKGa5U9UpB5xe1yY6CRFpyuD+pNCkDDeO/JH1RtSF5Y95nj RdJmSVGXGoMyYryeRQbkzfdhDP4t5I+3HP1mS/q7QAOlf/c/BRPjh7W0W/xupnLY1dDm PNCG4m8kYULgCDgLwXOVeL3u3G16aj/oYDP18LOVCWPKVOPzC9usudGj47t3Gq7HWSAb Kq6TyFmTIMe8IaMVps9eNuO1Fm4P3qaA2fGyXN8R7KQHVuPwy5m7YKRL6/t6Kr5GOkre W7NXOvr7qgk4wOqGu8fOHfjDVlaJd1MsbKI5PEUHix5HRh7m3ZTpydWrxiQcD+R3sVuY A1bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=oLyk2sgqTL5Vn/TKBovsUc1DwhBNmb78942+z6JgkFk=; b=OfSC+M93JiaU6W+itWXW4ExYr6W67qa9gKqlLcqenMcKIwCzHLqStpQeTnBd+KNdRh iFfQx/9gH8JeW1HlrjkAbUqv4mBUJyi2F7MyJF9DIdG4r6R0bjqE+5ODPkfmqjvbUQfZ +OByXeQ5LCVTI5rRUZW64D3AItzgSwsABPwSUbpyr2pDQLxsixI5rSxQYLkHv1VlUWlD i/2kRA9ZLkJdTtW7VCWwIQA+RnvRIR/Hj8oSRuz9mJRAmZSaBVGApb9sX4WTdVdCcxlL 1fjGtdEcQGy0P1U7N3UaEVYR9BZeThP0OaxQIwEPmc6AwpFZik1YETuVyT45LSgDLy5l TfMA== X-Gm-Message-State: AOAM531zq4bA44gTO4xFzUMC95U1gMpFzxkXb49/LqtvTz1HwslsJJM3 bdqkuWfclp7YM2IYmRkKBq+zOw== X-Received: by 2002:a17:902:e986:b029:ee:d430:6bf9 with SMTP id f6-20020a170902e986b02900eed4306bf9mr31780254plb.0.1620759479901; Tue, 11 May 2021 11:57:59 -0700 (PDT) Received: from google.com (240.111.247.35.bc.googleusercontent.com. [35.247.111.240]) by smtp.gmail.com with ESMTPSA id 130sm13473105pfy.75.2021.05.11.11.57.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 11:57:59 -0700 (PDT) Date: Tue, 11 May 2021 18:57:55 +0000 From: Sean Christopherson To: Ben Gardon Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, Paolo Bonzini , Peter Xu , Peter Shier , Yulei Zhang , Wanpeng Li , Xiao Guangrong , Kai Huang , Keqian Zhu , David Hildenbrand Subject: Re: [PATCH v4 7/7] KVM: x86/mmu: Lazily allocate memslot rmaps Message-ID: References: <20210511171610.170160-1-bgardon@google.com> <20210511171610.170160-8-bgardon@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511171610.170160-8-bgardon@google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 11, 2021, Ben Gardon wrote: > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > @@ -10935,6 +10937,46 @@ static int memslot_rmap_alloc(struct kvm_memory_slot *slot, > return 0; > } > > +int alloc_all_memslots_rmaps(struct kvm *kvm) > +{ > + struct kvm_memslots *slots; > + struct kvm_memory_slot *slot; > + int r = 0; No need to initialize r. And then it makes sense to put i and r on the same line. > + int i; > + > + /* > + * Check memslots_have_rmaps early before acquiring the > + * slots_arch_lock below. > + */ > + if (smp_load_acquire(&kvm->arch.memslots_have_rmaps)) > + return 0; > + > + mutex_lock(&kvm->slots_arch_lock); > + > + /* > + * Read memslots_have_rmaps again, under the slots arch lock, > + * before allocating the rmaps > + */ > + if (smp_load_acquire(&kvm->arch.memslots_have_rmaps)) > + return 0; This fails to drop slots_arch_lock. > + > + for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) { > + slots = __kvm_memslots(kvm, i); > + kvm_for_each_memslot(slot, slots) { > + r = memslot_rmap_alloc(slot, slot->npages); > + if (r) { > + mutex_unlock(&kvm->slots_arch_lock); > + return r; > + } > + } > + } > + > + /* Write rmap pointers before memslots_have_rmaps */ > + smp_store_release(&kvm->arch.memslots_have_rmaps, true); > + mutex_unlock(&kvm->slots_arch_lock); > + return 0; > +} > + > static int kvm_alloc_memslot_metadata(struct kvm *kvm, > struct kvm_memory_slot *slot, > unsigned long npages) > @@ -10949,7 +10991,8 @@ static int kvm_alloc_memslot_metadata(struct kvm *kvm, > */ > memset(&slot->arch, 0, sizeof(slot->arch)); > > - if (kvm->arch.memslots_have_rmaps) { > + /* Read memslots_have_rmaps before allocating the rmaps */ > + if (smp_load_acquire(&kvm->arch.memslots_have_rmaps)) { > r = memslot_rmap_alloc(slot, npages); > if (r) > return r; > -- > 2.31.1.607.g51e8a6a459-goog >