From patchwork Fri Jan 30 08:12:25 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 5747781 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A03659F302 for ; Fri, 30 Jan 2015 08:45:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF0EA201CE for ; Fri, 30 Jan 2015 08:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E4E3201BB for ; Fri, 30 Jan 2015 08:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759729AbbA3Ip3 (ORCPT ); Fri, 30 Jan 2015 03:45:29 -0500 Received: from mail-ob0-f173.google.com ([209.85.214.173]:35184 "EHLO mail-ob0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757862AbbA3Ip1 (ORCPT ); Fri, 30 Jan 2015 03:45:27 -0500 Received: by mail-ob0-f173.google.com with SMTP id uy5so11937480obc.4 for ; Fri, 30 Jan 2015 00:45:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=RzivX+NbXV/3yfdFIMx6y90Qs3RO4cjYrrv2Tz/vdVQ=; b=anKl3gFc+aR7KOhJ22XUKbQL/J11RmXcIJlkK1JvNFmuKlzIsE5aQkSMu29/kCQUvI W9+66tYt2ZaL7igp5rLeXawDyS1CHR99Ez8XCIC4Vguic42kG6D7gf/z/LEZe0lGcEYh lS3opLVHQAOShsn6j8sIMTiEcWHILJM3yKnCG2nSRh9GYVpM9u89zyN3EZFCVYyaSOBI zjMm93+YW4rdjoKHeDHEspHqIcD37eTKbOeP987m2apHPwqn9wT2Nd+ihuBeFxFf327h 1kBADLc/OU3hp1/o1kcZqRiSWFK7JJtdMmyg22Bo0fPIzPNcia1m13n96FYITvSsYn4F L9hg== X-Gm-Message-State: ALoCoQkpBaOxT7CZ28Uq9ocPqI29BeRYoUZFlPaEiEBER+O3rRtYQLH2AJE+Fw1BONT9wKCRixEx X-Received: by 10.202.209.151 with SMTP id i145mr2900004oig.108.1422607526437; Fri, 30 Jan 2015 00:45:26 -0800 (PST) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by mx.google.com with ESMTPSA id l3sm5046132obx.14.2015.01.30.00.45.25 (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 30 Jan 2015 00:45:26 -0800 (PST) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , kvm-devel , Paolo Bonzini , "Michael S. Tsirkin" , Nicholas Bellinger Subject: [PATCH 1/8] lib/iovec: Add memcpy_fromiovec_out library function Date: Fri, 30 Jan 2015 08:12:25 +0000 Message-Id: <1422605552-24797-2-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1422605552-24797-1-git-send-email-nab@daterainc.com> References: <1422605552-24797-1-git-send-email-nab@daterainc.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger This patch adds a new memcpy_fromiovec_out() library function which modifies the passed *iov following memcpy_fromiovec(), but also returns the next current iovec pointer via **iov_out. This is useful for vhost ANY_LAYOUT support when guests are allowed to generate incoming virtio request headers combined with subsequent SGL payloads into a single iovec. Cc: Michael S. Tsirkin Cc: Paolo Bonzini Signed-off-by: Nicholas Bellinger --- include/linux/uio.h | 2 ++ lib/iovec.c | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/linux/uio.h b/include/linux/uio.h index 1c5e453..3e4473d 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -136,6 +136,8 @@ size_t csum_and_copy_to_iter(void *addr, size_t bytes, __wsum *csum, struct iov_ size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len); +int memcpy_fromiovec_out(unsigned char *kdata, struct iovec *iov, + struct iovec **iov_out, int len); int memcpy_fromiovecend(unsigned char *kdata, const struct iovec *iov, int offset, int len); int memcpy_toiovecend(const struct iovec *v, unsigned char *kdata, diff --git a/lib/iovec.c b/lib/iovec.c index 2d99cb4..6a813dd 100644 --- a/lib/iovec.c +++ b/lib/iovec.c @@ -28,6 +28,33 @@ int memcpy_fromiovec(unsigned char *kdata, struct iovec *iov, int len) EXPORT_SYMBOL(memcpy_fromiovec); /* + * Copy iovec to kernel, saving the current iov to *iov_out. + * Returns -EFAULT on error. + */ + +int memcpy_fromiovec_out(unsigned char *kdata, struct iovec *iov, + struct iovec **iov_out, int len) +{ + while (len > 0) { + if (iov->iov_len) { + int copy = min_t(unsigned int, len, iov->iov_len); + if (copy_from_user(kdata, iov->iov_base, copy)) + return -EFAULT; + len -= copy; + kdata += copy; + iov->iov_base += copy; + iov->iov_len -= copy; + } + if (!iov->iov_len) + iov++; + } + *iov_out = iov; + + return 0; +} +EXPORT_SYMBOL(memcpy_fromiovec_out); + +/* * Copy kernel to iovec. Returns -EFAULT on error. */