Received: by 10.192.165.148 with SMTP id m20csp3041559imm; Sun, 22 Apr 2018 22:40:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/4GzPdjqB8kKblgHs1gi8kLBa/Jx1bgj+Uk+1EkvA1oNj13EGGQhp6zorRvKwwpnMhNE1J X-Received: by 10.98.93.20 with SMTP id r20mr18777176pfb.53.1524462012965; Sun, 22 Apr 2018 22:40:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524462012; cv=none; d=google.com; s=arc-20160816; b=s6G2jMZD6mrB816detwFcg5zWYkm2UDUSSkRbg7nISdte/j5loGY0UefOcZ92fvUNi qZR5vymEJ1NMQkG6qz+zVIxraOfmHqcxBf6OSMIdkyOek+UW3KMZl/BOUFw91DXByt13 MIfV9iliBZpj6FVRRPZo+wOuTehn4nvMBEq8s1tUHL7HzMVS4nLOsliV9Ccp024NfgY0 AvTkWIBDKNGyt/dYiqlCRJxAfVkfo+L+iblFQ/dQIjZLBICyVzN8zXn0J4JoXn60qxbQ JT2HMEbmjkUJnBSiwMhPyuu5+oY+T5yIsVZP6b2plqj8GaIjPyjtEx/s0IJ67qTM4uSc 4BXg== 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=F9uMWhU4sJTEeTIqJgcYfEgxa6WQU63A4Lm1XSB6nEA=; b=KS9l8LqOu+CJS0+asRoF7V/mRjl/5Qv+qutf4ozLn7GeodU8PZaTHymjrx7PxIaVVf 5R2646uX9abRtwVCZoKXxpcFHkn67sP4HZ8mDxU+QwDCHdLDTbsVD4FbeuIy8QWMpH9G TXdk6hqQSXw1GFnPftwojofuyyDklNAK4bRGJSbLWHwJYj11+MIxt/MD1WOwmP0X5if4 2GxCJIO0+4BL8M2Fm84HbgFO00UsiXS709thFe145ZhDUtgreBGEvuDfdOoxmwgZZqMh Mokgc4rgEJ40/i5Fnd8rr/Ryi9Bn+rhiBhwDXgTwc1nsTpfWDF4Kt6xmtdlng7JB9PzA QiRA== 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 g18-v6si10847265plo.586.2018.04.22.22.39.58; Sun, 22 Apr 2018 22:40:12 -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 S1754177AbeDWFhM (ORCPT + 99 others); Mon, 23 Apr 2018 01:37:12 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52530 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751516AbeDWFfc (ORCPT ); Mon, 23 Apr 2018 01:35:32 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B083406E968; Mon, 23 Apr 2018 05:35:32 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-101.pek2.redhat.com [10.72.12.101]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE9B2022DEB; Mon, 23 Apr 2018 05:35:28 +0000 (UTC) From: Jason Wang To: mst@redhat.com, jasowang@redhat.com Cc: kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, tiwei.bie@intel.com, jfreimann@redhat.com, wexu@redhat.com Subject: [RFC V3 PATCH 5/8] vhost: vhost_put_user() can accept metadata type Date: Mon, 23 Apr 2018 13:34:57 +0800 Message-Id: <1524461700-5469-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1524461700-5469-1-git-send-email-jasowang@redhat.com> References: <1524461700-5469-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 05:35:32 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Mon, 23 Apr 2018 05:35:32 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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 5cc1cdb..82a7b73 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -846,7 +846,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) { \ @@ -854,7 +854,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 \ @@ -1715,7 +1715,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. */ @@ -1734,7 +1734,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; @@ -2217,12 +2217,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; } @@ -2268,7 +2268,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