Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp2702184imw; Sun, 10 Jul 2022 13:04:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t2mymUab0H0b6QxiFJm0Yv2bM3gfhWgm3+nq9ArCeqa+YaK2tweXyOWKn+py0xeFtNIFMg X-Received: by 2002:a17:902:dacd:b0:16c:396a:7785 with SMTP id q13-20020a170902dacd00b0016c396a7785mr6568596plx.168.1657483491823; Sun, 10 Jul 2022 13:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657483491; cv=none; d=google.com; s=arc-20160816; b=U0ckZwoC3HvDExCpc5vgwKrmC17Kef9R03Pju9EhDvtvYye48Yrc9SCaHn4PHLAvSY pIBNcfuHxZtVbAtoWViFx498EIyu/UsZkY0UJ/dB+BFTvpsMyMSE9Fx6Fgftc4v4+8Mq q7+KXADXJtSxv5dhQMYmeOAizQwwsPdo+dhAXnC7XOMnibVSZqBekYMtAywnfU5Z5W25 dVcmPoyDSJo1zFQqVYB1+u1QPjHXNuQhJhbMeCjNxobhaqP0iVJeZNF9EXbTjskHqgOk a3/KL5Q77a58PD7vxZ05z5my1pO/gnpw2u+cHqpFu8WfqvTEF1UmmYEM1n+ypu5nvpa6 6sAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=AU84a54LMQtAp4Bbn2Cb/ADxUGGKmX/FMvyOTlD3ev0=; b=PdFAQ7mL8HiPyl9UnX88QJESTBjZDcswOsH4CU3yfPo9RhuTLDArz+byF8o734Wc7s xC8eRKLXGmQWTrrtI0VbQ1xrfCyFE4mlq3HIRX+1GhIXCFBZmGh21I7S5A339tGQZ8y7 mvmF3KetgD02k95W1Q8bDfuV4r4qmHb0aT2K0zGdeu8pOqo0Rbx4dIaf9fwNpyZuUcNi S4fpX0POnq6mY9vwNZcPbKCZbcRmYo1dV3RoraHi8sNWAXKUfyq1fKH0XqHU3vtApPX3 FZ/+k0KfXKOreQlUUGZt95pL4G8NB7SnZswQSP8ApwbiF69HRbkgcZmFrTqSZSgyrVfL Gthg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=R38ZHDBH; 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=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b15-20020a056a00114f00b00522c3a00ee9si7970382pfm.270.2022.07.10.13.04.38; Sun, 10 Jul 2022 13:04:51 -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=@canonical.com header.s=20210705 header.b=R38ZHDBH; 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=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229592AbiGJTGE (ORCPT + 99 others); Sun, 10 Jul 2022 15:06:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51914 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbiGJTGD (ORCPT ); Sun, 10 Jul 2022 15:06:03 -0400 Received: from smtp-relay-internal-1.canonical.com (smtp-relay-internal-1.canonical.com [185.125.188.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B107A11C07 for ; Sun, 10 Jul 2022 12:06:01 -0700 (PDT) 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-1.canonical.com (Postfix) with ESMTPS id 517AD3F0BE for ; Sun, 10 Jul 2022 19:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1657479959; bh=AU84a54LMQtAp4Bbn2Cb/ADxUGGKmX/FMvyOTlD3ev0=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=R38ZHDBHtKWLd/c1tZ9xKRb0xBTnMS3JGZdidMJ9IVC+yzbes3diVbMUhdtEQpXYH SL6QmBUmuHwIjbEhfQBfRdOrFyZ4RDbahBH313tUX7Ydz5POxjYOW6SsHgQTJufk0Z YsK5WI7V9IbfVA6xg2CgaoQLirl4O/qUxORtMqx247Y0D+vj28qHhcuhiHVFo/d+Mp 8AhiNGzSrCoEU+eVeknNcCWviz35vDfTjqRglUYoemI3OrrA1Zr78X1EIwr9nx9LWs CU5w9H4DbSw4u1x9M1OyXg1XJlcWi380A1q2cjr52Eoa2/fNsw2Q7gJj7mVOPrrMTP LWOpJxZLj3MjQ== Received: by mail-wm1-f71.google.com with SMTP id f16-20020a1c6a10000000b003a2d92ab4d8so1608378wmc.7 for ; Sun, 10 Jul 2022 12:05:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :to:cc:references:content-language:from:in-reply-to :content-transfer-encoding; bh=AU84a54LMQtAp4Bbn2Cb/ADxUGGKmX/FMvyOTlD3ev0=; b=r91LAa5zLOu+bGOKwfbFGEglbIbVP+lzr/bAhMDWGpL6C0PMzbZp9FxELnp/n6Rad/ 1ucpus2r58o68pWjs2pnMy6thFmz2J4uhtVXRGYSb9ZTgLXAqFj2u8IUP2DaMwzOaSeo x1EIDeoPo/ltfEoyFExCwk28UyXLTpsdzn1L4To683mlLGXTvmJVlGClXXqAV2Ci2mL0 Od7q49pDH+P09QqI0pHc5AA2DgJBGe8bqw3hC1r5IyOPZ9QrX538pxMdvTRLErTevR26 NbiOI03NQUcyU3vIrwhJ6jnqoLrAiV2iTPhCcKf+NNs85fvp2z8ODK28n0+SN5Sh8179 Z86A== X-Gm-Message-State: AJIora/EAkZHxtyqCKND3k4r4eDCENPDMaPowlPcyDgqgJHLsLFPnoT6 SsT2eS/1hTW/j4Fpu7RHoIspDG2kzFJMXVOJ4rz/e77LkLWKCF7JDpzJ8gDrGNjoOQFEUj3u8Ba 3eM9bLmqtE9Tol4GcHfeaJ3xaUsBaKmNxlSLU247hzA== X-Received: by 2002:adf:9d82:0:b0:21a:3906:59cc with SMTP id p2-20020adf9d82000000b0021a390659ccmr13390630wre.289.1657479957817; Sun, 10 Jul 2022 12:05:57 -0700 (PDT) X-Received: by 2002:adf:9d82:0:b0:21a:3906:59cc with SMTP id p2-20020adf9d82000000b0021a390659ccmr13390612wre.289.1657479957561; Sun, 10 Jul 2022 12:05:57 -0700 (PDT) Received: from [192.168.123.94] (ip-062-143-094-109.um16.pools.vodafone-ip.de. [62.143.94.109]) by smtp.gmail.com with ESMTPSA id m19-20020a05600c3b1300b003a2dd0d21f0sm6889262wms.13.2022.07.10.12.05.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 10 Jul 2022 12:05:57 -0700 (PDT) Message-ID: Date: Sun, 10 Jul 2022 21:05:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.0.1 Subject: Re: [PATCH] RISC-V: KVM: Fix SRCU deadlock caused by kvm_riscv_check_vcpu_requests() To: Anup Patel Cc: Palmer Dabbelt , Paul Walmsley , Alistair Francis , Bin Meng , Anup Patel , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Atish Patra References: <20220710151105.687193-1-apatel@ventanamicro.com> Content-Language: en-US From: Heinrich Schuchardt In-Reply-To: <20220710151105.687193-1-apatel@ventanamicro.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 7/10/22 17:11, Anup Patel wrote: > 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 Thanks Anup for resolving the problem originally reported in https://lore.kernel.org/all/5df27902-9009-afb9-68d3-186fdb4e4067@canonical.com/ Thanks to Bin for his analysis. > Signed-off-by: Anup Patel With this patch applied to Linux v5.19-rc5 I am able to run U-Boot qemu-riscv64_smode_defconfig on QEMU 7.0 with qemu-system-riscv64 \ -M virt -accel kvm -m 2G -smp 2 \ -nographic \ -kernel u-boot \ -drive file=kinetic-server-cloudimg-riscv64.raw,format=raw,if=virtio \ -device virtio-net-device,netdev=eth0 \ -netdev user,id=eth0,hostfwd=tcp::8022-:22 and load files from the virtio drive. Without the patch virtio access blocks: [ +0.102462] INFO: task qemu-system-ris:1254 blocked for more than 120 seconds. [ +0.004034] Not tainted 5.19.0-rc5 #4 [ +0.001145] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. [ +0.002189] task:qemu-system-ris state:D stack: 0 pid: 1254 ppid: 1068 flags:0x00000000 [ +0.001546] Call Trace: [ +0.000389] [] schedule+0x42/0xaa [ +0.008026] [] schedule_timeout+0xa0/0xd4 [ +0.000086] [] __wait_for_common+0x9a/0x19a [ +0.000057] [] wait_for_completion+0x1a/0x22 [ +0.000053] [] __synchronize_srcu.part.0+0x78/0xce [ +0.000049] [] synchronize_srcu_expedited+0x22/0x2c [ +0.000474] [] kvm_swap_active_memslots+0x12e/0x170 [kvm] [ +0.000864] [] kvm_set_memslot+0x1e8/0x388 [kvm] [ +0.000267] [] __kvm_set_memory_region+0x134/0x2f8 [kvm] [ +0.000439] [] kvm_vm_ioctl+0x1fc/0xba0 [kvm] [ +0.000232] [] sys_ioctl+0x80/0x96 [ +0.000129] [] ret_from_syscall+0x0/0x2 Tested-by: Heinrich Schuchardt > --- > 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 b7a433c54d0f..5d271b597613 100644 > --- a/arch/riscv/kvm/vcpu.c > +++ b/arch/riscv/kvm/vcpu.c > @@ -845,9 +845,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) { > /*