Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3599958ybi; Mon, 29 Jul 2019 09:16:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvMb00liGc/F7tSjiil2WHDDUGSYbDpyDDWWOvE/L+VsPDUKjAd7VaJJsW9yIznznc8c2Q X-Received: by 2002:aa7:90d8:: with SMTP id k24mr37201673pfk.115.1564416966900; Mon, 29 Jul 2019 09:16:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564416966; cv=none; d=google.com; s=arc-20160816; b=glaOJbdQ5k30MWUPiCHaw+2vxnS8i72EsdJP5OWSTgC3wuPkYq2o7Nt6dSk94SoqN5 WGXpSLiRRDqZu6GwPw0hEOpRTGLMumnlzsBXLDNQJqEM1mUnzQRGme+WCJ52xOJaeY73 9oIHaBedQYhjHiK68n5j2Rccqny3Sh4aXuEgPcKQTEuHn0M3H3Q86vSU3hQiC9VA74p+ R8BxPtUetev1fShOBTdKkEjCKMRSvRa7GERGJccVOzXaNsJ/GMHAeMostdmmcKNroJ5Q xYzKxr6tDp6zBclnZf4GSN6w6cWAeYdN9x6YYU8QBZi9UwLv0KPZ4uVlzRHfHZk9soGR jFdg== 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=DoNqX8RWU8p5wa0hRf4mpfQk5+CoY4k3BggOB+rTukY=; b=wpZduD7PcPgjYReGVTQ+5gIOoAERGBFAar8erx05fjH5sfOpRuWDjrPNP8gz5EpGcu jcNNpWCVmwJteY3lKeY1AbUheM8mTys0YsMWGZ+bzK3dyDlheTk76jGHrWDmKAYdh8ob VGkep5lr4wOkz6n7nghlbrf4RZm+VPG/ePtlmFBMZlxbf7r7Bipdl/HSPwczZdXVSVpA LotchI6iJoP5kHQNclEZWmu4j9MC/wKcDHCmpPWZ67PMOnRqztiATebc5bkid6WLmmCQ tKyFofeJM5CfwkZKF/Bpt/AOpsRXi6XmsGcs3tQWJUVJnFxXPU3RcVkGRC1kPrIjlUtX TADA== 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 1si6857511plz.351.2019.07.29.09.15.50; Mon, 29 Jul 2019 09:16:06 -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 S2387519AbfG2Oot (ORCPT + 99 others); Mon, 29 Jul 2019 10:44:49 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:45737 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387397AbfG2Oos (ORCPT ); Mon, 29 Jul 2019 10:44:48 -0400 Received: by mail-qt1-f194.google.com with SMTP id x22so54978045qtp.12 for ; Mon, 29 Jul 2019 07:44:48 -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=DoNqX8RWU8p5wa0hRf4mpfQk5+CoY4k3BggOB+rTukY=; b=sHqzXq5PwHZtuIuw1ukIGo+fe5NMbOu4SUFXjrLVOkqDRyz+N1r2gvvQwqP2IkRv1E Rvn4w9kvoTBHkfi/bl88E2hHZntCzB7jyv92IaxxswoIavDJUGmuYthQQCKOKiFjtG0/ iwo+qxbRfIT3aHFaiDcKAJv4L6Vg6AriQIWxP2zdrzt9Bvb5J4h0hYvTDXegE0px5XCE FF/ZTbUxTQmJ58sXkkwnMLeD0GLihhx69BJLhggC92Q7+b5f2V1xa76rDhZ6cJ5EmMmY vClELkDdYBVvl5u5vq+wtXJ2/znFJMieta44MMO6M5vhCA40CvApBj3rPBzrD9Ti7UEC OtAQ== X-Gm-Message-State: APjAAAVV6Z/68d8luxI0kDlL8hBz7Ja+nuG9tRI0yXbg34C22JZZV62x XcNflgvRNVS7VlSzDzBBWSGQAg== X-Received: by 2002:ac8:384c:: with SMTP id r12mr77572808qtb.153.1564411487834; Mon, 29 Jul 2019 07:44:47 -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 h40sm35464987qth.4.2019.07.29.07.44.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 07:44:46 -0700 (PDT) Date: Mon, 29 Jul 2019 10:44:38 -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: <20190729104028-mutt-send-email-mst@kernel.org> References: <11802a8a-ce41-f427-63d5-b6a4cf96bb3f@redhat.com> <20190726074644-mutt-send-email-mst@kernel.org> <5cc94f15-b229-a290-55f3-8295266edb2b@redhat.com> <20190726082837-mutt-send-email-mst@kernel.org> <20190726094756-mutt-send-email-mst@kernel.org> <0792ee09-b4b7-673c-2251-e5e0ce0fbe32@redhat.com> <20190729045127-mutt-send-email-mst@kernel.org> <4d43c094-44ed-dbac-b863-48fc3d754378@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <4d43c094-44ed-dbac-b863-48fc3d754378@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 29, 2019 at 10:24:43PM +0800, Jason Wang wrote: > > On 2019/7/29 下午4:59, Michael S. Tsirkin wrote: > > On Mon, Jul 29, 2019 at 01:54:49PM +0800, Jason Wang wrote: > > > On 2019/7/26 下午9:49, Michael S. Tsirkin wrote: > > > > > > Ok, let me retry if necessary (but I do remember I end up with deadlocks > > > > > > last try). > > > > > Ok, I play a little with this. And it works so far. Will do more testing > > > > > tomorrow. > > > > > > > > > > One reason could be I switch to use get_user_pages_fast() to > > > > > __get_user_pages_fast() which doesn't need mmap_sem. > > > > > > > > > > Thanks > > > > OK that sounds good. If we also set a flag to make > > > > vhost_exceeds_weight exit, then I think it will be all good. > > > > > > After some experiments, I came up two methods: > > > > > > 1) switch to use vq->mutex, then we must take the vq lock during range > > > checking (but I don't see obvious slowdown for 16vcpus + 16queues). Setting > > > flags during weight check should work but it still can't address the worst > > > case: wait for the page to be swapped in. Is this acceptable? > > > > > > 2) using current RCU but replace synchronize_rcu() with vhost_work_flush(). > > > The worst case is the same as 1) but we can check range without holding any > > > locks. > > > > > > Which one did you prefer? > > > > > > Thanks > > I would rather we start with 1 and switch to 2 after we > > can show some gain. > > > > But the worst case needs to be addressed. > > > Yes. > > > > How about sending a signal to > > the vhost thread? We will need to fix up error handling (I think that > > at the moment it will error out in that case, handling this as EFAULT - > > and we don't want to drop packets if we can help it, and surely not > > enter any error states. In particular it might be especially tricky if > > we wrote into userspace memory and are now trying to log the write. > > I guess we can disable the optimization if log is enabled?). > > > This may work but requires a lot of changes. I agree. > And actually it's the price of > using vq mutex. Not sure what's meant here. > Actually, the critical section should be rather small, e.g > just inside memory accessors. Also true. > > I wonder whether or not just do synchronize our self like: > > static void inline vhost_inc_vq_ref(struct vhost_virtqueue *vq) > { >         int ref = READ_ONCE(vq->ref); > >         WRITE_ONCE(vq->ref, ref + 1); > smp_rmb(); > } > > static void inline vhost_dec_vq_ref(struct vhost_virtqueue *vq) > { >         int ref = READ_ONCE(vq->ref); > > smp_wmb(); >         WRITE_ONCE(vq->ref, ref - 1); > } > > static void inline vhost_wait_for_ref(struct vhost_virtqueue *vq) > { >         while (READ_ONCE(vq->ref)); > mb(); > } Looks good but I'd like to think of a strategy/existing lock that let us block properly as opposed to spinning, that would be more friendly to e.g. the realtime patch. > > Or using smp_load_acquire()/smp_store_release() instead? > > Thanks These are cheaper on x86, yes. > >