Message ID | CAPm50aJPpzWz1nnBu6vhcac2kwKq29h-oq7jZtKz23XJ46LW0g@mail.gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2161180wru; Mon, 31 Oct 2022 00:26:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7boCI5z7bOu42bHse5aj9qJOVAGBYdxVHgogU+CYZYQa9XqCvwMVcm18m81NnsbIr/pcS+ X-Received: by 2002:a17:90b:3113:b0:213:82ad:9bc7 with SMTP id gc19-20020a17090b311300b0021382ad9bc7mr21586671pjb.131.1667201181879; Mon, 31 Oct 2022 00:26:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667201181; cv=none; d=google.com; s=arc-20160816; b=g+WQJ58QFTEz1AS15WRz7HwWVPc+kn/GdMt2+NYn7gaYLwY6agd+gt73n8y7a3GNQ2 /I35weUXepXcuGtI0YlWQMcDYXNk40bDElqytF0M2TfNnWawbMps6KtFPt1S9X358Soh nnVIAW+uC8Tqsys9K7O1WHwxB56bEHZJgi6yg/2fl0+LXa+aLr0/vczW0wXANmzIICgs dt8UbxtQ0UNCLSEJ0IssvhaZXgvlA5o3SIWg55wFmm+1m3fMyjvE0q7S8gnkIFT2HI/F niLOuXi5PR/z8bACkjMBvfwGxB3UMeYW1tO6PAO1NdKjSVE7OjQ6FOuCAfF+0EBEliza mNDA== 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:mime-version :dkim-signature; bh=yrNqh8qXz0mUaZPbmwYZ6bkRSvhVnWT2SUvHKAbyQeI=; b=zZE0oIyCX/nrw2NXFDbCYLatPFpNpQpcNpMB217Gq43R7Ut3jmBH4e7C2lf4WEjirx Fkr/+jV0S37mjzhV71jdIvaqkTRrB3UQsqT7Mv0+gCN0niC6leZIISxFX1qJGQeI0eOa LDZ6Zmf6yYXIuJgh50guuGezaoX8miGQARqpFdC9bJqzrNg2oq/E8NFoo5UlMShg15f4 Jx41mt9vzjhUhefdWyYi4kW3F9npERNyxsxxNexVyQJG4nnRjK00fHrHVGC/HvZ0juLC +lz6tLdbPJ4UcUREi3SOJuzWgVy76meL30kHPcYp0gsK7xy2JjegbipEWBZdIfSEbnNC nYIw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="AFji/w6T"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p22-20020a170902b09600b0017a034f7246si7154306plr.560.2022.10.31.00.26.08; Mon, 31 Oct 2022 00:26:21 -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=@gmail.com header.s=20210112 header.b="AFji/w6T"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbiJaHXZ (ORCPT <rfc822;kartikey406@gmail.com> + 99 others); Mon, 31 Oct 2022 03:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229441AbiJaHXX (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 31 Oct 2022 03:23:23 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A8DD21D; Mon, 31 Oct 2022 00:23:22 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id bg9-20020a05600c3c8900b003bf249616b0so7462962wmb.3; Mon, 31 Oct 2022 00:23:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=yrNqh8qXz0mUaZPbmwYZ6bkRSvhVnWT2SUvHKAbyQeI=; b=AFji/w6T6HNj1HCOxpfDpkRT8Lz25YKyAgO0065FyY0H598YV7C+NDJrOGnFT4F2vh E3p9JyZ9qn1HvUNG/6aeNDCrCSwnNbMIBEhS8dTs0C7SG+WJo4n8LPossfXSHFAhkFjL IZ7M0NCuLK/oGiOusrXoBzaESDly96i319+0ts8DvVco3BgxF/zpPUxizSylSlxlrHDI fIFusgkHKi3v8UXbHjmOux+9+JhCykb8pvxlfAbPInEwwfuNBHeh8mPCsShza55yX6ic 67d3y8NCzqEBy/Qdwaj0MxWyWtLLLhZ7Rm7aZzhAKGSF/HrscCdaDqgf/OjE+VayKF0W PdGQ== 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:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=yrNqh8qXz0mUaZPbmwYZ6bkRSvhVnWT2SUvHKAbyQeI=; b=JfBxjLMm2dHdfmK39MCIDEr5FMnod92Ufk6too5OgYtTScEQyx4qgTfkuNaHoygO9V wxPH3HjftSwrAGFUEkwzToNwiwwnts4vBGi6rypOXz9k2wdmdFYEtjzrzXlTmN5IEWur NDgXx0skzZt4BfzF2dgfDT4hYs3c95uL6cHwl6YJ/iGlAlqGzGjSmQsbCI36xgS4GdUX KbkgdyFe3CC4TP6AiE8EEZk60LnTGIgh1wSDQSI6/1JNxt/ni5ca+lTAuM8zYQhJov7g Ha6F8/okNCJSYB6oIVFsKhQfzNRdB/hhCZ8kvakyTmA3EgFDUWmU5OF0Ca8CPkyhe06V gXEg== X-Gm-Message-State: ACrzQf2HSsJ5ycsuqwEPRGLce3gLbWAIN0wObI4NUBLR3lovu7r2ax3Q oo8zDhRL/EUXTwyMBsgXwZhJLjJh0zdqm29qm1ETvm8xn3HsXQ== X-Received: by 2002:a05:600c:1c04:b0:3cf:5fd2:1f74 with SMTP id j4-20020a05600c1c0400b003cf5fd21f74mr9458659wms.45.1667201000765; Mon, 31 Oct 2022 00:23:20 -0700 (PDT) MIME-Version: 1.0 From: Hao Peng <flyingpenghao@gmail.com> Date: Mon, 31 Oct 2022 15:20:07 +0800 Message-ID: <CAPm50aJPpzWz1nnBu6vhcac2kwKq29h-oq7jZtKz23XJ46LW0g@mail.gmail.com> Subject: [RESEND PATCH v2] kvm: x86: Keep the lock order consistent To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Sean Christopherson <seanjc@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748187146774656229?= X-GMAIL-MSGID: =?utf-8?q?1748187146774656229?= |
Series |
[RESEND,v2] kvm: x86: Keep the lock order consistent
|
|
Commit Message
Hao Peng
Oct. 31, 2022, 7:20 a.m. UTC
From: Peng Hao <flyingpeng@tencent.com> Acquire SRCU before taking the gpc spinlock in wait_pending_event() so as to be consistent with all other functions that acquire both locks. It's not illegal to acquire SRCU inside a spinlock, nor is there deadlock potential, but in general it's preferable to order locks from least restrictive to most restrictive, e.g. if wait_pending_event() needed to sleep for whatever reason, it could do so while holding SRCU, but would need to drop the spinlock. Thanks Sean Christopherson for the comment. Signed-off-by: Peng Hao <flyingpeng@tencent.com> --- arch/x86/kvm/xen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) @@ -986,8 +986,8 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports, } out_rcu: - srcu_read_unlock(&kvm->srcu, idx); read_unlock_irqrestore(&gpc->lock, flags); + srcu_read_unlock(&kvm->srcu, idx); return ret; } -- 2.27.0
Comments
Nit, capitalize KVM in the shortlog, i.e. "KVM: x86:". On Mon, Oct 31, 2022, Hao Peng wrote: > From: Peng Hao <flyingpeng@tencent.com> > > Acquire SRCU before taking the gpc spinlock in wait_pending_event() so as > to be consistent with all other functions that acquire both locks. It's > not illegal to acquire SRCU inside a spinlock, nor is there deadlock > potential, but in general it's preferable to order locks from least > restrictive to most restrictive, e.g. if wait_pending_event() needed to > sleep for whatever reason, it could do so while holding SRCU, but would > need to drop the spinlock. Extra whitespace at the beginning of each line should be deleted. > Thanks Sean Christopherson for the comment. > > Signed-off-by: Peng Hao <flyingpeng@tencent.com> > --- Nits aside, Reviewed-by: Sean Christopherson <seanjc@google.com>
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 2dae413bd62a..766e8a4ca3ea 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -964,8 +964,8 @@ static bool wait_pending_event(struct kvm_vcpu *vcpu, int nr_ports, bool ret = true; int idx, i; - read_lock_irqsave(&gpc->lock, flags); idx = srcu_read_lock(&kvm->srcu); + read_lock_irqsave(&gpc->lock, flags); if (!kvm_gfn_to_pfn_cache_check(kvm, gpc, gpc->gpa, PAGE_SIZE)) goto out_rcu;