From patchwork Wed Jul 20 08:50:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Renner Berthing X-Patchwork-Id: 1658400 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=f1n/NGNX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LnqDY6Lxrz9s1l for ; Wed, 20 Jul 2022 18:51:08 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1oE5Q0-0008Ni-2y; Wed, 20 Jul 2022 08:50:56 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1oE5Py-0008NT-Vj for kernel-team@lists.ubuntu.com; Wed, 20 Jul 2022 08:50:54 +0000 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 99D813F11C for ; Wed, 20 Jul 2022 08:50:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1658307054; bh=SoYcrcgax9Pf6T+1RXGlqOomdGdJeEnHGZLCyrIEb6Q=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f1n/NGNXq4udfzHjtDSCknabCHA1/p/xXjEkG/dA5zHV4ifUu9j34ohUTXyh+xM/7 oGa+Ec+VvTtjqdbuQdbGt883HOA3GvRlJNATGkw4bYtgFC9ntwmenQ8FDFTITYyvnH M3JcWg75sF5UbJCaiTJCadA2KyxRkC7sFEW7pD+lxOxXbNA6ptc0FKbxZILSagfmVP MTvi1m3wkKDGPzks+f00OZ7dBxcYJz1a5lTLdZk4/v2ytQKdV78gbcafCi6G0mzj7t pSUVJ9a8QoF/uQuqLG+nqJFOFgedgzuX7+3d6XAUNSfYORL0B39At4kz95SCHEtMJs DPwKMn+P106fQ== Received: by mail-ej1-f70.google.com with SMTP id hq20-20020a1709073f1400b0072b9824f0a2so3876198ejc.23 for ; Wed, 20 Jul 2022 01:50:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SoYcrcgax9Pf6T+1RXGlqOomdGdJeEnHGZLCyrIEb6Q=; b=p1gJBwNYGHdQkznafst1E13orHqnv32uFKvFqMjS1fSBPzSzwdB3y/0cGk7AhwCZ12 AOpE+zitYEUtsb8D6BHVOtiZ5ItUe4juKg2rquSU4OPCbZEmBKdwBW+x9Pwz4PCqCoSk CDblQMLpFAC1P7v6GN2GDn+jqqpRlaXleI7jNXXDOb2XREAlnAkxzMlcfpbfbwChzDGX IjhvrkCplK+TtrcdkbU45gUyeaM4zqZxxRuULspL/x0GrufB3zA5leFt1B1mPBTzrLhn 9ThVHn0oJBw7oVXtRJummvhIph47a31uQrFxyn60tY/QoMZBf72QKLuz7x/hSK1Rgz34 PeTg== X-Gm-Message-State: AJIora8y/r05oaTugKoDJ5d0BWIR/gwlu0zl2ALDOUtPQUZZg+k4d4hS 2ieKy6il4LzIwoRFMCHoIvuDz/cmj8UMar1q5P+UdmbsXlcy7e83UrDRdh92TvtDeYo0kLfmGVh kjK/ir9HmYvon9fgOj7zCKioyL3ZiHTh5NsvCodrC3w== X-Received: by 2002:a05:6402:5513:b0:43a:b866:b9ab with SMTP id fi19-20020a056402551300b0043ab866b9abmr50105695edb.290.1658307054044; Wed, 20 Jul 2022 01:50:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spJ6V7ufOPyWiHkIbVgelIreGAT1L5UL7w6rZgiUoZLfc/Qz/MaimWAWJlU4h3FvNaL3U0GA== X-Received: by 2002:a05:6402:5513:b0:43a:b866:b9ab with SMTP id fi19-20020a056402551300b0043ab866b9abmr50105680edb.290.1658307053839; Wed, 20 Jul 2022 01:50:53 -0700 (PDT) Received: from stitch.. (80.71.140.73.ipv4.parknet.dk. [80.71.140.73]) by smtp.gmail.com with ESMTPSA id i29-20020a0564020f1d00b0042617ba638esm11975492eda.24.2022.07.20.01.50.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 01:50:53 -0700 (PDT) From: Emil Renner Berthing To: kernel-team@lists.ubuntu.com Subject: [SRU][J/allwinner-5.17][J/starfive-5.17][PATCH 1/1] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() Date: Wed, 20 Jul 2022 10:50:51 +0200 Message-Id: <20220720085051.1552907-2-emil.renner.berthing@canonical.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220720085051.1552907-1-emil.renner.berthing@canonical.com> References: <20220720085051.1552907-1-emil.renner.berthing@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Anup Patel BugLink: https://bugs.launchpad.net/bugs/1980594 The kvm_riscv_check_vcpu_requests() is called with SRCU read lock held and for KVM_REQ_SLEEP request it will block the VCPU without releasing SRCU read lock. This causes KVM ioctls (such as KVM_IOEVENTFD) from other VCPUs of the same Guest/VM to hang/deadlock if there is any synchronize_srcu() or synchronize_srcu_expedited() in the path. To fix the above in kvm_riscv_check_vcpu_requests(), we should do SRCU read unlock before blocking the VCPU and do SRCU read lock after VCPU wakeup. Fixes: cce69aff689e ("RISC-V: KVM: Implement VCPU interrupts and requests handling") Reported-by: Bin Meng Signed-off-by: Anup Patel Reviewed-by: Atish Patra Tested-by: Heinrich Schuchardt Tested-by: Bin Meng Signed-off-by: Anup Patel (cherry picked from commit be82abe6a76ba8e76f25312566182b0f13c4fbf9) Signed-off-by: Emil Renner Berthing --- arch/riscv/kvm/vcpu.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index aad430668bb4..0985a19ca67e 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -673,9 +673,11 @@ static void kvm_riscv_check_vcpu_requests(struct kvm_vcpu *vcpu) if (kvm_request_pending(vcpu)) { if (kvm_check_request(KVM_REQ_SLEEP, vcpu)) { + kvm_vcpu_srcu_read_unlock(vcpu); rcuwait_wait_event(wait, (!vcpu->arch.power_off) && (!vcpu->arch.pause), TASK_INTERRUPTIBLE); + kvm_vcpu_srcu_read_lock(vcpu); if (vcpu->arch.power_off || vcpu->arch.pause) { /*