From patchwork Wed Aug 7 06:54:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6832C13AC for ; Wed, 7 Aug 2019 06:55:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4BB362863C for ; Wed, 7 Aug 2019 06:55:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BF02288DA; Wed, 7 Aug 2019 06:55:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00BD3288DA for ; Wed, 7 Aug 2019 06:55:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D81416B000C; Wed, 7 Aug 2019 02:55:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D31E56B000D; Wed, 7 Aug 2019 02:55:05 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C21156B000E; Wed, 7 Aug 2019 02:55:05 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id AA3F46B000C for ; Wed, 7 Aug 2019 02:55:05 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id q9so2006682qtp.20 for ; Tue, 06 Aug 2019 23:55:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=tUjASA4+zAgItkGVuRA5d1D5k4PSp8myjrUvNkD8hTA=; b=XnMz2QpXlNVFNORaYOzKAUjr60+gsmbSyJYW9R7TGMEyE4x6jvir/teOMKnTRoixMp PD1Qmg8SWJRTNeEqimmUBRQApJsLw75JDQpfJcO2x8bIG4HRoHl8UC7QAIRLqGOMIDlB IADutRihuQuznObm/dnn03630wmuMKylgZzPInUO5Q8f0zWguR3bPvb+okBYcS60ZIHG ecrJgKqqijAvqmDEk8zVgIAGutE5PhM9FG/6d7UsQrbfsT2TTxkD4eJt/8Yb1UH3XuN7 Ru/Hhp3aB9wsonJ9S7Pz4eMz+tjK7vNn2cgWkR1OCbT6ahOqEFynbkEO6Y6DkxdzNzy/ PikA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUZEI9dZQfJVmap2nVev6mD47tlRDgbWYLc9LabJrYG163QUmrQ 0cXXAIwG83Bxk+ZlWHr36O32stN8ipH9KNaojI5/ht4h9d+fMs9sotBELKG5IMx0SSaSSU3g2e3 ZlfSn/5IDjCFV5uzdTRqfSkboLItwuebUuWUeUofSThBr9lxx+Hg9ubxYR2nqVTpZpQ== X-Received: by 2002:a37:6397:: with SMTP id x145mr6467493qkb.56.1565160905483; Tue, 06 Aug 2019 23:55:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwq/kTCBl39z7Gt+MFt7SeOGnp02gbJC1Kr16+jeRYGq/6M+9B1cN7bbdCTSBw7l2p4kmDD X-Received: by 2002:a37:6397:: with SMTP id x145mr6467477qkb.56.1565160904918; Tue, 06 Aug 2019 23:55:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160904; cv=none; d=google.com; s=arc-20160816; b=Kg3E8zXKbLc0b53ja4pp9ibmrKO6TZy0lVYe4NdPJsvKQG2viZxp6JCZaGru7jxGEr l8xtJcaNJC14CT/gg/B18S15UXlaagpyvLhr5bTHMQ0RUyNaZPy8hoo36mj9kkRXejDH WjnCNALSi+Cl2NlBHwb0JHWm17iQGiXrCP83PCeORDTSbBrsrIoKS4hfZkeSGscS2vUA pLk6eaopRjmdkcEMpMOOfX5NDdwI3zJrbj2qP/MT1XDHfxdBbFTz5pysIcT4lI/zYtQO kDLtm6GyhManx1RnPEvaPPuDCCd/aKaErJifTUthQewkBHnhXHdjTN/6CiQrIrY0Jnfc qzbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=tUjASA4+zAgItkGVuRA5d1D5k4PSp8myjrUvNkD8hTA=; b=nPm2k9W1+gcK6QB5w8yGB/kAzfBnNorlrAYkjNemNOCRpQ/98rDRuD1wfKSdbcIlrP Lu+nmXI2lKJXJVvw0dgO7rayqIFrIzpKx3MunESNBL02Aha4GKvuEE6wswy33Sn5/tz0 AjMnHBaj3PmvZ6IGrZwDR8o520cu3xxuN6DdDcaBhRaqEspW4oiss6VUyWtE5B3UUGf7 Otj0F7Txueedm1tYN/mMnUeAjV8CNzvGcHgGrzKeqEfmMtF8KWlOjK103P0xw+T8SLQh Rb+TuAeu69rfo9YmlcssN82UWXwFyLwh93ZJAZqf/hzxRI1vYfkym59GiY/RD7C48quK ZwyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d49si52962193qta.198.2019.08.06.23.55.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:04 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2297C9B28F; Wed, 7 Aug 2019 06:55:04 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id CB6001001281; Wed, 7 Aug 2019 06:55:01 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca Subject: [PATCH V3 01/10] vhost: disable metadata prefetch optimization Date: Wed, 7 Aug 2019 02:54:40 -0400 Message-Id: <20190807065449.23373-2-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 07 Aug 2019 06:55:04 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: "Michael S. Tsirkin" This seems to cause guest and host memory corruption. Disable for now until we get a better handle on that. Signed-off-by: Michael S. Tsirkin --- drivers/vhost/vhost.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 819296332913..42a8c2a13ab1 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -96,7 +96,7 @@ struct vhost_uaddr { }; #if defined(CONFIG_MMU_NOTIFIER) && ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE == 0 -#define VHOST_ARCH_CAN_ACCEL_UACCESS 1 +#define VHOST_ARCH_CAN_ACCEL_UACCESS 0 #else #define VHOST_ARCH_CAN_ACCEL_UACCESS 0 #endif From patchwork Wed Aug 7 06:54:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD276912 for ; Wed, 7 Aug 2019 06:55:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B8A02863C for ; Wed, 7 Aug 2019 06:55:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FC5E288C5; Wed, 7 Aug 2019 06:55:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA4862863C for ; Wed, 7 Aug 2019 06:55:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 963876B000D; Wed, 7 Aug 2019 02:55:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 914846B000E; Wed, 7 Aug 2019 02:55:09 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DBDB6B0010; Wed, 7 Aug 2019 02:55:09 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 661FC6B000D for ; Wed, 7 Aug 2019 02:55:09 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id t5so81213570qtd.21 for ; Tue, 06 Aug 2019 23:55:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=hXDPuh5Kn7pFxSlRRDrUdecWVXcCQZqbNwxxDsR27Vo=; b=rsf1jVvbxI6uTXHLPDllYhl3OxB156V90It/vz2HM8GmZkz33qGEe7Cu5fnKwFwia/ Y4PMjRIAV8pVt0nzUz+r81TJDRm/nxlg/Si92c7vIiqKK7evHsPMHiHVOrwusiTiH6cw W75k14h7e/QiTvPBaUe1HBeZXf0h95Whdv3IF+QS5o92GqA6Ea5i7y39TWDoxBA3yf0A xaJNoFoxZqLJNxeaxbozUcWx02ZV3gG5CJ4U+tYmOh4Utfi8+Ov1l74P4tkSWdzxFqva gq+TpyzMKyXtjy6qfw6vdhI37HjdtTNQjZeccc95KyjboDQ59phdvQ4Yt/8pXw2VoR+f GjMw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWZHmu38kg+CiIuIteJu/oI4l0n+sau25l73LzubJajlRbRSHye Dl4K3PTo5bQ+p/zyAf7fNSXiXe8dEN+ioor6Mbn+PBgQ300+QE2N3f1BbUDACVjLbE3HsXOUR/L ZCbe3sR2PeDZJGUz+j2Rjdx5L+QcFSasuOvMzJGsh8JsJ28gMckkPe65B3x26xjzhtA== X-Received: by 2002:ae9:ef48:: with SMTP id d69mr6766035qkg.313.1565160909230; Tue, 06 Aug 2019 23:55:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqxXmg4FbiH+rIvJMjNzRM4gcn0tc+ey7HCYQVrQzQ+xZTGT5tyRJm6qQLAI/vyea/QPLGI/ X-Received: by 2002:ae9:ef48:: with SMTP id d69mr6765993qkg.313.1565160908191; Tue, 06 Aug 2019 23:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160908; cv=none; d=google.com; s=arc-20160816; b=ugPd7vG01TobjKqD9LVhpVyDcC0HFQORh6K+fAHUQDusHsJWOQLqnqRKKT3l7+D5tb XejUt4eTQqXK8Il4e73pXjqONl5IfsrEmv3njKSru26z3Bf7E8ZdRBJhhXCyqtUCcDwb rOmeAR4qX0FcqKWWRJTML7CyfzXbVqkbb0UkNDUcfeLaVq5lSt0x4/sngqR8XztO6A0K 3Zymb4dXiJnLNEFoQWC/wRo0tDbZmYHsuiLBOv/JxvqHQqklKdmCx6ITjg7cA0xLU6q3 sMZAf8UA3m0/V3qe1Xqka3X4Xgld4YFiBYf8L/8zJFcL0ITPk1AWn8TyfnFZm90zqm0f 8fyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=hXDPuh5Kn7pFxSlRRDrUdecWVXcCQZqbNwxxDsR27Vo=; b=bPFCu1I0esEs8aHoRNBZCLHBj0ILVv0acICNeGQHz817z7O9igVWmkBS8+r6Li3IJs RWkoeNhnwgQRHvkgfOtb81Gm/GVuKNoZbLQ5sXQ3lvwq4svArPlaJrZTWu133DZgYUtv KvdNr+a2ZItSKVsJ89aoV9N7sjuS5dN0kDX1Xvn+h7Aqn6Bkp2Tzv7wqHk5nBDdyqem5 WNPmhlRWtr7KCP0JBsNdaScsIhd99OZRH2V4WCQVSu/TiOIZMf1O8ZQBxCXaNL4tbaHj Hvf5QwaddnaM2Uq8Fr9lyGLjtCMyyo8XdT/lx/DRS/Yh564E/1JPjxxwUodkL9DkDjfB gKfQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id g15si54179049qtk.184.2019.08.06.23.55.08 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:08 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6FB273DE02; Wed, 7 Aug 2019 06:55:07 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8EE3D1001281; Wed, 7 Aug 2019 06:55:04 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 02/10] vhost: don't set uaddr for invalid address Date: Wed, 7 Aug 2019 02:54:41 -0400 Message-Id: <20190807065449.23373-3-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 07 Aug 2019 06:55:07 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We should not setup uaddr for the invalid address, otherwise we may try to pin or prefetch mapping of wrong pages. Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 0536f8526359..488380a581dc 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2082,7 +2082,8 @@ static long vhost_vring_set_num_addr(struct vhost_dev *d, } #if VHOST_ARCH_CAN_ACCEL_UACCESS - vhost_setup_vq_uaddr(vq); + if (r == 0) + vhost_setup_vq_uaddr(vq); if (d->mm) mmu_notifier_register(&d->mmu_notifier, d->mm); From patchwork Wed Aug 7 06:54:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D9B6912 for ; Wed, 7 Aug 2019 06:55:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D0712863C for ; Wed, 7 Aug 2019 06:55:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 309AA288C5; Wed, 7 Aug 2019 06:55:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC4702863C for ; Wed, 7 Aug 2019 06:55:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 878CC6B000E; Wed, 7 Aug 2019 02:55:12 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7DAA46B0010; Wed, 7 Aug 2019 02:55:12 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6C8BC6B0266; Wed, 7 Aug 2019 02:55:12 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 48CE36B000E for ; Wed, 7 Aug 2019 02:55:12 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id l16so74537130qtq.16 for ; Tue, 06 Aug 2019 23:55:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=ObXb8s+P+33YOBHS71fbz/1szBcAnp4vJnFUmXXP1hc=; b=PaD67hXgCaPHUlLWg1LTMVbygMFciMBInCJUrVWQJJGHWdGEVFCikgTcKW0/TdYucR 433H8yftTk9t8uV3AC/tdIvntxYWZzWaQrFOUv+Mxlm87c1NZTyLjELblbkUFLJN3hMD CSeYfiqn6HFhqKY7+Icp4nPFni1bvQm+nH0WI5WRnSDpXU3TGxRou76MD3kO3vYOAS6b PSZOd2wErFUYs5xbYkIp4Hbgb62xkzLfNtxNdXNJ/FXyHo9X6V/8ZCYD5cGpbOKW2enl EdA6+QbtuDVHtpBqME/rCETP5sz+ClWVMo7s/ocFyaivljzk2r3tPFFme/yM+5CyRvSB fBfg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWeTXFtoOWuUa+sADho8uf+LrRXndYnPOfNP2hE0xV+DBGdJyeb 16tEmpjwDd57mEQr6Lswik8Hvdy1cztZSpYXEQYQHXQx56yrhzc71SPyex72a9mjtxJ51J6Noeb PsXlle/P+0kzm5XSIszAA8YblUpGS6Y+w1Uvqrz/Lor9zyBJOWslnhL46QxiuFjLuZg== X-Received: by 2002:a05:620a:15ce:: with SMTP id o14mr6973434qkm.30.1565160912094; Tue, 06 Aug 2019 23:55:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqyj/8vGMkYid9engB6YRdvmsfq50V9QkI8sGsIXrAjKG5ip+2Uf+x6bjZnG/CLPU/dlJfFv X-Received: by 2002:a05:620a:15ce:: with SMTP id o14mr6973397qkm.30.1565160911174; Tue, 06 Aug 2019 23:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160911; cv=none; d=google.com; s=arc-20160816; b=Aknb8ONLrngMvRA3UQc7Ht/p/KwNKbooTr0syQCH4VdQjQ/6gf/g7xOZ5yzX0QkZFF GXLpRAgN8/ZrV0sgMyCxjvjRABjthd3EsbPv0ZeZHGWKQV6CpB5ZfBfeIyuy8t4/+pWK RqzLuP1MQua6mlh/axsWQ7LHiLokC8y1CB2R3YKO+YgHyigBn/G/ygXbkH5BCI/NPzAB UxIcZpwCi7A1PEyzIkyyZdyeOpstdxZxz6CvwstOcxrqkAgE39NZCDdZZwIn/ogAGJWT rsw0sc0DhrH0kj3CXYZoovrMO9yeCwuvPS71al8TL1vVitJFktZjcB8MB94CkmZGbBIa oZ9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=ObXb8s+P+33YOBHS71fbz/1szBcAnp4vJnFUmXXP1hc=; b=dvq+JAmzQJu48SwKa//k+B4xobG4IaIKgzq4zQE7RQNPlBW28TujXwSKGxnEVEIX/A oz1T8Uv3Dz/5TjceU+xex0qge3dDCFQ09jWlo8Z/qviB4TAvx+jCheMhbVprvX/YA1Tk d5YkJ/nj+kQbjF06rZ9tDBeZa7zJvWM85663byVFyAuhoZ6l3suOTMaBVTxlrGSEYmIO fWejLz8VnWQE6jtb+7dWjbPEFKT54GMu4dYIKtBkA/Ed/0v07zCn+9QLDdLFff0OF1Kb H+4NTvvfxJ2dImtPTyqYRiHrdEUa+9Gi7koKZpedQQk0tBa9a9I9QsDmRLMc1L4AFJbP kbyQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id y2si10683055qvf.221.2019.08.06.23.55.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:11 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6EB818EA41; Wed, 7 Aug 2019 06:55:10 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2C7B10016F3; Wed, 7 Aug 2019 06:55:07 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 03/10] vhost: validate MMU notifier registration Date: Wed, 7 Aug 2019 02:54:42 -0400 Message-Id: <20190807065449.23373-4-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 07 Aug 2019 06:55:10 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The return value of mmu_notifier_register() is not checked in vhost_vring_set_num_addr(). This will cause an out of sync between mm and MMU notifier thus a double free. To solve this, introduce a boolean flag to track whether MMU notifier is registered and only do unregistering when it was true. Reported-and-tested-by: syzbot+e58112d71f77113ddb7b@syzkaller.appspotmail.com Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 19 +++++++++++++++---- drivers/vhost/vhost.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 488380a581dc..17f6abea192e 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -629,6 +629,7 @@ void vhost_dev_init(struct vhost_dev *dev, dev->iov_limit = iov_limit; dev->weight = weight; dev->byte_weight = byte_weight; + dev->has_notifier = false; init_llist_head(&dev->work_list); init_waitqueue_head(&dev->wait); INIT_LIST_HEAD(&dev->read_list); @@ -730,6 +731,7 @@ long vhost_dev_set_owner(struct vhost_dev *dev) if (err) goto err_mmu_notifier; #endif + dev->has_notifier = true; return 0; @@ -959,7 +961,11 @@ void vhost_dev_cleanup(struct vhost_dev *dev) } if (dev->mm) { #if VHOST_ARCH_CAN_ACCEL_UACCESS - mmu_notifier_unregister(&dev->mmu_notifier, dev->mm); + if (dev->has_notifier) { + mmu_notifier_unregister(&dev->mmu_notifier, + dev->mm); + dev->has_notifier = false; + } #endif mmput(dev->mm); } @@ -2064,8 +2070,10 @@ static long vhost_vring_set_num_addr(struct vhost_dev *d, /* Unregister MMU notifer to allow invalidation callback * can access vq->uaddrs[] without holding a lock. */ - if (d->mm) + if (d->has_notifier) { mmu_notifier_unregister(&d->mmu_notifier, d->mm); + d->has_notifier = false; + } vhost_uninit_vq_maps(vq); #endif @@ -2085,8 +2093,11 @@ static long vhost_vring_set_num_addr(struct vhost_dev *d, if (r == 0) vhost_setup_vq_uaddr(vq); - if (d->mm) - mmu_notifier_register(&d->mmu_notifier, d->mm); + if (d->mm) { + r = mmu_notifier_register(&d->mmu_notifier, d->mm); + if (!r) + d->has_notifier = true; + } #endif mutex_unlock(&vq->mutex); diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 42a8c2a13ab1..a9a2a93857d2 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -214,6 +214,7 @@ struct vhost_dev { int iov_limit; int weight; int byte_weight; + bool has_notifier; }; bool vhost_exceeds_weight(struct vhost_virtqueue *vq, int pkts, int total_len); From patchwork Wed Aug 7 06:54:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9DE7813AC for ; Wed, 7 Aug 2019 06:55:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CE072863C for ; Wed, 7 Aug 2019 06:55:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80A87288C5; Wed, 7 Aug 2019 06:55:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B71C2863C for ; Wed, 7 Aug 2019 06:55:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A89A6B0010; Wed, 7 Aug 2019 02:55:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 458E96B0266; Wed, 7 Aug 2019 02:55:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3477E6B0269; Wed, 7 Aug 2019 02:55:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 1CAE66B0010 for ; Wed, 7 Aug 2019 02:55:16 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id x11so76785415qto.23 for ; Tue, 06 Aug 2019 23:55:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=DkgRyBFTw1NOJeXBoWug970nIMArpHVJngzRV71MoTc=; b=a3jZ+WLt8ZpBlNDnZZXFKaNZYGuMQNG1BAwBLNRdNmmQM51d4IQ8UkhL5T+SRTx7Du 8nP+ZLTvyMt8LP5Xj/SLmvbQlZHLQun98tCInGuJ+a+eBBXxE8JgWY+bxE5mvZTpu15w PnipSKrz6+Ficx8JQGMwkiJ5zBlpnLKRr3uDKm0JjLlyqO+1DsVxeeIeLjFs3zFGxpBd frQ5QAuF7BfOHIswHev1TkHKrBB9/ihraYUg5wHB1vuGWoyoo7nVMzfmecHJm0/tdTsO ht2Aec0loTekTuADtl5xceLzzUTB90GTruERxMiEe9K1dNZGyOmhDpjGNWcaT2DXwBNd ibhg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAUhQQ15ipSXWSbyDYt3Wbb1ZFiM+OG9BzIxktTOiw7CzLzINq/I PLk1hHfA6MTRFH+6euUNR7iTlIeQdwkc636M0gkV6uRgPJ80E87G0RW81GvoBO18bl++aiRICbE l7Wzch4w11mD67Z26JWgd240u3tHWI3AxMZUNqFiLhhBQFD412M7TsgTOm8viuA7O5Q== X-Received: by 2002:ac8:538d:: with SMTP id x13mr536852qtp.223.1565160915908; Tue, 06 Aug 2019 23:55:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5j342wrRkqPrrbkCH4R3ZZRQif1FdxuSzCSPx8kjqm7QHN+OpxzP+MxTOKFFF8TDWe0Ue X-Received: by 2002:ac8:538d:: with SMTP id x13mr536819qtp.223.1565160915164; Tue, 06 Aug 2019 23:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160915; cv=none; d=google.com; s=arc-20160816; b=R6WozALoPf9CRdJoCKWKCq0QTxANpVt7OQjwNmefT6s46kMo+pLMwkeOvNbtx+iu1a Ae3Zm4e7NcuDGqldvAq7NkiffPLgOA//K7pmwhEja0pNMTu/S5xlVlehmUBhKatqB7nN q+f4iRJfNQT6EwlKg2J6+CHC0Nzib6wLjEezv2AUm+5llmq2pgxdJ0WJexRtdbiH2TK+ GW0ja5/ZRx9mz2emvaRAckydfgcRcb6nixM5Sdbbgch50dV2PQxz6F2vtnGzKck9jniR TwkkI8X8ZhYEJXOZIf1SoUcbX4J6okicH0HyQReG1H0syXsyM9NiOagDnVEK7GTuESYq gYTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=DkgRyBFTw1NOJeXBoWug970nIMArpHVJngzRV71MoTc=; b=BcuPhAgpeaUt9uBz0RqTafbc2u4NHoFfIl7bzdf0S1TnE9XqR0i4iWH9BQ1Dr6ep2Q BU9PTGXFJlAC4kjByT3IfBHZTSM0NIu6gLRAsokNLq7YX69yxmz1dd/6WHsQXKZNLp08 lpDOSTJC8mdemX1H9fvFTMIpEqQCPx7pxtL7iKovS/nQZkiSwmjvmehSOUj1wCf+VAdy jqfMr4eMemftYe5lNSt36CCPFP0R4eXdNR7L8HQMlWizJhR3/3YspfEPYjt/r/OKjW5e ksJZRADMkj80nobv3TPDuXmoR6a+F/lvHyyWuKlmCjXF7ses04NeHG78vwkP2TAOn060 Y4cA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id j94si50642014qte.116.2019.08.06.23.55.15 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:15 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6DA583066FD9; Wed, 7 Aug 2019 06:55:14 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id E10841000324; Wed, 7 Aug 2019 06:55:10 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 04/10] vhost: fix vhost map leak Date: Wed, 7 Aug 2019 02:54:43 -0400 Message-Id: <20190807065449.23373-5-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 07 Aug 2019 06:55:14 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We don't free map during vhost_map_unprefetch(). This means it could be leaked. Fixing by free the map. Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 17f6abea192e..2a3154976277 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -302,9 +302,7 @@ static void vhost_vq_meta_reset(struct vhost_dev *d) static void vhost_map_unprefetch(struct vhost_map *map) { kfree(map->pages); - map->pages = NULL; - map->npages = 0; - map->addr = NULL; + kfree(map); } static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq) From patchwork Wed Aug 7 06:54:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081125 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E351F912 for ; Wed, 7 Aug 2019 06:55:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2F4A2863C for ; Wed, 7 Aug 2019 06:55:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C728C288C5; Wed, 7 Aug 2019 06:55:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFB5E2863C for ; Wed, 7 Aug 2019 06:55:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D810E6B0269; Wed, 7 Aug 2019 02:55:23 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D324B6B026A; Wed, 7 Aug 2019 02:55:23 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C486F6B026B; Wed, 7 Aug 2019 02:55:23 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by kanga.kvack.org (Postfix) with ESMTP id A728E6B0269 for ; Wed, 7 Aug 2019 02:55:23 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id d11so78185978qkb.20 for ; Tue, 06 Aug 2019 23:55:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=xahfPfm1mZfbC4QuU9FoOa3rgOujgUARqGYj2KI+pdA=; b=KuTJ0fuuaNtfm/yilc0uTtCAUt5OrZKrIYnu5iSPxTZv17raYd/t6P3YLydiBpKhs/ zkK3K0AJDFO3mSfKgKMFI7LQTBNd1FSWKKCumpii9qRoPIEZ/Nr8sgGtEHXtGeCnSgFd 5SvJlFDq0UKVQvidTzJaOkI0SoVw+r3ngk+wmuTrf8AwUOmqILnjdgsybdVUzGcgfmHy SdKPnA9Ql7UMPWZQvUquVp29Ks7/PRHdMtTHBu5EEXCDWHZQUt46cvWx0zP7tYt2xngW F6ftWp2HpgxEQ9MbMmMtBBo1ZNYVjkdbWJxbpqdKwi12InoVkhX89NkmzLbqayMIWPuG aa6w== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAVSo9+9dPZfEqQHRtrQkHY7UQwZD1M+Bz8GrkskxdOUFMrYQgBZ Hq+TNXne44AF2xtgzhRML+DxNe86HvESoswHW/IIY1ArYCbft210BjdYb1cVP/xbF2JVDxH6qNi qTUPMzCZDNXgpikhr0rnCSNUYhr+kEbF0QPvNPFkhNQiPITLgcVs/XaQwy2Gl/Q/Low== X-Received: by 2002:a0c:b998:: with SMTP id v24mr6682173qvf.132.1565160923472; Tue, 06 Aug 2019 23:55:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqzuy8lTnViqOb89+zR9X/ClnOa7kmZiV+azpplA+j9Ut7znE2zur8rAW3b+30dVjWwDmAVd X-Received: by 2002:a0c:b998:: with SMTP id v24mr6682150qvf.132.1565160922709; Tue, 06 Aug 2019 23:55:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160922; cv=none; d=google.com; s=arc-20160816; b=FD/GBp1OkE1BdgQ0mJ87WJZsqy3aCeFwQrWI7joqECJo5VSQYKlKrMBuntWGppVyDn d0M7+/g/dbIr8lVqZKrqaHE1492wAYXXBaYg+VvTmNkpiAVq86co+mwJl92N+zN8zc0X gGyzNXLTuSG1/v6LThMuM9JVhA89ucPyY5wO7fSYzHALbN5+paBAFzKFhpi7D6IytYMG EpsrIrvF7IsjT4DKTBcFL0yXQe5V332Ydu+vmwfL8wvZ3ngzcecxRcsCns4Z5T4wVgsX 59yXriDj7JI1s8+DTN5xYs+81X1RB/0ku+/yOntVb/kUmfAhsJKCKjIMk+k5OpandBGi qLiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=xahfPfm1mZfbC4QuU9FoOa3rgOujgUARqGYj2KI+pdA=; b=bLbiOrQXzeCya3S0etx0p8tqC2SfDzIXIiMxeaFdSueAr8wsxM54TG/eZvR88kTY7/ YK6K0fkjnf9vcgVqwSUTxhDkF3KaiK7Wr/He5iwt3hcDAHppyp5ggaxXUWj1634dlXnO qhkYYHk61I7+vs6zekj21fiYMIgAwZV6x5E022zzeQZJMpH39YQlREBweqBo6keq5H+8 aBPbCI/5gD6rhiOroKw16vPVdZZrO1iYDVqWKUZKHQWleYC2cnBVvfgHw89mVqlCcPmw fWMMDGDAoWrgl0g9EFY1PLKTPdkBoPaCbk52L92X1Ws0LdpdfmiCiqhUdU5Ke5dJV7G9 pWiA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id o13si54603935qve.145.2019.08.06.23.55.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:22 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B7B0230C061C; Wed, 7 Aug 2019 06:55:21 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2503F1000324; Wed, 7 Aug 2019 06:55:14 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 05/10] vhost: reset invalidate_count in vhost_set_vring_num_addr() Date: Wed, 7 Aug 2019 02:54:44 -0400 Message-Id: <20190807065449.23373-6-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 07 Aug 2019 06:55:21 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP The vhost_set_vring_num_addr() could be called in the middle of invalidate_range_start() and invalidate_range_end(). If we don't reset invalidate_count after the un-registering of MMU notifier, the invalidate_cont will run out of sync (e.g never reach zero). This will in fact disable the fast accessor path. Fixing by reset the count to zero. Reported-by: Michael S. Tsirkin Reported-by: Jason Gunthorpe Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 2a3154976277..2a7217c33668 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2073,6 +2073,10 @@ static long vhost_vring_set_num_addr(struct vhost_dev *d, d->has_notifier = false; } + /* reset invalidate_count in case we are in the middle of + * invalidate_start() and invalidate_end(). + */ + vq->invalidate_count = 0; vhost_uninit_vq_maps(vq); #endif From patchwork Wed Aug 7 06:54:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 45E7A13AC for ; Wed, 7 Aug 2019 06:55:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 33C8E2863C for ; Wed, 7 Aug 2019 06:55:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2852D288C5; Wed, 7 Aug 2019 06:55:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD6D82863C for ; Wed, 7 Aug 2019 06:55:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89FA96B026A; Wed, 7 Aug 2019 02:55:26 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 851166B026B; Wed, 7 Aug 2019 02:55:26 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 717EC6B026C; Wed, 7 Aug 2019 02:55:26 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by kanga.kvack.org (Postfix) with ESMTP id 4FC386B026A for ; Wed, 7 Aug 2019 02:55:26 -0400 (EDT) Received: by mail-qt1-f199.google.com with SMTP id d26so81432795qte.19 for ; Tue, 06 Aug 2019 23:55:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=JzO6kN8vx263crDqN9GLB46XC0hjzWSfPRcXHfgmC3U=; b=mgRPV6/ONCxkWqtXXUqSEJ0gz6PoYsrIKS/dEUPIGvDtI/vTq00JTpxYAtgNozqa0R efMy9ZyxXqYbC6jjVjTvElUNVLAuDPVPOZ7by6+xD6N/6dAiNUsOJDNuXAhkyxOWLoTO ebJhujLVwEZxwKoE4bI+RL0dTfKqZJ44j9Q6soCkkfdIutrsD3vUlqm57Vv5P4QN+INL ntNfV2eY02C7O85z2nq3KMK2RRIRy47lJobFYjIpZ4R4PtCEqYWysJ8xbcLrIE/ejREB vV32tLYgBNvMc9REZvFw7pxZiquUIQ71KUQbhumIlregUICdjgu+tOyLfet56+njmgeW YlMw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAX78C4kcr/FtRxjV5Il83sO+RN71nJipVC6sBE7Q8eeCFW6P0z/ XR6aFKhzDM1VHS+u+fvuMFUksVOm08a/BRQPL7nFVS8C4cbPiNTOot4XIkqTIDveL9sw509sab9 a0sV9NmEOj4tO9J4Y3pDPhvGT2Vf18lNgJDIAWdY5nX+nw16NLNGKv+HW2F2M1BFgug== X-Received: by 2002:aed:3aaa:: with SMTP id o39mr6808933qte.146.1565160926127; Tue, 06 Aug 2019 23:55:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqx7yQEcyyM+QjDBUj8essh1KQn0vDcWU/cxU6zz4unjNsfkNKuAz0JIwThodzZs/s0q4aNa X-Received: by 2002:aed:3aaa:: with SMTP id o39mr6808904qte.146.1565160925432; Tue, 06 Aug 2019 23:55:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160925; cv=none; d=google.com; s=arc-20160816; b=qakpZg7l/wvRw/H5uAo8uteHyXx1Hgo4Rw6ztt+WZOH9u5ymqm8ANtp5JKMKXLcDzg /uFV3BT3QS98WmFg/Jnz3FC6O7ns/tlJOA1z1bfY63rahPMydMckNgbre5EIk/njF/ts tWBaBnZcUb8v+jcO+a4eG4K5J7gytZzxgW3TQbYfQUYQZz3KQRuZcn33g6OMl4XdTdG2 CxC+Z0eLxubu+0iZyZGRruarUKzzzDd+OFDCPbaLWVUpCfdB22hFK6JskKRW/+lWX1R4 DwkJ7eBPRYD3IEKblgJ3X0+48B6AJvKOLSxfdZQAM6X2enKi+ZbSytlK0OkfRLBQs1PO ZOrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=JzO6kN8vx263crDqN9GLB46XC0hjzWSfPRcXHfgmC3U=; b=gWFO1oGm7Qd8H6XLaBlk1MkQyHR28/esNR8u8199IWCILMBbcL9EnMIp0E32mFDJ1i 6kfzZLfZIBcu5sy4wgoK3Kn9GjU37J2WCEIkZtNsJ7QOf3BbLX9e6TQc74AXotKM7cGR rUTf45gSafS5grZOdDHyYzD6cyitrzTJhp3LKlNOscXcqEyBtV0tDfAba4b/fe2uE1S6 RHi1+J8JJ53hnoQUluLRuBuRw65BK3MWv/z7JbsVXXsQNPwY+e4TPBbxDQcC1j9RHYZT IcBMoD/qhY2pd6bp8ypimDAoHWK7SL8fW1/4V6Wb3rg33xSc/XRrtZlLj6KkAc9QZwl4 tPBw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id a55si23953452qtk.80.2019.08.06.23.55.25 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:25 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B30CC30C5859; Wed, 7 Aug 2019 06:55:24 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37BF91000324; Wed, 7 Aug 2019 06:55:21 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 06/10] vhost: mark dirty pages during map uninit Date: Wed, 7 Aug 2019 02:54:45 -0400 Message-Id: <20190807065449.23373-7-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 07 Aug 2019 06:55:24 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We don't mark dirty pages if the map was teared down outside MMU notifier. This will lead untracked dirty pages. Fixing by marking dirty pages during map uninit. Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 2a7217c33668..c12cdadb0855 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -305,6 +305,18 @@ static void vhost_map_unprefetch(struct vhost_map *map) kfree(map); } +static void vhost_set_map_dirty(struct vhost_virtqueue *vq, + struct vhost_map *map, int index) +{ + struct vhost_uaddr *uaddr = &vq->uaddrs[index]; + int i; + + if (uaddr->write) { + for (i = 0; i < map->npages; i++) + set_page_dirty(map->pages[i]); + } +} + static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq) { struct vhost_map *map[VHOST_NUM_ADDRS]; @@ -314,8 +326,10 @@ static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq) for (i = 0; i < VHOST_NUM_ADDRS; i++) { map[i] = rcu_dereference_protected(vq->maps[i], lockdep_is_held(&vq->mmu_lock)); - if (map[i]) + if (map[i]) { + vhost_set_map_dirty(vq, map[i], i); rcu_assign_pointer(vq->maps[i], NULL); + } } spin_unlock(&vq->mmu_lock); @@ -353,7 +367,6 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, { struct vhost_uaddr *uaddr = &vq->uaddrs[index]; struct vhost_map *map; - int i; if (!vhost_map_range_overlap(uaddr, start, end)) return; @@ -364,10 +377,7 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, map = rcu_dereference_protected(vq->maps[index], lockdep_is_held(&vq->mmu_lock)); if (map) { - if (uaddr->write) { - for (i = 0; i < map->npages; i++) - set_page_dirty(map->pages[i]); - } + vhost_set_map_dirty(vq, map, index); rcu_assign_pointer(vq->maps[index], NULL); } spin_unlock(&vq->mmu_lock); From patchwork Wed Aug 7 06:54:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081129 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE49B13AC for ; Wed, 7 Aug 2019 06:55:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD33F2863C for ; Wed, 7 Aug 2019 06:55:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D1890288C5; Wed, 7 Aug 2019 06:55:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C60122863C for ; Wed, 7 Aug 2019 06:55:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 592316B026B; Wed, 7 Aug 2019 02:55:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 520B26B026C; Wed, 7 Aug 2019 02:55:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40AA56B026D; Wed, 7 Aug 2019 02:55:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 227A66B026B for ; Wed, 7 Aug 2019 02:55:29 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id p18so4612543qke.9 for ; Tue, 06 Aug 2019 23:55:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=B1luxMJLkB4TGmpB4Z6oIauGJZZAFOoy1m4euQKOEm4=; b=pUCg6+YLHFO8MECx9YZtcJCaCj39lSoOOCkDbWmMXdfx7maVZgx183S90QiYfuQWMv F0QjeqQSZaTZeltI4NMrU7nR0O6KlxSwknRJUMcgX4do64+Jo+iJGYP9dDVGbW6HgmHj x6JAKNWTwrIlUtlUJZyj2+vITazYKzaz+mbggzIfRWm15gcSE5DQuYB1zuiLgrd2CYkH ZYhUw1eMkMs+H6Nsem74Ode7nA+q2EE3q710bko9QoJH8rsmj3ihRDk00EvWuEqsCg9O vK1s6JHd8F9THDasaeU6DwroBzivfLedzlGbZ8zbCN4zkejmmaIzWTOli9iH6JFtKKjd dOJw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWJxY2a0g58R5Km6v1fL6m3JCDtOgk/jTFkTXaq2iDHiBRy6wyW Tf2TuguN88HDYe3G6YWHLf54ifnA1XsVp8Jar3d8SapohidIh69ouZQJz0p2p1YuTQbMSLv6pre ZIQeIF/AomS96MAbVO7rgRGxrlvUXmZKlqmo/AcBJ40HpD/3+51WAvfkEEn86JP/82Q== X-Received: by 2002:a0c:d0fc:: with SMTP id b57mr6694880qvh.78.1565160928950; Tue, 06 Aug 2019 23:55:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJUWJepLoFU2/PZgUF73L8A8ul1PaUFelsfDjZ1R2rnH+HYU79bhb4lgS+dmZVnz9T2E2H X-Received: by 2002:a0c:d0fc:: with SMTP id b57mr6694864qvh.78.1565160928435; Tue, 06 Aug 2019 23:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160928; cv=none; d=google.com; s=arc-20160816; b=bwLa1jxwhjOKvJ3SzDjmmsIz1REtLYqA75BKsONNV9B+ZRudN0KuCuSCdwhJ4BvGNy ytSSGrKqN1zCjlVI6/vMnujQnMT4F8s9oNu+o7YwQsZm7y9Yd15NTNsmVzYzSb2/C60c JQoAU3O3x/Hv1gToS399P422cO6SHyZhxjzNUAn7w7xikH/2BzDnRKqUB88sipVwJ8bI NiAioZiGSClLByRT463MWJHhyE3jic/miE9rkVPD7rXCame1HOSDArNzywOruTKBsi3K p87W4aPGnu8KNeVHOTA6AZHmJZRGYp1iyZDf2HvUhMWpEiSVg4edi2uvfZupM3gfPNIo oYYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=B1luxMJLkB4TGmpB4Z6oIauGJZZAFOoy1m4euQKOEm4=; b=viMhoTR0cQALbP1Nup8YGd1RDTrPc7TBzpeX1vzrdsEeeYKggdwcGTIgd31Sru0lgv KjyCERzJYpSgFQE1xduL4lDZbcZZL1mOF8H7rQv+IHys4QILIllfW9ZpLicV3y57qlLN rmAmdMKb3pvvJRzL04gdp7qFrqkE/z42ENfd9O/h4wt9qV79hTksAwlqlBqVb4oObPF7 DV41FCebs+VO/9Swt1USk38tdqTOY/5mdE1O4Na2uD8eyRCTWpDd5N5SVfXBrw9Flmfl CHSaxF1fZx43WODaiDMtRLjf7uQ0GYC2igApOJzWei4liuxap/ItIJp2FZB14/q0M5oR ptzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id y10si52993902qvf.166.2019.08.06.23.55.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:28 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD0ED30C5859; Wed, 7 Aug 2019 06:55:27 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33C2A1001281; Wed, 7 Aug 2019 06:55:24 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 07/10] vhost: don't do synchronize_rcu() in vhost_uninit_vq_maps() Date: Wed, 7 Aug 2019 02:54:46 -0400 Message-Id: <20190807065449.23373-8-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 07 Aug 2019 06:55:27 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP There's no need for RCU synchronization in vhost_uninit_vq_maps() since we've already serialized with readers (memory accessors). This also avoid the possible userspace DOS through ioctl() because of the possible high latency caused by synchronize_rcu(). Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index c12cdadb0855..cfc11f9ed9c9 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -333,7 +333,9 @@ static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq) } spin_unlock(&vq->mmu_lock); - synchronize_rcu(); + /* No need for synchronize_rcu() or kfree_rcu() since we are + * serialized with memory accessors (e.g vq mutex held). + */ for (i = 0; i < VHOST_NUM_ADDRS; i++) if (map[i]) From patchwork Wed Aug 7 06:54:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081131 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59DC5912 for ; Wed, 7 Aug 2019 06:55:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 461B42863C for ; Wed, 7 Aug 2019 06:55:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39722288C5; Wed, 7 Aug 2019 06:55:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 566712863C for ; Wed, 7 Aug 2019 06:55:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E1DEC6B026C; Wed, 7 Aug 2019 02:55:32 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DCD986B026D; Wed, 7 Aug 2019 02:55:32 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6EC06B026E; Wed, 7 Aug 2019 02:55:32 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by kanga.kvack.org (Postfix) with ESMTP id A87436B026C for ; Wed, 7 Aug 2019 02:55:32 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id r15so2790499qtt.6 for ; Tue, 06 Aug 2019 23:55:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=SYlINvfnQReM9LtiAmH4n0lonK6ltUq2W4/IC64yAX0=; b=H3VPgK/N9RM4/LyRAih4n8pfHjg/Yf/8sJKsHg5s26YhEzITHDkuAU+aAnkyQcg5Zx aHTZc1eamx7prGB5txDHegecSuiZ4fnd3rnOZJqLXZ5IkBmCJAtr72U2XTPtTC+KiZes CFR0PPhWuLtlKZAwnLetkVqIwk1MyX4EkXMUZEt6EwlDhCVrqly10tRmgOdiXi8ytXd/ PZFkDO+n7RdZwO+DcSJcAgRoDwIMIdG7GfWDIteoptgDTdJLfd2KekFCt8vWg1GohnOl MnhCGC3IAbycGPgHvW7yySVz0TpRVLjJoJl4fMibtOdrp63cNZLa6/+OriRuINzuKNz9 a85A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAXGlVWaesl5jU6hlWwr6DI83e2wWK/tdv5U9QwSSKrqWlx12vy1 82P2mB0u+TJqiWJtASaEfKP1BO+9otClZB+P1PVNlk2PSdNQC236VV3JYALk4O8KmIyNKFUaI09 aYymZCq3zwMlVDi4HidUf44q6Zi/GVrKUgtPo4OBY9QxBFX9CqWZ7JCUBfPEiiF99nQ== X-Received: by 2002:ac8:25b1:: with SMTP id e46mr6844676qte.36.1565160932444; Tue, 06 Aug 2019 23:55:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxTIWeCsQUIHrc2kOunf10QIXG+8BI4DxWQYYb3M1+TXU6zp2UABXdX8z7GXtYzCrN6RnKL X-Received: by 2002:ac8:25b1:: with SMTP id e46mr6844644qte.36.1565160931477; Tue, 06 Aug 2019 23:55:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160931; cv=none; d=google.com; s=arc-20160816; b=S03P1xq8JA4TG6RbMIBU20ghvOwnCa8sdHM4C/11B6w4vrWf6JCpXy2YAkDZq99FAW iqXtYM9gRSmcDHU376aRBf63E6wE7XJDSkKd3VnhK8WGf3g7fWgk4Y88BScv72yLCwGW DYa7fT1rkaaPGFxbEEzGyXAvXn5yRkQHHn/mwK9iU8rRX+s8LxFXC/eGI2VoA3CAuBy4 cKz9tKJOE4sf7dbIRSHG+9GM+oABPWvIH/8HV56N6K7yapgbTVnpCD53oFJ9+uv9NhcZ +tnAuffy/zNmx0nyU8Eo5AsiMC2l9UO3LEa4otJhnuadBO+JszCTMapWm9yWlQN2ok+Z TsLA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=SYlINvfnQReM9LtiAmH4n0lonK6ltUq2W4/IC64yAX0=; b=aDFGRHIPqF1eg2Ff/fPaey1CrwtyaCYTksFzJT0kGGHgym9F02hv72chEXs5a8ELcL cvBXzHVd2bC75Rfp6inwq7JaWFqkXeU3pTXMoj3uMm8Ue0iOYB8KvDqY9W05F1r/GV/6 DcZ1I4w9QCtHm3xGCzIahFHgdFY7jNlNkMf7zmXod8bG1HKyq3QTKCqhQtpjPPapVk92 YRpmW88oFtckVDIGIP2o7upBdbwQf2xlqemhz3+z70uXDOc/hMqDCyQA+rCyIR2UuAY4 jS101AfTeJxtkFg7q7D2M8T8rLV2nrgI3/n87s+Cjx2hql3zrdi8QPRpqnTf6G9PR+0a 3qyw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id e45si42485236qve.198.2019.08.06.23.55.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:31 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB692307BCC4; Wed, 7 Aug 2019 06:55:30 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E3881000324; Wed, 7 Aug 2019 06:55:27 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 08/10] vhost: do not use RCU to synchronize MMU notifier with worker Date: Wed, 7 Aug 2019 02:54:47 -0400 Message-Id: <20190807065449.23373-9-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Wed, 07 Aug 2019 06:55:30 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We used to use RCU to synchronize MMU notifier with worker. This leads calling synchronize_rcu() in invalidate_range_start(). But on a busy system, there would be many factors that may slow down the synchronize_rcu() which makes it unsuitable to be called in MMU notifier. So this patch switches use seqlock counter to track whether or not the map was used. The counter was increased when vq try to start or finish uses the map. This means, when it was even, we're sure there's no readers and MMU notifier is synchronized. When it was odd, it means there's a reader we need to wait it to be even again then we are synchronized. Consider the read critical section is pretty small the synchronization should be done very fast. Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 141 ++++++++++++++++++++++++++---------------- drivers/vhost/vhost.h | 7 ++- 2 files changed, 90 insertions(+), 58 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index cfc11f9ed9c9..57bfbb60d960 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -324,17 +324,16 @@ static void vhost_uninit_vq_maps(struct vhost_virtqueue *vq) spin_lock(&vq->mmu_lock); for (i = 0; i < VHOST_NUM_ADDRS; i++) { - map[i] = rcu_dereference_protected(vq->maps[i], - lockdep_is_held(&vq->mmu_lock)); + map[i] = vq->maps[i]; if (map[i]) { vhost_set_map_dirty(vq, map[i], i); - rcu_assign_pointer(vq->maps[i], NULL); + vq->maps[i] = NULL; } } spin_unlock(&vq->mmu_lock); - /* No need for synchronize_rcu() or kfree_rcu() since we are - * serialized with memory accessors (e.g vq mutex held). + /* No need for synchronization since we are serialized with + * memory accessors (e.g vq mutex held). */ for (i = 0; i < VHOST_NUM_ADDRS; i++) @@ -362,6 +361,40 @@ static bool vhost_map_range_overlap(struct vhost_uaddr *uaddr, return !(end < uaddr->uaddr || start > uaddr->uaddr - 1 + uaddr->size); } +static void inline vhost_vq_access_map_begin(struct vhost_virtqueue *vq) +{ + write_seqcount_begin(&vq->seq); +} + +static void inline vhost_vq_access_map_end(struct vhost_virtqueue *vq) +{ + write_seqcount_end(&vq->seq); +} + +static void inline vhost_vq_sync_access(struct vhost_virtqueue *vq) +{ + unsigned int seq; + + /* Make sure any changes to map was done before checking seq + * counter. Paired with smp_wmb() in write_seqcount_begin(). + */ + smp_mb(); + seq = raw_read_seqcount(&vq->seq); + /* Odd means the map was currently accessed by vhost worker */ + if (seq & 0x1) { + /* When seq changes, we are sure no reader can see + * previous map */ + while (raw_read_seqcount(&vq->seq) == seq) { + if (need_resched()) + schedule(); + } + } + /* Make sure seq counter was checked before map is + * freed. Paired with smp_wmb() in write_seqcount_end(). + */ + smp_mb(); +} + static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, int index, unsigned long start, @@ -376,16 +409,15 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, spin_lock(&vq->mmu_lock); ++vq->invalidate_count; - map = rcu_dereference_protected(vq->maps[index], - lockdep_is_held(&vq->mmu_lock)); + map = vq->maps[index]; if (map) { vhost_set_map_dirty(vq, map, index); - rcu_assign_pointer(vq->maps[index], NULL); + vq->maps[index] = NULL; } spin_unlock(&vq->mmu_lock); if (map) { - synchronize_rcu(); + vhost_vq_sync_access(vq); vhost_map_unprefetch(map); } } @@ -457,7 +489,7 @@ static void vhost_init_maps(struct vhost_dev *dev) for (i = 0; i < dev->nvqs; ++i) { vq = dev->vqs[i]; for (j = 0; j < VHOST_NUM_ADDRS; j++) - RCU_INIT_POINTER(vq->maps[j], NULL); + vq->maps[j] = NULL; } } #endif @@ -655,6 +687,7 @@ void vhost_dev_init(struct vhost_dev *dev, vq->indirect = NULL; vq->heads = NULL; vq->dev = dev; + seqcount_init(&vq->seq); mutex_init(&vq->mutex); spin_lock_init(&vq->mmu_lock); vhost_vq_reset(dev, vq); @@ -921,7 +954,7 @@ static int vhost_map_prefetch(struct vhost_virtqueue *vq, map->npages = npages; map->pages = pages; - rcu_assign_pointer(vq->maps[index], map); + vq->maps[index] = map; /* No need for a synchronize_rcu(). This function should be * called by dev->worker so we are serialized with all * readers. @@ -1216,18 +1249,18 @@ static inline int vhost_put_avail_event(struct vhost_virtqueue *vq) struct vring_used *used; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_USED]); + map = vq->maps[VHOST_ADDR_USED]; if (likely(map)) { used = map->addr; *((__virtio16 *)&used->ring[vq->num]) = cpu_to_vhost16(vq, vq->avail_idx); - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1245,18 +1278,18 @@ static inline int vhost_put_used(struct vhost_virtqueue *vq, size_t size; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_USED]); + map = vq->maps[VHOST_ADDR_USED]; if (likely(map)) { used = map->addr; size = count * sizeof(*head); memcpy(used->ring + idx, head, size); - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1272,17 +1305,17 @@ static inline int vhost_put_used_flags(struct vhost_virtqueue *vq) struct vring_used *used; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_USED]); + map = vq->maps[VHOST_ADDR_USED]; if (likely(map)) { used = map->addr; used->flags = cpu_to_vhost16(vq, vq->used_flags); - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1298,17 +1331,17 @@ static inline int vhost_put_used_idx(struct vhost_virtqueue *vq) struct vring_used *used; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_USED]); + map = vq->maps[VHOST_ADDR_USED]; if (likely(map)) { used = map->addr; used->idx = cpu_to_vhost16(vq, vq->last_used_idx); - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1362,17 +1395,17 @@ static inline int vhost_get_avail_idx(struct vhost_virtqueue *vq, struct vring_avail *avail; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_AVAIL]); + map = vq->maps[VHOST_ADDR_AVAIL]; if (likely(map)) { avail = map->addr; *idx = avail->idx; - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1387,17 +1420,17 @@ static inline int vhost_get_avail_head(struct vhost_virtqueue *vq, struct vring_avail *avail; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_AVAIL]); + map = vq->maps[VHOST_ADDR_AVAIL]; if (likely(map)) { avail = map->addr; *head = avail->ring[idx & (vq->num - 1)]; - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1413,17 +1446,17 @@ static inline int vhost_get_avail_flags(struct vhost_virtqueue *vq, struct vring_avail *avail; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_AVAIL]); + map = vq->maps[VHOST_ADDR_AVAIL]; if (likely(map)) { avail = map->addr; *flags = avail->flags; - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1438,15 +1471,15 @@ static inline int vhost_get_used_event(struct vhost_virtqueue *vq, struct vring_avail *avail; if (!vq->iotlb) { - rcu_read_lock(); - map = rcu_dereference(vq->maps[VHOST_ADDR_AVAIL]); + vhost_vq_access_map_begin(vq); + map = vq->maps[VHOST_ADDR_AVAIL]; if (likely(map)) { avail = map->addr; *event = (__virtio16)avail->ring[vq->num]; - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1461,17 +1494,17 @@ static inline int vhost_get_used_idx(struct vhost_virtqueue *vq, struct vring_used *used; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_USED]); + map = vq->maps[VHOST_ADDR_USED]; if (likely(map)) { used = map->addr; *idx = used->idx; - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1486,17 +1519,17 @@ static inline int vhost_get_desc(struct vhost_virtqueue *vq, struct vring_desc *d; if (!vq->iotlb) { - rcu_read_lock(); + vhost_vq_access_map_begin(vq); - map = rcu_dereference(vq->maps[VHOST_ADDR_DESC]); + map = vq->maps[VHOST_ADDR_DESC]; if (likely(map)) { d = map->addr; *desc = *(d + idx); - rcu_read_unlock(); + vhost_vq_access_map_end(vq); return 0; } - rcu_read_unlock(); + vhost_vq_access_map_end(vq); } #endif @@ -1843,13 +1876,11 @@ static bool iotlb_access_ok(struct vhost_virtqueue *vq, #if VHOST_ARCH_CAN_ACCEL_UACCESS static void vhost_vq_map_prefetch(struct vhost_virtqueue *vq) { - struct vhost_map __rcu *map; + struct vhost_map *map; int i; for (i = 0; i < VHOST_NUM_ADDRS; i++) { - rcu_read_lock(); - map = rcu_dereference(vq->maps[i]); - rcu_read_unlock(); + map = vq->maps[i]; if (unlikely(!map)) vhost_map_prefetch(vq, i); } diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index a9a2a93857d2..12399e7c7a61 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -115,16 +115,17 @@ struct vhost_virtqueue { #if VHOST_ARCH_CAN_ACCEL_UACCESS /* Read by memory accessors, modified by meta data * prefetching, MMU notifier and vring ioctl(). - * Synchonrized through mmu_lock (writers) and RCU (writers - * and readers). + * Synchonrized through mmu_lock (writers) and seqlock + * counters, see vhost_vq_access_map_{begin|end}(). */ - struct vhost_map __rcu *maps[VHOST_NUM_ADDRS]; + struct vhost_map *maps[VHOST_NUM_ADDRS]; /* Read by MMU notifier, modified by vring ioctl(), * synchronized through MMU notifier * registering/unregistering. */ struct vhost_uaddr uaddrs[VHOST_NUM_ADDRS]; #endif + seqcount_t seq; const struct vhost_umem_node *meta_iotlb[VHOST_NUM_ADDRS]; struct file *kick; From patchwork Wed Aug 7 06:54:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081133 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BBB6D13AC for ; Wed, 7 Aug 2019 06:55:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B90027FAE for ; Wed, 7 Aug 2019 06:55:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BC9A284C8; Wed, 7 Aug 2019 06:55:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 226F927FAE for ; Wed, 7 Aug 2019 06:55:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DF6DB6B026D; Wed, 7 Aug 2019 02:55:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DA6FB6B026E; Wed, 7 Aug 2019 02:55:37 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBD4F6B026F; Wed, 7 Aug 2019 02:55:37 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by kanga.kvack.org (Postfix) with ESMTP id AFBD06B026D for ; Wed, 7 Aug 2019 02:55:37 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id c79so78370780qkg.13 for ; Tue, 06 Aug 2019 23:55:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=emOCY78+qYrPzYEsa6BTu0t1qLH1xOVvjmlFjmRfsdo=; b=DGqaaTOTMZG/wabUdNuxVj+/KAfRIwOSIT0JNrA4Dh7rKW87kNp5LGQ7apzAU7ki/t C+v2AQ4q2jQFuTwE1Rj3ivTyoq87nZu+aJBWsEe0yuQ/txjL+Z4BADq7+1NH7WYo/Adi 6UeHoEbFYRiXDQQ1Ml2EUnJfAxkY+GCrZFhDql+lYd9YWJFtdy8Rtpug0GhB44c0AW2p vDc4dib4fWqNHkSvM2vR7Q6eIO8AyJ8BToRomHZ0IDG4e56m25byqY8spfvITdtwAwa/ jvZay2a2SuZunn1Prqk7JVAbS1UBBZh6NqpD3rDSmZ+O3uhaO/7NruJf0O3cY/GBMxnB KA2A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAWIm4ZsPPeAn4Vo/6uIKbX+rD/mmoyDO7giv2t+DEqxzvF/uYP1 T/UaDNtOxF0KX+xugUUekqSOVhW3UpGYVmw6+8mNLUU8GTf0hEEWmqW+WON0YWbuMM1IRmXTHjN Az8z8E6mFXD77fMaRX/0pReDhlDTV4hYOLk5dMihkhMpgn+JTzNApxeKfp2fKrNN2ow== X-Received: by 2002:ac8:303c:: with SMTP id f57mr6686390qte.294.1565160937477; Tue, 06 Aug 2019 23:55:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqz+963/9CYiJLJEN+oo82DAjX9IsQ2GooXmYoF/BlSmsM9aHpNbqJtjS3xwsE5NW6Xp2Lb4 X-Received: by 2002:ac8:303c:: with SMTP id f57mr6686361qte.294.1565160936805; Tue, 06 Aug 2019 23:55:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160936; cv=none; d=google.com; s=arc-20160816; b=V21BUfmd3AArW6HTkRf+5MrcSOu9yMaVrVjNWAjt5yP6n2g5lS5F/RW7FvgGw0tww0 PUnQuWsspLVOSaEUor5NXMh9XdELkE5OyXlUBLvg21Nigt6JjfSrcLQwhXf9NNttTsH4 7VZqcNyzebQn0HZQvZH6jZiY8TfUOyx2+7VyjDQmjsZYPxqXg2k0cJDcplTQxTTNKet2 q9B2iUbdUIIZ8I+0VQky3Wpt2QXUsLDfBvq7B9cmNCSiOqGtWul4k5W+XR7Rrxuodvct g0BQ3pfgl2/dn0rzTyq4i075VJoeLpYWiuzeqpvWEJE69CSnXCcv+/fX0m7sUrxkfUYp oGLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=emOCY78+qYrPzYEsa6BTu0t1qLH1xOVvjmlFjmRfsdo=; b=ah7KqDW7X7fmv4SuI1RA+JCyvhR1xDooqedk6OFpNJmTk0KFzIouRCeq+BoIfhHRVv QmTXHQzqfxBQGnMpVYCxwWUAlNasFdLKSDfl5CC10E8rUxyMoVm4FpvlV55M9avtBRsz dE58wvSYAYR1t9WHjQGJhRoeX7TSz7wicTPlnTzDeWjbrnau0SUQY1lNEXnYaF4jakhu dhN8v+GahSsn8XF6se76yqz0iXPMjt7eNpL5zYLk0AxARlpVYwmLL0EUvsgZcLpQwkFT +gYUHZoXx8eEbsPfDZVhQ09CKVUaW/qHxRcUvAKDvapdlOYhAF5PdXZ0uMYcj+g2Qgkn RB2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id v46si26467838qvc.97.2019.08.06.23.55.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:36 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 10D5614AFAA; Wed, 7 Aug 2019 06:55:36 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D84A1001938; Wed, 7 Aug 2019 06:55:30 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 09/10] vhost: correctly set dirty pages in MMU notifiers callback Date: Wed, 7 Aug 2019 02:54:48 -0400 Message-Id: <20190807065449.23373-10-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 07 Aug 2019 06:55:36 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP We need make sure there's no reference on the map before trying to mark set dirty pages. Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 57bfbb60d960..6650a3ff88c1 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -410,14 +410,13 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, ++vq->invalidate_count; map = vq->maps[index]; - if (map) { - vhost_set_map_dirty(vq, map, index); + if (map) vq->maps[index] = NULL; - } spin_unlock(&vq->mmu_lock); if (map) { vhost_vq_sync_access(vq); + vhost_set_map_dirty(vq, map, index); vhost_map_unprefetch(map); } } From patchwork Wed Aug 7 06:54:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11081137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 513CC912 for ; Wed, 7 Aug 2019 06:55:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E88727FAE for ; Wed, 7 Aug 2019 06:55:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 324CA284C8; Wed, 7 Aug 2019 06:55:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6FCE27FAE for ; Wed, 7 Aug 2019 06:55:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C705B6B026E; Wed, 7 Aug 2019 02:55:44 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C1FED6B026F; Wed, 7 Aug 2019 02:55:44 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B0EDA6B0270; Wed, 7 Aug 2019 02:55:44 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by kanga.kvack.org (Postfix) with ESMTP id 9694E6B026E for ; Wed, 7 Aug 2019 02:55:44 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id c207so78067256qkb.11 for ; Tue, 06 Aug 2019 23:55:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=sYjMC87t7lQK71a5hL6RYQpnRJhjlWcFG0kpxjHSl+k=; b=lUIKzfYIW2QweOyRAwLPbZXBup3+K7z6n7LiWUvYAn1bKXBgzvhe+Sk6JaSAKncPL9 +YnW/JhbsWF+qWpak9Sj8k1LKZ1szugIiw3DBwPArUi8IXOIvKHW97Aa8J6Wl/0j5Bhc 85LVLDb12bpM0cldILzLZQEPGs8u/YvGNOdFmpeZumZdfzFQK6r531LQvTEVl9X1tD+b aypbs8cdkpgEIIyuzoQiHNMe8j4mbZWahxy+tPt8GEoC4GToTY7ONH4ybqzEwjYTkuua K+LUaKxUtrmeUkduuBZbf6oNm3GeWLiSf0xAM7EaYMPyAi6j0ZOCcQtag/PJGjKgfq0j t9jA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: APjAAAW5+SrkSgbxeiLtFgUNdB7/RBfI8aDwHJJ8pFhZx2mlPyGsQZlr YFD+0Oei+VmjWYr8sOHQIsSknHSaiUE4JE8DssDvtbB9HX9y8VMyvq7oqnyn3LsC/X/qXxVPHGg N5Cq4ONjDksd1kUf0h5XQWoA1S9jInACqwsArPe/AQCMbIwyyfgMLT05KjCzQJDi8/Q== X-Received: by 2002:a37:f511:: with SMTP id l17mr6248417qkk.99.1565160944417; Tue, 06 Aug 2019 23:55:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqw7V/uSjo2CaYf0mETI63b4XemXsz1B5NpOPWORgEUkYW3sz5xsjKPPqkoQMargU3umgFpF X-Received: by 2002:a37:f511:: with SMTP id l17mr6248395qkk.99.1565160943864; Tue, 06 Aug 2019 23:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565160943; cv=none; d=google.com; s=arc-20160816; b=cVIpjAvdl4yUuDHUeBqHfgQdK3ya6lzgh2Zh5ss3w3B0eXn8pt2S7q+jGuer91oWNt S9eABaXGC+vRcqDZ7S/ZwWOEfTZ+5LPGPXQPqvPry6j6eKYoGlmmj/H9EeeaLlJibUjz IljT++XFRTpAGpHBlb3dRkOdF2Y/augxTwBav9uPW+7bl8BdM3pNTtjYdDBap2Ro7vOX Asq7tMbEpLNiDAfIx9RvuOjaggkDbEOzMAcxVIojAX1HjWZROMYcxQtGChZeV7rj4w4H w2xjHzbPF/JDo4LW7Gyl7874li/Pd3Gh4mQV/saVpDD8XYMIIkHAA1a+Pkvd7+GY4EcN cN2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=sYjMC87t7lQK71a5hL6RYQpnRJhjlWcFG0kpxjHSl+k=; b=FW02CSIwJtvehW9Z8qNySlyLqg8ro9e7NeOmqVgk2HYGBgYscqc+mTzYuzqREDftNu YEXQuolRj9DDgvl3xcOqrwQuK8qYlLYkQG/8Ob2Lz7cWCOwHNm3WOboCc0vKt9pTEAxA MzWLJ8XAThj8q3c6SmT2yiaA0hOSs2ffkM1hbLbTaiVYVsV2gUMcaFwjPHcS24YuZ2D7 oIp9+TMHrQKGFZiduMUOAiSJ6ssE/uVNL36hDbDpu/vX38+af6qTjMpjV1nt27GPRQ/H mVADMZVv5tUGc/BGeEEcKuU9sxCMzK2qn+WtN4Yyf5xAcWilOs5plL4MlL2wB/qrP6tf NP7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id s54si51216749qte.241.2019.08.06.23.55.43 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Aug 2019 23:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of jasowang@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=jasowang@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2F233C08EC28; Wed, 7 Aug 2019 06:55:43 +0000 (UTC) Received: from hp-dl380pg8-01.lab.eng.pek2.redhat.com (hp-dl380pg8-01.lab.eng.pek2.redhat.com [10.73.8.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id A54A01001958; Wed, 7 Aug 2019 06:55:36 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V3 10/10] vhost: do not return -EAGAIN for non blocking invalidation too early Date: Wed, 7 Aug 2019 02:54:49 -0400 Message-Id: <20190807065449.23373-11-jasowang@redhat.com> In-Reply-To: <20190807065449.23373-1-jasowang@redhat.com> References: <20190807065449.23373-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 07 Aug 2019 06:55:43 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Instead of returning -EAGAIN unconditionally, we'd better do that only we're sure the range is overlapped with the metadata area. Reported-by: Jason Gunthorpe Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 6650a3ff88c1..0271f853fa9c 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -395,16 +395,19 @@ static void inline vhost_vq_sync_access(struct vhost_virtqueue *vq) smp_mb(); } -static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, - int index, - unsigned long start, - unsigned long end) +static int vhost_invalidate_vq_start(struct vhost_virtqueue *vq, + int index, + unsigned long start, + unsigned long end, + bool blockable) { struct vhost_uaddr *uaddr = &vq->uaddrs[index]; struct vhost_map *map; if (!vhost_map_range_overlap(uaddr, start, end)) - return; + return 0; + else if (!blockable) + return -EAGAIN; spin_lock(&vq->mmu_lock); ++vq->invalidate_count; @@ -419,6 +422,8 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, vhost_set_map_dirty(vq, map, index); vhost_map_unprefetch(map); } + + return 0; } static void vhost_invalidate_vq_end(struct vhost_virtqueue *vq, @@ -439,18 +444,19 @@ static int vhost_invalidate_range_start(struct mmu_notifier *mn, { struct vhost_dev *dev = container_of(mn, struct vhost_dev, mmu_notifier); - int i, j; - - if (!mmu_notifier_range_blockable(range)) - return -EAGAIN; + bool blockable = mmu_notifier_range_blockable(range); + int i, j, ret; for (i = 0; i < dev->nvqs; i++) { struct vhost_virtqueue *vq = dev->vqs[i]; - for (j = 0; j < VHOST_NUM_ADDRS; j++) - vhost_invalidate_vq_start(vq, j, - range->start, - range->end); + for (j = 0; j < VHOST_NUM_ADDRS; j++) { + ret = vhost_invalidate_vq_start(vq, j, + range->start, + range->end, blockable); + if (ret) + return ret; + } } return 0;