Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp8958735rwl; Tue, 10 Jan 2023 22:48:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXumY/sOfBOgr55dQO7hFXs6Acq+Fs5jVOS9qSH+aqMwy7nPqbvMco/wDJEepIjM7oa01jdV X-Received: by 2002:aa7:cb51:0:b0:498:8c60:d7d9 with SMTP id w17-20020aa7cb51000000b004988c60d7d9mr12035717edt.12.1673419721534; Tue, 10 Jan 2023 22:48:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673419721; cv=none; d=google.com; s=arc-20160816; b=iAdfES+FEe2qHBXocuQ4LJtW10temyI3RniTFnEpIQbh+GSbtBC4FE5r/EB1HHT1b9 tA+GhJENY6qF0guzlUMqzHEVvrsrKuFuSFbn9KTWn5frfx4b93UqFueOwgtLQgWxkK4W CIUg+ZlATq20nTL5dwcuQe/uoWfx2NXtya0n9FJfpR9sscpJT53o1fWSIIy0ZF0LUwxN vz9DB38m6bipeFvdiXQYFxwHlVgnpBsz/XHa9rLODLQ5tZT2QJ0KEn6TKdbi7dqgypJ4 7KhLUMSk8/oVBagioEgGG3tljtd45zoOtF300UI1+pN7msmx315sXv1JumSR3CT3KHPo /zvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=dSnK+amNRW+rHXJfTqvbLYb33E3j0tmAwfWlfG8ZZ9Q=; b=yYxC+6nZZLvU4EoDdYWqNgCplOLfnXqfLlOEaTtl1lsgdvWqiZIso4rImseWaBnS03 7L79RqOLZ8tiaqu6/A2ikAzTFD24ofpbu8KnaYwqkPyWbX9mCL8ZImaWOwEmKmHQpL8X 7t0tefZolb3FeQsddp1pmrJ+0gSnvdZwzUxD2ewdfIqg4Kti9sPDvatq5dT4nenYXlQU Ggk7ptLtxSbvkeadWhVtNxSVfIB8ZjZGdiwBYQrs9F9ASZ/deVFxVApRX5CkBbt/TPDM H+TXREtrauzLkbDavA5luK7ItLL52xja6WqNeNgRaZJYoM3QvayzMgCTlqO6a6lrSJKG fIsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=tqzmj2UB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cm25-20020a0564020c9900b00482a5c9b04fsi1945437edb.519.2023.01.10.22.48.28; Tue, 10 Jan 2023 22:48:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@igel-co-jp.20210112.gappssmtp.com header.s=20210112 header.b=tqzmj2UB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229450AbjAKGUB (ORCPT + 53 others); Wed, 11 Jan 2023 01:20:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjAKGT6 (ORCPT ); Wed, 11 Jan 2023 01:19:58 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5103E0A0 for ; Tue, 10 Jan 2023 22:19:56 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so18946189pjj.2 for ; Tue, 10 Jan 2023 22:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel-co-jp.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dSnK+amNRW+rHXJfTqvbLYb33E3j0tmAwfWlfG8ZZ9Q=; b=tqzmj2UBtkSMZ/tIFzP4h3jSYAGj4585ZBDKxHy6vHHixIIC0BMUJOiaSw3He92GHm DVVMHg9DvRdRItwka9z3y49pGbTKoO7Q9fMB8EtYRwUNYU4WBNiwnNGn2F07k7DI4mlq z3fYhN9fIlWQjOi5LTqDUCY79Ck4Yj2X4J0hJyMjv8MSctr9o5vfg5W26d5q+hcyNYgL moELVxWvVzjFIxIqZlUMBLha5bcsn2ekV1coOGzY8esbkL6cM9Za7ytzIVyqpMgwE9yH dYj5PaUglGiXlG3fH/EqrkLj8aEzYih5TeDxEvO+as2TZaicKyyIcRWerCG1h6Shiv/a fCug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dSnK+amNRW+rHXJfTqvbLYb33E3j0tmAwfWlfG8ZZ9Q=; b=mQDHGsV8oMksv32VrARvv12AmN0Lk7kkfigTpG12WeWUM+cFgPZebDZ2D4DZ2pEQQw GaOHxHi7awpJJdy/jWNJ0W0yYWfgTFk39qhz3gEN1fcOOeReFyJz1Wa4VSQ7kVdBZn7m 4d550ST+xerOM6CegKETsM22Me15pGNx83y88qlEVizfKHWNFlQBZaoWEf1QtL4dcmTw /oWaA78EsSCpR4rGcUFI0ktDKqZGl0vRNfNmBsJ7k908ZYAwlH/WZig8+y/ry1WUZIkA ImiQwx9RqivtfujMvw/1L2MLoYG4S4sVFBal0er1o8VVD3hwlBckYcuqMF6MdS90jSHG PDYw== X-Gm-Message-State: AFqh2kovGLk0VAO98Lh9sQX8z1Eeh72sZhSSikC2Kfk8zUbtuA6HozDG a0PmDZok8AStozD2uLUmj200nSVQnwTUQRl6JNg= X-Received: by 2002:a05:6a20:6f59:b0:a4:8725:fdcd with SMTP id gu25-20020a056a206f5900b000a48725fdcdmr71069560pzb.15.1673417996377; Tue, 10 Jan 2023 22:19:56 -0800 (PST) Received: from [10.16.128.218] (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id t21-20020a635355000000b0049f5da82b12sm7451111pgl.93.2023.01.10.22.19.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 10 Jan 2023 22:19:56 -0800 (PST) Message-ID: Date: Wed, 11 Jan 2023 15:19:52 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [RFC PATCH 2/9] vringh: remove vringh_iov and unite to vringh_kiov Content-Language: en-US To: Jason Wang Cc: "Michael S. Tsirkin" , Rusty Russell , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org References: <20221227022528.609839-1-mie@igel.co.jp> <20221227022528.609839-3-mie@igel.co.jp> <18a0a7cd-0601-0ff6-12d7-353819692155@igel.co.jp> From: Shunsuke Mie In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/01/11 14:54, Jason Wang wrote: > On Wed, Jan 11, 2023 at 11:27 AM Shunsuke Mie wrote: >> >> On 2022/12/28 15:36, Jason Wang wrote: >>> On Tue, Dec 27, 2022 at 3:06 PM Shunsuke Mie wrote: >>>> 2022年12月27日(火) 15:04 Jason Wang : >>>>> On Tue, Dec 27, 2022 at 10:25 AM Shunsuke Mie wrote: >>>>>> struct vringh_iov is defined to hold userland addresses. However, to use >>>>>> common function, __vring_iov, finally the vringh_iov converts to the >>>>>> vringh_kiov with simple cast. It includes compile time check code to make >>>>>> sure it can be cast correctly. >>>>>> >>>>>> To simplify the code, this patch removes the struct vringh_iov and unifies >>>>>> APIs to struct vringh_kiov. >>>>>> >>>>>> Signed-off-by: Shunsuke Mie >>>>> While at this, I wonder if we need to go further, that is, switch to >>>>> using an iov iterator instead of a vringh customized one. >>>> I didn't see the iov iterator yet, thank you for informing me. >>>> Is that iov_iter? https://lwn.net/Articles/625077/ >>> Exactly. >> I've investigated the iov_iter, vhost and related APIs. As a result, I >> think that it is not easy to switch to use the iov_iter. Because, the >> design of vhost and vringh is different. > Yes, but just to make sure we are on the same page, the reason I > suggest iov_iter for vringh is that the vringh itself has customized > iter equivalent, e.g it has iter for kernel,user, or even iotlb. At > least the kernel and userspace part could be switched to iov_iter. > Note that it has nothing to do with vhost. I agree. It can be switch to use iov_iter, but I think we need to change fundamentally. There are duplicated code on vhost and vringh to access vring, and some helper functions... Anyway, I'd like to focus vringh in this patchset. Thank you for your comments and suggestions! Best >> The iov_iter has vring desc info and meta data of transfer method. The >> vhost provides generic transfer function for the iov_iter. In constrast, >> vringh_iov just has vring desc info. The vringh provides transfer functions >> for each methods. >> >> In the future, it is better to use common data structure and APIs between >> vhost and vringh (or merge completely), but it requires a lot of >> changes, so I'd like to just >> organize data structure in vringh as a first step in this patch. > That's fine. > > Thansk > >> >> Best >> >>> Thanks >>> >>>>> Thanks >>>>> >>>>>> --- >>>>>> drivers/vhost/vringh.c | 32 ++++++------------------------ >>>>>> include/linux/vringh.h | 45 ++++-------------------------------------- >>>>>> 2 files changed, 10 insertions(+), 67 deletions(-) >>>>>> >>>>>> diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c >>>>>> index 828c29306565..aa3cd27d2384 100644 >>>>>> --- a/drivers/vhost/vringh.c >>>>>> +++ b/drivers/vhost/vringh.c >>>>>> @@ -691,8 +691,8 @@ EXPORT_SYMBOL(vringh_init_user); >>>>>> * calling vringh_iov_cleanup() to release the memory, even on error! >>>>>> */ >>>>>> int vringh_getdesc_user(struct vringh *vrh, >>>>>> - struct vringh_iov *riov, >>>>>> - struct vringh_iov *wiov, >>>>>> + struct vringh_kiov *riov, >>>>>> + struct vringh_kiov *wiov, >>>>>> bool (*getrange)(struct vringh *vrh, >>>>>> u64 addr, struct vringh_range *r), >>>>>> u16 *head) >>>>>> @@ -708,26 +708,6 @@ int vringh_getdesc_user(struct vringh *vrh, >>>>>> if (err == vrh->vring.num) >>>>>> return 0; >>>>>> >>>>>> - /* We need the layouts to be the identical for this to work */ >>>>>> - BUILD_BUG_ON(sizeof(struct vringh_kiov) != sizeof(struct vringh_iov)); >>>>>> - BUILD_BUG_ON(offsetof(struct vringh_kiov, iov) != >>>>>> - offsetof(struct vringh_iov, iov)); >>>>>> - BUILD_BUG_ON(offsetof(struct vringh_kiov, i) != >>>>>> - offsetof(struct vringh_iov, i)); >>>>>> - BUILD_BUG_ON(offsetof(struct vringh_kiov, used) != >>>>>> - offsetof(struct vringh_iov, used)); >>>>>> - BUILD_BUG_ON(offsetof(struct vringh_kiov, max_num) != >>>>>> - offsetof(struct vringh_iov, max_num)); >>>>>> - BUILD_BUG_ON(sizeof(struct iovec) != sizeof(struct kvec)); >>>>>> - BUILD_BUG_ON(offsetof(struct iovec, iov_base) != >>>>>> - offsetof(struct kvec, iov_base)); >>>>>> - BUILD_BUG_ON(offsetof(struct iovec, iov_len) != >>>>>> - offsetof(struct kvec, iov_len)); >>>>>> - BUILD_BUG_ON(sizeof(((struct iovec *)NULL)->iov_base) >>>>>> - != sizeof(((struct kvec *)NULL)->iov_base)); >>>>>> - BUILD_BUG_ON(sizeof(((struct iovec *)NULL)->iov_len) >>>>>> - != sizeof(((struct kvec *)NULL)->iov_len)); >>>>>> - >>>>>> *head = err; >>>>>> err = __vringh_iov(vrh, *head, (struct vringh_kiov *)riov, >>>>>> (struct vringh_kiov *)wiov, >>>>>> @@ -740,14 +720,14 @@ int vringh_getdesc_user(struct vringh *vrh, >>>>>> EXPORT_SYMBOL(vringh_getdesc_user); >>>>>> >>>>>> /** >>>>>> - * vringh_iov_pull_user - copy bytes from vring_iov. >>>>>> + * vringh_iov_pull_user - copy bytes from vring_kiov. >>>>>> * @riov: the riov as passed to vringh_getdesc_user() (updated as we consume) >>>>>> * @dst: the place to copy. >>>>>> * @len: the maximum length to copy. >>>>>> * >>>>>> * Returns the bytes copied <= len or a negative errno. >>>>>> */ >>>>>> -ssize_t vringh_iov_pull_user(struct vringh_iov *riov, void *dst, size_t len) >>>>>> +ssize_t vringh_iov_pull_user(struct vringh_kiov *riov, void *dst, size_t len) >>>>>> { >>>>>> return vringh_iov_xfer(NULL, (struct vringh_kiov *)riov, >>>>>> dst, len, xfer_from_user); >>>>>> @@ -755,14 +735,14 @@ ssize_t vringh_iov_pull_user(struct vringh_iov *riov, void *dst, size_t len) >>>>>> EXPORT_SYMBOL(vringh_iov_pull_user); >>>>>> >>>>>> /** >>>>>> - * vringh_iov_push_user - copy bytes into vring_iov. >>>>>> + * vringh_iov_push_user - copy bytes into vring_kiov. >>>>>> * @wiov: the wiov as passed to vringh_getdesc_user() (updated as we consume) >>>>>> * @src: the place to copy from. >>>>>> * @len: the maximum length to copy. >>>>>> * >>>>>> * Returns the bytes copied <= len or a negative errno. >>>>>> */ >>>>>> -ssize_t vringh_iov_push_user(struct vringh_iov *wiov, >>>>>> +ssize_t vringh_iov_push_user(struct vringh_kiov *wiov, >>>>>> const void *src, size_t len) >>>>>> { >>>>>> return vringh_iov_xfer(NULL, (struct vringh_kiov *)wiov, >>>>>> diff --git a/include/linux/vringh.h b/include/linux/vringh.h >>>>>> index 1991a02c6431..733d948e8123 100644 >>>>>> --- a/include/linux/vringh.h >>>>>> +++ b/include/linux/vringh.h >>>>>> @@ -79,18 +79,6 @@ struct vringh_range { >>>>>> u64 offset; >>>>>> }; >>>>>> >>>>>> -/** >>>>>> - * struct vringh_iov - iovec mangler. >>>>>> - * >>>>>> - * Mangles iovec in place, and restores it. >>>>>> - * Remaining data is iov + i, of used - i elements. >>>>>> - */ >>>>>> -struct vringh_iov { >>>>>> - struct iovec *iov; >>>>>> - size_t consumed; /* Within iov[i] */ >>>>>> - unsigned i, used, max_num; >>>>>> -}; >>>>>> - >>>>>> /** >>>>>> * struct vringh_kiov - kvec mangler. >>>>>> * >>>>>> @@ -113,44 +101,19 @@ int vringh_init_user(struct vringh *vrh, u64 features, >>>>>> vring_avail_t __user *avail, >>>>>> vring_used_t __user *used); >>>>>> >>>>>> -static inline void vringh_iov_init(struct vringh_iov *iov, >>>>>> - struct iovec *iovec, unsigned num) >>>>>> -{ >>>>>> - iov->used = iov->i = 0; >>>>>> - iov->consumed = 0; >>>>>> - iov->max_num = num; >>>>>> - iov->iov = iovec; >>>>>> -} >>>>>> - >>>>>> -static inline void vringh_iov_reset(struct vringh_iov *iov) >>>>>> -{ >>>>>> - iov->iov[iov->i].iov_len += iov->consumed; >>>>>> - iov->iov[iov->i].iov_base -= iov->consumed; >>>>>> - iov->consumed = 0; >>>>>> - iov->i = 0; >>>>>> -} >>>>>> - >>>>>> -static inline void vringh_iov_cleanup(struct vringh_iov *iov) >>>>>> -{ >>>>>> - if (iov->max_num & VRINGH_IOV_ALLOCATED) >>>>>> - kfree(iov->iov); >>>>>> - iov->max_num = iov->used = iov->i = iov->consumed = 0; >>>>>> - iov->iov = NULL; >>>>>> -} >>>>>> - >>>>>> /* Convert a descriptor into iovecs. */ >>>>>> int vringh_getdesc_user(struct vringh *vrh, >>>>>> - struct vringh_iov *riov, >>>>>> - struct vringh_iov *wiov, >>>>>> + struct vringh_kiov *riov, >>>>>> + struct vringh_kiov *wiov, >>>>>> bool (*getrange)(struct vringh *vrh, >>>>>> u64 addr, struct vringh_range *r), >>>>>> u16 *head); >>>>>> >>>>>> /* Copy bytes from readable vsg, consuming it (and incrementing wiov->i). */ >>>>>> -ssize_t vringh_iov_pull_user(struct vringh_iov *riov, void *dst, size_t len); >>>>>> +ssize_t vringh_iov_pull_user(struct vringh_kiov *riov, void *dst, size_t len); >>>>>> >>>>>> /* Copy bytes into writable vsg, consuming it (and incrementing wiov->i). */ >>>>>> -ssize_t vringh_iov_push_user(struct vringh_iov *wiov, >>>>>> +ssize_t vringh_iov_push_user(struct vringh_kiov *wiov, >>>>>> const void *src, size_t len); >>>>>> >>>>>> /* Mark a descriptor as used. */ >>>>>> -- >>>>>> 2.25.1 >>>>>> >>>> Best, >>>> Shunsuke >>>>