Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp6756306rwr; Tue, 9 May 2023 21:43:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5hFbhplZLa8PVWtRqQEmeljYqcLGIep/TwFS8K512/iDqpQzoT57NzeaaJOALrBZXPpZT+ X-Received: by 2002:a05:6a21:9211:b0:f8:c19f:1c1d with SMTP id tl17-20020a056a21921100b000f8c19f1c1dmr16088511pzb.61.1683693798033; Tue, 09 May 2023 21:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683693798; cv=none; d=google.com; s=arc-20160816; b=taINmplrg4aBqLBHixdup0+f4Q1KV0ZHuHS+iaT70fSA7c0XqtWlvUIxSOsbZfZa7M MCPQeFjqZuW/fEynC48LkFQgXm+rvvZfah5sEZnV4VOdE9HhnGYVIqdOziPwfnT7XvHD tnGD8G2MN8vB+E19YKkLII1GJigSTjJNZtjHWYsxQ5fhBzK5iy/aEpr2ys2jGhAvB2k1 sVei4BxAftSK9VebXOHhqPYoKpvyPhoq2HVwkP+6EMIZ7z9pofKj7N7yuftiKB97YeRx wb/XGRqkrRT04CCFDN1Y+iRcrDECdqnYCU/Ft6Cp9Ope5JrL6Yrlw85cu4RGQfhLjmtQ jNaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=gUMwiiMo+uImtVa1NMnxeZGa2c1vgyzXNYzjiq0BCYA=; b=C96KfqTE+IyzXwGQHtLcGWuDkEOpguvMVZjWdSueg+jIY7bTo9p/RfW3I9FjyhEEsS 5q//ZoIYxG0XukJCFCVsqxaQLuYaD19pO2Dl1p9Jp5iguHOJ58X0L7pOa8YeVy5fhwqa RTiMO2kZyYwt5bQNv5/rfPEhzVMaXS0UCCYWW8agswQZ9RNIkaQTOoVcM6XyvOnGQJ5V yeKZ/0GvnMa20j7Td15QQW+EQhkLle+RISJqDFxcj/8ow3vBnyvMNDJuB9sLZ8kBLoLu 8r2z695cRy7MtgThYKbr3zUpjC7KNbDYsRBt7j6AFTBV4JWNs8v2v2vY+lDKymqWGLTi OdJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SWY0uqYm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v25-20020a63b959000000b005289d0633d6si3324948pgo.498.2023.05.09.21.43.05; Tue, 09 May 2023 21:43:18 -0700 (PDT) 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=@redhat.com header.s=mimecast20190719 header.b=SWY0uqYm; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjEJEIB (ORCPT + 99 others); Wed, 10 May 2023 00:08:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbjEJEHv (ORCPT ); Wed, 10 May 2023 00:07:51 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 321A5268A for ; Tue, 9 May 2023 21:07:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683691622; 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=gUMwiiMo+uImtVa1NMnxeZGa2c1vgyzXNYzjiq0BCYA=; b=SWY0uqYmeRQGzWUhqi4VtQYgJeFTPxD1sgBa4CqdFJJD/iKFZ29oiXTnHGwg5zTZh21tLf ityJXvJNnesxoOB3uqS8uRsZLJX6G76SPCflNBPeiNSXqUxUI3bLhfpEXKeC+8flYY/ttR 8Hup7HVnv0nHe5zveLoQKGAGopDBOpU= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-Yp6Rftc2NN--iDDc1gJ9dQ-1; Wed, 10 May 2023 00:07:00 -0400 X-MC-Unique: Yp6Rftc2NN--iDDc1gJ9dQ-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-965cd056598so746275566b.0 for ; Tue, 09 May 2023 21:07:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683691620; x=1686283620; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gUMwiiMo+uImtVa1NMnxeZGa2c1vgyzXNYzjiq0BCYA=; b=CNDgFZdmqrw2gegfMNdta/VZ/PmFowqlfSeJyvz/N3hneHvyavXsQJxPVXrazXPqod XgjLGT8pXYieVCTrCRdWVl0f8NHvODRFV2BCzUcUKjAl0FQ5GhtHv9gO3/PHLhFn9zUD l7500rZtwDl6HN5F9Q34BYPmp2IKq5qjsniQFl4Ec2P23/GKTs8fFANe12B7vUHOBWCL mKdiJiUsiUICieh/zJYazrT4ntS6hEiSS2EoRU3WplVpYeYDnEiBnIibrr+KrxMTlhxe WNbYdrTsx5Rh+gWN2OB8BO+/fjZB2gnvJmppt1tRDAoPv+XTToMghN3KhtWW0J3oTFlB RHHg== X-Gm-Message-State: AC+VfDyxkNA2nH5ZxzPlpVx3vN5EFMXrcr2QOKNF5/XGZ0GAfTtCpg/j XIZSQpNLU6F+J0WH1kve2/SplcbXUm7pvy4BLgoAeMRRw/LJkgYfv/AUbWuWwlQdFSdlhaR+OJC 9PoiDEguOzGfGqwsJGKTdg21v X-Received: by 2002:a17:906:974b:b0:957:943e:7416 with SMTP id o11-20020a170906974b00b00957943e7416mr16092527ejy.15.1683691619889; Tue, 09 May 2023 21:06:59 -0700 (PDT) X-Received: by 2002:a17:906:974b:b0:957:943e:7416 with SMTP id o11-20020a170906974b00b00957943e7416mr16092513ejy.15.1683691619610; Tue, 09 May 2023 21:06:59 -0700 (PDT) Received: from redhat.com ([176.119.195.36]) by smtp.gmail.com with ESMTPSA id hx8-20020a170906846800b00965e839f56bsm2088336ejc.182.2023.05.09.21.06.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 21:06:59 -0700 (PDT) Date: Wed, 10 May 2023 00:06:54 -0400 From: "Michael S. Tsirkin" To: Jason Wang Cc: Xuan Zhuo , zhenwei pi , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Joerg Roedel Subject: Re: [PATCH] virtio_ring: use u32 for virtio_max_dma_size Message-ID: <20230510000603-mutt-send-email-mst@kernel.org> References: <20230510025437.377807-1-pizhenwei@bytedance.com> <1683689214.9647853-1-xuanzhuo@linux.alibaba.com> <20230509233907-mutt-send-email-mst@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 Wed, May 10, 2023 at 12:04:50PM +0800, Jason Wang wrote: > On Wed, May 10, 2023 at 11:44 AM Michael S. Tsirkin wrote: > > > > On Wed, May 10, 2023 at 11:26:54AM +0800, Xuan Zhuo wrote: > > > On Wed, 10 May 2023 10:54:37 +0800, zhenwei pi wrote: > > > > Both split ring and packed ring use 32bits to describe the length of > > > > a descriptor: see struct vring_desc and struct vring_packed_desc. > > > > This means the max segment size supported by virtio is U32_MAX. > > > > > > > > An example of virtio_max_dma_size in virtio_blk.c: > > > > u32 v, max_size; > > > > > > > > max_size = virtio_max_dma_size(vdev); -> implicit convert > > > > err = virtio_cread_feature(vdev, VIRTIO_BLK_F_SIZE_MAX, > > > > struct virtio_blk_config, size_max, &v); > > > > max_size = min(max_size, v); > > > > > > > > There is a risk during implicit convert here, once virtio_max_dma_size > > > > returns 4G, max_size becomes 0. > > > > > > > > Fixes: e6d6dd6c875e ("virtio: Introduce virtio_max_dma_size()") > > > > Cc: Joerg Roedel > > > > Signed-off-by: zhenwei pi > > > > --- > > > > drivers/virtio/virtio_ring.c | 12 ++++++++---- > > > > include/linux/virtio.h | 2 +- > > > > 2 files changed, 9 insertions(+), 5 deletions(-) > > > > > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > > > index c5310eaf8b46..55cfecf030a1 100644 > > > > --- a/drivers/virtio/virtio_ring.c > > > > +++ b/drivers/virtio/virtio_ring.c > > > > @@ -289,12 +289,16 @@ static bool vring_use_dma_api(const struct virtio_device *vdev) > > > > return false; > > > > } > > > > > > > > -size_t virtio_max_dma_size(const struct virtio_device *vdev) > > > > +u32 virtio_max_dma_size(const struct virtio_device *vdev) > > > > > > > > > LGTM > > > > > > But, should we change the parameter to vq, then use the dma_dev? > > > > > > @Jason > > > > > > Thanks. > > > > > > > > > that would be an unrelated rework. > > Probably, but I think it's better to be done on top otherwise we may forget. > > Thanks Just to make things clear I'm merging fixes for this release but cleanups belong in the next one. > > > > > > { > > > > - size_t max_segment_size = SIZE_MAX; > > > > + u32 max_segment_size = U32_MAX; > > > > > > > > - if (vring_use_dma_api(vdev)) > > > > - max_segment_size = dma_max_mapping_size(vdev->dev.parent); > > > > + if (vring_use_dma_api(vdev)) { > > > > + size_t max_dma_size = dma_max_mapping_size(vdev->dev.parent); > > > > + > > > > + if (max_dma_size < max_segment_size) > > > > + max_segment_size = max_dma_size; > > > > + } > > > > > > > > return max_segment_size; > > > > } > > > > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > > > > index b93238db94e3..1a605f408329 100644 > > > > --- a/include/linux/virtio.h > > > > +++ b/include/linux/virtio.h > > > > @@ -147,7 +147,7 @@ int virtio_device_restore(struct virtio_device *dev); > > > > #endif > > > > void virtio_reset_device(struct virtio_device *dev); > > > > > > > > -size_t virtio_max_dma_size(const struct virtio_device *vdev); > > > > +u32 virtio_max_dma_size(const struct virtio_device *vdev); > > > > > > > > #define virtio_device_for_each_vq(vdev, vq) \ > > > > list_for_each_entry(vq, &vdev->vqs, list) > > > > -- > > > > 2.20.1 > > > > > >