Received: by 10.213.65.68 with SMTP id h4csp991784imn; Sun, 25 Mar 2018 20:42:29 -0700 (PDT) X-Google-Smtp-Source: AG47ELtnVba24a+ZQzs2FCGqA8RLeZgyyeOaCTTXeXqmCYy0sMzaUiME7A5a1N8I68vl1M5fhX5y X-Received: by 10.99.98.196 with SMTP id w187mr27828325pgb.307.1522035749442; Sun, 25 Mar 2018 20:42:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522035749; cv=none; d=google.com; s=arc-20160816; b=EKZZvQIhFSeANCap/Eq8qGjKS9B0+b1rAZSe6+scC5ylkyN0YENlJpBNfa6ojBaPSi 6JDO4X0zNzYl5EEq1QO4cM2/aBfOmZjYbJJaU6I1bGKbA/ZC60J98+A28tle0diLi0pl 51F+tl6g12Db6H4wcYFPvcIkXYR+E2YLYxabGTh06448VDbOiqQzfZ2263pgIozsvQzc AJWbwlLosTb0QLaI5WjQ27jFl4ZeaMnB72V5Gv/RM/2gOK0hnYmYDbef7ofhGRbX9kKa XUIOLnsih9OLTIpBJFfPMHZtLd0nZGf4D9wai84OawjrZDtoPjEkVyXzi9MMTqPgL+hs 5dkQ== 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=tZ1moakav7QowpikGiVal1elxhU5Sr8u8Xj0MbmEuVE=; b=Qj91mHvANXG/esjgwDZOFofBI7dtCmv9VUuZo+Fm/ZM5/zm1GAq2U56bGEfttQSFZC Inj/RS832aFYXI3iCumTlcX4v66rvgWTlabSVHEmY/rvc09qyVG7UTennhlRagHO7z9o qaox8ETzB+8BwFmGNZ2KmGKPQrx/lFXIbgMs5NIDLLI7aJu37aZPD35oPHRHv35clEer eeDhSsn5d2HS0xzNg77zfdpJTelFVrPtZQOCzjCUccQq4ybpLjS97d9llYB9/U1IXV9L o6Fexlvx+waG1MCg321jYhDIbYOIayiEpuKWkKyD+l03mx0AfnEIjjAUUTLLvAezi8P4 GFNA== 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 t191si9715950pgc.566.2018.03.25.20.42.15; Sun, 25 Mar 2018 20:42:29 -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 S1752307AbeCZDj4 (ORCPT + 99 others); Sun, 25 Mar 2018 23:39:56 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:46712 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752192AbeCZDjv (ORCPT ); Sun, 25 Mar 2018 23:39:51 -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 489FC722C5; Mon, 26 Mar 2018 03:39:51 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-110.pek2.redhat.com [10.72.12.110]) by smtp.corp.redhat.com (Postfix) with ESMTP id EE212111DD01; Mon, 26 Mar 2018 03:39:44 +0000 (UTC) From: Jason Wang To: mst@redhat.com, virtualization@lists.linux-foundation.org Cc: kvm@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jason Wang Subject: [RFC PATCH V2 5/8] vhost: vhost_put_user() can accept metadata type Date: Mon, 26 Mar 2018 11:38:50 +0800 Message-Id: <1522035533-11786-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1522035533-11786-1-git-send-email-jasowang@redhat.com> References: <1522035533-11786-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.2]); Mon, 26 Mar 2018 03:39:51 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 03:39:51 +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 65954d6..dcac4d4 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -847,7 +847,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) { \ @@ -855,7 +855,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 \ @@ -1716,7 +1716,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. */ @@ -1735,7 +1735,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; @@ -2218,12 +2218,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; } @@ -2269,7 +2269,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