From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E4FEC76190 for ; Tue, 23 Jul 2019 15:02:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30B4C2239F for ; Tue, 23 Jul 2019 15:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388479AbfGWPCs (ORCPT ); Tue, 23 Jul 2019 11:02:48 -0400 Received: from mail-qk1-f196.google.com ([209.85.222.196]:42529 "EHLO mail-qk1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731767AbfGWPCr (ORCPT ); Tue, 23 Jul 2019 11:02:47 -0400 Received: by mail-qk1-f196.google.com with SMTP id 201so31338319qkm.9 for ; Tue, 23 Jul 2019 08:02:47 -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=R5M2K4AjBjzXbSZ/zP6imFgwCWLsiDqliCyMwtU6WVA=; b=RnrVNYjc9EZqbQaFVBv6rJwc53LqwPqd/iPqRmFLJatvZx0XRk2T35J8b57B5xaN3l zrn6cXLd5+2FG68slrWyFwD44mU8bBxaAiatCW+MD9WymJUwPE+A+HJQSXHOe6RhqG/H tX+QtVKzQygKFOb7YutNVt8hpLt4PHSYxG5ZF6DwW7g0KVFymZZcgYyylIS6yLRUgGdZ ei429QZFQUYxU3yNZ5xQvG+GjG2OWwSPdWGPSweN+d4oS1ESZhGhmY+jw427echlCBV9 Yg5ezInUAErkPgIU6Lw1tsY//CXFan1yZEE7Vp8dn7YgL9NXDnNB7YH7MLtj82V1ph+R nk7Q== X-Gm-Message-State: APjAAAUpIvpLMWiZTqvS4tw1G71s4h07s82wnTfeyU3mZkP71QW2rmqL 1YxM2uQ68vywAiP0boAfPyW7Lw== X-Google-Smtp-Source: APXvYqxzk6SWsTdinjKSsA/de1iMdf+1ZzQW/oUQt2F/o3dsQk8ga4tD5zxAx4DzheYaNy643xaKrA== X-Received: by 2002:ae9:e20c:: with SMTP id c12mr49989037qkc.210.1563894166621; Tue, 23 Jul 2019 08:02:46 -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 s25sm18898787qkm.130.2019.07.23.08.02.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 23 Jul 2019 08:02:45 -0700 (PDT) Date: Tue, 23 Jul 2019 11:02:37 -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: <20190723110219-mutt-send-email-mst@kernel.org> References: <20190721044615-mutt-send-email-mst@kernel.org> <75c43998-3a1c-676f-99ff-3d04663c3fcc@redhat.com> <20190722035657-mutt-send-email-mst@kernel.org> <20190723010156-mutt-send-email-mst@kernel.org> <124be1a2-1c53-8e65-0f06-ee2294710822@redhat.com> <20190723032800-mutt-send-email-mst@kernel.org> <20190723062221-mutt-send-email-mst@kernel.org> <9baa4214-67fd-7ad2-cbad-aadf90bbfc20@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9baa4214-67fd-7ad2-cbad-aadf90bbfc20@redhat.com> 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:34:29PM +0800, Jason Wang wrote: > > On 2019/7/23 下午6:27, Michael S. Tsirkin wrote: > > > Yes, since there could be multiple co-current invalidation requests. We need > > > count them to make sure we don't pin wrong pages. > > > > > > > > > > I also wonder about ordering. kvm has this: > > > > /* > > > > * Used to check for invalidations in progress, of the pfn that is > > > > * returned by pfn_to_pfn_prot below. > > > > */ > > > > mmu_seq = kvm->mmu_notifier_seq; > > > > /* > > > > * Ensure the read of mmu_notifier_seq isn't reordered with PTE reads in > > > > * gfn_to_pfn_prot() (which calls get_user_pages()), so that we don't > > > > * risk the page we get a reference to getting unmapped before we have a > > > > * chance to grab the mmu_lock without mmu_notifier_retry() noticing. > > > > * > > > > * This smp_rmb() pairs with the effective smp_wmb() of the combination > > > > * of the pte_unmap_unlock() after the PTE is zapped, and the > > > > * spin_lock() in kvm_mmu_notifier_invalidate_() before > > > > * mmu_notifier_seq is incremented. > > > > */ > > > > smp_rmb(); > > > > > > > > does this apply to us? Can't we use a seqlock instead so we do > > > > not need to worry? > > > I'm not familiar with kvm MMU internals, but we do everything under of > > > mmu_lock. > > > > > > Thanks > > I don't think this helps at all. > > > > There's no lock between checking the invalidate counter and > > get user pages fast within vhost_map_prefetch. So it's possible > > that get user pages fast reads PTEs speculatively before > > invalidate is read. > > > > -- > > > In vhost_map_prefetch() we do: > >         spin_lock(&vq->mmu_lock); > >         ... > >         err = -EFAULT; >         if (vq->invalidate_count) >                 goto err; > >         ... > >         npinned = __get_user_pages_fast(uaddr->uaddr, npages, >                                         uaddr->write, pages); > >         ... > >         spin_unlock(&vq->mmu_lock); > > Is this not sufficient? > > Thanks So what orders __get_user_pages_fast wrt invalidate_count read? -- MST