Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1887808imm; Sun, 15 Jul 2018 20:30:02 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdpV82fEsdHK5oUnxD1vEoDvRiDZooZc3qp4fZSFBAvqoFPNs14sbhD8aQWpN2VXs4UZVo6 X-Received: by 2002:a63:b605:: with SMTP id j5-v6mr14306204pgf.437.1531711802824; Sun, 15 Jul 2018 20:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531711802; cv=none; d=google.com; s=arc-20160816; b=OA4LzhKXf+4ZMc5e5RsWYlQKrxcudSZzxDYSAqWPR4xDOsdfsOrVxyJ5deKfmZnrtD frFcZB9R9kYj+n9czBIxW/UVu50yrU3knp08C14YUyOKQZmVJ72pGcHQlMzotl6NT74N qUcxbhbJoWrjdXoUsN04+4bWwFg+6wBrFcOqqAPfpn6kPzj9Ou6Y/ezAsowxcx5KWKfS /Wy+GAOB1veGnwgRK8lr8rLF46ypLrnflqsoqLB0glRiX43c7/zuxS5mG6c8IvJWB7ph cYzvvVEojQK3+8JDyvBwIVmgeRiLiSVV5HujSRT3RkSZSvYvKlyeewT0hLHow1wRkNgC T3WQ== 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=d7lTmD3VHXzWJkXJox9h2v0XgdM2Qp5Gbhxos2UA31reJiaFGkpYpJYp6ElSVBhaSF Hewe4VE2GL9voMjOhBwoFP2A+quY/wLwDT5XN3C0bCx1u7GE4VThMlMPsTZ0fvDPbD7H 6dYDOVR1jXunSomnGnpRXO9P7V9TFGCaNW9re0Mu37Yc0/jhZV2Z4jlJm52aG8GMz0hR a2BJs9iSFT2Iz1Si8P76qUBt+vsXp8okmGPdu5HvqX0szDNusMVHosTWQXsuMpdqaahJ bUrtA/Ywc13faZw/ln+SsnDMiFn3uj77k4yVhkD6NVBo1rn2B6H7ZEapLLuQb0j1Ls8i u8cw== 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 c13-v6si27996384pga.413.2018.07.15.20.29.48; Sun, 15 Jul 2018 20:30:02 -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 S1730063AbeGPDyG (ORCPT + 99 others); Sun, 15 Jul 2018 23:54:06 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:57414 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728442AbeGPDyF (ORCPT ); Sun, 15 Jul 2018 23:54:05 -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 A4C187B2B3; Mon, 16 Jul 2018 03:28:48 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-140.pek2.redhat.com [10.72.12.140]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7E5072026D66; Mon, 16 Jul 2018 03:28:44 +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, wexu@redhat.com, jfreimann@redhat.com, tiwei.bie@intel.com, maxime.coquelin@redhat.com Subject: [PATCH net-next V2 5/8] vhost: vhost_put_user() can accept metadata type Date: Mon, 16 Jul 2018 11:28:08 +0800 Message-Id: <1531711691-6769-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1531711691-6769-1-git-send-email-jasowang@redhat.com> References: <1531711691-6769-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.1]); Mon, 16 Jul 2018 03:28:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Mon, 16 Jul 2018 03:28:48 +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 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