From patchwork Sun Nov 13 13:52:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe JAILLET X-Patchwork-Id: 19364 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1689378wru; Sun, 13 Nov 2022 05:57:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf7FJV8NSNQG0VFg930UBw39vKiRTLWsBhzPJi2sgMruFbqrmj5G9HrEFstO8/h6tWXgM7/1 X-Received: by 2002:a63:fb4d:0:b0:45c:19bb:d225 with SMTP id w13-20020a63fb4d000000b0045c19bbd225mr8324910pgj.242.1668347872882; Sun, 13 Nov 2022 05:57:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668347872; cv=none; d=google.com; s=arc-20160816; b=i0PM0ASUbkSrBOArBEPg5jpicfxh+NHagO+GvspHhF1/UE6AJUPCZZ8ZMFR+7WlWop hsIDwA5idm0z96HtFK4cFLeWbS83IE+EqFBjoCf9jt/7eV+oCZT7/w6TmNxk5paeCwFt SnUmevAT26k6QodeDxbvB1MrMvPj92+bAFYBlRZYc3JOdTJnJqUljKzeoQOB5yzNtmw7 FeCzzQ+eh7OjytedgqgOvT+oBDJk+oYwS/3DxJ676Eq6MAHO+bX9sXJixK7KlyWd33em aDW7onD7oYYp3F3jEP7yEH9J7uaAZ9nn23mL5nWfKopU8yqDu/+2RTnalMnkrDltyp/d /1Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=/LEOXUbrZ42CVIv1I426H9q5e/a6B341gnVt0xt3chE=; b=i5TK3Ak3jPWzih/eACNh+6TVqwhph/2vTmPMWNs9xbA4Nkh2FXtXI2iEdRqBG4gCbC lYhUfFa7FS9PIHc+1btWqiggHq5fr0B7RLh9GJn6PrR9tzmtg5Q8m0OrzQ5ipu5efIf/ 1bEpBuNV5ivq09CN8a/sf6b2F9VyWJG200ibtlsuhlNpMsC+7JoP0c+dcp7Yxi22gvrO hEyrrue2Wv/2eMULZofrv0tgw02wryveTG7e/m9dFaGvXBzcQ7/wTU3F6g/j/aa2mwcg UqpWC3DdMtybgFCnT/ESbjE8/7UpOg9EtO2OOh2odoRkcjCxuurv+D0FV5BjwpLmuzxL SJ2g== ARC-Authentication-Results: i=1; mx.google.com; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i63-20020a638742000000b0046b3dce845dsi7669376pge.470.2022.11.13.05.57.38; Sun, 13 Nov 2022 05:57:52 -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; 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 S235388AbiKMNxE (ORCPT + 99 others); Sun, 13 Nov 2022 08:53:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235153AbiKMNxD (ORCPT ); Sun, 13 Nov 2022 08:53:03 -0500 Received: from smtp.smtpout.orange.fr (smtp-21.smtpout.orange.fr [80.12.242.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9BFDB11A35 for ; Sun, 13 Nov 2022 05:53:01 -0800 (PST) Received: from pop-os.home ([86.243.100.34]) by smtp.orange.fr with ESMTPA id uDPsoatM9TyouuDPso0z7n; Sun, 13 Nov 2022 14:52:59 +0100 X-ME-Helo: pop-os.home X-ME-Auth: Y2hyaXN0b3BoZS5qYWlsbGV0QHdhbmFkb28uZnI= X-ME-Date: Sun, 13 Nov 2022 14:52:59 +0100 X-ME-IP: 86.243.100.34 From: Christophe JAILLET To: Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org, Christophe JAILLET , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Subject: [PATCH] RISC-V: KVM: Simplify kvm_arch_prepare_memory_region() Date: Sun, 13 Nov 2022 14:52:54 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749389539109036501?= X-GMAIL-MSGID: =?utf-8?q?1749389539109036501?= 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 Reviewed-by: Anup Patel --- 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);