Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp937247rwb; Wed, 28 Sep 2022 10:56:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5uRjsJeh5uacH1PnhQdZeubphwyIGXGoEdcHUxAWCn3NzSpl0kFggzaceXXgGrkQJcTcjQ X-Received: by 2002:a17:907:7289:b0:783:afc4:1413 with SMTP id dt9-20020a170907728900b00783afc41413mr13028467ejc.388.1664387790506; Wed, 28 Sep 2022 10:56:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664387790; cv=none; d=google.com; s=arc-20160816; b=tE62sBTI2aPilBOADd9AuRLDnFI0IgPgE2yJwyI3VRuUxTaslPjNKaPHCYAHzgyfLG M8LBYfRoS2RkNH33Z8ArWAGaTlu2bHXKefn9PcHggZ1SpbHXMXR8XnvLKCnHGXzjGZtN 0vup8jlk+SviN1caaEU6MEYOKl1Z3NtNCYvUvvP59gVghdnei2n77E9g/xzZ6DevTofe G4rRayPc2GZdb0UvTzghzGC9yHYsVipt4U+hZeX9+B0ClHxHEP35ET1KgudPLe1bt1YO q+GEUotKtxILNL8W6vY5l8CjG70krl1PsfYFoAJMA6B24kF4iD7KxXBFRR+PAg/g4pax e/yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=4d6KuZOsMOU7NFpnx9W10QIiBigRqBCL2YFQkOodRVs=; b=ia1ocELGCtyhgwc2cdW/xnttmT3gp7n+h/u2hxvFUx2DfypLrZVn0ho1/2GGY24+o6 3mEPkhEX6LiaF3aHAtkDoIJudS1PjELPTSNeUmj1FxmBNBXeMg0IRl/KPpV4xSR9kUW+ H/P3iFWXGJVv2e+0ebxOEXMGDsDzthhSncBmqtF3apuqio2aRWhxcoMaf9eWS9VYdz+9 q6pa5ZH19m8YLYKT7W3TJd5Ul7UuGg1v9+tMI7OeZQjKm0pjc6MyXlhctgpHOr5D9HoU OobTj1cXlJAfCtDUQF+tYR20/NSq2u2rX5PnR8q2fQLbU3cfBK1DWYBTQUr7sJwYeSbi 5WqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GNMv3bP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ck1-20020a170906c44100b00781f51771b6si4792844ejb.900.2022.09.28.10.56.04; Wed, 28 Sep 2022 10:56:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GNMv3bP1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234157AbiI1REs (ORCPT + 99 others); Wed, 28 Sep 2022 13:04:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233396AbiI1REn (ORCPT ); Wed, 28 Sep 2022 13:04:43 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 280ABBF7B for ; Wed, 28 Sep 2022 10:04:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664384681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4d6KuZOsMOU7NFpnx9W10QIiBigRqBCL2YFQkOodRVs=; b=GNMv3bP1h/ABObSPbvs9cWvsi8PF1DtDbyxSPYNMjPJf0D33af4s8G99aib7YRVuOxFcNT GslubkPH7a3H6X3doeW6R8WvrYVK3XzaT9pGQTsuQJ5yrjfuNAWQ6j/b1j0g5ZNKn/lumQ BgwGPTWUimb4dD4kp+kGcRQMZfonDMk= Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-354-dvXjC3Y8OFCe8wShxuP_0w-1; Wed, 28 Sep 2022 13:04:39 -0400 X-MC-Unique: dvXjC3Y8OFCe8wShxuP_0w-1 Received: by mail-ej1-f70.google.com with SMTP id ga36-20020a1709070c2400b007837e12cd7bso4729368ejc.9 for ; Wed, 28 Sep 2022 10:04:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=4d6KuZOsMOU7NFpnx9W10QIiBigRqBCL2YFQkOodRVs=; b=bv9NzcGTm9hXDgZP82xLRvBNIrTnoQrvL1pxOZKxj14jiarG8wptJ8q7n6ss+un563 vbH2EWTck/G4+NniNLsnJ/Cwng/MGNEtuLwPMhiA/U0Q0bcbBmMeOFWV5lYPt7pICKaK axClP+tEFmMXK83FIdlvyq+clyuiJsw1ZS6wdYFmtS3rzK1ZQ6F19OIZ8QVgv+co3aJg xjrhbouJLd7VIerG5dGZukyW0GKVX3FvxoubBQA5KJp+mYABDYAfDdvbxCZvU5nD+wUC C9ebjo30SwDzJfZ2bWrpdL/Y9K95R2Z2CcK8aIxSxzxqtCvHSynFtnwbhzAoSPu1hQFR eEoQ== X-Gm-Message-State: ACrzQf0M78wYDb9iyK+gVrGT08aCgSQgtyNuRAHHzbmzAh/zMJJJE8U7 o+BijRpfaWo9Zl+Ldrs8AcVZUkDMlDXJ72n1oIoS+WceN3QkuIVzlUay9uKpXCRKKUXeCW+KoyG QuWjVmO6BlnVz9baX7V70TW1k X-Received: by 2002:a05:6402:5249:b0:451:67ff:f02 with SMTP id t9-20020a056402524900b0045167ff0f02mr34874654edd.227.1664384678746; Wed, 28 Sep 2022 10:04:38 -0700 (PDT) X-Received: by 2002:a05:6402:5249:b0:451:67ff:f02 with SMTP id t9-20020a056402524900b0045167ff0f02mr34874609edd.227.1664384678433; Wed, 28 Sep 2022 10:04:38 -0700 (PDT) Received: from ?IPV6:2001:b07:6468:f312:2f4b:62da:3159:e077? ([2001:b07:6468:f312:2f4b:62da:3159:e077]) by smtp.googlemail.com with ESMTPSA id kl14-20020a170907994e00b007813968e154sm2610479ejc.86.2022.09.28.10.04.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Sep 2022 10:04:37 -0700 (PDT) Message-ID: Date: Wed, 28 Sep 2022 19:04:36 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 Content-Language: en-US To: Emanuele Giuseppe Esposito , kvm@vger.kernel.org Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , David Hildenbrand , Maxim Levitsky , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org References: <20220909104506.738478-1-eesposit@redhat.com> <20220909104506.738478-5-eesposit@redhat.com> From: Paolo Bonzini Subject: Re: [RFC PATCH 4/9] kvm_main.c: split logic in kvm_set_memslots In-Reply-To: <20220909104506.738478-5-eesposit@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/9/22 12:45, Emanuele Giuseppe Esposito wrote: > +/* > + * Takes kvm->slots_arch_lock, and releases it only if > + * invalid_slot allocation or kvm_prepare_memory_region failed. > +*/ Much simpler: "kvm->slots_arch_lock is taken on a successful return." This is a small change in phrasing, but it makes a lot more sense: on success you are preparing for the final commit operation, otherwise you just want the caller to return your errno value. [...] > +/* Must be called with kvm->slots_arch_lock held, but releases it. */ s/but/and/. Even better, "and releases it before returning". "But" tells the reader that something strange is going on, "and" tells it that something simple is going on. I would also rename the functions along the lines of my review to patch 3, to highlight that these function prepare/commit a *change* to a memslot. > +static void kvm_finish_memslot(struct kvm *kvm, > + struct kvm_internal_memory_region_list *batch) > +{ > + struct kvm_memory_slot *invalid_slot = batch->invalid; > + struct kvm_memory_slot *old = batch->old; > + struct kvm_memory_slot *new = batch->new; > + enum kvm_mr_change change = batch->change; lockdep_assert_held(&kvm->slots_arch_lock); > > /* > * For DELETE and MOVE, the working slot is now active as the INVALID > @@ -1883,6 +1898,18 @@ static int kvm_set_memslot(struct kvm *kvm, > * responsible for knowing that new->arch may be stale. > */ > kvm_commit_memory_region(kvm, batch); > +} > + > +static int kvm_set_memslot(struct kvm *kvm, > + struct kvm_internal_memory_region_list *batch) > +{ > + int r; > + > + r = kvm_prepare_memslot(kvm, batch); > + if (r) > + return r; > + > + kvm_finish_memslot(kvm, batch); > > return 0; Ok, these are the functions I hinted at in the review of the previous patch, so we're not far away. You should be able to move the kvm_set_memslot call to kvm_set_memory_region in patch 3, and then replace it with the two calls here directly in kvm_set_memory_region. Paolo