Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp2087941rwi; Tue, 11 Oct 2022 04:49:22 -0700 (PDT) X-Google-Smtp-Source: AMsMyM60eO6Nt0tfirMKRbWcB8gKMS+5RnlymrB3eMcmvLy3prY0jeyIwbnESXu80sLsmt+d1Roa X-Received: by 2002:a17:902:d50b:b0:178:3ea4:2945 with SMTP id b11-20020a170902d50b00b001783ea42945mr23445268plg.67.1665488962565; Tue, 11 Oct 2022 04:49:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665488962; cv=none; d=google.com; s=arc-20160816; b=QVbupv+fyruqR/vpL6F9aE43sIBQWTvftI7qsJ+qpfqFHhs3zLyGlPJP/E+nl6PQI/ qV1gENq3IyHsaKVaRQpyFEJDgDv010Hv2eKm8qILsve3F8tekN4xOvjGr3em4d4cagh7 i3oQARWUdsY55Z2iu/ZdWHYSr0WMcATutkRlhIubCJQ6kDrNhUxqL54H2JnHEIu9KyTt xz2Xsv93RBoLrrkv3COf5omsCXtRGOV9T70mHsKVGhGm/uqoie0Y9z68Cu6p+2ZeYzSr /VihyNhK8QFIwdW+rDqFJXP6hYYfrsxV/N0UbiXqs5s5MsKVic0IH32dQ8VHldt+VztT Z2+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=+xcQQsh5NuFq1T/qH4QeaqjBaA5pkbwB5vlBALKSM0U=; b=RczcIxOg63ckdjCECEgFiGcOd5JyQMFMFZOBM9aqViaBXWjZo0mM60G8KcslrfhQkI jEJUmCbA+6c88WoVp8kcEeDYeUqrPqqDpRPnqpT2L9bEo2fHJrJR3lNmoLkwCNxeMcaf 9+wvtK2B8I2txqJYuq2arPZBDvzwxoj/ky9zK3lPOOSzaI4qiImhdF00LChhdr8O2SLV 7ZXBKpP4Ib3zm32ccevosGzvrDAoPRhU08Oy9QtqLhDecXJ1J+ZD4jj2hvjT39wsU0wk 8Fat7SxfrZie3mpyTmlR8TroFJG3y/xHDm6ILjk03S5ckX/hkwVjNTSeHuElih7cD2hS U1gg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d4-20020a170902cec400b00176ab430a57si17384598plg.546.2022.10.11.04.49.10; Tue, 11 Oct 2022 04:49:22 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbiJKLsN convert rfc822-to-8bit (ORCPT + 99 others); Tue, 11 Oct 2022 07:48:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229505AbiJKLsL (ORCPT ); Tue, 11 Oct 2022 07:48:11 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C93FDE6 for ; Tue, 11 Oct 2022 04:48:10 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-158-Lh8fam-hP0CDpIxos_Mzhw-1; Tue, 11 Oct 2022 12:48:07 +0100 X-MC-Unique: Lh8fam-hP0CDpIxos_Mzhw-1 Received: from AcuMS.Aculab.com (10.202.163.4) by AcuMS.aculab.com (10.202.163.4) with Microsoft SMTP Server (TLS) id 15.0.1497.38; Tue, 11 Oct 2022 12:48:05 +0100 Received: from AcuMS.Aculab.com ([::1]) by AcuMS.aculab.com ([::1]) with mapi id 15.00.1497.040; Tue, 11 Oct 2022 12:48:05 +0100 From: David Laight To: 'Leon Romanovsky' , Rui Ma CC: "helgaas@kernel.org" , "linux-kernel@vger.kernel.org" , "linux-pci@vger.kernel.org" , "Alexander.Deucher@amd.com" , "bhelgaas@google.com" Subject: RE: [PATCH] PCI/IOV: Decrease VF memory BAR size to save host memory occupied by PTEs Thread-Topic: [PATCH] PCI/IOV: Decrease VF memory BAR size to save host memory occupied by PTEs Thread-Index: AQHY3WXQJdhdERmAOESu97r3UBgaK64JE0ig Date: Tue, 11 Oct 2022 11:48:05 +0000 Message-ID: References: <20221011112325.992317-1-Rui.Ma@amd.com> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,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 From: Leon Romanovsky > Sent: 11 October 2022 12:37 > > On Tue, Oct 11, 2022 at 07:23:25PM +0800, Rui Ma wrote: > > In some certain SR-IOV scene, when the device physical space(such as Video > > RAM)is fixed, as the number of VFs increases, some device driver may decrease > > actual BAR memory space used by each VF. However, the VF BAR memory mapping is > > always based on the usual BAR probing algorithm in PCIe spec. So do not map this > > unneeded memory can save host memory which occupied by PTEs. Although each PTE > > only occupies a few bytes of space on its own, a large number of PTEs can still > > take up a lot of space. ... > > + /* > > + * Some SR-IOV device's BAR map range is larger than they can actually use. > > + * This extra BAR space occupy too much reverse mapping size(physical page > > + * back to the PTEs). So add a divisor shift parameter to resize the request > > + * resource of VF according to num of VFs. > > + */ > > + u16 shift = 1; Why u16?? > > + virtfn->resource[i].end = virtfn->resource[i].start + (size >> (shift - 1)) - 1; The 'shift - 1' may require a mask. ... > > +struct virtfn_get_shift_methods { > > + u16 vendor; > > + u16 device; > > + u16 (*get_shift)(struct pci_dev *dev, u16 arg, int arg2); More pointless u16 - they just make the code larger. ... > > +static inline u16 virtfn_get_shift(struct pci_dev *dev, u16 arg1, int arg2) > > +{ > > + return (u16)1; > > <...> > > > + return (u16)1; > > Why do you need these casts? You can omit them. Kill all the u16 David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)