From patchwork Fri Jul 29 09:16:32 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: 1661936 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=NrptkMG+; 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 4LvMN04JsKz9sGv for ; Fri, 29 Jul 2022 19:16:47 +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 1oHM6p-0001Ab-BI; Fri, 29 Jul 2022 09:16:39 +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 1oHM6m-00019s-Kh for kernel-team@lists.ubuntu.com; Fri, 29 Jul 2022 09:16:36 +0000 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) (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 5FE213F11F for ; Fri, 29 Jul 2022 09:16:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1659086196; bh=fzy2hlL0KOcIkVU4rWOIiWZkfRLhwKIUB20gM4tsIfc=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=NrptkMG+OgwKbiUSTajdkPNL9OCnoRrhTHvr2pJxeF3cQ6yBmsFl8qtB5y1KJmcr2 qN7fizu36NvX5XQ7kodWfNTXYja13dZ7B1Os/KygBmfvNojFb1lm9Iu+pq2bfqpgfr /xxznFXeph1zKi28A+lacYfcrM7ZI8Z0dobKDXgLajXWfbzkFr/Z4lQW9zIY630GQP 4awAZ+jrG/hBxXXiM3XgDjp2jh7cFdK9HNdUStKeqSDcb4MF+TsIDxU+SbC7EQHvVK A5qWyEUfagJyPelGUij4v6lcPd+QcU+PsYgh1bHyrFqWHNjS2SvsbWJ0xdkaZUiFhn L/7z6Y4s1OdLQ== Received: by mail-wm1-f71.google.com with SMTP id x17-20020a05600c21d100b003a32dda6577so702821wmj.7 for ; Fri, 29 Jul 2022 02:16:36 -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=fzy2hlL0KOcIkVU4rWOIiWZkfRLhwKIUB20gM4tsIfc=; b=IjfOEAx8WwcamZl4lRhVbgJlnTWkuxyPaSgNy4rhnSfpJ0vu2PoXH0pEkAl+VmjohR UzpKk8bjeWfLtcseG/jabDCY+iQvXhkt4vkCDm9AKLvV0WOxON73Eqna2AVvoCLd++q+ bmRP141zS9ry4LSqEL7NHkq422iZZHh8S6m7O9+C5HspAE8+aKCvfX84LxpyYBKElarz D3DK/7Ro33E+hfsGRs8CAyGzC7jilh0js+X3Pm5kBHRWV34kff0y/Sx0fLufp8DDfsUV LJrOSYA2/mVk2uCCKWqHpVLckcbK0ZLE0vN25tWVtJGu/rq6oygCIBYCd1BV/dPRQe9F xb1A== X-Gm-Message-State: ACgBeo39cS+9u4KZrMydRNhHMOnWhTdApLtdYCVJH86WhplwNxYdHGMb axvMgWi/HdufAHmM0VPylUwLsb0rSEuC5rA4GE1jpvXyTk+9yOiI5flpo4iHim8JWNEXUgsyKUa w8H+KMCl1lRwSsyJAVTgsErMgkxf304Gxx23aPR1xlg== X-Received: by 2002:a5d:6a8d:0:b0:21f:af3:c1be with SMTP id s13-20020a5d6a8d000000b0021f0af3c1bemr1726093wru.313.1659086195569; Fri, 29 Jul 2022 02:16:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR5276lfOK05fN6dK6T4tAfg7U9M+YkhCnv3tLOllWNUi+E04wRb/5BANYrePYoY8Xdt4yRC0g== X-Received: by 2002:a5d:6a8d:0:b0:21f:af3:c1be with SMTP id s13-20020a5d6a8d000000b0021f0af3c1bemr1726073wru.313.1659086195232; Fri, 29 Jul 2022 02:16:35 -0700 (PDT) Received: from stitch.. (80.71.140.73.ipv4.parknet.dk. [80.71.140.73]) by smtp.gmail.com with ESMTPSA id c19-20020a05600c0a5300b003a32251c3f0sm3902252wmq.33.2022.07.29.02.16.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Jul 2022 02:16:34 -0700 (PDT) From: Emil Renner Berthing To: kernel-team@lists.ubuntu.com Subject: [SRU][J/allwinner-5.17][J/starfive-5.17][PATCH v2 1/1] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() Date: Fri, 29 Jul 2022 11:16:32 +0200 Message-Id: <20220729091632.777999-2-emil.renner.berthing@canonical.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220729091632.777999-1-emil.renner.berthing@canonical.com> References: <20220729091632.777999-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 (backported from commit be82abe6a76ba8e76f25312566182b0f13c4fbf9) [esmil: open code the srcu lock/unlock that now has static inline wrappers] Signed-off-by: Emil Renner Berthing Acked-by: Stefan Bader Acked-by: Kleber Sacilotto de Souza --- 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..5c00a6526dca 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)) { + srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); rcuwait_wait_event(wait, (!vcpu->arch.power_off) && (!vcpu->arch.pause), TASK_INTERRUPTIBLE); + vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); if (vcpu->arch.power_off || vcpu->arch.pause) { /*