Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp1942347imm; Wed, 16 May 2018 05:34:56 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoXht+GdcVnoGL/zIRXhsph6dReGjVjOojI4MYCzH0ukgBb/31WJm/nYOiEbgfpJBO9NsPK X-Received: by 2002:a62:8b07:: with SMTP id j7-v6mr818273pfe.28.1526474095942; Wed, 16 May 2018 05:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526474095; cv=none; d=google.com; s=arc-20160816; b=snVOk828fUcBswY6Vs1jyRx8v1elvZ9aKhlhkM7Y+lX4aajrJv70X+mVsJelAkisdW 7zndAsuJVV4SRFBV8787sPlUXM3NfDvGKc8jI9G/NsgYnEg82q3RNFuNLfDE0ro9ivYZ qcn3h94WzJBcLXp76j/V86hhGy78I4WPZfRNqnIMrIsaf8dMrMYFSXmyaETTVPXHD+Fq PDRczRxsiT/8Kb195ED5uNQn8aTpbX6l1blsOsWRDa3UvBvW8IxxRG18Vu1DKYCqXTQu mWyICABRwXNQRqg9E0BqdwPXSeWhsC8relnRgopVf5KZt75GnSdFHQUd94fvD7FsHGQQ zZSg== 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=23NR8zWTAocNtUUdNbr2n0npr4lruSqWPZFPqU2jAdM=; b=CvecYQESfEg1XDz5Wy5HdZtS/vjhEmc53+jO/nlTc8T5kc5y16o8LIEQ6xtXgQtUaK rI5jcRFhpElRzj29FA7MYBfJuxZb+7pgeS3EGmnkrAyc5MX8Z8DMkji843EDKURxao+L dIkfqzIWIRGL5KnwEaXP+p2FRJn/cOrozNYVN9Dn3QsILw4BsR1b0YtVOKz0f1clUdA9 prtgWVNpbKlC3lusnDrgyY0jxEhiKPBhjSuIAoZI68RWTc2BmIM4puitOy/Hj59hRZmw 19QT/LrGsGWNMfTLlv5zoTWUIb1bfU8SZ7ROKI2ldxsFcsZZZTujZwRB0eCbkEx88Eby YJeA== 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 v10-v6si1993961pgt.359.2018.05.16.05.34.41; Wed, 16 May 2018 05:34:55 -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 S1752642AbeEPMc7 (ORCPT + 99 others); Wed, 16 May 2018 08:32:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52392 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752610AbeEPMc4 (ORCPT ); Wed, 16 May 2018 08:32:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3962F407048B; Wed, 16 May 2018 12:32:56 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-64.pek2.redhat.com [10.72.12.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9528D2166BAD; Wed, 16 May 2018 12:32:51 +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, jfreimann@redhat.com, wexu@redhat.com, tiwei.bie@intel.com Subject: [RFC V4 PATCH 5/8] vhost: vhost_put_user() can accept metadata type Date: Wed, 16 May 2018 20:32:18 +0800 Message-Id: <1526473941-16199-6-git-send-email-jasowang@redhat.com> In-Reply-To: <1526473941-16199-1-git-send-email-jasowang@redhat.com> References: <1526473941-16199-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 12:32:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Wed, 16 May 2018 12:32:56 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.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 2ef1859..8304c30 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -811,7 +811,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) { \ @@ -819,7 +819,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 \ @@ -1680,7 +1680,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. */ @@ -1699,7 +1699,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; @@ -2182,12 +2182,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; } @@ -2233,7 +2233,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