From patchwork Fri Aug 9 05:48: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: 11085343 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 53F15912 for ; Fri, 9 Aug 2019 05:49:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4271F28BB8 for ; Fri, 9 Aug 2019 05:49:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 367B928C28; Fri, 9 Aug 2019 05:49:07 +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 D919828BB8 for ; Fri, 9 Aug 2019 05:49:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5DD56B0006; Fri, 9 Aug 2019 01:49:05 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B0FF96B0007; Fri, 9 Aug 2019 01:49: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 9AF726B0008; Fri, 9 Aug 2019 01:49: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 807796B0006 for ; Fri, 9 Aug 2019 01:49:05 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id h7so749463qtq.5 for ; Thu, 08 Aug 2019 22:49: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=hXDPuh5Kn7pFxSlRRDrUdecWVXcCQZqbNwxxDsR27Vo=; b=DrGVSPxhjpUjgmnu6+b7CkoDy1Ehvu2Dm0MLoZp3jXEgXPdi5bU044r1OYq614yybe 9SfUObfXWUoKEE93iVgIoPUy3eGYzsA++szIOhba1EGgXBnaJe8odB9M8VDU4s4wZZsx PVY2lSzCXAX7xiOEEBptm1pK5pze4nIjF+aOL0BUr5mBJr6QTDiWqtumCEeIbpJvTYWL X2WCQGqbYM50dGkDlcpX7BhMPPjZNyiN7ZraXS0/LfIOcoC17pBsgRmprjm82xga8XmS g+zBwgJqEiN9NGnmnbN4W5fGtWvQnQwYuemtbA/xx9QEqn5AJ9gcVuGibSHzaJBh3nXo 2Tmg== 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: APjAAAWgMhZcP4/4b3UbC7xS0GclAx/nreNBy6+FiY0D7Px917csjwPN oR0tZwcBOFPhJlNfnR5piwX0a0gV20ozkNsLr3/9TjkLhRQQIXYhrjoIcHmM4DxtcZrzU/zGLfb Aj6pWF7hd4UKKiOMIDppMPd9rDb+zt82pwHo8rwwt6vtMa3tUo6W5pFcMiwejlZRxnw== X-Received: by 2002:a37:dcc7:: with SMTP id v190mr16991806qki.169.1565329745323; Thu, 08 Aug 2019 22:49:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqyzc6zPGFLAKqaVA/8m7Y16ZVyVIWiBo6JnM2Sl0okJDuAPYyNnZe/xYK9IiDK8G/KO7BlG X-Received: by 2002:a37:dcc7:: with SMTP id v190mr16991788qki.169.1565329744809; Thu, 08 Aug 2019 22:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329744; cv=none; d=google.com; s=arc-20160816; b=SQkt0Z4VyEYyW4UpMtK9QVaxn/TDImFhLXRaO1k4nr1CR0ZiSjrzZmMNMtt76Ii0fY OmzpRE847zyfW+8orMasOVTYHhUTqrU5LhO0tfLk9tNyJoxIf76/S0i8o8yE1rJysg9O 407bgdRrKxQyhRtBQMfI3ABsUgbBxUBoqZRlnzUGDbQsUITOHZcvPKk0yCn4tcfbvnA1 UrrEd2LD9/AZr0eBrNrjAEHe1pjSn0ObIY0EBBvnvo3AUY8p+qrors8chnzFqZaHeqrD 4gXZouedwqQ6J/46Tq4L43YYuSwx2bTkHD6jDpW8nXf4ck+EfZ5sIXNjVwcWz4U+VtRp 06zg== 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=aAOWncHdISozDhqXj4xAvC5WqU5z7s6b8GKLmDukV/ExjXR18sYZqnJ4oLojaAinsK dm8Dfb6XUiyp7dNkMsVLsBpCCM1q2H7llRW0rtoXlW+4S+7SFrSUsse3wcZbYWuAKhKF sL+S4ITxIq58F0r3RHyYoo8wcrGqmQMJaNA1BhqcfYD4RbTF1Wg9CjnBimLSE+rd4M9F l2vS5o5X/+feoiB/7xlqGnUe6vVOnbBoQwmbUb98DAbZpN9+43pq8QzOZ22V1jIS5efh 8U8CaPjDg/R3JieToWcPOPm1ClcXzAExLLV69Fs5IfxsQekYRPci5zrM0Idkw34FF4aT h1Mw== 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 m12si1886618qtf.221.2019.08.08.22.49.04 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49: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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07BE830FB8DC; Fri, 9 Aug 2019 05:49: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 7F6315D9CD; Fri, 9 Aug 2019 05:49:01 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 1/9] vhost: don't set uaddr for invalid address Date: Fri, 9 Aug 2019 01:48:43 -0400 Message-Id: <20190809054851.20118-2-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 09 Aug 2019 05:49: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 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 Fri Aug 9 05:48: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: 11085345 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 DC6C9912 for ; Fri, 9 Aug 2019 05:49:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9C5828BB8 for ; Fri, 9 Aug 2019 05:49:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDC0128C28; Fri, 9 Aug 2019 05:49:10 +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 4431E28BB8 for ; Fri, 9 Aug 2019 05:49:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14CD06B0008; Fri, 9 Aug 2019 01:49:09 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0FE546B000A; Fri, 9 Aug 2019 01:49: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 F2CB06B000C; Fri, 9 Aug 2019 01:49:08 -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 D0F4B6B0008 for ; Fri, 9 Aug 2019 01:49:08 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id t2so140212qkd.3 for ; Thu, 08 Aug 2019 22:49:08 -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=nRrIqEh8IaZNYu7u70yJwpwpjGF+JNYljLFvFKnfovI9w2otwURY1Iy+jMOEtq7aMv gT8V4Y+oNAhVxkABkzfdVKXYP1JVf+nkCSsGBktQAUtq+SpqvMG+CWhW9B3TLSzEt8uR 6WGYpEVXGoXp1xWpg/MIcyWV7+jc6Mp/dZLcDY0JMo9cewSkpK0driD6CiG8qPNM77BT AmqvFzEwR0/EsAj1/oDY2SNKLmJnfeeNLwAN3DxNB5BquMwQg9q5w6jAxI6ZZPREdsmW 6AtyswRwGS3RJHspu8KH3SUvsWBr5nMntAbJnlf3LrfZBwLr8wc2YfYBZ5AAVkTv614l QAbQ== 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: APjAAAUjOx12TkH2EBujBTI/KVlMwyBdU9gwCiYXCBHDDXHkDAK+PB/R LqJUpRqOC6WXDY7Pnu432MaAmvhyubJBCFvAwhZgrwY9M6WtHaJZf4Ui5YCuasGswxAksuOpm+a WSWIwn5iAVbA9sArR3gGA1wk0jJ6ufXPDjY862Cfcun0ARUxafS4IEueDhfAoZXafIw== X-Received: by 2002:a37:4944:: with SMTP id w65mr16263165qka.111.1565329748640; Thu, 08 Aug 2019 22:49:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyIIH7Nf9zsbaV5TkE9oU4UuGU8xYZfJym+XTxB3k4nI8wQWcPnB52Y8rg2j9+sUSsSIgBI X-Received: by 2002:a37:4944:: with SMTP id w65mr16263134qka.111.1565329747722; Thu, 08 Aug 2019 22:49:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329747; cv=none; d=google.com; s=arc-20160816; b=uOVhI0hylJMKFaf5+Q4jf6qwH8bmNViFoxhdy2/zO8lcB+kelNdr0SXqcYMOmMQsfp jeqQP8XrlFxQrQHUHSjC62DfI0dhsJbxpfWgnMFZUA4nAXyDEZYOht5rDoe0sf31cVVk MVqwXmrdCgV9JxYUa4U0Mndu5Q8P+5pytMaNLgeNzMHTvqkBQIT6fDWt9Wqp9qMmKHkC 7b8VF1WK0Po0hlM7pBNxg0eoRGyIlBH/20gFC9mTaoariM6P85Qu3OcUrmsjb8CQfWOu e3aljL4mDHolzxULu8gf2ZBq/643Nul/i0PQMliCVWiLVcHP77NHFV1E1wJlEHHLTh/G hGYQ== 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=bw+oe2EqH5oW8e2tzAeRt7vwJa02YwmCY/TSDzv3oZFE5LTf1906Ec/mVOGR2U8UwN dB5AKW5LjRJON9ZZdx7TEtzLns91sjectJSvOc/lFmhbMtlF2jYq4MtSL133jSz6g/EG F6DO3fjMVoCXHJQyexKmLgkWWfQb8orc6NROmMcqKof5yasCLU/JM2ozsxniqmZXn/W0 lztLoHD1oCq5RhHZrtaSMS0VDeCl3k/8cHJwOK34lUtGnIs170nLD1Ay9iueGhzdA7xc xk6XZo87cB2BcYu926L1iH654zJ0zCC2gNg6PPCjoYwGjiWXKzoFTnJHEz8eBNVNBdjG khJA== 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 j96si55269664qtb.125.2019.08.08.22.49.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:07 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 01C9A30832E1; Fri, 9 Aug 2019 05:49: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 7A0545D9CC; Fri, 9 Aug 2019 05:49:04 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 2/9] vhost: validate MMU notifier registration Date: Fri, 9 Aug 2019 01:48:44 -0400 Message-Id: <20190809054851.20118-3-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 09 Aug 2019 05:49: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 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 Fri Aug 9 05:48: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: 11085347 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 94898912 for ; Fri, 9 Aug 2019 05:49:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8425C28BB8 for ; Fri, 9 Aug 2019 05:49:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7827728C28; Fri, 9 Aug 2019 05:49:13 +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 252B028BB8 for ; Fri, 9 Aug 2019 05:49:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B84BE6B000A; Fri, 9 Aug 2019 01:49:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B38796B000C; Fri, 9 Aug 2019 01:49:11 -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 A25DD6B000D; Fri, 9 Aug 2019 01:49:11 -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 858696B000A for ; Fri, 9 Aug 2019 01:49:11 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id c207so84603693qkb.11 for ; Thu, 08 Aug 2019 22:49:11 -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=MljaEvdc2BcGsVhzcTXxO1/5leP3NFTroGkLQfvK46RtXmXPr3EeYOxkQEtLxSQJ+i tYONRgF80KiZWDiiLGKBSLFa3Lb9yhAAWLzGzLquSYTjZBCjWdNESdjLftQcdAUo7NCM wz8D9FepjnxxPO40bnrDuaRJOnab/HoldKho45lbhG2E0ZMyE5xBiwLd6elVBT1vIEHY vXxGZlRwIWFwz1maLnGlydgHt34RB85YVCAmVpu3nh/Maub0xeUx/JlRCRHmB6o7s3iY JXbjXKanuopT8PZ2jtrGXazNkQv/AvckruS1gKqaU8PTzNuwOeKZsq15r3cHOGeSPnDr LlBw== 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: APjAAAXwHqH5oy4XFM/WgQ4rpjmAt0aMqc+2EY/LOyYoGdLpJo8YJpwg Oi7CSfh2jlMI+0cNZRVrC7LzGt13hVMgRFcdqxqqPWE8tQAHwpQcVnkllN78rqhYVefGEK3B7aP VaB+9O+ynMRYJlNCvmxrMjAMOWLZOszJeDlmqkaZZucvKzl7788KYDmM6hPpJKBJwIQ== X-Received: by 2002:ae9:ed94:: with SMTP id c142mr4531928qkg.70.1565329751302; Thu, 08 Aug 2019 22:49:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzz2XUIbHS0Vo8UtbN55sjomKBaUlDG7Pexfa56+5M4qVzf4swG+t+rSNreKStgIA7NMdau X-Received: by 2002:ae9:ed94:: with SMTP id c142mr4531903qkg.70.1565329750743; Thu, 08 Aug 2019 22:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329750; cv=none; d=google.com; s=arc-20160816; b=kX33KnfvTSO0BkLrYNNpYrg/jM9r67sdxsXHgpV2DLHI1d/aPNLPattb+gBm+l25ky nWOkTVGmAUsWkyEdToQdd6165dAZPVuHA1vCpLtU5gJ/1IKUJI660oEFuc3p3RKeV20p 3Wn0C0xWGEiJhvFNWAIY+r9o4hcsQkxyrlIeipUy7Ywpxp4OPslJnFnTFGvuFtdoD5I1 1kQAjhIws2NlWjS7Xmp+p+mGp3Nh3thL5jYFEKm0fCG1z230aRBczpa5sgFXDLtmNiNk lASMycrz/ZMy6TzeUnW5d9wJRDnKr0naQ/jbajRVf5fb9wLNR7Qw+nZVmbsGMxeshtZu YLbQ== 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=BNch3S7jzpPWBM/Okh5JpTS2DAnvL5oea0+O6KjKEsWWxFkQXX/qyBrOTe9cuMsk3P iz3HQ6lSDmiE2xjH2HJBOioAZ1Ix9nE0bfTQWC3LxhLLVWoa4Xz2ezZhqwYGVg1Odi/P 9W/syUUlsg7qecb8vc8msP1qwpNRubvwS6b3BtCIHhMxPB7ZUPTa0EQQtYPOWrbBuK55 DstSuJR7vJ4ZrZjKKYhyzCksmtNq7Bjl2juMoYqrUCUEUZp6Z7uLY27Te3wYkUMAivVs KXqutJGtF1h56GPBmomyrEMNor6e5jtdz9NaU0kHm3eRZjjOUIHQ7GtYHQipXuZtn2jA ZEZg== 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 h19si10975611qkl.44.2019.08.08.22.49.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:10 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0353970DD; Fri, 9 Aug 2019 05:49:09 +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 7596C5D9CC; Fri, 9 Aug 2019 05:49:07 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 3/9] vhost: fix vhost map leak Date: Fri, 9 Aug 2019 01:48:45 -0400 Message-Id: <20190809054851.20118-4-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 09 Aug 2019 05:49: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 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 Fri Aug 9 05:48: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: 11085349 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 78B5D14D5 for ; Fri, 9 Aug 2019 05:49:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6611428BB8 for ; Fri, 9 Aug 2019 05:49:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 59F8F28C28; Fri, 9 Aug 2019 05:49:16 +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 E110328BB8 for ; Fri, 9 Aug 2019 05:49:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9ABB6B000C; Fri, 9 Aug 2019 01:49:14 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A4F516B000D; Fri, 9 Aug 2019 01:49:14 -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 8A8D46B000E; Fri, 9 Aug 2019 01:49:14 -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 65C4C6B000C for ; Fri, 9 Aug 2019 01:49:14 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id d203so6502679qke.4 for ; Thu, 08 Aug 2019 22:49:14 -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=QiaTlTQOPqg5IgdYAWRREFpZ9TwRpPDQdSyP4YgHR84=; b=LbR9MRuHHJK4tfuTe87n6wST0c+J3Vb+P3Rs8kIyPVZVvSHCrC6bCDhEeRO0Kh3psM LaGZfJpvzvfGEsQ+FRel6i0l1DvoMpz2QbLh6XVCuzL69M2evr+bW57sW4s+FwF/mfdz i2CGD6yH7AqIlX4PUux3gijKNGguYjRLus6R9xwc9cZXeEzXDOm++SBaUVcrxvYQ8tt0 /YiGb5bxkztKyrtOSsIcAf8obIqfmeIggVyj/aNPXzLFwutfxmtdKBKi/i+Sa1rebFXL qjZphMwB0KXkiek1vTswI0uabCfPm86G9jZjsbVrBUir6V8/TCMLTMD9P2gEnM9Gw8QG NjGA== 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: APjAAAWQvwICAJSmUzAh+IIElZvc4zlGSyt41Y2EZA8f18h0582yC8TS XNAuTVWODEHjR1LrErfFrqma9NRB5u55WQhVPZwS0nvZM/F2LhYPVBF+9BSwAhrvjrOXCjvTL09 /iKYw2S3juA5JjArSsKMcljf7eadmQrH2h/RsXlAi8JJVvd8bP8K1w5hwiKUvx3cacQ== X-Received: by 2002:a37:f505:: with SMTP id l5mr16954705qkk.235.1565329754236; Thu, 08 Aug 2019 22:49:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyFokIeOhDrnV7mP+Eo9zgMIV6Me38P/GD2UxN/eKK9Cq27O1vsS1+ttQBA5Yl37EI3xN5n X-Received: by 2002:a37:f505:: with SMTP id l5mr16954686qkk.235.1565329753695; Thu, 08 Aug 2019 22:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329753; cv=none; d=google.com; s=arc-20160816; b=IlRpl9W7DChkxCHU4K+BPE5hf9idiuKqsQ9TAgA7xidJrZs3QJHYKQ5YniN2aYIHsx 9DMZShuRJfcrnhxkDrF61cohrggPUhPWRy22KqAJHOxWWSnajZNqoiyWSq7C4sTcdqG1 Fe0txdD1Iuh9in9+ZwpgjNiUAMZc6jUGZn4LRL0RfupipYimQ3dfK1+HjFUv4dUmPTtB ubIJToCJqAa9gqx8cn4pQfHVsVSDWbx4+vXsCtIjH6N//4DYzzuVZ0aH/2iduYUw+DRZ SMuj/F2ogD5qZ2KT/1m0AX3xXPJWhLGyIX1/ZKT2jb6FRIEFWXXdOpEbtNySuFr3mDTA E/NQ== 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=QiaTlTQOPqg5IgdYAWRREFpZ9TwRpPDQdSyP4YgHR84=; b=DwSLjHQ0o2P0oRACVuN+Rr7c1ojS8BnQ9jA3M9b0Ndne2RfxjizFj6JnCTXtZvFVxt QNS4/0+oOg5aFvw8dOv6Q0MpsQZGP8yu4EMXXxBar2EYvJwFP9ycukY11jjbMvkcR7rj It3We1nY7uUBwcULZ1W2wN62WlCkAkcrbkGNZRAfwp8JjqBToKbAqxxo0l1x/4KB7R/1 m1dRJIiqx3+3k7QZ71r5+EcIf79Ejov4H51EKSSsvQgoyabwJrC6sK3CKVKXDOpQHgAp W2QHPEkdF+rFow39P8cre90kY+t9w5Dd1IQNQl3jnUqthiULFS6ylYT8LT9Rw1J6HeLT d5nQ== 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 b185si52719662qkf.40.2019.08.08.22.49.13 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:13 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EC9E281F31; Fri, 9 Aug 2019 05:49:12 +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 7054C5D9CC; Fri, 9 Aug 2019 05:49:10 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 4/9] vhost: reset invalidate_count in vhost_set_vring_num_addr() Date: Fri, 9 Aug 2019 01:48:46 -0400 Message-Id: <20190809054851.20118-5-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 09 Aug 2019 05:49:13 +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 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 Fri Aug 9 05:48: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: 11085351 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 7E00614D5 for ; Fri, 9 Aug 2019 05:49:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CE5128BB8 for ; Fri, 9 Aug 2019 05:49:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6004428C28; Fri, 9 Aug 2019 05:49:19 +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 F117328BB8 for ; Fri, 9 Aug 2019 05:49:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 012446B000D; Fri, 9 Aug 2019 01:49:18 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F06476B000E; Fri, 9 Aug 2019 01:49:17 -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 DD0A86B0010; Fri, 9 Aug 2019 01:49:17 -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 BB6336B000D for ; Fri, 9 Aug 2019 01:49:17 -0400 (EDT) Received: by mail-qk1-f199.google.com with SMTP id v4so84617910qkj.10 for ; Thu, 08 Aug 2019 22:49:17 -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=c0injk5SDbik5nEv7QVKCEaXwDwSbkdV8lzGdtgpyOH3k/B+N4rc15DA3h4fCae4EK xVyZmfer12vuYAkmEcLkWXnQyMVxvgPLhIktRDBfobeQtX4LwEyr8fNvTqU2yN20hEDK 6i7j2oHvxmCcUzgb9eZV/RwDMVA8WrWxLCuHOenYE6Z4kF/xpqj6tGgP3H/YLHCYPBSr iRiWOGPgaMWafiOw3Ssc+04zHhvoYB5CJFD8/g5xb0OYg1x43CmPDf9Qu0XuP+TeVjdQ ExpJm8rQJq9EqAzMQB2Bc1LdK7tWpcw4tYrcL5E2TODssXByQd1LI8YJol0b0pDsA3Kh GCdg== 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: APjAAAVuuILItzZUb7xzuLTtHHpq/y677p0Yd3w73o98EpILQFYxbQox 9e9chp94myFn6dyhTmooPacsWx9PGWdP5iMSR4WdTakztImOlRAvsQ98fxHS7pokj9psaA3sjI/ oMzSDD5KW7w69yC1Zb4IBnam5oREFp+uxbGftfGHxJpbE5Jk892KZoA+ZbMIR0exvsQ== X-Received: by 2002:ac8:2774:: with SMTP id h49mr15768115qth.97.1565329757555; Thu, 08 Aug 2019 22:49:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYDmhpWOolRV35GwsGeR0M7iXN054gN/zt6vqU3875cK2/wW0DkeCmjq54UpkRODyTjXri X-Received: by 2002:ac8:2774:: with SMTP id h49mr15768073qth.97.1565329756677; Thu, 08 Aug 2019 22:49:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329756; cv=none; d=google.com; s=arc-20160816; b=xdmR990kPFcDSEJTEnDdCy4+9QsSNf0vrsechVg1flRqzbnifqsmGVT3IHfEpBBLHe KyUROgAyVhEQZnp8orPqlMf04sKH0TFcwqE/mSGtTzkslDqDbN+FC9OtxeV3N2/nDkyF SJ9gJhoa9Td6OXywDIbCr9xmpF/Z9ow++2yAHSbvdjVlFHhQ73oHgbC47paNIzR3ATfc BU0WVRL+BQqhrtP/PPegiNf741dh14Q+7ye/FWyxFRiSirxkHewyGq8k5KZm2Pd76kLf hG9IDy4sUIKY1SdL82Bbeql7r/ERqm/upX7Qv4vrPM2cWRewVfsnteCqF2h+DsUHXdo8 /Yuw== 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=zfrQ277CAExHGpvzODPRSmYbgEjNAXr/65MIg8bv/MaWdiX1rJb+ozGlMgONDBOQ+0 Ff3icBIpwNIFHtl3c3xwSzQlBe2bskrd/8HemPtFefcw6lxRw6s9SryXxW+DlhWj7j+Q QHSb0wB5U4lE7gBGQLZZvPgFym9HE29EDrd8CTo4M8H7LRvJLABvRXyLTlpa01H0fDu7 XB11Dyn53y0T2iFNhwcLwUCXHe0k+dYEgL0YDqXs1pLIS3ayGGRV3wBEThB4y8TYDldw iakNQ3uB4rmZtKMaeBqhPIeyNsObuo40/xwCplr+qQmOnyh6dUv4eY/n2i4gCK+49uHl RtNg== 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 a186si3956083qkf.13.2019.08.08.22.49.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:16 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E6EBA30BA080; Fri, 9 Aug 2019 05:49:15 +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 6BE455D9CC; Fri, 9 Aug 2019 05:49:13 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 5/9] vhost: mark dirty pages during map uninit Date: Fri, 9 Aug 2019 01:48:47 -0400 Message-Id: <20190809054851.20118-6-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 09 Aug 2019 05:49:16 +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 Fri Aug 9 05:48: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: 11085357 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 E72D414D5 for ; Fri, 9 Aug 2019 05:49:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3F2528BB8 for ; Fri, 9 Aug 2019 05:49:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7FE228C28; Fri, 9 Aug 2019 05:49: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 7E87728BB8 for ; Fri, 9 Aug 2019 05:49:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC0BC6B000E; Fri, 9 Aug 2019 01:49:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A718D6B0010; Fri, 9 Aug 2019 01:49:24 -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 9874F6B0266; Fri, 9 Aug 2019 01:49:24 -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 7935F6B000E for ; Fri, 9 Aug 2019 01:49:24 -0400 (EDT) Received: by mail-qk1-f198.google.com with SMTP id c79so84927121qkg.13 for ; Thu, 08 Aug 2019 22:49:24 -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=PlSWhLHnt2mdBUi0c+gQNi7f4bl/m62dXyay+CX2PTFHqk+ttozhAXT4urxg1NOIxS DAWXLGMMm8Q1+wGNfzfQCY1L2ZBeGkE/SPHasSsssSt2vFAzpCmqusKuf0C1geajWcyX zSloC3LfcRjqUeuF0lv43LiuhCtunCcGS8228lcQpwwHineoHWpSPYrug1gIph09nAXS obvDRoGKUSBYOT4CkEjaag1jBJOb6cH79Drz5RKXhuKsuwEl5i78r67rkkRZWiBmjgqJ SkYqu7xaIqKHSkBMjLw2p5Bi6B1U/pqFskIsLUuD7pajOiMfyEK8h92u9Cb8Ha1oHmxB aIWQ== 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: APjAAAWX/oGESYttmXenjmQFswWUhVlci5y2g7p/gMhbz9Te4Roa1HIE 7EOMy0QWvNwnJGOndcqYVBl2mmcZpWhW6Bjhq4SPimi2JS3JDFZvMR+9RRMJx0bTktveYcqZPEO C/w7NUOdwVhmjmjQ9Nas68lXf+1V40Vr0uEeCSgmndy9lNRPJ172tbxSETpCAYPutPw== X-Received: by 2002:a37:274a:: with SMTP id n71mr15486260qkn.448.1565329764312; Thu, 08 Aug 2019 22:49:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyjPL1NkGVk9oMxe4EpkTOxtDo4SC8VYCgx7AsQ6V8HhdZnx3q9eKrjVCOf9mDWp2Fz2bVj X-Received: by 2002:a37:274a:: with SMTP id n71mr15486240qkn.448.1565329763800; Thu, 08 Aug 2019 22:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329763; cv=none; d=google.com; s=arc-20160816; b=ePfO3ysNU3ucV57xn5QqbNk164yL7Uyt+bnlfMliO4c85IAYB1qMsTZH/lCkDvIVw4 XvptelNvcTQFYggDqReb186M7yKj8Ki/jL91VwYVMitRtJg7fLD2CatC2Oxx5k61sbMD aUzy0M6C9LWNHra/QEPuuwMzamY4GL1vRuqvuT6DJv/eQVrcmmNfzr5UUnz4fyPcZY5H JF2vVk+5RvOJMbvyTV3Hj9jXBnWCCaWfEmZVIB5nKvs1oINqSFQV4f4mx7WsEkbAY6ba jTvWORpTh0TmG5ze0m2ohFnhpzNyQGRbeOPpIuieYBGCgfSSF70naVrVlfVP0tDTL+pS noGg== 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=XIZMMP+4i0eI6rDLcY+qsreorwnRuM2x1pbxExqZ3ABDnJ3sQDD+xku8aP+MqpqFaO 0EEGW1E5dLKkKNJkEy6B0uR6Z+3Httc+jRQoOTm+c00zIILpkfKvsi+XM3Rx7rtLd9D1 OWKxzKBYCI6VX+ZDlooDDbyrOfmx/hUGKvJWOFcTIU3b7zZHbo+zNFx+2ZByyDlKHGuj 2JsqYJ/bOZC2dOa0qJ2Ns7tRILI9eZ4YOZNB1tYam2p79Zq7RePhGb0nK5dUGdVl83fv o0ZaWghAqHkrwZ6IqVj+0iWWZYqOs5qVa/5owa4RcE1+mOpzBRglij5FhZ4FnggWvhEZ uQ1Q== 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 a13si1663485qkl.142.2019.08.08.22.49.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:23 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1256B30FB8DE; Fri, 9 Aug 2019 05:49:23 +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 C064D5D9D6; Fri, 9 Aug 2019 05:49:16 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 6/9] vhost: don't do synchronize_rcu() in vhost_uninit_vq_maps() Date: Fri, 9 Aug 2019 01:48:48 -0400 Message-Id: <20190809054851.20118-7-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 09 Aug 2019 05:49:23 +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 Fri Aug 9 05:48: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: 11085361 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 6C9A71709 for ; Fri, 9 Aug 2019 05:49:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C56228C1C for ; Fri, 9 Aug 2019 05:49:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5011928C2B; Fri, 9 Aug 2019 05:49:32 +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 81E7828C1C for ; Fri, 9 Aug 2019 05:49:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8C5F46B0010; Fri, 9 Aug 2019 01:49:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 827C76B0266; Fri, 9 Aug 2019 01:49:30 -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 6EF136B0269; Fri, 9 Aug 2019 01:49:30 -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 4D1A56B0010 for ; Fri, 9 Aug 2019 01:49:30 -0400 (EDT) Received: by mail-qk1-f200.google.com with SMTP id v4so84618264qkj.10 for ; Thu, 08 Aug 2019 22:49:30 -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=cu5ybPkIHpAYROttCwxcI9tKzPKtlCMY7/rAFebvtRU=; b=tM9n5FxHefaN19rvCOq1WuPlcIc45at/ZkCbXv/ajA+rlnyfiw1zdgm70JN/qgoCgs NGXSPFU+mcw4l3cv24sAtUbiqFEpMTDgTFrsCD6Vwik8WiIeY0pGGYWgSkiRUY1664qJ wr+oUtvvxfzNIwtLi/JaQAT8HG/S4PdysnhWqYJDeZ48YxYwvIj8l5meXPLmPGuiSrlT v30o82ZWMfXUDXMuuP/9k32p6majidvBQZHr6wg4v1sCcN6rdUIaUjRAal2GNiDHNFDq R3kAWsl9qipzdaLbuvyP8gVO1ThFBG5BihkHlgPHujYFWJGI+1pdQze/PBsIKs4VF34v Oymw== 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: APjAAAVYKxgd1NzrrEEJQsKHIUsy5oIHdvWJQjOroJrU2BN5ssD32vlA BXOt57goNDiccEgWR7m1FYUEtlDmEK4A28x7quZrq7MgCso7IfdYRnBzyP9LGVSahNS7XUxvMeZ NEK34FuhXa2iYWSO2fujJxFN6yoGuF4GkwrenzhGL8d/Fu4termLvHjxEYkZEZTquuA== X-Received: by 2002:a0c:983b:: with SMTP id c56mr16809388qvd.131.1565329770078; Thu, 08 Aug 2019 22:49:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqyytmZzXDEVUbrQmw9oIA6wSLK6CeBHXiSRUzo1wxqdQ3/IopWn2ZoW4UyIDv6DKW65fI7o X-Received: by 2002:a0c:983b:: with SMTP id c56mr16809334qvd.131.1565329768751; Thu, 08 Aug 2019 22:49:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329768; cv=none; d=google.com; s=arc-20160816; b=qsTOkG2CNj2uoKnQV/QVOseB1oyBEWbKc0n0/sqlxJ4nXYLLhKzBoM5ACz3oKYHtuu 1PIYLrQmgM5UAk6DXm+7sz+shP39vhxoQ9CH35UKcMC83DWU8uRzNcQOk9V30gTyfqq/ iDDnaWca+7NQTgNBVn10ljwHr4TvvZVAaQ6U+mCPRwovV8ovE9Vzfti21xonw3S/cncN kPnaQ8KTGEcgV6StWZH+TKg2erv5QPsS+ETUyPFXLICq7F22yzNAzxHfYVhoiMNbrL0F 04udsO0F+ph25puckQhpUgnLP1L63HmUC2Hd0uafIsUuCIbVGNGdi9cQqWo4CGADpxsB ke/Q== 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=cu5ybPkIHpAYROttCwxcI9tKzPKtlCMY7/rAFebvtRU=; b=qbDYwER1gvsDDCHbJioPJROkywVPtR8lmBZoOxWMtiYjVTAfB7QmE/XFlZ+Kw4C1KQ K5CsGYGRkJI0H6IYTtU+CYH8OwlG0KvYm5l/+e7iGPkpMDNsIrdJndqbyd2NILqHW6ab TVMYrfUUCSqzrOxadSq/23++Q0zIEpE9uVqxLf4G62stW468lbiDM/72Byme5kWc4QhY qwBkTxZTXNuxYBDvF8pb1wl44fwhZK6QYGCVZ3ybziONPwwZmbVbcS8rc4Z3k3EaiHB2 4BVbFY+ezuJRuAhNjpRSrAreyeHt2HiG813vTG1GvLczq0wcNCfgxidhGvQAEHbR+Rb7 x2VQ== 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 v5si3406473qkf.36.2019.08.08.22.49.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49: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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA7768E237; Fri, 9 Aug 2019 05:49: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 975E95D9CC; Fri, 9 Aug 2019 05:49:23 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 7/9] vhost: do not use RCU to synchronize MMU notifier with worker Date: Fri, 9 Aug 2019 01:48:49 -0400 Message-Id: <20190809054851.20118-8-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 09 Aug 2019 05:49:28 +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. This path switch to use a simple spinlock to do the synchronization. Benchmark was done through testpmd + vhost_net + XDP_DROP on tap. Compare to copy_{to|from}_user() path, on Sandy Bridge (without SMAP support), 1.5% PPS improvement was measured; on Broadwell (with SMAP and enabled), 14% PPS improvement was measured. This means we are not as fast as what 7f466032dc9e did because the spinlock overhead in the datapath. This needs to be addressed in the future. Reported-by: Michael S. Tsirkin Fixes: 7f466032dc9e ("vhost: access vq metadata through kernel virtual address") Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 115 ++++++++++++++++++++++-------------------- drivers/vhost/vhost.h | 5 +- 2 files changed, 62 insertions(+), 58 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index cfc11f9ed9c9..29e8abe694f7 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,16 @@ 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) +{ + spin_lock(&vq->mmu_lock); +} + +static void inline vhost_vq_access_map_end(struct vhost_virtqueue *vq) +{ + spin_unlock(&vq->mmu_lock); +} + static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, int index, unsigned long start, @@ -376,16 +385,14 @@ 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) { + vq->maps[index] = NULL; vhost_set_map_dirty(vq, map, index); - rcu_assign_pointer(vq->maps[index], NULL); } spin_unlock(&vq->mmu_lock); if (map) { - synchronize_rcu(); vhost_map_unprefetch(map); } } @@ -457,7 +464,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 @@ -921,7 +928,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 +1223,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 +1252,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 +1279,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 +1305,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 +1369,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 +1394,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 +1420,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 +1445,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 +1468,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 +1493,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 +1850,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..983d06e62f12 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -115,10 +115,9 @@ 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. */ - 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. From patchwork Fri Aug 9 05:48:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11085363 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 E56A714D5 for ; Fri, 9 Aug 2019 05:49:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5BDF28BB8 for ; Fri, 9 Aug 2019 05:49:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C761628C2B; Fri, 9 Aug 2019 05:49: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 672A728BB8 for ; Fri, 9 Aug 2019 05:49:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67B996B0266; Fri, 9 Aug 2019 01:49:34 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 62BD96B0269; Fri, 9 Aug 2019 01:49:34 -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 4CD1D6B026A; Fri, 9 Aug 2019 01:49:34 -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 2A7E56B0266 for ; Fri, 9 Aug 2019 01:49:34 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id k31so87917261qte.13 for ; Thu, 08 Aug 2019 22:49:34 -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=Xg9xaOgVIH9JkOSw3sYvrdIssRyzR2ThUQFgQ50g+yQ=; b=Lxi3QF/raJu/+hPg/8QUqI+uCufPbB/KJsQ72n6iwwByELrMcPPlGmWwbHr33iaLmR Rkwc8wlbM5tmE0aU9RgwIYSDKTLTZmK2oraZJ8FtiwymDD3ydnZWccsZMyqXqdJVIAZL 7iwn07Yekq58lSaUPv6IVc1d5Hbpv9LMa7AFbnUwRhdu+DWElUNy3DgmELrTPxVLPt1L xAkUIssI1jrtDTC4TECLxzmH965IVDsflcbQ31x5wwuDU4Ux+De7aRl2GKk/Kb7eqR3E U9zNkigwSeelj8TM1IbPut6/lcUmbFSm3Assq1r+nGH+W0OvC8KSLjzs/t9sRjESPHfR qwng== 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: APjAAAWhxff0poNZzpgGfsZn7dHHUuXrsHqS9CFkOa20POfdKHJQ93Um Bp5m/sYZPgiFSiAqxg2oSSxShjdgrxp0sz/vzX9mj1h7u/oL6olqdlKoLGHKjzQkzsdJDltNzab xWWKaUHkJjFjF9P+pbx7BZ81cGhC3eCwKS8BYU4B0FvuRLpssGpaG1+3FarKBcyBchw== X-Received: by 2002:ac8:2439:: with SMTP id c54mr16190871qtc.160.1565329773984; Thu, 08 Aug 2019 22:49:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqzv/Bl/ABY4mgPXyEvQfpVqY+a74raZj4prRu/zGsMc11q54tXt9g4urIZRVhFlacgF/VMF X-Received: by 2002:ac8:2439:: with SMTP id c54mr16190851qtc.160.1565329773429; Thu, 08 Aug 2019 22:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329773; cv=none; d=google.com; s=arc-20160816; b=jY1KkKargHlia2K72Ci37H4oi0b52yd2X7Zxa/K3x59UtPfc9aeMOIK5GPCgyTOcEl WKC1U+m40/Pnh1YZrlNkyTzeUOl8Del5kaPbn2PjFs87oXXg587pWdoKFmmWWCoNc6Kt aNrOBGxg6DjEsKZubBNW5wbGGduBkmpb2Pl5frFMZry+QJylnuGCtAdHYu5cnvNWzlm/ JqdGy91UN5QImrcVbd6Djh8+jJNSJMCzumAWk5xv0rrgp+vZ4Ii62ZGG0mPESYtKkTmR fAsJcP+6BC/pMfJcDx+XqR6IAIPQjnuTCfAUFRZgukUBZ+Q7h0jDLFxbxcvVy8TWyBPi 6/+A== 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=Xg9xaOgVIH9JkOSw3sYvrdIssRyzR2ThUQFgQ50g+yQ=; b=dFDCEU9OZ/PLu9aOyOWYlCmm1GGhLL0wZu1MSKdyyPXQf326LcX9Em1JEU38mIZkmI QoghJNIM15rSDbKgICC3k+hZLXXEjdiwX2KKAsZYgcIKFIdTdLqQyKX1vcFUopH+GAYM +HZYxUwh2nI0aETxyLuAugLQ7jBtgHkCx2gl3i1xw3ck8uItzX2Ilm3EJMslvv7mPk28 P0uZBN/11Fz04iLCfuOQn0sNpPnhqiSeZLP8BdYunIb2VVQalNiRkkrpZgq9MDgMghgp +J7d3LX8vO1/3UzjzTE76ousxWFsupTtf7EpsCzKR7BCYfKdeLh2nostfSlDhaJG/cJm tIVQ== 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 m16si38191338qki.109.2019.08.08.22.49.33 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49:33 -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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93EEE300BEAC; Fri, 9 Aug 2019 05:49:32 +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 70C8F5D9CC; Fri, 9 Aug 2019 05:49:28 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 8/9] vhost: correctly set dirty pages in MMU notifiers callback Date: Fri, 9 Aug 2019 01:48:50 -0400 Message-Id: <20190809054851.20118-9-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Fri, 09 Aug 2019 05:49:32 +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 29e8abe694f7..d8863aaaf0f6 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -386,13 +386,12 @@ static void vhost_invalidate_vq_start(struct vhost_virtqueue *vq, ++vq->invalidate_count; map = vq->maps[index]; - if (map) { + if (map) vq->maps[index] = NULL; - vhost_set_map_dirty(vq, map, index); - } spin_unlock(&vq->mmu_lock); if (map) { + vhost_set_map_dirty(vq, map, index); vhost_map_unprefetch(map); } } From patchwork Fri Aug 9 05:48:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 11085365 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 339BB14D5 for ; Fri, 9 Aug 2019 05:49:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2276628C1C for ; Fri, 9 Aug 2019 05:49:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16FA028C2B; Fri, 9 Aug 2019 05:49: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 999EC28C1C for ; Fri, 9 Aug 2019 05:49:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6CB2F6B0269; Fri, 9 Aug 2019 01:49:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 67AF56B026A; Fri, 9 Aug 2019 01:49: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 569886B026B; Fri, 9 Aug 2019 01:49:37 -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 33DB36B0269 for ; Fri, 9 Aug 2019 01:49:37 -0400 (EDT) Received: by mail-qt1-f197.google.com with SMTP id t5so87652996qtd.21 for ; Thu, 08 Aug 2019 22:49: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=GwEBtSZWPDxK4om7nakiiAS3FtL3tCJnZqvdYC99I0E=; b=kbNKlPkAvlZVtFgKYHOuNX3maQ9FM4TscWtYQK96GnLpgzn9tstw2OGB4py6YtMdbT NHkzlfCK0ujqpB1RdF/gPtEnRTEBxMMTwruiol+WwZRHGLNBo6GrIPbJepPRE/3fdCko iKIf1SM2zP5w+iHlrp3bgD2sTNmD2lybmbg3UXh00psIdcksnqxFC6E1XBplwS7GeJVl ZEFV3PrtCg4++K7zSL8kddmXw/uwIPngJEPi0jjlY/fYYJZZGGGxy8My03Jo5jIYL1AN UoDQOoGsEcMDIQ56HRBVTJGmyaR4/A4RGTUP81Gv08jfG+Xmm9Wq3/fzCzXol0cjRr/E dOCA== 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: APjAAAUUFkCLBjRy38p9DC8gwzESWgcYUtkB449+3XUAsUAeV3stXDWe +7Dxzjmnvu7QHyf0zcTJ3ssA3DJrPMcFOH7EvGxKBp7UrmbBCKMO2F4NWg6eOx1iOLN/QjZCKSr t45jDvwZvmidMrte6KhBrzpvLMr1UEBq0Ng+rFpjRxdjPIdRpCnuKi4AtSrheHnKUgA== X-Received: by 2002:a37:7643:: with SMTP id r64mr16091124qkc.467.1565329777012; Thu, 08 Aug 2019 22:49:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6PxMjLcY3ySZ9CMdlQQgmjW0QfVj5ke8zhD9v3C7gTDIzPfvuq6puN3C91AZfWJwb2UJa X-Received: by 2002:a37:7643:: with SMTP id r64mr16091098qkc.467.1565329776428; Thu, 08 Aug 2019 22:49:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565329776; cv=none; d=google.com; s=arc-20160816; b=qPd8uuv773wPx/M3N6q/F9Hc7Bs3OSIstHWKGRR9lQAjF2ZX8dWNDK8Gyj+bphB8hk s1W41tcqShkLbPQm42Izw9FGslWxXA1CclBs0THLLV9pThxGGmRftPmupHtp+rYyySqm g7U7xBkjh895DHkFel6zm/fHSReiNUr8bwTJZKexJuXavf23ttBeInbyErl51R9gzLBz yxRfeDp9pXe92vDduVlVfWny8Kw/Lb/KM+Xe6x4YTld1iL6BvSEFbTwpC0c7fvpi2aCx f6Hr1F6JSf/dt1YpZTcp0wkQdybAG3iR/qpe6S+ko8plLLdStzKzbiiLB5AKzDfHPe0K wnNQ== 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=GwEBtSZWPDxK4om7nakiiAS3FtL3tCJnZqvdYC99I0E=; b=ecOvqljC2CpRX4t5034J7G7lX7L5wX9cBGFVcSYL2GkRptGhYq9R1wjQZ+K0pBtbm+ l5akkQksW7XpQE0jOosb8BEfiNdLR1r/mhGNcvuwftDelyruT0bJ+NzD9AEbj28WjuES VtXn47z8qxwwhb1MoamWBKqtUEdBTVulYlCZrBP+pt8wdkaxQbtebC6NvG4KGn0ieumH qdLKxfwj1WvfGtNNwsc4wvpH25ZJpMN6nao0YjVXBKfyxGOjhM6/6Q2RFnLBjt/p+gAv efGJB2tzbt63g9jn0GhljYlumWg4o+7IEzhTwT2OIpUHhYnXyjy0tIRZRmaXGZOhmDMX cQSw== 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 w6si53559738qkc.123.2019.08.08.22.49.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Aug 2019 22:49: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-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A097D300C768; Fri, 9 Aug 2019 05:49:35 +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 184825D9CC; Fri, 9 Aug 2019 05:49:32 +0000 (UTC) From: Jason Wang To: mst@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, jgg@ziepe.ca, Jason Wang Subject: [PATCH V5 9/9] vhost: do not return -EAGAIN for non blocking invalidation too early Date: Fri, 9 Aug 2019 01:48:51 -0400 Message-Id: <20190809054851.20118-10-jasowang@redhat.com> In-Reply-To: <20190809054851.20118-1-jasowang@redhat.com> References: <20190809054851.20118-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 09 Aug 2019 05:49:35 +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 d8863aaaf0f6..f98155f28f02 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -371,16 +371,19 @@ static void inline vhost_vq_access_map_end(struct vhost_virtqueue *vq) spin_unlock(&vq->mmu_lock); } -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; @@ -394,6 +397,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, @@ -414,18 +419,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;