Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp11063012ybi; Thu, 25 Jul 2019 09:19:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqxWDM1MRRP5TwqD+w9FVQiDB52gVvUPJo3fvmnDYZ/iCcamYH3IICehO1ewkpqvAtidcTEn X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr41746520pju.63.1564071540491; Thu, 25 Jul 2019 09:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564071540; cv=none; d=google.com; s=arc-20160816; b=RkGlRs7/DXF6VPgKIgid9ZPP1ToAd7cf795q+4q5KqaNnb7y+Qs2ZsMkRlWlK4eiLU q/CDRFhAS0JmXd4EjpqcIzr5tWBGucnyakNLcXVGdABTAPQ6zmA6ISbD0ncqc2yT5pmA Cd0nLIBDcERHw/IGeYxMg0VOIIedG+vMPjO4Au+pqn7BQed0Tdsyw9MwngdCIKIUdL3B TxwbaoPY9QS6ka0P0Xep+lK8i4vGd6LP8v9y2CoXuDooFJj8Ht+MdHU2nYctsHWlE4U1 Eu//R9+wuHLOWNAzkHwXJXMl6mFJKQqcfiMUUrLKMxuQHHdVdWKfQZf+xEuBzJjHhJYR B0EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=acAUfxbZ2yCJCgOcrOJ/SiLQh/4Iw8FfpHBr0uZv6Bc=; b=P9i2pgc4Y4sgpv2azKvYfVZxFplpeIn09X3zOYu6170z5x+VnY8JWMzbCLPWaxcn2x bGsRFDxKJoistvUZn4DR3sTrvwh82I+R6ibh0Pc3MrlOBjqGqsgxfvXzS14bXcDlZpn9 0TsU895N4rhz/RuBISSTCy9zN0k8zD7L3IOzEzGDMn44LVnW03VdBgMSrSl9lDjd6M5r snJZfs2bPk3dcmhff+fx/tJgRsFW4jaXiSKRTBeVxytWgMp+2VOjKag9LoXIo2GZPfVm JlaXffcpIfwYw8tjmn8vw33/7l/fhj3rUGuWOOLrGNpdFGyq9PN4ER4WJZPt5KizB2KP 8Amw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v13si18921905pfe.217.2019.07.25.09.18.39; Thu, 25 Jul 2019 09:19:00 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388243AbfGYHoX (ORCPT + 99 others); Thu, 25 Jul 2019 03:44:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45586 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388193AbfGYHoX (ORCPT ); Thu, 25 Jul 2019 03:44:23 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD73530917AF; Thu, 25 Jul 2019 07:44:21 +0000 (UTC) Received: from [10.72.12.18] (ovpn-12-18.pek2.redhat.com [10.72.12.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id B998060852; Thu, 25 Jul 2019 07:44:04 +0000 (UTC) Subject: Re: WARNING in __mmdrop To: "Michael S. Tsirkin" Cc: syzbot , aarcange@redhat.com, akpm@linux-foundation.org, christian@brauner.io, davem@davemloft.net, ebiederm@xmission.com, elena.reshetova@intel.com, guro@fb.com, hch@infradead.org, james.bottomley@hansenpartnership.com, jglisse@redhat.com, keescook@chromium.org, ldv@altlinux.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-parisc@vger.kernel.org, luto@amacapital.net, mhocko@suse.com, mingo@kernel.org, namit@vmware.com, peterz@infradead.org, syzkaller-bugs@googlegroups.com, viro@zeniv.linux.org.uk, wad@chromium.org References: <20190722040230-mutt-send-email-mst@kernel.org> <4bd2ff78-6871-55f2-44dc-0982ffef3337@redhat.com> <20190723010019-mutt-send-email-mst@kernel.org> <20190723032024-mutt-send-email-mst@kernel.org> <1d14de4d-0133-1614-9f64-3ded381de04e@redhat.com> <20190723035725-mutt-send-email-mst@kernel.org> <3f4178f1-0d71-e032-0f1f-802428ceca59@redhat.com> <20190723051828-mutt-send-email-mst@kernel.org> <20190725012149-mutt-send-email-mst@kernel.org> From: Jason Wang Message-ID: <55e8930c-2695-365f-a07b-3ad169654d28@redhat.com> Date: Thu, 25 Jul 2019 15:43:41 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: <20190725012149-mutt-send-email-mst@kernel.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 25 Jul 2019 07:44:22 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/7/25 下午1:52, Michael S. Tsirkin wrote: > On Tue, Jul 23, 2019 at 09:31:35PM +0800, Jason Wang wrote: >> On 2019/7/23 下午5:26, Michael S. Tsirkin wrote: >>> On Tue, Jul 23, 2019 at 04:49:01PM +0800, Jason Wang wrote: >>>> On 2019/7/23 下午4:10, Michael S. Tsirkin wrote: >>>>> On Tue, Jul 23, 2019 at 03:53:06PM +0800, Jason Wang wrote: >>>>>> On 2019/7/23 下午3:23, Michael S. Tsirkin wrote: >>>>>>>>> Really let's just use kfree_rcu. It's way cleaner: fire and forget. >>>>>>>> Looks not, you need rate limit the fire as you've figured out? >>>>>>> See the discussion that followed. Basically no, it's good enough >>>>>>> already and is only going to be better. >>>>>>> >>>>>>>> And in fact, >>>>>>>> the synchronization is not even needed, does it help if I leave a comment to >>>>>>>> explain? >>>>>>> Let's try to figure it out in the mail first. I'm pretty sure the >>>>>>> current logic is wrong. >>>>>> Here is what the code what to achieve: >>>>>> >>>>>> - The map was protected by RCU >>>>>> >>>>>> - Writers are: MMU notifier invalidation callbacks, file operations (ioctls >>>>>> etc), meta_prefetch (datapath) >>>>>> >>>>>> - Readers are: memory accessor >>>>>> >>>>>> Writer are synchronized through mmu_lock. RCU is used to synchronized >>>>>> between writers and readers. >>>>>> >>>>>> The synchronize_rcu() in vhost_reset_vq_maps() was used to synchronized it >>>>>> with readers (memory accessors) in the path of file operations. But in this >>>>>> case, vq->mutex was already held, this means it has been serialized with >>>>>> memory accessor. That's why I think it could be removed safely. >>>>>> >>>>>> Anything I miss here? >>>>>> >>>>> So invalidate callbacks need to reset the map, and they do >>>>> not have vq mutex. How can they do this and free >>>>> the map safely? They need synchronize_rcu or kfree_rcu right? >>>> Invalidation callbacks need but file operations (e.g ioctl) not. >>>> >>>> >>>>> And I worry somewhat that synchronize_rcu in an MMU notifier >>>>> is a problem, MMU notifiers are supposed to be quick: >>>> Looks not, since it can allow to be blocked and lots of driver depends on >>>> this. (E.g mmu_notifier_range_blockable()). >>> Right, they can block. So why don't we take a VQ mutex and be >>> done with it then? No RCU tricks. >> >> This is how I want to go with RFC and V1. But I end up with deadlock between >> vq locks and some MM internal locks. So I decide to use RCU which is 100% >> under the control of vhost. >> >> Thanks > And I guess the deadlock is because GUP is taking mmu locks which are > taken on mmu notifier path, right? Yes, but it's not the only lock. I don't remember the details, but I can confirm I meet issues with one or two other locks. > How about we add a seqlock and take > that in invalidate callbacks? We can then drop the VQ lock before GUP, > and take it again immediately after. > > something like > if (!vq_meta_mapped(vq)) { > vq_meta_setup(&uaddrs); > mutex_unlock(vq->mutex) > vq_meta_map(&uaddrs); The problem is the vq address could be changed at this time. > mutex_lock(vq->mutex) > > /* recheck both sock->private_data and seqlock count. */ > if changed - bail out > } > > And also requires that VQ uaddrs is defined like this: > - writers must have both vq mutex and dev mutex > - readers must have either vq mutex or dev mutex > > > That's a big change though. For now, how about switching to a per-vq SRCU? > That is only a little bit more expensive than RCU, and we > can use synchronize_srcu_expedited. > Consider we switch to use kfree_rcu(), what's the advantage of per-vq SRCU? Thanks