Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10774817ybi; Thu, 25 Jul 2019 05:05:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdj7sTVzercyzmbyFCwyieNlLmaa/JB2IX8Y6qzTF7IN0vxdkH+1U768ArkC7KizXK/ILB X-Received: by 2002:a17:902:be0a:: with SMTP id r10mr85617328pls.51.1564056308744; Thu, 25 Jul 2019 05:05:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564056308; cv=none; d=google.com; s=arc-20160816; b=gYCGjvLbGal5LpZO3z2EVDT+79IWPoYFXdSTARhEJUhrMmOtl4ycd6o91y5dvqh02E Wasr7NKomqRxZMKh2havkiDWhcRI5kY+qPkyHo3VbkZySWawoY5nCLs9ynzCJ+RvN4fB UuTb7k9uOMDUr5eQ3+C7kTE0X8D7PakmcVKn8uJD8MgJp848YZDqn34AaE0EjmFmAEXz /cZm2fLsZDv/RVldt4z8q8YLyjp4tsStN7n7PIhPmKzPy/llRbnPcTRZlI3DAvfy9jRc IlHSnekwk8maEEVJZQLFw/xM42P6DcdFqVGbMVOShUPPvcJe0Pp6CS6QEfBKMCB6BbnI 5mbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=JO71JAUQG8v5NWS9aFNJS8lKMgEFxdUfgocNmFAYG40=; b=sSyGR8x3CueUO/OAucgWipv7F/A9p9BexWIpNXnM0LocU7d9Pi+grzyWC611j28EBT lUSj/fG/XwZ6y4iVZTPfc7GOK/HwgtgEDCJpqlqbQiw9diLjsxnId+MOzc+sGw6vicsK KWiziF39jbOHmiG5KHJ9hTV5EJjj/Zyn90yaZY1wIcYSK8tueEz+BHa7vPVeboLBG3Fh 1PMp5N5UB5tx6a5N/RUM6kPKSMfhFA4XFcgJaVyl9zQ9vOn9hg62u/Nso0vPkg3UkyiV iLkw775RI6U+5fa1aF/8InqAI4z7oVWx52ihmKnFXFDx8a9XMWncTBY34wN070Du6Azs VfoQ== 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 a9si15659327plm.295.2019.07.25.05.04.53; Thu, 25 Jul 2019 05:05:08 -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 S1727962AbfGYFxL (ORCPT + 99 others); Thu, 25 Jul 2019 01:53:11 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:41156 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfGYFxD (ORCPT ); Thu, 25 Jul 2019 01:53:03 -0400 Received: by mail-qk1-f195.google.com with SMTP id v22so35578204qkj.8 for ; Wed, 24 Jul 2019 22:53:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=JO71JAUQG8v5NWS9aFNJS8lKMgEFxdUfgocNmFAYG40=; b=XrVa0fKePRdW0HQjt2Bz+x0ipygoGSct+6oqoZt4RjCn2UddSrCpB2PoToJRaM23iS tKVjz7hZ2gOypXnvjm+scD1xXVW4xo2avaK9HEpeg6jsqSqNXXSP768KbplTCOVz/M9k 96aHEKJpJdzVxbpTbD8zPI67CLIk6zJQiQrH/lHpv/wmIQFq9Em+sCmPJS7/BEaMbsl/ syTQTBxtIm2VZCifSABWJiRKOv71N8vcQcFhUu6kKZKagdLBdZYf7wUNdHmsKR/EH56d 59Qrmq/yCX6wm/FTm1M5YKubG2SIkgTxFzkXRSBik+p1lBCkcRCrYrpRf7enNgsoSFAS /LCA== X-Gm-Message-State: APjAAAXYYPjr3w6YZC5zZc9KIpqaJgORWekOve0txvuYGXUVzXbPj+fO 4zN/8o91xI+6jssPWiM704HZgQ== X-Received: by 2002:a37:91c2:: with SMTP id t185mr56548270qkd.193.1564033982538; Wed, 24 Jul 2019 22:53:02 -0700 (PDT) Received: from redhat.com (bzq-79-181-91-42.red.bezeqint.net. [79.181.91.42]) by smtp.gmail.com with ESMTPSA id p3sm33849924qta.12.2019.07.24.22.52.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 24 Jul 2019 22:53:01 -0700 (PDT) Date: Thu, 25 Jul 2019 01:52:53 -0400 From: "Michael S. Tsirkin" To: Jason Wang 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 Subject: Re: WARNING in __mmdrop Message-ID: <20190725012149-mutt-send-email-mst@kernel.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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? 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); 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. -- MST