Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp13394379rwb; Sun, 27 Nov 2022 05:11:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf6HEpMEO5G/1B9ZLW3sqvj1u4EuOZSs79fLZnWv+wNEVPddItQCQSkruki27XAmS+mIQBDU X-Received: by 2002:a17:902:d4c5:b0:189:5e92:d457 with SMTP id o5-20020a170902d4c500b001895e92d457mr14282006plg.166.1669554662878; Sun, 27 Nov 2022 05:11:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669554662; cv=none; d=google.com; s=arc-20160816; b=RVsnvq7oWbCo63O8HHGksme/qB9kQ5vOEXF0wnpExfo36gGiMs7z/BHbi58JBIndJm wrDjSM1qd+nX++uOH3WHjOGAZxcNNI8/0PVARRyuCgd7J8jr5moW14JgJ6MfMqIzzRm8 4QSvdODnpMbQzAsJ9Iu1wJmLn7KECvPChM+W/JGAObOPo4qlNHEvYiKOK/aUgiNWb5/U wcg9kyB3euVzbjxSd6JAABWsrocEB38fDi2v8bd6z2hoDPqKKNcceQpsfbJBk94AMICh lzfLRV+VnKFrPDHmKQ3cUvscUUvpG3fiYfeoTGKmOls42e9QZA+cVKhsPQ+98jJLTbFg 9aZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=4/jGKMCRGMK21dJ1aCsortAFYXlCDfIKm1QYzbvgS2c=; b=dF1yCCCR821Pw8OyYdOaM/5zwEo8oLTX7ymOqT93AgPxSgnPygF4pJwrmGA/AvcFkI QO/VZBdz9OwA3bzXj6kSn5QeJWbdVtOvpl5+u9+vbU7IxFsyegnssAax4tTSoEVkDueV afShojPG2wh+sC/FTLYIM7vMAEumJ45eCt9u6srAwnD9871/s9meRId6BeKJqEfkJSUE TflFk/EHwM6Dkzs9lmgaYEStItDHdKc+nS8ArHUDchO9DyfEgw6i76doTtEChRHwKJyy cFJKRRLANo9mVr0tRaW40l2giHUB2PkmFFejJBZIzmMkGC/YPGJYwaNi33+QD+46rYHm PBsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=NXW07i+f; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a134-20020a621a8c000000b0056cb8f6f027si8084027pfa.357.2022.11.27.05.10.52; Sun, 27 Nov 2022 05:11:02 -0800 (PST) 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=@brainfault-org.20210112.gappssmtp.com header.s=20210112 header.b=NXW07i+f; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229500AbiK0Mhh (ORCPT + 84 others); Sun, 27 Nov 2022 07:37:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbiK0Mhg (ORCPT ); Sun, 27 Nov 2022 07:37:36 -0500 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFF97E5B for ; Sun, 27 Nov 2022 04:37:30 -0800 (PST) Received: by mail-ej1-x630.google.com with SMTP id i10so19785123ejg.6 for ; Sun, 27 Nov 2022 04:37:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=4/jGKMCRGMK21dJ1aCsortAFYXlCDfIKm1QYzbvgS2c=; b=NXW07i+fE98DmbrjPPH7Em35P9hSzgrdqGIspcOhXrHkH45LeFM4Ma9uzZyAwqM4nf kyHZcHVZQ1ODY5HvfgpH4tf0q9xmXaYsadXiJ2GiCNZJc6afvbPIBI2MpVA3erqHSLHh avQgmwPVPhy4KbRq8MyOqZgeDlD0go2IT9WzVsg6H0KLZvi28SmzjLXYSgGXQc56bPxf QbY9ctnOfmjk+u3nn0U62MaQYdOCmmXRjY8Ry+Wt6D7WJgvoS+AnDPIUF72yvcNaWI9v 4rMQrMMoaClwCzyhv/QQ/ZRUTma6IYKY06rC0CLInBNvwAxwASr84tfas+Z+J1NvjEQZ PCUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4/jGKMCRGMK21dJ1aCsortAFYXlCDfIKm1QYzbvgS2c=; b=7iHRGEJJAiKZXpqpNGldtqRw/yGqCjYitiuIKvjMnl+9HOka5+tKDRN/KW9YiKo9tF mLshf9A+Dh5wdIEKDvrijyWFCw1CuYGc44HPHM6C8Auk3rxqJRjQdUWxajJ+xbz0CLZz Q5WjzVKjek8eWpRJhXypqmWFpKiDjyRYo5/wx+6Xx46C2EfEb+WJ7ce7qtvygxJdiIHo GteOwsHtqyLnymvvpbRiz+0NpzxKPAhGhsdQU0tKqQNtagXSDQlK5FM/XY05hsi60cN6 c7cnTdLXq69xddGvYpge8preg54W49qMaKlQOs6NrXGlS9VVVoS9DPqA5ultEiU75rNu ugng== X-Gm-Message-State: ANoB5pk/iMG5kVcLzk8S2TtC3qJ//1y6d7kE3luESDmSk+vDnQyDF3Pl 6v1g3YhdBSrC7aGGpuhxbf8aXNfHYvynNPG/5LwvmA== X-Received: by 2002:a17:906:6dd5:b0:78d:a633:b55 with SMTP id j21-20020a1709066dd500b0078da6330b55mr41141442ejt.106.1669552649306; Sun, 27 Nov 2022 04:37:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Anup Patel Date: Sun, 27 Nov 2022 18:07:17 +0530 Message-ID: Subject: Re: [PATCH] RISC-V: KVM: Simplify kvm_arch_prepare_memory_region() To: Christophe JAILLET Cc: Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 Sun, Nov 13, 2022 at 7:22 PM Christophe JAILLET wrote: > > In kvm_arch_prepare_memory_region(), if no error occurs, a spin_lock()/ > spin_unlock() call can be avoided. > > Switch to kvm_riscv_gstage_iounmap() that is the same as the current code, > but with a better semantic. > It also embeds the locking logic. So it is avoided if ret == 0. > > Signed-off-by: Christophe JAILLET Looks good to me. Reviewed-by: Anup Patel I have tested this on QEMU virt machine for RV64. Queued this patch for Linux-6.2 Thanks, Anup > --- > I don't use cross-compiler, so this patch is NOT even compile tested. > --- > arch/riscv/kvm/mmu.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c > index 3620ecac2fa1..c8834e463763 100644 > --- a/arch/riscv/kvm/mmu.c > +++ b/arch/riscv/kvm/mmu.c > @@ -537,10 +537,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm, > if (change == KVM_MR_FLAGS_ONLY) > goto out; > > - spin_lock(&kvm->mmu_lock); > if (ret) > - gstage_unmap_range(kvm, base_gpa, size, false); > - spin_unlock(&kvm->mmu_lock); > + kvm_riscv_gstage_iounmap(kvm, base_gpa, size); > > out: > mmap_read_unlock(current->mm); > -- > 2.34.1 >