Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp759368imm; Mon, 2 Jul 2018 22:40:08 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd8gBeq957fsXW2BqJjqswyu3mcYwlp54HvdrTecoezYETfPUia+UFFzDZGYNfebiSIoNza X-Received: by 2002:a62:c819:: with SMTP id z25-v6mr27224803pff.44.1530596408896; Mon, 02 Jul 2018 22:40:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530596408; cv=none; d=google.com; s=arc-20160816; b=eoZPtkR3UGCJzG5+4tx7SxfJAY0m2+yWXI5XJTgogDMaolJ/VOTxFANC2mni5NPU9A D5ug5hHmG4SEC0g3yep+XrS1O7OfvNaG31WDHTPkESZapA4xAxK2sGpt4tT82v2ndtV+ RD5CU4+jnMMT2cSnw2HmmaN+hRK7fJwWLwulwrk6VNQxmUt7omOF0XR31dfRkwffO9N0 RB5Fiytp6kuxplfMfXD5I81jzLgyFglqamfJojFHjZTX2pvtAHJ7p9wq9VwA2yItbMfW HKMbVLT4HQQpe+qN3jHcaqyuGdIRAbSE5YKTM9yUF40PawfmS5AzS017VCZbUCk2bwY2 CA1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=nwSXbUjt6ChflslB+8BrnaLdCwwtr7LTBJO9t2pwME8=; b=eF5N+GFrzFsw8adEbOBspznsFjfqH24Nn4eYAuGeE7n2e6e+1jgie3q1pAyws5uVHk AkTGBApHRaHPc9nfBzGsxltkKjyi5Z9EU9kH9x7GMqHCwZVRXeRvHgtsAI1TOp1r+/gJ KQEX7XL1zm1BVKMy7qRyfJB2SRdHK5W8nVdSdurxmaAqdnpkpK5aJrHYcE5LBjwSbV+j XrHalR7nbk5iEjeqsOWuXUuLNtxVQRwNuvWGJ/zsLdWOHe16cYVSodWHcoRfGSmnSIpf Vo7bSdynYgvyTHM8ZR7q/w+ALlcFW8vVzs9X1vI2U5VCQFMrgVP3XzTawQZH2gqL9zFs BZYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u8-v6si350635pfl.87.2018.07.02.22.39.54; Mon, 02 Jul 2018 22:40:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932842AbeGCFiz (ORCPT + 99 others); Tue, 3 Jul 2018 01:38:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:39360 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932732AbeGCFit (ORCPT ); Tue, 3 Jul 2018 01:38:49 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0C7FC40267A1; Tue, 3 Jul 2018 05:38:49 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-60.pek2.redhat.com [10.72.12.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 050DF1117624; Tue, 3 Jul 2018 05:38:44 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com, kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: wexu@redhat.com, tiwei.bie@intel.com, maxime.coquelin@redhat.com, jfreimann@redhat.com Subject: [PATCH net-next 5/8] vhost: vhost_put_user() can accept metadata type Date: Tue, 3 Jul 2018 13:38:01 +0800 Message-Id: <1530596284-4101-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1530596284-4101-1-git-send-email-jasowang@redhat.com> References: <1530596284-4101-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Jul 2018 05:38:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Jul 2018 05:38:49 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jasowang@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We assumes used ring update is the only user for vhost_put_user() in the past. This may not be the case for the incoming packed ring which may update the descriptor ring for used. So introduce a new type parameter. Signed-off-by: Jason Wang --- drivers/vhost/vhost.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index af15bec..060a431 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -814,7 +814,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, return __vhost_get_user_slow(vq, addr, size, type); } -#define vhost_put_user(vq, x, ptr) \ +#define vhost_put_user(vq, x, ptr, type) \ ({ \ int ret = -EFAULT; \ if (!vq->iotlb) { \ @@ -822,7 +822,7 @@ static inline void __user *__vhost_get_user(struct vhost_virtqueue *vq, } else { \ __typeof__(ptr) to = \ (__typeof__(ptr)) __vhost_get_user(vq, ptr, \ - sizeof(*ptr), VHOST_ADDR_USED); \ + sizeof(*ptr), type); \ if (to != NULL) \ ret = __put_user(x, to); \ else \ @@ -1687,7 +1687,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) { void __user *used; if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->used_flags), - &vq->used->flags) < 0) + &vq->used->flags, VHOST_ADDR_USED) < 0) return -EFAULT; if (unlikely(vq->log_used)) { /* Make sure the flag is seen before log. */ @@ -1706,7 +1706,7 @@ static int vhost_update_used_flags(struct vhost_virtqueue *vq) static int vhost_update_avail_event(struct vhost_virtqueue *vq, u16 avail_event) { if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->avail_idx), - vhost_avail_event(vq))) + vhost_avail_event(vq), VHOST_ADDR_USED)) return -EFAULT; if (unlikely(vq->log_used)) { void __user *used; @@ -2189,12 +2189,12 @@ static int __vhost_add_used_n(struct vhost_virtqueue *vq, used = vq->used->ring + start; for (i = 0; i < count; i++) { if (unlikely(vhost_put_user(vq, heads[i].elem.id, - &used[i].id))) { + &used[i].id, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used id"); return -EFAULT; } if (unlikely(vhost_put_user(vq, heads[i].elem.len, - &used[i].len))) { + &used[i].len, VHOST_ADDR_USED))) { vq_err(vq, "Failed to write used len"); return -EFAULT; } @@ -2240,7 +2240,7 @@ int vhost_add_used_n(struct vhost_virtqueue *vq, struct vhost_used_elem *heads, /* Make sure buffer is written before we update index. */ smp_wmb(); if (vhost_put_user(vq, cpu_to_vhost16(vq, vq->last_used_idx), - &vq->used->idx)) { + &vq->used->idx, VHOST_ADDR_USED)) { vq_err(vq, "Failed to increment used idx"); return -EFAULT; } -- 2.7.4