From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22682C433E6 for ; Fri, 5 Feb 2021 22:59:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C33CC64FB0 for ; Fri, 5 Feb 2021 22:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbhBEW7n (ORCPT ); Fri, 5 Feb 2021 17:59:43 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:31080 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232797AbhBEOk6 (ORCPT ); Fri, 5 Feb 2021 09:40:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612541897; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NnP5XCU4u3GLA5tU6K2RnQ5rd1UvAC9ZZ89SyiHV8bU=; b=jHWLp9fXeO5yPVNAl5Qq4lKE1QLdW9VH2ka22e3qy0V5gQLW8KBACGp0rXKIZnX4uXUJZB i77/O5NXtDuz+K3rDXVYd4x0R+76WGdCWSJ3ialrhOD4+u97xFBJFLOAy9MxLVkJtNvTLX tUSQ6q5VGdlCmSmMeTD2vpOpY7noVQc= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-425-Y8SuSeBXOiSulWG-iBwssw-1; Fri, 05 Feb 2021 09:17:11 -0500 X-MC-Unique: Y8SuSeBXOiSulWG-iBwssw-1 Received: by mail-wm1-f70.google.com with SMTP id y9so3024331wmj.7 for ; Fri, 05 Feb 2021 06:17:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=NnP5XCU4u3GLA5tU6K2RnQ5rd1UvAC9ZZ89SyiHV8bU=; b=bfQ9+1VcBGu5yhnfV+NEOtfpSpcCybTy88it22MuJXbO1mI6feGFSaakSo5yAwrSHm e3cfu3eU8K7fgwzKlg9QCEgKK1a1xjbq9ON0ZvTdjJuFb1Hqgw2yxj0tGdMxjV7E0EmC t++BP+KxVqrLmMVO6LLoNn4OdCH2f3sW7zzxblM9TLZeGmIr8C/DjMawf2Jn4AkYhDcO hIUtIJZguMcNspCqCtQakztFLyFNYlRETU+TSe+EDPHWhEgLkOlQ3o4cDAAEe1BwiA7A DPe2HneF23MwMKOvv+lBep4Ge+Qz7yXwShKWyBTagROpSoUxa46p++cfzCNtNG2+Arf2 Ch4g== X-Gm-Message-State: AOAM532QDiXGliUokP2y4GZSCWjZ7vTPUhxGtmCUG0+O67fiwPhFs+9w SYjLPBu+Zn5CmCwfNUqNq5i1u13BtOdydzQb/u/2Bd0KlUBFkHJJybOSTruhCdu6qjOdGrV6gy7 PUGYkDGeD2wBj6qn/9NbQvEbU X-Received: by 2002:a5d:453b:: with SMTP id j27mr5351074wra.92.1612534630613; Fri, 05 Feb 2021 06:17:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxoN6BUEbnc4t31XEyr636+ZdDqrgfqdIVz7cbLxF0zafdGnFimMKQJ7JMi3xLjdYuOKx6feA== X-Received: by 2002:a5d:453b:: with SMTP id j27mr5351061wra.92.1612534630414; Fri, 05 Feb 2021 06:17:10 -0800 (PST) Received: from steredhat (host-79-34-249-199.business.telecomitalia.it. [79.34.249.199]) by smtp.gmail.com with ESMTPSA id v6sm12579287wrx.32.2021.02.05.06.17.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Feb 2021 06:17:09 -0800 (PST) Date: Fri, 5 Feb 2021 15:17:07 +0100 From: Stefano Garzarella To: "Michael S. Tsirkin" Cc: Jason Wang , virtualization@lists.linux-foundation.org, Xie Yongji , kvm@vger.kernel.org, Laurent Vivier , Stefan Hajnoczi , Max Gurtovoy , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 09/13] vhost/vdpa: remove vhost_vdpa_config_validate() Message-ID: <20210205141707.clbckauxnrzd7nmv@steredhat> References: <20210204172230.85853-1-sgarzare@redhat.com> <20210204172230.85853-10-sgarzare@redhat.com> <6919d2d4-cc8e-2b67-2385-35803de5e38b@redhat.com> <20210205091651.xfcdyuvwwzew2ufo@steredhat> <20210205083108-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210205083108-mutt-send-email-mst@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 05, 2021 at 08:32:37AM -0500, Michael S. Tsirkin wrote: >On Fri, Feb 05, 2021 at 10:16:51AM +0100, Stefano Garzarella wrote: >> On Fri, Feb 05, 2021 at 11:27:32AM +0800, Jason Wang wrote: >> > >> > On 2021/2/5 上午1:22, Stefano Garzarella wrote: >> > > get_config() and set_config() callbacks in the 'struct vdpa_config_ops' >> > > usually already validated the inputs. Also now they can return an error, >> > > so we don't need to validate them here anymore. >> > > >> > > Let's use the return value of these callbacks and return it in case of >> > > error in vhost_vdpa_get_config() and vhost_vdpa_set_config(). >> > > >> > > Originally-by: Xie Yongji >> > > Signed-off-by: Stefano Garzarella >> > > --- >> > > drivers/vhost/vdpa.c | 41 +++++++++++++---------------------------- >> > > 1 file changed, 13 insertions(+), 28 deletions(-) >> > > >> > > diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c >> > > index ef688c8c0e0e..d61e779000a8 100644 >> > > --- a/drivers/vhost/vdpa.c >> > > +++ b/drivers/vhost/vdpa.c >> > > @@ -185,51 +185,35 @@ static long vhost_vdpa_set_status(struct vhost_vdpa *v, u8 __user *statusp) >> > > return 0; >> > > } >> > > -static int vhost_vdpa_config_validate(struct vhost_vdpa *v, >> > > - struct vhost_vdpa_config *c) >> > > -{ >> > > - long size = 0; >> > > - >> > > - switch (v->virtio_id) { >> > > - case VIRTIO_ID_NET: >> > > - size = sizeof(struct virtio_net_config); >> > > - break; >> > > - } >> > > - >> > > - if (c->len == 0) >> > > - return -EINVAL; >> > > - >> > > - if (c->len > size - c->off) >> > > - return -E2BIG; >> > > - >> > > - return 0; >> > > -} >> > > - >> > > static long vhost_vdpa_get_config(struct vhost_vdpa *v, >> > > struct vhost_vdpa_config __user *c) >> > > { >> > > struct vdpa_device *vdpa = v->vdpa; >> > > struct vhost_vdpa_config config; >> > > unsigned long size = offsetof(struct vhost_vdpa_config, buf); >> > > + long ret; >> > > u8 *buf; >> > > if (copy_from_user(&config, c, size)) >> > > return -EFAULT; >> > > - if (vhost_vdpa_config_validate(v, &config)) >> > > + if (config.len == 0) >> > > return -EINVAL; >> > > buf = kvzalloc(config.len, GFP_KERNEL); >> > >> > >> > Then it means usersapce can allocate a very large memory. >> >> Good point. >> >> > >> > Rethink about this, we should limit the size here (e.g PAGE_SIZE) or >> > fetch the config size first (either through a config ops as you >> > suggested or a variable in the vdpa device that is initialized during >> > device creation). >> >> Maybe PAGE_SIZE is okay as a limit. >> >> If instead we want to fetch the config size, then better a config ops in my >> opinion, to avoid adding a new parameter to __vdpa_alloc_device(). >> >> I vote for PAGE_SIZE, but it isn't a strong opinion. >> >> What do you and @Michael suggest? >> >> Thanks, >> Stefano > >Devices know what the config size is. Just have them provide it. > Okay, I'll add get_config_size() callback in vdpa_config_ops and I'll leave vhost_vdpa_config_validate() that will use that callback instead of 'virtio_id' to get the config size from the device. At this point I think I can remove the "vdpa: add return value to get_config/set_config callbacks" patch and leave void return to get_config/set_config callbacks. Does this make sense? Thanks, Stefano